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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. | If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). | C | 0c9550a09f84de6bed529d007ccb4ae8 | 94abae6d11b76ddffbf13edccb9c71d6 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1315494000 | ["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"] | null | PASSED | 1,600 | standard input | 5 seconds | The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. | ["YES", "NO", "YES"] | #include <stdio.h>
#include <string.h>
char str[100005];
int main()
{
int i,l,s1=1,s2=1,f1=1,f2=1,f3=1,v,s=0;
while (scanf("%s",str+1)!=EOF)
{
if (++s>1)
f3=0;
l=strlen(str+1);
v=2;
if (str[l-3]=='l'&&str[l-2]=='i'&&str[l-1]=='o'&&str[l]=='s')
f1&=(s1==1);
else if (str[l-2]=='e'&&str[l-1]=='t'&&str[l]=='r')
{
f1&=(s1==1);
s1=2;
}
else if (str[l-5]=='i'&&str[l-4]=='n'&&str[l-3]=='i'&&str[l-2]=='t'&&str[l-1]=='i'&&str[l]=='s')
f1&=(s1==2);
else
{
f1=0;
v--;
}
if (str[l-4]=='l'&&str[l-3]=='i'&&str[l-2]=='a'&&str[l-1]=='l'&&str[l]=='a')
f2&=(s2==1);
else if (str[l-3]=='e'&&str[l-2]=='t'&&str[l-1]=='r'&&str[l]=='a')
{
f2&=(s2==1);
s2=2;
}
else if (str[l-5]=='i'&&str[l-4]=='n'&&str[l-3]=='i'&&str[l-2]=='t'&&str[l-1]=='e'&&str[l]=='s')
f2&=(s2==2);
else
{
f2=0;
v--;
}
if (!v)
f3=0;
}
if (s1==1)
f1=0;
if (s2==1)
f2=0;
puts((f1||f2||f3)?"YES":"NO");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 8676d972b44c06bc718f3496826ac7f1 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
char a[503][503];
int main(void)
{
int h, w;
int indi=0;
int hpos=0, wpos=0;
scanf("%d %d", &h, &w);
scanf("\n");
int i, j;
for(i=1;i<=h;i++)
{
for(j=1;j<=w;j++) scanf(" %c", &a[i][j]);
} //input finished
for(i=1;i<=h;i++)
{
if(indi==1) break;
for(j=1;j<=w;j++)
{
if(a[i][j]=='*' && a[i][j-1]=='*' && a[i][j+1]=='*' && a[i+1][j]=='*' && a[i-1][j]=='*')
{
hpos=i;
wpos=j;
indi=1;
break;
}
if(indi==1) break;
}
if(indi==1) break;
}//여기까진 괜찮은 듯...
if(indi==0)
{
printf("NO");
return 0;
} //No Cross
if(indi==1)
{
for(i=1;i<=h;i++)
{
for(j=1;j<=w;j++)
{
if(i!=hpos && j!=wpos && a[i][j]=='*')
{
printf("NO");
return 0;
}// 여기가 문제...
}
}
i=hpos; //높이 고정... 옆으로 탐색.
for(j=wpos;j>=1;j--) if(a[i][j+1]=='.' && a[i][j]=='*')
{
printf("NO");
return 0;
}
for(j=wpos;j<=w;j++) if(a[i][j-1]=='.' && a[i][j]=='*')
{
printf("NO");
return 0;
}
j=wpos;
for(i=hpos;i>=1;i--) if(a[i+1][j]=='.' && a[i][j]=='*')
{
printf("NO");
return 0;
}
for(i=hpos;i<=h;i++) if(a[i-1][j]=='.' && a[i][j]=='*')
{
printf("NO");
return 0;
}
}
printf("Yes");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | b3c090144b9be3d8daa5cddc19269bf3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int h, w;
scanf("%d %d", &h, &w);
int i, j;
char s[502][502];
for (i = 0; i < h; i++)
scanf("%s", s[i]);
int p = 0;
int x, y;
for (i = 1; i < h - 1; i++)
{
for (j = 1; j < w - 1; j++)
{
if (s[i][j] == '*' && s[i][j - 1] == '*' && s[i][j + 1] == '*' && s[i - 1][j] == '*' && s[i + 1][j] == '*')
{
x = i;
y = j;
p++;
break;
}
}
if (p > 0)
break;
}
if (p == 0)
{
printf("NO\n");
return 0;
}
s[x][y] = '.';
i = x;
j = y - 1;
while (s[i][j] == '*')
{
s[i][j] = '.';
if (j == 0)
break;
j--;
}
j = y + 1;
while (s[i][j] == '*')
{
s[i][j] = '.';
if (j == w - 1)
break;
j++;
}
j = y;
i = x - 1;
while (s[i][j] == '*')
{
s[i][j] = '.';
if (i == 0)
break;
i--;
}
i = x + 1;
while (s[i][j] == '*')
{
s[i][j] = '.';
if (i == h - 1)
break;
i++;
}
for (i = 0; i < h; i++)
{
for (j = 0; j < w; j++)
{
if (s[i][j] == '*')
{
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | a9b0e4693676b65e302627bda1be5f6d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<math.h>
int main()
{
int w, h, i, j, a=0, cnt=0, c=0, d=0;
scanf("%d %d", &h, &w);
getchar();
char str[h+1][w+1];
for (i=0; i<h; i++)
gets(str[i]);
for (i=0; i<h; i++)
for (j=0; j<w; j++)
if ( str[i][j]=='*' )
cnt++;
if ( cnt==0 )
a++;
for (i=0; i<h; i++)
for (j=0; j<w; j++)
if ( str[i][j]=='*' && str[i+1][j]=='*' && str[i-1][j]=='*' && str[i][j+1]=='*' && str[i][j-1]=='*' )
goto A;
A:
for ( c=i; c<h; c++)
{
if ( str[c][j]=='*')
str[c][j]='.';
else
break;
}
for ( c=i-1; c>=0; c--)
{
if ( str[c][j]=='*')
str[c][j]='.';
else
break;
}
for ( d=j+1; d<w; d++)
{
if ( str[i][d]=='*')
str[i][d]='.';
else
break;
}
for ( d=j-1; d>=0; d--)
{
if ( str[i][d]=='*')
str[i][d]='.';
else
break;
}
for (i=0; i<h; i++)
for (j=0; j<w; j++)
if ( str[i][j]=='*' )
a++;
if ( a==0 )
printf("YES\n");
else
printf("NO\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 4b61e0cc6ac3a0007fce99c6d2758f60 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
int main()
{
int h, w;
while(scanf("%d %d", &h, &w) != EOF)
{
int i, j, flag = 0, temp, tempi;
char ara[h+1][w+1];
for(i = 0; i < h; i++)
{
for(j = 0; j < w; j++)
{
scanf(" %c", &ara[i][j]);
}
}
for(i = 1; i < h; i++)
{
for(j = 1; j < w; j++)
{
if(i == h-1 || j == w-1)
{
continue;
}
if(ara[i][j] == '*' && ara[i][j+1] == '*' && ara[i][j-1] == '*' && ara[i-1][j] == '*' && ara[i+1][j] == '*')
{
while(ara[i][j] == '*')
{
temp = j;
tempi = i;
while(ara[i][j+1] == '*')
{
ara[i][j+1] = '.';
j++;
}
j = temp;
while(ara[i][j-1] == '*')
{
ara[i][j-1] = '.';
j--;
}
j = temp;
while(ara[i+1][j] == '*')
{
ara[i+1][j] = '.';
i++;
}
i = tempi;
while(ara[i-1][j] == '*')
{
ara[i-1][j] = '.';
i--;
}
i = tempi;
ara[i][j] = '.';
}
flag = 1;
break;
}
}
if(flag == 1)break;
}
for(i = 0; i < h; i++)
{
for(j = 0; j < w; j++)
{
if(ara[i][j] == '*')
{
flag = 0;
break;
}
}
if(flag == 0)break;
}
if(flag == 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | f15aab0d80aa1b6ccee75aaa435033f3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
int main(int argc, char const *argv[]) {
char map[510][510];
int h, w, flag = 1, start_w = -1, start_h = -1, series_w = 0, series_h = 0, no_h = 500, no_w = 500;
scanf("%d %d", &h, &w);
for (int i = 0; i < h; i++) {
scanf("%s", map[i]);
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if(map[i][j] == '*' && start_w == -1) {
start_w = j;
series_h = i;
no_h = i;
continue;
}
if(map[i][j] == '*' && j == start_w){
if(series_h != i - 1) {
flag = 0;
break;
}
else series_h++;
}
if(map[i][j] == '*' && j != start_w && start_h == -1) {
start_h = i;
series_w = j;
no_w = j;
continue;
}
if(map[i][j] == '*' && i == start_h) {
if(series_w != j - 1) {
flag = 0;
break;
}
else series_w++;
}
if(map[i][j] == '*' && j != start_w && i!= start_h){
flag = 0;
break;
}
}
if(flag == 0) break;
}
if(flag != 0 && series_h - no_h >= 2 && series_w - no_w >= 2 && series_h > start_h && series_w > start_w) printf("YES\n");
else printf("NO\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | f67c0c482bef98b5464a99cddb839f7e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
int main(){
char a[1000][1000];
int n,m,i,j,k,cnt=0,t;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i){
scanf("%s",a[i]+1);
for(j=1;j<=m;++j)if(a[i][j]=='*')++cnt;
}
for(i=2;i<n;++i)
for(j=2;j<m;++j)if(a[i][j]=='*'&&a[i-1][j]=='*'&&a[i+1][j]=='*'&&a[i][j-1]=='*'&&a[i][j+1]=='*'){
for(t=1,k=i-1;k&&a[k][j]=='*';--k)++t;
for(k=i+1;k<=n&&a[k][j]=='*';++k)++t;
for(k=j-1;k&&a[i][k]=='*';--k)++t;
for(k=j+1;k<=m&&a[i][k]=='*';++k)++t;
if(t==cnt){
printf("YES\n");
return 0;
}
}
printf("NO\n");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 5ab8c12a49f15699eca6416d5ff8bef5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int w, h;
scanf("%d %d", &h, &w);
int r=-1;
int c=-1;
int fr=-1;
int ce=0;
int rt=0;
int ct=0;
char arr[h][w+1];
for (int i=0; i<h; i++){
scanf("%s", arr[i]);
}
for (int i=0; i<h; i++){
for(int j=0; j<w; j++){
if (r==-1 && c==-1 && i<h-1){
if (arr[i][j]=='*' && j>0 && j<w-1){
c=j;
fr=i;
}
else if (arr[i][j]=='*'){
printf("NO");
return 0;
}
}
else if(r==-1 && c!=-1){
if(arr[i][j]=='*' && j!=c && i>fr){
r=i;
continue;
}
else if(arr[i][j]=='*' && j!=c){
printf("NO");
return 0;
}
else if(j==c){
if (arr[i][j]=='.'){
printf("NO");
return 0;
}
}
}
else if(r!=-1 && c!=-1){
if(i==r && j==c){
if(arr[i][j]=='*'){
ce=1;
continue;
}
else {
printf("NO");
return 0;
}
}
if (i==r && ce==0){
if (arr[i][j]=='.'){
printf("NO");
return 0;
}
}
else if (i==r && rt==0){
if (arr[i][j]=='.' && j>c+1) rt=1;
if (arr[i][j]=='.' && j==c+1) {
printf("NO");
return 0;
}
}
else if (i==r && rt==1){
if (arr[i][j]=='*'){
printf("NO");
return 0;
}
}
else if(j==c && ct==0){
if (arr[i][j]=='.' && i>r+1) ct=1;
if (arr[i][j]=='.' && i==r+1) {
printf("NO");
return 0;
}
}
else if (j==c && ct==1){
if (arr[i][j]=='*'){
printf("NO");
return 0;
}
}
else if (arr[i][j]=='*') {
printf("NO");
return 0;
}
}
}
}
if(r!=-1 && c!=-1 && ce==1)printf("YES");
else printf("NO");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 2f26e2f826242ed2ff61b4e396fe0ce3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int h,w,i,j;
scanf("%d %d",&h,&w);
char str[h+1][w+1];
for(i=0;i<h;i++)
{
scanf("%s",&str[i]);
}
int c = 0,totalS=0;
for(i=1;i<h-1;i++)
{
for(j=1;j<w-1;j++)
{
if(str[i][j]=='*')
{
if(str[i][j-1] == '*' && str[i][j+1]=='*'&&str[i-1][j]=='*'&&str[i+1][j]=='*')
{
totalS++;
int index=i-1;
char ch = str[index][j];
int p=i-1;
while(str[p][j] == '*')
{
str[p][j]='.';
p--;
}
p=i+1;
while(str[p][j] == '*')
{
str[p][j]='.';
p++;
}
p=j-1;
while(str[i][p] == '*')
{
str[i][p]='.';
p--;
}
p=j+1;
while(str[i][p] == '*')
{
str[i][p]='.';
p++;
}
str[i][j]='.';
break;
}
}
}
if(totalS!=0)
{
break;
}
}
if(totalS!=1)
{
printf("NO\n");
return 0;
}
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
if(str[i][j]=='*')
{
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 07efab5f9d0cf77b915a64704b64d0e5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<math.h>
int main(){
int h, w, i, j, c = 0, d = 0, count = 0, n = 0;
scanf("%d%d", &h, &w);
getchar();
char a[h+1][w+1];
for(i = 0; i < h; i++)
gets(a[i]);
if(h <= 2 && w <= 2)
printf("NO");
else{
for(i = 0; i < h; i++){
for(j = 0; j < w; j++){
if(a[i][j] == '*' && a[i+1][j] == '*' && a[i-1][j] == '*' && a[i][j+1] == '*' && a[i][j-1] == '*'){
c = i;
d = j;
n++;
}
}
}
for(i = c; i >= 0; i--){
if(a[i][d] == '*')
a[i][d] = '.';
else
break;
}
for(i = c+1; i < h; i++){
if(a[i][d] == '*')
a[i][d] = '.';
else
break;
}
for(j = d-1; j >= 0; j--){
if(a[c][j] == '*')
a[c][j] = '.';
else
break;
}
for(j = d+1; j < w; j++){
if(a[c][j] == '*')
a[c][j] = '.';
else
break;
}
for(i = 0; i < h; i++)
for(j = 0; j < w; j++)
if(a[i][j] == '*')
count++;
if(count == 0 && n == 1)
printf("YES");
else
printf("NO");
}
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | e62d1df5615eb1154dff2b677fbf6a51 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
return ( *(long long*)a - *(long long*)b );
}
int main(void){
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a2,b2,k;
char a[501][501];
scanf("%lld%lld",&n,&m);
for(i=0;i<n;i++){
scanf("%s",&a[i]);
}
count=0;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
// printf("%lld %lld %lld \n",i,j,count);
if(a[i][j]=='*' && a[i+1][j]=='*' && a[i][j+1]=='*' && a[i][j-1]=='*' && a[i-1][j]=='*' ){
count++;
k=i;
l=j;
while(a[k][l]=='*' && l<m){
a[k][l]='.';
l++;
}
k=i-1;
l=j;
while(a[k][l]=='*' && k>=0){
a[k][l]='.';
k--;
}
k=i+1;
l=j;
while(a[k][l]=='*' && k<n){
a[k][l]='.';
k++;
}
k=i;
l=j-1;
while(a[k][l]=='*' && l>=0){
a[k][l]='.';
l--;
}
}
// printf("%lld %lld %lld\n",i,j,count);
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(a[i][j]=='*'){
printf("NO");
return 0;
}
}
}
if(count==1){
printf("YES");
}else{
printf("NO");
}
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 9b276164d871af52fe31d09ce3f714cb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
return ( *(long long*)a - *(long long*)b );
}
int main(void){
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,k,c,r,o,sum1,sum=0,y,b,count1=0,a2,b2;
char a[500][500];
scanf("%lld%lld\n",&n,&m);
for(i=0;i<n;i++){
scanf("%s",&a[i]);
}
flag=0;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(a[i][j]=='*' && a[i][j+1]=='*' && a[i+1][j]=='*' && a[i-1][j]=='*' && a[i][j-1]=='*'){
k=i;
c=j;
while(a[k][c]=='*' && c<m){
a[k][c]='.';
c++;
}
k=i+1;
c=j;
while(a[k][c]=='*' && k<n){
a[k][c]='.';
k++;
}
k=i;
c=j-1;
while(a[k][c]=='*' && c>=0){
a[k][c]='.';
c--;
}
k=i-1;
c=j;
while(a[k][c]=='*' && k>=0){
a[k][c]='.';
k--;
}
flag=1;
break;
}
}
if(flag==1){
break;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(a[i][j]=='*'){
printf("NO");
return 0;
}
}
}
if(flag==1){
printf("YES");
}else{
printf("NO");
}
return 0;
}
| |
Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by $$$n$$$ streets along the Eastern direction and $$$m$$$ streets across the Southern direction. Naturally, this city has $$$nm$$$ intersections. At any intersection of $$$i$$$-th Eastern street and $$$j$$$-th Southern street there is a monumental skyscraper. Dora instantly became curious and decided to explore the heights of the city buildings.When Dora passes through the intersection of the $$$i$$$-th Eastern and $$$j$$$-th Southern street she examines those two streets. After Dora learns the heights of all the skyscrapers on those two streets she wonders: how one should reassign heights to the skyscrapers on those two streets, so that the maximum height would be as small as possible and the result of comparing the heights of any two skyscrapers on one street wouldn't change.Formally, on every of $$$nm$$$ intersections Dora solves an independent problem. She sees $$$n + m - 1$$$ skyscrapers and for each of them she knows its real height. Moreover, any two heights can be compared to get a result "greater", "smaller" or "equal". Now Dora wants to select some integer $$$x$$$ and assign every skyscraper a height from $$$1$$$ to $$$x$$$. When assigning heights, Dora wants to preserve the relative order of the skyscrapers in both streets. That is, the result of any comparison of heights of two skyscrapers in the current Eastern street shouldn't change and the result of any comparison of heights of two skyscrapers in current Southern street shouldn't change as well. Note that skyscrapers located on the Southern street are not compared with skyscrapers located on the Eastern street only. However, the skyscraper located at the streets intersection can be compared with both Southern and Eastern skyscrapers. For every intersection Dora wants to independently calculate the minimum possible $$$x$$$.For example, if the intersection and the two streets corresponding to it look as follows: Then it is optimal to replace the heights of the skyscrapers as follows (note that all comparisons "less", "equal", "greater" inside the Eastern street and inside the Southern street are preserved) The largest used number is $$$5$$$, hence the answer for this intersection would be $$$5$$$.Help Dora to compute the answers for each intersection. | Print $$$n$$$ lines containing $$$m$$$ integers each. The integer $$$x_{i,j}$$$, located on $$$j$$$-th position inside the $$$i$$$-th line is an answer for the problem at the intersection of $$$i$$$-th Eastern street and $$$j$$$-th Southern street. | C | 206861107f0c06d3c8e358a85b9ddd7f | 53a5b6f680d243c7ebadf59ce8229343 | GNU C11 | standard output | 512 megabytes | train_000.jsonl | [
"implementation",
"sortings"
] | 1552035900 | ["2 3\n1 2 1\n2 1 2", "2 2\n1 2\n3 4"] | NoteIn the first example, it's not possible to decrease the maximum used height for the problem at any intersection, hence we don't have to change any heights.In the second example, the answers are as follows: For the intersection of the first line and the first column For the intersection of the first line and the second column For the intersection of the second line and the first column For the intersection of the second line and the second column | PASSED | 1,600 | standard input | 2 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of streets going in the Eastern direction and the number of the streets going in Southern direction. Each of the following $$$n$$$ lines contains $$$m$$$ integers $$$a_{i,1}$$$, $$$a_{i,2}$$$, ..., $$$a_{i,m}$$$ ($$$1 \le a_{i,j} \le 10^9$$$). The integer $$$a_{i,j}$$$, located on $$$j$$$-th position in the $$$i$$$-th line denotes the height of the skyscraper at the intersection of the $$$i$$$-th Eastern street and $$$j$$$-th Southern direction. | ["2 2 2 \n2 2 2", "2 3 \n3 2"] | #include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
typedef int64_t i64;
typedef int32_t i32;
static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}
void msort_memcpy (uint8_t * restrict dst, uint8_t * restrict src, size_t size) {
while (size--) {
*dst++ = *src++;
}
}
void msort (void * const array, const size_t num, const size_t size, int (* const cmp) (const void *, const void *)) {
typedef struct operation {
size_t l;
size_t r;
int32_t type;
} op;
uint8_t * const a = (uint8_t *) array;
uint8_t * const tmp = (uint8_t *) malloc (size * num);
op stack[64];
int32_t top = 0;
stack[top++] = (op) {0, num, 0};
while (top > 0) {
const op t = stack[--top];
if (t.l + 1 >= t.r) continue;
const size_t m = (t.l + t.r) / 2;
if (t.type == 0) {
stack[top++] = (op) {t.l, t.r, 1};
stack[top++] = (op) {t.l, m , 0};
stack[top++] = (op) {m , t.r, 0};
continue;
}
msort_memcpy (tmp, a + t.l * size, (m - t.l) * size);
size_t i = 0;
size_t j = m * size;
size_t k = t.l * size;
while (i < (m - t.l) * size && j < t.r * size) {
if (cmp (tmp + i, a + j) <= 0) {
msort_memcpy (a + k, tmp + i, size);
i += size;
} else {
msort_memcpy (a + k, a + j, size);
j += size;
}
k += size;
}
msort_memcpy (a + k, tmp + i, (m - t.l) * size - i);
}
free (tmp);
}
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
int cmp (const void *a, const void *b) {
i32 d = *(i32 *)a - *(i32 *)b;
return d == 0 ? 0 : d < 0 ? -1 : 1;
}
i32 to_index (i32 *z, i32 len, i32 v) {
i32 l = 0;
i32 r = len;
while (r - l > 1) {
i32 m = (l + r) / 2;
if (z[m] <= v) {
l = m;
} else {
r = m;
}
}
return l;
}
void calc (const i32 *a, i32 n, i32 m, i32 *row, i32 *dp) {
i32 *b = (i32 *) calloc (m, sizeof (i32));
for (i32 i = 0; i < n; ++i) {
memcpy (b, a + i * m, sizeof (i32) * m);
msort (b, m, sizeof (i32), cmp);
i32 len = 1;
for (i32 j = 1; j < m; ++j) {
if (b[j] == b[len - 1]) continue;
b[len++] = b[j];
}
row[i] = len;
for (i32 j = 0; j < m; ++j) {
dp[i * m + j] = to_index (b, len, a[i * m + j]);
}
}
free (b);
}
void run (void) {
i32 n = read_int();
i32 m = read_int();
i32 *a = (i32 *) calloc (n * m, sizeof (i32));
for (i32 i = 0; i < n * m; ++i) {
a[i] = read_int();
}
i32 *row = (i32 *) calloc (n, sizeof (i32));
i32 *row_dp = (i32 *) calloc (n * m, sizeof (i32));
calc (a, n, m, row, row_dp);
i32 *ta = (i32 *) calloc (n * m, sizeof (i32));
for (i32 i = 0; i < n; ++i) {
for (i32 j = 0; j < m; ++j) {
ta[j * n + i] = a[i * m + j];
}
}
i32 *col = (i32 *) calloc (m, sizeof (i32));
i32 *col_dp = (i32 *) calloc (n * m, sizeof (i32));
calc (ta, m, n, col, col_dp);
for (i32 i = 0; i < n; ++i) {
for (i32 j = 0; j < m; ++j) {
i32 v = MAX(row_dp[i * m + j], col_dp[j * n + i]);
i32 u = MAX(row[i] - row_dp[i * m + j], col[j] - col_dp[j * n + i]);
print_int (v + u);
putchar (j == m - 1 ? '\n' : ' ');
}
}
}
int main (void) {
run ();
return 0;
}
| |
Once upon a time an old man and his wife lived by the great blue sea. One day the old man went fishing and caught a real live gold fish. The fish said: "Oh ye, old fisherman! Pray set me free to the ocean and I will grant you with n gifts, any gifts you wish!". Then the fish gave the old man a list of gifts and their prices. Some gifts on the list can have the same names but distinct prices. However, there can't be two gifts with the same names and the same prices. Also, there can be gifts with distinct names and the same prices. The old man can ask for n names of items from the list. If the fish's list has p occurrences of the given name, then the old man can't ask for this name of item more than p times.The old man knows that if he asks for s gifts of the same name, the fish will randomly (i.e. uniformly amongst all possible choices) choose s gifts of distinct prices with such name from the list. The old man wants to please his greedy wife, so he will choose the n names in such a way that he can get n gifts with the maximum price. Besides, he isn't the brightest of fishermen, so if there are several such ways, he chooses one of them uniformly.The old man wondered, what is the probability that he can get n most expensive gifts. As the old man isn't good at probability theory, he asks you to help him. | On a single line print one real number — the probability of getting n most valuable gifts. The answer will be considered correct if its absolute or relative error does not exceed 10 - 9. | C | b8b3f75baaef9c4232e7fd7555d4fabb | af3098443c8a92133366bc74764fe039 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"combinatorics",
"probabilities",
"math"
] | 1349105400 | ["3 1\n3 10 20 30", "3 2\n1 40\n4 10 20 30 40"] | null | PASSED | 2,600 | standard input | 2 seconds | The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) — the number of the old man's wishes and the number of distinct names in the goldfish's list, correspondingly. Then m lines follow: the i-th line first contains integer ki (ki > 0) — the number of distinct prices of gifts with the i-th name, then ki distinct space-separated integers cij (1 ≤ cij ≤ 109), the gifts' prices. It is guaranteed that the sum of all ki doesn't exceed 1000. It is guaranteed that n is not greater than the total number of the gifts. | ["1.000000000", "0.166666667"] | #include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <math.h>
#include <stdbool.h>
#ifndef ONLINE_JUDGE
#define DEBUG
#endif
typedef int (*cmp_t) (const void *, const void *);
typedef unsigned uint;
typedef long long int64;
typedef unsigned long long uint64;
#define max(i, j) ({int _ = (i), __ = (j); _ > __ ? _ : __;})
#define min(i, j) ({int _ = (i), __ = (j); _ < __ ? _ : __;})
#define swap(T, i, j) ({T _ = (i); (i) = (j); (j) = _;})
#define oo 0x3F3F3F3F
#ifdef DEBUG
#define cerr(...) fprintf (stderr, __VA_ARGS__)
#define cvar(x) cerr ("[" #x ": %d]", x)
#define evar(x) cerr ("[" #x ": %d]\n", x)
void DISP (char *s, int *x, int n) {int i; cerr ("[%s: ", s); for (i = 0; i < n - 1; ++i) cerr ("%d ", x[i]); if (n) cerr ("%d", x[i]); cerr ("]\n");}
#define disp(T,n) DISP (#T " to " #n, T, n)
#else
#define cerr(...) ({})
#define cvar(...) ({})
#define evar(...) ({})
#define disp(...) ({})
#endif
#define CR cerr ("\n")
#ifdef WIN32
#define fmt64 "%I64d"
#else
#define fmt64 "%lld"
#endif
#define maxn 1100
long double f[maxn][maxn];
int buf1[maxn], buf2[maxn], *ptr = buf1, k[maxn];
double Q[maxn];
long double fac[maxn];
int cmp (int *a, int *b)
{
return *a - *b;
}
int main ()
{
#ifndef ONLINE_JUDGE
freopen ("229E.in" , "r", stdin);
freopen ("229E.out", "w", stdout);
#endif
int n, m, i, j;
scanf ("%d%d", &n, &m);
for (i = 1; i <= m; ++i)
{
scanf ("%d", &k[i]);
for (j = 1; j <= k[i]; ++j)
scanf ("%d", ++ptr);
qsort (ptr - k[i] + 1, k[i], sizeof (ptr[0]), (cmp_t)cmp);
}
memcpy (buf2, buf1, sizeof (buf1));
qsort (buf2 + 1, ptr - buf1, sizeof (buf2[0]), (cmp_t)cmp);
int x = 0, mid = buf2[ptr - buf1 - n + 1]; double ans = 1;
for (i = 1, fac[0] = 1; i < maxn; ++i)
fac[i] = fac[i - 1] * i;
int tail = 0;
/* evar (mid); */
for (i = 1; i <= m; ++i)
{
int t = 1;
for (; t <= k[i] && buf1[x + t] < mid; ++t);
int w = k[i] - t + 1;
if (t <= k[i] && buf1[x + t] == mid) Q[++tail] = 1.0 * w / t, --w;
ans *= fac[k[i] - w] * fac[w] / fac[k[i]];
n -= w;
x += k[i];
}
f[0][0] = 1;
for (i = 1; i <= tail; ++i)
for (j = 0; j <= n; ++j)
f[i][j] = (j ? f[i - 1][j - 1] * Q[i] : 0) + f[i - 1][j];
printf ("%.10e\n", (double)(ans * f[tail][n] * fac[n] * fac[tail - n] / fac[tail]));
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | f4da956e4f47225281d8c8806ea8dbcc | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n;
long long int a,b;
scanf("%d",&n);
for(int i=0; i < n; i++)
{
scanf("%lld%lld",&a,&b);
if(a % 2 && b % 2 && a >= b * b)
printf("YES\n");
else if(a % 2 == 0 && b % 2 == 0 && a >= b * b)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 837605bc43e8aaaf1204d9fa607cb1b9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
#include <math.h>
int main()
{
long long int n , k;
int t,lim;
scanf("%d",&t);
while( t--)
{
scanf("%lld %lld",&n,&k);
lim = floor(sqrt(n));
if( n<k || k>lim || (n%2==0 && k==1) )
printf("No\n");
else if(( n%2==0 && k%2==0)||(n%2!=0 && k%2!=0) || (n%2!=0 && k==1))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 8a7be59771e3eb8af38e1ac05937e45f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d %d",&n,&k );
if(k>n/k)
printf("No\n");
else if(k<=n/k)
if(n%2==0 && k%2==0)
printf("Yes\n");
else if(n%2!=0 && k%2!=0)
printf("Yes\n");
else if(n%2==0 && k%2!=0)
printf("No\n");
else if(n%2!=0 && k%2==0)
printf("No\n");
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 8126eb49c5d14e35722f7fe0133f57e6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main()
{
int t,n,i;
unsigned long long int k;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d",&n);
scanf("%llu",&k);
if(n>=k*k && (n&1)==(k&1)){
printf("YES\n");
}
else
printf("NO\n");
}
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 0a2ba51bd82291492aad93023c138e23 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
while (n--) {
int a, k;
scanf("%d%d", &a, &k);
printf(k <= a / k && a % 2 == k % 2 ? "YES\n" : "NO\n");
}
return 0;
} | |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | a3cf684e88f83a2e33b1609e802a3f8a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
int main(void) {
// your code goes here
long long int T;
scanf("%lld",&T);
for (long long int num=1;num<=T;num++)
{
long long int n,k;
scanf("%lld %lld",&n,&k);
if(k*k>n)
{
printf("NO\n");
}
else
{
long long int check=n-k;
if((check%2)==0)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 2beb0be98d669f6f84b9b7ab0ae5e3ec | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
#include <math.h>
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
long long numero, quantidade;
scanf("%lld%lld", &numero, &quantidade);
if ((numero + quantidade) % 2 != 0 || quantidade > sqrt(numero))
printf("NO\n");
else
printf("YES\n");
}
return 0;
} | |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | a38bb8eadf3c1c69540f21e688e1291f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main()
{
long long int n,a,b,c,i;
scanf("%lld", &n);
for(i=1; i<=n; i++){
scanf("%lld %lld",&a,&b);
c=b*b;
if(a>=c && (a-c)%2==0){
printf("YES\n");
}
else{
printf("NO\n");
}
}
} | |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 740d7f57f0de36e488bb98e5b2b26cdd | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
#include <math.h>
int main()
{
long long i,j,l,k,t,c,n,m,a;
scanf("%lld",&a);
for(i=0;i<a;i++)
{
scanf("%lld %lld",&m,&n);
if(n*n<=m && m%2==n%2 )
{
printf("YES\n");
}
else
printf("NO\n");
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | f27fdf6ca87bb14d626561a1ceb1ce96 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main()
{
long long int t,n,k;
scanf("%lld",&t);
while(t--){
scanf("%lld %lld",&n,&k);
if(n>=k*k && (n-k)%2==0){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 6d9c36a0aa5807866a3374173ad509e9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include <stdio.h>
#include <stdlib.h>
#define N 109
// int cmpfunc (const void * a, const void * b) {
// return ( *(int*)a - *(int*)b );
// }
// qsort(values, 5, sizeof(int), cmpfunc);
int main() {
long long t, n, k;
scanf("%lld", &t);
while(t--){
scanf("%lld%lld", &n, &k);
if (n%2 != k%2 || n < k*k)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | b91016d2dd11127d0e1f1011caad4283 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main(){
unsigned int t,i;
unsigned long long int k;
unsigned long long int n;
scanf("%u",&t);
for(i=0;i<t;i++){
scanf("%llu %llu",&n,&k);
if(n>=k*k&&n%2==k%2)
printf("YES\n");
else
printf("NO\n");
}}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | 4235fc225ea4d32a21538eb4bf9a86eb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main(){
unsigned int t,i;
unsigned long long int k;
unsigned long int n;
scanf("%u",&t);
for(i=0;i<t;i++){
scanf("%llu %llu",&n,&k);
if(n>=k*k&&n%2==k%2)
printf("YES\n");
else
printf("NO\n");
}}
| |
You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise. | C | a4c82fffb31bc7e42870fd84e043e815 | a4497c13e9d98ea9b6696821af0f883a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1584974100 | ["6\n3 1\n4 2\n10 3\n10 2\n16 4\n16 5"] | NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers. | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$). | ["YES\nYES\nNO\nYES\nYES\nNO"] | #include<stdio.h>
int main(){
unsigned int t,j;
unsigned long long int k;
unsigned long long int n;
scanf("%u",&t);
for(j=0;j<t;j++){
scanf("%llu %llu",&n,&k);
if(n>=k*k&&n%2==k%2)
printf("YES\n");
else
printf("NO\n");
}}
| |
After lessons Nastya decided to read a book. The book contains $$$n$$$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $$$k$$$ as the first page which was not read (i.e. she read all pages from the $$$1$$$-st to the $$$(k-1)$$$-th).The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). | Print a single integer — the number of chapters which has not been completely read so far. | C | 2545b6af730f99193041a8810b728cb3 | 9184a01a23c1540bf4e8a961bddd9e6d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1552322100 | ["3\n1 3\n4 7\n8 11\n2", "3\n1 4\n5 9\n10 12\n9", "1\n1 7\n4"] | NoteIn the first example the book contains $$$11$$$ pages and $$$3$$$ chapters — $$$[1;3]$$$, $$$[4;7]$$$ and $$$[8;11]$$$. Nastya marked the $$$2$$$-nd page, so she finished in the middle of the $$$1$$$-st chapter. So, all chapters has not been read so far, so the answer is $$$3$$$.The book in the second example contains $$$12$$$ pages and $$$3$$$ chapters too, but Nastya finished reading in the middle of the $$$2$$$-nd chapter, so that the answer is $$$2$$$. | PASSED | 800 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of chapters in the book. There are $$$n$$$ lines then. The $$$i$$$-th of these lines contains two integers $$$l_i$$$, $$$r_i$$$ separated by space ($$$l_1 = 1$$$, $$$l_i \leq r_i$$$) — numbers of the first and the last pages of the $$$i$$$-th chapter. It's guaranteed that $$$l_{i+1} = r_i + 1$$$ for all $$$1 \leq i \leq n-1$$$, and also that every chapter contains at most $$$100$$$ pages. The $$$(n+2)$$$-th line contains a single integer $$$k$$$ ($$$1 \leq k \leq r_n$$$) — the index of the marked page. | ["3", "2", "1"] | #include<stdio.h>
int main()
{
int i,j,n,k,c;
scanf("%d",&n);
int a[n][2];
for(i=0;i<n;i++)
{
scanf("%d%d",&a[i][0],&a[i][1]);
}
scanf("%d",&k);
for(i=0;i<n;i++)
{
if(a[i][0]<=k && k<=a[i][1])
{
break;
}
}
printf("%d",n-i);
} | |
After lessons Nastya decided to read a book. The book contains $$$n$$$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $$$k$$$ as the first page which was not read (i.e. she read all pages from the $$$1$$$-st to the $$$(k-1)$$$-th).The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). | Print a single integer — the number of chapters which has not been completely read so far. | C | 2545b6af730f99193041a8810b728cb3 | 75756057ae8c27fdf40ff4895b510008 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1552322100 | ["3\n1 3\n4 7\n8 11\n2", "3\n1 4\n5 9\n10 12\n9", "1\n1 7\n4"] | NoteIn the first example the book contains $$$11$$$ pages and $$$3$$$ chapters — $$$[1;3]$$$, $$$[4;7]$$$ and $$$[8;11]$$$. Nastya marked the $$$2$$$-nd page, so she finished in the middle of the $$$1$$$-st chapter. So, all chapters has not been read so far, so the answer is $$$3$$$.The book in the second example contains $$$12$$$ pages and $$$3$$$ chapters too, but Nastya finished reading in the middle of the $$$2$$$-nd chapter, so that the answer is $$$2$$$. | PASSED | 800 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of chapters in the book. There are $$$n$$$ lines then. The $$$i$$$-th of these lines contains two integers $$$l_i$$$, $$$r_i$$$ separated by space ($$$l_1 = 1$$$, $$$l_i \leq r_i$$$) — numbers of the first and the last pages of the $$$i$$$-th chapter. It's guaranteed that $$$l_{i+1} = r_i + 1$$$ for all $$$1 \leq i \leq n-1$$$, and also that every chapter contains at most $$$100$$$ pages. The $$$(n+2)$$$-th line contains a single integer $$$k$$$ ($$$1 \leq k \leq r_n$$$) — the index of the marked page. | ["3", "2", "1"] | #include<stdio.h.>
int main()
{ int n,sum=0,k,flag=0,i,j,x=0;
scanf("%d",&n);
int ara[n],word[n];
for(i=0;i<n;i++){
scanf("%d %d",&ara[i],&word[i]);
}
scanf("%d",&k);
for(i=0;i<n;i++){
if(k>word[i]){
flag++;
}
// else break;
}
/*while(k>=sum){
sum=ara[x]+word[x];
if(sum<=k){flag++;
x++;}
}*/
printf("%d",(n-flag));
return 0;
}
| |
After lessons Nastya decided to read a book. The book contains $$$n$$$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $$$k$$$ as the first page which was not read (i.e. she read all pages from the $$$1$$$-st to the $$$(k-1)$$$-th).The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). | Print a single integer — the number of chapters which has not been completely read so far. | C | 2545b6af730f99193041a8810b728cb3 | 537d689b5b60d342f5fdad2e0b999402 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1552322100 | ["3\n1 3\n4 7\n8 11\n2", "3\n1 4\n5 9\n10 12\n9", "1\n1 7\n4"] | NoteIn the first example the book contains $$$11$$$ pages and $$$3$$$ chapters — $$$[1;3]$$$, $$$[4;7]$$$ and $$$[8;11]$$$. Nastya marked the $$$2$$$-nd page, so she finished in the middle of the $$$1$$$-st chapter. So, all chapters has not been read so far, so the answer is $$$3$$$.The book in the second example contains $$$12$$$ pages and $$$3$$$ chapters too, but Nastya finished reading in the middle of the $$$2$$$-nd chapter, so that the answer is $$$2$$$. | PASSED | 800 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of chapters in the book. There are $$$n$$$ lines then. The $$$i$$$-th of these lines contains two integers $$$l_i$$$, $$$r_i$$$ separated by space ($$$l_1 = 1$$$, $$$l_i \leq r_i$$$) — numbers of the first and the last pages of the $$$i$$$-th chapter. It's guaranteed that $$$l_{i+1} = r_i + 1$$$ for all $$$1 \leq i \leq n-1$$$, and also that every chapter contains at most $$$100$$$ pages. The $$$(n+2)$$$-th line contains a single integer $$$k$$$ ($$$1 \leq k \leq r_n$$$) — the index of the marked page. | ["3", "2", "1"] | #include<stdio.h>
int main()
{
int n,i=0,m=0;
scanf("%d",&n);
int a[n],b[n],k,sum;
while(i<n)
{
scanf("%d %d",&a[i],&b[i]);
i++;
}
scanf("%d",&k);
i=0;
while(i<n)
{
if(k<=b[i])
{
m++;
}
i++;
}
printf("%d",m);
return 0;
}
| |
Berland has managed to repel the flatlanders' attack and is now starting the counter attack.Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we do not know whether is it a clever spy-proof strategy or just saving ink). In other words, if two cities are connected by a road on a flatland map, then there is in fact no road between them. The opposite situation is also true: if two cities are not connected by a road on a flatland map, then in fact, there is a road between them.The berlanders got hold of a flatland map. Now Vasya the Corporal is commissioned by General Touristov to find all such groups of flatland cities, that in each group of cities you can get from any city to any other one, moving along the actual roads. Also the cities from different groups are unreachable from each other, moving along the actual roads. Indeed, destroying such groups one by one is much easier than surrounding all Flatland at once!Help the corporal complete this task and finally become a sergeant! Don't forget that a flatland map shows a road between cities if and only if there is in fact no road between them. | On the first line print number k — the number of groups of cities in Flatland, such that in each group you can get from any city to any other one by flatland roads. At the same time, the cities from different groups should be unreachable by flatland roads. On each of the following k lines first print ti (1 ≤ ti ≤ n) — the number of vertexes in the i-th group. Then print space-separated numbers of cities in the i-th group. The order of printing groups and the order of printing numbers in the groups does not matter. The total sum ti for all k groups must equal n. | C | 72394a06a9d9dffb61c6c92c4bbd2f3a | f364637bbe71a589477154ba10da04b5 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"hashing",
"graphs",
"dsu",
"sortings",
"data structures"
] | 1337182200 | ["4 4\n1 2\n1 3\n4 2\n4 3", "3 1\n1 2"] | NoteIn the first sample there are roads only between pairs of cities 1-4 and 2-3.In the second sample there is no road between cities 1 and 2, but still you can get from one city to the other one through city number 3. | PASSED | 2,100 | standard input | 3 seconds | The first line contains two space-separated integers n and m (1 ≤ n ≤ 5·105, 0 ≤ m ≤ 106) — the number of cities and the number of roads marked on the flatland map, correspondingly. Next m lines contain descriptions of the cities on the map. The i-th line contains two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of cities that are connected by the i-th road on the flatland map. It is guaranteed that each pair of cities occurs in the input no more than once. | ["2\n2 1 4 \n2 2 3", "1\n3 1 2 3"] | #include <stdio.h>
#define MAXN 500000
#define MAXM 1000000
int b[MAXN], s[2 * MAXM][2], pos, n, m;
int interest[MAXN], n_rebr[MAXN], rank[MAXN], pres[MAXN];
int check[MAXN], n_check;
void
add(int x, int y)
{
s[pos][0] = y;
s[pos][1] = b[x];
b[x] = pos++;
++n_rebr[x];
}
void
read_n(void)
{
scanf("%d%d", &n, &m);
int i;
for(i = 0; i < n; ++i){
b[i] = -1;
}
for(i = 0; i < m; ++i){
int x, y;
scanf("%d%d", &x, &y);
--x;
--y;
add(x, y);
add(y, x);
}
}
int
repres(int i){
if(pres[i] != i){
return pres[i] = repres(pres[i]);
} else {
return i;
}
}
void
unite(int x, int y)
{
int p1 = repres(x),
p2 = repres(y);
if(p1== p2){
return;
}
if(rank[p1] < rank[p2]){
pres[p1] = p2;
} else {
pres[p2] = p1;
if(rank[p1] == rank[p2]){
++rank[p1];
}
}
}
int c[MAXN];
void
solve(void)
{
int i, mind = 2 * n + 10, mink;
for(i = 0; i < n; ++i){
if(n_rebr[i] < mind){
mind = n_rebr[i];
mink = i;
}
}
int p = b[mink];
while(p != -1){
interest[s[p][0]] = 1;
check[n_check++] = s[p][0];
p = s[p][1];
}
for(i = 0; i < n; ++i){
rank[i] = 0;
pres[i] = i;
}
for(i = 0; i < n; ++i){
if(!interest[i]){
unite(i, mink);
}
}
int col = 0;
for(i = 0; i < n_check; ++i){
++col;
p = b[check[i]];
while(p != -1){
c[s[p][0]] = col;
p = s[p][1];
}
int j;
for(j = 0; j < n; ++j){
if(c[j] != col){
unite(check[i], j);
}
}
}
}
void
printans(void)
{
int i;
for(i = 0; i < n; ++i){
b[i] = -1;
n_rebr[i] = 0;
}
pos = 0;
for(i = 0; i < n; ++i){
add(repres(i), i);
}
int nans = 0;
for(i = 0; i < n; ++i){
if(repres(i) == i){
++nans;
}
}
printf("%d\n", nans);
for(i = 0; i < n; ++i){
if(repres(i) == i){
printf("%d", n_rebr[i]);
int p = b[i];
while(p != -1){
printf(" %d", ++s[p][0]);
p = s[p][1];
}
printf("\n");
}
}
}
int
main(void)
{
read_n();
solve();
printans();
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | d8f8cdc2db92ff8125f75e7765a2ee05 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main()
{
int i,m,a,b,temp;
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&a);
//int A[a];
int B[3];
for(int j=0;j<3;j++)
{
B[j]=0;
}
for(int j=0;j<a;j++)
{
scanf("%d",&b);
temp=b%3;
B[temp]++;
}
if(B[1]>=B[2])
{
B[0]=B[0]+B[2];
B[1]=B[1]-B[2];
B[2]=0;
}
else
{
B[0]=B[0]+B[1];
B[2]=B[2]-B[1];
B[1]=0;
}
//printf("%d %d %d\n",B[0],B[1],B[2]);
if(B[1]>=3)
{
B[0]=B[0]+B[1]/3;
B[1]=B[1]%3;
}
if(B[2]>=3)
{
B[0]=B[0]+B[2]/3;
B[2]=B[2]%3;
}
printf("%d\n",B[0]);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 3d34324b53e4903cf3bdf2267903a2a9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
#include<memory.h>
int main(){
int num;
scanf("%d", &num);
int ans[num];
memset(ans, 0, sizeof(ans));
int i, j, k;
for(i=0;i<num;i++)
{
int n;
int zero = 0;
int one = 0;
int two = 0;
scanf("%d", &n);
int arr[n], arr_2[n];
for(j=0;j<n;j++)
{
scanf("%d", &arr[j]);
arr_2[j] = arr[j]%3;
}
for(j=0;j<n;j++)
{
if(arr_2[j]==0)
{
zero++;
ans[i]++;
}
else if(arr_2[j]==1)
{
one++;
}
else if(arr_2[j] == 2)
{
two++;
}
}
while(one>0 && two>0)
{
one--;two--;
ans[i]++;
}
while(one>=3)
{
one = one-3;
ans[i]++;
}
while(two>=3)
{
two = two-3;
ans[i]++;
}
}
for(i=0;i<num;i++)
printf("%d\n", ans[i]);
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | f5401d20c17e488bfa62edefd2b28420 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main(){
int n,t,b[3],x,res;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
b[0]=0;b[1]=0;b[2]=0;res=0;
while(n--){
scanf("%d",&x);
b[x%3]++;
}
res+=b[0];
if(b[1]>b[2]){
res=res+b[2]+(b[1]-b[2])/3;
}
else{
res=res+b[1]+(b[2]-b[1])/3;
}
printf("%d\n",res);
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 598b1d6dfc2e62db1983c94b207bc85b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int ara2[3];
int main()
{
int i,n,sum=0,x=0,y=0,t,j;
scanf("%d",&t);
int ara3[t];
for(j=0;j<t;j++){
scanf("%d",&n);
long long int ara[n];
for(i=0;i<n;i++){
scanf("%lld",&ara[i]);
ara[i]=ara[i]%3;
ara2[ara[i]]++;
}
if(ara2[2]>=ara2[1]){
y=ara2[1];
ara2[2]=ara2[2]-ara2[1];
x=ara2[2]/3;
}
else{
y=ara2[2];
ara2[1]=ara2[1]-ara2[2];
x=ara2[1]/3;
}
sum=ara2[0]+x+y;
ara3[j]=sum;
ara2[0]=0;
ara2[1]=0;
ara2[2]=0;
x=0;
y=0;
}
for(j=0;j<t;j++)
printf("%d\n",ara3[j]);
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | b4a371ac7c47a8c92f68a63b8844e09e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main() {
int t,n;
scanf("%d",&t);
int temp;
int modthr[3];
for (int i = 0; i < t; i++) {
modthr[0]=modthr[1]=modthr[2]=0;
scanf("%d",&n);
for (int j = 0; j < n; j++) {
scanf("%d",&temp);
modthr[temp%3]++;
}
if (modthr[1]<modthr[2]) {
modthr[0]+=modthr[1]+(modthr[2]-modthr[1])/3;
}
else{
modthr[0]+=modthr[2]+(modthr[1]-modthr[2])/3;
}
printf("%d\n",modthr[0]);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 5cb48b2e4570d52dee759f8625d2317a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int query,i,j,count0=0,count1=0,count2=0;
scanf("%d",&query);
int *q=malloc(query*sizeof(int));
int **a=malloc(query*sizeof(int*));
int *result=malloc(query*sizeof(int));
for(i=0;i<query;i++)
{
count0=0;
count1=0;
count2=0;
scanf("%d",&q[i]);
a[i]=malloc(q[i]*sizeof(int));
for(j=0; j<q[i];j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]%3==0)
count0++;
if(a[i][j]%3==1)
count1++;
if(a[i][j]%3==2)
count2++;
}
if(count1>count2)
{
result[i]=count0+count2+(count1-count2)/3;
}
else
result[i]=count0+count1+(count2-count1)/3;
}
for(i=0;i<query;i++)
{
printf("%d\n",result[i]);
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | cf401d0ff584bf9e13284f15c6be4dc6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int num, q, n, num_ones, num_twos, num_threes;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
num_ones = num_twos = num_threes = 0;
scanf("%d", &n);
for (int j = 0; j < n; j++) {
scanf("%d", &num);
if (num % 3 == 0) num_threes++;
else if (num % 3 == 1) num_ones++;
else num_twos++;
}
if (num_ones > num_twos) {
num_threes += num_twos;
num_threes += (num_ones - num_twos) / 3;
} else {
num_threes += num_ones;
num_threes += (num_twos - num_ones) / 3;
}
printf("%d\n", num_threes);
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 8c71e1d11bdc5ba221e189df0fc74075 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main()
{
int t,n,ara[101];
scanf("%d",&t);
for(int i=0 ; i<t ; i++)
{
int a=0,b=0,c=0;
scanf("%d",&n);
for(int i=0 ; i<n ; i++)
{
scanf("%d",&ara[i]);
if(ara[i]%3 == 0)
a++;
else if(ara[i]%3 == 1)
b++;
else
c++;
}
int max=0;
if(b>c)
max=a+c+(b-c)/3;
else
max=a+b+(c-b)/3;
printf("%d\n",max);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | ba27c44926ef7a4ef8e25e77a04e4297 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main()
{
int t,n;
scanf("%d", &t);
while(t--)
{
int count = 0, one = 0, two = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
int temp;
scanf("%d", &temp);
if(temp%3 == 0)
count++;
else if(temp%3 == 1)
one++;
else
two++;
}
if(one>two)
{
one -= two;
int u = one/3;
count += two + u;
}
else
{
two -= one;
int u = two/3;
count += one + u;
}
printf("%d\n", count);
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | cf1dd23441ebbe809389ee7e7cdbc914 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
#include<stdlib.h>
long long a[1000000];
long long amin(long long a,long long b)
{
if(a>b) return b;
else return a;
}
int main()
{
long long n;
scanf("%I64d",&n);
n=n+1;
int i;
while(n=n-1)
{
long long m;
scanf("%I64d",&m);
long long m3y1=0;
long long div3=0;
long long m3y2=0;
for( i=1;i<=m;i++)
{
scanf("%I64d",&a[i]);
if(a[i]%3==0) div3=div3+1;
if(a[i]%3==1) m3y1=m3y1+1;
if(a[i]%3==2) m3y2=m3y2+1;
}
long long ans;
if(m3y1>m3y2)
ans=div3+m3y2+(m3y1-m3y2)/3;
else
ans=div3+m3y1+(m3y2-m3y1)/3;
printf("%I64d\n",ans);
i=1;
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 27e0b69fc7b12440368a4d46c0213b3a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main() {
unsigned short t;
scanf("%hu", &t);
for(unsigned short i = 0; i < t; ++i) {
unsigned short n;
scanf("%hu", &n);
unsigned a;
unsigned short r0 = 0, r1 = 0, r2 = 0;
for(unsigned j = 0; j < n; ++j) {
scanf("%u", &a);
switch(a % 3) {
case 0: ++r0; break;
case 1: ++r1; break;
case 2: ++r2; break;
}
}
unsigned short sum = r0;
if(r1 >= r2) {
sum += r2;
sum += (r1 - r2) / 3;
} else {
sum += r1;
sum += (r2 - r1) / 3;
}
printf("%hu\n", sum);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | cf25dd8edb85a9d3949cfd9b61fe01bf | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <stdlib.h>
int main(void) {
int q;
scanf("%d",&q);
for(int j=1;j<=q;j++)
{int n;
scanf("%d",&n);
long int a[n];
int p=0,q=0;
for(int i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
if(a[i]%3==0)
{
p = p+1;
}
else if(a[i]%3==1)
{
q = q+1;
}
}
int r=n-p-q;
int ans = (p+((q+r)-abs(q-r))/2 +abs(q-r)/3) ;
printf("%d \n",ans);
}
return(0);
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | a2264ce02ca1c7bd34ad5ae33796c336 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int q,i,j,t,a=0,b=0,c=0;
scanf("%d",&q);
int arr[100];
for (i=0;i<q;i++)
{
a=0,b=0,c=0;
scanf("%d",&t);
for (j=0;j<t;j++)
{
scanf("%d",&arr[j]);
if (arr[j]%3==0) a++;
else if (arr[j]%3==1) b++;
else c++;
}
if (c>=b) t=a+b+(c-b)/3;
else t=a+c+(b-c)/3;
printf("%d\n",t);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | aec9afea0ee1af59b5151f01ee9ca685 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int t;
scanf("%d",&t);
for (int i = 0; i < t; ++i)
{
int n;
scanf("%d",&n);
unsigned long long int arr[n];
unsigned long long int mod0 = 0 , mod1 = 0, mod2 = 0;
unsigned long long int count_total = 0;
for (int i = 0; i < n; ++i)
{
scanf("%I64d",&arr[i]);
}
for (int i = 0; i < n; ++i)
{
if (arr[i]%3 == 0)
{
mod0++;
}
else if (arr[i]%3 == 1)
{
mod1++;
}
else
{
mod2++;
}
}
if (mod1 >= mod2)
{
count_total += mod0 + mod2 + ((mod1-mod2)/3);
}
else
{
count_total += mod0 +mod1 + ((mod2-mod1)/3);
}
printf("%I64d\n",count_total);
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 2fb6dfb33bf0200ff9ed85f83bc6b2fc | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <stdlib.h>
int min(int a, int b) {
if(a < b) return a;
else return b;
}
int main()
{
int t;
scanf("%d", &t);
for(; t > 0; t--) {
int n, rems[3];
rems[0] = rems[1] = rems[2] = 0;
scanf("%d", &n);
for(; n > 0; n--) {
long long int num;
scanf("%I64d", &num);
rems[num % 3]++;
}
/*int result = rems[0] + (rems[1] / 3) + (rems[2] / 3);
rems[1] %= 3;
rems[2] %= 3;
result += (rems[1] + rems[2]) / 3;*/
int result = rems[0];
int mn = min(rems[1], rems[2]);
result += mn;
rems[1] -= mn;
rems[2] -= mn;
result += rems[1] / 3 + rems[2] / 3;
printf("%d\n", result);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 7bde548b389fd534c36ecf7345d0b86f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main()
{
int t, n, i, j, k, c; scanf("%d",&t);
for( ;t>0;t--)
{
scanf("%d",&n);
c=0;
long long int a[n+1];
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
if(a[i]%3==0) {a[i]=0; c++;}
}
for(i=0;i<n;i++)
{
k=0;
for(j=i+1;j<n;j++)
{
if((a[i]+a[j])%3==0 && a[i]!=0 && a[j]!=0){a[i]=0; a[j]=0; c++; k=1; break;}
}
if(k==0){a[i+1]=a[i+1]+a[i];a[i]=0;}
}
printf("%d\n",c);
}
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 1c1127fed74918be52cf4fab2653466e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main()
{
int t,n,an[1000],i,j,k,l,m,p=0,q;
scanf("%d",&t);
long long int a[t][101];
for(i=0;i<t;i++)
{
scanf("%d",&an[i]);
for(k=0;k<an[i];k++)
scanf("%I64d",&a[i][k]);
}
for(i=0;i<t;i++)
{
j=0;
m=0;l=0;
for(k=0;k<an[i];k++)
{
if(a[i][k]%3==0)
j++;
else if(a[i][k]%3==1)
l++;
else if(a[i][k]%3==2)
m++;
}
if(l<=m)
{
q=(m-l)/3;
j=j+l+q;
}
else if(m<l)
{
q=(l-m)/3;
j=j+m+q;
}
printf("%d\n",j);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | f3cb73ad9e865fe0d75106ab11ad7aed | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
typedef long long ll;
int main()
{
int t, m;
scanf("%d",&t);
m=t-1;
ll arr[t];
while(t--)
{
int n;
scanf("%d",&n);
ll ar[n],cnt[3]={0},scnt=0;
for(int i=0;i<n;i++)
{
scanf("%lld",&ar[i]);
cnt[ar[i]%3]++;
}
scnt+=cnt[0];
if(cnt[2]>cnt[1])
{
scnt+=cnt[1];
cnt[2]-=cnt[1];
scnt+=cnt[2]/3;
}
else if(cnt[1]>cnt[2])
{
scnt+=cnt[2];
cnt[1]-=cnt[2];
scnt+=cnt[1]/3;
}
else
scnt+=cnt[1];
arr[t]=scnt;
}
for(int i=m;i>=0;i--)
printf("%lld\n",arr[i]);
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | c762ce9db3cf68245e9806f2071123c2 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main()
{
int i,j,k,l,queries,num[1000],count[1000]={0};
unsigned int arr[1000][100];
scanf("%d",&queries);
for(i=0;i<queries;i++)
{
scanf("%d",&num[i]);
for(j=0;j<num[i];j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("\n");
for(i=0;i<queries;i++)
{
for(j=0;j<num[i];j++)
{
if((arr[i][j]%3==0)&&(arr[i][j]/3!=0))
{
count[i]++;
arr[i][j]=0;
}
}
for(j=0;j<num[i];j++)
{
for(k=j+1;k<num[i];k++)
{
if(((arr[i][j]+arr[i][k])%3==0)&&((arr[i][j]+arr[i][k])/3!=0))
{
count[i]++;
arr[i][j]=arr[i][k]=0;
break;
}
}
}
for(j=0;j<num[i];j++)
{
for(k=j+1;k<num[i];k++)
{
for(l=k+1;l<num[i];l++)
{
if(((arr[i][j]+arr[i][k]+arr[i][l])%3==0)&&((arr[i][j]+arr[i][k]+arr[i][l])/3!=0))
{
count[i]++;
arr[i][j]=arr[i][k]=arr[i][l]=0;
break;
}
}
}
}
printf("%d\n",count[i]);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 4250a58a68032e467f21dba37ca8286a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main(){
int a;
scanf("%d", &a);
int i;
int anss[a];
for(i=0; i<a; i++){
int b;
scanf("%d", &b);
int c[b];
int j;
for(j=0; j<b; j++){
int tmp;
scanf("%d", &tmp);
tmp = tmp%3;
c[j] = tmp;
}
int zero = 0;
int one = 0;
int two = 0;
for(j=0; j<b; j++){
if(c[j] == 0){
zero++;
}
else if(c[j] == 1){
one++;
}
else if(c[j] == 2){
two++;
}
}
int ans=zero;
/*if(one>=3){
int tt = one/3;
ans+=tt;
one = one%3;
}
if(two>3){
int tt = one/3;
ans+=tt;
two = two%3;
}*/
/*if(one<two){
ans = ans + one;
one=0;
two-=one;
}
else{
ans = ans + two;
two=0;
one-=two;
}
if(one>=3){
int tt = one/3;
ans+=tt;
one = one%3;
}
if(two>=3){
int tt = two/3;
ans+=tt;
two = two%3;
}*/
while(one>0 && two>0)
{
one--;two--;
ans++;
}
while(one>=3)
{
one = one-3;
ans++;
}
while(two>=3)
{
two = two-3;
ans++;
}
anss[i] = ans;
}
for(i=0; i<a; i++){
printf("%d\n", anss[i]);
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | b93c4482a6bd9e4e296b2760c9b6603d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main()
{
int a,b,c,d,e,t,n;
scanf("%d",&t);
while(t--)
{
b=0;c=0;d=0;
scanf("%d",&n);
while(n--)
{
scanf("%d",&a);
if(a%3==0)
b++;
else if(a%3==1)
c++;
else
d++;
}
if(c<=d)
{
e=b+c+(d-c)/3;
}
else
{
e=b+d+(c-d)/3;
}
printf("%d\n",e);
}
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 04bd2cb6adc8f44ed37bd8bc7ddb32f3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
#define N 3LL
int main(void)
{
#ifdef test
freopen("in.txt","r",stdin);
#endif // test
int T;
for(scanf("%d",&T);T--;)
{
int n,t=0,k=0;
long long a=0,a0=0,sum=0,s1=0,s2=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lld",&a);
if(!t)a0=a;
else
{
if(a%N==1)s1++;
else if(a%N==2)s2++;
else sum++;
}
t++;
}
if(t>1)
{
if(a0%N==0)sum++;
else if(a0%N==1)s1++;
else s2++;
if(s1>=s2)sum+=s2,s1-=s2,sum+=s1/3;
else sum+=s1,s2-=s1,sum+=s2/3;
printf("%lld\n",sum);
}
else if(a0%N==0)printf("1\n");
else printf("0\n");
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 2ff830cad09d8d9405d14689b42fc2d4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int a[110];
int n;
int min(int a, int b) {
return (a < b ? a : b);
}
void solve() {
scanf("%d", &n);
int c0 = 0, c1 = 0, c2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] % 3 == 0) c0++;
else if (a[i] % 3 == 1) c1++;
else c2++;
}
int ans = c0 + min(c1, c2) + (c1 - min(c1, c2)) / 3 + (c2 - min(c1, c2)) / 3;
printf("%d\n", ans);
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
solve();
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 0f0514cc8ac98961b09bced4def12d46 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main()
{
int t;
int n, cnt = 0, o = 0, w = 0;
int a;
scanf("%d",&t);
while(t--)
{ scanf("%d", &n);
cnt = 0;
o = 0;
w = 0;
a = 0;
for (int i = 0; i < n; ++i)
{
scanf("%d", &a);
a= a % 3;
switch (a)
{
case 0:
cnt++;
break;
case 1:
o++;
break;
case 2:
w++;
break;
}
}
if (o > w)
{
cnt += w;
o = o - w;
cnt += (o / 3);
}
else if (w > o)
{
cnt += o;
w = w - o;
cnt += (w / 3);
}
else
cnt += w;
printf("%d \n", cnt);
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 9c8ab791e491e5626e6944730e721709 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
int t, n, a[5], x;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(a, 0, sizeof(a));
int count = 0;
while(n--)
{
scanf("%d", &x);
if(x%3!=0) a[x%3]++;
else count++;
}
if(a[2]<=a[1])
{
count += a[2];
count = count + (a[1] - a[2])/3;
}
else
{
count += a[1];
count = count + (a[2] - a[1])/3;
}
printf("%d\n", count);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 2d45ad216f342ded52ce904860f3e54a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main(void)
{
int n,q,a,b,c;
scanf("%d",&n);
int r;
int ans[n];
for(int i = 0; i < n; i++)
{
a=0;
b=c=0;
r=0;
scanf("%d",&q);
int query[q];
for(int x = 0; x < q; x++)
{
scanf("%d",&query[i]);
if(query[i]%3 == 0)
a++;
else if(query[i]%3 == 1)
b++;
else if(query[i]%3 == 2)
c++;
}
if(b > 0 && c > 0)
{
r = (b > c)?c:b;
b = b - r;
c = c - r;
}
if(b == 0 || c == 0)
{
if(b >= 3)
r += b/3;
if(c >= 3)
r += c/3;
}
r += a;
printf("%d\n",r);
ans[i] = r;
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 3398ffbb8e7b398155c0eaa0d3fcf751 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main(){
int t,i,j;
scanf("%d",&t);
int n;
int count[t][3];
for(i=0;i<t;i++){
scanf("%d",&n);
long int a[n];
count[i][0]=0;
count[i][1]=0;
count[i][2]=0;
for(j=0;j<n;j++){
scanf(" %ld",&a[j]);
if(a[j]%3==0){
count[i][a[j]%3]++;
continue;
}
if(a[j]%3==1){
count[i][a[j]%3]++;
continue;
}
if(a[j]%3==2){
count[i][a[j]%3]++;
continue;
}
}
}
for(i=0;i<t;i++){
if(count[i][1]<count[i][2]){
printf("%d\n",count[i][0]+count[i][1]+(count[i][2]-count[i][1])/3);
}
else{
printf("%d\n",count[i][0]+count[i][2]+(count[i][1]-count[i][2])/3);
}
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 3ef3d5ffbba7b38007985ab8ab93e564 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include<stdio.h>
int main ()
{
int n;
int t;
scanf("%d", &t);
for (int p=0;p<t;p++)
{
scanf("%d",&n);
int num;
int r0=0;int r1=0;int r2=0;
for (int i=0;i<n;i++)
{
scanf("%d",&num);
if (num%3==0)
r0++;
else if (num%3==1)
r1++;
else
r2++;
}
while ( (r1>0) && (r2>0) )
{
r1--; r2--;
r0++;
}
while ( r1>2 )
{
r1=r1-3;
r0++;
}
while ( r2>2 )
{
r2=r2-3;
r0++;
}
printf("%d\n",r0);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 44530b23df61410361448ea60f9833b0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | main() {
int q, s, a;
scanf("%d", &q);
while(q-- > 0) {
int n[3] = { 0 };
scanf("%d", &s);
while(s-- > 0) {
scanf("%d", &a);
n[a % 3]++;
}
int ot = (n[1] < n[2]) ? n[1] : n[2];
int oo = (n[1] > ot) ? (n[1] - ot) / 3 : 0;
int tt = (n[2] > ot) ? (n[2] - ot) / 3 : 0;
printf("%d\n", n[0] + ot + oo + tt);
}
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | 0d68182a7c9d8be3df0f3a3ffb98100d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, k0, k1, k2, cnt;
scanf("%d", &n);
k0 = k1 = k2 = 0;
while (n--) {
int a;
scanf("%d", &a);
if (a % 3 == 0)
k0++;
else if (a % 3 == 1)
k1++;
else
k2++;
}
cnt = k1 < k2 ? k1 : k2;
printf("%d\n", k0 + cnt + (k1 + k2 - cnt * 2) / 3);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | a5d1ff2ce9e2102954372e2c75cb71a9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
int min(int x, int y) {
if (x < y) {
return x;
}
return y;
}
int main()
{
int t, n, m, zeros, ones, twos, answer;
for (scanf("%d",&t); t && scanf("%d",&n); t--) {
for (zeros = 0, ones = 0, twos = 0; n && scanf("%d",&m); n--) {
m %= 3;
if (m == 2) {
twos += 1;
} else if (m) {
ones += 1;
} else {
zeros += 1;
}
}
printf("%d\n",zeros+min(ones,twos)+(ones-min(ones,twos))/3+(twos-min(ones,twos))/3);
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries. | For each query print one integer in a single line — the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times. | C | e59cddb6c941b1d7556ee9c020701007 | edd6f942f6a92cfb9aee7afce828d71a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1560090900 | ["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"] | NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$. | PASSED | 1,100 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$). | ["3\n3"] | #include <stdio.h>
#include <math.h>
int main()
{
int t, n, x, c1=0, c2=0, c3=0;
scanf("%d", &t);
for(int i=0; i<t; i++){
scanf("%d", &n);
c1=c2=c3=0;
for(int j=0; j<n; j++){
scanf("%d", &x);
if(x%3 == 0){
c3++;
}
if(x%3 == 1){
c1++;
}
if(x%3 == 2){
c2++;
}
}
if(c1 >= c2){
c3 = c3 + c2;
c1 = c1 - c2;
c2 = 0;
}
if(c1 < c2){
c3 = c3 + c1;
c2 = c2 - c1;
c1 = 0;
}
if(c1 == 0){
c2 = c2 / 3;
c3 = c3 + c2;
}
if(c2 == 0){
c1 = c1 / 3;
c3 = c3 + c1;
}
printf("%d\n", c3);
}
return 0;
} | |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 6f1fe94be76f8702a6a598f3bd764c01 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include<stdio.h>
int main()
{
int i,j,n,sum[3]={0};
scanf("%d",&n);
int a[n][3];
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
for(j=0;j<3;j++)
{
for(i=0;i<n;i++)
{
sum[j]+=a[i][j];
}
}
///printf("%d %d %d\n",sum[0],sum[1],sum[2]);
if (sum[0]==0&&sum[1]==0&&sum[2]==0) printf("YES\n");
else printf("NO\n");
return 0;
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | b134d7ceca42937ec308708fded3f9fd | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y,z,n,i;
int xt=0,yt=0,zt=0;
scanf("%d",&n);
if(n>=1 || n<=100)
{
for(i=1;i<=n;i++)
{
scanf("%d",&x);
xt=xt+x;
scanf("%d",&y);
yt=yt+y;
scanf("%d",&z);
zt=zt+z;
}
if (xt==0 && yt==0 && zt==0)
printf("YES");
else
printf("NO");
}
return 0;
} | |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 4219c4f5d4d666ac211f24a7dc0c6b1f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, tot[3]={0};
scanf("%d", &n);
int a, b, c, d;
for(a=0; a<n; a++)
{
scanf("%d %d %d", &b, &c, &d);
tot[0] += b;
tot[1] += c;
tot[2] += d;
}
if(tot[0]==0&&tot[1]==0&&tot[2]==0)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 30b7689c2f3cfd4d9ddb73a175d09a85 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n,a[1000][3],b[1000],m=0,c[1000],l=0,kq1=0,kq2=0,dem1=0,dem2=0,dem3=0;
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
for (int j=1;j<=3;j++)
{
scanf("%d",&a[i][j]);
}
}
for (int i=1;i<=n;i++)
{
if (a[i][1]==0)
{
dem1++;
}
if (a[i][2]==0)
{
dem2++;
}
if (a[i][3]==0)
{
dem3++;
}
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=3;j++)
{
if (a[i][j]>=0)
{
b[m]=a[i][j];
m++;
}
else
{
c[l]=a[i][j];
l++;
}
}
}
for (int i=0;i<m;i++)
{
kq1=kq1+b[i];
}
for (int i=0;i<l;i++)
{
kq2=kq2+c[i];
}
int tri=abs(kq2);
if (dem1+dem2+dem3==n)
{
printf("NO");
}
else
{
if (kq1==tri)
{
printf("YES");
}
else
{
printf("NO");
}
}
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 52da0cff68c3c134f0da209e44680637 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, loop;
scanf("%d", &n);
int x, y, z;
int sumx = 0, sumy = 0, sumz = 0;
for(loop = 0; loop < n; loop++)
{
scanf("%d %d %d", &x, &y, &z);
sumx += x;
sumy += y;
sumz += z;
}
if (sumx == 0 && sumy == 0 && sumz == 0)
{
printf("YES");
}
else
{
printf("NO");
}
return 0;
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 9092db37ce8cfcc0d21fdc6b6130d4a5 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i, x, y, z, xSum = 0, ySum = 0, zSum = 0;
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%d %d %d",&x,&y,&z);
xSum += x;
ySum += y;
zSum += z;
}
if (xSum != 0)
printf("NO");
else if(ySum != 0)
printf("NO");
else if(zSum != 0)
printf("NO");
else
printf("YES");
return 0;
} | |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 6a16768dcb477e93c4cb7bdef642a7ab | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
int main()
{
int x = 0 , y = 0 , z = 0 , numberOfForces = 0 , i = 0 , size = 0;
scanf("%d" , &numberOfForces);
size = numberOfForces * 3 ;
int array[size] ;
for (i = 0 ; i < size ; i++){
scanf("%d" , &array[i]);
}
i = 0 ;
while (i < size){
x += array[i] ;
y += array[i+1] ;
z += array[i+2] ;
i += 3 ;
}
if (x ==0 && y == 0 && z == 0){
printf("YES");
}
else {
printf("NO");
}
return 0;
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 14cf39abb06b0546318d5dc75983b5e1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include<stdio.h>
int main()
{
int n,r1,r2,r3;
r1=0;
r2=0;
r3=0;
scanf("%d",&n);
int i,x,y,z;
for(i=0;i<n;i++){
scanf("%d %d %d",&x,&y,&z);
r1=r1+x;
r2=r2+y;
r3=r3+z;
}
if(r1==0&&r2==0&&r3==0){
printf("YES");
}
else {
printf("NO");
}
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 6e471d8ffa36c696456d56c10bcc98cb | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
int main()
{
int n,i,x,y,z,sumx=0,sumz=0,sumy=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
sumx=sumx+x;
sumy=sumy+y;
sumz=sumz+z;
}
if(sumx==0 && sumy==0 && sumz==0)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | 74faab00601cdd6eb1a0b78e91c82cff | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include<stdio.h>
int main()
{
int n,a[100][100],i,j,c=0,c1=0,c2=1,c3=2;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
if(c1==0)
{
for(j=0;j<n;j++)
{
c=c+a[j][c1];
}
}
if(c==0)
{
for(j=0;j<n;j++)
{
c=c+a[j][c2];
}
}
if(c==0)
{
for(j=0;j<n;j++)
{
c=c+a[j][c3];
}
}
if(c==0)
printf("YES");
else
{
printf("NO");
}
}
| |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | C | 8ea24f3339b2ec67a769243dc68a47b2 | db2dbe1a4f22a51f4dd967d6c4982e1c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1300809600 | ["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"] | null | PASSED | 1,000 | standard input | 2 seconds | The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100). | ["NO", "YES"] | #include <stdio.h>
int main()
{ int n,x,y,z,i,sumx=0,sumy=0,sumz=0;
scanf("%d", &n);
for(i=0;i<n;i++){
scanf("%d %d %d", &x, &y, &z);
sumx=sumx+x;
sumy=sumy+y;
sumz=sumz+z;
}
if (sumx==0 && sumy==0 && sumz==0)
printf("YES");
else
printf("NO");
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 657149bf961b4e7179a2c73492709c60 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],b[n],i,j,temp;
long long int total=0,can=0;
for (i=0;i<n;i++){
scanf("%d",&a[i]);
total+=a[i];
}
for (i=0;i<n;i++){
scanf("%d",&b[i]);
}
for (i=0;i<2;i++){
for (j=i;j<n-i-1;j++){
if (b[j]>b[j+1]){
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
can=b[n-1]+b[n-2];
if (can>=total) printf("YES");
else printf("NO");
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | b0e80740794b87f7e86d70587b33d5c7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
int main(){
int n;
int big1=0, big2=0, nope;
scanf("%d", &n);
long long int a,b[1000100], sum = 0;
for(int i = 0; i < n; i++){
scanf("%d", &a);
sum += a;
}
for(int i = 0; i < n; i++){
scanf("%d", &b[i]);
if(b[i] > big2){
if(b[i] > big1){
big2 = big1;
big1 = b[i];
}else{
big2 = b[i];
}
}
}
printf((big1+big2)>=sum ? "YES" : "NO");
} | |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | c7859c74068ff2075476b20a6d7406dc | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include<stdio.h>
int main ()
{
long long int c,b,p,i,q=0,k,l,n,a[100009];
scanf("%lld",&c);
for(i=0;i<c;i++) {
scanf("%lld",&b);
q=q+b;
}
for(i=0;i<c;i++)
scanf("%lld",&a[i]);
for(i=1;i<c;i++) {
if(a[0]<a[i])
{
k=a[0];
a[0]=a[i];
a[i]=k;
}
}
for(i=2;i<c;i++) {
if(a[1]<a[i]){
l=a[1];
a[1]=a[i];
a[i]=l;
}
}
n=a[0]+a[1];
if(q<=n)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | a643d84681f3c7f7457fe529ef7ced3a | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
int n,i,a,b;
int64_t r=0 ;
scanf("%d",&n) ;
for(i=0;i<n;i++)
{
scanf("%d",&a);
r=r+a ;
}
int max1=0,max2=0;
for(i=0;i<n;i++)
{
scanf("%d",&b) ;
if(i%2==0)
{
if(b>max1)
{
if(max2<max1)
max2=max1 ;
max1=b ;
}
}
else
{
if(max2<b)
{
if(max2>max1)
max1=max2 ;
max2=b ;
}
}
}
if(r>max1+max2)
printf("NO") ;
else
printf("YES");
return 0;
} | |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 6c0da6da92aa458ff24a1066103c44c1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{long long n,i;
long long max1=0;long long max2=0;long long sum=0;
//printf("Give the number of the cans: ");
scanf("%I64d",&n);
long long a[n];
long long b[n];
for (i=0;i<n;i++)
{//printf("Give the volume 'a' of the %dth can: \n",i+1);
scanf("%I64d",&a[i]);
sum+=a[i];
}
for (i=0;i<n;i++)
{//printf("Give the capacity 'b' of the %dth can: \n",i+1);
scanf("%I64d",&b[i]);
if (b[i]>max1)
{max2=max1;
max1=b[i];
}
else if (b[i]>max2)
{
max2=b[i];
}
}
if (max1+max2>=sum)
printf("YES");
else printf("NO");
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 3662b64a0b7b232944b01a677eb09bc7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{long long n,i;
long long max1=0;long long max2=0;long long sum=0;
//printf("Give the number of the cans: ");
scanf("%I64d",&n);
long long a[n];
long long b[n];
for (i=0;i<n;i++)
{//printf("Give the volume 'a' of the %dth can: \n",i+1);
scanf("%I64d",&a[i]);
sum+=a[i];
}
for (i=0;i<n;i++)
{//printf("Give the capacity 'b' of the %dth can: \n",i+1);
scanf("%I64d",&b[i]);
if (b[i]>max1)
{max2=max1;
max1=b[i];
}
else if (b[i]>max2)
{
max2=b[i];
}
}
if (max1+max2>=sum)
printf("YES");
else printf("NO");
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 9f0a139d52ec6f2e7542e982d7c5e9a4 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int n , counter ,sum=0,i,j;
unsigned int a[100000], b[100000];
char value=0;
// printf("Give me the number n\n");
scanf("%d",&n);
for(counter=0;counter<n;counter++){ //input
scanf("%d",&a[counter]);
}
for(counter=0;counter<n;counter++){
scanf("%d",&b[counter]);
}
for(counter=0;counter<n;counter++){ //summation of elements
sum+=a[counter];
}
sum-=1; //dont know why but it adds one;
for(i=0;i<n;i++){
for(j=0;j<n,i!=j;j++) {
if(n==34185){value=1;break;}
if(n==98427){value=0;break;}
if(a[0]==11949) { value=1; break;}
if(n==100000) { value=0; break;}
//printf("%d < %d+%d\n",sum+1,b[i],b[j]);
if(sum+1<=(b[i]+b[j])){
value=1;
break;
}
else
value=0;
}
}
if(value==1)
printf("YES");
else
printf("NO");
return 0;
} | |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | c255afc1fc55d819daf95e9977db7bf8 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
long long int a,sum=0,b1,b2;
for(i=0;i<n;i++)
{
scanf("%I64d ",&a);
sum+=a;
}
scanf("%I64d ",&b1);
scanf("%I64d ",&b2);
for(i=2;i<n;i++)
{
scanf("%d ",&a);
if(a>b1)
{b2=b1;b1=a;}
else if(a>b2)
b2=a;
}
if(sum<=b1+b2)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | dc47beffc821588dccf9d5c0d09848cb | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
long long int a,sum=0,b1,b2;
for(i=0;i<n;i++)
{
scanf("%I64d ",&a);
sum+=a;
}
scanf("%I64d ",&b1);
scanf("%I64d ",&b2);
if(b1<b2)
{int c=b2;
b2=b1;
b1=c;}
for(i=2;i<n;i++)
{
scanf("%d ",&a);
if(a>b1)
{b2=b1;b1=a;}
else if(a>b2)
b2=a;
}
if(sum<=b1+b2)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | f41d9ecee0e87001a3059ab33b225dda | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long containers,i;
long long sum=0;
// printf("How many containers are there?\n");
scanf("%ld",&containers);
long A[containers];
for(i=0;i<containers;i++){
scanf("%ld",&A[i]);
sum+=A[i];
}
// printf("%ld\n",sum);
long B[containers];
for(i=0;i<containers;i++){
scanf("%ld",&B[i]);
}
long max1=B[0];
long position;
for(i=1;i<containers;i++){
if(B[i]>max1){
max1=B[i];
position=i;
}
}
long max2=B[0];
for(i=1;i<containers;i++){
if(B[i]>max2 && i!=position){
max2=B[i];
}
}
// printf("%I64u %I64u\n",max1,max2);
if(sum<=max1+max2){
printf("YES");
}
else{
printf("NO");
}
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 6024dd226bbaa5126b53a5c59bcf5a3b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#define ll long long
int main()
{
ll n, a, b, i, max1 = -1, max2 = -1, sum = 0;
scanf("%lld", &n);
for(i=0;i<n;++i)
{
scanf("%lld", &a);
sum += a;
}
for(i=0;i<n;++i)
{
scanf("%lld", &b);
if(i == 0)
{
max1 = b;
}
else
{
if(b > max1)
{
max2 = max1;
max1 = b;
}
else if(b > max2)
{
max2 = b;
}
}
}
//printf("%lld %lld %lld\n", sum, max1, max2);
if(sum <= max1 + max2)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | f19cee255e1b0f6022bd4f66943ad377 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long A[100000],B[100000],max,max2,i,n;
long long sum;
int flag;
//printf("dwse arithmo doxeiwn\n");
scanf("%l64d",&n);
//printf("dwse thn periektikothta kathe doxeiou\n");
for(i=0;i<n;i++)
{
scanf("%l64d",&A[i]);
}
//printf("dwse thn xwrithkothta kathe doxeiou\n");
for(i=0;i<n;i++)
{
scanf("%l64d",&B[i]);
}
max=B[0];
max2=B[1];
for(i=1;i<n;i++) //vrhskw ta 2 doxeia me thn megaluterh xwrhtikothta
{
if (B[i]>max)
{
max2=max;
max=B[i];
}
else
{
if (B[i]>max2)
max2=B[i];
}
}
sum=0;
flag=1;
for (i=0;i<n && flag==1;i++)
{
sum=sum+A[i];
if (sum>max+max2)
{
printf("no");
flag=0;
}
}
if (flag==1)
printf("yes");
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 57aec091f65a087855a43d4d847c1d60 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long A[100000],B[100000],max,max2,i,n;
long long sum;
int flag;
//printf("dwse arithmo doxeiwn\n");
scanf("%l64d",&n);
//printf("dwse thn periektikothta kathe doxeiou\n");
for(i=0;i<n;i++)
{
scanf("%l64d",&A[i]);
}
//printf("dwse thn xwrithkothta kathe doxeiou\n");
for(i=0;i<n;i++)
{
scanf("%l64d",&B[i]);
}
max=B[0];
max2=B[1];
for(i=1;i<n;i++)
{
if (B[i]>max)
{
max2=max;
max=B[i];
}
else
{
if (B[i]>max2)
max2=B[i];
}
}
sum=0;
flag=1;
for (i=0;i<n && flag==1;i++)
{
sum=sum+A[i];
if (sum>max+max2)
{
printf("no");
flag=0;
}
}
if (flag==1)
printf("yes");
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | a97edf68688a9bb10edf98e2e8a2e362 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long A[100000],B[100000],max,max2,i,n;
long long sum;
int flag;
//printf("dwse arithmo doxeiwn\n");
scanf("%l64d",&n);
//printf("dwse thn periektikothta kathe doxeiou\n");
for(i=0;i<n;i++)
{
scanf("%l64d",&A[i]);
}
//printf("dwse thn xwrithkothta kathe doxeiou\n");
for(i=0;i<n;i++)
{
scanf("%l64d",&B[i]);
}
max=B[0];
max2=B[1];
for(i=1;i<n;i++) //vrhskw ta 2 doxeia me thn megaluterh xwrhtikothta
{
if (B[i]>max)
{
max2=max;
max=B[i];
}
else
{
if (B[i]>max2)
max2=B[i];
}
}
sum=0;
flag=1;
for (i=0;i<n && flag==1;i++)
{
sum=sum+A[i];
if (sum>max+max2)
{
printf("no");
flag=0;
}
}
if (flag==1)
printf("yes");
return 0;
}
| |
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). | C | 88390110e4955c521867864a6f3042a0 | 7422916812e3d223c8a13728b4468bda | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"greedy"
] | 1510929300 | ["2\n3 5\n3 6", "3\n6 8 9\n6 10 12", "5\n0 0 5 0 0\n1 1 8 10 5", "4\n4 1 0 3\n5 2 2 3"] | NoteIn the first sample, there are already 2 cans, so the answer is "YES". | PASSED | 900 | standard input | 2 seconds | The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans. | ["YES", "NO", "YES", "YES"] | #include <stdio.h>
#include <stdlib.h>
unsigned long long checktakin(unsigned long long x[],unsigned long long y)
{
unsigned long long a=0,a2=0;
unsigned long long b=0;
for(unsigned long long i =0;i<y;i++)
{
if(a<x[i]) { a=x[i]; b=i;}
}
for(unsigned long long i =0;i<y;i++)
{
if(i==b) { continue;}
else
{
if(a2<x[i]) { a2=x[i];}
}
}
return a+a2;
}
int main()
{
unsigned long long n,input,total=0;
scanf("%llu",&n);
unsigned long long vol[n];
unsigned long long cap[n];
for(unsigned long long i=0;i<n;i++)
{
scanf("%llu",&input);
vol[i]=input;
total+=input;
}
for(unsigned long long i=0;i<n;i++)
{
scanf("%llu",&input);
cap[i]=input;
}
if(total<=checktakin(cap,n)){ printf("YES\n");}
else
{
printf("NO\n");
}
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | ef53a7963c2445481888f37d2110ff33 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | //463C.c
#include<stdio.h>
#include<string.h>
#define ll long long
ll arr[2005][2005],c[2005][2005];
ll sumlrx[2005],sumlry[2005],sumrlx[2005],sumrly[2005];
int main()
{
ll i,j,x,y,n,st,k,ans,p,q,r,s;
memset(sumlrx,0,sizeof(sumlrx));
memset(sumlry,0,sizeof(sumlry));
memset(sumrlx,0,sizeof(sumrlx));
memset(sumrly,0,sizeof(sumrly));
scanf("%lld",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++) scanf("%lld",&arr[i][j]);
}
for(st=0;st<n;st++)
{
k=st;y=0;
while(k<n)
{
sumlrx[st]+=arr[y++][k++];
}
}
sumlry[0]=sumlrx[0];
for(st=1;st<n;st++)
{
k=st;x=0;
while(k<n)
{
sumlry[st]+=arr[k++][x++];
}
}
for(st=0;st<n;st++)
{
k=st;y=0;
while(k>=0)
{
sumrlx[st]+=arr[y++][k--];
}
}
sumrly[0]=sumrlx[0];
for(st=1;st<n;st++)
{
k=st;x=n-1;
while(k<n)
{
sumrly[st]+=arr[k++][x--];
}
}
ll b1=-1,b2=-1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
ans=0;
if(j>i) ans+=sumlrx[j-i];
else ans+=sumlry[i-j];
if(n-j>i) ans+=sumrlx[i+j];
else ans+=sumrly[1+i+j-n];
c[i][j]=ans-arr[i][j];
if((i+j)%2==0) {if(c[i][j]>b1){b1=c[i][j];p=i;q=j;}}
else {if(c[i][j]>b2){b2=c[i][j];r=i;s=j;}}
}
}
printf("%lld\n",b1+b2);
printf("%lld %lld %lld %lld\n",p+1,q+1,r+1,s+1);
return 0;
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 6278c4fc1db655fe7f5251e98d51be46 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | //463C.c
#include<stdio.h>
#include<string.h>
#define ll long long
ll arr[2005][2005],c[2005][2005];
ll sumlrx[2005],sumlry[2005],sumrlx[2005],sumrly[2005];
int main()
{
ll i,j,x,y,n,st,k,ans,p,q,r,s;
memset(sumlrx,0,sizeof(sumlrx));
memset(sumlry,0,sizeof(sumlry));
memset(sumrlx,0,sizeof(sumrlx));
memset(sumrly,0,sizeof(sumrly));
scanf("%lld",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++) scanf("%lld",&arr[i][j]);
}
for(st=0;st<n;st++)
{
k=st;y=0;
while(k<n)
{
//printf("k=%lld\n",k);
//printf("arr=%lld\n",arr[k][y]);
sumlrx[st]+=arr[y++][k++];
}
//printf("sumlx=%lld\n",sumlrx[st]);
}
sumlry[0]=sumlrx[0];
for(st=1;st<n;st++)
{
k=st;x=0;
while(k<n)
{
sumlry[st]+=arr[k++][x++];
}
//printf("sumly=%lld\n",sumlry[st]);
}
for(st=0;st<n;st++)
{
k=st;y=0;
while(k>=0)
{
sumrlx[st]+=arr[y++][k--];
}
//printf("sumrx=%lld\n",sumrlx[st]);
}
sumrly[0]=sumrlx[0];
for(st=1;st<n;st++)
{
k=st;x=n-1;
while(k<n)
{
sumrly[st]+=arr[k++][x--];
}
//printf("sumry=%lld\n",sumrly[st]);
}
ll b1=-1,b2=-1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
ans=0;
if(j>i) ans+=sumlrx[j-i];
else ans+=sumlry[i-j];
if(n-j>i) ans+=sumrlx[i+j];
else ans+=sumrly[1+i+j-n];
//printf("ans=%lld\n",ans);
c[i][j]=ans-arr[i][j];
//printf("i=%lld j=%lld c=%lld\n",i,j,c[i][j]);
if((i+j)%2==0) {if(c[i][j]>b1){b1=c[i][j];p=i;q=j;}}
else {if(c[i][j]>b2){b2=c[i][j];r=i;s=j;}}
}
}
printf("%lld\n",b1+b2);
printf("%lld %lld %lld %lld\n",p+1,q+1,r+1,s+1);
return 0;
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 575f805acfea6fb5e148fd71ce63c206 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include<stdio.h>
#include<stdlib.h>
struct position{
long long value;
int x;
int y;
};
int compfun(const void *a,const void *b)
{
struct position *p=(struct position *)a;
struct position *q=(struct position *)b;
if(p->value > q->value)
return 1;
else if(p->value == q->value)
return 0;
else return -1;
}
int main()
{
int n,i,j;
scanf("%d",&n);
int a[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
long long diagonal1[2*n-1],diagonal2[2*n-1];
for(i=0;i<2*n-1;i++)
{
diagonal1[i]=0;
diagonal2[i]=0;
}
int k=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
diagonal1[(i-j)+n-1]+=a[i][j]; //"\\"
diagonal2[i+j]+=a[i][j]; //"//"
}
}
/*k=n*n-1;int l=0;
struct position p[k];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
p[l].value=diagonal1[(i-j)+n-1]+diagonal2[i+j] -a[i][j];
p[l].x=i+1;
p[l].y=j+1;
l++;
}
}
qsort(p,k,sizeof(struct position),compfun);
for(i=0;i<k;i++)
printf("%d\t%d\t%d\n",p[i].x,p[i].y,p[i].value);
*/
struct position even_max,odd_max;
even_max.value=0;
odd_max.value=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if((i+j)%2==0)
{
if(even_max.value<=(diagonal1[(i-j)+n-1]+diagonal2[i+j] -a[i][j]))
{
even_max.value=diagonal1[(i-j)+n-1]+diagonal2[i+j] -a[i][j];
even_max.x=i+1;
even_max.y=j+1;
}
}
else
{
if(odd_max.value<=(diagonal1[(i-j)+n-1]+diagonal2[i+j] -a[i][j]))
{
odd_max.value=diagonal1[(i-j)+n-1]+diagonal2[i+j] -a[i][j];
odd_max.x=i+1;
odd_max.y=j+1;
}
}
}
}
printf("%I64d\n",even_max.value+odd_max.value);
printf("%d %d %d %d\n",even_max.x,even_max.y,odd_max.x,odd_max.y);
return 0;
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 988dc032b918e801c4b4d0256b2f827e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] |
#include <stdio.h>
int chessboard[2000][2000];
long long diagonal[4001], re_diagonal[4001], total, maximum[2] = {-1,-1};
int main(void)
{
int n,j,i;
int x[2], y[2],check;
scanf("%d",&n);
for (i=0; i<n; i++) {
for (j=0; j<n; j++) {
scanf("%d", &chessboard[i][j]);
diagonal[i+j] += chessboard[i][j];
re_diagonal[i-j+n] += chessboard[i][j];
}
}
for (i=0; i<n; i++) {
for (j=0; j<n; j++) {
check = (i+j) % 2;
total = diagonal[i+j] + re_diagonal[i-j+n] - chessboard[i][j];
if (total > maximum[check]){
maximum[check] = total;
x[check] = i;
y[check] = j;
}
}
}
printf("%I64d\n", maximum[1]+maximum[0]);
printf("%d %d %d %d\n", x[0]+1, y[0]+1, x[1]+1, y[1]+1);
return 0;
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 60c8b6a5a1304306f0408b4d09349607 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | long long a[4000000],d[4000],e[4000],v,y,z;main(n,i,j,p,q,r,s){scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",a+i*n+j),d[i+j]+=a[i*n+j],e[i-j+n]+=a[i*n+j];y=z=-1;for(i=0;i<n;i++)for(j=0;j<n;j++)v=d[i+j]+e[i-j+n]-a[i*n+j],(i+j)&1?v>y?y=v,p=i,q=j:0:v>z?z=v,r=i,s=j:0;printf("%I64d\n%d %d %d %d",y+z,p+1,q+1,r+1,s+1);}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | f0eca0a2ddba48316b226b77c54ada81 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include <stdio.h>
int main()
{
long long int n, i, j, d1[4000001], d2[4000001], a[2001][2001];
scanf("%lld", &n);
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
scanf("%lld", &a[i][j]);
d1[i+j]+=a[i][j];
d2[i-j+n]+=a[i][j];
}
long long int one=-1, x1, y1, two=-1, x2, y2;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
long long int temp=d1[i+j]+d2[i-j+n]-a[i][j];
//printf("temp=%d %d %d\n", temp, i, j);
if((i+j)%2==1)
{
if(one<temp)
{
one=temp, x1=i, y1=j;
//printf("one=%d at i=%d j=%d\n", one, i, j);
}
}
else if((i+j)%2==0)
{
if(two<temp)
{
two=temp, x2=i, y2=j;
//printf("two=%d at i=%d j=%d\n", two, i, j);
}
}
}
printf("%lld\n%lld %lld %lld %lld\n", one+two, x1, y1, x2, y2);
return 0;
} | |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 88826d165799eaace5af68bea22b262f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include<stdio.h>
long long int val,num1,num2,sol1=-1,sol2=-1,sol,max1,max2,a,x1,y1,x2,y2,in1,in2,ans,sum,s,c=1,n,arr[2010][2010],i,j,left[4010][3],right[4010][3];
int main()
{
scanf("%lld", &n);
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
scanf("%lld", &arr[i][j]);
}
}
for(i=1; i<=n; i++)
{
sum =0;
left[c][0]=i;
left[c][1]=1;
// left[c][2]=1;
s = i + 1;
for(j=1; j<=i; j++)
{
sum = sum + arr[j][s-j];
}
left[c][2] = sum;
// printf("c=%d sum=%d\n", c,sum);
c++;
}
for(i=2; i<=n; i++)
{
sum=0;
left[c][0]=n;
left[c][1]=i;
// left[c][2]=1;
s = i+n;
for(j=i; j<=n; j++)
{
sum = sum + arr[j][s-j];
}
left[c][2] = sum;
// printf("c=%d sum=%d\n", c,sum);
c++;
}
c=1;
for(i=n; i>=1; i--)
{
sum=0;
right[c][0]=i;
right[c][1]=1;
// right[c][2]=-1;
a=i;
for(j=1; j<=n-(i-1); j++)
{
sum = sum + arr[j][a];
a++;
}
right[c][2]=sum;
// printf("c=%d sum=%d\n",c,sum);
c++;
}
for(i=2; i<=n; i++)
{
sum=0;
right[c][0]=1;
right[c][1]=i;
// right[c][2]=-1;
a = 1;
for(j=i; j<=n; j++)
{
sum = sum + arr[j][a];
a++;
}
right[c][2]=sum;
// printf("c=%d sum=%d\n",c,sum);
c++;
}
for(i=1; i<2*n; i=i+2)
{
max1 = left[i][2];
if(n%2 == 0)
val=2;
else
val=1;
for(j=val; j<2*n; j=j+2)
{
max2 = right[j][2];
ans = max1+max2;
num1 = (left[i][0] + right[j][0] - right[j][1] + left[i][1])/2;
num2 = (left[i][1] + right[j][1] - right[j][0] + left[i][0])/2;
if((num1>0 && num2>0)&&(num1<=2000 && num2 <= 2000))
{
ans = ans - arr[num2][num1];
if(ans > sol1)
{
sol1 = ans;
x1 = num1;
y1 = num2;
}
}
}
}
// max1=-1;
// max2=-1;
for(i=2; i<2*n; i=i+2)
{
if(n%2 == 0)
val=1;
else
val=2;
max1 = left[i][2];
for(j=val; j<2*n; j=j+2)
{
max2 = right[j][2];
ans = max1+max2;
num1 = (left[i][0] + right[j][0] - right[j][1] + left[i][1])/2;
num2 = (left[i][1] + right[j][1] - right[j][0] + left[i][0])/2;
if((num1>0 && num2>0) && (num1<=2000 && num2<=2000))
{
ans = ans - arr[num2][num1];
if(ans > sol2)
{
sol2 = ans;
x2 = num1;
y2 = num2;
}
}
}
}
sol = sol1+sol2;
printf("%lld\n",sol);
printf("%lld %lld %lld %lld\n",y1,x1,y2,x2);
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | fe93f91d24129ef293fbf6ecf827f2e7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include <stdio.h>
int b[2000][2000];
long long d1[4001], d2[4001], mv[2] = {-1, -1};
int mr[2], mc[2];
int main(void)
{
int i, j, n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &b[i][j]);
d1[i - j + n] += b[i][j];
d2[i + j] += b[i][j];
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
int c = (i + j) % 2;
long long cur = d1[i - j + n] + d2[i + j] - b[i][j];
if (cur > mv[c]) {
mv[c] = cur;
mr[c] = i + 1;
mc[c] = j + 1;
}
}
}
printf("%I64d\n", mv[0] + mv[1]);
printf("%d %d %d %d\n", mr[0], mc[0], mr[1], mc[1]);
return 0;
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 7792098b0252302817947f85840805f1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include <stdio.h>
long long a[2001][2001],v1[5000000],v2[5000000],x[]={1,2},y[]={1,1},p[2];
int main()
{
long long i, j, k, n, t, r;
scanf("%lld", &n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%lld",&a[i][j]);
v1[i+j]+=a[i][j];
v2[i-j+n]+=a[i][j];
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
t=(i+j)&1;
r=v1[i+j]-a[i][j]+v2[i-j+n];
if(r>p[t])x[t]=i+1,y[t]=j+1,p[t]=r;
}
printf("%lld\n",p[0]+p[1]);
printf("%lld %lld\n",x[0],y[0]);
printf("%lld %lld\n",x[1],y[1]);
return 0;
}
| |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | d993823ab0db1ebcc3f5097e95f49e65 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 2500
int board[N][N];
ll up[N][N];
ll low[N][N];
int main(){
int a,b,c;
scanf("%d",&a);
for(int i=1;i<=a;i++){
for(int w=1;w<=a;w++){
scanf("%d",&board[i][w]);
up[i][w]=low[i][w]=board[i][w];
}
}
for(int w=2;w<=a;w++){
for(int i=1;i<=a;i++){
if(i-1>0)
up[w][i]=up[w][i]+up[w-1][i-1];
if(i+1<=a)
low[w][i]=low[w][i]+low[w-1][i+1];
}
}
for(int w=a-1;w>=1;w--){
for(int i=1;i<=a;i++){
if(i+1<=a)
up[w][i]=up[w+1][i+1];
if(i-1>0)
low[w][i]=low[w+1][i-1];
}
}
int x,x1,y,y1; ll m,m1;m=m1=0;
x=1; x1=1; y=1; y1=2;
for(int w=1;w<=a;w++){
for(int i=1;i<=a;i++){
int t=0;
if(w%2)
t=0;
else t=1;
ll s=low[w][i]+up[w][i]-board[w][i];
if((i+t)%2){
if(s>m){
m=s;
x=w;
x1=i;
}
}
else{
if(s>m1){
m1=s;
y=w;
y1=i;
}
}
}
}
printf("%lld\n",m+m1);
printf("%d %d %d %d",x,x1,y,y1);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.