problem_id stringlengths 4 4 | problem_description stringlengths 5 7.37k | c_code stringlengths 87 16.5k | rust_code stringlengths 101 4.89k | difficulty stringclasses 3
values |
|---|---|---|---|---|
1401 | Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something. Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed his ... | int solution() {
long long int t;
scanf("%lld", &t);
do {
long long int n;
scanf("%lld", &n);
long long int a[n];
long long int i;
for (i = 0; i < n; ++i) {
scanf("%lld", &a[i]);
}
long long int sol = 0;
for (i = 0; i < n - 1; ++i) {
if (a[i] + 1 < a[i + 1]) {
... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
let mut xs: Vec<(usize, usize)> = lines
.next()
... | medium |
1402 | You have a sequence $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$, consisting of integers between $$$1$$$ and $$$m$$$. You also have a string $$$s$$$, consisting of $$$m$$$ characters B.You are going to perform the following $$$n$$$ operations. At the $$$i$$$-th ($$$1 \le i \le n$$$) operation, you replace either the... | int solution() {
int t = 0;
scanf("%d", &t);
while (--t >= 0) {
int n = 0;
int m = 0;
scanf("%d", &n);
scanf("%d", &m);
char *carr = (char *)malloc(sizeof(char) * (m + 1));
for (int i = 0; i < m; ++i) {
carr[i] = 'B';
}
carr[m] = '\0';
for (int i = 0; i < n; ++i) {
... | fn solution() {
let n = std::io::stdin()
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<i32>()
.unwrap();
for _ in 0..n {
let mut k = String::new();
let mut l = String::new();
std::io::stdin().read_line(&mut k);
std::... | hard |
1403 | 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 New Year party at his place and invited n his friends there.If the... | int solution() {
int n = 0;
int i = 0;
int ara1[101] = {0};
int ara2[101] = {0};
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &ara1[i]);
ara2[ara1[i]] = i;
}
for (i = 1; i <= n; i++) {
printf("%d ", ara2[i]);
}
return 0;
} | fn solution() {
use std::io;
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
buf.clear();
io::stdin().read_line(&mut buf).unwrap();
let friends: Vec<u32> = buf
.split_whitespace()
.map(|str| str.trim().parse().unwrap())
.collect();
let mut gave ... | hard |
1404 | You are given two integer arrays $$$a$$$ and $$$b$$$ of length $$$n$$$.You can reverse at most one subarray (continuous subsegment) of the array $$$a$$$. Your task is to reverse such a subarray that the sum $$$\sum\limits_{i=1}^n a_i \cdot b_i$$$ is maximized. | int solution() {
long long int n;
long long int i;
long long int a[5003];
long long int b[5003];
long long int d;
long long int j;
long long int mult1[5005];
long long int mult2[5005];
long long int sum1;
long long int sum2;
long long int sum;
long long int x;
long long int y;
scanf("%lld", ... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let n: usize = str.trim().parse().unwrap();
let mut A: Vec<i64> = vec![0; n + 1];
let mut B: Vec<i64> = vec![0; n + 1];
let mut A_dot_B: Vec<Vec<i64>> = vec![Vec::new(); n];
let mut A_not_B: Vec<i64> =... | medium |
1405 | You are given a string $$$s$$$ of length $$$n$$$ consisting of characters a and/or b.Let $$$\operatorname{AB}(s)$$$ be the number of occurrences of string ab in $$$s$$$ as a substring. Analogically, $$$\operatorname{BA}(s)$$$ is the number of occurrences of ba in $$$s$$$ as a substring.In one step, you can choose any i... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
char str[100];
scanf("%s", str);
int i = 0;
while (str[i] != '\0') {
i++;
}
if (str[0] == 'a' && str[i - 1] == 'b') {
str[i - 1] = 'a';
} else if (str[0] == 'b' && str[i - 1] == 'a') {
str[i - 1] = 'b';
}
... | fn solution() {
let stdin = io::stdin();
let mut n = String::new();
stdin.read_line(&mut n).unwrap();
let n = n.trim().parse::<i32>().unwrap();
for _ in 0..n {
let mut s = String::new();
stdin.read_line(&mut s).unwrap();
let mut s = s.trim().to_string();
let ab = s... | medium |
1406 | You are given two integers $$$n$$$ and $$$m$$$. Calculate the number of pairs of arrays $$$(a, b)$$$ such that: the length of both arrays is equal to $$$m$$$; each element of each array is an integer between $$$1$$$ and $$$n$$$ (inclusive); $$$a_i \le b_i$$$ for any index $$$i$$$ from $$$1$$$ to $$$m$$$; array $$$a... | int solution() {
long long int n;
long long int m;
scanf("%lld%lld", &n, &m);
m = 2 * m;
long long int a[21][1001] = {0};
for (int i = 1; i <= n; i++) {
a[1][i] = i;
}
for (int i = 1; i <= m; i++) {
a[i][1] = 1;
}
for (long long int i = 2; i <= n; i++) {
for (long long int o = 2; o <= m;... | fn solution() {
let mut buffer = String::new();
{
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).unwrap();
}
let arr = buffer
.split_whitespace()
.map(|x| x.parse::<usize>().expect("convert to number"))
.collect... | medium |
1407 | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $$$f(0) = a$$$; $$$f(1) = b$$$; $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n &... | int solution() {
int qtos;
int a;
int b;
int n;
scanf("%d", &qtos);
if (qtos >= 1 && qtos <= 1000) {
for (int i = 0; i < qtos; i++) {
scanf("%d %d %d", &a, &b, &n);
if (a >= 0 && b >= 0 && n >= 0) {
if (n % 3 == 0) {
printf("%d\n", a);
} else if (n % 3 == 1) {
... | fn solution() {
let mut t = String::new();
io::stdin()
.read_line(&mut t)
.expect("failed to read from stdin");
let t: u32 = t.trim().parse().expect("expect a number");
for _ in 0..t {
let mut line = String::new();
io::stdin()
.read_line(&mut line)
... | medium |
1408 | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: the Power Gem of purple color, the Time Gem of green color, the Space Gem of blue color, the Soul Gem of orange color, the Reality Gem of red color, the Mind Gem of yellow color. Using colors of Gems you s... | int solution() {
char save[6][20] = {"Power", "Time", "Space", "Soul", "Reality", "Mind"};
char s[20];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
if (*s == 'p') {
memset(save[0], 0, sizeof(save[0]));
}
if (*s == 'g') {
memset(save[1], 0, sizeof(save[0]));... | fn solution() {
let mut visited = HashMap::new();
visited.insert("purple", ("Power", false));
visited.insert("green", ("Time", false));
visited.insert("blue", ("Space", false));
visited.insert("orange", ("Soul", false));
visited.insert("red", ("Reality", false));
visited.insert("yellow", ("M... | medium |
1409 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>A</var> apples and <var>P</var> pieces of apple.</p>
<p>We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.</p>
<p>Find the max... | int solution(void) {
int a = 0;
int p = 0;
int ans = 0;
scanf("%d%d", &a, &p);
ans = (a * 3 + p) / 2;
printf("%d\n", ans);
} | fn solution() {
let mut ap = String::new();
stdin().read_line(&mut ap).unwrap();
let a: usize = ap.split_whitespace().collect::<Vec<&str>>()[0]
.parse()
.unwrap();
let p: usize = ap.split_whitespace().collect::<Vec<&str>>()[1]
.parse()
.unwrap();
let k = a * 3 + p;
... | easy |
1410 | Let's say string $$$s$$$ has period $$$k$$$ if $$$s_i = s_{i + k}$$$ for all $$$i$$$ from $$$1$$$ to $$$|s| - k$$$ ($$$|s|$$$ means length of string $$$s$$$) and $$$k$$$ is the minimum positive integer with this property.Some examples of a period: for $$$s$$$="0101" the period is $$$k=2$$$, for $$$s$$$="0000" the perio... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
char ch[100];
scanf("%s", ch);
int l = strlen(ch);
int cnt1 = 0;
int cnt0 = 0;
int k = l;
while (l) {
l--;
if (ch[l] == '1') {
cnt1++;
} else {
cnt0++;
}
}
if (cnt1 == 0 || cnt0 == ... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let test: i64 = str.trim().parse().unwrap();
for _ in 0..test {
str.clear();
let _ = stdin().read_line(&mut str).unwrap();
let ones = str
.trim()
.chars()
... | medium |
1411 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> y... | int solution() {
int n;
int m;
int i;
int a;
int b[20] = {0};
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
scanf("%d", &a);
b[a] = 1;
}
while (1) {
for (i = n++; i && b[i % 10] == 0; i /= 10) {
;
}
if (i == 0) {
break;
}
}
printf("%d\n", n - 1);
return 0;... | fn solution() {
input! {
n: usize,
k: usize,
v: [usize; k]
}
let mut l = [false; 10];
for i in 0..k {
l[v[i]] = true;
}
'outer: for i in n..n * 10 {
let mut m = i;
while m > 0 {
if l[m % 10] {
continue 'outer;
... | medium |
1412 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a permutation <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_n</var>} of {<var>1,\ 2,\ ...,\ n</var>}.</p>
<p>Print the number of elements <var>p_i</var> (<var>1 < i < n</var>) that satisfy the ... | int solution() {
int n;
scanf("%d", &n);
int p[n];
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
int cnt = 0;
for (int i = 1; i < n - 1; i++) {
if ((p[i - 1] <= p[i] && p[i] < p[i + 1]) ||
(p[i + 1] <= p[i] && p[i] < p[i - 1]) ||
(p[i] < p[i - 1] && p[i - 1] == p[i + 1])... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let items: Vec<i32> = (0..n)
.map(|_| iter.next().unwrap().parse().unwrap())
.collect();
... | hard |
1413 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the State of Takahashi in AtCoderian Federation, there are <var>N</var> cities, numbered <var>1, 2, ..., N</var>.
<var>M</var> bidirectional roads connect these cities.
The <var>i</var>-th road conne... | int solution() {
int i;
int u;
int w;
int N;
int M;
int adj[701][701] = {};
scanf("%d %d", &N, &M);
for (i = 1; i <= M; i++) {
scanf("%d %d", &u, &w);
adj[u][w] = 1;
adj[w][u] = 1;
}
int k;
int flag[701] = {};
int size[701];
int q[701];
int head;
int tail;
for (i = 1, k = 0;... | fn solution() {
input! {
n: usize,
m: usize,
es: [(usize1, usize1); m]
}
let mut g = vec![(0..n).collect::<BTreeSet<usize>>(); n];
for i in 0..n {
g[i].remove(&i);
}
for &(a, b) in &es {
g[a].remove(&b);
g[b].remove(&a);
}
let g = g
... | medium |
1414 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> integers. The <var>i</var>-th integer is <var>A_i</var>.</p>
<p>Find <var>\sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j)</var>, modulo <var>(10^9+7)</var>.</p>
<details>
<s... | int solution() {
int n;
scanf("%d", &n);
int i;
int j;
long long int a[300005];
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
int b[300005][62];
for (i = 0; i < n; i++) {
for (j = 0; j < 62; j++) {
b[i][j] = (int)(a[i] % 2);
a[i] /= 2;
}
}
long long int ans = 0;
long ... | fn solution() {
let mut input_str = String::new();
std::io::stdin().read_to_string(&mut input_str).unwrap();
let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
let mut input_parts_it = input_parts.iter().cloned();
let mut next = || input_parts_it.next().unwrap();
let n: usize ... | hard |
1415 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It is known that the area of a regular dodecagon inscribed in a circle of radius <var>a</var> is <var>3a^2</var>.</p>
<p>Given an integer <var>r</var>, find the area of a regular dodecagon inscribed in ... | int solution(void) {
int r = 0;
scanf("%d", &r);
printf("%d", 3 * r * r);
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let r = buf.trim().parse::<i32>().ok().unwrap();
println!("{}", 3 * r * r);
} | easy |
1416 | Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ... | int solution(void) {
int n = 0;
int m = 0;
int x = 0;
int y = 0;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &x);
scanf("%d", &y);
if (x - 1 != 0) {
arr[x - 2] = y - 1 + arr[x - 2]... | fn solution() {
use std::io;
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
buf.clear();
io::stdin().read_line(&mut buf).unwrap();
let mut wires: Vec<u32> = buf
.split(" ")
.map(|str| str.trim().parse().unwrap())
.collect();
buf.clear();
io... | medium |
1417 | Vasya owns a cornfield which can be defined with two integers $$$n$$$ and $$$d$$$. The cornfield can be represented as rectangle with vertices having Cartesian coordinates $$$(0, d), (d, 0), (n, n - d)$$$ and $$$(n - d, n)$$$. An example of a cornfield with $$$n = 7$$$ and $$$d = 2$$$. Vasya also knows that there ar... | int solution(void) {
int n = 0;
int d = 0;
int c = 0;
double dlA = 0.0;
double dlB = 0.0;
double S = 0.0;
double S1 = 0.0;
double S2 = 0.0;
double S3 = 0.0;
double S4 = 0.0;
scanf("%d %d", &n, &d);
scanf("%d", &c);
int x[c];
int y[c];
int yG[4];
int xG[4];
for (int j = 0; j < c; ++j)... | fn solution() {
let mut buffer = String::new();
let stdin = io::stdin();
let mut handle = stdin.lock();
handle.read_to_string(&mut buffer).unwrap();
let arr = buffer
.split_whitespace()
.map(|x| x.parse::<i32>().unwrap())
.collect::<Vec<_>>();
let n = arr[0];
let d ... | medium |
1418 | Baby Ehab is known for his love for a certain operation. He has an array $$$a$$$ of length $$$n$$$, and he decided to keep doing the following operation on it: he picks $$$2$$$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR. Note that the length of the array decr... | int solution() {
int a[2010];
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int temp = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
temp ^= a[i];
}
if (temp == 0) {
printf("YES\n");
continue;
}
int cnt = 0;
int tt = 0;
for... | fn solution() {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut itr = buf.split_whitespace();
use std::io::Write;
let out = std::io::stdout();
let mut out = std::io::BufWriter::new(out.lock());
let t: usize = scan!(usize);... | easy |
1419 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> points in a two-dimensional plane.<br/>
The coordinates of the <var>i</var>-th point <var>(1 \leq i \leq N)</var> are <var>(x_i,y_i)</var>.<br/>
Let us consider a rectangle whose si... | int solution() {
int i;
int N;
int K;
long long x[51];
long long y[51];
scanf("%d %d", &N, &K);
for (i = 1; i <= N; i++) {
scanf("%lld %lld", &(x[i]), &(y[i]));
}
int j;
int k;
int l;
int m;
int count;
long long X[2];
long long Y[2];
long long min = (long long)1 << 62;
for (i = 1;... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
let K: usize = itr.next().unwrap().parse().unwrap();
let xy: Vec<(i64, i64)> = (0..n)
.map(|_| {
... | easy |
1420 | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.One day Vasya decided to make himself an orange cocktail. He took equal proportions of each... | int solution() {
float n;
scanf("%f", &n);
float a[100];
float sum = 0;
for (int i = 0; i < n; i++) {
scanf("%f", &a[i]);
sum = sum + a[i];
}
float orange = (sum / n) * 1.0;
printf("%f", orange);
return 0;
} | fn solution() {
let n: f32 = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim().parse().unwrap()
};
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
println!(
"{}",
input
.split_... | medium |
1421 | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.ZS and Chris are g... | int solution() {
int n;
int flat = 0;
scanf("%d", &n);
char a[100000];
for (int i = 0; i < n * 6; i++) {
scanf("%c", &a[i]);
}
for (int i = 1; i < n * 6; i++) {
if (a[i] == 'O' && a[i - 1] == 'O') {
flat = 1;
a[i] = '+';
a[i - 1] = '+';
break;
}
}
if (flat == 1) {
... | fn solution() {
let n: usize = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim().parse().unwrap()
};
let mut bus = Vec::with_capacity(n);
let mut found = false;
for _ in 0..n {
let mut row = String::new();
std::io::stdin... | medium |
1422 | You are given $$$n$$$ points with integer coordinates on a coordinate axis $$$OX$$$. The coordinate of the $$$i$$$-th point is $$$x_i$$$. All points' coordinates are distinct and given in strictly increasing order.For each point $$$i$$$, you can do the following operation no more than once: take this point and move it ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int pass = 0;
int f = 1;
scanf("%d", &n);
int v[n];
for (int i = 0; i < n; ++i) {
scanf("%d", (v + i));
}
for (int i = 1; i < n; ++i) {
if (v[i] - 1 == v[i - 1]) {
continue;
}
if (v[i... | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).unwrap();
let t: usize = buf.trim().parse().unwrap();
for _ in 0..t {
buf.clear();
stdin.read_line(&mut buf).unwrap();
buf.clear();
stdin.read_line(&mut buf).unwrap();
... | medium |
1423 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>S</var> sheep and <var>W</var> wolves.</p>
<p>If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.</p>
<p>If the wolves will attack the she... | int solution() {
int s = 0;
int w = 0;
scanf("%d %d", &s, &w);
if (s > w) {
printf("safe\n");
} else {
printf("unsafe\n");
}
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let s: Vec<i32> = s
.trim()
.split(' ')
.map(|x| x.parse::<i32>().unwrap())
.collect();
if s[0] > s[1] {
println!("safe");
} else {
println!("unsafe");
}
} | easy |
1424 | Monocarp has been collecting rare magazines for quite a while, and now he has decided to sell them. He distributed the magazines between $$$n$$$ boxes, arranged in a row. The $$$i$$$-th box contains $$$a_i$$$ magazines. Some of the boxes are covered with lids, others are not. Suddenly it started to rain, and now Monoca... | int solution(void) {
int t;
scanf("%d", &t);
while (t--) {
int n;
int sum = 0;
scanf("%d", &n);
char s[n + 1];
scanf("%s", s);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%i", &arr[i]);
if (s[i] == '1') {
sum += arr[i];
}
}
int var = -1;
int s... | fn solution() {
use std::io::*;
let mut s = String::new();
stdin().read_line(&mut s).ok();
for _ in 0i32..(s.trim().parse().unwrap()) {
stdin().read_line(&mut "".to_owned()).ok();
let mut s = String::new();
stdin().read_line(&mut s).ok();
let lids: Vec<bool> = s.trim().ch... | hard |
1425 | New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus.Vasya's verse contains $$$n$$$ parts. It takes $$$a_i$$$ seconds to recite the $$$i$$$-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes $$$a_1$$$ seconds, secondly... | int solution() {
int32_t t;
scanf("%d", &t);
while (t--) {
int32_t ch = 0;
int32_t n;
int32_t s;
int32_t max = 0;
int32_t sum = 0;
int32_t ans = 0;
scanf("%d%d", &n, &s);
int32_t num[n];
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
}
for (int i = 0; i < n; ... | fn solution() {
let stdin = io::stdin();
let mut input = stdin.lock();
let mut line = String::new();
input.read_line(&mut line).unwrap();
let mut queries: i8 = line.trim().parse().unwrap();
while queries > 0 {
line.clear();
input.read_line(&mut line).unwrap();
let mut num... | hard |
1426 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke stands on a number line. He has <var>L</var> ears, and he will walk along the line continuously under the following conditions:</p>
<ul>
<li>He never visits a point with coordinate less than <var>... | int solution() {
int i;
int L;
int A[200001];
scanf("%d", &L);
for (i = 1; i <= L; i++) {
scanf("%d", &(A[i]));
}
int j;
const long long sup = (long long)1 << 60;
long long dp[2][5];
long long tmp[5];
for (j = 0; j < 5; j++) {
dp[0][j] = 0;
}
for (i = 1; i <= L; i++) {
for (j = 1;... | fn solution() {
input! {
n: usize,
v: [usize; n]
}
let mut dp: Vec<[usize; 4]> = vec![[0, 0, 0, 0]; n + 1];
let v_o: Vec<usize> = v.iter().clone().map(|x| (x + 1) % 2).collect();
let v_e: Vec<usize> = v
.iter()
.clone()
.map(|x| if *x == 0 { 2 } else { x % 2 }... | hard |
1427 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is interested in strings that satisfy the following conditions:</p>
<ul>
<li>The length of the string is at least <var>N</var>.</li>
<li>The first <var>N</var> characters equal to the string <var>... | int solution() {
int n;
char s[101];
char t[101];
scanf("%d%s%s", &n, s, t);
for (int i = 0; i <= n; i++) {
bool isOK = true;
for (int j = 0; j < n; j++) {
if (i + j < n && s[i + j] != t[j]) {
isOK = false;
break;
}
}
if (isOK) {
printf("%d\n", n + i);
b... | fn solution() {
let _N: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
let s: String = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line... | hard |
1428 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an infinitely large pond, which we consider as a number line.
In this pond, there are <var>N</var> lotuses floating at coordinates <var>0</var>, <var>1</var>, <var>2</var>, ..., <var>N-2</var> ... | int solution() {
int n;
int i;
int j;
long long d[100010];
long long s;
long long m = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lld", &d[i]);
}
for (i = 1; i < n; i++) {
for (j = s = 0; i * j < n; j++) {
if ((n - 1) % i == 0 && i * j >= n - 1 - i * j) {
break;
... | fn solution() {
input! {
n: usize,
v: [isize; n]
}
let mut ans: isize = 0;
for c in 1..n - 1 {
let mut s: isize = 0;
for i in 1..(n - 1) / c {
s += v[i * c] + v[n - 1 - i * c];
if (n - 1) % c == 0 && (n - 1) / c <= 2 * i {
continue;... | hard |
1429 | Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble.There is a set $$$S$$$ containing very important nu... | int solution() {
long long int t;
scanf("%lld", &t);
while (t--) {
long long int n;
long long int a[1024];
scanf("%lld", &n);
for (long int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
long int x = 1;
long int y;
long int q = 1;
while (x < 1025) {
long int count = 0... | fn solution() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.split_whitespace();
let t: usize = itr.next().unwrap().parse().unwrap();
let mut out = Vec::new();
for _ in 0..t {
let n: usize = itr.next().unwrap().parse().unwrap();
... | medium |
1430 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In AtCoder city, there are five antennas standing in a straight line. They are called Antenna <var>A, B, C, D</var> and <var>E</var> from west to east, and their coordinates are <var>a, b, c, d</var> a... | int solution(void) {
int a[256];
scanf("%d %d %d %d %d %d", &a[1], &a[2], &a[3], &a[4], &a[5], &a[0]);
if (a[0] >= a[5] - a[1]) {
printf("Yay!");
} else {
printf(":(");
}
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let a: usize = buf.trim().parse().unwrap();
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let _b: usize = buf.trim().parse().unwrap();
let mut buf = String::new();
... | medium |
1431 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We call a <var>4</var>-digit integer with three or more consecutive same digits, such as <var>1118</var>, <strong>good</strong>.</p>
<p>You are given a <var>4</var>-digit integer <var>N</var>. Answer th... | int solution(void) {
char n[5];
scanf("%s", n);
if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
printf("Yes\n");
} else {
printf("No\n");
}
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let d: Vec<char> = buf.trim().chars().collect();
if d[0] == d[1] && d[1] == d[2] || d[1] == d[2] && d[2] == d[3] {
println!("Yes");
} else {
println! {"No"};
}
} | easy |
1432 | You are given an array $$$a$$$ consisting of $$$n$$$ nonnegative integers. Let's define the prefix OR array $$$b$$$ as the array $$$b_i = a_1~\mathsf{OR}~a_2~\mathsf{OR}~\dots~\mathsf{OR}~a_i$$$, where $$$\mathsf{OR}$$$ represents the bitwise OR operation. In other words, the array $$$b$$$ is formed by computing the $$... | int solution(void) {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int n;
scanf("%d", &n);
unsigned long long data[n];
for (int j = 0; j < n; j++) {
scanf("%llu", &data[j]);
}
int settled = 0;
int alive = n;
unsigned long long now = 0;
while (settled < alive) {
... | fn solution() {
let t: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
for _ in 0..t {
let n: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&m... | medium |
1433 | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: Tetrahedron. Tetrahedron has 4 triangular faces. Cube. Cube has 6 square faces. Octahedron. Octahedron has 8 triangular faces. Dodecahedron. Dodecahedron has 12 pentagonal faces. Icosahedron. Icosah... | int solution() {
char poligono[12];
int n = 0;
int i = 0;
int caras = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", poligono);
if (poligono[0] == 'T') {
caras = caras + 4;
} else if (poligono[0] == 'C') {
caras = caras + 6;
} else if (poligono[0] == 'O') {
cara... | fn solution() {
let input = stdin();
let handle = input.lock();
let mut lines = handle.lines();
let count: i32 = lines
.next()
.expect("ERROR: next count")
.expect("Unwrap ended")
.parse()
.expect("Error: parse round");
let mut stack: Vec<u32> = Vec::new();
... | hard |
1434 | <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem A: Clock</h1>
<h2>Problem</h2>
<p>
がっちょ君はお気に入りの時計を持っている。ある日時計の長針が取れてしまい、どこかへなくしてしまった。しかし、がっちょ君はその時計を使い続けたいため短針だけで時刻を読み取りたいと考えている。
</p>
<p>
短針の情報<var>θ</var>に対する... | int solution() {
int a;
scanf("%d", &a);
printf("%d %d\n", a / 30, a % 30 * 2);
return 0;
} | fn solution() {
input!(theta:i32);
let S = 12 * 3600 / 360 * theta;
let h = S / 3600;
let m = S % 3600 / 60;
println!("{} {}", h, m);
} | hard |
1435 | <H1>English Sentence</H1>
<p>
Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters.
</p>
<p>
The text includes only alphabetical characters and spaces. A word is... | int solution() {
int n = 0;
int i;
int cnt[100] = {0};
int j = 0;
int max = 0;
int longer = 0;
int cou[100] = {0};
char str;
char save[100][100];
while (1) {
scanf("%c", &str);
if (str == '\n') {
break;
}
if (str != ' ') {
if (isupper(str)) {
str = tolower(str);
... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let ss = s.split_whitespace().collect::<Vec<&str>>();
let mut map_count = HashMap::with_capacity(ss.len());
for s in ss {
*map_count.entry(s).or_insert(0) += 1;
}
let max_count = {
let m... | medium |
1436 | You are given a set of $$$n$$$ ($$$n$$$ is always a power of $$$2$$$) elements containing all integers $$$0, 1, 2, \ldots, n-1$$$ exactly once.Find $$$\frac{n}{2}$$$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly e... | int solution() {
int t;
scanf("%d", &t);
getchar();
for (int qwq = 0; qwq < t; qwq++) {
long long n;
long long k;
scanf("%lld %lld", &n, &k);
getchar();
if (k == 3 && n == 4) {
printf("-1\n");
continue;
}
if (k == n - 1) {
printf("0 2\n1 %lld\n", n - 3);
for ... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<usize> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x... | easy |
1437 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi, Nakahashi and Hikuhashi have integers <var>A</var>, <var>B</var> and <var>C</var>, respectively.
After repeating the following operation <var>K</var> times, find the integer Takahashi will ge... | int solution() {
int a;
int b;
int k;
scanf("%d%d%*d%d", &a, &b, &k);
if (k & 1) {
printf("%d", b - a);
} else {
printf("%d", a - b);
}
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).ok();
let (a, b, _c, k) = {
let v: Vec<i64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
(v[0], v[1], v[2], v[3])
};
println!("{}", if k % 2 == 0 { a - b } else { b - a });
} | medium |
1438 | <h1>Bit Operation II</h1>
<p>
Given two non-negative decimal integers $a$ and $b$, calculate their AND (logical conjunction), OR (logical disjunction) and XOR (exclusive disjunction) and print them in binary representation of 32 bits.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<p... | int solution() {
unsigned int a;
unsigned int b;
unsigned int n;
unsigned int m;
unsigned int o;
unsigned int x;
fscanf(stdin, "%u %u", &n, &m);
char buf[100];
buf[32] = buf[65] = buf[98] = '\n';
buf[99] = '\0';
a = n & m;
o = n | m;
x = n ^ m;
int i = 0;
for (b = 2147483648U; b > 0; b >>=... | fn solution() {
let mut stdin = io::stdin();
let mut buf = String::new();
let _ = stdin.read_to_string(&mut buf);
let mut iter = buf.split_whitespace();
let a: u32 = iter.next().unwrap().parse().unwrap();
let b: u32 = iter.next().unwrap().parse().unwrap();
println!("{:032b}", a & b);
pri... | hard |
1439 | Ivan wants to play a game with you. He picked some string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $$$1$$$ to $$$n-1$$$), but he didn't tell you which s... | int solution() {
int a;
int b = 0;
int n;
int i;
int j;
int k;
int l = 0;
int m = 0;
int flag = 0;
int len[200];
int len2[105] = {0};
int len3[105] = {0};
char str[200][105];
char str2[105];
char str3[105] = " ";
char str4[200];
char str5[200];
scanf("%d", &n);
a = 2 * n - 2;
for... | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let n = get!(usize);
let mut ss = vec![];
for i in 0..2 * n - 2 {
let s = get(... | medium |
1440 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a train going from Station <var>A</var> to Station <var>B</var> that costs <var>X</var> yen (the currency of Japan).</p>
<p>Also, there is a bus going from Station <var>B</var> to Station <var>C... | int solution() {
int x = 0;
int y = 0;
scanf("%d %d", &x, &y);
printf("%d", x + (y / 2));
return 0;
} | fn solution() {
let scan = std::io::stdin();
let mut line = String::new();
let _ = scan.read_line(&mut line);
let vec: Vec<&str> = line.split_whitespace().collect();
let n: u32 = vec[0].parse().unwrap_or(0);
let m: u32 = vec[1].parse().unwrap_or(0);
println!("{}", n + m / 2);
} | medium |
1441 | Petya has a rectangular Board of size $$$n \times m$$$. Initially, $$$k$$$ chips are placed on the board, $$$i$$$-th chip is located in the cell at the intersection of $$$sx_i$$$-th row and $$$sy_i$$$-th column.In one action, Petya can move all the chips to the left, right, down or up by $$$1$$$ cell.If the chip was in... | int solution() {
int n;
int m;
scanf("%d %d", &n, &m);
printf("%d\n", n + m - 3 + (n * m));
for (int i = 0; i < m - 1; i++) {
printf("L");
}
for (int i = 0; i < n - 1; i++) {
printf("D");
}
for (int i = 0; i < n; i++) {
if (i != 0) {
printf("U");
}
for (int j = 0; j < m - 1; ... | fn solution() {
let mut stdin = BufReader::new(io::stdin());
let mut stdout = BufWriter::new(io::stdout());
let mut buffer = String::new();
stdin.read_line(&mut buffer).unwrap();
let buffer: Vec<i32> = buffer
.trim()
.split_ascii_whitespace()
.map(|x| x.parse().unwrap())
... | medium |
1442 | There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ... | int solution() {
int n;
int a;
int b;
int c;
int t;
scanf("%d%d%d%d%d", &n, &a, &b, &c, &t);
int time[n];
for (int i = 0; i < n; ++i) {
scanf("%d", &time[i]);
}
int ans = 0;
if (b >= c) {
printf("%d", n * a);
}
else {
ans = n * a;
int x = 0;
for (int i = 0; i < n; ++i) ... | fn solution() {
let mut input = String::new();
use std::io;
use std::io::prelude::*;
io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let n: i64 = it.next().unwrap().parse().unwrap();
let a: i64 = it.next().unwrap().parse().unwrap();
let b: i64 = i... | easy |
1443 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is buying a lamp.
The light of the lamp can be adjusted to <var>m</var> levels of brightness, represented by integers from <var>1</var> through <var>m</var>, by the two buttons on the remote contr... | int solution() {
int i;
int n;
int m;
int a;
int b;
int diff;
long long sum = 0;
long long add[100001][2] = {};
scanf("%d %d", &n, &m);
scanf("%d", &a);
a--;
for (i = 2; i <= n; i++) {
scanf("%d", &b);
b--;
diff = (b - a + m) % m;
sum += diff;
if (diff >= 2) {
a = (a + ... | fn solution() {
input!(n: usize, m: usize, a: [usize1; n]);
let mut start = vec![vec![]; m];
let mut end = vec![vec![]; m];
for i in 0..(n - 1) {
let from = a[i];
let to = a[i + 1];
start[from].push(to);
end[to].push(from);
}
let mut total = 0;
let mut count ... | medium |
1444 | Alice and Bob are playing a game. They start with a positive integer $$$n$$$ and take alternating turns doing operations on it. Each turn a player can subtract from $$$n$$$ one of its divisors that isn't $$$1$$$ or $$$n$$$. The player who cannot make a move on his/her turn loses. Alice always moves first.Note that they... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int flag = 0;
scanf("%d", &n);
if (n % 2 == 1) {
printf("Bob\n");
continue;
}
while (n > 1) {
if (n % 2 == 1) {
flag = -2;
break;
}
n = n / 2;
flag++;
}
if (flag == -2)... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | easy |
1445 | You are given an array $$$a$$$ consisting of $$$n$$$ integers.Your task is to determine if $$$a$$$ has some subsequence of length at least $$$3$$$ that is a palindrome.Recall that an array $$$b$$$ is called a subsequence of the array $$$a$$$ if $$$b$$$ can be obtained by removing some (possibly, zero) elements from $$$... | int solution() {
int t = 0;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
int size = 0;
scanf("%d", &size);
int arr[size];
for (int j = 0; j < size; j++) {
scanf("%d", &arr[j]);
}
int flag = 0;
for (int j = 0; j <= size - 3; j++) {
for (int k = j + 2; k < size; k++) {
... | fn solution() {
let mut t = String::new();
stdin().read_line(&mut t).unwrap();
for _i in 0..t.trim().parse::<u32>().unwrap() {
let mut n = String::new();
stdin().read_line(&mut n).unwrap();
n = String::new();
stdin().read_line(&mut n).unwrap();
let n: Vec<_> = n
... | medium |
1446 | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | int solution() {
int n;
scanf("%d", &n);
if (n % 2 == 1 && n > 2) {
printf("7");
n -= 3;
}
while (n > 1) {
printf("1");
n -= 2;
}
} | fn solution() {
let mut n = String::new();
std::io::stdin()
.read_line(&mut n)
.expect("Reading n error!");
let mut n: u32 = n.trim().parse().expect("Error while parsing!");
while n > 0 {
if n % 2 == 1 {
print!("7");
n -= 3;
} else {
... | easy |
1447 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It is September <var>9</var> in Japan now.</p>
<p>You are given a two-digit integer <var>N</var>. Answer the question: Is <var>9</var> contained in the decimal notation of <var>N</var>?</p>
</section>
<... | int solution(void) {
char no[100];
scanf("%s", no);
if (no[0] != '9' && no[1] != '9') {
printf("No\n");
} else {
printf("Yes\n");
}
return 0;
} | fn solution() {
let mut buffer = String::new();
let _ = io::stdin().read_to_string(&mut buffer);
print!(
"{}",
if buffer.chars().any(|c| c == '9') {
"Yes"
} else {
"No"
}
);
} | easy |
1448 | To improve the boomerang throwing skills of the animals, Zookeeper has set up an $$$n \times n$$$ grid with some targets, where each row and each column has at most $$$2$$$ targets each. The rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the columns are numbered from $$$1$$$ to $$$n$$$ from left to r... | int solution() {
int n;
scanf("%d", &n);
int i;
int a[100005];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int y[100005];
int ans[200005][2];
int cnt = 0;
int s[100005];
int ss = 0;
int t[100005];
int tt = 0;
for (i = n - 1; i >= 0; i--) {
if (a[i] == 0) {
continue;
}
... | fn solution() {
let mut str = String::new();
let _ = stdin().read_line(&mut str).unwrap();
let n: usize = str.trim().parse().unwrap();
str.clear();
let _ = stdin().read_line(&mut str).unwrap();
let throws: Vec<usize> = str
.split_whitespace()
.map(|x| x.parse().unwrap())
... | hard |
1449 | A binary matrix is called good if every even length square sub-matrix has an odd number of ones. Given a binary matrix $$$a$$$ consisting of $$$n$$$ rows and $$$m$$$ columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all. All the terms ab... | int solution() {
int j;
int n;
int m;
scanf("%d%d", &n, &m);
char a[n][m];
for (j = 0; j < n; j++) {
scanf("%s", &(a[j][0]));
}
if (n > 3) {
printf("-1\n");
return (0);
}
if (n == 1) {
printf("0\n");
return (0);
}
if (n == 2) {
int min, count = 0;
for (j = 0; j < m; j... | fn solution() {
let stdout = io::stdout();
let mut output = BufWriter::new(stdout.lock());
let mut stdin = io::stdin();
let mut input_string = String::new();
stdin.read_to_string(&mut input_string).unwrap();
let mut input_iter = input_string.split_whitespace();
let n: usize = read!()... | easy |
1450 | You are the gym teacher in the school.There are $$$n$$$ students in the row. And there are two rivalling students among them. The first one is in position $$$a$$$, the second in position $$$b$$$. Positions are numbered from $$$1$$$ to $$$n$$$ from left to right.Since they are rivals, you want to maximize the distance b... | int solution() {
int t = 0;
int n = 0;
int x = 0;
int a = 0;
int b = 0;
int i = 0;
int j = 0;
int nminusbig = 0;
int smallminusone = 0;
int modified = 0;
int finaldistance = 0;
int nsdistance = 0;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d %d %d %d", &n, &x, &a, &b);
... | fn solution() {
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("Failed to read line");
let num_queries = buffer.trim().parse::<i32>().expect("parse error");
for _i in 0..num_queries {
buffer.clear();
io::stdin()
.read_line(&mut bu... | medium |
1451 | There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in ... | int solution() {
char s[26];
char s1[26];
char w[10001];
char t[26];
scanf("%s", s);
scanf("%s", s1);
scanf("%s", w);
for (int i = 0; i < 26; i++) {
t[s[i] - 'a'] = s1[i];
}
int i = 0;
while (w[i] != '\0') {
if (w[i] - '0' >= 0 && w[i] - '0' <= 9) {
printf("%c", w[i]);
} else if ... | fn solution() {
let mut fl = String::new();
stdin().read_line(&mut fl).unwrap();
let fl = fl.trim();
let mut sl = String::new();
stdin().read_line(&mut sl).unwrap();
let sl = sl.trim();
let mut txt = String::new();
stdin().read_line(&mut txt).unwrap();
let txt = txt.trim();
... | hard |
1452 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have three boxes <var>A</var>, <var>B</var>, and <var>C</var>, each of which contains an integer.<br/>
Currently, the boxes <var>A</var>, <var>B</var>, and <var>C</var> contain the integers <var>X</... | int solution(void) {
int X = 0;
int Y = 0;
int Z = 0;
scanf("%d %d %d", &X, &Y, &Z);
printf("%d %d %d", Z, X, Y);
return 0;
} | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let mut v: Vec<_> = s
.split_whitespace()
.map(|x| x.parse::<i32>().unwrap())
.collect();
v.swap(0, 1);
v.swap(0, 2);
println!("{} {} {}", v[0], v[1], v[2]);
} | medium |
1453 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke signed up for a new website which holds programming competitions.
He worried that he might forget his password, and he took notes of it.
Since directly recording his password would cause him troub... | int solution() {
char o[51];
char e[51];
scanf("%s%s", o, e);
int eoo = 0;
int eoe = 0;
for (int i = 0; i < 51; i++) {
if (o[i] != '\0' && eoo == 0) {
printf("%c", o[i]);
} else {
eoo = 1;
}
if (e[i] != '\0' && eoe == 0) {
printf("%c", e[i]);
} else {
eoe = 1;
... | fn solution() {
let mut a = String::new();
let mut b = String::new();
let mut s = String::new();
std::io::stdin().read_line(&mut a).ok();
std::io::stdin().read_line(&mut b).ok();
let a = a.chars().collect::<Vec<char>>();
let b = b.chars().collect::<Vec<char>>();
for i in 0..a.len() + ... | hard |
1454 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> integers: <var>1,2,\ldots,N</var>.
He will choose <var>K</var> of them and give those to Takahashi.</p>
<p>How many ways are there to choose <var>K</var> consecutive integers?</p>... | int solution() {
int n = 0;
int k = 0;
scanf("%d %d", &n, &k);
printf("%d\n", n - k + 1);
return 0;
} | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let k: usize = iter.next().unwrap().parse().unwrap();
let ans: usize = n - k + 1;
let out = stdo... | easy |
1455 | There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pie... | int solution() {
int n = 0;
int m = 0;
int x[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &m);
for (int f = 0; f < m; f++) {
scanf("%d", &x[f]);
}
int count = 0;
for (int k = 0; k < m; k++) {
if (x[k] != 1) {
count += x[k] - 1;
}
}
if... | fn solution() {
let mut str: String = String::new();
io::stdin()
.read_line(&mut str)
.expect("failed to read input");
let t: usize = str.trim().parse::<usize>().expect("could not parse T");
let mut arr: [u32; 105] = [0; 105];
for _t in 0..t {
str.clear();
io::stdin()... | medium |
1456 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Japan, people make offerings called <em>hina arare</em>, colorful crackers, on March <var>3</var>.</p>
<p>We have a bag that contains <var>N</var> hina arare. (From here, we call them arare.)</p>
<p>... | int solution(void) {
int n = 0;
char hina[101] = {0};
int i = 0;
int cnt = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%c", hina + i);
}
i = 0;
while (hina[i] != '\0') {
if (hina[i] == 'Y') {
cnt++;
}
i++;
}
if (cnt > 0) {
printf("Four\n");
} else {
pri... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let mut hn = [false; 4];
for s in buf.trim().split(' ') {
match s {
"P" => hn[0] = true,
"W" => hn[1] = ... | medium |
1457 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an integer <var>N</var>, find the base <var>-2</var> representation of <var>N</var>.</p>
<p>Here, <var>S</var> is the base <var>-2</var> representation of <var>N</var> when the following are all s... | int solution(void) {
int n;
scanf("%d", &n);
long long a[20];
long long b[20];
a[0] = 1;
b[0] = 1;
for (int i = 1; i < 20; i++) {
a[i] = a[i - 1] * 4;
}
for (int i = 1; i < 20; i++) {
b[i] = b[i - 1] + a[i];
}
int x = 0;
for (int i = 17; i > 0; i--) {
if (n > b[i - 1] && b[i] >= n) {... | fn solution() {
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
let mut n: i32 = s.trim().parse().unwrap();
if n == 0 {
println!("0");
} else {
let mut ans = vec![];
while n != 0 {
ans.push(if n & 1 != 0 { '1' } else { '0' });
n... | hard |
1458 | Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $$$n$$$ days from Petya's live and you have to determine what happened with his flower in the end.The flower grows as follows: If the flower isn't watered for two days in a row, it dies. If the flower is w... | int solution() {
int t;
int n;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d", &n);
int a[n];
int height = 1;
for (int j = 0; j < n; j++) {
scanf("%d", &a[j]);
if (j > 0 && a[j] == 0 && a[j - 1] == 0) {
height = -1;
while (++j < n) {
scanf("%d", &... | fn solution() {
let mut handle = std::io::BufWriter::new(std::io::stdout());
let mut test_no = String::new();
std::io::stdin().read_line(&mut test_no).unwrap();
let test_no: u8 = test_no.trim().parse().unwrap();
for _ in 0..test_no {
let mut array_size = String::new();
std::io::stdin... | medium |
1459 | Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked $$$n$$$ of them how much effort they needed to reach red."Oh, I just spent $$$x_i$$$ hours solving problems", said the $$$i$$$-th of them. Bob wants to train h... | int solution() {
int n;
scanf("%d", &n);
while (n--) {
char ISLA[150];
scanf("%s", ISLA);
char E = 0;
char Z = 0;
int LL = 0;
for (int i = 0; ISLA[i]; i++) {
LL += ISLA[i] - '0';
if (!((ISLA[i] - '0') & 1)) {
if (ISLA[i] == '0') {
if (Z == 0) {
Z =... | fn solution() {
let mut result = Vec::new();
let reader = io::stdin();
let grandmaster_count = reader
.lock()
.lines()
.next()
.unwrap()
.unwrap()
.parse::<i32>()
.unwrap();
for _i in 0..grandmaster_count {
let str_number = reader.lock().... | easy |
1460 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are a sequence of <var>N</var> positive integers <var>A_1</var>, <var>A_2</var>, <var>\ldots</var>, <var>A_N</var> and another positive integer <var>S</var>.<br/>
For a non-empty subset <var>T</va... | int solution(void) {
long n;
long s;
scanf("%ld %ld", &n, &s);
long a[n];
for (long i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
long mod = 998244353;
long value;
long dp[n][s + 1];
for (long i = 0; i < n; i++) {
for (long j = 0; j <= s; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 2;
... | fn solution() {
const MOD: u64 = 998244353;
let (n, s): (usize, usize) = {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let mut iter = buf.split_whitespace();
let n: usize = iter.next().unwrap().parse().unwrap();
let s: usize = iter.next()... | easy |
1461 | A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in the class, and you are given an array $$$s$$$ in non-decreasing order, where... | int solution() {
int tc;
scanf("%d", &tc);
for (int i = 0; i < tc; i++) {
long long int n;
scanf("%lli\n", &n);
long long int arr[n + 1];
for (long long int l = 0; l < n; l++) {
scanf("%lli ", &arr[l]);
}
arr[n + 1] = -1;
long long int count = 1;
long long int flag = 0;
l... | fn solution() {
let stdin = stdin();
let mut buffer = String::new();
stdin.read_line(&mut buffer).unwrap();
let count: u32 = buffer.trim().parse().unwrap();
'a: for _ in 0..count {
stdin.read_line(&mut buffer).unwrap();
buffer.clear();
stdin.read_line(&mut buffer).unwrap... | medium |
1462 | <H1>Print Test Cases</H1>
<p>
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
</p>
<p>
Write a program which reads an integer <var>x</var> and p... | int solution() {
int n = 0;
int i = 1;
while (scanf("%d", &n) && n != 0) {
printf("Case %d: %d\n", i++, n);
}
return 0;
} | fn solution() {
let out = &mut BufWriter::new(stdout());
for i in 0..10000 {
let mut input = String::new();
stdin().read_line(&mut input).ok();
match input.trim().parse::<i32>() {
Ok(x) => {
writeln!(out, "Case {}: {}", i + 1, x).ok();
}
... | easy |
1463 | <H1>Shuffle</H1><br>
<p>
Your task is to shuffle a deck of <var>n</var> cards, each of which is marked by a alphabetical letter.
</p>
<p>
A single shuffle action takes out <var>h</var> cards from the bottom of the deck and moves them to the top of the deck.
</p>
<p>
The deck of cards is represented by a string... | int solution() {
char buf[2][201];
char *p1 = buf[0];
char *p2 = buf[1];
while (scanf("%s\n", p1) && strcmp(p1, "-") != 0) {
int m;
scanf("%d\n", &m);
while (m--) {
int h;
scanf("%d\n", &h);
int rest = strlen(p1) - h;
memcpy(p2, p1 + h, rest);
memcpy(p2 + rest, p1, h... | fn solution() {
let stdin = std::io::stdin();
let mut lines = stdin.lock().lines();
loop {
let word = lines.by_ref().next().unwrap().unwrap();
let word = word.trim();
if word == "-" {
break;
}
let m = lines
.by_ref()
.next()
... | medium |
1464 | Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself,... | int solution() {
int t;
int n;
scanf("%d", &t);
while (t--) {
int a[200001];
int b[200001];
int k = 1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = ((i + a[i]) % n + n) % n;
}
for (int i = 0; i < n - 1 && k != 0; i++) {
for (int j = i + ... | fn solution() {
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("Failed to read line");
let t: i32 = buffer.trim().parse().unwrap();
for _ in 0..t {
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.ex... | easy |
1465 | A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily $$$7$$$ days!In detail, she can choose any integer $$$k$$$ which satisfies $$$1 \leq k \leq r$$$, and set $$$k$$$ days as the number of days in a week.Alic... | int solution() {
int t;
int i;
long long A[1005];
long long B[1005];
scanf("%d\n", &t);
for (i = 0; i < t; i++) {
scanf("%lld %lld", &A[i], &B[i]);
if (A[i] > B[i]) {
A[i] = B[i] * (B[i] + 1) / 2;
} else {
A[i] = A[i] * (A[i] - 1) / 2 + 1;
}
}
for (i = 0; i < t; i++) {
p... | fn solution() {
let stdin = io::stdin();
let mut lines = stdin.lock().lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let xs: Vec<u64> = lines
.next()
.unwrap()
.unwrap()
.split(' ')
.map(|x| x.p... | medium |
1466 | Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.This day, Mocha got a sequence $$$a$$$ of length $$$n$$$. In each operation, she can select an ar... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int x = arr[0];
for (int i = 1; i < n; i++) {
x &= arr[i];
}
printf("%d\n", x);
}
return 0;
} | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let t = lines.next().unwrap().par... | hard |
1467 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are <var>N</var> rows with <var>N</var> seats each, forming an <var>N\times N</var> squa... | int solution() {
int i;
int N;
int P[250001];
scanf("%d", &N);
for (i = 1; i <= N * N; i++) {
scanf("%d", &(P[i]));
}
int j;
int min[502][502] = {};
int tmp;
for (i = 1; i <= (N + 1) / 2; i++) {
for (j = 1; j <= (N + 1) / 2; j++) {
tmp = ((i < j) ? i : j) - 1;
min[i][j] = tmp;
... | fn solution() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut buf_it = buf.split_whitespace();
let N = buf_it.next().unwrap().parse::<usize>().unwrap();
let P = (0..N * N)
.map(|_| buf_it.next().unwrap().parse::<usize>().unwrap() - 1)
.coll... | medium |
1468 | <H1>Reverse Sequence</H1>
<p>
Write a program which reverses a given string <var>str</var>.
</p>
<H2>Input</H2>
<p>
<var>str</var> (the size of <var>str</var> ≤ 20) is given in a line.
</p>
<H2>Output</H2>
<p>
Print the reversed <var>str</var> in a line.
</p>
<H2>Sample Input</H2>
<pre>
w32nimda
</pre>
<H2>Ou... | int solution(void) {
char word[21];
scanf("%s", word);
for (int i = 20; i >= 0; i--) {
if ((word[i] >= 48 && word[i] <= 57) || (word[i] >= 65 && word[i] <= 90) ||
(word[i] >= 97 && word[i] <= 122)) {
printf("%c", word[i]);
}
}
printf("\n");
} | fn solution() {
let mut buf = String::new();
if let Ok(_) = stdin().read_line(&mut buf) {
println!("{}", buf.trim().chars().rev().collect::<String>());
}
} | hard |
1469 | You are given four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$. Timur and three other people are running a marathon. The value $$$a$$$ is the distance that Timur has run and $$$b$$$, $$$c$$$, $$$d$$$ correspond to the distances the other three participants ran. Output the number of participants in front of Tim... | int solution() {
int tc = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int ahead = 0;
scanf("%d", &tc);
while (tc--) {
scanf("%d %d %d %d", &a, &b, &c, &d);
if (b > a) {
ahead++;
}
if (c > a) {
ahead++;
}
if (d > a) {
ahead++;
}
printf("%d\n", ahead);
... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).expect("E");
for _ in 0..(input.trim().to_string().parse::<u16>().unwrap()) {
input = String::new();
io::stdin().read_line(&mut input).expect("E");
let mut data: Vec<u16> = vec![];
for i in input... | hard |
1470 | Welcome to Rockport City!It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet $$$a$$$ dollars and Ronnie has bet $$$b$$$ dollars. But the fans seem to be disappointed. The excitement of the fans is given by $$$gcd(a,b)$$$, where $$$gcd(x, y)$$$ denotes the greatest ... | int solution(void) {
int tc;
scanf("%d", &tc);
while (tc-- > 0) {
long long a;
long long b;
scanf("%lld %lld", &a, &b);
if (a == b) {
puts("0 0");
continue;
}
if (a > b) {
long long t = a;
a = b;
b = t;
}
long long d = b - a;
long long lo = a / d *... | fn solution() {
let mut line = String::new();
stdin().read_line(&mut line).unwrap();
let t: i64 = line.trim().parse().unwrap();
for _ in 0..t {
line.clear();
stdin().read_line(&mut line).unwrap();
let words: Vec<i64> = line
.split_whitespace()
.map(|x| ... | medium |
1471 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is giving cookies to his three goats.</p>
<p>He has two cookie tins. One contains <var>A</var> cookies, and the other contains <var>B</var> cookies. He can thus give <var>A</var> cookies, <var>B</... | int solution() {
int a[4];
scanf("%d%d", &a[0], &a[1]);
if ((a[0] + a[1]) % 3 != 0 && a[0] % 3 != 0 && a[1] % 3 != 0) {
printf("Impossible");
} else {
printf("Possible");
}
} | fn solution() {
let stdin = io::stdin();
let mut buf = String::new();
stdin.read_line(&mut buf).ok();
let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
let (a, b) = (it.next().unwrap(), it.next().unwrap());
if a % 3 == 0 {
println!("Possible");
return;
... | easy |
1472 | You have a string $$$s_1 s_2 \ldots s_n$$$ and you stand on the left of the string looking right. You want to choose an index $$$k$$$ ($$$1 \le k \le n$$$) and place a mirror after the $$$k$$$-th letter, so that what you see is $$$s_1 s_2 \ldots s_k s_k s_{k - 1} \ldots s_1$$$. What is the lexicographically smallest st... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
char s[n];
scanf("%s", s);
int j = 1;
while ((s[j] < s[j - 1] && j < n) || (s[j] == s[j - 1] && j > 1)) {
j++;
}
for (int i = 0; i < j; i++) {
printf("%c", s[i]);
}
for (int i = j - 1... | fn solution() {
let mut buf = String::new();
let stdin = io::stdin();
let r = stdin.read_line(&mut buf);
match r {
Ok(_) => {}
_ => panic!("could not read from stdin"),
}
let n: u32 = buf.trim().parse().unwrap();
'testcases: for _i in 0..n {
let mut buf = String::ne... | hard |
1473 | Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $$$i$$$ ($$$1 \le i \le n-1$$$), this condition must be satisfied: $$$$$$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \le 2$$$$$$For example, the arrays $$$[1, 2, 3, 4, 3]$$$... | int solution() {
int t;
int n;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
int c = 0;
scanf("%d", &n);
int a[n];
for (int j = 0; j < n; j++) {
scanf("%d", &a[j]);
}
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1] * 2) {
int g = a[j + 1];
while (a[j] >... | fn solution() {
let (stdin, stdout) = (io::stdin(), io::stdout());
let mut sc = cf_scanner::Scanner::new(stdin.lock());
let mut out = io::BufWriter::new(stdout.lock());
let tc: usize = sc.next();
for _ in 0..tc {
let n: usize = sc.next();
let arr: Vec<i32> = (0..n).map(|_| sc.next()... | medium |
1474 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of digits between <code>1</code> and <code>9</code>, inclusive.
You can insert the letter <code>+</code> into some of the positions (possibly none) between... | int solution() {
long S[12];
int fig = 0;
long ans = 0;
int x;
S[0] = getc(stdin) - '0';
ans += S[0];
for (fig = 1; fig < 10; fig++) {
S[fig] = getchar() - '0';
if (S[fig] > 9 || S[fig] < 1) {
break;
}
ans *= 10;
for (x = 1; x <= fig; x++) {
ans += S[x - 1] * pow(2, fig -... | fn solution() {
input! {
S: chars,
}
let mut ans: u64 = 0;
for bit in 0..1 << (S.len() - 1) {
let mut acc_str = String::new();
let mut acc = 0_u64;
acc_str.push(S[0]);
for i in 0..S.len() - 1 {
if bit & 1 << i != 0 {
acc += acc_str.par... | hard |
1475 | Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ... | int solution() {
int n = 0;
scanf("%d", &n);
int pass = 0;
int capacity = 0;
for (int i = 0; i < n; i++) {
int exitt = 0;
int enter = 0;
scanf("%d %d\n", &exitt, &enter);
pass = pass + enter - exitt;
if (pass > capacity) {
capacity = pass;
}
}
printf("%d", capacity);
ret... | fn solution() {
let mut text = String::new();
std::io::stdin()
.read_line(&mut text)
.expect("cannot read line number");
let n = text.trim().parse::<u32>().expect("failed to parse");
let mut total = 0;
let mut max = 0;
for _ in 0..n {
let mut line = String::new();
... | hard |
1476 | A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are n... | int solution() {
int n;
scanf("%d", &n);
int letter;
int sig;
int occurences[40];
int correct = 1;
getc(stdin);
for (int i = 0; i < n; i++) {
correct = 1;
for (int j = 0; j < 40; j++) {
occurences[j] = 0;
}
while ((letter = getc(stdin)) != '\n' && letter != EOF) {
sig = lette... | fn solution() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let n: usize = input.trim().parse().unwrap();
input.clear();
for _ in 0..n {
io::stdin().read_line(&mut input).unwrap();
let mut s: Vec<char> = input.trim().chars().collect();
s.sort... | medium |
1477 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An adult game master and <var>N</var> children are playing a game on an ice rink.
The game consists of <var>K</var> rounds.
In the <var>i</var>-th round, the game master announces:</p>
<ul>
<li>Form gro... | int solution(void) {
long long k;
long long max = 2;
long long min = 2;
scanf("%lld", &k);
long long a[k];
for (int i = 0; i < k; i++) {
scanf("%lld", &a[i]);
}
for (int i = k - 1; i >= 0; i--) {
min = ((min + a[i] - 1) / a[i]) * a[i];
if (min > (max / a[i]) * a[i]) {
printf("-1\n");
... | fn solution() {
let mut buf: String = String::new();
io::stdin().read_line(&mut buf).unwrap();
buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let iter = buf.split_whitespace();
let mut nums: Vec<i64> = Vec::new();
for i in iter {
nums.push(i.parse::<i64>().unwrap());
... | medium |
1478 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns.
Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from t... | int solution() {
int h;
int w;
scanf("%d %d", &h, &w);
int i;
int j;
char a[1003][1003];
for (i = 0; i < h; i++) {
scanf("%s", a[i]);
}
long long int p = 1e9 + 7;
long long int dp[1003][1003];
for (i = 0; i <= h; i++) {
for (j = 0; j <= w; j++) {
dp[i][j] = 0;
}
}
dp[1][1] = ... | fn solution() {
input! {
h: usize,
w: usize,
boards: [chars; h],
}
let d = 1000000000 + 7;
let mut dp = vec![vec![0; w + 1]; h + 1];
let mut left;
let mut top;
for i in 0..h {
for j in 0..w {
if j > 0 {
left = if boards[i][j - 1] == '.... | easy |
1479 | Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.Chouti remembered that $$$n$$$ persons took part in that party. To make the party funnier, each person wore one hat among $$$n$$$... | int solution() {
int n;
scanf("%d", &n);
int i;
int en[n];
int con = 1;
int fre[n + 1];
int va[n + 1];
memset(fre, 0, sizeof fre);
for (i = 0; i < n; i++) {
scanf("%d", &en[i]);
en[i] = n - en[i];
fre[en[i]]++;
}
for (i = 0; i < n; i++) {
if (fre[en[i]] % en[i]) {
break;
... | fn solution() {
let stdin = io::stdin();
let mut input = stdin.lock();
let mut line = String::new();
input.read_line(&mut line).unwrap();
let total: i32 = line.trim().parse().unwrap();
line.clear();
let mut recalls: BTreeMap<i32, (i32, i32)> = BTreeMap::new();
let mut hats = Vec::with_ca... | hard |
1480 | Let $$$\mathsf{AND}$$$ denote the bitwise AND operation, and $$$\mathsf{OR}$$$ denote the bitwise OR operation.You are given an array $$$a$$$ of length $$$n$$$ and a non-negative integer $$$k$$$. You can perform at most $$$k$$$ operations on the array of the following type: Select an index $$$i$$$ ($$$1 \leq i \leq n$... | int solution() {
int test_cases;
scanf("%d", &test_cases);
int ans[test_cases];
for (int t = 0; t < test_cases; t++) {
int n;
int k;
scanf("%d %d", &n, &k);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int remaining = k;
for (int pos = 30; pos >= 0; pos-... | fn solution() {
let t = read!(u64);
for _i in 0..t {
let (_n, k) = read_pair!(usize);
let a: Vec<u32> = read_vec!(u32);
let mut bits: [u32; 31] = [0; 31];
for num in a {
for j in 0..31 {
let jth_bit = (num >> j) & 1;
if jth_bit == 0 {... | medium |
1481 | <span class="lang-en">
<p>Score: <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east.</p>
<p>They start simultaneously at the same point and moves as follows <strong>t... | int solution() {
long long int T1;
long long int T2;
long long int A1;
long long int A2;
long long int B1;
long long int B2;
scanf("%lld %lld", &T1, &T2);
scanf("%lld %lld", &A1, &A2);
scanf("%lld %lld", &B1, &B2);
long long int diff = (T1 * (A1 - B1)) + (T2 * (A2 - B2));
if (diff == 0) {
prin... | fn solution() {
let mut s = String::new();
use std::io::Read;
std::io::stdin().read_to_string(&mut s).unwrap();
let mut s = s.split_whitespace();
let t = (
s.next().unwrap().parse::<i64>().unwrap(),
s.next().unwrap().parse::<i64>().unwrap(),
);
let a = (
s.next().unwr... | easy |
1482 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two deer, AtCoDeer and TopCoDeer, are playing a game called <em>Honest or Dishonest</em>.
In this game, an honest player always tells the truth, and an dishonest player always tell lies.
You are given t... | int solution() {
char A = ' ';
char B = ' ';
scanf("%c %c", &A, &B);
if (A == B) {
printf("H");
} else {
printf("D");
}
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let iter = buf.split_whitespace();
let mut v: Vec<char> = Vec::new();
for i in iter {
v.push(i.chars().collect::<Vec<char>>()[0]);
}
if v[0] == 'H' {
println!("{}", v[1]);
} else {
... | easy |
1483 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>You are given three integers <var>A, B</var> and <var>C</var>.</p>
<p>Determine if there exists an equilateral triangle whose sides have lengths <var>A, B</var> and <var>C</var>.</p>
</section>
</div>
... | int solution() {
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &a, &b, &c);
if (a == b && b == c) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let mut three_iter = buf.split_whitespace().map(|s| s.parse::<u32>().unwrap());
let first = three_iter.next().unwrap();
match three_iter.all(|elem| elem == first) {
true => println!("Yes"),
false ... | medium |
1484 | Polycarp wrote on a whiteboard an array $$$p$$$ of length $$$n$$$, which is a permutation of numbers from $$$1$$$ to $$$n$$$. In other words, in $$$p$$$ each number from $$$1$$$ to $$$n$$$ occurs exactly once.He also prepared a resulting array $$$a$$$, which is initially empty (that is, it has a length of $$$0$$$).Afte... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[n + 1];
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
}
if (arr[1] != n && arr[n] != n) {
printf("-1\n");
} else {
printf("%d ", n);
for (int i = n; i >= 1; i--) {
... | fn solution() {
let (i, o) = (io::stdin(), io::stdout());
let mut o = bw::new(o.lock());
for l in i.lock().lines().skip(2).step_by(2) {
let v = l
.unwrap()
.split(' ')
.map(|w| w.parse::<u32>().unwrap())
.collect::<Vec<_>>();
let x = *v.iter().... | medium |
1485 | This is the easy version of the problem. The only difference is the constraints on $$$n$$$ and $$$k$$$. You can make hacks only if all versions of the problem are solved.You have a string $$$s$$$, and you can do two types of operations on it: Delete the last character of the string. Duplicate the string: $$$s:=s+s$$... | int solution() {
int n;
int k;
int a = 1;
scanf("%d %d", &n, &k);
char s[n + 1];
scanf("%s", s);
for (int i = 0; i < n; i++) {
if (s[i] > s[i % a]) {
break;
}
if (s[i] < s[i % a]) {
a = i + 1;
}
}
for (int i = 0; i < k; i++) {
putchar(s[i % a]);
}
printf("\n");
re... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|r| r.unwrap());
let s = lines.next().unwrap();
... | hard |
1486 | You had $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ arranged in a circle. For each pair of neighboring numbers ($$$a_1$$$ and $$$a_2$$$, $$$a_2$$$ and $$$a_3$$$, ..., $$$a_{n - 1}$$$ and $$$a_n$$$, and $$$a_n$$$ and $$$a_1$$$), you wrote down: are the numbers in the pair equal or not.Unfortunately, you've lost... | int solution() {
int n_case = 0;
scanf("%d", &n_case);
char s[52];
int n_sum = 0;
for (int ii = 0; ii < n_case; ++ii) {
scanf("%s", s);
n_sum = 0;
for (int i = 0; s[i] != '\0'; ++i) {
if (s[i] == 'N') {
++n_sum;
if (n_sum > 1) {
printf("YES\n");
break;
... | fn solution() {
let mut t = String::new();
io::stdin().read_line(&mut t).expect("input error");
let mut t: i32 = t.trim().parse().expect("input error");
while t > 0 {
let mut input = String::new();
io::stdin().read_line(&mut input).expect("input error");
if input.matches('N').cou... | medium |
1487 | Berland annual chess tournament is coming!Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.Thus, organizers should... | int solution() {
int n;
scanf("%d", &n);
int arr[2 * n];
int i = 0;
int j = 0;
for (i = 0; i < 2 * n; i++) {
scanf("%d ", &arr[i]);
}
for (i = 0; i < 2 * n; i++) {
for (j = i + 1; j < 2 * n; j++) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = ... | fn solution() {
let mut reader = BufReader::new(io::stdin());
let mut res = String::new();
reader
.read_to_string(&mut res)
.expect("Could not read stdin");
let values: Vec<&str> = res.split_whitespace().collect();
let n: usize = values[0].parse().unwrap();
let mut players: Vec<... | medium |
1488 | Bucket sort | void solution(int arr[]) {
const int NARRAY = 8;
const int NBUCKET = 5;
const int INTERVAL = 10;
int i, j;
struct Node **buckets;
buckets = (struct Node **)malloc(sizeof(struct Node *) * NBUCKET);
for (i = 0; i < NBUCKET; ++i) {
buckets[i] = NULL;
}
for (i = 0; i < NARRAY; ++i) {
struct No... | fn solution(arr: &[usize]) -> Vec<usize> {
if arr.is_empty() {
return vec![];
}
let max = *arr.iter().max().unwrap();
let len = arr.len();
let mut buckets = vec![vec![]; len + 1];
for x in arr {
buckets[len * *x / max].push(*x);
}
for bucket in buckets.iter_mut() {
... | medium |
1489 | <script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h2>Transformation</h2><br>
<p>... | int solution() {
char str[1000];
char operation[10];
int operation_number = 0;
int a = 0;
int b = 0;
int i = 0;
char p[1000];
char tmp;
scanf("%s", str);
scanf("%d", &operation_number);
while (operation_number > 0) {
scanf("%s %d %d", operation, &a, &b);
if (strcmp(operation, "replace") =... | fn solution() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
s = s.trim().to_string();
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
let n: i32 = n.trim().parse().unwrap();
for _ in 0..n {
let mut t = String::new();
io::stdin().rea... | medium |
1490 | You have a string $$$s$$$ consisting of digits from $$$0$$$ to $$$9$$$ inclusive. You can perform the following operation any (possibly zero) number of times: You can choose a position $$$i$$$ and delete a digit $$$d$$$ on the $$$i$$$-th position. Then insert the digit $$$\min{(d + 1, 9)}$$$ on any position (at the b... | int solution() {
int t;
scanf("%d", &t);
char str[200001];
for (int i = 0; i < t; i++) {
scanf("%s", str);
int arr[10];
int ind[10];
for (int j = 0; j < 10; j++) {
arr[j] = 0;
ind[j] = -1;
}
for (int j = 0; str[j] != '\0'; j++) {
arr[str[j] - 48]++;
ind[str[j]... | fn solution() {
let mut tests_str = String::new();
std::io::stdin().read_line(&mut tests_str).unwrap();
for _ in 0..tests_str.trim().parse::<usize>().unwrap() {
let mut s_str = String::new();
std::io::stdin().read_line(&mut s_str).unwrap();
let mut new_chars = Vec::new();
l... | medium |
1491 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> empty boxes arranged in a row from left to right.
The integer <var>i</var> is written on the <var>i</var>-th box from the left <var>(1 \leq i \leq N)</var>.</p>
<p>For each of the... | int solution(void) {
int N;
scanf("%d", &N);
int a[N];
for (int i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
int ans[N];
for (int i = 0; i < N; i++) {
ans[i] = 0;
}
int ball = 0;
for (int i = N; i >= 1; i--) {
if (i == 1) {
if (ball % 2 != a[i - 1]) {
ans[i - 1] = 1;
... | fn solution() {
let mut n = String::new();
stdin().read_line(&mut n).unwrap();
let n: usize = n.trim().parse().unwrap();
let mut array = String::new();
stdin().read_line(&mut array).unwrap();
let array: Vec<u8> = array.split_whitespace().flat_map(str::parse).collect();
let mut boxes = [0; 2... | medium |
1492 | You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. Polycarp wants to remove exactly $$$k$$$ characters ($$$k \le n$$$) from the string $$$s$$$. Polycarp uses the following algorithm $$$k$$$ times: if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, oth... | int solution() {
int n;
int k;
scanf("%d %d\n", &n, &k);
char str[n + 1];
scanf("%s", str);
int count = 0;
for (int i = 0; i < 26 && count < k; i++) {
for (int j = 0; j < n; j++) {
if (str[j] == i + 97 && count < k) {
str[j] = '.';
count++;
} else if (count == k) {
... | fn solution() {
let stdin: io::Stdin = io::stdin();
let mut lines: io::Lines<io::StdinLock> = stdin.lock().lines();
let next_line = lines.next().unwrap().unwrap();
let flv: Vec<_> = next_line
.trim()
.split(' ')
.map(|n| n.parse::<u32>().unwrap())
.collect();
let k... | hard |
1493 | Timur has a stairway with $$$n$$$ steps. The $$$i$$$-th step is $$$a_i$$$ meters higher than its predecessor. The first step is $$$a_1$$$ meters higher than the ground, and the ground starts at $$$0$$$ meters. The stairs for the first test case. Timur has $$$q$$$ questions, each denoted by an integer $$$k_1, \dots, k... | int solution() {
int zushu;
scanf("%d", &zushu);
for (int zu = 1; zu <= zushu; zu++) {
int n;
int q;
scanf("%d%d", &n, &q);
if (zu != 1) {
printf("\n");
}
long long int step[n + 1][2];
long long int temp;
step[0][0] = 0;
step[0][1] = 0;
for (int i = 1; i <= n; i++) {... | fn solution() {
let t: usize = {
let mut line: String = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
};
for _ in 0..t {
let (n, q): (usize, usize) = {
let mut line: String = String::new();
std::io::stdin(... | medium |
1494 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.</p>
<p>The bulletin board is in the form of a grid with <var>N</var> r... | int solution() {
int w = 0;
int h = 0;
int n = 0;
scanf("%d", &n);
scanf("%d", &h);
scanf("%d", &w);
if (h == n && w == n) {
printf("%d", 1);
} else if ((n - w) == 0 || (n - h) == 0) {
printf("%d", ((n - h) + 1) * ((n - w) + 1));
} else {
printf("%d", ((n - w) + 1) * ((n - h) + 1));
}
} | fn solution() {
let mut buf = String::new();
let handle = std::io::stdin();
let n: isize = {
handle.read_line(&mut buf).unwrap();
let tmp = buf.trim().parse().unwrap();
buf.clear();
tmp
};
let h: isize = {
handle.read_line(&mut buf).unwrap();
let tmp ... | easy |
1495 | "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme.""Little Alena got an array as a birthday present..."The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure:b1 = b2 = b3 = b4 ... | int solution(void) {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
char b[n + 1];
scanf("%s", b);
int lmin = -1000000000;
int rmax = 1000000000;
for (int i = 4; i < n; i++) {
bool same = true;
for (int j = 1; j < 4; j++) {
if (b[i - j] != ... | fn solution() {
let mut input = String::new();
use std::io;
use std::io::prelude::*;
io::stdin().read_to_string(&mut input).unwrap();
let mut it = input.split_whitespace();
let n: usize = it.next().unwrap().parse().unwrap();
let mut a = Vec::with_capacity(n);
for _ in 0..n {
l... | medium |
1496 | <H1>A + B Problem</H1>
<p>
Compute A + B.
</p>
<H2>Input</H2>
<p>
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
</p>
<H2>Output</H2>
<p>
For each pair of input integers A and B, you must output the sum o... | int solution() {
int a = 0;
int b = 0;
while (scanf("%d %d", &a, &b) != EOF) {
printf("%d\n", a + b);
}
return 0;
} | fn solution() {
let mut input: String;
loop {
input = String::new();
match std::io::stdin().read_line(&mut input) {
Ok(0) => {
break;
}
Ok(_) => {
println!(
"{}",
input
... | medium |
1497 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><var>N</var> friends of Takahashi has come to a theme park.</p>
<p>To ride the most popular roller coaster in the park, you must be at least <var>K</var> centimeters tall.</p>
<p>The <var>i</var>-th fr... | int solution() {
int i = 0;
int n = 0;
int k = 0;
int h[10000000];
int result = 0;
scanf("%d %d", &n, &k);
while (i < n) {
if (i < n - 1) {
scanf("%d ", &h[i]);
} else {
scanf("%d", &h[i]);
}
if (h[i] >= 1 && h[i] <= 500) {
if (h[i] >= k) {
result++;
} el... | fn solution() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).expect("");
let mut iter = buf.split_whitespace();
let n = match iter.next().unwrap().parse::<i32>() {
Ok(m) => m,
_ => panic!(""),
};
let k = match iter.next().unwrap().parse::<i32>() {
Ok(m) =>... | medium |
1498 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> integers, <var>A_1, A_2, ..., A_N</var>, written on a blackboard.</p>
<p>We will repeat the following operation <var>N-1</var> times so that we have only one integer on the blackb... | int solution(void) {
long n;
scanf("%ld", &n);
long a[n];
for (long i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
long plus = 0;
long minus = 0;
long sum = 0;
long abs;
long min = -1;
long min_i;
for (long i = 0; i < n; i++) {
if (a[i] >= 0) {
plus++;
abs = a[i];
} else {
... | fn solution() {
let mut stdin = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
let mut stdin = stdin.split_whitespace();
let mut get = || stdin.next().unwrap();
let n = get!(usize);
let mut vs = vec![];
for _ in 0..n {
let v = get!();
... | hard |
1499 | Nastia has received an array of $$$n$$$ positive integers as a gift.She calls such an array $$$a$$$ good that for all $$$i$$$ ($$$2 \le i \le n$$$) takes place $$$gcd(a_{i - 1}, a_{i}) = 1$$$, where $$$gcd(u, v)$$$ denotes the greatest common divisor (GCD) of integers $$$u$$$ and $$$v$$$.You can perform the operation: ... | int solution() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d ", &a[i]);
}
printf("%d\n", n / 2);
for (int i = 0; i < n - 1; i += 2) {
printf("%d %d %d %d\n", i + 1, i + 2, a[i] < a[i + 1] ? a[i] : a[i + 1],... | fn solution() {
let std_in = stdin();
let in_lock = std_in.lock();
let input = BufReader::new(in_lock);
let std_out = stdout();
let out_lock = std_out.lock();
let mut output = BufWriter::new(out_lock);
let mut lines = input.lines().map(|x| x.unwrap());
let t = lines.next().unwrap().pa... | hard |
1500 | <H1>BMI</H1>
<p>
肥満は多くの成人病の原因として挙げられています。過去においては、一部の例外を除けば、高校生には無縁なものでした。しかし、過度の受験勉強等のために運動不足となり、あるいはストレスによる過食症となることが、非現実的なこととはいえなくなっています。高校生にとっても十分関心を持たねばならない問題になるかもしれません。
</p>
<p>
そこで、あなたは、保健室の先生の助手となって、生徒のデータから肥満の疑いのある生徒を探し出すプログラムを作成することになりました。
</p>
<p>
方法は BMI (Body Mass Index) という数値を算出する方法です。BMIは次の式で与えられます。
</p... | int solution(void) {
int num[50];
int c = 0;
double h[50];
double w[50];
while (scanf("%d,%lf,%lf", &num[c], &w[c], &h[c]) != EOF) {
if ((w[c] / (h[c] * h[c])) >= 25) {
printf("%d\n", num[c]);
}
c++;
}
return 0;
} | fn solution() {
loop {
let mut input = String::new();
match std::io::stdin().read_line(&mut input).unwrap() {
0 => break,
_ => {
let v: Vec<&str> = input.trim().split(',').collect();
let (w, h): (f64, f64) = (v[1].parse().unwrap(), v[2].parse()... | easy |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.