problem
stringlengths
3
7
family
stringclasses
2 values
description
stringlengths
513
6.02k
tags
stringlengths
17
139
spec
stringlengths
306
6.78k
code
stringlengths
109
3.75k
code_spec
stringlengths
442
8.81k
verified
stringlengths
449
65k
main
stringlengths
558
3.69k
⌀
checker
null
testcases_path
stringlengths
34
40
mutated_testcases_path
stringlengths
42
48
cf1036D
codeforces
# Vasya and Arrays Time limit: 1 second | Memory limit: 256 megabytes Vasya has two arrays $$$A$$$ and $$$B$$$ of lengths $$$n$$$ and $$$m$$$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a singl...
Rating: 1600 greedy, two pointers Solved by: 10509 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn prefix_sum(nums: Seq<i64>, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::prefix_sum(nums...
impl Solution { pub fn max_equal_block_count(a: Vec<i64>, b: Vec<i64>) -> i64 { let n = a.len(); let m = b.len(); let mut ta: i64 = 0; let mut tb: i64 = 0; let mut u = 0usize; while u < n { ta = ta + a[u]; u = u + 1; } u = 0usiz...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn prefix_sum(nums: Seq<i64>, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::prefix_sum(nums...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn prefix_sum(nums: Seq<i64>, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::prefix_sum(nums...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_equal_block_count(a: Vec<i64>, b: Vec<i64>) -> i64 { let n = a.len(); let m = b.len(); let mut ta: i64 = 0; let mut tb: i64 = 0; let mut u = 0usize; while u < n { ta = ta + a[u]; ...
null
codeforces/cf1036D/tests/testcases.jsonl
codeforces/cf1036D/tests/mutated_testcases.jsonl
cf1118B
codeforces
# Tanya and Candies Time limit: 1 second | Memory limit: 256 megabytes Tanya has $$$n$$$ candies numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th candy has the weight $$$a_i$$$. She plans to eat exactly $$$n-1$$$ candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers...
Rating: 1200 implementation Solved by: 13127 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn odd_sum_before(nums: Seq<i64>, end_pos: int) -> int recommends 0 <= end_pos <= nums.len(), decreases end_pos, { if end_pos <= 0 { 0 } else { S...
impl Solution { pub fn count_equal_sums(a: Vec<i64>) -> i32 { let n = a.len(); let mut total_even_idx = 0i64; let mut total_odd_idx = 0i64; let mut t = 0; while t < n { if t % 2 == 0 { total_even_idx = total_even_idx + a[t]; } else { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn odd_sum_before(nums: Seq<i64>, end_pos: int) -> int recommends 0 <= end_pos <= nums.len(), decreases end_pos, { if end_pos <= 0 { 0 } else { S...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn odd_sum_before(nums: Seq<i64>, end_pos: int) -> int recommends 0 <= end_pos <= nums.len(), decreases end_pos, { if end_pos <= 0 { 0 } else { S...
use std::io; struct Solution; impl Solution { pub fn count_equal_sums(a: Vec<i64>) -> i32 { let n = a.len(); let mut total_even_idx = 0i64; let mut total_odd_idx = 0i64; let mut t = 0; while t < n { if t % 2 == 0 { total_even_idx = total_even_idx...
null
codeforces/cf1118B/tests/testcases.jsonl
codeforces/cf1118B/tests/mutated_testcases.jsonl
cf1141B
codeforces
# Maximal Continuous Rest Time limit: 2 seconds | Memory limit: 256 megabytes Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if...
Rating: 900 implementation Solved by: 22887 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn circ_rest_segment(a: Seq<i32>, n: int, start: int, len: int) -> bool { &&& 0 <= start < n &&& 0 <= len &&& forall|k: int| 0 <= k < len ==> #[trigger] a[(start + k) % n] == 1 } pub open spec fn rest_run_len_ending_...
impl Solution { pub fn maximal_continuous_rest(a: Vec<i32>) -> i32 { let n = a.len(); let mut best: i32 = 0; let mut cur: i32 = 0; let mut i: usize = 0; let total: usize = 2 * n; while i < total { let idx: usize = i % n; if a[idx] == 1 { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn circ_rest_segment(a: Seq<i32>, n: int, start: int, len: int) -> bool { &&& 0 <= start < n &&& 0 <= len &&& forall|k: int| 0 <= k < len ==> #[trigger] a[(start + k) % n] == 1 } pub open spec fn rest_run_len_ending_...
use vstd::prelude::*; use vstd::arithmetic::div_mod::*; fn main() {} verus! { pub struct Solution; pub open spec fn circ_rest_segment(a: Seq<i32>, n: int, start: int, len: int) -> bool { &&& 0 <= start < n &&& 0 <= len &&& forall|k: int| 0 <= k < len ==> #[trigger] a[(start + k) % n] == 1 } pub...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn maximal_continuous_rest(a: Vec<i32>) -> i32 { let n = a.len(); let mut best: i32 = 0; let mut cur: i32 = 0; let mut i: usize = 0; let total: usize = 2 * n; while i < total { let idx: usiz...
null
codeforces/cf1141B/tests/testcases.jsonl
codeforces/cf1141B/tests/mutated_testcases.jsonl
cf1200C
codeforces
# Round Corridor Time limit: 1 second | Memory limit: 256 megabytes Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by $$$n$$$ sectors, and the outer area is equally divided by $$$m$$$ sectors. A wall exists between each pair of sectors of same area (inn...
Rating: 1400 math, number theory Solved by: 10540 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd_u64(a: u64, b: u64) -> u64 decreases b, { if b == 0 { a } else { Self::spec_gcd_u64(b, a % b) } } pub open spec fn spec_component_id_u64...
impl Solution { pub fn corridor_same_component( n: i64, m: i64, t1: i32, y1: i64, t2: i32, y2: i64, ) -> bool { let nu = n as u64; let mu = m as u64; let mut a: u64 = nu; let mut b: u64 = mu; while b != 0 { let r...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd_u64(a: u64, b: u64) -> u64 decreases b, { if b == 0 { a } else { Self::spec_gcd_u64(b, a % b) } } pub open spec fn spec_component_id_u64...
use vstd::prelude::*; use vstd::arithmetic::div_mod::*; fn main() {} verus! { proof fn lemma_spec_gcd_u64_min(a: u64, b: u64) requires a >= 1, b >= 1, ensures Solution::spec_gcd_u64(a, b) >= 1, decreases b, { reveal_with_fuel(Solution::spec_gcd_u64, 2); assert(Solution::sp...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn corridor_same_component( n: i64, m: i64, t1: i32, y1: i64, t2: i32, y2: i64, ) -> bool { let nu = n as u64; let mu = m as u64; let mut a: u64 = nu; let mut b: u64 ...
null
codeforces/cf1200C/tests/testcases.jsonl
codeforces/cf1200C/tests/mutated_testcases.jsonl
cf1203C
codeforces
# Common Divisors Time limit: 2 seconds | Memory limit: 256 megabytes You are given an array $$$a$$$ consisting of $$$n$$$ integers. Your task is to say the number of such positive integers $$$x$$$ such that $$$x$$$ divides **each** number from the array. In other words, you have to find the number of common divisor...
Rating: 1300 implementation, math Solved by: 23835 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd_nat(a: nat, b: nat) -> nat decreases b, { if b == 0 { a } else { Self::spec_gcd_nat(b, a % b) } } pub open spec fn spec_gcd(a: int, b: i...
impl Solution { pub fn count_common_divisors(n: usize, a: Vec<i64>) -> i64 { let mut g: i64 = a[0]; let mut i: usize = 1; while i < n { let mut x: i64 = g; let mut y: i64 = a[i]; while y != 0 { let t: i64 = y; y = x % y; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd_nat(a: nat, b: nat) -> nat decreases b, { if b == 0 { a } else { Self::spec_gcd_nat(b, a % b) } } pub open spec fn spec_gcd(a: int, b: i...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd_nat(a: nat, b: nat) -> nat decreases b, { if b == 0 { a } else { Self::spec_gcd_nat(b, a % b) } } pub open spec fn spec_gcd(a: int, b: i...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn count_common_divisors(n: usize, a: Vec<i64>) -> i64 { let mut g: i64 = a[0]; let mut i: usize = 1; while i < n { let mut x: i64 = g; let mut y: i64 = a[i]; while y != 0 { ...
null
codeforces/cf1203C/tests/testcases.jsonl
codeforces/cf1203C/tests/mutated_testcases.jsonl
cf1343D
codeforces
# Constant Palindrome Sum Time limit: 1 second | Memory limit: 256 megabytes You are given an array $$$a$$$ consisting of $$$n$$$ integers (it is guaranteed that $$$n$$$ is even, i.e. divisible by $$$2$$$). All $$$a_i$$$ does not exceed some integer $$$k$$$. Your task is to replace the **minimum** number of elements...
Rating: 1700 brute force, data structures, greedy, two pointers Solved by: 13487 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn pair_cost(ai: i64, aj: i64, k: i64, x: i64) -> int { if ai + aj == x { 0 } else if x >= ({let lo = if ai < aj { ai } else { aj }; lo} + 1) && x <= ({let hi = if ai > aj { ai } else { aj }; hi} + k) { 1 } else { 2 } } pub open spec ...
impl Solution { fn build_tables(n: usize, k: i64, a: &Vec<i64>) -> (Vec<i64>, Vec<i64>) { let half = n / 2; let size = (2 * k + 2) as usize; let mut diff: Vec<i64> = Vec::new(); let mut exact: Vec<i64> = Vec::new(); let mut idx: usize = 0; while idx < size { ...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn pair_cost(ai: i64, aj: i64, k: i64, x: i64) -> int { if ai + aj == x { 0 } else if x >= ({let lo = if ai < aj { ai } else { aj }; lo} + 1) && x <= ({let hi = if ai > aj { ai } else { aj }; hi} + k) { 1 } else { 2 } } pub open spec ...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn pair_cost(ai: i64, aj: i64, k: i64, x: i64) -> int { if ai + aj == x { 0 } else if x >= ({let lo = if ai < aj { ai } else { aj }; lo} + 1) && x <= ({let hi = if ai > aj { ai } else { aj }; hi} + k) { 1 } else { 2 } } pub open spec ...
use std::io::{self, BufRead, Write, BufWriter}; struct Solution; impl Solution { fn build_tables(n: usize, k: i64, a: &Vec<i64>) -> (Vec<i64>, Vec<i64>) { let half = n / 2; let size = (2 * k + 2) as usize; let mut diff: Vec<i64> = Vec::new(); let mut exact: Vec<i64> = Vec::new(); ...
null
codeforces/cf1343D/tests/testcases.jsonl
codeforces/cf1343D/tests/mutated_testcases.jsonl
cf1358C
codeforces
# Celex Update Time limit: 2 seconds | Memory limit: 256 megabytes During the quarantine, Sicromoft has more free time to create the new functions in "`Celex-2021`". The developers made a new function `GAZ-GIZ`, which infinitely fills an infinite table to the right and down from the upper left corner as follows: T...
Rating: 1600 math Solved by: 18296 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_celex_distinct_sums(x1: int, y1: int, x2: int, y2: int) -> int { (x2 - x1) * (y2 - y1) + 1 } impl Solution { pub fn celex_distinct_sums(x1: i64, y1: i64, x2: i64, y2: i64) -> (r: i64) requires 1 <= x1...
impl Solution { pub fn celex_distinct_sums(x1: i64, y1: i64, x2: i64, y2: i64) -> i64 { let dx = x2 - x1; let dy = y2 - y1; dx * dy + 1 } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_celex_distinct_sums(x1: int, y1: int, x2: int, y2: int) -> int { (x2 - x1) * (y2 - y1) + 1 } impl Solution { pub fn celex_distinct_sums(x1: i64, y1: i64, x2: i64, y2: i64) -> (r: i64) requires 1 <= x1...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_celex_distinct_sums(x1: int, y1: int, x2: int, y2: int) -> int { (x2 - x1) * (y2 - y1) + 1 } impl Solution { pub fn celex_distinct_sums(x1: i64, y1: i64, x2: i64, y2: i64) -> (r: i64) requires 1 <= x1...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn celex_distinct_sums(x1: i64, y1: i64, x2: i64, y2: i64) -> i64 { let dx = x2 - x1; let dy = y2 - y1; dx * dy + 1 } } fn main() { let stdin = io::stdin(); let mut lines = stdin.lock().lines(); let t: usiz...
null
codeforces/cf1358C/tests/testcases.jsonl
codeforces/cf1358C/tests/mutated_testcases.jsonl
cf136A
codeforces
# Presents Time limit: 2 seconds | Memory limit: 256 megabytes Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a N...
Rating: 800 implementation Solved by: 144275 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn value_occurs(p: Seq<i32>, n: int, v: int) -> bool { exists|i: int| 0 <= i < n && p[i] == v } pub open spec fn is_permutation_1_to_n(p: Seq<i32>, n: int) -> bool { p.len() == n && 1 <= n <= 100 && forall|i: int...
impl Solution { pub fn inverse_presents(p: Vec<i32>, n: usize) -> Vec<i32> { let mut result = Vec::new(); let mut i = 0usize; while i < n { result.push(0i32); i += 1; } i = 0usize; while i < n { let idx = (p[i] as usize) - 1; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn value_occurs(p: Seq<i32>, n: int, v: int) -> bool { exists|i: int| 0 <= i < n && p[i] == v } pub open spec fn is_permutation_1_to_n(p: Seq<i32>, n: int) -> bool { p.len() == n && 1 <= n <= 100 && forall|i: int...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn value_occurs(p: Seq<i32>, n: int, v: int) -> bool { exists|i: int| 0 <= i < n && p[i] == v } pub open spec fn is_permutation_1_to_n(p: Seq<i32>, n: int) -> bool { p.len() == n && 1 <= n <= 100 && forall|i: int...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn inverse_presents(p: Vec<i32>, n: usize) -> Vec<i32> { let mut result = Vec::new(); let mut i = 0usize; while i < n { result.push(0i32); i += 1; } i = 0usize; while i < n { ...
null
codeforces/cf136A/tests/testcases.jsonl
codeforces/cf136A/tests/mutated_testcases.jsonl
cf1433B
codeforces
# Yet Another Bookshelf Time limit: 1 second | Memory limit: 256 megabytes There is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is **at least one book** on the bookshelf. In...
Rating: 800 greedy, implementation Solved by: 29831 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn first_one_idx(a: Seq<u8>, k: int) -> int decreases k, { if k <= 0 { -1 } else { let r = first_one_idx(a, k - 1); if r != -1 { r } else if a[k - 1] == 1u8 { k - 1 ...
impl Solution { pub fn min_moves_books(n: usize, a: Vec<u8>) -> usize { let mut first: usize = 0; let mut found_first = false; let mut i: usize = 0; while i < n { if a[i] == 1u8 && !found_first { first = i; found_first = true; }...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn first_one_idx(a: Seq<u8>, k: int) -> int decreases k, { if k <= 0 { -1 } else { let r = first_one_idx(a, k - 1); if r != -1 { r } else if a[k - 1] == 1u8 { k - 1 ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn first_one_idx(a: Seq<u8>, k: int) -> int decreases k, { if k <= 0 { -1 } else { let r = first_one_idx(a, k - 1); if r != -1 { r } else if a[k - 1] == 1u8 { k - 1 ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn min_moves_books(n: usize, a: Vec<u8>) -> usize { let mut first: usize = 0; let mut found_first = false; let mut i: usize = 0; while i < n { if a[i] == 1u8 && !found_first { ...
null
codeforces/cf1433B/tests/testcases.jsonl
codeforces/cf1433B/tests/mutated_testcases.jsonl
cf1462D
codeforces
# Add to Neighbour and Remove Time limit: 3 seconds | Memory limit: 256 megabytes Polycarp was given an array of $$$a[1 \dots n]$$$ of $$$n$$$ integers. He can perform the following operation with the array $$$a$$$ no more than $$$n$$$ times: - Polycarp selects the index $$$i$$$ and adds the value $$$a_i$$$ to **one...
Rating: 1400 greedy, math, number theory Solved by: 18025 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn sum_range(a: Seq<i64>, start: int, end: int) -> int decreases end - start { if end <= start { 0 } else { a[end - 1] as int + sum_range(a, start, end - 1) } } pub open spec fn can_partition_k(a: Seq<i64>, n: usize, k: int) -...
impl Solution { fn compute_sum(n: usize, a: &Vec<i64>) -> i64 { let mut total: i64 = 0; let mut i: usize = 0; while i < n { total += a[i]; i += 1; } total } fn check_partition(n: usize, a: &Vec<i64>, g: usize, total: i64) -> bool { let...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn sum_range(a: Seq<i64>, start: int, end: int) -> int decreases end - start { if end <= start { 0 } else { a[end - 1] as int + sum_range(a, start, end - 1) } } pub open spec fn can_partition_k(a: Seq<i64>, n: usize, k: int) -...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn sum_range(a: Seq<i64>, start: int, end: int) -> int decreases end - start { if end <= start { 0 } else { a[end - 1] as int + sum_range(a, start, end - 1) } } proof fn lemma_sum_range_additive(a: Seq<i64>, s: int, m: int, e:...
use std::io::{self, BufRead, Write, BufWriter}; struct Solution; impl Solution { fn compute_sum(n: usize, a: &Vec<i64>) -> i64 { let mut total: i64 = 0; let mut i: usize = 0; while i < n { total += a[i]; i += 1; } total } fn check_partition(...
null
codeforces/cf1462D/tests/testcases.jsonl
codeforces/cf1462D/tests/mutated_testcases.jsonl
cf148A
codeforces
# Insomnia cure Time limit: 2 seconds | Memory limit: 256 megabytes «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she cou...
Rating: 800 constructive algorithms, implementation, math Solved by: 110942 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn damaged(i: int, k: int, l: int, m: int, n: int) -> bool { i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 } pub open spec fn count_damaged_spec(k: int, l: int, m: int, n: int, d: int) -> int decreases d, { if d < 1 {...
impl Solution { pub fn count_damaged(k: i32, l: i32, m: i32, n: i32, d: i32) -> i32 { let mut count = 0i32; let mut i = 1i32; while i <= d { if i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 { count = count + 1; } i = i + 1; }...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn damaged(i: int, k: int, l: int, m: int, n: int) -> bool { i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 } pub open spec fn count_damaged_spec(k: int, l: int, m: int, n: int, d: int) -> int decreases d, { if d < 1 {...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn damaged(i: int, k: int, l: int, m: int, n: int) -> bool { i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 } pub open spec fn count_damaged_spec(k: int, l: int, m: int, n: int, d: int) -> int decreases d, { if d < 1 {...
use std::io; struct Solution; impl Solution { pub fn count_damaged(k: i32, l: i32, m: i32, n: i32, d: i32) -> i32 { let mut count = 0i32; let mut i = 1i32; while i <= d { if i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 { count = count + 1; } ...
null
codeforces/cf148A/tests/testcases.jsonl
codeforces/cf148A/tests/mutated_testcases.jsonl
cf14A
codeforces
# Letter Time limit: 1 second | Memory limit: 64 megabytes A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with $n$ rows and $m$ columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. ...
Rating: 800 implementation Solved by: 12356 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn bounding_box(grid: &Vec<Vec<u8>>, n: usize, m: usize) -> (result: (usize, usize, usize, usize)) requires 1 <= n <= 50, 1 <= m <= 50, grid.len() == n, forall|i: int| 0 <...
impl Solution { pub fn bounding_box(grid: &Vec<Vec<u8>>, n: usize, m: usize) -> (usize, usize, usize, usize) { let mut min_r: usize = n; let mut max_r: usize = 0; let mut min_c: usize = m; let mut max_c: usize = 0; let mut found: bool = false; let mut i: usize = 0; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn bounding_box(grid: &Vec<Vec<u8>>, n: usize, m: usize) -> (result: (usize, usize, usize, usize)) requires 1 <= n <= 50, 1 <= m <= 50, grid.len() == n, forall|i: int| 0 <...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn bounding_box(grid: &Vec<Vec<u8>>, n: usize, m: usize) -> (result: (usize, usize, usize, usize)) requires 1 <= n <= 50, 1 <= m <= 50, grid.len() == n, forall|i: int| 0 <...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn bounding_box(grid: &Vec<Vec<u8>>, n: usize, m: usize) -> (usize, usize, usize, usize) { let mut min_r: usize = n; let mut max_r: usize = 0; let mut min_c: usize = m; let mut max_c: usize = 0; ...
null
codeforces/cf14A/tests/testcases.jsonl
codeforces/cf14A/tests/mutated_testcases.jsonl
cf1535A
codeforces
# Fair Playoff Time limit: 2 seconds | Memory limit: 256 megabytes Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of th...
800 brute force, implementation 56802
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn max2(a: i64, b: i64) -> i64 { if a >= b { a } else { b } } pub open spec fn min2(a: i64, b: i64) -> i64 { if a <= b { a } else { b } } pub open spec fn fair_playoff_spec(s1: i64, s...
impl Solution { pub fn fair_playoff(s1: i64, s2: i64, s3: i64, s4: i64) -> bool { let w1 = if s1 >= s2 { s1 } else { s2 }; let w2 = if s3 >= s4 { s3 } else { s4 }; let l1 = if s1 <= s2 { s1 } else { s2 }; let l2 = if s3 <= s4 { s3 } else { s4 }; let weaker_winner = if w1 <= w...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn max2(a: i64, b: i64) -> i64 { if a >= b { a } else { b } } pub open spec fn min2(a: i64, b: i64) -> i64 { if a <= b { a } else { b } } pub open spec fn fair_playoff_spec(s1: i64, s...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn max2(a: i64, b: i64) -> i64 { if a >= b { a } else { b } } pub open spec fn min2(a: i64, b: i64) -> i64 { if a <= b { a } else { b } } pub open spec fn fair_playoff_spec(s1: i64, s...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn fair_playoff(s1: i64, s2: i64, s3: i64, s4: i64) -> bool { let w1 = if s1 >= s2 { s1 } else { s2 }; let w2 = if s3 >= s4 { s3 } else { s4 }; let l1 = if s1 <= s2 { s1 } else { s2 }; let l2 = if s3 <= s4 { s3 } else ...
null
codeforces/cf1535A/tests/testcases.jsonl
codeforces/cf1535A/tests/mutated_testcases.jsonl
cf1547D
codeforces
# Co-growing Sequence Time limit: 2 seconds | Memory limit: 512 megabytes A sequence of non-negative integers $$$a_1, a_2, \dots, a_n$$$ is called *growing* if for all $$$i$$$ from $$$1$$$ to $$$n - 1$$$ all ones (of binary representation) in $$$a_i$$$ are in the places of ones (of binary representation) in $$$a_{i +...
Rating: 1300 bitmasks, constructive algorithms, greedy Solved by: 18491 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_co_growing(x: Seq<u32>, y: Seq<u32>, n: usize) -> bool { x.len() == n && y.len() == n && forall|i: int| #![trigger x[i]] 0 <= i && i < n as int - 1 ==> (x[i] ^ y[i]) & (x[i + 1] ^ y[i + 1]) == (x[i] ^ y[i]) } pub open spec fn lex_le_u32...
impl Solution { pub fn co_growing(n: usize, x: Vec<u32>) -> Vec<u32> { let mut y: Vec<u32> = Vec::new(); let mut z: u32 = x[0]; let y0 = z ^ x[0]; y.push(y0); let mut i: usize = 1; while i < n { let old_z = z; z = z | x[i]; let yi =...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_co_growing(x: Seq<u32>, y: Seq<u32>, n: usize) -> bool { x.len() == n && y.len() == n && forall|i: int| #![trigger x[i]] 0 <= i && i < n as int - 1 ==> (x[i] ^ y[i]) & (x[i + 1] ^ y[i + 1]) == (x[i] ^ y[i]) } pub open spec fn lex_le_u32...
use vstd::arithmetic::div_mod::lemma_small_mod; use vstd::arithmetic::power2::{lemma2_to64, pow2}; use vstd::bits::{lemma_low_bits_mask_values, lemma_u32_low_bits_mask_is_mod, low_bits_mask}; use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_co_growing(x: Seq<u32>, y: Seq<u32>, n: usize) -> bool { ...
use std::io::{self, BufRead, Write, BufWriter}; struct Solution; impl Solution { pub fn co_growing(n: usize, x: Vec<u32>) -> Vec<u32> { let mut y: Vec<u32> = Vec::new(); let mut z: u32 = x[0]; let y0 = z ^ x[0]; y.push(y0); let mut i: usize = 1; while i < n { ...
null
codeforces/cf1547D/tests/testcases.jsonl
codeforces/cf1547D/tests/mutated_testcases.jsonl
cf158A
codeforces
# Next Round Time limit: 3 seconds | Memory limit: 256 megabytes "Contestant who earns a score equal to or greater than the $k$-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of $n$ participants took part in the ...
Rating: 800 implementation Solved by: many users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn advances(score: int, threshold: int) -> bool { score >= threshold && score > 0 } pub open spec fn count_advancing_to(scores: Seq<i32>, threshold: int, end: int) -> nat recommends 0 <= end <= scores.len(), decrease...
impl Solution { pub fn count_advancing(scores: Vec<i32>, k: usize) -> usize { let threshold = scores[k - 1]; let mut count = 0usize; let mut i = 0usize; while i < scores.len() { if scores[i] >= threshold && scores[i] > 0 { count += 1; } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn advances(score: int, threshold: int) -> bool { score >= threshold && score > 0 } pub open spec fn count_advancing_to(scores: Seq<i32>, threshold: int, end: int) -> nat recommends 0 <= end <= scores.len(), decrease...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn advances(score: int, threshold: int) -> bool { score >= threshold && score > 0 } pub open spec fn count_advancing_to(scores: Seq<i32>, threshold: int, end: int) -> nat recommends 0 <= end <= scores.len(), decrease...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn count_advancing(scores: Vec<i32>, k: usize) -> usize { let threshold = scores[k - 1]; let mut count = 0usize; let mut i = 0usize; while i < scores.len() { if scores[i] >= threshold && scores[i] > 0 { ...
null
codeforces/cf158A/tests/testcases.jsonl
codeforces/cf158A/tests/mutated_testcases.jsonl
cf1598B
codeforces
# Groups Time limit: 4 seconds | Memory limit: 256 megabytes $$$n$$$ students attended the first meeting of the Berland SU programming course ($$$n$$$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday,...
Rating: 1000 brute force, implementation Solved by: 16860 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn student_can_attend(days: Seq<Vec<bool>>, i: int, d: int) -> bool { days[i]@[d] } pub open spec fn count_can_attend_one(days: Seq<Vec<bool>>, d: int, end: int) -> int decreases end { if end <= 0 { 0 } else { count_can_attend_one(days, d, en...
impl Solution { pub fn groups(n: usize, days: Vec<Vec<bool>>) -> bool { let mut found = false; let mut d1: usize = 0; while d1 < 5 && !found { let mut d2: usize = d1 + 1; while d2 < 5 && !found { let mut either: usize = 0; let mut can_d...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn student_can_attend(days: Seq<Vec<bool>>, i: int, d: int) -> bool { days[i]@[d] } pub open spec fn count_can_attend_one(days: Seq<Vec<bool>>, d: int, end: int) -> int decreases end { if end <= 0 { 0 } else { count_can_attend_one(days, d, en...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn student_can_attend(days: Seq<Vec<bool>>, i: int, d: int) -> bool { days[i]@[d] } pub open spec fn count_can_attend_one(days: Seq<Vec<bool>>, d: int, end: int) -> int decreases end { if end <= 0 { 0 } else { count_can_attend_one(days, d, en...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn groups(n: usize, days: Vec<Vec<bool>>) -> bool { let mut found = false; let mut d1: usize = 0; while d1 < 5 && !found { let mut d2: usize = d1 + 1; while d2 < 5 && !found { let mut...
null
codeforces/cf1598B/tests/testcases.jsonl
codeforces/cf1598B/tests/mutated_testcases.jsonl
cf1602C
codeforces
# Array Elimination Time limit: 2 seconds | Memory limit: 512 megabytes You are given array $$$a_1, a_2, \ldots, a_n$$$, consisting of non-negative integers. Let's define operation of "elimination" with integer parameter $$$k$$$ ($$$1 \leq k \leq n$$$) as follows: - Choose $$$k$$$ distinct array indices $$$1 \leq i...
Rating: 1300 bitmasks, math, number theory Solved by: N/A users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn common_divisor(cnt: Seq<i32>, d: int) -> bool recommends cnt.len() == 30, { &&& 1 <= d &&& forall|b: int| 0 <= b < 30 ==> #[trigger] ((cnt[b] as int) % d) == 0 } pub...
impl Solution { pub fn valid_k_values(n: usize, cnt: Vec<i32>) -> Vec<i32> { let mut ans: Vec<i32> = Vec::new(); let mut k: usize = 1; while k <= n { let k_i32: i32 = k as i32; let mut b: usize = 0; let mut bad_idx: i32 = -1; while b < 30 { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn common_divisor(cnt: Seq<i32>, d: int) -> bool recommends cnt.len() == 30, { &&& 1 <= d &&& forall|b: int| 0 <= b < 30 ==> #[trigger] ((cnt[b] as int) % d) == 0 } pub...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn common_divisor(cnt: Seq<i32>, d: int) -> bool recommends cnt.len() == 30, { &&& 1 <= d &&& forall|b: int| 0 <= b < 30 ==> #[trigger] ((cnt[b] as int) % d) == 0 } pub...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn valid_k_values(n: usize, cnt: Vec<i32>) -> Vec<i32> { let mut ans: Vec<i32> = Vec::new(); let mut k: usize = 1; while k <= n { let k_i32: i32 = k as i32; let mut b: usize = 0; let mut ba...
null
codeforces/cf1602C/tests/testcases.jsonl
codeforces/cf1602C/tests/mutated_testcases.jsonl
cf1644C
codeforces
# Increase Subarray Sums Time limit: 2 seconds | Memory limit: 256 megabytes You are given an array $$$a_1, a_2, \dots, a_n$$$, consisting of $$$n$$$ integers. You are also given an integer value $$$x$$$. Let $$$f(k)$$$ be the maximum sum of a contiguous subarray of $$$a$$$ after applying the following operation: ad...
Rating: 1400 brute force, dp, greedy, implementation Solved by: 14904 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn neg_inf() -> int { -1_000_000_000_000 } pub open spec fn min_int(a: int, b: int) -> int { if a <= b { a } else { b } } pub open spec fn range_sum(a: Seq<i64>, start: int, len: int)...
impl Solution { fn max_sum_for_len(a: &Vec<i64>, len: usize) -> i64 { let n = a.len(); let mut j: usize = 0; let mut window_sum: i64 = 0; while j < len { let j0 = j; window_sum = window_sum + a[j0]; j = j0 + 1; } let mut best_len = ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn neg_inf() -> int { -1_000_000_000_000 } pub open spec fn min_int(a: int, b: int) -> int { if a <= b { a } else { b } } pub open spec fn range_sum(a: Seq<i64>, start: int, len: int)...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn neg_inf() -> int { -1_000_000_000_000 } pub open spec fn min_int(a: int, b: int) -> int { if a <= b { a } else { b } } pub open spec fn range_sum(a: Seq<i64>, start: int, len: int)...
use std::io::{self, Read}; struct Solution; impl Solution { fn max_sum_for_len(a: &Vec<i64>, len: usize) -> i64 { let n = a.len(); let mut j: usize = 0; let mut window_sum: i64 = 0; while j < len { let j0 = j; window_sum = window_sum + a[j0]; j =...
null
codeforces/cf1644C/tests/testcases.jsonl
codeforces/cf1644C/tests/mutated_testcases.jsonl
cf1676B
codeforces
# Equal Candies Time limit: 1 second | Memory limit: 256 megabytes There are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside. You also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. Bu...
Rating: 800 greedy, math, sortings Solved by: N/A users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_min_value(s: Seq<i64>, m: int) -> bool { &&& s.len() > 0 &&& exists|j: int| 0 <= j < s.len() && s[j] as int == m &&& forall|j: int| 0 <= j < s.len() ==> m <= s[j] as int } pub open spec fn sum_decrease_with(s: Seq<i64>...
impl Solution { pub fn min_operations_to_equal(candies: Vec<i64>) -> i64 { let n = candies.len(); let mut min_val = candies[0]; let mut i: usize = 1; while i < n { if candies[i] < min_val { min_val = candies[i]; } i += 1; } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_min_value(s: Seq<i64>, m: int) -> bool { &&& s.len() > 0 &&& exists|j: int| 0 <= j < s.len() && s[j] as int == m &&& forall|j: int| 0 <= j < s.len() ==> m <= s[j] as int } pub open spec fn sum_decrease_with(s: Seq<i64>...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_min_value(s: Seq<i64>, m: int) -> bool { &&& s.len() > 0 &&& exists|j: int| 0 <= j < s.len() && s[j] as int == m &&& forall|j: int| 0 <= j < s.len() ==> m <= s[j] as int } pub open spec fn sum_decrease_with(s: Seq<i64>...
use std::io::{self, Read}; pub struct Solution; impl Solution { pub fn min_operations_to_equal(candies: Vec<i64>) -> i64 { let n = candies.len(); let mut min_val = candies[0]; let mut i: usize = 1; while i < n { if candies[i] < min_val { min_val = candie...
null
codeforces/cf1676B/tests/testcases.jsonl
codeforces/cf1676B/tests/mutated_testcases.jsonl
cf1678A
codeforces
# Tokitsukaze and All Zero Sequence Time limit: 1 second | Memory limit: 256 megabytes Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$). - If $$$a_i = a_j$$$, change one of them to $$$0$$$. - Otherwise...
Rating: 800 implementation Solved by: 19146 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_prefix_count(s: Seq<i32>, i: int, v: int) -> int decreases i, { if i <= 0 { 0int } else { spec_prefix_count(s, i - 1, v) + if s[i - 1] as int == v { 1int } else { 0int ...
impl Solution { pub fn min_ops_to_all_zero(a: Vec<i32>) -> i32 { let n = a.len(); let mut cnt: Vec<i32> = Vec::new(); let mut t = 0usize; while t < 101 { cnt.push(0i32); t = t + 1; } let mut i = 0usize; while i < n { let x =...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_prefix_count(s: Seq<i32>, i: int, v: int) -> int decreases i, { if i <= 0 { 0int } else { spec_prefix_count(s, i - 1, v) + if s[i - 1] as int == v { 1int } else { 0int ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_prefix_count(s: Seq<i32>, i: int, v: int) -> int decreases i, { if i <= 0 { 0int } else { spec_prefix_count(s, i - 1, v) + if s[i - 1] as int == v { 1int } else { 0int ...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn min_ops_to_all_zero(a: Vec<i32>) -> i32 { let n = a.len(); let mut cnt: Vec<i32> = Vec::new(); let mut t = 0usize; while t < 101 { cnt.push(0i32); t = t + 1; } let mut i = ...
null
codeforces/cf1678A/tests/testcases.jsonl
codeforces/cf1678A/tests/mutated_testcases.jsonl
cf1690B
codeforces
# Array Decrements Time limit: 1 second | Memory limit: 256 megabytes Kristina has two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ non-negative integers. She can perform the following operation on array $$$a$$$ any number of times: - apply a decrement to each non-zero element of the array, that is, replace ...
Rating: 800 greedy, implementation Solved by: 26865 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_valid_decrements(n: usize, a: Seq<i32>, b: Seq<i32>, max_diff: i32) -> bool { (forall|i: int| 0 <= i && i < n ==> a[i] >= b[i]) && (forall|i: int| 0 <= i && i < n ==> a[i] - b[i] <= max_diff) && (forall|i: int| 0 <= i && i < n ==> (a...
impl Solution { pub fn is_possible(n: usize, a: Vec<i32>, b: Vec<i32>) -> bool { let mut max_diff: i32 = 0; let mut i: usize = 0; let mut possible = true; while i < n { if a[i] < b[i] { possible = false; } else { let di...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_valid_decrements(n: usize, a: Seq<i32>, b: Seq<i32>, max_diff: i32) -> bool { (forall|i: int| 0 <= i && i < n ==> a[i] >= b[i]) && (forall|i: int| 0 <= i && i < n ==> a[i] - b[i] <= max_diff) && (forall|i: int| 0 <= i && i < n ==> (a...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_valid_decrements(n: usize, a: Seq<i32>, b: Seq<i32>, max_diff: i32) -> bool { (forall|i: int| 0 <= i && i < n ==> a[i] >= b[i]) && (forall|i: int| 0 <= i && i < n ==> a[i] - b[i] <= max_diff) && (forall|i: int| 0 <= i && i < n ==> (a...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn is_possible(n: usize, a: Vec<i32>, b: Vec<i32>) -> bool { let mut max_diff: i32 = 0; let mut i: usize = 0; let mut possible = true; while i < n { if a[i] < b[i] { possible = f...
null
codeforces/cf1690B/tests/testcases.jsonl
codeforces/cf1690B/tests/mutated_testcases.jsonl
cf1690C
codeforces
# Restoring the Duration of Tasks Time limit: 2 seconds | Memory limit: 256 megabytes Recently, Polycarp completed $$$n$$$ successive tasks. For each completed task, the time $$$s_i$$$ is known when it was given, no two tasks were given at the same time. Also given is the time $$$f_i$$$ when the task was completed. ...
Rating: 800 data structures, greedy, implementation Solved by: 28009 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn duration(s: Seq<i64>, f: Seq<i64>, i: int) -> int recommends 0 <= i < s.len(), s.len() == f.len(), decreases i, { if i <= 0 { f[0] as int - s[0] as in...
impl Solution { pub fn restore_durations(s: Vec<i64>, f: Vec<i64>) -> Vec<i64> { let n = s.len(); let mut result: Vec<i64> = Vec::with_capacity(n); let mut i: usize = 0; while i < n { let start = if i == 0 || s[i] > f[i - 1] { s[i] } else { f[i - 1] }; let dur...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn duration(s: Seq<i64>, f: Seq<i64>, i: int) -> int recommends 0 <= i < s.len(), s.len() == f.len(), decreases i, { if i <= 0 { f[0] as int - s[0] as in...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn duration(s: Seq<i64>, f: Seq<i64>, i: int) -> int recommends 0 <= i < s.len(), s.len() == f.len(), decreases i, { if i <= 0 { f[0] as int - s[0] as in...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn restore_durations(s: Vec<i64>, f: Vec<i64>) -> Vec<i64> { let n = s.len(); let mut result: Vec<i64> = Vec::with_capacity(n); let mut i: usize = 0; while i < n { let start = if i == 0 || s[i] > f[i - 1] {...
null
codeforces/cf1690C/tests/testcases.jsonl
codeforces/cf1690C/tests/mutated_testcases.jsonl
cf1690D
codeforces
# Black and White Stripe Time limit: 2 seconds | Memory limit: 256 megabytes You have a stripe of checkered paper of length $$$n$$$. Each cell is either white or black. What is the minimum number of cells that must be recolored from white to black in order to have a segment of $$$k$$$ consecutive black cells on the ...
Rating: 1200 brute force, implementation, strings, two pointers Solved by: unknown users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn sum_range(s: Seq<i64>, l: int, r: int) -> int recommends 0 <= l <= r <= s.len(), decreases r - l, { if l >= r { 0 } else { s[l] as int + Self:...
impl Solution { pub fn min_recolors(n: usize, k: usize, s: Vec<i64>) -> usize { let mut cur: i64 = 0; let mut j: usize = 0; while j < k { cur = cur + s[j]; j += 1; } let mut best: i64 = cur; let mut left: usize = 0; while left + k < n...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn sum_range(s: Seq<i64>, l: int, r: int) -> int recommends 0 <= l <= r <= s.len(), decreases r - l, { if l >= r { 0 } else { s[l] as int + Self:...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn sum_range(s: Seq<i64>, l: int, r: int) -> int recommends 0 <= l <= r <= s.len(), decreases r - l, { if l >= r { 0 } else { s[l] as int + Self:...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn min_recolors(n: usize, k: usize, s: Vec<i64>) -> usize { let mut cur: i64 = 0; let mut j: usize = 0; while j < k { cur = cur + s[j]; j += 1; } let mut best: i64 = cur; let mu...
null
codeforces/cf1690D/tests/testcases.jsonl
codeforces/cf1690D/tests/mutated_testcases.jsonl
cf1709A
codeforces
# Three Doors Time limit: 2 seconds | Memory limit: 256 megabytes There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door. There are three keys — one for each door....
Rating: 800 brute force, greedy, implementation, math Solved by: 31504 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_value(v: int, x: int, a: int, b: int, c: int) -> int { (if x == v { 1int } else { 0 }) + (if a == v { 1int } else { 0 })...
impl Solution { pub fn can_open_all_doors(x: i32, a: i32, b: i32, c: i32) -> bool { let y = if x == 1 { a } else if x == 2 { b } else { c }; if y == 0 { false } else { let z = if y == 1 { a ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_value(v: int, x: int, a: int, b: int, c: int) -> int { (if x == v { 1int } else { 0 }) + (if a == v { 1int } else { 0 })...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_value(v: int, x: int, a: int, b: int, c: int) -> int { (if x == v { 1int } else { 0 }) + (if a == v { 1int } else { 0 })...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn can_open_all_doors(x: i32, a: i32, b: i32, c: i32) -> bool { let y = if x == 1 { a } else if x == 2 { b } else { c }; if y == 0 { false } else { ...
null
codeforces/cf1709A/tests/testcases.jsonl
codeforces/cf1709A/tests/mutated_testcases.jsonl
cf1714A
codeforces
# Everyone Loves to Sleep Time limit: 2 seconds | Memory limit: 256 megabytes Vlad, like everyone else, loves to sleep very much. Every day Vlad has to do $$$n$$$ things, each at a certain time. For each of these things, he has an alarm clock set, the $$$i$$$-th of them is triggered on $$$h_i$$$ hours $$$m_i$$$ minu...
Rating: 900 implementation, math Solved by: 32743 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_wait_minutes(now: int, alarm: int) -> int { if alarm >= now { alarm - now } else { alarm + 1440 - now } } pub fn min_wait_minutes(now: i32, alarms: Vec<...
impl Solution { pub fn wait_minutes(now: i32, alarm: i32) -> i32 { if alarm >= now { alarm - now } else { alarm + 1440 - now } } pub fn min_wait_minutes(now: i32, alarms: Vec<i32>) -> i32 { let n = alarms.len(); let mut best = Self::wait_minut...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_wait_minutes(now: int, alarm: int) -> int { if alarm >= now { alarm - now } else { alarm + 1440 - now } } pub fn wait_minutes(now: i32, alarm: i32) -> (...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_wait_minutes(now: int, alarm: int) -> int { if alarm >= now { alarm - now } else { alarm + 1440 - now } } pub fn wait_minutes(now: i32, alarm: i32) -> (...
use std::io::{self, Read}; struct Solution; fn next_usize<'a, I: Iterator<Item = &'a str>>(it: &mut I) -> Option<usize> { it.next()?.parse().ok() } fn next_i32<'a, I: Iterator<Item = &'a str>>(it: &mut I) -> Option<i32> { it.next()?.parse().ok() } impl Solution { pub fn wait_minutes(now: i32, alarm: i32...
null
codeforces/cf1714A/tests/testcases.jsonl
codeforces/cf1714A/tests/mutated_testcases.jsonl
cf1721A
codeforces
# Image Time limit: 2 seconds | Memory limit: 512 megabytes You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters. You want to recolor some of the pixels of the image **so that all $$$4$$$ pixels have th...
Rating: 800 greedy, implementation Solved by: 28248 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn letter_mask(a: u8, b: u8, c: u8, d: u8) -> u32 { (1u32 << a) | (1u32 << b) | (1u32 << c) | (1u32 << d) } pub open spec fn popcount_prefix(mask: u32, k: int) -> int decreases k, { ...
impl Solution { pub fn popcount_mask26(mask: u32) -> i32 { let mut d: i32 = 0; let mut k: u8 = 0; while k < 26 { let pre_d = d; let bit: i32 = if (mask >> k) & 1u32 == 0u32 { 0 } else { 1 }; d = pre_d...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn letter_mask(a: u8, b: u8, c: u8, d: u8) -> u32 { (1u32 << a) | (1u32 << b) | (1u32 << c) | (1u32 << d) } pub open spec fn popcount_prefix(mask: u32, k: int) -> int decreases k, { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn letter_mask(a: u8, b: u8, c: u8, d: u8) -> u32 { (1u32 << a) | (1u32 << b) | (1u32 << c) | (1u32 << d) } pub open spec fn popcount_prefix(mask: u32, k: int) -> int decreases k, { ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn popcount_mask26(mask: u32) -> i32 { let mut d: i32 = 0; let mut k: u8 = 0; while k < 26 { let pre_d = d; let bit: i32 = if (mask >> k) & 1u32 == 0u32 { 0 } else { ...
null
codeforces/cf1721A/tests/testcases.jsonl
codeforces/cf1721A/tests/mutated_testcases.jsonl
cf1730A
codeforces
# Planets Time limit: 1 second | Memory limit: 256 megabytes One day, Vogons wanted to build a new hyperspace highway through a distant system with $$$n$$$ planets. The $$$i$$$-th planet is on the orbit $$$a_i$$$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and n...
Rating: 800 data structures, greedy, sortings Solved by: 24707 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_prefix_count(a: Seq<i32>, i: int, v: int) -> int decreases i, { if i <= 0 { 0int } else { spec_prefix_count(a, i - 1, v) + if a[i - 1] as int == v { 1int } else { 0int } } } pub open spec fn spec_...
impl Solution { pub fn min_destroy_cost(orbits: Vec<i32>, c: i32) -> i32 { let n = orbits.len(); let mut cnt: Vec<i32> = Vec::new(); let mut t = 0usize; while t < 101 { cnt.push(0); t = t + 1; } let mut i = 0usize; while i < n { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_prefix_count(a: Seq<i32>, i: int, v: int) -> int decreases i, { if i <= 0 { 0int } else { spec_prefix_count(a, i - 1, v) + if a[i - 1] as int == v { 1int } else { 0int } } } pub open spec fn spec_...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_prefix_count(a: Seq<i32>, i: int, v: int) -> int decreases i, { if i <= 0 { 0int } else { spec_prefix_count(a, i - 1, v) + if a[i - 1] as int == v { 1int } else { 0int } } } pub open spec fn spec_...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn min_destroy_cost(orbits: Vec<i32>, c: i32) -> i32 { let n = orbits.len(); let mut cnt: Vec<i32> = Vec::new(); let mut t = 0usize; while t < 101 { cnt.push(0); t = t + 1; } ...
null
codeforces/cf1730A/tests/testcases.jsonl
codeforces/cf1730A/tests/mutated_testcases.jsonl
cf1742A
codeforces
# Sum Time limit: 1 second | Memory limit: 256 megabytes You are given three integers $$$a$$$, $$$b$$$, and $$$c$$$. Determine if one of them is the sum of the other two. ## Input The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 9261$$$) — the number of test cases. The description of each test ca...
Rating: 800 implementation Solved by: 102641 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_one_is_sum_of_others(a: int, b: int, c: int) -> bool { a == b + c || b == a + c || c == a + b } impl Solution { pub fn one_is_sum_of_others(a: i64, b: i64, c: i64) -> (res: bool) requires 0 <= a <= 20...
impl Solution { pub fn one_is_sum_of_others(a: i64, b: i64, c: i64) -> bool { a == b + c || b == a + c || c == a + b } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_one_is_sum_of_others(a: int, b: int, c: int) -> bool { a == b + c || b == a + c || c == a + b } impl Solution { pub fn one_is_sum_of_others(a: i64, b: i64, c: i64) -> (res: bool) requires 0 <= a <= 20...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_one_is_sum_of_others(a: int, b: int, c: int) -> bool { a == b + c || b == a + c || c == a + b } impl Solution { pub fn one_is_sum_of_others(a: i64, b: i64, c: i64) -> (res: bool) requires 0 <= a <= 20...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn one_is_sum_of_others(a: i64, b: i64, c: i64) -> bool { a == b + c || b == a + c || c == a + b } } fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).unwrap(); let mut it = input.split_whitesp...
null
codeforces/cf1742A/tests/testcases.jsonl
codeforces/cf1742A/tests/mutated_testcases.jsonl
cf1742D
codeforces
# Coprime Time limit: 3 seconds | Memory limit: 256 megabytes Given an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$). Find the maximum value of $$$i + j$$$ such that $$$a_i$$$ and $$$a_j$$$ are coprime,$$$^{\dagger}$$$ or $$$-1$$$ if no such $$$i$$$, $$$j$$$ exist. For exam...
Rating: 1100 brute force, greedy, number theory Solved by: 33611 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd(a: nat, b: nat) -> nat decreases b { if b == 0 { a } else { Self::spec_gcd(b, a % b) } } pub open spec fn spec_divides_both(d: int, x: int, y: int) -> bool { x % d == 0...
impl Solution { pub fn is_coprime_values(x: i32, y: i32) -> bool { let mut a = x; let mut b = y; while b != 0 { let r = a % b; a = b; b = r; } a == 1 } pub fn max_coprime_index_sum(a: Vec<i32>) -> i32 { let n = a.len(); ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd(a: nat, b: nat) -> nat decreases b { if b == 0 { a } else { Self::spec_gcd(b, a % b) } } pub open spec fn spec_divides_both(d: int, x: int, y: int) -> bool { x % d == 0...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_gcd(a: nat, b: nat) -> nat decreases b { if b == 0 { a } else { Self::spec_gcd(b, a % b) } } pub open spec fn spec_divides_both(d: int, x: int, y: int) -> bool { x % d == 0...
use std::io::{self, Read}; struct Solution; fn next_usize<'a, I: Iterator<Item = &'a str>>(it: &mut I) -> Option<usize> { it.next()?.parse().ok() } fn next_i32<'a, I: Iterator<Item = &'a str>>(it: &mut I) -> Option<i32> { it.next()?.parse().ok() } impl Solution { pub fn is_coprime_values(x: i32, y: i32)...
null
codeforces/cf1742D/tests/testcases.jsonl
codeforces/cf1742D/tests/mutated_testcases.jsonl
cf1760C
codeforces
# Advantage Time limit: 2 seconds | Memory limit: 256 megabytes There are $$$n$$$ participants in a competition, participant $$$i$$$ having a strength of $$$s_i$$$. Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant $$$i$$$ wants to know th...
Rating: 800 data structures, implementation, sortings Solved by: 43524 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn valid_advantage(s: Seq<i64>, i: int, d: int) -> bool { exists|j: int| { &&& 0 <= j < s.len() &&& j != i &&& d == s[i] as int - s[j] as int &&& forall|k: int| 0 <= k < s.len() && k != i ==> s[k] as int <= #[trigger] s[j] ...
impl Solution { pub fn advantages(s: Vec<i64>) -> Vec<i64> { let n = s.len(); let mut max1: i64 = s[0]; let mut idx1: usize = 0; let mut max2: i64 = s[1]; let mut idx2: usize = 1; if max2 > max1 { let tv = max1; let ti = idx1; max1...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn valid_advantage(s: Seq<i64>, i: int, d: int) -> bool { exists|j: int| { &&& 0 <= j < s.len() &&& j != i &&& d == s[i] as int - s[j] as int &&& forall|k: int| 0 <= k < s.len() && k != i ==> s[k] as int <= #[trigger] s[j] ...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn valid_advantage(s: Seq<i64>, i: int, d: int) -> bool { exists|j: int| { &&& 0 <= j < s.len() &&& j != i &&& d == s[i] as int - s[j] as int &&& forall|k: int| 0 <= k < s.len() && k != i ==> s[k] as int <= #[trigger] s[j] ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn advantages(s: Vec<i64>) -> Vec<i64> { let n = s.len(); let mut max1: i64 = s[0]; let mut idx1: usize = 0; let mut max2: i64 = s[1]; let mut idx2: usize = 1; if max2 > max1 { let tv = max...
null
codeforces/cf1760C/tests/testcases.jsonl
codeforces/cf1760C/tests/mutated_testcases.jsonl
cf1760D
codeforces
# Challenging Valleys Time limit: 2 seconds | Memory limit: 256 megabytes You are given an array $$$a[0 \dots n-1]$$$ of $$$n$$$ integers. This array is called a "*valley*" if there exists **exactly one** subarray $$$a[l \dots r]$$$ such that: - $$$0 \le l \le r \le n-1$$$, - $$$a_l = a_{l+1} = a_{l+2} = \dots = a_...
Rating: 1000 implementation, two pointers Solved by: 26784 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_valley_at(a: Seq<i64>, n: usize, l: int, r: int) -> bool { 0 <= l && l <= r && r < n && (forall|i: int| l <= i && i <= r ==> a[i] == a[l]) && (l == 0 || a[l - 1] > a[l]) && (r == n - 1 || a[r] < a[r + 1]) } pub open spec fn has_unique_v...
impl Solution { pub fn is_valley(n: usize, a: Vec<i64>) -> i64 { let mut count: i64 = 0; let mut i: usize = 0; while i < n { let block_start = i; while i < n && a[i] == a[block_start] { i += 1; } let block_end = i - 1; ...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_valley_at(a: Seq<i64>, n: usize, l: int, r: int) -> bool { 0 <= l && l <= r && r < n && (forall|i: int| l <= i && i <= r ==> a[i] == a[l]) && (l == 0 || a[l - 1] > a[l]) && (r == n - 1 || a[r] < a[r + 1]) } pub open spec fn has_unique_v...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn is_valley_at(a: Seq<i64>, n: usize, l: int, r: int) -> bool { 0 <= l && l <= r && r < n && (forall|i: int| l <= i && i <= r ==> a[i] == a[l]) && (l == 0 || a[l - 1] > a[l]) && (r == n - 1 || a[r] < a[r + 1]) } pub open spec fn has_unique_v...
use std::io::{self, BufRead, Write, BufWriter}; struct Solution; impl Solution { pub fn is_valley(n: usize, a: Vec<i64>) -> i64 { let mut count: i64 = 0; let mut i: usize = 0; while i < n { let block_start = i; while i < n && a[i] == a[block_start] { ...
null
codeforces/cf1760D/tests/testcases.jsonl
codeforces/cf1760D/tests/mutated_testcases.jsonl
cf1807D
codeforces
# Odd Queries Time limit: 2 seconds | Memory limit: 256 megabytes You have an array $$$a_1, a_2, \dots, a_n$$$. Answer $$$q$$$ queries of the following form: - If we change all elements in the range $$$a_l, a_{l+1}, \dots, a_r$$$ of the array to $$$k$$$, will the sum of the entire array be odd? Note that queries ...
Rating: 900 data structures, implementation Solved by: 56531 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_range(a: Seq<u32>, l: int, r: int) -> int recommends 0 <= l <= r <= a.len(), decreases r - l, { if l >= r { 0int } else { a[l] as int + sum_range(a, l + 1, r) } } impl Solution { pub fn odd_queries( a:...
impl Solution { pub fn odd_queries( a: Vec<u32>, n: usize, ls: Vec<u32>, rs: Vec<u32>, ks: Vec<u32>, q: usize, ) -> Vec<bool> { let mut prefix: Vec<i64> = Vec::with_capacity(n + 1); prefix.push(0i64); let mut s: i64 = 0; let mut i: ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_range(a: Seq<u32>, l: int, r: int) -> int recommends 0 <= l <= r <= a.len(), decreases r - l, { if l >= r { 0int } else { a[l] as int + sum_range(a, l + 1, r) } } impl Solution { pub fn odd_queries( a:...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_range(a: Seq<u32>, l: int, r: int) -> int recommends 0 <= l <= r <= a.len(), decreases r - l, { if l >= r { 0int } else { a[l] as int + sum_range(a, l + 1, r) } } pub open spec fn pref_sum(a: Seq<u32>, k: int) -> ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn odd_queries( a: Vec<u32>, n: usize, ls: Vec<u32>, rs: Vec<u32>, ks: Vec<u32>, q: usize, ) -> Vec<bool> { let mut prefix: Vec<i64> = Vec::with_capacity(n + 1); pr...
null
codeforces/cf1807D/tests/testcases.jsonl
codeforces/cf1807D/tests/mutated_testcases.jsonl
cf1829B
codeforces
# Blank Space Time limit: 1 second | Memory limit: 256 megabytes You are given a binary array $$$a$$$ of $$$n$$$ elements, a binary array is an array consisting only of $$$0$$$s and $$$1$$$s. A blank space is a segment of **consecutive** elements consisting of only $$$0$$$s. Your task is to find the length of the...
Rating: 800 implementation Solved by: 75733 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn zero_run_len_ending_at(a: Seq<i32>, i: int) -> int decreases i + 1, { if i < 0 || i >= a.len() { 0 } else if a[i] != 0 { 0 } else if i == 0 { 1 } else if a[i - 1] == 0 { zero_run_len...
impl Solution { pub fn longest_blank_space(a: &Vec<i32>) -> i32 { let n = a.len(); let mut best: i32 = 0; let mut cur: i32 = 0; let mut i: usize = 0; while i < n { if a[i] == 0 { cur = cur + 1; } else { cur = 0; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn zero_run_len_ending_at(a: Seq<i32>, i: int) -> int decreases i + 1, { if i < 0 || i >= a.len() { 0 } else if a[i] != 0 { 0 } else if i == 0 { 1 } else if a[i - 1] == 0 { zero_run_len...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn zero_run_len_ending_at(a: Seq<i32>, i: int) -> int decreases i + 1, { if i < 0 || i >= a.len() { 0 } else if a[i] != 0 { 0 } else if i == 0 { 1 } else if a[i - 1] == 0 { zero_run_len...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn longest_blank_space(a: &Vec<i32>) -> i32 { let n = a.len(); let mut best: i32 = 0; let mut cur: i32 = 0; let mut i: usize = 0; while i < n { if a[i] == 0 { cur = cur + 1; ...
null
codeforces/cf1829B/tests/testcases.jsonl
codeforces/cf1829B/tests/mutated_testcases.jsonl
cf1833C
codeforces
# Vlad Building Beautiful Array Time limit: 1 second | Memory limit: 256 megabytes Vlad was given an array $$$a$$$ of $$$n$$$ positive integers. Now he wants to build a *beautiful* array $$$b$$$ of length $$$n$$$ from it. Vlad considers an array *beautiful* if all the numbers in it are positive and have the same par...
Rating: 800 greedy, math Solved by: 27869 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn vlad_beautiful(a: Vec<u32>, n: usize) -> (result: bool) requires 1 <= n <= 200_000, a.len() == n, forall|i: int| 0 <= i < a.len() ==> 1 <= #[trigger] a[i] <= 1_000_000_000, ...
impl Solution { pub fn vlad_beautiful(a: Vec<u32>, n: usize) -> bool { let mut min_even: u64 = u64::MAX; let mut min_odd: u64 = u64::MAX; let mut min_even_idx: usize = 0; let mut min_odd_idx: usize = 0; let mut i: usize = 0; while i < n { let v = a[i] as u...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn vlad_beautiful(a: Vec<u32>, n: usize) -> (result: bool) requires 1 <= n <= 200_000, a.len() == n, forall|i: int| 0 <= i < a.len() ==> 1 <= #[trigger] a[i] <= 1_000_000_000, ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn vlad_beautiful(a: Vec<u32>, n: usize) -> (result: bool) requires 1 <= n <= 200_000, a.len() == n, forall|i: int| 0 <= i < a.len() ==> 1 <= #[trigger] a[i] <= 1_000_000_000, ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn vlad_beautiful(a: Vec<u32>, n: usize) -> bool { let mut min_even: u64 = u64::MAX; let mut min_odd: u64 = u64::MAX; let mut min_even_idx: usize = 0; let mut min_odd_idx: usize = 0; let mut i...
null
codeforces/cf1833C/tests/testcases.jsonl
codeforces/cf1833C/tests/mutated_testcases.jsonl
cf1840C
codeforces
# Ski Resort Time limit: 1 second | Memory limit: 256 megabytes Dima Vatrushin is a math teacher at school. He was sent on vacation for $$$n$$$ days for his good work. Dima has long dreamed of going to a ski resort, so he wants to allocate several **consecutive days** and go skiing. Since the vacation requires carefu...
Rating: 1000 combinatorics, math, two pointers Solved by: 45969 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn subarray_all_leq(a: Seq<i64>, q: i64, l: int, r: int) -> bool { forall|i: int| l <= i && i <= r ==> #[trigger] a[i] <= q } pub open spec fn valid_interval(n: int, k: int, q: i64, a: Seq<i64>, l: int, r: int) -> bool { 0 <= l && l <= r && r < n && ...
impl Solution { pub fn count_vacations(n: usize, k: usize, q: i64, a: Vec<i64>) -> i64 { let mut pos: usize = 0; let mut total: i64 = 0; while pos < n { if a[pos] > q { pos += 1; } else { let start = pos; while pos < n &...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn subarray_all_leq(a: Seq<i64>, q: i64, l: int, r: int) -> bool { forall|i: int| l <= i && i <= r ==> #[trigger] a[i] <= q } pub open spec fn valid_interval(n: int, k: int, q: i64, a: Seq<i64>, l: int, r: int) -> bool { 0 <= l && l <= r && r < n && ...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn subarray_all_leq(a: Seq<i64>, q: i64, l: int, r: int) -> bool { forall|i: int| l <= i && i <= r ==> #[trigger] a[i] <= q } pub open spec fn valid_interval(n: int, k: int, q: i64, a: Seq<i64>, l: int, r: int) -> bool { 0 <= l && l <= r && r < n && ...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn count_vacations(n: usize, k: usize, q: i64, a: Vec<i64>) -> i64 { let mut pos: usize = 0; let mut total: i64 = 0; while pos < n { if a[pos] > q { pos += 1; } else { ...
null
codeforces/cf1840C/tests/testcases.jsonl
codeforces/cf1840C/tests/mutated_testcases.jsonl
cf1873B
codeforces
# Good Kid Time limit: 1 second | Memory limit: 256 megabytes Slavic is preparing a present for a friend's birthday. He has an array $$$a$$$ of $$$n$$$ digits and the present will be the product of all these digits. Because Slavic is a good kid who wants to make the biggest product possible, he wants to add $$$1$$$ t...
Rating: 800 brute force, greedy, math Solved by: 61795 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_factor_at(a: Seq<i64>, bump: int, k: int) -> int recommends 0 <= k && k < a.len(), { if k == bump { a[k] as int + 1 } else { a[k] as int } } pub open spec fn spec_prefix_with_bump(a: Seq<i...
impl Solution { pub fn max_product_one_increment(a: Vec<i64>) -> i64 { let n = a.len(); let mut best: i64 = 0; let mut i: usize = 0; while i < n { let mut p: i64 = 1; let mut j: usize = 0; while j < n { if j == i { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_factor_at(a: Seq<i64>, bump: int, k: int) -> int recommends 0 <= k && k < a.len(), { if k == bump { a[k] as int + 1 } else { a[k] as int } } pub open spec fn spec_prefix_with_bump(a: Seq<i...
use vstd::arithmetic::mul::lemma_mul_upper_bound; use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_factor_at(a: Seq<i64>, bump: int, k: int) -> int recommends 0 <= k && k < a.len(), { if k == bump { a[k] as int + 1 } else { a[k] as int } ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_product_one_increment(a: Vec<i64>) -> i64 { let n = a.len(); let mut best: i64 = 0; let mut i: usize = 0; while i < n { let mut p: i64 = 1; let mut j: usize = 0; while j < n {...
null
codeforces/cf1873B/tests/testcases.jsonl
codeforces/cf1873B/tests/mutated_testcases.jsonl
cf1901A
codeforces
# Line Trip Time limit: 2 seconds | Memory limit: 256 megabytes There is a road, which can be represented as a number line. You are located in the point $$$0$$$ of the number line, and you want to travel from the point $$$0$$$ to the point $$$x$$$, and back to the point $$$0$$$. You travel by car, which spends $$$1$...
Rating: 800 greedy, math Solved by: 73228 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_i2max(a: int, b: int) -> int { if a >= b { a } else { b } } pub open spec fn spec_prefix_gaps_up(s: Seq<i64>, k: int) -> int recommends s.len() >= 2, -1 <= k <= s.len() - 2, de...
impl Solution { pub fn min_tank_liters(x: i64, a: Vec<i64>) -> i64 { let n = a.len(); let mut ans: i64 = a[0]; let mut i: usize = 0; let bound = n - 1; while i < bound { let d: i64 = a[i + 1] - a[i]; if d > ans { ans = d; } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_i2max(a: int, b: int) -> int { if a >= b { a } else { b } } pub open spec fn spec_prefix_gaps_up(s: Seq<i64>, k: int) -> int recommends s.len() >= 2, -1 <= k <= s.len() - 2, de...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_i2max(a: int, b: int) -> int { if a >= b { a } else { b } } pub open spec fn spec_prefix_gaps_up(s: Seq<i64>, k: int) -> int recommends s.len() >= 2, -1 <= k <= s.len() - 2, de...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn min_tank_liters(x: i64, a: Vec<i64>) -> i64 { let n = a.len(); let mut ans: i64 = a[0]; let mut i: usize = 0; let bound = n - 1; while i < bound { let d: i64 = a[i + 1] - a[i]; if d >...
null
codeforces/cf1901A/tests/testcases.jsonl
codeforces/cf1901A/tests/mutated_testcases.jsonl
cf1902B
codeforces
# Getting Points Time limit: 1 second | Memory limit: 256 megabytes Monocarp is a student at Berland State University. Due to recent changes in the Berland education system, Monocarp has to study only one subject — programming. The academic term consists of $$$n$$$ days, and in order not to get expelled, Monocarp ha...
1100 binary search brute force greedy 16314
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn ceil_div_pos(a: int, b: int) -> int recommends a >= 0, b > 0, { if a % b == 0 { a / b } else { a / b + 1 } } pub open spe...
impl Solution { pub fn max_rest_days(n: i64, p: i64, l: i64, t: i64) -> i64 { let tasks: i64 = (n + 6) / 7; let pairs: i64 = tasks / 2; let odd: i64 = tasks % 2; let pair_pts: i64 = l + 2 * t; let pair_total: i64 = pairs * pair_pts; let mut study_days: i64; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn ceil_div_pos(a: int, b: int) -> int recommends a >= 0, b > 0, { if a % b == 0 { a / b } else { a / b + 1 } } pub open spe...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn ceil_div_pos(a: int, b: int) -> int recommends a >= 0, b > 0, { if a % b == 0 { a / b } else { a / b + 1 } } pub open spe...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_rest_days(n: i64, p: i64, l: i64, t: i64) -> i64 { let tasks: i64 = (n + 6) / 7; let pairs: i64 = tasks / 2; let odd: i64 = tasks % 2; let pair_pts: i64 = l + 2 * t; let pair_total: i64 = pairs * pair_p...
null
codeforces/cf1902B/tests/testcases.jsonl
codeforces/cf1902B/tests/mutated_testcases.jsonl
cf1950C
codeforces
# Clock Conversion Time limit: 1 second | Memory limit: 256 megabytes Given the time in 24-hour format, output the equivalent time in 12-hour format. - 24-hour format divides the day into 24 hours from $$$00$$$ to $$$23$$$, each of which has 60 minutes from $$$00$$$ to $$$59$$$. - 12-hour format divides the day in...
Rating: 800 implementation, math Solved by: 46828 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn hour12_spec(h24: int) -> int recommends 0 <= h24 <= 23, { if h24 == 0 { 12 } else if h24 <= 11 { h24 } else if h24 == 12 { 12 } else { h24 - 12 } } impl Solution { pub fn co...
impl Solution { pub fn convert_hour(h24: u8) -> (u8, bool) { if h24 == 0 { (12, false) } else if h24 < 12 { (h24, false) } else if h24 == 12 { (12, true) } else { (h24 - 12, true) } } pub fn convert_time(h24: u8, minute...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn hour12_spec(h24: int) -> int recommends 0 <= h24 <= 23, { if h24 == 0 { 12 } else if h24 <= 11 { h24 } else if h24 == 12 { 12 } else { h24 - 12 } } impl Solution { pub fn co...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn hour12_spec(h24: int) -> int recommends 0 <= h24 <= 23, { if h24 == 0 { 12 } else if h24 <= 11 { h24 } else if h24 == 12 { 12 } else { h24 - 12 } } impl Solution { pub fn co...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn convert_hour(h24: u8) -> (u8, bool) { if h24 == 0 { (12, false) } else if h24 < 12 { (h24, false) } else if h24 == 12 { (12, true) } else { (h24 - 12...
null
codeforces/cf1950C/tests/testcases.jsonl
codeforces/cf1950C/tests/mutated_testcases.jsonl
cf1985C
codeforces
# Good Prefixes Time limit: 2 seconds | Memory limit: 256 megabytes Alex thinks some array is *good* if there exists some element that can be represented as the sum of all **other** elements (the sum of all other elements is $$$0$$$ if there are no other elements). For example, the array $$$[1,6,3,2]$$$ is good since...
Rating: 1000 greedy Solved by: 40037 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn prefix_sum(a: Seq<u64>, end: int) -> int recommends 0 <= end <= a.len(), decreases end, { if end <= 0 { 0int } else { prefix_sum(a, end - 1) + a[end - 1] as int } } pub open spec fn prefix_...
impl Solution { pub fn count_good_prefixes_fn(a: Vec<u64>) -> usize { let mut sum: u64 = 0; let mut max_val: u64 = 0; let mut count: usize = 0; let mut i: usize = 0; while i < a.len() { let ai = a[i]; sum = sum + ai; if ai > max_val { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn prefix_sum(a: Seq<u64>, end: int) -> int recommends 0 <= end <= a.len(), decreases end, { if end <= 0 { 0int } else { prefix_sum(a, end - 1) + a[end - 1] as int } } pub open spec fn prefix_...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn prefix_sum(a: Seq<u64>, end: int) -> int recommends 0 <= end <= a.len(), decreases end, { if end <= 0 { 0int } else { prefix_sum(a, end - 1) + a[end - 1] as int } } pub open spec fn prefix_...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn count_good_prefixes_fn(a: Vec<u64>) -> usize { let mut sum: u64 = 0; let mut max_val: u64 = 0; let mut count: usize = 0; let mut i: usize = 0; while i < a.len() { let ai = a[i];...
null
codeforces/cf1985C/tests/testcases.jsonl
codeforces/cf1985C/tests/mutated_testcases.jsonl
cf1989A
codeforces
# Catch the Coin Time limit: 2 seconds | Memory limit: 256 megabytes Monocarp visited a retro arcade club with arcade cabinets. There got curious about the "Catch the Coin" cabinet. The game is pretty simple. The screen represents a coordinate grid such that: - the X-axis is directed from left to right; - the Y-a...
Rating: 800 implementation Solved by: 29249 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn coin_catchable(y: int) -> bool { y >= -1 } pub fn can_catch_coin(x: i32, y: i32) -> (ok: bool) requires -50 <= x <= 50, -50 <= y <= 50, !(x == 0 && y == ...
impl Solution { pub fn can_catch_coin(x: i32, y: i32) -> bool { let _ = x; y >= -1 } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn coin_catchable(y: int) -> bool { y >= -1 } pub fn can_catch_coin(x: i32, y: i32) -> (ok: bool) requires -50 <= x <= 50, -50 <= y <= 50, !(x == 0 && y == ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn coin_catchable(y: int) -> bool { y >= -1 } pub fn can_catch_coin(x: i32, y: i32) -> (ok: bool) requires -50 <= x <= 50, -50 <= y <= 50, !(x == 0 && y == ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn can_catch_coin(x: i32, y: i32) -> bool { let _ = x; y >= -1 } } fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).unwrap(); let mut it = input.split_whitespace(); let n: usize = ...
null
codeforces/cf1989A/tests/testcases.jsonl
codeforces/cf1989A/tests/mutated_testcases.jsonl
cf1992D
codeforces
# Test of Love Time limit: 2 seconds | Memory limit: 256 megabytes ErnKor is ready to do anything for Julen, even to swim through crocodile-infested swamps. We decided to test this love. ErnKor will have to swim across a river with a width of $$$1$$$ meter and a length of $$$n$$$ meters. The river is very cold. Ther...
Rating: 1200 dp, greedy, implementation Solved by: 23973 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn dp_inf() -> i64 { 300_000i64 } pub open spec fn is_land_or_log(a: Seq<u8>, p: int) -> bool { p == 0 || p == a.len() + 1 || (1 <= p && p <= a.len() && a[p - 1] == 2u8) } pub open spec fn is_water(a: Seq<u8>, p: int) -...
impl Solution { pub fn can_cross(a: Vec<u8>, m: usize, k: i64) -> bool { let n = a.len(); let inf: i64 = 300_000; let mut dp: Vec<i64> = Vec::with_capacity(n + 2); dp.push(0); let mut p: usize = 1; while p <= n + 1 { let val = if p <= n && a[p - 1] == 1 { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn dp_inf() -> i64 { 300_000i64 } pub open spec fn is_land_or_log(a: Seq<u8>, p: int) -> bool { p == 0 || p == a.len() + 1 || (1 <= p && p <= a.len() && a[p - 1] == 2u8) } pub open spec fn is_water(a: Seq<u8>, p: int) -> bool {...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn dp_inf() -> i64 { 300_000i64 } pub open spec fn is_land_or_log(a: Seq<u8>, p: int) -> bool { p == 0 || p == a.len() + 1 || (1 <= p && p <= a.len() && a[p - 1] == 2u8) } pub open spec fn is_water(a: Seq<u8>, p: int) -> bool {...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn can_cross(a: Vec<u8>, m: usize, k: i64) -> bool { let n = a.len(); let inf: i64 = 300_000; let mut dp: Vec<i64> = Vec::with_capacity(n + 2); dp.push(0); let mut p: usize = 1; while ...
null
codeforces/cf1992D/tests/testcases.jsonl
codeforces/cf1992D/tests/mutated_testcases.jsonl
cf1A
codeforces
# Theatre Square Time limit: 1 second | Memory limit: 256 megabytes Theatre Square in the capital city of Berland has a rectangular shape with the size $n × m$ meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size $a × ...
Rating: 1000 math Solved by: 315793 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn ceil_div(n: int, a: int) -> int { (n + a - 1) / a } impl Solution { pub fn min_flagstones(n: u64, m: u64, a: u64) -> (result: u64) requires 1 <= n <= 1_000_000_000, 1 <= m <= 1_000_000_000, ...
impl Solution { pub fn min_flagstones(n: u64, m: u64, a: u64) -> u64 { let rows = (n + a - 1) / a; let cols = (m + a - 1) / a; rows * cols } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn ceil_div(n: int, a: int) -> int { (n + a - 1) / a } impl Solution { pub fn min_flagstones(n: u64, m: u64, a: u64) -> (result: u64) requires 1 <= n <= 1_000_000_000, 1 <= m <= 1_000_000_000, ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn ceil_div(n: int, a: int) -> int { (n + a - 1) / a } impl Solution { pub fn min_flagstones(n: u64, m: u64, a: u64) -> (result: u64) requires 1 <= n <= 1_000_000_000, 1 <= m <= 1_000_000_000, ...
use std::io; struct Solution; impl Solution { pub fn min_flagstones(n: u64, m: u64, a: u64) -> u64 { let rows = (n + a - 1) / a; let cols = (m + a - 1) / a; rows * cols } } fn main() { let mut line = String::new(); io::stdin().read_line(&mut line).expect("read line"); let ...
null
codeforces/cf1A/tests/testcases.jsonl
codeforces/cf1A/tests/mutated_testcases.jsonl
cf2000D
codeforces
# Right Left Wrong Time limit: 2 seconds | Memory limit: 256 megabytes Vlad found a strip of $$$n$$$ cells, numbered from left to right from $$$1$$$ to $$$n$$$. In the $$$i$$$-th cell, there is a positive integer $$$a_i$$$ and a letter $$$s_i$$$, where all $$$s_i$$$ are either '`L`' or '`R`'. Vlad invites you to try...
Rating: 1200 greedy, implementation, two pointers Solved by: 28778 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn pref_sum(a: Seq<i64>, idx: int) -> int recommends 0 <= idx <= a.len(), decreases idx, { if idx <= 0 { 0int } else { pref_sum(a, idx - 1) + a[idx - 1] as int } } pub open spec fn leftmost_l(...
impl Solution { pub fn max_score(a: Vec<i64>, s: Vec<u8>) -> i64 { let n = a.len(); let mut prefix: Vec<i64> = Vec::with_capacity(n + 1); prefix.push(0); let mut i: usize = 0; while i < n { let next = prefix[i] + a[i]; prefix.push(next); i ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn pref_sum(a: Seq<i64>, idx: int) -> int recommends 0 <= idx <= a.len(), decreases idx, { if idx <= 0 { 0int } else { pref_sum(a, idx - 1) + a[idx - 1] as int } } pub open spec fn leftmost_l(...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn pref_sum(a: Seq<i64>, idx: int) -> int recommends 0 <= idx <= a.len(), decreases idx, { if idx <= 0 { 0int } else { pref_sum(a, idx - 1) + a[idx - 1] as int } } pub open spec fn leftmost_l(...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn max_score(a: Vec<i64>, s: Vec<u8>) -> i64 { let n = a.len(); let mut prefix: Vec<i64> = Vec::with_capacity(n + 1); prefix.push(0); let mut i: usize = 0; while i < n { let next =...
null
codeforces/cf2000D/tests/testcases.jsonl
codeforces/cf2000D/tests/mutated_testcases.jsonl
cf2014D
codeforces
# Robert Hood and Mrs Hood Time limit: 2 seconds | Memory limit: 256 megabytes *Impress thy brother, yet fret not thy mother.* Robin's brother and mother are visiting, and Robin gets to choose the start day for each visitor. All days are numbered from $$$1$$$ to $$$n$$$. Visitors stay for $$$d$$$ continuous days, al...
Rating: 1400 brute force, data structures, greedy, sortings Solved by: N/A users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_overlaps_window(start: int, d: int, l: int, r: int) -> bool { start <= r && l <= start + d - 1 } pub open spec fn spec_overlap_count_prefix(start: int, d: int, left: Seq<i32>, right: Seq<i32>,...
impl Solution { pub fn overlaps_window(start: i32, d: i32, l: i32, r: i32) -> bool { (start as i64) <= (r as i64) && (l as i64) <= (start as i64) + (d as i64) - 1 } pub fn overlap_count(start: i32, d: i32, left: &Vec<i32>, right: &Vec<i32>) -> i32 { let mut cnt: i32 = 0; let...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_overlaps_window(start: int, d: int, l: int, r: int) -> bool { start <= r && l <= start + d - 1 } pub open spec fn spec_overlap_count_prefix(start: int, d: int, left: Seq<i32>, right: Seq<i32>,...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_overlaps_window(start: int, d: int, l: int, r: int) -> bool { start <= r && l <= start + d - 1 } pub open spec fn spec_overlap_count_prefix(start: int, d: int, left: Seq<i32>, right: Seq<i32>,...
use std::io::{self, Read}; struct Solution; fn next_i32<'a, I: Iterator<Item = &'a str>>(it: &mut I) -> Option<i32> { it.next()?.parse().ok() } impl Solution { pub fn overlaps_window(start: i32, d: i32, l: i32, r: i32) -> bool { (start as i64) <= (r as i64) && (l as i64) <= (start as i64) + (d as...
null
codeforces/cf2014D/tests/testcases.jsonl
codeforces/cf2014D/tests/mutated_testcases.jsonl
cf2020B
codeforces
# Brightness Begins Time limit: 1 second | Memory limit: 256 megabytes Imagine you have $$$n$$$ light bulbs numbered $$$1, 2, \ldots, n$$$. **Initially, all bulbs are on**. To *flip* the state of a bulb means to turn it off if it used to be on, and to turn it on otherwise. Next, you do the following: - for each $$$...
Rating: 1200 binary search, math Solved by: 21266 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_floor_sqrt_rec(lo: int, hi: int, n: int) -> int recommends 0 <= lo < hi, lo * lo <= n, n < hi * hi, decreases hi - lo, { if lo + 1 >= hi { ...
impl Solution { pub fn floor_sqrt_u64(x: u64) -> u64 { let mut lo = 1u64; let mut hi = 2_000_000_001u64; while lo < hi { let mid = lo + (hi - lo) / 2; if mid * mid <= x { lo = mid + 1; } else { hi = mid; } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_floor_sqrt_rec(lo: int, hi: int, n: int) -> int recommends 0 <= lo < hi, lo * lo <= n, n < hi * hi, decreases hi - lo, { if lo + 1 >= hi { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn spec_floor_sqrt_rec(lo: int, hi: int, n: int) -> int recommends 0 <= lo < hi, lo * lo <= n, n < hi * hi, decreases hi - lo, { if lo + 1 >= hi { ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn floor_sqrt_u64(x: u64) -> u64 { let mut lo = 1u64; let mut hi = 2_000_000_001u64; while lo < hi { let mid = lo + (hi - lo) / 2; if mid * mid <= x { lo = mid + 1; } else { ...
null
codeforces/cf2020B/tests/testcases.jsonl
codeforces/cf2020B/tests/mutated_testcases.jsonl
cf2044C
codeforces
# Hard Problem Time limit: 1 second | Memory limit: 256 megabytes Ball is the teacher in Paperfold University. The seats of his classroom are arranged in $$$2$$$ rows with $$$m$$$ seats each. Ball is teaching $$$a + b + c$$$ monkeys, and he wants to assign as many monkeys to a seat as possible. Ball knows that $$$a$...
Rating: 800 greedy, math Solved by: 45179 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn min_int(x: int, y: int) -> int { if x <= y { x } else { y } } impl Solution { pub fn max_monkeys(m: u64, a: u64, b: u64, c: u64) -> (result: u64) requires 1 <= m <= 100000000, 1 <= a <= 1000000...
impl Solution { pub fn max_monkeys(m: u64, a: u64, b: u64, c: u64) -> u64 { let row1: u64 = if m <= a { m } else { a }; let row2: u64 = if m <= b { m } else { b }; let remaining: u64 = 2 * m - row1 - row2; let extra: u64 = if c <= remaining { c } else { remaining }; row1 + ro...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn min_int(x: int, y: int) -> int { if x <= y { x } else { y } } impl Solution { pub fn max_monkeys(m: u64, a: u64, b: u64, c: u64) -> (result: u64) requires 1 <= m <= 100000000, 1 <= a <= 1000000...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn min_int(x: int, y: int) -> int { if x <= y { x } else { y } } impl Solution { pub fn max_monkeys(m: u64, a: u64, b: u64, c: u64) -> (result: u64) requires 1 <= m <= 100000000, 1 <= a <= 1000000...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn max_monkeys(m: u64, a: u64, b: u64, c: u64) -> u64 { let row1: u64 = if m <= a { m } else { a }; let row2: u64 = if m <= b { m } else { b }; let remaining: u64 = 2 * m - row1 - row2; let extra: u64...
null
codeforces/cf2044C/tests/testcases.jsonl
codeforces/cf2044C/tests/mutated_testcases.jsonl
cf2060D
codeforces
# Subtract Min Sort Time limit: 2 seconds | Memory limit: 256 megabytes You are given a sequence $$$a$$$ consisting of $$$n$$$ positive integers. You can perform the following operation any number of times. - Select an index $$$i$$$ ($$$1 \le i \lt n$$$), and subtract $$$\min(a_i,a_{i+1})$$$ from both $$$a_i$$$ a...
Rating: 1100 greedy Solved by: 26069 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn remaining_val(a: Seq<i64>, i: int) -> int recommends 0 <= i < a.len(), decreases i, { if i <= 0 { a[0] as int } else { let prev = Self::remain...
impl Solution { pub fn can_sort(a: Vec<i64>) -> bool { let n = a.len(); let mut cur: i64 = a[0]; let mut i: usize = 0; while i < n - 1 { let next = a[i + 1]; if cur > next { return false; } let new_cur = next - cur; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn remaining_val(a: Seq<i64>, i: int) -> int recommends 0 <= i < a.len(), decreases i, { if i <= 0 { a[0] as int } else { let prev = Self::remain...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn remaining_val(a: Seq<i64>, i: int) -> int recommends 0 <= i < a.len(), decreases i, { if i <= 0 { a[0] as int } else { let prev = Self::remain...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn can_sort(a: Vec<i64>) -> bool { let n = a.len(); let mut cur: i64 = a[0]; let mut i: usize = 0; while i < n - 1 { let next = a[i + 1]; if cur > next { return false; ...
null
codeforces/cf2060D/tests/testcases.jsonl
codeforces/cf2060D/tests/mutated_testcases.jsonl
cf2122B
codeforces
# Pile Shuffling Time limit: 1 second | Memory limit: 256 megabytes You are given $$$n$$$ binary piles, the $$$i$$$-th of which consists of $$$a_i$$$ zeros on the top and $$$b_i$$$ ones on the bottom. In one operation, you can take the **top element** of any pile and move it to any position in any pile, including th...
Rating: 1100 greedy, math Solved by: 15044 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_contrib(a: int, b: int, c: int, d: int) -> int { let a_after = if a > c { c } else { a }; let part1 = if a > c { a - c } else { 0 }; let part2 = if b > d { b - d...
impl Solution { pub fn min_pile_shuffle_operations(a: &Vec<i64>, b: &Vec<i64>, c: &Vec<i64>, d: &Vec<i64>) -> i64 { let n = a.len(); let mut ans: i64 = 0; let mut i: usize = 0; while i < n { let mut av: i64 = a[i]; let bv: i64 = b[i]; let cv: i64 =...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_contrib(a: int, b: int, c: int, d: int) -> int { let a_after = if a > c { c } else { a }; let part1 = if a > c { a - c } else { 0 }; let part2 = if b > d { b - d...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_contrib(a: int, b: int, c: int, d: int) -> int { let a_after = if a > c { c } else { a }; let part1 = if a > c { a - c } else { 0 }; let part2 = if b > d { b - d...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn min_pile_shuffle_operations(a: &Vec<i64>, b: &Vec<i64>, c: &Vec<i64>, d: &Vec<i64>) -> i64 { let n = a.len(); let mut ans: i64 = 0; let mut i: usize = 0; while i < n { let mut av: i64 = a[i]; ...
null
codeforces/cf2122B/tests/testcases.jsonl
codeforces/cf2122B/tests/mutated_testcases.jsonl
cf227B
codeforces
# Effective Approach Time limit: 2 seconds | Memory limit: 256 megabytes Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that ...
Rating: 1100 implementation Solved by: 32149 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn value_occurs(permutation: Seq<i32>, value: int) -> bool { exists|pos: int| 0 <= pos < permutation.len() && permutation[pos] == value } pub open spec fn all_values_occur(permutation: Seq<i32>) -> bool { forall|value: int| 1 <=...
impl Solution { pub fn effective_approach(permutation: Vec<i32>, queries: Vec<i32>) -> (i64, i64) { let n = permutation.len(); let mut positions = Vec::new(); let mut t = 0usize; while t <= n { positions.push(0i64); t += 1; } let mut i = 0usize...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn value_occurs(permutation: Seq<i32>, value: int) -> bool { exists|pos: int| 0 <= pos < permutation.len() && permutation[pos] == value } pub open spec fn all_values_occur(permutation: Seq<i32>) -> bool { forall|value: int| 1 <=...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn value_occurs(permutation: Seq<i32>, value: int) -> bool { exists|pos: int| 0 <= pos < permutation.len() && permutation[pos] == value } pub open spec fn all_values_occur(permutation: Seq<i32>) -> bool { forall|value: int| 1 <=...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn effective_approach(permutation: Vec<i32>, queries: Vec<i32>) -> (i64, i64) { let n = permutation.len(); let mut positions = Vec::new(); let mut t = 0usize; while t <= n { positions.push(0i64); ...
null
codeforces/cf227B/tests/testcases.jsonl
codeforces/cf227B/tests/mutated_testcases.jsonl
cf230B
codeforces
# T-primes Time limit: 2 seconds | Memory limit: 256 megabytes We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer $t$ Т-prime, if $t$ has exactly three distinct positive divisors. You are given an array of $n$ positive integers....
Rating: 1300 binary search, implementation, math, number theory Solved by: 93954 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_prime(n: int) -> bool { 2 <= n && forall|d: int| 2 <= d && d <= n / d ==> #[trigger] (n % d) != 0 } pub open spec fn is_t_prime(x: int) -> bool { exists|p: int| 2 <= p && p * p == x && is_prime(p) } impl Solution { pu...
impl Solution { fn floor_sqrt(x: u64) -> u64 { let mut lo = 1u64; let mut hi = 1_000_001u64; while lo < hi { let mid = lo + (hi - lo) / 2; if mid * mid <= x { lo = mid + 1; } else { hi = mid; } } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_prime(n: int) -> bool { 2 <= n && forall|d: int| 2 <= d && d <= n / d ==> #[trigger] (n % d) != 0 } pub open spec fn is_t_prime(x: int) -> bool { exists|p: int| 2 <= p && p * p == x && is_prime(p) } impl Solution { fn...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_prime(n: int) -> bool { 2 <= n && forall|d: int| 2 <= d && d <= n / d ==> #[trigger] (n % d) != 0 } pub open spec fn is_t_prime(x: int) -> bool { exists|p: int| 2 <= p && p * p == x && is_prime(p) } proof fn lemma_unique_...
use std::io::{self, Read}; struct Solution; impl Solution { fn floor_sqrt(x: u64) -> u64 { let mut lo = 1u64; let mut hi = 1_000_001u64; while lo < hi { let mid = lo + (hi - lo) / 2; if mid * mid <= x { lo = mid + 1; } else { ...
null
codeforces/cf230B/tests/testcases.jsonl
codeforces/cf230B/tests/mutated_testcases.jsonl
cf242B
codeforces
# Big Segment Time limit: 2 seconds | Memory limit: 256 megabytes A coordinate line has $n$ segments, the $i$-th segment starts at the position $l_i$ and ends at the position $r_i$. We will denote such a segment as $[l_i, r_i]$. You have suggested that one of the defined segments covers all others. In other words, t...
Rating: 1100 implementation, sortings Solved by: 17216 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn segment_contains(left: Seq<i32>, right: Seq<i32>, i: int, j: int) -> bool recommends left.len() == right.len(), 0 <= i < left.len(), 0 <= j < left.len(), { left[i] <= left[j] && right[j] <= right[i] } ...
impl Solution { pub fn find_covering_segment(left: Vec<i32>, right: Vec<i32>) -> i32 { let mut candidate = 0usize; let mut i = 1usize; while i < left.len() { if left[i] < left[candidate] || (left[i] == left[candidate] && right[candidate] < right[i]) { candidate = ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn segment_contains(left: Seq<i32>, right: Seq<i32>, i: int, j: int) -> bool recommends left.len() == right.len(), 0 <= i < left.len(), 0 <= j < left.len(), { left[i] <= left[j] && right[j] <= right[i] } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn segment_contains(left: Seq<i32>, right: Seq<i32>, i: int, j: int) -> bool recommends left.len() == right.len(), 0 <= i < left.len(), 0 <= j < left.len(), { left[i] <= left[j] && right[j] <= right[i] } ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn find_covering_segment(left: Vec<i32>, right: Vec<i32>) -> i32 { let mut candidate = 0usize; let mut i = 1usize; while i < left.len() { if left[i] < left[candidate] || (left[i] == left[candidate] && right[candida...
null
codeforces/cf242B/tests/testcases.jsonl
codeforces/cf242B/tests/mutated_testcases.jsonl
cf265A
codeforces
# Colorful Stones (Simplified Edition) Time limit: 2 seconds | Memory limit: 256 megabytes There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string $s$. The $i$-th (1-based) character of $s$ represents the color of the $i$-th stone. If the character is "`R`...
Rating: 800 implementation Solved by: 42604 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn final_position(s: Seq<u8>, t: Seq<u8>, k: int) -> int recommends 0 <= k <= t.len(), s.len() >= 1, decreases k, { if k <= 0 { 0int } else { let prev = final_position(s, t, k - 1); ...
impl Solution { pub fn final_pos(s: Vec<u8>, t: Vec<u8>) -> usize { let mut pos: usize = 0; let m = t.len(); let n = s.len(); let mut i: usize = 0; while i < m { if pos < n && s[pos] == t[i] { pos = pos + 1; } i = i + 1; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn final_position(s: Seq<u8>, t: Seq<u8>, k: int) -> int recommends 0 <= k <= t.len(), s.len() >= 1, decreases k, { if k <= 0 { 0int } else { let prev = final_position(s, t, k - 1); ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn final_position(s: Seq<u8>, t: Seq<u8>, k: int) -> int recommends 0 <= k <= t.len(), s.len() >= 1, decreases k, { if k <= 0 { 0int } else { let prev = final_position(s, t, k - 1); ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn final_pos(s: Vec<u8>, t: Vec<u8>) -> usize { let mut pos: usize = 0; let m = t.len(); let n = s.len(); let mut i: usize = 0; while i < m { if pos < n && s[pos] == t[i] { ...
null
codeforces/cf265A/tests/testcases.jsonl
codeforces/cf265A/tests/mutated_testcases.jsonl
cf265B
codeforces
# Roadside Trees (Simplified Edition) Time limit: 2 seconds | Memory limit: 256 megabytes Squirrel Liss loves nuts. There are $n$ trees (numbered $1$ to $n$ from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree $i$ is $h_i$. Liss wants to eat all nuts. Now Lis...
Rating: 1000 greedy, implementation Solved by: 17884 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_time(heights: Seq<i32>, i: int, cur_h: int) -> int decreases heights.len() - i, { if i >= heights.len() { 0 } else { let target = heights[i] as int; let climb = if target > cur_h { target - cur...
impl Solution { pub fn min_time(heights: Vec<i32>) -> i64 { let n = heights.len(); let mut time = 0i64; let mut current_height = 0i32; let mut i: usize = 0; while i < n { let target_height = heights[i]; let climb: i64 = if target_height > current_heigh...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_time(heights: Seq<i32>, i: int, cur_h: int) -> int decreases heights.len() - i, { if i >= heights.len() { 0 } else { let target = heights[i] as int; let climb = if target > cur_h { target - cur...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_time(heights: Seq<i32>, i: int, cur_h: int) -> int decreases heights.len() - i, { if i >= heights.len() { 0 } else { let target = heights[i] as int; let climb = if target > cur_h { target - cur...
use std::io; struct Solution; impl Solution { pub fn min_time(heights: Vec<i32>) -> i64 { let n = heights.len(); let mut time = 0i64; let mut current_height = 0i32; let mut i: usize = 0; while i < n { let target_height = heights[i]; let climb: i64 = ...
null
codeforces/cf265B/tests/testcases.jsonl
codeforces/cf265B/tests/mutated_testcases.jsonl
cf287B
codeforces
# Pipeline Time limit: 0.4 seconds | Memory limit: 256 megabytes Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly $n$ houses in Ultimate Thule, Vova wants the city to have exactly $n$ pipes, each such pipe should be connected to the water supply. A pipe can be connected to the wate...
Rating: 1700 binary search, math Solved by: 11422 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn max_additional(k: int, m: nat) -> int decreases m, { if m == 0 { 0 } else { max_additional(k, (m - 1) as nat) + (k - m as int) } } impl Solution { pub fn min_splitters(n: i128, k: i128) -> (res: i1...
impl Solution { fn max_additional_exec(k: i128, m: i128) -> i128 { let res = m * (2 * k - m - 1) / 2; res } pub fn min_splitters(n: i128, k: i128) -> i128 { if n == 1 { return 0; } let need = n - 1; let total = Self::max_additional_exec(k, k - 1);...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn max_additional(k: int, m: nat) -> int decreases m, { if m == 0 { 0 } else { max_additional(k, (m - 1) as nat) + (k - m as int) } } impl Solution { fn max_additional_exec(k: i128, m: i128) -> (res: ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn max_additional(k: int, m: nat) -> int decreases m, { if m == 0 { 0 } else { max_additional(k, (m - 1) as nat) + (k - m as int) } } proof fn lemma_max_additional_step(k: int, m: nat) requires ...
use std::io::{self, Read}; struct Solution; impl Solution { fn max_additional_exec(k: i128, m: i128) -> i128 { let res = m * (2 * k - m - 1) / 2; res } pub fn min_splitters(n: i128, k: i128) -> i128 { if n == 1 { return 0; } let need = n - 1; le...
null
codeforces/cf287B/tests/testcases.jsonl
codeforces/cf287B/tests/mutated_testcases.jsonl
cf327A
codeforces
# Flipping Game Time limit: 1 second | Memory limit: 256 megabytes Iahub got bored, so he invented a game to be played on paper. He writes $n$ integers $a_1, a_2, ..., a_n$. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices $i$ and $j$ ($1 ≤ i ≤ j ≤ n$) and fli...
Rating: 1200 brute force, dp, implementation Solved by: 49232 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_ones(nums: Seq<i32>, start: int, end: int) -> int recommends 0 <= start <= end <= nums.len(), decreases end - start, { if start >= end { 0 } else { ...
impl Solution { pub fn max_ones_after_flip(a: Vec<i32>) -> i32 { let n = a.len(); let mut result = 0; let mut i = 0; while i < n { let mut j = i; while j < n { let mut count = 0; let mut k = 0; while k < n { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_ones(nums: Seq<i32>, start: int, end: int) -> int recommends 0 <= start <= end <= nums.len(), decreases end - start, { if start >= end { 0 } else { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_ones(nums: Seq<i32>, start: int, end: int) -> int recommends 0 <= start <= end <= nums.len(), decreases end - start, { if start >= end { 0 } else { ...
use std::io; struct Solution; impl Solution { pub fn max_ones_after_flip(a: Vec<i32>) -> i32 { let n = a.len(); let mut result = 0; let mut i = 0; while i < n { let mut j = i; while j < n { let mut count = 0; let mut k = 0; ...
null
codeforces/cf327A/tests/testcases.jsonl
codeforces/cf327A/tests/mutated_testcases.jsonl
cf330A
codeforces
# Cakeminator Time limit: 1 second | Memory limit: 256 megabytes You are given a rectangular cake, represented as an $r × c$ grid. Each cell either has an evil strawberry, or is empty. For example, a $3 × 4$ cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or ...
Rating: 800 brute force, implementation Solved by: 31408 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn row_has_strawberry(grid: Seq<Vec<u8>>, i: int, c: int) -> bool { exists|j: int| 0 <= j < c && #[trigger] grid[i]@[j] == 1u8 } pub open spec fn col_has_strawberry(grid: Seq<Vec<u8>>, j: int, r: int) -> bool { exists|i: int| 0...
impl Solution { pub fn cakeminator(r: usize, c: usize, grid: Vec<Vec<u8>>) -> u64 { let mut clean_rows: u64 = 0; let mut i: usize = 0; while i < r { let mut clean: bool = true; let mut j: usize = 0; while j < c { if grid[i][j] == 1 { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn row_has_strawberry(grid: Seq<Vec<u8>>, i: int, c: int) -> bool { exists|j: int| 0 <= j < c && #[trigger] grid[i]@[j] == 1u8 } pub open spec fn col_has_strawberry(grid: Seq<Vec<u8>>, j: int, r: int) -> bool { exists|i: int| 0 ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn row_has_strawberry(grid: Seq<Vec<u8>>, i: int, c: int) -> bool { exists|j: int| 0 <= j < c && #[trigger] grid[i]@[j] == 1u8 } pub open spec fn col_has_strawberry(grid: Seq<Vec<u8>>, j: int, r: int) -> bool { exists|i: int| 0 ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn cakeminator(r: usize, c: usize, grid: Vec<Vec<u8>>) -> u64 { let mut clean_rows: u64 = 0; let mut i: usize = 0; while i < r { let mut clean: bool = true; let mut j: usize = 0; ...
null
codeforces/cf330A/tests/testcases.jsonl
codeforces/cf330A/tests/mutated_testcases.jsonl
cf339A
codeforces
# Helpful Maths Time limit: 2 seconds | Memory limit: 256 megabytes Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the...
800 implementation, sortings, strings (solved count from API)
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn count_digit(seq: Seq<u8>, v: int, end: int) -> nat recommends 0 <= end <= seq.len(), decreases end, { if end <= 0 { 0nat } else { count_digit(seq, v, end - 1) + (if seq[end - 1] as i...
impl Solution { pub fn sort_digits(nums: Vec<u8>) -> Vec<u8> { let n = nums.len(); let mut c1 = 0usize; let mut c2 = 0usize; let mut c3 = 0usize; let mut i = 0usize; while i < n { if nums[i] == 1 { c1 += 1; } else if nums[i] == ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn count_digit(seq: Seq<u8>, v: int, end: int) -> nat recommends 0 <= end <= seq.len(), decreases end, { if end <= 0 { 0nat } else { count_digit(seq, v, end - 1) + (if seq[end - 1] as i...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn count_digit(seq: Seq<u8>, v: int, end: int) -> nat recommends 0 <= end <= seq.len(), decreases end, { if end <= 0 { 0nat } else { count_digit(seq, v, end - 1) + (if seq[end - 1] as i...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn sort_digits(nums: Vec<u8>) -> Vec<u8> { let n = nums.len(); let mut c1 = 0usize; let mut c2 = 0usize; let mut c3 = 0usize; let mut i = 0usize; while i < n { if nums[i] == 1 { ...
null
codeforces/cf339A/tests/testcases.jsonl
codeforces/cf339A/tests/mutated_testcases.jsonl
cf365B
codeforces
# The Fibonacci Segment Time limit: 1 second | Memory limit: 256 megabytes You have array $a_1, a_2, ..., a_n$. Segment $[l, r]$ ($1 ≤ l ≤ r ≤ n$) is good if $a_i = a_i - 1 + a_i - 2$, for all $i$ $(l + 2 ≤ i ≤ r)$. Let's define $len([l, r]) = r - l + 1$, $len([l, r])$ is the length of the segment $[l, r]$. Segment ...
1100 implementation 15299
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn good_segment(nums: Seq<i64>, l: int, r: int) -> bool { &&& 0 <= l < r <= nums.len() &&& forall|t: int| l + 2 <= t < r ==> #[trigger] nums[t] == nums[t - 1] + nums[t - 2] } pub fn longest_fi...
impl Solution { pub fn longest_fibonacci_segment(nums: Vec<i64>) -> usize { let n = nums.len(); if n <= 2 { return n; } let mut best = 2usize; let mut cur = 2usize; let mut i = 2usize; while i < n { if nums[i] == nums[i - 1] + nums[i -...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn good_segment(nums: Seq<i64>, l: int, r: int) -> bool { &&& 0 <= l < r <= nums.len() &&& forall|t: int| l + 2 <= t < r ==> #[trigger] nums[t] == nums[t - 1] + nums[t - 2] } pub fn longest_fi...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn good_segment(nums: Seq<i64>, l: int, r: int) -> bool { &&& 0 <= l < r <= nums.len() &&& forall|t: int| l + 2 <= t < r ==> #[trigger] nums[t] == nums[t - 1] + nums[t - 2] } pub fn longest_fi...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn longest_fibonacci_segment(nums: Vec<i64>) -> usize { let n = nums.len(); if n <= 2 { return n; } let mut best = 2usize; let mut cur = 2usize; let mut i = 2usize; while i < n { ...
null
codeforces/cf365B/tests/testcases.jsonl
codeforces/cf365B/tests/mutated_testcases.jsonl
cf38A
codeforces
# Army Time limit: 2 seconds | Memory limit: 256 megabytes The Berland Armed Forces System consists of $n$ ranks that are numbered using natural numbers from $1$ to $n$, where $1$ is the lowest rank and $n$ is the highest rank. One needs exactly $d_i$ years to rise from rank $i$ to rank $i + 1$. Reaching a certain r...
Rating: 800 implementation Solved by: 26398 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_range(d: Seq<u32>, lo: int, hi: int) -> int decreases hi - lo, { if hi <= lo || lo < 0 || hi > d.len() { 0int } else { d[lo] as int + sum_range(d, lo + 1, hi) } } impl Solution { pub fn years_n...
impl Solution { pub fn years_needed(n: usize, d: Vec<u32>, a: usize, b: usize) -> u32 { let mut sum: u32 = 0; let mut i: usize = a - 1; let lo: usize = a - 1; let hi: usize = b - 1; while i < hi { sum += d[i]; i += 1; } sum } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_range(d: Seq<u32>, lo: int, hi: int) -> int decreases hi - lo, { if hi <= lo || lo < 0 || hi > d.len() { 0int } else { d[lo] as int + sum_range(d, lo + 1, hi) } } impl Solution { pub fn years_n...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_range(d: Seq<u32>, lo: int, hi: int) -> int decreases hi - lo, { if hi <= lo || lo < 0 || hi > d.len() { 0int } else { d[lo] as int + sum_range(d, lo + 1, hi) } } proof fn lemma_sum_range_bound(d: ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn years_needed(n: usize, d: Vec<u32>, a: usize, b: usize) -> u32 { let mut sum: u32 = 0; let mut i: usize = a - 1; let lo: usize = a - 1; let hi: usize = b - 1; while i < hi { sum...
null
codeforces/cf38A/tests/testcases.jsonl
codeforces/cf38A/tests/mutated_testcases.jsonl
cf432A
codeforces
# Choosing Teams Time limit: 1 second | Memory limit: 256 megabytes The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has $n$ students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each...
Rating: 800 greedy, implementation, sortings Solved by: 68893 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_eligible_threshold(k: int) -> int { 5 - k } pub open spec fn spec_is_eligible(y: int, k: int) -> bool { y <= spec_eligible_threshold(k) } pub open spec fn spec_count_eligible(s: Seq<i64>, n: int, k: int) -> int reco...
impl Solution { pub fn max_teams(n: usize, k: i32, y: Vec<i64>) -> i32 { let mut cnt: usize = 0; let mut i: usize = 0; while i < n { if y[i] <= (5 - k) as i64 { cnt = cnt + 1; } i = i + 1; } (cnt / 3) as i32 } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_eligible_threshold(k: int) -> int { 5 - k } pub open spec fn spec_is_eligible(y: int, k: int) -> bool { y <= spec_eligible_threshold(k) } pub open spec fn spec_count_eligible(s: Seq<i64>, n: int, k: int) -> int reco...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_eligible_threshold(k: int) -> int { 5 - k } pub open spec fn spec_is_eligible(y: int, k: int) -> bool { y <= spec_eligible_threshold(k) } pub open spec fn spec_count_eligible(s: Seq<i64>, n: int, k: int) -> int reco...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn max_teams(n: usize, k: i32, y: Vec<i64>) -> i32 { let mut cnt: usize = 0; let mut i: usize = 0; while i < n { if y[i] <= (5 - k) as i64 { cnt = cnt + 1; } i = i + 1; ...
null
codeforces/cf432A/tests/testcases.jsonl
codeforces/cf432A/tests/mutated_testcases.jsonl
cf437C
codeforces
# The Child and Toy Time limit: 1 second | Memory limit: 256 megabytes On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of $n$ parts and $m$ ropes. Each rope links two parts, but every pair of parts is linked by...
1400 graphs, greedy, sortings 14879
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn same_undirected_edge(a: (usize, usize), b: (usize, usize)) -> bool { (a.0 == b.0 && a.1 == b.1) || (a.0 == b.1 && a.1 == b.0) } pub open spec fn valid_edge(weights: Seq<i64>, edge: (usize, usize)) -> bool { edge.0 < weights.l...
impl Solution { pub fn min_total_energy(weights: Vec<i64>, edges: Vec<(usize, usize)>) -> i64 { let mut total = 0i64; let mut i = 0usize; while i < edges.len() { let u = edges[i].0; let v = edges[i].1; let wu = weights[u]; let wv = weights[v]; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn same_undirected_edge(a: (usize, usize), b: (usize, usize)) -> bool { (a.0 == b.0 && a.1 == b.1) || (a.0 == b.1 && a.1 == b.0) } pub open spec fn valid_edge(weights: Seq<i64>, edge: (usize, usize)) -> bool { edge.0 < weights.l...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn same_undirected_edge(a: (usize, usize), b: (usize, usize)) -> bool { (a.0 == b.0 && a.1 == b.1) || (a.0 == b.1 && a.1 == b.0) } pub open spec fn valid_edge(weights: Seq<i64>, edge: (usize, usize)) -> bool { edge.0 < weights.l...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn min_total_energy(weights: Vec<i64>, edges: Vec<(usize, usize)>) -> i64 { let mut total = 0i64; let mut i = 0usize; while i < edges.len() { let u = edges[i].0; let v = edges[i].1; let wu =...
null
codeforces/cf437C/tests/testcases.jsonl
codeforces/cf437C/tests/mutated_testcases.jsonl
cf456C
codeforces
# Boredom Time limit: 1 second | Memory limit: 256 megabytes Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence $a$ consisting of $n$ integers. The player can make several steps. In a single ste...
Rating: 1500 dp Solved by: N/A users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn freq_prefix(nums: Seq<i32>, v: int, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::freq_p...
impl Solution { pub fn max_boredom_points(nums: Vec<i32>) -> i64 { let mut cnt: Vec<u64> = Vec::new(); let mut t: usize = 0; while t < 100_001 { cnt.push(0); t = t + 1; } let mut j: usize = 0; while j < nums.len() { let v = nums[j] ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn freq_prefix(nums: Seq<i32>, v: int, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::freq_p...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn freq_prefix(nums: Seq<i32>, v: int, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::freq_p...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_boredom_points(nums: Vec<i32>) -> i64 { let mut cnt: Vec<u64> = Vec::new(); let mut t: usize = 0; while t < 100_001 { cnt.push(0); t = t + 1; } let mut j: usize = 0; while...
null
codeforces/cf456C/tests/testcases.jsonl
codeforces/cf456C/tests/mutated_testcases.jsonl
cf459B
codeforces
# Pashmak and Flowers Time limit: 1 second | Memory limit: 256 megabytes Pashmak decided to give Parmida a pair of flowers from the garden. There are $n$ flowers in the garden and the $i$-th of them has a beauty number $b_i$. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers ne...
Rating: 1300 combinatorics, implementation, sortings Solved by: 44929 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn abs_diff(a: int, b: int) -> int { if a >= b { a - b } else { b - a } } pub open spec fn is_minimum(nums: Seq<i64>, mn: int) -> bool { nums.len() > 0 && exists|i: int| 0 <= i < nums.len() && nums[i] as int == mn ...
impl Solution { pub fn max_beauty_and_pair_count(flowers: Vec<i64>) -> (i64, i64) { let mut min_val = flowers[0]; let mut max_val = flowers[0]; let mut min_count = 1i64; let mut max_count = 1i64; let mut i = 1usize; while i < flowers.len() { let x = flower...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn abs_diff(a: int, b: int) -> int { if a >= b { a - b } else { b - a } } pub open spec fn is_minimum(nums: Seq<i64>, mn: int) -> bool { nums.len() > 0 && exists|i: int| 0 <= i < nums.len() && nums[i] as int == mn ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn abs_diff(a: int, b: int) -> int { if a >= b { a - b } else { b - a } } pub open spec fn is_minimum(nums: Seq<i64>, mn: int) -> bool { nums.len() > 0 && exists|i: int| 0 <= i < nums.len() && nums[i] as int == mn ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_beauty_and_pair_count(flowers: Vec<i64>) -> (i64, i64) { let mut min_val = flowers[0]; let mut max_val = flowers[0]; let mut min_count = 1i64; let mut max_count = 1i64; let mut i = 1usize; while ...
null
codeforces/cf459B/tests/testcases.jsonl
codeforces/cf459B/tests/mutated_testcases.jsonl
cf466C
codeforces
# Number of Ways Time limit: 2 seconds | Memory limit: 256 megabytes You've got array $a[1], a[2], ..., a[n]$, consisting of $n$ integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find...
Rating: 1700 binary search, brute force, data structures, dp, two pointers Solved by: 41245 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn prefix_sum(nums: Seq<i64>, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::prefix_sum(nums...
impl Solution { pub fn count_equal_sum_splits(nums: Vec<i64>) -> u64 { let n = nums.len(); if n < 3 { return 0; } let mut total: i128 = 0; let mut idx: usize = 0; while idx < n { total = total + nums[idx] as i128; idx = idx + 1; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn prefix_sum(nums: Seq<i64>, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::prefix_sum(nums...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn prefix_sum(nums: Seq<i64>, end: int) -> int recommends 0 <= end <= nums.len(), decreases end, { if end <= 0 { 0 } else { Self::prefix_sum(nums...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn count_equal_sum_splits(nums: Vec<i64>) -> u64 { let n = nums.len(); if n < 3 { return 0; } let mut total: i128 = 0; let mut idx: usize = 0; while idx < n { total = total + nu...
null
codeforces/cf466C/tests/testcases.jsonl
codeforces/cf466C/tests/mutated_testcases.jsonl
cf469A
codeforces
# I Wanna Be the Guy Time limit: 1 second | Memory limit: 256 megabytes There is a game called "I Wanna Be the Guy", consisting of $n$ levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only $p$ levels of the game. And Little Y can pass onl...
800 implementation, math (solved count from API when available)
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn level_in_seq(seq: Seq<i32>, level: int) -> bool { exists|i: int| 0 <= i < seq.len() && #[trigger] seq[i] == level } pub open spec fn level_passable(level: int, x_levels: Seq<i32>, y_levels: Seq<i32>) -> bool { level_in_seq(x_...
impl Solution { pub fn can_be_the_guy(n: i32, x_levels: Vec<i32>, y_levels: Vec<i32>) -> bool { let mut k = 1i32; while k <= n { let x_len = x_levels.len(); let y_len = y_levels.len(); let mut found = false; let mut i = 0usize; while i < x_...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn level_in_seq(seq: Seq<i32>, level: int) -> bool { exists|i: int| 0 <= i < seq.len() && #[trigger] seq[i] == level } pub open spec fn level_passable(level: int, x_levels: Seq<i32>, y_levels: Seq<i32>) -> bool { level_in_seq(x_...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn level_in_seq(seq: Seq<i32>, level: int) -> bool { exists|i: int| 0 <= i < seq.len() && #[trigger] seq[i] == level } pub open spec fn level_passable(level: int, x_levels: Seq<i32>, y_levels: Seq<i32>) -> bool { level_in_seq(x_...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn can_be_the_guy(n: i32, x_levels: Vec<i32>, y_levels: Vec<i32>) -> bool { let mut k = 1i32; while k <= n { let x_len = x_levels.len(); let y_len = y_levels.len(); let mut found = false; ...
null
codeforces/cf469A/tests/testcases.jsonl
codeforces/cf469A/tests/mutated_testcases.jsonl
cf474D
codeforces
# Flowers Time limit: 1.5 seconds | Memory limit: 256 megabytes We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some ...
Rating: 1700 dp Solved by: 30159 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn modulus() -> int { 1_000_000_007 } pub open spec fn sum_blocks(blocks: Seq<int>) -> int decreases blocks.len(), { if blocks.len() == 0 { 0 } else { sum_blocks(blocks.drop_last()) + blocks[blocks.len() ...
impl Solution { fn add_mod(x: i32, y: i32) -> i32 { let sum = x + y; if sum >= 1_000_000_007i32 { sum - 1_000_000_007i32 } else { sum } } fn sub_mod(x: i32, y: i32) -> i32 { if x >= y { x - y } else { x + 1_000_...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn modulus() -> int { 1_000_000_007 } pub open spec fn sum_blocks(blocks: Seq<int>) -> int decreases blocks.len(), { if blocks.len() == 0 { 0 } else { sum_blocks(blocks.drop_last()) + blocks[blocks.len() ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn modulus() -> int { 1_000_000_007 } pub open spec fn sum_blocks(blocks: Seq<int>) -> int decreases blocks.len(), { if blocks.len() == 0 { 0 } else { sum_blocks(blocks.drop_last()) + blocks[blocks.len() ...
use std::io::{self, Read}; struct Solution; impl Solution { fn add_mod(x: i32, y: i32) -> i32 { let sum = x + y; if sum >= 1_000_000_007i32 { sum - 1_000_000_007i32 } else { sum } } fn sub_mod(x: i32, y: i32) -> i32 { if x >= y { ...
null
codeforces/cf474D/tests/testcases.jsonl
codeforces/cf474D/tests/mutated_testcases.jsonl
cf478C
codeforces
# Table Decorations Time limit: 1 second | Memory limit: 256 megabytes You have $r$ red, $g$ green and $b$ blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number $t$ of tables can be decorated ...
Rating: 1800 greedy Solved by: 20414 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn total_balloons(r: int, g: int, b: int) -> int { r + g + b } pub open spec fn max_color(r: int, g: int, b: int) -> int { if r >= g { if r >= b { r } else { b } } else { if g >= b { g } else { b } } } p...
impl Solution { pub fn max_decorated_tables(r: i64, g: i64, b: i64) -> i64 { let sum = r + g + b; let rg_max = if r >= g { r } else { g }; let largest = if rg_max >= b { rg_max } else { b }; let limit_by_total = sum / 3; let limit_by_dominant = sum - largest; if limit...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn total_balloons(r: int, g: int, b: int) -> int { r + g + b } pub open spec fn max_color(r: int, g: int, b: int) -> int { if r >= g { if r >= b { r } else { b } } else { if g >= b { g } else { b } } } p...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn total_balloons(r: int, g: int, b: int) -> int { r + g + b } pub open spec fn max_color(r: int, g: int, b: int) -> int { if r >= g { if r >= b { r } else { b } } else { if g >= b { g } else { b } } } p...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_decorated_tables(r: i64, g: i64, b: i64) -> i64 { let sum = r + g + b; let rg_max = if r >= g { r } else { g }; let largest = if rg_max >= b { rg_max } else { b }; let limit_by_total = sum / 3; let limit...
null
codeforces/cf478C/tests/testcases.jsonl
codeforces/cf478C/tests/mutated_testcases.jsonl
cf486A
codeforces
# Calculating Function Time limit: 1 second | Memory limit: 256 megabytes For a positive integer $n$ let's define a function $f$: $f(n) =  - 1 + 2 - 3 + .. + ( - 1)^nn$ Your task is to calculate $f(n)$ for a given integer $n$. ## Input The single line contains the positive integer $n$ ($1 ≤ n ≤ 10^15$). ## Outp...
Rating: 800 implementation, math Solved by: 153703 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn f_value(n: int) -> int decreases n, { if n <= 0 { 0int } else if n % 2 == 0 { f_value(n - 1) + n } else { f_value(n - 1) - n } } impl Solution { pub fn calculating_function(n: i64) -> (...
impl Solution { pub fn calculating_function(n: i64) -> i64 { if n % 2 == 0 { n / 2 } else { -((n + 1) / 2) } } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn f_value(n: int) -> int decreases n, { if n <= 0 { 0int } else if n % 2 == 0 { f_value(n - 1) + n } else { f_value(n - 1) - n } } impl Solution { pub fn calculating_function(n: i64) -> (...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn f_value(n: int) -> int decreases n, { if n <= 0 { 0int } else if n % 2 == 0 { f_value(n - 1) + n } else { f_value(n - 1) - n } } proof fn lemma_f_value(n: int) requires n >= 0, ...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn calculating_function(n: i64) -> i64 { if n % 2 == 0 { n / 2 } else { -((n + 1) / 2) } } } fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut inp...
null
codeforces/cf486A/tests/testcases.jsonl
codeforces/cf486A/tests/mutated_testcases.jsonl
cf507B
codeforces
# Amr and Pins Time limit: 1 second | Memory limit: 256 megabytes Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius $r$ and center in point $(x, y)$. He wants the circle center to be in new position $(x', y')$. In one step Amr can put a pin to the border of the circl...
Rating: 1400 geometry, math Solved by: 26558 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn square(x: int) -> int { x * x } pub open spec fn distance_sq(x: int, y: int, x2: int, y2: int) -> int { square(x2 - x) + square(y2 - y) } pub open spec fn jump_sq(r: int) -> int { square(2 * r) } pub open spec fn can_re...
impl Solution { pub fn min_steps_to_target(r: i128, x: i128, y: i128, x2: i128, y2: i128) -> i128 { let dx = x2 - x; let dy = y2 - y; let dist_sq = dx * dx + dy * dy; let two_r = 2 * r; let jump_sq_val = two_r * two_r; let mut ans = 0i128; while ans < 200000 &...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn square(x: int) -> int { x * x } pub open spec fn distance_sq(x: int, y: int, x2: int, y2: int) -> int { square(x2 - x) + square(y2 - y) } pub open spec fn jump_sq(r: int) -> int { square(2 * r) } pub open spec fn can_re...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn square(x: int) -> int { x * x } pub open spec fn distance_sq(x: int, y: int, x2: int, y2: int) -> int { square(x2 - x) + square(y2 - y) } pub open spec fn jump_sq(r: int) -> int { square(2 * r) } pub open spec fn can_re...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn min_steps_to_target(r: i128, x: i128, y: i128, x2: i128, y2: i128) -> i128 { let dx = x2 - x; let dy = y2 - y; let dist_sq = dx * dx + dy * dy; let two_r = 2 * r; let jump_sq_val = two_r * two_r; let...
null
codeforces/cf507B/tests/testcases.jsonl
codeforces/cf507B/tests/mutated_testcases.jsonl
cf509A
codeforces
# Maximum in Table Time limit: 2 seconds | Memory limit: 256 megabytes An $n × n$ table $a$ is defined as follows: - The first row and the first column contain ones, that is: $a_i, 1 = a_1, i = 1$ for all $i = 1, 2, ..., n$. - Each of the remaining numbers in the table is equal to the sum of the number above it and...
Rating: 800 brute force, implementation Solved by: 44053 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn table_value(n: int, i: int, j: int) -> int decreases i + j, { if i < 0 || j < 0 || i >= n || j >= n { 0int } else if i == 0 || j == 0 { 1int } else { table_value(n, i - 1, j) + table_value(n, i,...
impl Solution { pub fn max_in_table(n: u32) -> u32 { let nu: usize = n as usize; let mut row: Vec<u32> = Vec::new(); let mut k: usize = 0; while k < nu { row.push(1u32); k = k + 1; } let mut i: usize = 1; while i < nu { let ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn table_value(n: int, i: int, j: int) -> int decreases i + j, { if i < 0 || j < 0 || i >= n || j >= n { 0int } else if i == 0 || j == 0 { 1int } else { table_value(n, i - 1, j) + table_value(n, i,...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn table_value(n: int, i: int, j: int) -> int decreases i + j, { if i < 0 || j < 0 || i >= n || j >= n { 0int } else if i == 0 || j == 0 { 1int } else { table_value(n, i - 1, j) + table_value(n, i,...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn max_in_table(n: u32) -> u32 { let nu: usize = n as usize; let mut row: Vec<u32> = Vec::new(); let mut k: usize = 0; while k < nu { row.push(1u32); k = k + 1; } ...
null
codeforces/cf509A/tests/testcases.jsonl
codeforces/cf509A/tests/mutated_testcases.jsonl
cf519B
codeforces
# A and B and Compilation Errors Time limit: 2 seconds | Memory limit: 256 megabytes *A and B are preparing themselves for programming contests.* B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed $n$ compilation error...
Rating: 1100 data structures, implementation, sortings Solved by: 43400 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn all_errors_valid(s: Seq<i64>) -> bool { forall|i: int| 0 <= i < s.len() ==> 1 <= #[trigger] s[i] <= 1_000_000_000 } pub open spec fn count_value(s: Seq<i64>, value: i64) -> int decreases s.len(), { if s.len() == 0 { ...
impl Solution { pub fn find_compilation_errors(first: Vec<i64>, second: Vec<i64>, third: Vec<i64>) -> (i64, i64) { let mut sum_first: i64 = 0; let mut i: usize = 0; while i < first.len() { sum_first = sum_first + first[i]; i = i + 1; } let mut sum_sec...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn all_errors_valid(s: Seq<i64>) -> bool { forall|i: int| 0 <= i < s.len() ==> 1 <= #[trigger] s[i] <= 1_000_000_000 } pub open spec fn count_value(s: Seq<i64>, value: i64) -> int decreases s.len(), { if s.len() == 0 { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn all_errors_valid(s: Seq<i64>) -> bool { forall|i: int| 0 <= i < s.len() ==> 1 <= #[trigger] s[i] <= 1_000_000_000 } pub open spec fn count_value(s: Seq<i64>, value: i64) -> int decreases s.len(), { if s.len() == 0 { ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn find_compilation_errors(first: Vec<i64>, second: Vec<i64>, third: Vec<i64>) -> (i64, i64) { let mut sum_first: i64 = 0; let mut i: usize = 0; while i < first.len() { sum_first = sum_first + first[i]; ...
null
codeforces/cf519B/tests/testcases.jsonl
codeforces/cf519B/tests/mutated_testcases.jsonl
cf519C
codeforces
# A and B and Team Training Time limit: 1 second | Memory limit: 256 megabytes *A and B are preparing themselves for programming contests.* An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefo...
Rating: 1300 greedy, implementation, math, number theory Solved by: 20642 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn feasible_team_count(n: int, m: int, t: int) -> bool { 0 <= t <= n && 0 <= t <= m && t <= (n + m) / 3 } impl Solution { pub fn max_training_teams(n: i64, m: i64) -> (result: i64) requires 0 <= n <= 500000, ...
impl Solution { pub fn max_training_teams(n: i64, m: i64) -> i64 { let mut ans = if n < m { n } else { m }; let by_total = (n + m) / 3; if by_total < ans { ans = by_total; } ans } }
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn feasible_team_count(n: int, m: int, t: int) -> bool { 0 <= t <= n && 0 <= t <= m && t <= (n + m) / 3 } impl Solution { pub fn max_training_teams(n: i64, m: i64) -> (result: i64) requires 0 <= n <= 500000, ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn feasible_team_count(n: int, m: int, t: int) -> bool { 0 <= t <= n && 0 <= t <= m && t <= (n + m) / 3 } impl Solution { pub fn max_training_teams(n: i64, m: i64) -> (result: i64) requires 0 <= n <= 500000, ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_training_teams(n: i64, m: i64) -> i64 { let mut ans = if n < m { n } else { m }; let by_total = (n + m) / 3; if by_total < ans { ans = by_total; } ans } } fn main() { let mut input =...
null
codeforces/cf519C/tests/testcases.jsonl
codeforces/cf519C/tests/mutated_testcases.jsonl
cf534C
codeforces
# Polycarpus' Dice Time limit: 1 second | Memory limit: 256 megabytes Polycarp has $n$ dice $d_1, d_2, ..., d_n$. The $i$-th dice shows numbers from $1$ to $d_i$. Polycarp rolled all the dice and the sum of numbers they showed is $A$. Agrippina didn't see which dice showed what number, she knows only the sum $A$ and ...
Rating: 1600 math Solved by: 5250 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_maxima(maxima: Seq<i64>, end: int) -> int recommends 0 <= end <= maxima.len(), decreases end, { if end <= 0 { 0 } else { sum_maxima(maxima, end - 1) + maxima[end - 1] as int } } pub open spec f...
impl Solution { pub fn impossible_face_counts(total: i64, maxima: Vec<i64>) -> Vec<i64> { let n = maxima.len(); let mut sum_all = 0i64; let mut i = 0usize; while i < n { sum_all += maxima[i]; i += 1; } let mut res = Vec::new(); i = 0; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_maxima(maxima: Seq<i64>, end: int) -> int recommends 0 <= end <= maxima.len(), decreases end, { if end <= 0 { 0 } else { sum_maxima(maxima, end - 1) + maxima[end - 1] as int } } pub open spec f...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_maxima(maxima: Seq<i64>, end: int) -> int recommends 0 <= end <= maxima.len(), decreases end, { if end <= 0 { 0 } else { sum_maxima(maxima, end - 1) + maxima[end - 1] as int } } pub open spec f...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn impossible_face_counts(total: i64, maxima: Vec<i64>) -> Vec<i64> { let n = maxima.len(); let mut sum_all = 0i64; let mut i = 0usize; while i < n { sum_all += maxima[i]; i += 1; } ...
null
codeforces/cf534C/tests/testcases.jsonl
codeforces/cf534C/tests/mutated_testcases.jsonl
cf545C
codeforces
# Woodcutters Time limit: 1 second | Memory limit: 256 megabytes Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are $n$ trees loc...
Rating: 1500 dp, greedy Solved by: 32465 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn x_at(x: Seq<i64>, j: int) -> int { x[j] as int } pub open spec fn middle_felled(x: Seq<i64>, h: Seq<i64>, i: int, last: int) -> int recommends x.len() == h.len(), 1 ...
impl Solution { pub fn max_felled_trees(x: Vec<i64>, h: Vec<i64>) -> i64 { let n = x.len(); if n == 1 { return 1i64; } let mut ans: i64 = 2; let mut last: i64 = x[0]; let mut i: usize = 1; while i < n - 1 { let xi = x[i]; le...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn x_at(x: Seq<i64>, j: int) -> int { x[j] as int } pub open spec fn middle_felled(x: Seq<i64>, h: Seq<i64>, i: int, last: int) -> int recommends x.len() == h.len(), 1 ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn x_at(x: Seq<i64>, j: int) -> int { x[j] as int } pub open spec fn middle_felled(x: Seq<i64>, h: Seq<i64>, i: int, last: int) -> int recommends x.len() == h.len(), 1 ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_felled_trees(x: Vec<i64>, h: Vec<i64>) -> i64 { let n = x.len(); if n == 1 { return 1i64; } let mut ans: i64 = 2; let mut last: i64 = x[0]; let mut i: usize = 1; while i < n -...
null
codeforces/cf545C/tests/testcases.jsonl
codeforces/cf545C/tests/mutated_testcases.jsonl
cf546D
codeforces
# Soldier and Number Game Time limit: 3 seconds | Memory limit: 256 megabytes Two soldiers are playing a game. At the beginning first of them chooses a positive integer $n$ and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positi...
Rating: 1700 constructive algorithms, dp, math, number theory Solved by: 13612 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn divides(n: int, d: int) -> bool { 1 <= d && n % d == 0 } pub open spec fn has_factor_below(n: int, bound: int) -> bool recommends 2 <= bound, { exists|d: int| 2 <= d < bound && #[trigger] divides(n, d) } pub open...
impl Solution { pub fn max_scores_for_games(queries: Vec<(i32, i32)>) -> Vec<u64> { let mut spf: Vec<usize> = Vec::new(); let mut i: usize = 0; while i <= 5_000_000usize { spf.push(0usize); i = i + 1; } i = 2usize; while i <= 5_000_000usize { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn divides(n: int, d: int) -> bool { 1 <= d && n % d == 0 } pub open spec fn has_factor_below(n: int, bound: int) -> bool recommends 2 <= bound, { exists|d: int| 2 <= d < bound && #[trigger] divides(n, d) } pub open...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn divides(n: int, d: int) -> bool { 1 <= d && n % d == 0 } pub open spec fn has_factor_below(n: int, bound: int) -> bool recommends 2 <= bound, { exists|d: int| 2 <= d < bound && #[trigger] divides(n, d) } pub open...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn max_scores_for_games(queries: Vec<(i32, i32)>) -> Vec<u64> { let mut spf: Vec<usize> = Vec::new(); let mut i: usize = 0; while i <= 5_000_000usize { spf.push(0usize); i = i + 1; } i ...
null
codeforces/cf546D/tests/testcases.jsonl
codeforces/cf546D/tests/mutated_testcases.jsonl
cf580A
codeforces
# Kefa and First Steps Time limit: 2 seconds | Memory limit: 256 megabytes Kefa decided to make some money doing business on the Internet for exactly $n$ days. He knows that on the $i$-th day ($1 ≤ i ≤ n$) he makes $a_i$ money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing ...
Rating: 900 brute force, dp, implementation Solved by: 103283 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_nd_contiguous(seq: Seq<i64>, l: int, r: int) -> bool { &&& 0 <= l <= r < seq.len() &&& forall|k: int| l <= k < r ==> #[trigger] seq[k] <= seq[k + 1] } impl Solution { pub fn longest_non_decreasing_run(a: Vec<i64>) -> (...
impl Solution { pub fn longest_non_decreasing_run(a: Vec<i64>) -> usize { let n = a.len(); let mut best = 1usize; let mut cur = 1usize; let mut i = 1usize; while i < n { if a[i] >= a[i - 1] { cur = cur + 1; } else { cur ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_nd_contiguous(seq: Seq<i64>, l: int, r: int) -> bool { &&& 0 <= l <= r < seq.len() &&& forall|k: int| l <= k < r ==> #[trigger] seq[k] <= seq[k + 1] } impl Solution { pub fn longest_non_decreasing_run(a: Vec<i64>) -> (...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_nd_contiguous(seq: Seq<i64>, l: int, r: int) -> bool { &&& 0 <= l <= r < seq.len() &&& forall|k: int| l <= k < r ==> #[trigger] seq[k] <= seq[k + 1] } pub open spec fn run_len_ending_at(seq: Seq<i64>, i: int) -> int de...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn longest_non_decreasing_run(a: Vec<i64>) -> usize { let n = a.len(); let mut best = 1usize; let mut cur = 1usize; let mut i = 1usize; while i < n { if a[i] >= a[i - 1] { cur = c...
null
codeforces/cf580A/tests/testcases.jsonl
codeforces/cf580A/tests/mutated_testcases.jsonl
cf688A
codeforces
# Opponents Time limit: 1 second | Memory limit: 256 megabytes Arya has $n$ opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day ...
Rating: 800 implementation Solved by: 14736 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn all_opponents_present(row: Seq<u8>) -> bool { forall|j: int| 0 <= j && j < row.len() ==> #[trigger] row[j] == 49u8 } pub open spec fn arya_beats(row: Seq<u8>) -> bool { !all_opponents_present(row) } pub open spec fn win_interval(days: Seq<Vec<u8>...
impl Solution { fn is_win_row(row: &Vec<u8>) -> bool { let n = row.len(); let mut j = 0usize; let mut found = false; while j < n { if row[j] == 48u8 { found = true; } j = j + 1; } found } pub fn max_consecut...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn all_opponents_present(row: Seq<u8>) -> bool { forall|j: int| 0 <= j && j < row.len() ==> #[trigger] row[j] == 49u8 } pub open spec fn arya_beats(row: Seq<u8>) -> bool { !all_opponents_present(row) } pub open spec fn win_interval(days: Seq<Vec<u8>...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn all_opponents_present(row: Seq<u8>) -> bool { forall|j: int| 0 <= j && j < row.len() ==> #[trigger] row[j] == 49u8 } pub open spec fn arya_beats(row: Seq<u8>) -> bool { !all_opponents_present(row) } pub open spec fn win_interval(days: Seq<Vec<u8>...
use std::io::{self, Read}; struct Solution; impl Solution { fn is_win_row(row: &Vec<u8>) -> bool { let n = row.len(); let mut j = 0usize; let mut found = false; while j < n { if row[j] == 48u8 { found = true; } j = j + 1; ...
null
codeforces/cf688A/tests/testcases.jsonl
codeforces/cf688A/tests/mutated_testcases.jsonl
cf69A
codeforces
# Young Physicist Time limit: 2 seconds | Memory limit: 256 megabytes A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to...
1200 math, implementation 100000+
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_dim(vec: Seq<i32>, n: int, d: int) -> int recommends 0 <= d < 3, 0 <= n, 3 * n <= vec.len(), decreases n, { if n <= 0 { 0 } else { vec[3 * (n - 1) + d] as int + sum_dim(vec, ...
impl Solution { pub fn is_equilibrium(vec: Vec<i32>, n: usize) -> bool { let mut sum_x = 0i64; let mut sum_y = 0i64; let mut sum_z = 0i64; let mut i = 0usize; while i < n { sum_x += vec[3 * i] as i64; sum_y += vec[3 * i + 1] as i64; sum_z +...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_dim(vec: Seq<i32>, n: int, d: int) -> int recommends 0 <= d < 3, 0 <= n, 3 * n <= vec.len(), decreases n, { if n <= 0 { 0 } else { vec[3 * (n - 1) + d] as int + sum_dim(vec, ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn sum_dim(vec: Seq<i32>, n: int, d: int) -> int recommends 0 <= d < 3, 0 <= n, 3 * n <= vec.len(), decreases n, { if n <= 0 { 0 } else { vec[3 * (n - 1) + d] as int + sum_dim(vec, ...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn is_equilibrium(vec: Vec<i32>, n: usize) -> bool { let mut sum_x = 0i64; let mut sum_y = 0i64; let mut sum_z = 0i64; let mut i = 0usize; while i < n { sum_x += vec[3 * i] as i64; su...
null
codeforces/cf69A/tests/testcases.jsonl
codeforces/cf69A/tests/mutated_testcases.jsonl
cf6A
codeforces
# Triangle Time limit: 2 seconds | Memory limit: 64 megabytes Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of differen...
Rating: 900 brute force, geometry Solved by: 22540 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn triangle_inequality(a: int, b: int, c: int) -> bool { a + b > c && a + c > b && b + c > a } pub open spec fn segment_inequality(a: int, b: int, c: int) -> bool { a + b == c || a + c == b || b + c == a } pub open spec fn vali...
impl Solution { pub fn has_triangle(sticks: Vec<i32>) -> bool { let mut found = false; let mut i = 0usize; while i < 4 { let mut j = 0usize; while j < 4 { let mut k = 0usize; while k < 4 { if i != j && i != k && j !=...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn triangle_inequality(a: int, b: int, c: int) -> bool { a + b > c && a + c > b && b + c > a } pub open spec fn segment_inequality(a: int, b: int, c: int) -> bool { a + b == c || a + c == b || b + c == a } pub open spec fn vali...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn triangle_inequality(a: int, b: int, c: int) -> bool { a + b > c && a + c > b && b + c > a } pub open spec fn segment_inequality(a: int, b: int, c: int) -> bool { a + b == c || a + c == b || b + c == a } pub open spec fn vali...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn has_triangle(sticks: Vec<i32>) -> bool { let mut found = false; let mut i = 0usize; while i < 4 { let mut j = 0usize; while j < 4 { let mut k = 0usize; while k < 4 ...
null
codeforces/cf6A/tests/testcases.jsonl
codeforces/cf6A/tests/mutated_testcases.jsonl
cf716A
codeforces
# Crazy Computer Time limit: 2 seconds | Memory limit: 256 megabytes ZS the Coder is coding on a crazy computer. If you don't type in a word for a $c$ consecutive seconds, everything you typed disappear! More formally, if you typed a word at second $a$ and then the next word at second $b$, then if $b - a ≤ c$, just...
Rating: 800 implementation Solved by: 23964 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_screen( t: Seq<i64>, n: int, c: int, i: int, cnt: int, ) -> int decreases n - i, { if i >= n { cnt } else { let gap = t[i] - t[i - 1]; let new_cnt = if gap <= c { cnt + 1 } else { 1 }; ...
impl Solution { pub fn remaining_words(n: usize, c: i64, t: Vec<i64>) -> usize { let mut cnt = 1usize; let mut i = 1usize; while i < n { if t[i] - t[i - 1] <= c { cnt = cnt + 1; } else { cnt = 1; } i = i + 1; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_screen( t: Seq<i64>, n: int, c: int, i: int, cnt: int, ) -> int decreases n - i, { if i >= n { cnt } else { let gap = t[i] - t[i - 1]; let new_cnt = if gap <= c { cnt + 1 } else { 1 }; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_screen( t: Seq<i64>, n: int, c: int, i: int, cnt: int, ) -> int decreases n - i, { if i >= n { cnt } else { let gap = t[i] - t[i - 1]; let new_cnt = if gap <= c { cnt + 1 } else { 1 }; ...
use std::io::{self, Read}; struct Solution; impl Solution { pub fn remaining_words(n: usize, c: i64, t: Vec<i64>) -> usize { let mut cnt = 1usize; let mut i = 1usize; while i < n { if t[i] - t[i - 1] <= c { cnt = cnt + 1; } else { cnt...
null
codeforces/cf716A/tests/testcases.jsonl
codeforces/cf716A/tests/mutated_testcases.jsonl
cf758A
codeforces
# Holiday Of Equality Time limit: 1 second | Memory limit: 256 megabytes In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are $n$ citizens, the welfare of each of them ...
Rating: 800 implementation, math Solved by: 74431 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_max_of(a: Seq<i32>, n: int) -> int recommends 1 <= n <= a.len(), decreases n, { if n <= 1 { a[0] as int } else { let m = spec_max_of(a, n - 1); if (a[n - 1] as int) > m { a[n - ...
impl Solution { pub fn holiday_equality_burles(n: usize, a: Vec<i32>) -> i32 { let mut maxv = a[0]; let mut i = 1usize; while i < n { if a[i] > maxv { maxv = a[i]; } i += 1; } let mut sum = 0i32; let mut j = 0usize; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_max_of(a: Seq<i32>, n: int) -> int recommends 1 <= n <= a.len(), decreases n, { if n <= 1 { a[0] as int } else { let m = spec_max_of(a, n - 1); if (a[n - 1] as int) > m { a[n - ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn spec_max_of(a: Seq<i32>, n: int) -> int recommends 1 <= n <= a.len(), decreases n, { if n <= 1 { a[0] as int } else { let m = spec_max_of(a, n - 1); if (a[n - 1] as int) > m { a[n - ...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn holiday_equality_burles(n: usize, a: Vec<i32>) -> i32 { let mut maxv = a[0]; let mut i = 1usize; while i < n { if a[i] > maxv { maxv = a[i]; } i += 1; } ...
null
codeforces/cf758A/tests/testcases.jsonl
codeforces/cf758A/tests/mutated_testcases.jsonl
cf80A
codeforces
# Panoramix's Prediction Time limit: 2 seconds | Memory limit: 256 megabytes *A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers $2*, 7$, $3$ are prime, and $1$, $6$, $4$ are not. *The next prime number after $x* is the **smallest** prime number greater than x$. ...
Rating: 800 brute force Solved by: 66159 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn divides(d: int, n: int) -> bool { d > 0 && n > 0 && n % d == 0 } pub open spec fn is_prime(n: int) -> bool { n >= 2 && (forall|d: int| 2 <= d < n ==> !divides(d, n)) } impl Solution { pub fn is_next_prime(n: u32, m: u32)...
impl Solution { pub fn is_next_prime(n: u32, m: u32) -> bool { let mut x: u32 = n + 1; while x <= m { let mut prime: bool = true; let mut d: u32 = 2; while d < x { if x % d == 0 { prime = false; } ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn divides(d: int, n: int) -> bool { d > 0 && n > 0 && n % d == 0 } pub open spec fn is_prime(n: int) -> bool { n >= 2 && (forall|d: int| 2 <= d < n ==> !divides(d, n)) } impl Solution { pub fn is_next_prime(n: u32, m: u32)...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn divides(d: int, n: int) -> bool { d > 0 && n > 0 && n % d == 0 } pub open spec fn is_prime(n: int) -> bool { n >= 2 && (forall|d: int| 2 <= d < n ==> !divides(d, n)) } impl Solution { pub fn is_next_prime(n: u32, m: u32)...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn is_next_prime(n: u32, m: u32) -> bool { let mut x: u32 = n + 1; while x <= m { let mut prime: bool = true; let mut d: u32 = 2; while d < x { if x % d == 0 { ...
null
codeforces/cf80A/tests/testcases.jsonl
codeforces/cf80A/tests/mutated_testcases.jsonl
cf92A
codeforces
# Chips Time limit: 2 seconds | Memory limit: 256 megabytes There are $n$ walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number $2$ sits to the left of the walrus number $1$, the walrus number $3$ sits to the left of the walrus number $2$, ..., the walrus number $1$ sits to ...
Rating: 800 implementation, math Solved by: 21504 users
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn round_sum(n: int) -> int { n * (n + 1) / 2 } pub open spec fn after_full_rounds(n: int, m: int) -> int { if round_sum(n) > 0 { m % round_sum(n) } else { m } } pub open spec fn final_remainder(n: int, rem: int, walrus: int) -...
impl Solution { pub fn presenter_chips(n: u32, m: u32) -> u32 { let r_sum: u32 = n * (n + 1) / 2; let mut remaining: u32 = m % r_sum; let mut walrus: u32 = 1; while walrus <= n && remaining >= walrus { remaining = remaining - walrus; walrus = walrus + 1; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn round_sum(n: int) -> int { n * (n + 1) / 2 } pub open spec fn after_full_rounds(n: int, m: int) -> int { if round_sum(n) > 0 { m % round_sum(n) } else { m } } pub open spec fn final_remainder(n: int, rem: int, walrus: int) -> in...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn round_sum(n: int) -> int { n * (n + 1) / 2 } pub open spec fn after_full_rounds(n: int, m: int) -> int { if round_sum(n) > 0 { m % round_sum(n) } else { m } } pub open spec fn final_remainder(n: int, rem: int, walrus: int) -> in...
use std::io::{self, Read, Write, BufWriter}; struct Solution; impl Solution { pub fn presenter_chips(n: u32, m: u32) -> u32 { let r_sum: u32 = n * (n + 1) / 2; let mut remaining: u32 = m % r_sum; let mut walrus: u32 = 1; while walrus <= n && remaining >= walrus { remain...
null
codeforces/cf92A/tests/testcases.jsonl
codeforces/cf92A/tests/mutated_testcases.jsonl
cf935B
codeforces
# Fafa and the Gates Time limit: 2 seconds | Memory limit: 256 megabytes Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by th...
Rating: 900 implementation Solved by: 12339 users
use vstd::prelude::*; fn main() {} verus! { pub open spec fn x_pos(s: Seq<i32>, k: int) -> int decreases k { if k <= 0 { 0int } else { x_pos(s, k - 1) + if s[k - 1] == 1 { 1int } else { 0int } } } pub open spec fn y_pos(s: Seq<i32>, k: int) -> int decreases k { if k <= 0 { 0int } else { y_po...
impl Solution { pub fn fafa_and_gates(n: usize, s: Vec<i32>) -> i32 { let mut x = 0; let mut y = 0; let mut coins = 0; let mut i = 0; while i < n { let nxt = s[i]; if i > 0 && x == y && s[i - 1] == nxt { coins += 1; } ...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn x_pos(s: Seq<i32>, k: int) -> int decreases k { if k <= 0 { 0int } else { x_pos(s, k - 1) + if s[k - 1] == 1 { 1int } else { 0int } } } pub open spec fn y_pos(s: Seq<i32>, k: int) -> int decreases k { if k <= 0 { 0int } else { y_po...
use vstd::prelude::*; fn main() {} verus! { pub open spec fn x_pos(s: Seq<i32>, k: int) -> int decreases k { if k <= 0 { 0int } else { x_pos(s, k - 1) + if s[k - 1] == 1 { 1int } else { 0int } } } pub open spec fn y_pos(s: Seq<i32>, k: int) -> int decreases k { if k <= 0 { 0int } else { y_po...
use std::io::{self, BufRead}; struct Solution; impl Solution { pub fn fafa_and_gates(n: usize, s: Vec<i32>) -> i32 { let mut x = 0; let mut y = 0; let mut coins = 0; let mut i = 0; while i < n { let nxt = s[i]; if i > 0 && x == y && s[i - 1] == nxt ...
null
codeforces/cf935B/tests/testcases.jsonl
codeforces/cf935B/tests/mutated_testcases.jsonl
lc1004
leetcode
# Max Consecutive Ones III Given a binary array `nums` and an integer `k`, return the maximum number of consecutive `1`'s in the array if you can flip at most `k` `0`'s. ## Example 1: > **Input:** nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2 > **Output:** 6 > **Explanation:** The underlined subarray `[1,1,1,0,0,1,1,1,1,1,1...
Medium Array, Binary Search, Sliding Window, Prefix Sum Acceptance rate: 67.3%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_zeros(s: Seq<i32>, l: int, r: int) -> int recommends 0 <= l <= r <= s.len(), decreases r - l, { if l >= r { 0 } else { (if s[l] == 0 { 1...
impl Solution { pub fn longest_ones(nums: Vec<i32>, k: i32) -> i32 { let n = nums.len(); let mut left: usize = 0; let mut zeros: i32 = 0; let mut result: i32 = 0; let mut right: usize = 0; while right < n { if nums[right] == 0 { zeros = ze...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_zeros(s: Seq<i32>, l: int, r: int) -> int recommends 0 <= l <= r <= s.len(), decreases r - l, { if l >= r { 0 } else { (if s[l] == 0 { 1...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_zeros(s: Seq<i32>, l: int, r: int) -> int recommends 0 <= l <= r <= s.len(), decreases r - l, { if l >= r { 0 } else { (if s[l] == 0 { 1...
null
null
leetcode/lc1004/tests/testcases.jsonl
leetcode/lc1004/tests/mutated_testcases.jsonl
lc1035
leetcode
# Uncrossed Lines You are given two integer arrays `nums1` and `nums2`. We write the integers of `nums1` and `nums2` (in the order they are given) on two separate horizontal lines. We may draw connecting lines: a straight line connecting two numbers `nums1[i]` and `nums2[j]` such that: - `nums1[i] == nums2[j]`, and ...
Medium Array, Dynamic Programming Acceptance rate: 65.1%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_strictly_sorted(s: Seq<int>) -> bool { forall |k: int, l: int| 0 <= k < l < s.len() ==> s[k] < s[l] } pub open spec fn all_in_range(s: Seq<int>, hi: int) -> bool { forall |k: int| 0 <= k < s.len() ==> 0 <= #[trigger] s[k] ...
impl Solution { pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 { let m = nums1.len(); let n = nums2.len(); let mut dp: Vec<i32> = Vec::new(); let mut k: usize = 0; while k <= n { dp.push(0); k = k + 1; } let mut i: ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_strictly_sorted(s: Seq<int>) -> bool { forall |k: int, l: int| 0 <= k < l < s.len() ==> s[k] < s[l] } pub open spec fn all_in_range(s: Seq<int>, hi: int) -> bool { forall |k: int| 0 <= k < s.len() ==> 0 <= #[trigger] s[k] ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_strictly_sorted(s: Seq<int>) -> bool { forall |k: int, l: int| 0 <= k < l < s.len() ==> s[k] < s[l] } pub open spec fn all_in_range(s: Seq<int>, hi: int) -> bool { forall |k: int| 0 <= k < s.len() ==> 0 <= #[trigger] s[k...
null
null
leetcode/lc1035/tests/testcases.jsonl
leetcode/lc1035/tests/mutated_testcases.jsonl
lc1039
leetcode
# Minimum Score Triangulation of Polygon You have a convex `n`-sided polygon where each vertex has an integer value. You are given an integer array `values` where `values[i]` is the value of the `i`th vertex in clockwise order. Polygon triangulation is a process where you divide a polygon into a set of triangles and ...
Medium Array, Dynamic Programming Acceptance rate: 67.4%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub enum SplitTree { Leaf, Node(int, Box<SplitTree>, Box<SplitTree>), } pub open spec fn split_tree_valid(tree: SplitTree, i: int, j: int) -> bool decreases tree, { match tree { SplitTree::Leaf => j - i < 2, Spli...
impl Solution { fn triple_product(a: i32, b: i32, c: i32) -> i32 { let ab = a * b; ab * c } pub fn min_score_triangulation(values: Vec<i32>) -> i32 { let n = values.len(); let nn = n * n; let mut dp: Vec<i32> = Vec::new(); let mut idx = 0usize; while ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub enum SplitTree { Leaf, Node(int, Box<SplitTree>, Box<SplitTree>), } pub open spec fn split_tree_valid(tree: SplitTree, i: int, j: int) -> bool decreases tree, { match tree { SplitTree::Leaf => j - i < 2, Spli...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub enum SplitTree { Leaf, Node(int, Box<SplitTree>, Box<SplitTree>), } pub open spec fn split_tree_valid(tree: SplitTree, i: int, j: int) -> bool decreases tree, { match tree { SplitTree::Leaf => j - i < 2, Spli...
null
null
leetcode/lc1039/tests/testcases.jsonl
leetcode/lc1039/tests/mutated_testcases.jsonl
lc1040
leetcode
# Moving Stones Until Consecutive II There are some stones in different positions on the X-axis. You are given an integer array `stones`, the positions of the stones. Call a stone an **endpoint stone** if it has the smallest or largest position. In one move, you pick up an **endpoint stone** and move it to an unoccup...
Medium Array, Math, Sliding Window, Sorting Acceptance rate: 58.8%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_sorted(s: Seq<i32>) -> bool { forall |i: int, j: int| 0 <= i < j < s.len() ==> s[i] < s[j] } pub open spec fn max_of(a: int, b: int) -> int { if a >= b { a } else { b } } pub open spec fn min_of(a: int, b: int) -> int { ...
impl Solution { pub fn num_moves_stones_ii(stones: Vec<i32>) -> Vec<i32> { let mut stones = stones; let n = stones.len(); let mut si: usize = 1; while si < n { let mut sj: usize = si; while sj > 0 && stones[sj - 1] > stones[sj] { let tmp = sto...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_sorted(s: Seq<i32>) -> bool { forall |i: int, j: int| 0 <= i < j < s.len() ==> s[i] < s[j] } pub open spec fn max_of(a: int, b: int) -> int { if a >= b { a } else { b } } pub open spec fn min_of(a: int, b: int) -> int { ...
use vstd::prelude::*; use vstd::seq_lib::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_sorted(s: Seq<i32>) -> bool { forall |i: int, j: int| 0 <= i < j < s.len() ==> s[i] < s[j] } pub open spec fn max_of(a: int, b: int) -> int { if a >= b { a } else { b } } pub open spec fn min_of(a: i...
null
null
leetcode/lc1040/tests/testcases.jsonl
leetcode/lc1040/tests/mutated_testcases.jsonl
lc1073
leetcode
# Adding Two Negabinary Numbers Given two numbers `arr1` and `arr2` in base **-2**, return the result of adding them together. Each number is given in *array format*: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (...
Medium Array, Math Acceptance rate: 37.7%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn negabinary_val(s: Seq<i32>) -> int decreases s.len(), { if s.len() == 0 { 0int } else { s.last() as int + (-2int) * negabinary_val(s.drop_last()) } } impl Solution { pub fn add_negabinary(arr1: Vec...
impl Solution { pub fn add_negabinary(arr1: Vec<i32>, arr2: Vec<i32>) -> Vec<i32> { let n1 = arr1.len(); let n2 = arr2.len(); let max_len = if n1 >= n2 { n1 } else { n2 }; let max_iters = max_len + 3; let mut res: Vec<i32> = Vec::new(); let mut carry: i32 = 0; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn negabinary_val(s: Seq<i32>) -> int decreases s.len(), { if s.len() == 0 { 0int } else { s.last() as int + (-2int) * negabinary_val(s.drop_last()) } } impl Solution { pub fn add_negabinary(arr1: Vec...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn negabinary_val(s: Seq<i32>) -> int decreases s.len(), { if s.len() == 0 { 0int } else { s.last() as int + (-2int) * negabinary_val(s.drop_last()) } } pub open spec fn val_lsb(s: Seq<i32>) -> int de...
null
null
leetcode/lc1073/tests/testcases.jsonl
leetcode/lc1073/tests/mutated_testcases.jsonl
lc1103
leetcode
# Distribute Candies to People We distribute some number of `candies` to a row of `n = num_people` people in the following way: We give 1 candy to the first person, 2 candies to the second person, and so on until we give `n` candies to the last person. Then, we go back to the start of the row, giving `n + 1` candies...
Easy Math, Simulation Acceptance rate: 67.5%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn to_int_seq(s: Seq<i32>) -> Seq<int> { Seq::new(s.len(), |i: int| s[i] as int) } pub open spec fn distribute_helper(remaining: int, n: int, step: int, acc: Seq<int>) -> Seq<int> decreases re...
impl Solution { pub fn distribute_candies(candies: i32, num_people: i32) -> Vec<i32> { let n = num_people as usize; let mut result: Vec<i32> = Vec::new(); let mut idx: usize = 0; while idx < n { result.push(0i32); idx = idx + 1; } let mut remai...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn to_int_seq(s: Seq<i32>) -> Seq<int> { Seq::new(s.len(), |i: int| s[i] as int) } pub open spec fn distribute_helper(remaining: int, n: int, step: int, acc: Seq<int>) -> Seq<int> decreases re...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn to_int_seq(s: Seq<i32>) -> Seq<int> { Seq::new(s.len(), |i: int| s[i] as int) } pub open spec fn distribute_helper(remaining: int, n: int, step: int, acc: Seq<int>) -> Seq<int> decreases re...
null
null
leetcode/lc1103/tests/testcases.jsonl
leetcode/lc1103/tests/mutated_testcases.jsonl
lc1122
leetcode
# Relative Sort Array Given two arrays `arr1` and `arr2`, the elements of `arr2` are distinct, and all elements in `arr2` are also in `arr1`. Sort the elements of `arr1` such that the relative ordering of items in `arr1` are the same as in `arr2`. Elements that do not appear in `arr2` should be placed at the end of `...
Easy Array, Hash Table, Sorting, Counting Sort Acceptance rate: 75.2%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count(s: Seq<i32>, v: i32) -> int decreases s.len() { if s.len() == 0 { 0 } else { (if s[0] == v { 1int } else { 0int }) + Self::count(s.subrange(1, s.len() as in...
impl Solution { pub fn relative_sort_array(arr1: Vec<i32>, arr2: Vec<i32>) -> Vec<i32> { let mut cnt: Vec<i32> = Vec::new(); let mut i: usize = 0; while i < 1001 { cnt.push(0); i = i + 1; } let mut j: usize = 0; while j < arr1.len() { ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count(s: Seq<i32>, v: i32) -> int decreases s.len() { if s.len() == 0 { 0 } else { (if s[0] == v { 1int } else { 0int }) + Self::count(s.subrange(1, s.len() as in...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count(s: Seq<i32>, v: i32) -> int decreases s.len() { if s.len() == 0 { 0 } else { (if s[0] == v { 1int } else { 0int }) + Self::count(s.subrange(1, s.len() as in...
null
null
leetcode/lc1122/tests/testcases.jsonl
leetcode/lc1122/tests/mutated_testcases.jsonl
lc1140
leetcode
# Stone Game II Alice and Bob continue their games with piles of stones. There are a number of piles **arranged in a row**, and each pile has a positive integer number of stones `piles[i]`. The objective of the game is to end with the most stones. Alice and Bob take turns, with Alice starting first. On each player's...
Medium Array, Math, Dynamic Programming, Prefix Sum, Game Theory Acceptance rate: 72.9%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn suffix_sum(piles: Seq<i32>, i: int) -> int decreases piles.len() - i { if i >= piles.len() { 0 } else { piles[i] as int + Self::suffix_sum(piles, i + 1) }...
impl Solution { pub fn stone_game_ii(piles: Vec<i32>) -> i32 { let n = piles.len(); let stride = n + 1; let mut suffix_sums: Vec<i32> = Vec::new(); let mut k: usize = 0; while k < stride { suffix_sums.push(0i32); k += 1; } let mut si = ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn suffix_sum(piles: Seq<i32>, i: int) -> int decreases piles.len() - i { if i >= piles.len() { 0 } else { piles[i] as int + Self::suffix_sum(piles, i + 1) }...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn suffix_sum(piles: Seq<i32>, i: int) -> int decreases piles.len() - i { if i >= piles.len() { 0 } else { piles[i] as int + Self::suffix_sum(piles, i + 1) }...
null
null
leetcode/lc1140/tests/testcases.jsonl
leetcode/lc1140/tests/mutated_testcases.jsonl
lc1157
leetcode
# Online Majority Element In Subarray Given an array `arr`, find the **majority element** of a given subarray. The **majority element** of a subarray is an element that occurs `threshold` times or more in the subarray. Given `arr`, `left`, `right`, and `threshold`, return the element in the subarray `arr[left...right...
Hard Array, Binary Search, Design, Binary Indexed Tree, Segment Tree Acceptance rate: 40.3%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_occurrences(arr: Seq<i32>, left: int, right: int, val: i32) -> int decreases right - left + 1 { if left > right { 0 } else if arr[left] == val { 1 + Self::c...
pub struct MajorityChecker { pub arr: Vec<i32>, } impl MajorityChecker { pub fn new(arr: Vec<i32>) -> Self { MajorityChecker { arr } } pub fn query(&self, left: i32, right: i32, threshold: i32) -> i32 { let l = left as usize; let r = right as usize; let mut candidate: i...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_occurrences(arr: Seq<i32>, left: int, right: int, val: i32) -> int decreases right - left + 1 { if left > right { 0 } else if arr[left] == val { 1 + Self::c...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn count_occurrences(arr: Seq<i32>, left: int, right: int, val: i32) -> int decreases right - left + 1 { if left > right { 0 } else if arr[left] == val { 1 + Self::c...
null
null
leetcode/lc1157/tests/testcases.jsonl
leetcode/lc1157/tests/mutated_testcases.jsonl
lc1200
leetcode
# Minimum Absolute Difference Given an array of **distinct** integers `arr`, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order (with respect to pairs), each pair `[a, b]` follows: - `a, b` are from `arr` - `a < b` - `b - a` equals to the mi...
Easy Array, Sorting Acceptance rate: 75.1%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn abs_diff(a: int, b: int) -> int { if a >= b { a - b } else { b - a } } pub open spec fn seq_contains(s: Seq<i32>, v: i32) -> bool { exists |i: int| 0 <= i < s.len() && s[i] == v } pub open spec fn consec_diff(s: Seq<i32>, k:...
impl Solution { pub fn minimum_abs_difference(arr: Vec<i32>) -> Vec<Vec<i32>> { let n = arr.len(); let mut sorted = arr; let mut i: usize = 1; while i < n { let key = sorted[i]; let mut j = i; while j > 0 && sorted[j - 1] > key { s...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn abs_diff(a: int, b: int) -> int { if a >= b { a - b } else { b - a } } pub open spec fn seq_contains(s: Seq<i32>, v: i32) -> bool { exists |i: int| 0 <= i < s.len() && s[i] == v } pub open spec fn consec_diff(s: Seq<i32>, k:...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn abs_diff(a: int, b: int) -> int { if a >= b { a - b } else { b - a } } pub open spec fn seq_contains(s: Seq<i32>, v: i32) -> bool { exists |i: int| 0 <= i < s.len() && s[i] == v } pub open spec fn consec_diff(s: Seq<i32>, k:...
null
null
leetcode/lc1200/tests/testcases.jsonl
leetcode/lc1200/tests/mutated_testcases.jsonl
lc1223
leetcode
# Dice Roll Simulation A die simulator generates a random number from `1` to `6` for each roll. You introduced a constraint to the generator such that it cannot roll the number `i` more than `rollMax[i]` (**1-indexed**) consecutive times. Given an array of integers `rollMax` and an integer `n`, return the number of d...
Hard Array, Dynamic Programming Acceptance rate: 50.8%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn dp_val(i: int, j: int, rm: Seq<i32>) -> int recommends 0 <= j < 6, rm.len() == 6, decreases i, 17int, { if i <= 0 { 0 } else if i == 1 { 1 } ...
impl Solution { pub fn die_simulator(n: i32, roll_max: Vec<i32>) -> i32 { let modp: i64 = 1_000_000_007; let n_us = n as usize; let dp_size = (n_us + 1) * 6; let mut dp: Vec<i64> = Vec::new(); let mut idx = 0usize; while idx < dp_size { dp.push(0i64); ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn dp_val(i: int, j: int, rm: Seq<i32>) -> int recommends 0 <= j < 6, rm.len() == 6, decreases i, 17int, { if i <= 0 { 0 } else if i == 1 { 1 } ...
use vstd::prelude::*; use vstd::arithmetic::div_mod::{lemma_fundamental_div_mod, lemma_mod_multiples_vanish}; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn dp_val(i: int, j: int, rm: Seq<i32>) -> int recommends 0 <= j < 6, rm.len() == 6, ...
null
null
leetcode/lc1223/tests/testcases.jsonl
leetcode/lc1223/tests/mutated_testcases.jsonl
lc1260
leetcode
# Shift 2D Grid Given a 2D `grid` of size `m x n` and an integer `k`. You need to shift the `grid` `k` times. In one shift operation: - Element at `grid[i][j]` moves to `grid[i][j + 1]`. - Element at `grid[i][n - 1]` moves to `grid[i + 1][0]`. - Element at `grid[m - 1][n - 1]` moves to `grid[0][0]`. Return the 2D g...
Easy Array, Matrix, Simulation Acceptance rate: 68.0%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn shifted_element(grid: Seq<Seq<i32>>, n: int, k: int, i: int, j: int) -> i32 { let total = (grid.len() as int) * n; let k_eff = k % total; let src = (i * n + j + total - k_eff) % total; ...
impl Solution { pub fn shift_grid(grid: Vec<Vec<i32>>, k: i32) -> Vec<Vec<i32>> { let m: usize = grid.len(); let n: usize = grid[0].len(); let total: usize = m * n; let k_eff: usize = (k as usize) % total; let mut result: Vec<Vec<i32>> = Vec::new(); let mut i: usize =...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn shifted_element(grid: Seq<Seq<i32>>, n: int, k: int, i: int, j: int) -> i32 { let total = (grid.len() as int) * n; let k_eff = k % total; let src = (i * n + j + total - k_eff) % total; ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub open spec fn shifted_element(grid: Seq<Seq<i32>>, n: int, k: int, i: int, j: int) -> i32 { let total = (grid.len() as int) * n; let k_eff = k % total; let src = (i * n + j + total - k_eff) % total; ...
null
null
leetcode/lc1260/tests/testcases.jsonl
leetcode/lc1260/tests/mutated_testcases.jsonl
lc1262
leetcode
# Greatest Sum Divisible by Three Given an integer array `nums`, return the **maximum possible sum** of elements of the array such that it is divisible by three. ## Example 1: > **Input:** nums = [3,6,5,1,8] > **Output:** 18 > **Explanation:** Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3). ...
Medium Array, Dynamic Programming, Greedy, Sorting Acceptance rate: 57.1%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn subset_sum(nums: Seq<i32>, sel: Seq<bool>, hi: int) -> int decreases hi { if hi <= 0 { 0 } else { (if sel[hi - 1] { nums[hi - 1] as int } else { 0 }) + subset_sum(nums, sel, hi - 1) } } impl Solution {...
impl Solution { pub fn max_sum_div_three(nums: Vec<i32>) -> i32 { let n = nums.len(); let mut dp0: i32 = 0; let mut dp1: i32 = 0; let mut dp2: i32 = 0; let mut i: usize = 0; while i < n { let a = nums[i]; let old0 = dp0; let old1 = ...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn subset_sum(nums: Seq<i32>, sel: Seq<bool>, hi: int) -> int decreases hi { if hi <= 0 { 0 } else { (if sel[hi - 1] { nums[hi - 1] as int } else { 0 }) + subset_sum(nums, sel, hi - 1) } } impl Solution {...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn subset_sum(nums: Seq<i32>, sel: Seq<bool>, hi: int) -> int decreases hi { if hi <= 0 { 0 } else { (if sel[hi - 1] { nums[hi - 1] as int } else { 0 }) + subset_sum(nums, sel, hi - 1) } } pub open spec ...
null
null
leetcode/lc1262/tests/testcases.jsonl
leetcode/lc1262/tests/mutated_testcases.jsonl
lc1276
leetcode
# Number of Burgers with No Waste of Ingredients Given two integers `tomatoSlices` and `cheeseSlices`. The ingredients of different burgers are as follows: - **Jumbo Burger:** 4 tomato slices and 1 cheese slice. - **Small Burger:** 2 tomato slices and 1 cheese slice. Return `[total_jumbo, total_small]` so that the n...
Medium Math Acceptance rate: 50.9%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> (result: Vec<i32>) requires 0 <= tomato_slices <= 10_000_000, 0 <= cheese_slices <= 10_000_000, ensures result@.le...
impl Solution { pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec<i32> { if tomato_slices % 2 != 0 { return Vec::new(); } let jumbo = tomato_slices / 2 - cheese_slices; let small = cheese_slices - jumbo; if jumbo < 0 || small < 0 { r...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> (result: Vec<i32>) requires 0 <= tomato_slices <= 10_000_000, 0 <= cheese_slices <= 10_000_000, ensures result@.le...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; impl Solution { pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> (result: Vec<i32>) requires 0 <= tomato_slices <= 10_000_000, 0 <= cheese_slices <= 10_000_000, ensures result@.le...
null
null
leetcode/lc1276/tests/testcases.jsonl
leetcode/lc1276/tests/mutated_testcases.jsonl
lc1277
leetcode
# Count Square Submatrices with All Ones Given a `m * n` matrix of ones and zeros, return how many **square** submatrices have all ones. ## Example 1: > **Input:** matrix = [[0,1,1,1],[1,1,1,1],[0,1,1,1]] > **Output:** 15 > **Explanation:** > There are **10** squares of side 1. > There are **4** squares of side 2. >...
Medium Array, Dynamic Programming, Matrix Acceptance rate: 80.7%
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_all_ones_square(mat: Seq<Vec<i32>>, r: int, c: int, s: int) -> bool { &&& s >= 1 &&& r >= 0 && r + s <= mat.len() &&& c >= 0 && c + s <= mat[0int].len() &&& forall|dr: int, dc: int| 0 <= d...
impl Solution { fn set_dp(dp: &mut Vec<Vec<i32>>, row: usize, col: usize, value: i32) { let mut current_row = dp[row].clone(); current_row[col] = value; dp[row] = current_row; } pub fn count_squares(matrix: Vec<Vec<i32>>) -> i32 { let m = matrix.len(); let n = matrix...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_all_ones_square(mat: Seq<Vec<i32>>, r: int, c: int, s: int) -> bool { &&& s >= 1 &&& r >= 0 && r + s <= mat.len() &&& c >= 0 && c + s <= mat[0int].len() &&& forall|dr: int, dc: int| 0 <= d...
use vstd::prelude::*; fn main() {} verus! { pub struct Solution; pub open spec fn is_all_ones_square(mat: Seq<Vec<i32>>, r: int, c: int, s: int) -> bool { &&& s >= 1 &&& r >= 0 && r + s <= mat.len() &&& c >= 0 && c + s <= mat[0int].len() &&& forall|dr: int, dc: int| 0 <= d...
null
null
leetcode/lc1277/tests/testcases.jsonl
leetcode/lc1277/tests/mutated_testcases.jsonl