prob_desc_description stringlengths 63 3.8k | prob_desc_output_spec stringlengths 17 1.47k ⌀ | lang_cluster stringclasses 2 values | src_uid stringlengths 32 32 | code_uid stringlengths 32 32 | lang stringclasses 7 values | prob_desc_output_to stringclasses 3 values | prob_desc_memory_limit stringclasses 19 values | file_name stringclasses 111 values | tags listlengths 0 11 | prob_desc_created_at stringlengths 10 10 | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_notes stringlengths 4 3k ⌀ | exec_outcome stringclasses 1 value | difficulty int64 -1 3.5k ⌀ | prob_desc_input_from stringclasses 3 values | prob_desc_time_limit stringclasses 27 values | prob_desc_input_spec stringlengths 28 2.42k ⌀ | prob_desc_sample_outputs stringlengths 2 796 | source_code stringlengths 42 65.5k | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 3e87959b0da98a7e222d2b688c23dbb7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | /*
* Coder: @SumitRaut
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>
int Min(int x,int y) { return y^((x^y)&-(x<y)); }
int Max(int x,int y) { return y^((x^y)&-(y<x)); }
void smin(int* a, int b) { if(*a>b) *a=b; }
int main()
{
#ifndef ONLINE_JUDGE
freopen("int.txt","r",stdin);
#endif
int t,q,n,k,ans,i,sq;scanf("%d",&t); while(t--) {
scanf("%d%d",&n,&k);
ans=n;
sq=sqrt(n)+1;
i=2;
if(n<=k)
ans=1;
else {
while(i<sq) {
if(n%i==0) {
q=n/i;
if(q<=k) {
smin(&ans,i);
break;
}
if(i<=k)
smin(&ans,q);
}
++i;
}
}
printf("%d\n",ans);
}
return 0;
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 0c1d06b2dc577429c2edb9d449fb5b8b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
#include<stdlib.h>
typedef long long int ll;
int finddivisor(int n,int k)
{
int a=0;
for(int i=1;i<=n/i;i++)
{
if(n%i==0)
{
if(i<=k)
a=i>a?i:a;
if((n/i)<=k)
a=(n/i)>a?(n/i):a;
}
}
return a;
}
int main()
{
int t,n,k,d;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&k);
d=finddivisor(n,k);
printf("%d\n",(n/d));
}
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | e249455c859a4111ad8db8cca6a350f5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
#include<math.h>
void pd(int n,int k)
{
int i,q1,q2,max=1;
for (int i=sqrt(n); i>=1; i--)
{
if (n%i == 0)
{
q1=i;
q2=n/i;
if(q1>max && q1<=k)
max=q1;
if(q2>max && q2<=k)
max=q2;
}
}
printf("%d\n",n/max);
}
int main()
{
int t,n,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
if(n<=k)
{
printf("1\n");
}
else
{
pd(n,k);
}
}
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 16daf2e706658c2e8a0a4e61687d5ab5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#define MOD 1000000007
#define PI 3.14159265
#define seive_len 1000001
int *array;
int seive[seive_len];
int prime_prime[seive_len];
int min(int a, int b) {
return a<b?a:b;
}
int max(int a, int b) {
return a>b?a:b;
}
int compare(const void* a, const void* b) {
return *(int*)a-*(int*)b;
}
int cmp(const void *a, const void *b){
int ia = *(int *)a;
int ib = *(int *)b;
return array[ia] < array[ib] ? -1 : array[ia] > array[ib];
}
int abs(int n) {
if(n < 0)
return n*(-1);
return n;
}
void swap(int *a, int *b) {
*a = (*a)^(*b);
*b = (*a)^(*b);
*a = (*a)^(*b);
}
int binSearch(int a[], int x, int l, int r) {
if(r >= l) {
int mid = l + ((r-l)>>1);
if(a[mid] == x)
return mid;
if(a[mid] > x) {
return binSearch(a, x, l, mid-1);
}
else if(a[mid] < x) {
return binSearch(a, x, mid+1, r);
}
}
return -1;
}
void makeSeive() {
int i;
seive[1] = 1;
for(i=2;i<seive_len;i++) {
if(seive[i] == 0) {
long long int temp=(long long int)i*i;
while(temp <= 1000000) {
seive[temp] = 1;
temp += i;
}
}
}
}
int isPrime(int n) {
int i;
for(i=2;i*i<=n;i++) {
if(n%i == 0)
return 0;
}
return 1;
}
void testCase() {
int n, k, i;
scanf("%d%d", &n, &k);
if(k>=n) {
printf("1");
return;
}
if(isPrime(n)) {
printf("%d", n);
return;
}
int x = sqrt(n), res = INT_MIN;
x = min(k, x);
for(i=1;i<=x;i++) {
if(n%i == 0) {
if(n/i <= k) {
int x = max(n/i, i);
res = max(res, x);
}
else {
res = max(res, i);
}
}
}
printf("%d", n/res);
}
int main() {
int t=1;
scanf("%d", &t);
while(t--) {
testCase();
printf("\n");
}
return 0;
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | fe187c83dffa630f650fc6b9bd7fcfb3 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
int main()
{
int t,j;
scanf("%d",&t);
for(j=0;j<t;j++)
{
int n,k,max=0,f=0;
scanf("%d %d",&n,&k);
int i;
for(i=1;i*i<=n&&i<=k;i++)
{
if(n%i==0&&n/i<=k)
{
printf("%d\n",i);
f=1;
break;
}
else if(n%i==0)
max=n/i;
}
if(f==0)
printf("%d\n",max);
}
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 7d0a7072a6d821ccbc81b70229313f52 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include "stdio.h"
int factor(int a, int b)
{
int f = 1;
for(int i = 2; i * i <= a && i <= b; i++)
if(a % i == 0)
{
if(a / i <= b)
{
f = a / i;
break;
}
else
f = i;
}
return f;
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
int n, k, ans;
scanf("%d%d",&n,&k);
ans = k >= n ? 1 : n / factor(n, k);
printf("%d\n",ans);
}
return 0;
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 2dcab0f844c38febae5fbb31b93766f8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include <stdio.h>
#include <stdlib.h>
#define N 109
int min(int a, int b)
{
if (a<b)
return a;
return b;
}
// int cmpfunc (const void * a, const void * b) {
// return ( *(int*)a - *(int*)b );
// }
// qsort(values, 5, sizeof(int), cmpfunc);
int main() {
int t,n,k,i, ans;
scanf("%d", &t);
while (t--){
scanf("%d%d", &n, &k);
int smallDiv = 0;
int bigDiv = 1;
ans = n;
while ( (++smallDiv)*smallDiv <= n ){
if (n%smallDiv == 0){
bigDiv = n/smallDiv;
if (bigDiv <=k)
ans = min(smallDiv, ans);
if (smallDiv <= k)
ans = min(bigDiv, ans);
}
}
printf("%d\n", ans);
}
return 0;
}
| |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | f6cdc3e793de91b68bafd533818f732a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i=0,j;
char a[101], b[101], c[101];
scanf("%s %s %s",a,b,c);
for(int j=0;j<strlen(a);j++)
{
if(a[j]==c[j] || b[j]==c[j])
i++;
}
if (i==strlen(a))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
| |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | 4259c92871b308a13ad9ffc1e1599fc5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
char A[101],B[101],C[101];
int i,l;
scanf("%s",A);
l=strlen(A);
scanf("%s",B);
scanf("%s",C);
for(i=0;i<l;i++)
{
if(C[i]!=A[i]&&C[i]!=B[i])
{
break;
}
}
if(i<l)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}
| |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | 13e91332c801f286c001b8c8110ac5fc | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int t,i;
char a[102],b[102],c[102];
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
getchar();
scanf("%s",b);
getchar();
scanf("%s",c);
getchar();
for(i=0;i<strlen(c);i++)
{
if((a[i]==b[i]&&a[i]==c[i])||a[i]==c[i]||b[i]==c[i])
continue;
else break;
}
if(i==strlen(c)) printf("YES\n");
else printf("NO\n");
}
return 0;
}
| |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | a331f08d96119afad0d362c01ca21737 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int t,i;
char a[102],b[102],c[102],ch1,ch2,ch3;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
getchar();
scanf("%s",b);
getchar();
scanf("%s",c);
getchar();
for(i=0;i<strlen(c);i++)
{
if((a[i]==b[i]&&a[i]==c[i])||a[i]==c[i]||b[i]==c[i])
continue;
else break;
}
if(i==strlen(c)) printf("YES\n");
else printf("NO\n");
}
return 0;
}
| |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | b38baa416f7071c3b7047298ea4d5c65 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char a[100], b[100], c[100];
void check ()
{
int i;
scanf("%s %s %s", a, b, c);
for (i = 0; i < strlen(a); i++)
{
if (c[i] != a[i] && c[i] != b[i])
{ printf ("NO\n"); return; }
}
printf ("YES\n");
return;
}
int main (int argc, char *argv[])
{
int t;
scanf ("%d", &t);
while (t--)
{ check(); }
exit (0);
} | |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | cc66d3273c0d9e39d54818481223404f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t--){
int cnt=0;
char a[1000];
char b[1000];
char c[1000];
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
for(int i=0;i<strlen(a);i++){
if(c[i]!=a[i] && c[i]!=b[i]){
printf("NO\n");
cnt++;
break;
}
}
if(cnt==0){
printf("YES\n");
}
}
} | |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | 7b5d276de6a33324ee1ed9b577c8b74a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
char a[101],b[101],c[101];
scanf("%s%s%s",a,b,c);
int x;
x=strlen(c);
for(int i=0;i<x;i++){
if(c[i]!=b[i] && c[i]!=a[i]){
printf("NO\n");
break;
}
else if(i==x-1){
printf("YES\n");
}
}
}
return 0;
}
| |
You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$? | Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers. | C | 08679e44ee5d3c3287230befddf7eced | ff236d163b9e076cfa4d873cdf40fe18 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1581604500 | ["4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim"] | NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$. | PASSED | 800 | standard input | 1 second | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$. | ["NO\nYES\nYES\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
char a[210],b[200],c[200];
int t,z=0,i,j,l;
scanf("%d",&t);
for(j=0;j<t;j++)
{
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
l=strlen(a);
for(i=0;i<l;i++)
{
if(a[i]!=c[i]&&b[i]!=c[i])
{
z=1;
}
}
if(z==0)
printf("YES\n");
else if (z==1)
printf("NO\n");
z=0;
}
}
| |
You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which area exceeds S.Alyona tried to construct a triangle with integer coordinates, which contains all n points and which area doesn't exceed 4S, but, by obvious reason, had no success in that. Please help Alyona construct such triangle. Please note that vertices of resulting triangle are not necessarily chosen from n given points. | Print the coordinates of three points — vertices of a triangle which contains all n points and which area doesn't exceed 4S. Coordinates of every triangle's vertex should be printed on a separate line, every coordinate pair should be separated by a single space. Coordinates should be an integers not exceeding 109 by absolute value. It is guaranteed that there is at least one desired triangle. If there is more than one answer, print any of them. | C | d7857d3e6b981c313ac16a9b4b0e1b86 | efdcd4dbe6a0b7a628c6a257431ee4e7 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"two pointers",
"geometry"
] | 1466181300 | ["4 1\n0 0\n1 0\n0 1\n1 1"] | Note | PASSED | 2,600 | standard input | 3 seconds | In the first line of the input two integers n and S (3 ≤ n ≤ 5000, 1 ≤ S ≤ 1018) are given — the number of points given and the upper bound value of any triangle's area, formed by any three of given n points. The next n lines describes given points: ith of them consists of two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — coordinates of ith point. It is guaranteed that there is at least one triple of points not lying on the same line. | ["-1 0\n2 0\n0 2"] | // Long time no C!
#include <stdio.h>
#define MAXN 5005
typedef long long int64;
int64 abs(int64 x) { return x > 0 ? x : -x; }
int n;
int x[MAXN], y[MAXN];
//int64 s;
int64 area(int i, int j, int k)
{
return abs(
(int64)(x[j] - x[i]) * (y[k] - y[i]) -
(int64)(y[j] - y[i]) * (x[k] - x[i]));
}
int main()
{
int i, a, b, c;
scanf("%d%*I64d", &n);
for (i = 0; i < n; ++i) scanf("%d%d", &x[i], &y[i]);
a = 0, b = 1, c = 2;
unsigned char updated = 1;
while (updated) {
updated = 0;
for (i = 0; i < n; ++i) {
if (area(a, b, i) > area(a, b, c)) { c = i; updated = 1; }
if (area(a, i, c) > area(a, b, c)) { b = i; updated = 1; }
if (area(i, b, c) > area(a, b, c)) { a = i; updated = 1; }
}
}
printf("%d %d\n%d %d\n%d %d\n",
-x[a] + x[b] + x[c], -y[a] + y[b] + y[c],
x[a] - x[b] + x[c], y[a] - y[b] + y[c],
x[a] + x[b] - x[c], y[a] + y[b] - y[c]);
return 0;
}
| |
You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which area exceeds S.Alyona tried to construct a triangle with integer coordinates, which contains all n points and which area doesn't exceed 4S, but, by obvious reason, had no success in that. Please help Alyona construct such triangle. Please note that vertices of resulting triangle are not necessarily chosen from n given points. | Print the coordinates of three points — vertices of a triangle which contains all n points and which area doesn't exceed 4S. Coordinates of every triangle's vertex should be printed on a separate line, every coordinate pair should be separated by a single space. Coordinates should be an integers not exceeding 109 by absolute value. It is guaranteed that there is at least one desired triangle. If there is more than one answer, print any of them. | C | d7857d3e6b981c313ac16a9b4b0e1b86 | 1fc6fad98927020e23883e6670b26dc3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"two pointers",
"geometry"
] | 1466181300 | ["4 1\n0 0\n1 0\n0 1\n1 1"] | Note | PASSED | 2,600 | standard input | 3 seconds | In the first line of the input two integers n and S (3 ≤ n ≤ 5000, 1 ≤ S ≤ 1018) are given — the number of points given and the upper bound value of any triangle's area, formed by any three of given n points. The next n lines describes given points: ith of them consists of two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — coordinates of ith point. It is guaranteed that there is at least one triple of points not lying on the same line. | ["-1 0\n2 0\n0 2"] | #include <stdio.h>
#include <stdlib.h>
long long int *x, *y;
static long long int area(int a, int b, int c) {
long long int S;
S = (x[a] - x[c]) * (y[b] - y[c]) - (y[a] - y[c]) * (x[b] - x[c]);
if(S < 0) S = -S;
return S;
}
int main() {
int n, i, a, b, c;
long long int S, T;
scanf("%d%*s", &n);
x = malloc(n * sizeof(*x));
y = malloc(n * sizeof(*y));
for(i = 0; i < n; i++) {
scanf("%I64d%I64d", &x[i], &y[i]);
}
a = 0;
b = 1;
c = 2;
S = area(a, b, c);
again:
for(i = 0; i < n; i++) {
T = area(i, b, c);
if(T > S) {
S = T;
a = i;
goto again;
}
T = area(a, i, c);
if(T > S) {
S = T;
b = i;
goto again;
}
T = area(a, b, i);
if(T > S) {
S = T;
c = i;
goto again;
}
}
printf("%I64d %I64d\n", x[b] + x[c] - x[a], y[b] + y[c] - y[a]);
printf("%I64d %I64d\n", x[c] + x[a] - x[b], y[c] + y[a] - y[b]);
printf("%I64d %I64d\n", x[a] + x[b] - x[c], y[a] + y[b] - y[c]);
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | ab123d4ab5c81d5b3dbe188f07e05a75 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int qcase,l1,l2,r1,r2;
scanf("%d",&qcase);
while(qcase--)
{
scanf("%d %d %d %d",&l1,&r1,&l2,&r2);
printf("%d %d\n", r1, r1 != l2 ? l2 : r2);
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 272c989fec58204d7de46a4c71f9df8d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main(){
int l1, l2, r1, r2;
int p, i;
scanf("%d", &p);
for(i = 0; i < p; i++){
scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
if(l1==l2&&r1==r2){
printf("%d %d", r1, l1);
}else if(l1==l2&&r1!=r2){
printf("%d ", l1);
if(r1 < r2){
printf("%d", r1);
}else{
printf("%d", r2);
}
}else if(l1!=l2&&r1==r2){
if(l1 < l2){
printf("%d %d", l2, r1);
}else{
printf("%d %d", l1, r1);
}
}else if(l1 < l2&&r2 < r1){
printf("%d %d", l2, r2);
}else if(l1 > l2&&r2 > r1){
printf("%d %d", l1, r1);
}else{
printf("%d %d", (l1+r1)/2, (l2+r2)/2);
}
if(i != (p-1)){
printf("\n");
}
}
return 0;
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | bc9970d54991cd50d6f551809365ec93 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
main()
{
int n, a, b, c, d, i, j;
scanf("%d", &n);
while (n--)
{
scanf("%d%d%d%d", &a, &b, &c, &d);
for (i = a; i <= b; i++)
{
for (j = c; j <= d; j++)
if (i != j)
{
printf("%d %d\n", i, j);
break;
}
break;
}
}
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | fa3b7941ce5b800a5daa4a6180521057 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int a,b,c,d,t,i=0;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a==c)
a++;
printf("%d %d\n",a,c);
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 70faab091f4a732cc212d1b652e3513f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
{
int num1,num2,num3,num4;
scanf("%d %d %d %d",&num1,&num2,&num3,&num4);
if(num1==num3&&num2==num4)
{
printf("%d %d",num1,num2);
printf("\n");
}
else if(num1!=num3)
{
printf("%d %d",num1,num3);
printf("\n");
}
else if(num1!=num4)
{
printf("%d %d",num1,num4);
printf("\n");
}
else if(num2!=num3)
{
printf("%d %d",num2,num3);
printf("\n");
}
else
{
printf("%d %d",num2,num4);
printf("\n");
}
}
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | f3af6d78e2ddaaa95acffd5e8cd1646d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
int main(){
int n;
scanf("%d", &n);
while(n--){
int l1, r1, l2, r2;
scanf("%d %d", &l1, &r1);
scanf("%d %d", &l2, &r2);
if(l1!=r2){
printf("%d %d", l1, r2);
}
else if(l1==r2){
printf("%d ", l1);
int ans;
if(l2>r2){
ans=r2;
}
else{
ans=l2;
}
if(ans==l1){
printf("%d", ans+1);
}
else{
printf("%d", ans);
}
}
printf("\n");
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 9facb9cde6e3f00e078ce50b187132b4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
int main(){
int n, l1, r1, l2, r2;
scanf("%d", &n);
while(n--){
scanf("%d %d\n%d %d", &l1, &r1, &l2, &r2);
if(l1 == r1){
printf("%d %d\n", l1, l1 != l2 ? l2 : r2);
} else{
printf("%d %d\n", l2 != l1 ? l1: r1, l2);
}
}
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 310003e6f11602221eaf505a0ac6ffcd | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
int a,b,c,d,min=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
if (a!=d)
{
printf("%d %d",a,d );
}
else
if (a==d)
{
printf("%d %d",a,c );
}
printf("\n");
}
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 1d527c20c73a79794b9942e484be14da | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main() {
int n,l,r,L,R;
scanf("%d",&n);
while(n--)
{
scanf("%d%d%d%d",&l,&r,&L,&R);
if(l!=R)
{
printf("%d %d\n",l,R);
}
else
{
printf("%d %d\n",r,L);
}
}
}
//sayeedi mottakin | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 4228a857a7d65aae80ad917b8989858c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main() {
int l1,r1,l2,r2;
int q1,q2;
int n;
int i;
scanf("%d",&n);
for(i=0; i<n; i++) {
scanf("%d %d %d %d",&l1,&r1,&l2,&r2);
q1=l1;
q2=l2;
if(q1==q2) {
q2=l2+1;
}
printf("%d %d\n",q1,q2);
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | d139b78be0696c99842e749fbd506d37 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | // Two Distinct Point
#include<stdio.h>
int main(void) {
int Q;
long int l1, l2, r1, r2;
scanf("%d", &Q);
while (Q--) {
scanf("%ld%ld%ld%ld", &l1, &r1, &l2, &r2);
if (l1 != r2)
printf("%ld %ld\n", l1, r2);
else {
printf("%ld %ld\n", r1, l2);
}
}
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 4c82aa2fea81c85ab58d414318033ba9 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
long int l1,r1,l2,r2;
int i,q;
scanf("%d",&q);
for(i=0;i<q;i++)
{
scanf("%ld %ld %ld %ld",&l1,&r1,&l2,&r2);
if(l1==r2)
printf("%ld %ld\n",l1,l2);
else
printf("%ld %ld\n",l1,r2);
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | acaee453c76a2dae32eb124a5ef7e1b6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
int l1,r1,l2,r2;
while(t-->0)
{
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
int b=r2;
for(int a=l1;a<=r1 && b>=l2;a++,b--)
{
if(a!=b)
{
printf("%d %d\n",a,b);
break;
}
}
}
return 0;
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | c8b194e380077b1cc8568ac8caf8254b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,x,y;
scanf("%d%d%d%d",&a,&b,&x,&y);
if(a>x&&b<y)
printf("%d %d",a,y);
else if(a<x&&b<y)
printf("%d %d",a,y);
else if(a>x&&b>y)
printf("%d %d",b,x);
else if(a==x&&b==y)
printf("%d %d",a,y);
else if(a==x&&b<y)
printf("%d %d",a,y);
else if(a>x&&b==y)
printf("%d %d",a,y);
else if(a<x&&b>y)
printf("%d %d",a,y);
else if(a==x&&b>y)
printf("%d %d",a,y);
else if(a<x&&b==y)
printf("%d %d",a,y);
printf("\n");
}
return 0;
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 2caea3cbff324a3352f7809da54d2799 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int i,j,k,l,n,f,a,b;
scanf("%d",&n);
for(f=1;f<=n;f++)
{
scanf("%d%d%d%d",&i,&j,&k,&l);
a=(i+j)/2;
b=(k+l)/2;
if(a!=b)
{
printf("%d ",a);
printf("%d\n",b);
}
else
{
printf("%d ",a+1);
printf("%d\n",b);
}
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 9668643d54cf45ab4a8e95fb10c5a60c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main(){int a[500],b[500],c[500],d[500];
int g,h;
scanf("%d",&g);
for(h=0;h<g;h++){
scanf("%d%d%d%d",&a[h],&b[h],&c[h],&d[h]);
}
for(h=0;h<g;h++)
{
{if (a[h]!=d[h])
{printf("%d %d",a[h],d[h]);
printf("\n");
continue ;}
if(b[h]!=c[h])
{printf("%d %d",b[h],c[h]);
printf("\n");
continue;}
if(a[h]==c[h]&&b[h]==d[h])
{printf("%d %d",a[h],d[h]);
printf("\n");
continue;}
}
printf("\n");
}
return 0;}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | df35c667fe488a79f8bcbd1d9f4dca0c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
#include <math.h>
int main()
{ long long int j,p,i,t,l1,l2,r1,r2,c=0,d=0;
scanf("%lld",&t);
for(i=1;i<=t;i++)
{ scanf("%lld %lld %lld %lld",&l1,&r1,&l2,&r2);
if(l1!=l2){
printf("%lld %lld\n",l1,l2);
}
else if(l1==l2)
{
printf("%lld %lld\n",l1,l2+1);
}
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 0da7d7d904de392ffa9d2b9c4cdcce9d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int q,a,b,c,d,i;
scanf("%d",&q);
for(i=1;i<=q;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
if(c<=b&&d>=b)
{
if(a==b)
printf("%d %d\n",a,b-1);
else
printf("%d %d\n",a,b);
}
else if(c>b||d<b)
{
if(a==d)
printf("%d %d\n",a,d-1);
else
printf("%d %d\n",a,d);
}
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 40547659886d45104b37721193a24db8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a,b,c,d;
while(n--){
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a==c)
{
if(b>a)
printf("%d %d\n",a+1,c);
else
printf("%d %d\n",a,c+1);
}
else
printf("%d %d\n",a,c);
}
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 95d47d29015aaa1cfe5a241d5a636d4c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
int main(){
int q,L1[500],L2[500],R2[500],R1[500],m[500];
int i,t,h=0,hh=0,tt;
scanf("%d",&q);
for (i=1;i<=q;i++)
scanf("%d%d%d%d",&L1[i],&R1[i],&L2[i],&R2[i]);
for (i=1;i<=q;i++){
h=L1[i];
if (L1[i]==R2[i]) hh=L2[i];
else hh=R2[i];
printf("%d %d\n",h,hh);
}
return 0;
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | d8bd67a781d9386c5f860938b8588c9b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
int main()
{
int q;
scanf("%d",&q);
while(q--)
{
int l1,r1,l2,r2;
scanf("%d %d %d %d",&l1,&r1,&l2,&r2);
int a=(l1+r1)/2,b=(l2+r2)/2;
int c=(l1+r1+1)/2,d=(l2+r2+1)/2;
int e=(l1+r1-1)/2,f=(l2+r2-1)/2;
if(a!=b)
{
printf("%d %d\n",a,b);
}
else
{
if(b!=c)
{
printf("%d %d\n",c,b);
}
else
{
printf("%d %d\n",e,b);
}
}
}
return 0;
}
| |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | a4d6a07d55fb5dbaa1c87e1969f9a6d8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include<stdio.h>
int main(){
int n;
scanf("%d", &n);
int i, l1, r1, l2, r2;
for(i=0; i<n; i++){
scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
if(l1 != l2) printf("%d %d\n", l1, l2);
else if(l1 == l2 && r1 != r2) printf("%d %d\n", r1, r2);
else printf("%d %d\n", l1, r1);
}
} | |
You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other. The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries. | Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any. | C | cdafe800094113515e1de1acb60c4bb5 | 4dbda4534e12f5aa8da80d5b6e151569 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1548254100 | ["5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8"] | null | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query. | ["2 1\n3 4\n3 2\n1 2\n3 7"] | #include <stdio.h>
int main()
{
int l1,r1,l2,r2,q,a,b,i;
scanf("%d",&q);
for(i=0;i<q;i++){
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
a=l1,b=l2;
if(a==b) b=++l2;
printf("%d %d\n",a,b);
}
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 4d0e1bdd5d244ed0eab9ff46c74a54e6 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
short n,k=0,i,j,m,flag=0,flag1=0;
int big,u=0,sum=0,pos;
scanf("%d",&n);
pos=n;
char **name=(char **)malloc(sizeof(char *)*n);
char **name1=(char **)malloc(sizeof(char *)*n);
int *pts=(int *)malloc(sizeof(int)*n);
int *pts1=(int *)malloc(sizeof(int)*n);
int *another=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
flag1=0;
name[i]=(char *)malloc(sizeof(char )*35);
scanf("%s",name[i]);
for(j=0;j<k;j++)
{
if(strcmp(name[i],name1[j])==0)
{
scanf("%d",&pts[i]);
pts1[j]=pts1[j]+pts[i];
flag1=1;
if(flag==j)
{
big=big+ pts[i];
for(m=0;m<k;m++)
{
if(pts1[m]>big)
{
flag=m;
big=pts1[m];
}
}
}
else
{
if(pts1[j]>big)
{
flag=j;
big=pts1[j];
}
}
break;
}
}
if(flag1==1)
continue;
name1[k]=(char *)malloc(sizeof(char )*35);
name1[k]=name[i];
scanf("%d",&pts[i]);
pts1[k]=pts[i];
if(k==0)
big=pts1[k];
if(pts1[k]>big)
{
flag=k;
big=pts1[k];
}
k++;
}
for(m=0;m<k;m++)
{
if(pts1[m]==big)
{
another[u]=m;
u++;
}
}
for(i=0;i<u;i++)
{
sum=0;
for(j=0;j<n;j++)
{
if(strcmp(name1[another[i]],name[j])==0)
{
sum=sum+pts[j];
if(sum>=big)
{
if(j<pos)
{
pos=j;
flag=another[i];
}
break;
}
}
}
}
printf("%s",name1[flag]);
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 963123304163a8cc036afcc65cb69c84 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include<stdio.h>
#include<string.h>
struct game
{
char nm[35];
int pnt;
}rnd[1005];
int tt(char name[],int n)
{
int i,sum=0;
for (i=0;i<=n;i++)
{
if(strcmp(name,rnd[i].nm)==0)
{
sum+=rnd[i].pnt;
}
}
return sum;
}
int main()
{
int n,pt,len=0,k,i,j;
scanf("%d",&n);
char str[n][35];
int cnt[1000]={0};
for(k=0;k<n;k++)
{
scanf("%s %d",rnd[k].nm,&rnd[k].pnt);
for(j=0;j<len;j++)
{
if(strcmp(rnd[k].nm,str[j])==0)
{
cnt[j]+=rnd[k].pnt;break;
}
}
if(j==len)
{
strcpy(str[len],rnd[k].nm);cnt[len]+=rnd[k].pnt;len++;
}
}
int max=cnt[0];
for(i=0;i<len;i++)
{
if(cnt[i]>max)
{
max=cnt[i];
}
}
int summ,idx,p;
for(i=0;i<n;i++)
{
for(p=0;p<len;p++)
{
if(strcmp(str[p],rnd[i].nm)==0)
{
idx=p;break;
}
}
summ=tt(rnd[i].nm,i);
if((summ>=max)&&(cnt[idx]==max))
{
printf("%s\n",rnd[i].nm);
return 0;
}
}
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 754c4f8b375d983061c172ad48cd81ed | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include<stdio.h>
#include<string.h>
struct order{
int num;
int i;
}command[1005];
int main(){
char name[1005][100];
int num[1005];
char peo[100];
int k, n, i, j, m = 0;
int max=0;
int time = 1005;
scanf("%d",&n);
for(j=0;j<n;j++){
scanf("%s%d",peo,&k);
for(i=0;i<m;i++){
if(strcmp(peo,name[i])==0)break;
}
command[j].i=i;
if(i==m){
m++;
strcpy(name[i],peo);
}
num[i]+=k;
command[j].num = num[i];
}
for(j=0;j<m;j++) if(num[max]<num[j]) max = j;
for(j=0;j<m;j++){
if(num[j]==num[max]){
for(i=0;i<n;i++){
if(command[i].i==j && command[i].num>=num[max] && time>i){
time = i;
}
}
}
}
printf("%s",name[command[time].i]);
return 0;
} | |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | f54111b02013ff7ed9c46acb6dc8e1a5 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include<stdio.h>
#define true 1
#define false 0
#define is_max_col 0
#define total_score_col 1
#define number_of_index_col 2
#define unique_index_col 3
int main(){
typedef int bool;
int n,i,j,score[1000],person,count=1,k=0,max;
int round_table[1000][1003]={0,},winner_index,f=unique_index_col,row,more_max=0;
int x,y,sum1,sum2,flag;
char name[1000][80];
bool found[1000]={false};
scanf("%d",&n);
person=n;
for(i=0;i<n;i++){
scanf("%s%d",name[i],&score[i]);
}
for(i=0;i<n ;i++){
if(found[i]) continue;
round_table[k][total_score_col]=round_table[k][total_score_col]+score[i];
round_table[k][f++]=i;
for(j=i+1;j<n;j++){
if(!found[j] && strcmp(name[i],name[j])==0){
found[j]=true;
count++;
round_table[k][total_score_col]=round_table[k][total_score_col]+score[j];
round_table[k][f++]=j;
}
}
person=person-count+1;
count=1;
round_table[k][number_of_index_col]=f-3;
f=unique_index_col;
k++;
}
max=round_table[0][total_score_col],winner_index=round_table[0][unique_index_col],row=0;
for(j=1;j<person;j++){
if(round_table[j][total_score_col]>max){
max=round_table[j][total_score_col];
winner_index=round_table[j][unique_index_col];
row=j;
}
}
for(j=row+1;j<person;j++){
if(round_table[j][total_score_col]==max){
x=3,y=3,sum1=0,sum2=0,flag=0;
sum1=sum1+score[round_table[row][x]];
while(1){
if(flag==0 && sum1>=max){
winner_index=round_table[row][unique_index_col];
break;
}
else if(flag==0 && ++x<=round_table[row][number_of_index_col]+2){
if(round_table[row][x]<round_table[j][y]){
sum1=sum1+score[round_table[row][x]];
continue;
}
else{
sum2=sum2+score[round_table[j][y]];
flag=1;
}
}
if(flag==1 && sum2>=max){
winner_index=round_table[j][unique_index_col];
row=j;
j=row;
break;
}
else if(flag==1 && ++y<=round_table[j][number_of_index_col]+2){
if(round_table[j][y]<round_table[row][x]){
sum2=sum2+score[round_table[j][y]];
continue;
}
else {
sum1=sum1+score[round_table[row][x]];
flag=0;
}
}
}
}
}
printf("%s\n",name[winner_index]);
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 5a343b4eca1352a783cf5dbebe21d235 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define HM 107
struct dict{
char name[34];
int points[1000];
int sum;
int index[1000];
int total;
};
struct table{
struct dict *D;
int entry;
};
int hash(char *name){
int i=0;
int sum=0;
while(name[i]){
sum=(sum*13+name[i]-'a')%HM;
i++;
}
return sum%HM;
}
void addEntry(char *name, int a, int ind, struct table *T){
int hashval=hash(name);
int i;
for(i=0;i<T[hashval].entry;i++){
if(strcmp(name,T[hashval].D[i].name)==0){
T[hashval].D[i].sum+=a;
T[hashval].D[i].points[T[hashval].D[i].total]=a;
T[hashval].D[i].index[T[hashval].D[i].total]=ind;
T[hashval].D[i].total++;
return;
}
}
T[hashval].entry++;
int entry=T[hashval].entry;
if(entry==1){
T[hashval].D=(struct dict*)malloc(entry*sizeof(struct dict));
}
T[hashval].D=realloc(T[hashval].D,entry*sizeof(struct dict));
strcpy(T[hashval].D[entry-1].name,name);
T[hashval].D[entry-1].total=1;
T[hashval].D[entry-1].index[0]=ind;
T[hashval].D[entry-1].points[0]=a;
T[hashval].D[entry-1].sum=a;
}
int main(){
int t,i,j,k,a;
char str[34];
struct table *T=(struct table *)malloc(HM*sizeof(struct table));
for(i=0;i<HM;i++){
T[i].entry=0;
}
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%s%d",str,&a);
addEntry(str,a,i,T);
}
int max_p=-1,min_i=t;
for(i=0;i<HM;i++){
for(j=0;j<T[i].entry;j++){
if(max_p<T[i].D[j].sum){
max_p=T[i].D[j].sum;
}
}
}
for(i=0;i<HM;i++){
for(j=0;j<T[i].entry;j++){
int sum=0;
for(k=0;k<T[i].D[j].total;k++){
sum+=T[i].D[j].points[k];
if(sum>=max_p){
if(T[i].D[j].index[k]<min_i && T[i].D[j].sum==max_p){
strcpy(str,T[i].D[j].name);
min_i=T[i].D[j].index[k];
}
break;
}
}
}
}
printf("%s\n",str);
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 1eaf55ffadc0f9fff09c8c150407320e | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include<stdio.h>
#include<string.h>
int n,m,x,u,max,i,ii,j,h[1002],hh[1002],hhh[1002],d,max;
char a[1002][34],b[34];
int main()
{
scanf("%d",&n);
scanf("%s %d",a[u++],&x);
h[0]+=x;
hh[0]=x;
for(i=1;i<n;i++)
{
scanf("%s %d",b,&x);
for(j=0;j<u;j++)
{
if(strcmp(b,a[j])==0)
break;
}
if(j==u)
{
strcpy(a[u],b);
u++;
}
h[j]+=x;
hh[i]=h[j];
hhh[i]=j;
}
max=h[0];
for(i=1;i<u;i++)
if(h[i]>max)
max=h[i];
for(i=0;i<n;i++)
{
if(h[hhh[i]] == max && hh[i]>=max){
break;
}
}
printf("%s",a[hhh[i]]);
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | eb30b645e6074f7c285db487c41ca770 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int n, m;
int i = 0, j = 0, k = 0;
struct nameSorceSt {
char name[33];
int sorce;
};
struct nameSorceSt nameSorce[1000] = {{0, 0}};
struct nameSorceSt nameSorce2[1000] = {{0, 0}};
struct maxSorceSt {
int maxNameIndex;
int maxIndex;
};
int emptyIndex = 0;
struct maxSorceSt maxSorceArray[100] = {{0, 0}};
int maxNum = 0;
int maxSorce = 0;
scanf("%d", &n);
m = n;
while(n--)
{
scanf("%s %d", nameSorce[m-n-1].name, &(nameSorce[m-n-1].sorce));
memcpy(&nameSorce2[m-n-1], &nameSorce[m-n-1], sizeof(nameSorce[m-n-1]));
for(i=0; i<emptyIndex; i++)
{
if(strcmp(nameSorce[i].name, nameSorce[m-n-1].name) == 0)
{
nameSorce[i].sorce += nameSorce[m-n-1].sorce;
break;
}
}
if(i == emptyIndex)
{
strcpy(nameSorce[i].name, nameSorce[m-n-1].name);
nameSorce[i].sorce = nameSorce[m-n-1].sorce;
emptyIndex++;
}
}//计算出每个人的最终得分
maxSorce = nameSorce[0].sorce;
for(i=0; i<emptyIndex; i++)
{
if(nameSorce[i].sorce > maxSorce)
{
maxSorce = nameSorce[i].sorce;
maxNum = 1;
memset(maxSorceArray, 0, sizeof(maxSorceArray));
maxSorceArray[0].maxNameIndex = i;
}
else if(nameSorce[i].sorce == maxSorce)
{
maxSorceArray[maxNum].maxNameIndex = i;
maxNum++;
}
}//计算出最高分,并统计出得到最高分人的位置
// for(j=0; j<maxNum; j++)
// {
// for(i=m-1; i>=0; i--)
// {
// if(strcmp(nameSorce[i].name, nameSorce[maxSorceArray[j].maxNameIndex].name) == 0)
// {
// maxSorceArray[j].maxIndex = i;
// break;
// }
// }
// }//计算出最高分最后一次结算的位置
int tempSorce;
for(n=0; n<m; n++)
{
for(i=0; i<maxNum; i++)
{
if(strcmp(nameSorce2[n].name, nameSorce[maxSorceArray[i].maxNameIndex].name) == 0)
{
maxSorceArray[i].maxIndex += nameSorce2[n].sorce;
if(maxSorceArray[i].maxIndex >= maxSorce)
{
printf("%s\n", nameSorce2[n].name);
return 0;
}
break;
}
}
}
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | f3cb7b1480e24721a4039f8856ff863c | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n,i,j,max=-200000000,score[1000],t=0,dew[1000],a=0;
int score2[1000];
char name[1000][50];
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",name[i]);
scanf("%d",&dew[i]);
if(i==1)
{
score[1]=dew[1];
}
if(i>1)
{
for(j=1;j<i;j++)
{
if(strcmp(name[i],name[j])==0)
{
score[j]+=dew[i];
score[i]=-300000000;
break;
}
}
if(j>=i) score[i]=dew[i];
}
}
for(j=1;j<=n;j++)
{
if(score[j]>max) max=score[j];
}
//printf(">> %d\n",max);
for(i=1;i<=n;i++)
{
if(i==1)
{
score2[1]=dew[i];
if(score2[1]>=max&&score[1]>=max) {printf("%s",name[1]); exit(0);}
}
if(i>1)
{
for(j=1;j<i;j++)
{
if(strcmp(name[i],name[j])==0)
{
score2[j]+=dew[i];
//score2[i]=-300000000;
if(score2[j]>=max&&score[j]>=max) {printf("%s",name[j]); exit(0);}
break;
}
}
if(j>=i)
{
score2[i]=dew[i];
if(score2[i]>=max&&score[j]>=max) {printf("%s",name[i]); exit(0);}
}
}
}
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 61631a613afeff99d478f6cab11ed55b | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include <stdio.h>
struct _game {
char name[33];
int score;
};
int number = 0;
struct _game data[1000];
struct _game game[1000];
struct _game game2[1000];
int max_iis[1000];
int max_iis_number = 0;
int main(void)
{
int nn = 0;
int ii = 0;
scanf("%d", &nn);
for(; ii < nn; ii ++) {
char name[33] = {0,};
int score = 0;
scanf("%s %d", data[ii].name, &(data[ii].score));
search_and_add(data[ii].name, data[ii].score);
}
int max = find_max_value();
find_max_iis(max);
number = 0;
for(ii = 0; ii < nn; ii ++) {
int ret = search_and_add_2(max, data[ii].name, data[ii].score);
if (1 == ret)
break;
}
return 0;
}
void find_max_iis(int max)
{
int ii = 0;
for (; ii < number; ii ++) {
if (max == game[ii].score) {
max_iis[max_iis_number ++] = ii;
}
}
}
int find_max_value(void)
{
int ii = 0;
int max = 0;
for (; ii < number; ii ++) {
if (max < game[ii].score)
max = game[ii].score;
}
return max;
}
int search_and_add(char *name, int score)
{
int ii = 0;
for (; ii < number; ii++) {
if (strlen(name) != strlen(game[ii].name))
continue;
if (0 != strcmp(game[ii].name, name))
continue;
game[ii].score += score;
return;
}
strcpy(game[number].name, name);
game[number].name[strlen(name)] = 0x00;
game[number].score = score;
number ++;
}
int search_and_add_2(int max, char *name, int score)
{
int ii = 0;
for (; ii < number; ii++) {
if (strlen(name) != strlen(game2[ii].name))
continue;
if (0 != strcmp(game2[ii].name, name))
continue;
game2[ii].score += score;
if (game2[ii].score >= max && is_there(ii)) {
printf("%s\n", game2[ii].name);
return 1;
}
return 0;
}
strcpy(game2[number].name, name);
game2[number].name[strlen(name)] = 0x00;
game2[number].score = score;
if (game2[number].score >= max && is_there(number)) {
printf("%s\n", game2[number].name);
return 1;
}
number ++;
}
int is_there(int idx)
{
int ii = 0;
for (; ii < max_iis_number; ii ++) {
if (idx == max_iis[ii])
return 1;
}
return 0;
} | |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | b7e83e8a5ca51c0e00fe1846d317b728 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include <stdio.h>
#include <string.h> //û������������ˣ���������
char s[1005][40];
int a[1005];//������¼����ֵ
int a1[1005];//������¼ÿһ����ͻ��ֵ
int a2[1005];//������¼ÿһ����ͻ��ֵ�Ƿ������ĸ�ֵ��ͻ��
int main()
{
int n;
int i,j;
int max;
scanf("%d\n", &n);
for (i = 0; i < n; i++)
{
scanf("%s%d", &s[i], &a[i]);
}
for (i = 1; i < n; i++)
{
for (j = 0; j <= i; j++)
if (strcmp(s[i], s[j]) == 0)
break;
if (j < i)
{
a[j] += a[i];
a[i] = 0;
}
a1[i] = a[j];//��¼ÿһ����ͻ����ֵ���п�������ֵ
a2[i] = j;//������¼��ÿһ������һ��ֵͻ���ˣ�Ϊ������ж�˭�ȴﵽ��ֵ������
}
max = a[0];
for (i = 0; i < n; i++)
{
if (a[i] > max)
max = a[i];
}
for (i = 0; i < n; i++)
{
if (a[a2[i]] == max && a1[i] >= max)
break;
}
printf("%s\n", s[i]);
return 0;
}
| |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | Print the name of the winner. | C | c9e9b82185481951911db3af72fd04e7 | 35752214c78686b5c0123a38c047f430 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"implementation",
"hashing"
] | 1267117200 | ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5"] | null | PASSED | 1,500 | standard input | 1 second | The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | ["andrew", "andrew"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct name
{
char ch[33];
int m;
};
int main()
{
int n,a;
scanf("%d",&n);
char na[33];int s;
struct name mt[1001],nt[1001];
int i;
scanf("%s %d",mt[0].ch,&mt[0].m);
strcpy(nt[0].ch,mt[0].ch);
nt[0].m=mt[0].m;
int max=mt[0].m;
int k=0,j;
for(i=1;i<n;i++)
{
scanf("%s %d",na,&s);
strcpy(nt[i].ch,na);
nt[i].m=s;
for(j=0;j<=k;j++)
{
if(strcmp(mt[j].ch,na)==0)
{
mt[j].m=mt[j].m+s;
break;
}
}
if(j==(k+1))
{
strcpy(mt[k+1].ch,na);
mt[k+1].m=s;
k++;
}
}
max=mt[0].m;
for(i=1;i<=k;i++)
max=max>mt[i].m?max:mt[i].m;
// printf("%d",max);
struct name list[1001];
j=0;
for(i=0;i<=k;i++)
{
if(mt[i].m==max)
{ strcpy(list[j].ch,mt[i].ch);
list[j].m=max;
j++;}
}
//for(i=0;i<j;i++)
// printf("%s %d\n",list[i].ch,list[i].m);
if(j==1)
{
printf("%s",list[0].ch);exit(0);}
int l;
for(i=0;i<n;i++)
{
for(l=0;l<j;l++)
{
if(strcmp(nt[i].ch,list[l].ch)==0)
{
list[l].m=list[l].m-nt[i].m;
if(list[l].m<=0)
{
printf("%s",list[l].ch);
exit(0);
}
/* }
else if(a==0)
{
if(list[l].m>=0)
{
printf("%s",list[l].ch);
exit(0);
}
}*/
}
}
}
exit(0);
}
| |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | b058b77dc09eeba36e21e7157e127be3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include<stdio.h>
int main()
{
int n;
int i = 1;
scanf("%d", &n);
while(i<n)
{
printf("%d ", i);
i+=2;
}
i-=2;
if((n&1) && n!=i) printf("%d ", n);
while(i>0)
{
printf("%d ", i);
i-=2;
}
i = 2;
while(i<n)
{
printf("%d ", i);
i+=2;
}
i-=2;
if((!(n&1)) && n!=i) printf("%d ", n);
while(i>0)
{
printf("%d ", i);
i-=2;
}
printf("%d\n", n);
return 0;
}
| |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | 018e8c5b2e4ddb57d3402d8b65d15257 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include<stdio.h>
int arr[1000000];
int main()
{
int n,even,odd=0,i;
scanf("%d",&n);
even=n;
for(i=1;i<n;i++)
{
if(!(i&1))
{
arr[even]=arr[even+n-i]=i;
even++;
}
else
{
arr[odd]=arr[odd+n-i]=i;
odd++;
}
}
arr[2*n-1]=n;
if(n&1)
arr[(n-1)/2]=n;
else
arr[(3*(n)-2)/2]=n;
for(i=0;i<2*n;i++)
{
printf("%d ",arr[i]);
}
return 0;
} | |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | ae57a7fb2c0a14c3ad79adbdc84dd7a2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include <stdio.h>
#define N 500000
int main() {
static int aa[N * 2];
int n, i, j, a;
scanf("%d", &n);
for (a = 1, i = 0, j = n - 1; i < j; a += 2, i++, j--)
aa[i] = aa[j] = a;
for (a = 2, i = n, j = n * 2 - 2; i < j; a += 2, i++, j--)
aa[i] = aa[j] = a;
aa[n * 2 - 1] = n;
if (n % 2 == 1)
aa[(n - 1) / 2] = n;
else
aa[(n * 3 - 2) / 2] = n;
for (i = 0; i < n * 2; i++)
printf("%d ", aa[i]);
printf("\n");
return 0;
}
| |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | 1993f3c3ee6e1cb1bdeef0acd9c6c0af | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include <stdio.h>
#include <stdlib.h>
int mat[1000010];
int main () {
int n;
int x;
int i;
scanf("%d", &n);
if (n == 1) {
printf("1 1\n");
} else if (n == 2) {
printf("1 1 2 2\n");
} else {
int i1 = (n - 1) / 2, i2 = n + (n - 2) / 2;
x = 1;
for (i = 0; i < 2 * n; i++) {
if (i <= i1) {
printf("%d ", x);
x += 2;
} else if (i == i1 + 1) {
if (n % 2)
x -= 4;
if (!(n % 2))
x -= 2;
printf("%d ", x);
x -= 2;
} else if (i < n) {
printf("%d ", x);
x -= 2;
} else if (i == n) {
x = 2;
printf("%d ", x);
x += 2;
} else if (i <= i2) {
printf("%d ", x);
x += 2;
} else if (i == i2 + 1) {
if (!(n % 2))
x -= 4;
if (n % 2)
x -= 2;
printf("%d ", x);
x -= 2;
} else if (i < 2 * n - 1) {
printf("%d ", x);
x -= 2;
} else {
printf("%d\n", n);
}
}
}
return 0;
} | |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | f5a60f0fa42ea01c7b50443a81886d88 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include<stdio.h>
int main()
{
int n;
int i = 1;
scanf("%d", &n);
while(i<n)
{
printf("%d ", i);
i+=2;
}
i-=2;
if((n&1) && n!=i) printf("%d ", n);
while(i>0)
{
printf("%d ", i);
i-=2;
}
i = 2;
while(i<n)
{
printf("%d ", i);
i+=2;
}
i-=2;
if((!(n&1)) && n!=i) printf("%d ", n);
while(i>0)
{
printf("%d ", i);
i-=2;
}
printf("%d\n", n);
return 0;
}
| |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | 962c5473feb957be6d45baa30dedcfed | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[2*n],i;
for(i=0;i<2*n;i++)
a[i] = n;
for(i =1;i<n;i++)
{
int x ;
if(i & 1) x = i>>1;
else x = (n-1) + (i>>1);
int y = n-i + x;
a[x] = a[y]= i;
// = i;
}
for(i=0;i<2*n;i++)
{
printf("%d ",a[i]);
}
return 0;
} | |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | e3fd5b5bc73a0e807ef9802e8cc8eabf | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | /*
f(i) = abs((n - i) * Di - (n - i)^2)
s = sigma i from [1, n] : f(i)
best Di = n - i
Yi = Xi + Di
= Xi + n - i
let n = 10
D1 = 9
D2 = 8
D3 = 7
D4 = 6
D5 = 5
D6 = 4
D7 = 3
D8 = 2
D9 = 1
D10 = 0 <- impossible, but f(n) = 0 anyway
9 9
9 9 8 10 8
7 9 9 7 8 10 8
7 9 9 7 6 8 10 8 6
.
.
.
1 3 5 7 9 9 7 5 3 1 2 4 6 8 10 8 6 4 2
n = 13 ?
D8= 5
D9 =4
D10=3
D11=2
D12=1
D13=0
8 10 12 12 10 8 9 11 13 11 9
*/
#include <stdio.h>
int main(void)
{
int n, b, i;
scanf("%d", &n);
for (b = 1; b <= 2; b++) {
for (i = b; i <= n; i += 2)
printf("%d ", i);
i -= 2;
for (i = i == n ? n - 2 : i; i >= b; i -= 2)
printf("%d ", i);
}
printf("%d\n", n);
return 0;
}
| |
You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define the value di = yi - xi — the distance between the positions of the number i. Permute the numbers in array a to minimize the value of the sum . | Print 2n integers — the permuted array a that minimizes the value of the sum s. | C | c234cb0321e2bd235cd539a63364b152 | 3fb7863f6d43f93f764d77a08670f2bb | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"constructive algorithms"
] | 1455116400 | ["2", "1"] | null | PASSED | 1,900 | standard input | 1 second | The only line contains integer n (1 ≤ n ≤ 5·105). | ["1 1 2 2", "1 1"] | #include <stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==0){
for(i=1;i<n;i+=2) printf("%d ",i);
for(i=n-1;i>0;i-=2) printf("%d ",i);
for(i=2;i<=n;i+=2) printf("%d ",i);
for(i=n-2;i>0;i-=2) printf("%d ",i);
printf("%d",n);
}
else{
for(i=1;i<=n;i+=2) printf("%d ",i);
for(i=n-2;i>0;i-=2) printf("%d ",i);
for(i=2;i<n;i+=2) printf("%d ",i);
for(i=n-1;i>0;i-=2) printf("%d ",i);
printf("%d",n);
}
return 0;
} | |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 22cd41752470442dd4d34cd674ac8fbb | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include<stdio.h>
int main()
{
unsigned long long int n,temp,r1,r2,r3,i,f=0;
unsigned long long int r;
unsigned long long int m=5040,k=120,l=720;
scanf("%I64d",&n);
temp=n;
for(i=1;i<=4;i++)
{
temp= temp*(n-i);
}
r1=temp/120;
f=0;
temp=n;
for(i=1;i<=5;i++)
{
temp= temp*(n-i);
}
r2=temp/720;
f=0;
temp=n;
if(n==7)
r3=1;
else
{
for(i=1;i<=6;i++)
{
temp= temp*(n-i);
if(f==0)
{
if(temp%120==0)
{
temp=temp/120;
f=1;
}
}
}
if(f==0)
r3=temp/5040;
else
r3=temp/42;
}
r=r1+r2+r3;
printf("%I64d",r);
return 0;
}
| |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 39f8a7d9e23b69de570e948c85d380f2 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include <stdio.h>
#include <math.h>
long long gcd(long long a, long long b)
{
return b ? gcd(b, a%b) : a;
}
int main()
{
long long n = 1;
scanf("%I64d", &n);
long long res = 0, t, a, d;
t = 1;
a = 1;
for (int i = 2; i <= 5; i++)
{
a *= i;
}
for (int i = 0; i < 5; i++)
{
d = gcd(n - i, a);
t *= (n - i) / d;
a /= d;
}
res += t;
t = 1;
a = 1;
for (int i = 2; i <= 6; i++)
{
a *= i;
}
for (int i = 0; i < 6; i++)
{
d = gcd(n - i, a);
t *= (n - i) / d;
a /= d;
}
res += t;
t = 1;
a = 1;
for (int i = 2; i <= 7; i++)
{
a *= i;
}
for (int i = 0; i < 7; i++)
{
d = gcd(n - i, a);
t *= (n - i) / d;
a /= d;
}
res += t;
printf("%I64d\n", res);
return 0;
} | |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | fb870c290c8f668762075224848119f1 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include<stdio.h>
int main(){
long long n;
scanf("%I64d",&n);
unsigned long long i,sum=0,factof5=1,factof6=1,factof7=1;
for(i=1;i<=7;i++){
if(i<=6){
factof6*=i;
}
if(i<=5){
factof5*=i;
}
factof7*=i;
}
unsigned long long x1=1,x2=1,x3=1;
for(i=n;i>=n-4;i--){
x1*=i;
}
x1=x1/factof5;
x2=(x1*(n-5))/(factof6/factof5);
x3=(x2*(n-6))/(factof7/factof6);
sum+=x1+x2+x3;
//printf("%I64d %I64d %I64d\n",x1,x2,x3);
printf("%I64d\n",sum);
return 0;
}
| |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | c6f37d7145ba033861456ca2f1921118 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAX 1010
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
long long binomial[MAX][MAX];
void Generate(){
int i, j;
clr(binomial);
for (i = 0; i < MAX; i++){
for (j = 0; j <= i; j++){
if (i == j || j == 0) binomial[i][j] = 1;
else binomial[i][j] = (binomial[i - 1][j] + binomial[i - 1][j - 1]);
}
}
}
int main(){
Generate();
int n, i, j;
while (scanf("%d", &n) != EOF){
long long res = binomial[n][5] + binomial[n][6] + binomial[n][7];
printf("%lld\n", res);
}
return 0;
}
| |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 2bc45def3edc3ba970308c592d48fdac | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define prime 1000000007
long long combi(int n,int k)
{
long long ans=1;
k=k>n-k?n-k:k;
int j=1;
for(;j<=k;j++,n--)
{
if(n%j==0)
{
ans*=n/j;
}else
if(ans%j==0)
{
ans=ans/j*n;
}else
{
ans=(ans*n)/j;
}
}
return ans;
}
int main()
{
int n;
long long ans;
scanf("%d",&n);
ans=combi(n,5);
ans=ans+combi(n,6);
ans=ans+combi(n,7);
printf("%lli\n",ans);
return 0;
}
| |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 8d94ce78e192b9cbbe7c5f9746ff1a1c | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include <stdio.h>
unsigned long long comb(int n, int k )
{
if(k==0) return 1;
return (comb(n-1,k-1)*n)/k;
}
int main()
{
int n;
scanf("%d",&n);
printf("%lli",comb(n,5) + comb(n,6) + comb(n,7));
} | |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 400f35b0009a32e043361e101612bbfc | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include<stdio.h>
int main()
{
unsigned long long n=0,k=0;
scanf("%llu",&n);
k = ((n*(n-1)*(n-2)*(n-3)*(n-4))/120) + (( ( (n*(n-1)*(n-2)*(n-3)*(n-4)/120) * (n-5) ) )/6) +
(( ( (n*(n-1)*(n-2)*(n-3)*(n-4)/120) * (n-5) * (n-6) ) )/42);
printf("%llu",k);
return 0;
} | |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 03122aaf4644a0fcd8d339154c4a9902 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include <stdio.h>
#include <stdlib.h>
long long int fact5(int a)
{
long long int x=1;
int i;
for(i=1;i<=5;i++)
{
x*=(long long int)a;
a--;
}
x/=120;
return x;
}
long long int fact6(int b)
{
long long int y=1;
int j;
for(j=1;j<=5;j++)
{
y*=(long long int)b;
b--;
}
y/=120;
y*=(long long int)(b);
y/=6;
return y;
}
long long int fact7(int c)
{
long long int z=1;
int k;
for(k=1;k<=5;k++)
{
z*=(long long int)c;
c--;
}
z/=120;
z*=(long long int)(c--);
z/=6;
z*=(long long int)(c);
z/=7;
return z;
}
int main()
{
int n;
scanf("%d", &n);
long long int count=0;
count+=fact5(n);
count+=fact6(n);
count+=fact7(n);
printf("%lld", count);
return 0;
} | |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | 9bb2b6cc4ac22dfc3c94695d65346b17 | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include<stdio.h>
int main()
{
unsigned long long n,num5,num6,num7,k,arr[780];
for(n=7; n<=777; n++)
{
k=(n*(n-1)*(n-2)*(n-3)*(n-4));
num5=k/120;
num6=(k*(n-5))/720;
num7=n*(n-1)/2*(n-2)/3*(n-3)/4*(n-4)/5*(n-5)/6*(n-6)/7;
arr[n]=num5+num6+num7;
}
while(scanf("%I64d",&n)==1)
{
printf("%I64d\n",arr[n]);
}
return 0;
}
| |
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate. | Output one integer — the number of different variants of group composition. | C | 09276406e16b46fbefd6f8c9650472f0 | d692ee91bd528a173f239ef931b8cbfb | GNU C | standard output | 64 megabytes | train_002.jsonl | [
"combinatorics",
"math"
] | 1455807600 | ["7"] | null | PASSED | 1,300 | standard input | 0.5 seconds | The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes. | ["29"] | #include<stdio.h>
int main ()
{
long long int n,i,a,b,c;
scanf("%I64d",&n);
a=n*(n-1)/2*(n-2)/3*(n-3)/4*(n-4)/5;
b=n*(n-1)/2*(n-2)/3*(n-3)/4*(n-4)/5*(n-5)/6;
c=n*(n-1)/2*(n-2)/3*(n-3)/4*(n-4)/5*(n-5)/6*(n-6)/7;
printf("%I64d\n",a+b+c);
return 0;
}
| |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 8b1f02d1561559582359b647ec502add | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include<stdio.h>
int main()
{ long int n[10000000],q;
scanf("%d",&q);
for (int i=1;i<=q;i++)
scanf("%d",&n[i]);
for (int i=1;i<=q;i++)
{
if (n[i]<4) puts("-1");else
if (n[i]%4==0) printf("%d\n",n[i]/4); else
if (n[i]%4==1)
{ if(n[i]/4-1<=0) puts("-1");else
printf("%d\n",n[i]/4-1);}
else
if (n[i]%4==2) {
printf("%d\n",n[i]/4);}
else
if (n[i]%4==3) {
if(n[i]/4-2<=0) puts("-1"); else
printf("%d\n",n[i]/4-1);}
}} | |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 32e64c587b4b8c228205ca7773470c5b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include<stdio.h>
int main ()
{
int a,n;
scanf ("%d",&n);
for (long long i=1; i<=n ;i++)
{
scanf("%d",&a);
if(a<4 || a==5||a==7||a==11) printf ("-1\n");
else if (a%2==0) printf ("%d\n",a/4);
else printf ("%d\n",a/4-1);
}
} | |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 26639ec9b040a72572a4738011218ad0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | /* Coached by rainboy */
#include <stdio.h>
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n, ans;
scanf("%d", &n);
if (n % 4 == 0)
ans = n / 4;
else if (n % 4 == 1)
if (n >= 9)
ans = (n - 9) / 4 + 1;
else
ans = -1;
else if (n % 4 == 2)
if (n >= 6)
ans = (n - 6) / 4 + 1;
else
ans = -1;
else
if (n >= 15)
ans = (n - 15) / 4 + 2;
else
ans = -1;
printf("%d\n", ans);
}
return 0;
}
| |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 1e832e5a3154704e5a39d690a4a7e68e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | /* Coached by rainboy */
#include <stdio.h>
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n, ans;
scanf("%d", &n);
if (n % 4 == 0)
ans = n / 4;
else if (n % 4 == 1)
ans = n >= 9 ? (n - 9) / 4 + 1 : -1;
else if (n % 4 == 2)
ans = n >= 6 ? (n - 6) / 4 + 1 : -1;
else
ans = n >= 15 ? (n - 15) / 4 + 2 : -1;
printf("%d\n", ans);
}
return 0;
}
| |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 81816bee42b3913e15a5a34d648782cc | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include <stdio.h>
int main()
{
int q, n;
scanf("%d", &q);
while(q--) {
scanf("%d", &n);
if(n == 4 || n == 6 || n == 9) {
puts("1");
} else if(n == 8 || n == 10) {
puts("2");
} else if(n >= 12) {
int table[4] = {3, 2, 3, 2};
printf("%d\n", table[n & 3] + ((n - 12) >> 2));
} else {
puts("-1");
}
}
return 0;
}
| |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | f5bbc9c4a9e0d62bb18c2aa63fe7b413 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
long long int i,j,k,n,ara[100000],t,a,b,c,ans;
scanf("%lld",&t);
for(i=0;i<t;i++){
scanf("%lld",&ara[i]);
}
for(i=0;i<t;i++){
a=ara[i]-6;
b=ara[i]-9;
c=ara[i]-15;
if(ara[i]%4==0){
ans=ara[i]/4;
}
else if((a%4==0)&&(a>=0)){
ans=(a/4)+1;
}
else if((b%4==0)&&(b>=0)){
ans=(b/4)+1;
}
else if((c%4==0)&&(c>=0)){
ans=(c/4)+2;
}
else{
ans=-1;
}
printf("%lld\n",ans);
}
return 0;
}
| |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | dac9e315491d29273ce3a08094df07bd | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include <stdio.h>
#include <stdlib.h>
int FindCh(int n) {
return n / 4;
}
int Calc(int n) {
if (n % 2 == 0) {
if (FindCh(n) == 0)
return -1;
else
return FindCh(n);
}
else {
if (n - 9 < 0 || n - 9 == 2)
return -1;
else
return 1 + FindCh(n - 9);
}
}
int main() {
int q, *mas, i;
scanf("%d", &q);
mas = malloc(sizeof(int) * q);
for (i = 0; i < q; i++) {
scanf("%d", &(mas[i]));
}
for (i = 0; i < q; i++) {
printf("%d\n", Calc(mas[i]));
}
return 0;
} | |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 9bce4373a993df58f55d422b55d577c2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include<stdio.h>
int main()
{
int q;
scanf("%d",&q);
while(q--)
{
int n,cnt=0;
scanf("%d",&n);
if(n%2==0)
{
if(n==2)
printf("-1\n");
else
{
cnt=n/4;
printf("%d\n",cnt);
}
}
else
{
if(n<=11)
{
if(n==9)
printf("1\n");
else
printf("-1\n");
}
else
{
n-=9;
cnt=n/4;
cnt++;
printf("%d\n",cnt);
}
}
}
return 0;
} | |
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | C | 0c2550b2df0849a62969edf5b73e0ac5 | 92f978aa9a46e0884d2426ef5ea53be3 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"number theory",
"greedy",
"math"
] | 1508054700 | ["1\n12", "2\n6\n8", "3\n1\n2\n3"] | Note12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.8 = 4 + 4, 6 can't be split into several composite summands.1, 2, 3 are less than any composite number, so they do not have valid splittings. | PASSED | 1,300 | standard input | 2 seconds | The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query. | ["3", "1\n2", "-1\n-1\n-1"] | #include <stdio.h>
#include <stdlib.h>
int main(void){
int q = 0, otv = 0, n = 0;
scanf("%d",&q);
for(int i = 0; i < q; i++){
otv = 0;
scanf("%d",&n);
while(n >= 4){
otv++;
n = n - 4;
}
if(n == 0){
printf("%d\n",otv);
}else if(n == 2){
if(otv >= 1) printf("%d\n",otv);
else printf("%d\n",-1);
}else if(n == 1){
if(otv >= 2) printf("%d\n",(otv-1));
else printf("%d\n",-1);
}else if(n == 3){
if(otv >= 3) printf("%d\n",(otv-1));
else printf("%d\n",-1);
}
}
return 0;
} | |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | 0e5acfc7b88f2a6f808c9bd3d0c3084e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include<stdio.h>
#include<stdlib.h>
struct node {
int val;
struct node* next;
};
struct node* a[100005];
int cat[100005],m,ans=0,ct[100005];
int verified[100005];
void insert (int u,int v) {
struct node* q;
q=(struct node*)malloc(1*sizeof(struct node));
q->val=v;
q->next=NULL;
if(a[u]==NULL)
a[u]=q;
else {
struct node* p;
p=a[u];
q->next=p;
a[u]=q;
}
}
void dfs( int x,int count,int flag)
{
struct node *p;
int k=x;
p=a[x];
if(cat[k]==1)
{
count++;
}
else
{
count=0;
}
if(count>m)
{
flag=1;
}
if(ct[k]==1 && k!=1)
{
if(flag==0)
{
ans++;
}
}
while(p!=NULL)
{
x=p->val;
if(verified[x]==0)
{
verified[x]=k;
dfs(x,count,flag);
}
p=p->next;
}
}
int main()
{
int n,i,u,v;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&cat[i]);
ct[i]=0;
}
for(i=0;i<n-1;i++)
{
scanf("%d %d",&u,&v);
insert(u,v);
insert(v,u);
ct[u]++;
ct[v]++;
}
verified[1]=-1;
dfs(1,0,0);
printf("%d\n",ans);
} | |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | e954547febb993703707013b49b0fad9 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include <stdio.h>
#include <malloc.h>
const int N = 1e5 + 4 ;
int deg[100010] ;
int U[100010],V[100010] ;
int *a[100010] ;
int sz[100010] ;
int n , m ;
int ans ;
int col[100010] ;
void dfs(int u , int p , int c) {
if (c > m) return ;
if (sz[u] == 1 && u != 1) ans++ ;
int i ;
for (i = 0 ; i < sz[u] ; i++) {
int v = a[u][i] ;
if (v != p) {
if (col[v])
dfs(v,u,c+1) ;
else
dfs(v,u,0) ;
}
}
}
int main () {
scanf("%d %d",&n,&m) ;
int i ;
for (i = 1 ; i <= n ; i++) scanf("%d" , &col[i]) ;
for (i = 1 ; i < n ; i++) {
int u , v ;
scanf("%d %d",&u,&v) ;
U[i] = u , V[i] = v ;
deg[u]++ ;
deg[v]++ ;
}
for (i = 1 ; i <= n ; i++) {
a[i] = (int*)calloc(deg[i],sizeof(int)) ;
}
for (i = 1 ; i < n ; i++) {
int u = U[i] , v = V[i] ;
a[u][sz[u]++] = v ;
a[v][sz[v]++] = u ;
}
/*for (int i = 1 ; i <= n ; i++) {
printf ("%d : " , i) ;
for(int j = 0 ; j < sz[i] ; j++) {
printf (" %d" , a[i][j]) ;
}
printf ("\n") ;
}*/
dfs(1,-1,col[1]) ;
printf ("%d\n" , ans) ;
return 0 ;
}
| |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | 5252e91f402dcfa655f7299175a0f67b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include <stdio.h>
#include <malloc.h>
int deg[100010] ;
int U[100010],V[100010] ;
int *a[100010] ;
int sz[100010] ;
int n , m ;
int ans ;
int col[100010] ;
void dfs(int u , int p , int c) {
if (c > m) return ;
if (sz[u] == 1 && u != 1) ans++ ;
int i ;
for (i = 0 ; i < sz[u] ; i++) {
int v = a[u][i] ;
if (v != p) {
if (col[v])
dfs(v,u,c+1) ;
else
dfs(v,u,0) ;
}
}
}
int main () {
scanf("%d %d",&n,&m) ;
int i ;
for (i = 1 ; i <= n ; i++) scanf("%d" , &col[i]) ;
for (i = 1 ; i < n ; i++) {
int u , v ;
scanf("%d %d",&u,&v) ;
U[i] = u , V[i] = v ;
deg[u]++ ;
deg[v]++ ;
}
for (i = 1 ; i <= n ; i++) {
a[i] = (int*)calloc(deg[i],sizeof(int)) ;
}
for (i = 1 ; i < n ; i++) {
int u = U[i] , v = V[i] ;
a[u][sz[u]++] = v ;
a[v][sz[v]++] = u ;
}
/*for (int i = 1 ; i <= n ; i++) {
printf ("%d : " , i) ;
for(int j = 0 ; j < sz[i] ; j++) {
printf (" %d" , a[i][j]) ;
}
printf ("\n") ;
}*/
dfs(1,-1,col[1]) ;
for (i = 1 ; i <= n ; i++) {
free(a[i]) ;
}
printf ("%d\n" , ans) ;
return 0 ;
}
| |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | fee65973d5dc4001c104f5f614b2b793 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long int LLI;
#define TRUE (1==1)
#define FALSE (!TRUE)
#define fo3(i,a,b) for(i=((int)a);i<=((int)b);i++)
#define of3(i,a,b) for(i=((int)a);i>=((int)b);i--)
#define in1(n) scanf("%d",&(n))
#define LL1(n) scanf("%I64d",&(n))
#define in2(n,m) scanf("%d%d",&(n),&(m))
#define pri(n) printf("%d\n",n)
#define prs(n) printf("%s\n",n)
#define prL(n) printf("%I64d\n",n)
#define strin(n) scanf("%s",n)
#define newint(n) (int*)calloc((n),sizeof(int))
#define arrint(ret,n,i) fo3(i,1,n) in1(ret[i-1])
#define newLLI(n) (LLI*)calloc((n),sizeof(LLI))
#define arrLLI(ret,n,i) fo3(i,1,n) LL1(ret[i-1])
typedef struct AL AL;
struct AL{
int * vals;
int size;
int cap;
};
AL * ALCreate(int s) {
AL * ret = (AL *) calloc(1, sizeof(AL));
if (s == 0) ret->vals = NULL;
else ret->vals = (int *) calloc(s, sizeof(int));
ret->size = 0; ret->cap = s;
return ret;
}
void ALAdd(AL * list, int ele) {
if (list->cap == list->size) {
int nC = ((list->cap << 1) | 1);
list->vals = realloc(list->vals, sizeof(int) * nC);
list->cap = nC;
}
list->vals[list->size++] = ele;
}
typedef struct Pair {
int fi, se;
} Pair;
int comp(Pair ** arr, int f, int s) {// CHANGE THIS
if (arr[f]->fi != arr[s]->fi)
return arr[f]->fi - arr[s]->fi;
return arr[f]->se - arr[s]->se;
}
void sort(Pair ** arr, int size) {
int i;
if (size < 6) {
int nSize = 0;
Pair * swp;
while (size != 0) {
nSize = 0;
for (i = 0; i < size - 1; i++)
if (comp(arr, i, i + 1) > 0) {
nSize = i + 1;
swp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = swp;
}
size = nSize;
}
return;
}
Pair ** tmp = (Pair **)calloc(size, sizeof(Pair *)); // CHANGE THIS
int lSize = (size >> 1);
int rSize = size - lSize;
sort(arr, lSize); sort(arr + lSize, rSize);
int lPtr = 0, rPtr = 0;
int ptr = 0;
while (ptr != size) {
if (lPtr == lSize){
tmp[ptr] = arr[lSize + (rPtr++)];
} else if (rPtr == rSize || comp(arr, lPtr, lSize + rPtr) <= 0){ // CHANGE THIS
tmp[ptr] = arr[lPtr++];
} else {
tmp[ptr] = arr[lSize + (rPtr++)];
}
ptr++;
}
for (i = 0; i < size; i++)
arr[i] = tmp[i];
free(tmp);
}
int main(void) {
int n, i, con, fptr = 0, bptr = 0;
in2(n,con);
AL ** graph = calloc(n, sizeof(AL*));
int * hasCat = calloc(n, sizeof(int));
int * parent = calloc(n, sizeof(int));
int * q = calloc(n + 1, sizeof(int));
int * con2 = calloc(n + 1, sizeof(int));
fo3(i,0,n-1) {
graph[i] = ALCreate(1);
in1(hasCat[i]);
parent[i] = -2;
}
fo3(i,2,n) {
int a, b;
in2(a,b);
a--;b--;
ALAdd(graph[a],b);
ALAdd(graph[b],a);
}
parent[0] = -1;
q[bptr++] = 0;
int ans = 0;
con2[0] = hasCat[0];
while (fptr != bptr) {
int cur = q[fptr++];
int hasChild = FALSE;
fo3(i,0,graph[cur]->size - 1) {
int next = graph[cur]->vals[i];
if (parent[cur] != next) {
q[bptr++] = next;
parent[next] = cur;
con2[next] = 0;
if (con2[cur] == con + 1)
con2[next] = con + 1;
else if (hasCat[next])
con2[next] = con2[cur] + 1;
hasChild = TRUE;
}
}
if (!hasChild && con2[cur] != con + 1) ans++;
}
pri(ans);
return 0;
} | |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | ea738afb8963549a5fbf21c9cac27bd0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
typedef struct ll
{
int x;
struct ll* next;
}node;
node* a[100020];
long long int b[100020],count=0;
node* nnode(void)
{
node* temp = (node*)malloc(sizeof(node));
temp->next = NULL;
return temp;
}
void initialize(void)
{
long long int i;
for(i=0; i<100020; i++)
{
a[i]=NULL;
}
}
void add_edge(long long int x,long long int y)
{
if(a[x]==NULL)
{
a[x]=nnode();
a[x]->x = y;
a[x]->next = NULL;
return;
}
node* temp = a[x];
a[x] = nnode();
a[x]->next = temp;
a[x]->x = y;
}
void dfs(long long int cur,long long int parent,long long int m,long long int m_max)
{
if(m<0)
{
return;
}
int c=0,curm = m;
if(b[cur]==1)
{
curm--;
if(curm<0)
{
return;
}
}
else
{
curm = m_max;
}
node* temp = a[cur];
while(temp!=NULL)
{
// printf("while loop of : %lld\n",cur);
// printf("current m : %d\n",curm);
// printf("parent : %lld\n\n",parent);
if(temp->x != parent)
{
c++;
dfs(temp->x,cur,curm,m_max);
}
temp=temp->next;
}
if(c==0)
{
count++;
}
}
int main()
{
initialize();
long long int n,m,i,x,y;
scanf("%lld",&n);
scanf("%lld",&m);
for(i=1; i<=n; i++)
{
scanf("%lld",&b[i]);
}
for(i=1; i<=n-1; i++)
{
scanf("%lld",&x);
scanf("%lld",&y);
add_edge(x,y);
add_edge(y,x);
}
dfs(1,0,m,m);
printf("%lld\n",count);
return 0;
} | |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | 883eb8275480a4942b07733f089884c5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include "stdio.h"
#include "stdlib.h"
#define MAX_VERTICES_COUNT 100005
#define BASE "%d"
typedef int Base;
typedef struct UTreeNode
{
Base *Childrens;
Base ChildrenCount;
Base IsCatHere;
Base IsVisited;
} UTreeNode;
static UTreeNode Tree[MAX_VERTICES_COUNT];
Base DFSWithCatCount(UTreeNode *Tree, Base Vertex, Base CatResistance, const Base InitialCatResistance)
{
static Base Leafs = 0;
Base CurrentCatResistance = CatResistance;
Tree[Vertex].IsVisited = 1;
if (Tree[Vertex].IsCatHere)
{
CurrentCatResistance--;
}
else
{
CurrentCatResistance = InitialCatResistance;
}
if (CurrentCatResistance < 0)
{
return Leafs;
}
for (Base i = 0; i < Tree[Vertex].ChildrenCount; i++)
{
if (!Tree[Tree[Vertex].Childrens[i]].IsVisited)
{
DFSWithCatCount(Tree, Tree[Vertex].Childrens[i], CurrentCatResistance, InitialCatResistance);
}
}
if ((Tree[Vertex].ChildrenCount == 1) && (Vertex != 1))
{
Leafs++;
}
return Leafs;
}
int main()
{
Base Vertices = 0;
Base CatResistance = 0;
Base FirstNode = 0;
Base SecondNode = 0;
Base Root = 1;
scanf(BASE BASE, &Vertices, &CatResistance);
for (Base i = 1; i <= Vertices; i++)
{
scanf(BASE, &Tree[i].IsCatHere);
Tree[i].ChildrenCount = 0;
Tree[i].IsVisited = 0;
}
for (Base i = 0; i < Vertices - 1; i++)
{
scanf(BASE BASE, &FirstNode, &SecondNode);
Tree[FirstNode].Childrens = (Base *) realloc(Tree[FirstNode].Childrens,
(Tree[FirstNode].ChildrenCount + 1) * sizeof(Base));
Tree[SecondNode].Childrens = (Base *) realloc(Tree[SecondNode].Childrens,
(Tree[SecondNode].ChildrenCount + 1) * sizeof(Base));
Tree[FirstNode].Childrens[Tree[FirstNode].ChildrenCount++] = SecondNode;
Tree[SecondNode].Childrens[Tree[SecondNode].ChildrenCount++] = FirstNode;
}
printf(BASE"\n", DFSWithCatCount(Tree, Root, CatResistance, CatResistance));
return 0;
}
| |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | b592d771e8163689f200488e2d3a0c8c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | /* Coached by rainboy */
#include <stdio.h>
#define N 100000
int oo[1 + (N - 1) * 2], oj[1 + (N - 1) * 2];
int link(int o, int j) {
static int _ = 1;
oo[_] = o, oj[_] = j;
return _++;
}
int cc[N], ae[N];
int m, cnt;
void dfs(int p, int i, int k) {
int o;
k = cc[i] ? k + 1 : 0;
if (k > m)
return;
if (p != -1 && oo[ae[i]] == 0) {
cnt++;
return;
}
for (o = ae[i]; o; o = oo[o]) {
int j = oj[o];
if (j != p)
dfs(i, j, k);
}
}
int main() {
int n, h, i, j;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%d", &cc[i]);
for (h = 0; h < n - 1; h++) {
scanf("%d%d", &i, &j), i--, j--;
ae[i] = link(ae[i], j);
ae[j] = link(ae[j], i);
}
dfs(-1, 0, 0);
printf("%d\n", cnt);
return 0;
}
| |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | 25d5dace9090788257a74a1e2a37da73 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int num;
struct node* next;
}Node;
typedef struct
{
int cat;
int total_cat;
int vis;
Node* head;
Node* use;
}Point;
int ans;
void Add(int, int, Point*);
void Dfs(Point*,int ,int, int);
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
ans=0;
Point *vetice=calloc(n+1,sizeof(Point));
int i,j,k;
for(i=1;i<=n;i++)
{
vetice[i].head=NULL;
vetice[i].use=NULL;
scanf("%d",&vetice[i].cat);
}
for(i=1;i<n;i++)
{
scanf("%d%d",&j,&k);
Add(j,k,vetice);
Add(k,j,vetice);
}
Dfs(vetice,1,0,m);
printf("%d\n",ans);
free(vetice);
}
}
void Add(int i,int j,Point vetice[])
{
if(vetice[i].head==NULL)
{
vetice[i].head=calloc(1,sizeof(Node));
vetice[i].use=vetice[i].head;
}
else
{
vetice[i].use->next=calloc(1,sizeof(Node));
vetice[i].use=vetice[i].use->next;
}
vetice[i].use->next=NULL;
vetice[i].use->num=j;
}
void Dfs(Point vetice[],int now,int last,int total)
{
vetice[now].vis=1;
if(now!=1)
{
if(vetice[now].cat==1)
{
vetice[now].total_cat=vetice[last].total_cat+1;
if(vetice[now].total_cat>total) return ;
}
else vetice[now].total_cat=0;
}
else
{
if(vetice[now].cat==1)
{
vetice[now].total_cat=1;
}
}
if(vetice[now].head->next==NULL&&now!=1)
{
ans++;
}
vetice[now].use=vetice[now].head;
while(vetice[now].use)
{
if(vetice[vetice[now].use->num].vis==0)
Dfs(vetice,vetice[now].use->num,now,total);
vetice[now].use=vetice[now].use->next;
}
}
| |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | 2bce64148beb5282a3217770c9f2d71f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include<stdio.h>
#include<stdlib.h>
#define sf scanf
#define pf printf
#define sz 100001
struct arr
{
int a;
struct arr *next;
};
typedef struct arr linklist;
linklist *G[sz];
int vis[sz],cat[sz],m,ans;
int length(linklist *head)
{
int count=0;
linklist *cur=head;
while(cur!=NULL)
{
count++;
if(count>1)
return count;
cur=cur->next;
}
return count;
}
void dfs(int u,int total)
{
if(total>m)return;
vis[u]=1;
linklist *temp=G[u];
int len=length(temp);
if(u>1&&len==1&&total<=m){ans++;
//pf("%d!!%d\n",u,total);
}
while(temp!=NULL)
{
if(!vis[temp->a]){
if(cat[temp->a])
cat[temp->a]=total+1;
dfs(temp->a,cat[temp->a]);
}
temp=temp->next;
}
}
void push(linklist** head,int u,int v)
{
linklist *x;
x=(linklist*)malloc(sizeof(linklist));
x->a=v;
if(*head==NULL)
{
x->next=NULL;
*head=x;
return;
}
x->next=*head;
*head=x;
}
int main()
{
int v,e,i,u1,u2,n;
sf("%d %d",&n,&m);///v=vertex,e=edge
for(i=1;i<=n;i++){
sf("%d",&cat[i]);
G[i]=NULL;
}
for(i=1;i<n;i++){
sf("%d %d",&u1,&u2);
push(&G[u1],u1,u2);
push(&G[u2],u2,u1);
}
dfs(1,cat[1]);
pf("%d\n",ans);
return 0;
}
| |
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats. | C | 875e7048b7a254992b9f62b9365fcf9b | 01a69e37f80ef07d060bf4f9b5ed9c69 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1442939400 | ["4 1\n1 1 0 0\n1 2\n1 3\n1 4", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"] | NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test: The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test: The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge. It is guaranteed that the given set of edges specifies a tree. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
#define max(a,b) a > b ? a : b;
#define START_SIZE 16
#define print(int_var) printf("%d\n", int_var);
typedef struct {
int* content;
size_t size;
size_t pos;
} Stack;
Stack* init() {
Stack *new_stack = malloc(sizeof(Stack));
new_stack->content = malloc(START_SIZE * sizeof(int));
new_stack->size = START_SIZE;
new_stack->pos = 0;
return new_stack;
}
void resize(Stack* stack) {
stack->size *= 2;
stack->content = realloc(stack->content, stack->size * sizeof(int));
}
void push(Stack* stack, int x) {
if (stack->pos >= stack->size) {
resize(stack);
}
stack->content[stack->pos] = x;
stack->pos++;
}
int **arr_init(int n, int m) {
int **arr = malloc(n * sizeof(int*) + n * m * sizeof(int));
arr[0] = (int*) (arr + n);
for (int i = 0; i < n; ++i) {
arr[i] = arr[0] + i * m;
}
return arr;
}
// ver0 i - cats from i in line
// ver1 i - parent
// ver2 i - max cat line from i
void update(int **ver, int x) {
int par = ver[1][x];
if (ver[2][par] == -1) {
update(ver, par);
}
if (ver[0][x]) {
ver[0][x] = ver[0][par] + 1;
}
ver[2][x] = max(ver[0][x], ver[2][par]);
}
void zagnat_graph(Stack** prepare, int** ver, int x) {
for (int i = 0; i < prepare[x]->pos; ++i) {
int child = prepare[x]->content[i];
if (ver[2][child] == -2) {
ver[2][x] = -1;
ver[1][child] = x;
zagnat_graph(prepare, ver, child);
}
}
}
void print_stack(Stack* stack) {
for (int i = 0; i < stack->pos; ++i) {
printf("%d ", stack->content[i]);
}
printf("\n");
}
int main() {
int n, c;
scanf("%d %d", &n, &c);
Stack** prepare = malloc(n * sizeof(Stack*));
for (int i = 0; i < n; ++i) {
prepare[i] = init();
}
int **ver = arr_init(3, n);
for (int i = 0; i < n; ++i) {
scanf("%d", &ver[0][i]);
ver[2][i] = -2;
}
for (int i = 1; i < n; ++i) {
int x, y;
scanf("%d %d", &x, &y);
push(prepare[x - 1], y - 1);
push(prepare[y - 1], x - 1);
}
zagnat_graph(prepare, ver, 0);
ver[2][0] = ver[0][0];
int r = 0;
for (int i = 0; i < n; ++i) {
if (ver[2][i] == -2) {
update(ver, i);
if (ver[2][i] <= c) {
r++;
}
}
}
printf("%d\n", r);
free(ver);
return 0;
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | af32a80038e5cb73858186f93b1d49f6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <ctype.h>
#define INT_MAX 200000
int palindrome(char str[],int N){
int i=0,j=0;
while(i<=N/2-1 && j<=N/2-1){
if(abs((str[i])-(str[N-i-1]))==2 || str[i]==str[N-i-1]){
j++;
}
i++;
}
return j;
}
int main(){
int T,N,x,y,i=0;
char str[100];
scanf("%d",&T);
while(T--){
scanf("%d",&N);
scanf("%s",str);
y=strlen(str);
x=palindrome(str,N);
if(x==N/2){
printf("YES\n");
}
else{
printf("NO\n");
}
for(i=0;i<=y;i++){
str[i]='\0';
}
i=0;
}
return 0;
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | a99c73f943560c828883a961fd0a8b2d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i,p=0;
scanf("%d",&n);
char str[n+1];
scanf("%s",str);
for(i=0; i<n/2; i++)
{
if((str[i]+1)==(str[n-i-1]+1))
{
p=1;
}
else if((str[i]+1)==(str[n-i-1]-1))
{
p=1;
}
else if((str[i]-1)==(str[n-i-1]-1))
{
p=1;
}
else if((str[i]-1)==(str[n-i-1]+1))
{
p=1;
}
else
{
p=0;
printf("NO\n");
break;
}
}
if(p==1)
{
printf("YES\n");
}
}
}
| |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 77cbc17694e3b523b75b6536fe67fe2d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include <stdio.h>
int main(){
int n,counter=0,i,x,l,z,e,c=0;
scanf("%d",&n);
while(counter<n){
scanf("%d",&x);
c=0;
char s[x];
scanf("%s",s);
for(i=0,e=x-1-i;i<x/2;i++,e--){
if(s[i]==s[e])
c++;
else{
l=s[i];
z=s[e];
if((l+2==z) || (l-2==z))
c++;
}
}
if(c*2 == x)
printf("YES\n");
else
printf("NO\n");
counter++;
}
return 0;
}
| |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 5dd5229565ca252b73f4e79f3dbd3144 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
#include<math.h>
main()
{
int t, n, f, i, p, j;
char a[102];
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
scanf("%s", a);
for (i=0, j=n-1, f=0; j>i; i++, j--)
{
p=abs(a[i]-a[j]);
if (p!=0 && p!=2)
{
f=1;
break;
}
}
if (f==0)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | c94e1c5ec9c0e752074e9f718f7113ff | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int f,k;
scanf("%d\n",&k);
while(k>0)
{
scanf("%d\n",&f);
char s[f];
int q;
gets(s);
int d=strlen(s),i=0,z=0,n,m;
int j=d-1;
while(i!=j&&i<=(d/2)&&j>=(d/2))
{
n=(int)s[i];
m=(int)s[j];
if(m==n||(m+1)==(n+1)||(m-1)==(n-1)||(m+1)==(n-1)||(m-1)==(n+1))
{
z++;
}
i++;
j--;
}
if(z==(strlen(s))/2)
{
printf("YES\n");
}
else{
printf("NO\n");}
k--;}
return 0;
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 2f81ab1621e3698cff05f13f2c860ce5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include <stdio.h>
int areequal(char a, char b){
int p=a, q =b;
int parr[3]={0,1,-1}, qarr[3]={0,1,-1};
if(p=='z')
parr[1]=-1;
if(q=='z')
qarr[1]=-1;
if(p=='a')
parr[2]=1;
if(q=='a')
qarr[2]=1;
for(int i=1; i<3; i++){
for(int j=1; j<3; j++){
if(p+parr[i] == q+qarr[j])
return 1;
}
}
return 0;
}
int main(){
int test;
scanf("%d", &test);
while(test--){
int n;
char str[101];
scanf("%d", &n);
scanf("%s", str);
int flag = 0;
for(int i=0; 2*i<=n-1; i++){
if(areequal(str[i], str[n-i-1])==0){
printf("NO\n");
flag = 1;
break;
}
}
if(flag == 0)
printf("YES\n");
}
return 0;
}
| |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 8833533ab83993c630fd68d088ed484c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
#include<string.h>
int main( ){
int s;
scanf("%d",&s);
for(int i=0;i<s;i++){
int x;
scanf("%d",&x);
char a[x];
scanf("%s",a);
int f=0;
for(int i=0;i<x/2;i++){
if((a[i]!=a[x-1-i])&&(abs(((a[x-1-i]-a[i])))!=2)){
f=1;
}
}
if(f==1){
printf("NO\n");
}
else{
printf("YES\n");
}
}
return 0;
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 9073390c5cea9361f9df66f6e6b97804 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
#include<string.h>
int main()
{
int f,k;
scanf("%d\n",&k);
while(k>0)
{
scanf("%d\n",&f);
char s[f];
int q;
gets(s);
int d=strlen(s),i=0,z=0,n,m;
int j=d-1;
while(i!=j&&i<=(d/2)&&j>=(d/2))
{
n=(int)s[i];
m=(int)s[j];
if(m==n||(m+1)==(n+1)||(m-1)==(n-1)||(m+1)==(n-1)||(m-1)==(n+1))
{
z++;
}
i++;
j--;
}
if(z==(strlen(s))/2)
{
printf("YES\n");
}
else{
printf("NO\n");}
k--;}
return 0;
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | bead47dce5b0db72656d8f5ce90a798b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
#include<string.h>
int main(){
int t;
scanf("%d",&t);
for(int i=0;i<t;i++){
int n,m=0;
scanf("%d",&n);
char s[n];
scanf("%s",s);
int k=strlen(s);
for(int j=0;j<k/2;j++){
if(s[j]==s[k-j-1]||s[j]==s[k-j-1]+2||s[j]==s[k-j-1]-2){
m+=1;
}
}
if(m==k/2)printf("YES\n");
else printf("NO\n");
}
} | |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 41b7440edd8019e2fb643cb6d74fbc39 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include <stdio.h>
#include <stdlib.h>
int main ()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
char s[n];
int c=0,i,j;
scanf("%s",s);
for(i=0;i<n/2;i++)
{
j=abs(s[i]-s[n-1-i]);
if(j==2||j==0)
c++;
}
if(c==n/2)
printf("YES\n");
else
printf("NO\n");
}
}
| |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 3e7cd13ba6b9dcc3cc0fc81228ef0ba8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
#include<math.h>
int main()
{
int p;
scanf("%d",&p);
while(p--)
{
int n,b=0,i;
scanf("%d",&n);
char s[n];
scanf("%s",s);
for(i=0;i<n/2;i++)
{
if(s[i]-s[n-1-i]==2 || s[i]-s[n-i-1]==-2 || s[i]-s[n-i-1]==0)
{
b++;
}
}
if(b==n/2)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
| |
You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately. | Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise. | C | cc4cdcd162a83189c7b31a68412f3fe7 | 13abe16dd49a07ddb2943d3306357902 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"strings"
] | 1534602900 | ["5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml"] | NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm". | PASSED | 1,000 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. | ["YES\nNO\nYES\nNO\nNO"] | #include<stdio.h>
int check(char s[],int n){
int f=0,c=0;
for(int i=0,j=n-1;i<=n/2,j>=n/2;i++,j--){
int p=s[i];int q=s[j];
if(p==q || p-q==2 || p-q==-2){
f=0;c++;
}
else{f=1;}
}
if(c==n/2)
{return f;}
else return -1;
}
int main(){
int t;
scanf("%d\n",&t);
for(int i=0;i<t;i++){
int n;
scanf("%d\n",&n);
char s[n];
scanf("%s",s);
int r=check(s,n);
if(r==0){printf("YES\n");}
else{printf("NO\n");}
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.