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
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $$$n$$$ packets with inflatable balloons, where $$$i$$$-th of them has exactly $$$a_i$$$ balloons inside.They want to divide the balloons among themselves. In addition, there are several conditions to hold: Do not rip the packets (both Grigory and Andrew should get unbroken packets); Distribute all packets (every packet should be given to someone); Give both Grigory and Andrew at least one packet; To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions.
If it's impossible to divide the balloons satisfying the conditions above, print $$$-1$$$. Otherwise, print an integer $$$k$$$Β β€” the number of packets to give to Grigory followed by $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$Β β€” the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them.
C
2b55012c899645bac8d293e85e73148f
a7aea6a4ec58e03524ea88db6d7fec1a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1530453900
["3\n1 2 1", "2\n5 5", "1\n10"]
NoteIn the first test Grigory gets $$$3$$$ balloons in total while Andrey gets $$$1$$$.In the second test there's only one way to divide the packets which leads to equal numbers of balloons.In the third test one of the boys won't get a packet at all.
PASSED
1,000
standard input
1 second
The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10$$$)Β β€” the number of packets with balloons. The second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 1000$$$)Β β€” the number of balloons inside the corresponding packet.
["2\n1 2", "-1", "-1"]
#include <stdio.h> #include <stdlib.h> int at_least_one_diff(int *tab, int packets_number) { int i = 0, j; if (packets_number > 2) return (1); while (i < packets_number) { j = i + 1; while (j < packets_number) { if (tab[i] != tab[j]) return (1); j++; } i++; } return (0); } void find_smallest(int *tab, int packets_number) { int i = 0, min = tab[0], j = 1; while (i < packets_number) { if (min > tab[i]) { min = tab[i]; j = i + 1; } i++; } printf("1\n%d", j); } int main() { int packets_number, i = 0; int *tab; scanf("%d", &packets_number); if (!(tab = malloc(sizeof (int) * packets_number))) return(0); while (i < packets_number) scanf("%d", &tab[i++]); if (packets_number >= 2 && at_least_one_diff(tab, packets_number)) find_smallest(tab, packets_number); else printf("-1"); free(tab); return(0); }
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $$$n$$$ packets with inflatable balloons, where $$$i$$$-th of them has exactly $$$a_i$$$ balloons inside.They want to divide the balloons among themselves. In addition, there are several conditions to hold: Do not rip the packets (both Grigory and Andrew should get unbroken packets); Distribute all packets (every packet should be given to someone); Give both Grigory and Andrew at least one packet; To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions.
If it's impossible to divide the balloons satisfying the conditions above, print $$$-1$$$. Otherwise, print an integer $$$k$$$Β β€” the number of packets to give to Grigory followed by $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$Β β€” the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them.
C
2b55012c899645bac8d293e85e73148f
c9224564d8b3a3621e830d79e666c647
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1530453900
["3\n1 2 1", "2\n5 5", "1\n10"]
NoteIn the first test Grigory gets $$$3$$$ balloons in total while Andrey gets $$$1$$$.In the second test there's only one way to divide the packets which leads to equal numbers of balloons.In the third test one of the boys won't get a packet at all.
PASSED
1,000
standard input
1 second
The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10$$$)Β β€” the number of packets with balloons. The second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 1000$$$)Β β€” the number of balloons inside the corresponding packet.
["2\n1 2", "-1", "-1"]
#include <stdio.h> int a[1005]; int main() { int n,sum=0,min=0xfffffff,t; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; if(min>a[i]){ min=a[i],t=i;}} if(n==1) printf("-1\n"); else{ if(min==(sum-min)) printf("-1\n"); else{ printf("1\n%d\n",t); } } return 0; }//
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants.
Print q whitespace-separated integers β€” the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
87045c4df69110642122f2c114476947
fc9c78b75a346b9f6ac1cf43f1cee1d3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy" ]
1348500600
["5\n2 3 4 1 1\n2\n2 3"]
NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2).
PASSED
1,900
standard input
2 seconds
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial sizes of the stone piles. The third line contains integer q (1 ≀ q ≀ 105) β€” the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≀ ki ≀ 105) β€” the values of number k for distinct queries. Note that numbers ki can repeat.
["9 8"]
#include<stdio.h> #include<stdlib.h> int cmp(long long int *a1,long long int *a2) {return(*a1-*a2);} int main() {long long int i,j,n,q,x,k,t,a[100005]={0},s[100005]={0},d[100005]={0}; scanf("%I64d",&n); for(i=1;i<=n;i++) scanf("%I64d",&a[i]); qsort(a+1,n,sizeof(long long int),cmp); s[1]=a[1]; for(i=1;i<=n;i++) s[i]=s[i-1]+a[i]; scanf("%I64d",&q); j=0; while(j<q) {i=n-1;scanf("%I64d",&k);x=k; if(d[k]==0) {t=0; while(i>=1) { t+=s[i]; i-=x; x*=k; }d[k]=t;}printf("%I64d ",d[k]);j++;} return 0; }
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants.
Print q whitespace-separated integers β€” the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
87045c4df69110642122f2c114476947
31524535760c734751df1212f7fbd608
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy" ]
1348500600
["5\n2 3 4 1 1\n2\n2 3"]
NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2).
PASSED
1,900
standard input
2 seconds
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial sizes of the stone piles. The third line contains integer q (1 ≀ q ≀ 105) β€” the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≀ ki ≀ 105) β€” the values of number k for distinct queries. Note that numbers ki can repeat.
["9 8"]
#include <stdio.h> #include <stdlib.h> int cmp(int*a,int*b){return*b-*a;} int n,a[100001],q,p; long long s[100001],memo[100001]; int main(){ int i; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",a+i); qsort(a+1,n,4,cmp); s[1] = a[1]; for(i=2;i<=n;i++) s[i] = s[i-1] + a[i]; scanf("%d",&q); while(q--){ long long ans=0,mul=0,d=1,j=0,k; scanf("%d",&p); if(memo[p]!=0) printf("%I64d ",memo[p]); else{ j=0; while(1){ k=j+d; if(k<=n){ ans += mul*(s[k]-s[j]); d*=p; j=k; mul++; }else{ ans += mul*(s[n]-s[j]); break; } } printf("%I64d ",memo[p]=ans); } } puts(""); return 0; }
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants.
Print q whitespace-separated integers β€” the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
87045c4df69110642122f2c114476947
b8029c61a3fc1579371de9c0e88b39f5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy" ]
1348500600
["5\n2 3 4 1 1\n2\n2 3"]
NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2).
PASSED
1,900
standard input
2 seconds
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial sizes of the stone piles. The third line contains integer q (1 ≀ q ≀ 105) β€” the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≀ ki ≀ 105) β€” the values of number k for distinct queries. Note that numbers ki can repeat.
["9 8"]
#include<stdio.h> #define F(a,b)for(i=a;b;i++) int n,i,q,k;long long P[100000],R[100000],j,t;int c(long long*a,long long*b){return*a-*b;}int main(){scanf("%d",&n);F(0,i<n)scanf("%I64d",&P[i]);qsort(P,n,8,c);F(1,i<n)P[i]+=P[i-1];F(1,i<=n){j=n-2;t=i;while(j>=0){R[i-1]+=P[j];j-=t;t*=i;}}scanf("%d",&q);F(0,i<q){scanf("%d",&k);printf("%I64d ",k<n?R[k-1]:R[n-1]);}puts("");return 0;}
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants.
Print q whitespace-separated integers β€” the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
87045c4df69110642122f2c114476947
32cbe60dc29a2dd3bd95e4f9856d97e1
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy" ]
1348500600
["5\n2 3 4 1 1\n2\n2 3"]
NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2).
PASSED
1,900
standard input
2 seconds
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial sizes of the stone piles. The third line contains integer q (1 ≀ q ≀ 105) β€” the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≀ ki ≀ 105) β€” the values of number k for distinct queries. Note that numbers ki can repeat.
["9 8"]
#include <stdio.h> #include <stdint.h> uint64_t P[100000], R[100000]; int compare(const void *a, const void *b) { return *(uint64_t*)a - *(uint64_t*)b; } int main(){ int n, i, q; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%I64d", &P[i]); } qsort(P, n, sizeof(uint64_t), compare); for(i = 1; i < n; i++) { P[i] += P[i-1]; } for(i = 1; i <= n; i++) { int64_t j = n-2, t = i; while(j >= 0) { R[i-1] += P[j]; j -= t; t *= i; } } scanf("%d", &q); for(i = 0; i < q; i++) { int k; scanf("%d", &k); printf("%I64d ", k < n ? R[k-1] : R[n-1]); } printf("\n"); return 0; }
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants.
Print q whitespace-separated integers β€” the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
87045c4df69110642122f2c114476947
dfa7b69b61b5adc07d3b5dee1b0c4bf0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy" ]
1348500600
["5\n2 3 4 1 1\n2\n2 3"]
NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2).
PASSED
1,900
standard input
2 seconds
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial sizes of the stone piles. The third line contains integer q (1 ≀ q ≀ 105) β€” the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≀ ki ≀ 105) β€” the values of number k for distinct queries. Note that numbers ki can repeat.
["9 8"]
#include <stdio.h> #include <stdint.h> uint64_t A[100000], P[100000], R[100000]; int compare(const void *a, const void *b) { return *(uint64_t*)a - *(uint64_t*)b; } int main(){ int n, i, q; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%I64d", &A[i]); } qsort(A, n, sizeof(uint64_t), compare); P[0] = A[0]; for(i = 1; i < n; i++) { P[i] = P[i-1] + A[i]; } for(i = 1; i <= n; i++) { int64_t j = n-2, t = i; while(j >= 0) { R[i-1] += P[j]; j -= t; t *= i; } } scanf("%d", &q); for(i = 0; i < q; i++) { int k; scanf("%d", &k); printf("%I64d ", k < n ? R[k-1] : R[n-1]); } printf("\n"); return 0; }
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.How many trees are there in the forest?
You should output the number of trees in the forest where PolandBall lives.
C
6d940cb4b54f63a7aaa82f21e4c5b994
3d8998314933ed820187c6466c2f7150
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "graphs", "dsu", "interactive", "dfs and similar", "trees" ]
1484499900
["5\n2 1 5 3 3", "1\n1"]
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PASSED
1,300
standard input
1 second
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id. It's guaranteed that the sequence p corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer n (1 ≀ n ≀ 104)Β β€” the number of Balls and the integer m (0 ≀ m &lt; n)Β β€” the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows: 5 31 23 44 5
["2", "1"]
#include<stdio.h> #include<string.h> int main(){ int n,i,j,fcount,check; scanf("%d",&n); int p[n]; int visited[n]; memset(visited,0,n*sizeof(int)); for(i=0;i<n;i++){ scanf("%d",&p[i]); } fcount=0; check = 1; for(i=0;i<n;i++){ if(visited[i]==0){ visited[i] = check; for(j=p[i]-1;visited[j]==0;j=p[j]-1){ visited[j] = check; } if(visited[j]==check){ fcount++; } check++; } } printf("%d\n",fcount); }
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.How many trees are there in the forest?
You should output the number of trees in the forest where PolandBall lives.
C
6d940cb4b54f63a7aaa82f21e4c5b994
bca0dff5cd98c4706548a973cd015c1d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "graphs", "dsu", "interactive", "dfs and similar", "trees" ]
1484499900
["5\n2 1 5 3 3", "1\n1"]
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PASSED
1,300
standard input
1 second
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id. It's guaranteed that the sequence p corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer n (1 ≀ n ≀ 104)Β β€” the number of Balls and the integer m (0 ≀ m &lt; n)Β β€” the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows: 5 31 23 44 5
["2", "1"]
#include <stdio.h> #include <string.h> #define N 10000 int dsu[N]; int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); } void join(int i, int j) { i = find(i); j = find(j); if (i == j) return; if (dsu[i] > dsu[j]) dsu[i] = j; else { if (dsu[i] == dsu[j]) dsu[i]--; dsu[j] = i; } } int main() { int n, i, p, ans; scanf("%d", &n); memset(dsu, -1, sizeof dsu); for (i = 0; i < n; i++) { scanf("%d", &p), p--; join(p, i); } ans = 0; for (p = 0; p < n; p++) if (dsu[p] < 0) ans++; printf("%d\n", ans); return 0; }
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.How many trees are there in the forest?
You should output the number of trees in the forest where PolandBall lives.
C
6d940cb4b54f63a7aaa82f21e4c5b994
036007b8be347b4d8f15171531526175
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "graphs", "dsu", "interactive", "dfs and similar", "trees" ]
1484499900
["5\n2 1 5 3 3", "1\n1"]
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PASSED
1,300
standard input
1 second
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id. It's guaranteed that the sequence p corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer n (1 ≀ n ≀ 104)Β β€” the number of Balls and the integer m (0 ≀ m &lt; n)Β β€” the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows: 5 31 23 44 5
["2", "1"]
#include <stdio.h> #include <string.h> #define MAXV 10001 typedef struct { int to; int next; } Edge_t; Edge_t E[MAXV << 1]; int Adj[MAXV]; int Size; char Visit[MAXV]; int Queue[MAXV]; void Init(int N) { memset(Adj, -1, sizeof(Adj)); Size = 0; } void Add_Edge(int u, int v) { E[Size].to = v; E[Size].next = Adj[u]; Adj[u] = Size++; } void BFS(int start) { int j, Head, Tail; Head = Tail = 0; Visit[start] = 1; Queue[Tail++] = start; while(Head < Tail) { for(j = Adj[Queue[Head]]; ~j; j = E[j].next) { if(!Visit[E[j].to]) { Visit[E[j].to] = 1; Queue[Tail++] = E[j].to; } } ++Head; } } int main() { int n; scanf("%d", &n); Init(n); for(int i = 1; i <= n; ++i) { int p; scanf("%d", &p); Add_Edge(i, p); Add_Edge(p, i); } int ans = 0; for(int i = 1; i <= n; ++i) { if(!Visit[i]) { BFS(i); ++ans; } } printf("%d\n", ans); return 0; }
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.How many trees are there in the forest?
You should output the number of trees in the forest where PolandBall lives.
C
6d940cb4b54f63a7aaa82f21e4c5b994
bf77b386c8fd6ba8fd75140af555006b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "graphs", "dsu", "interactive", "dfs and similar", "trees" ]
1484499900
["5\n2 1 5 3 3", "1\n1"]
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PASSED
1,300
standard input
1 second
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id. It's guaranteed that the sequence p corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer n (1 ≀ n ≀ 104)Β β€” the number of Balls and the integer m (0 ≀ m &lt; n)Β β€” the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows: 5 31 23 44 5
["2", "1"]
#include <stdio.h> #include <stdlib.h> #include <mem.h> #define __for(a, b, k) for(int k = a; k < b; k++) int n; int forest[10001]; int trees_count; int dsu_find(int a){ if(forest[a] != a) forest[a] = dsu_find(forest[a]); return forest[a]; } void dsu_union(int a, int b){ int ap = dsu_find(a); int bp = dsu_find(b); if(ap == bp) return; forest[ap] = bp; } int main(){ scanf("%d", &n); trees_count = n; __for(1, n + 1, i){ forest[i] = i; } __for(1, n + 1, i){ int p; scanf("%d", &p); if(dsu_find(i) != dsu_find(p)){ trees_count--; dsu_union(i, p); } } printf("%d\n", trees_count); }
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.How many trees are there in the forest?
You should output the number of trees in the forest where PolandBall lives.
C
6d940cb4b54f63a7aaa82f21e4c5b994
76a2c106cd55ff7a6b0ceee3a553ba6c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "graphs", "dsu", "interactive", "dfs and similar", "trees" ]
1484499900
["5\n2 1 5 3 3", "1\n1"]
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PASSED
1,300
standard input
1 second
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id. It's guaranteed that the sequence p corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer n (1 ≀ n ≀ 104)Β β€” the number of Balls and the integer m (0 ≀ m &lt; n)Β β€” the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows: 5 31 23 44 5
["2", "1"]
#include<stdio.h> int main() { int n, num, end = 0, label = 0; int gg[10010]; int cheak[10010]; scanf("%d", &n); int i, j; for (i = 0; i < n; i++)gg[i] = i; for (i = 0; i < n; i++) { scanf("%d", &num); for (int j = 0; j < i; j++) { if (gg[j] == gg[i])gg[j] = gg[num - 1]; } gg[i] = gg[num - 1]; } for (i = 0; i < n; i++) { for (j = 0; j < end; j++) { if (cheak[j] == gg[i]) { label = 1; break; } } if (label == 0) { cheak[j] = gg[i]; end++; } label = 0; } printf("%d\n", end); for (i = 0; i < n; i++) { gg[i] = i; cheak[i] = 0; } end = 0; label = 0; return 0; }
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.How many trees are there in the forest?
You should output the number of trees in the forest where PolandBall lives.
C
6d940cb4b54f63a7aaa82f21e4c5b994
15625fe77e6535ec6b5e035fff291836
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "graphs", "dsu", "interactive", "dfs and similar", "trees" ]
1484499900
["5\n2 1 5 3 3", "1\n1"]
NoteIn the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall.In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
PASSED
1,300
standard input
1 second
The first line contains single integer n (1 ≀ n ≀ 104)Β β€” the number of Balls living in the forest. The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≀ pi ≀ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id. It's guaranteed that the sequence p corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer n (1 ≀ n ≀ 104)Β β€” the number of Balls and the integer m (0 ≀ m &lt; n)Β β€” the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows: 5 31 23 44 5
["2", "1"]
#include <limits.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 11111 typedef struct _list{ int v; struct _list *next; } list; list *g[N]; int cnt, n, a, b; bool vis[N]; void pushg(int u, int v){ list *ptr=(list *) malloc(sizeof(list)); ptr->v=v; ptr->next=g[u]; g[u]=ptr; } void dfs(int v){ vis[v]=true; for (list *a=g[v]; a; a=a->next) if (!vis[a->v]) dfs(a->v); } int main(){ scanf("%d", &n); for (a=1; a<=n; a++) scanf("%d", &b), pushg(a, b), pushg(b, a); for (a=1; a<=n; a++) if (!vis[a]) cnt++, dfs(a); printf("%d\n", cnt); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
ae0eb3984e197d99e9d6b7f3ebe56cb9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> #include<string.h> int main() { char num1[100010]={0},num2[100010]={0}; long long n,i,count=0,a=0,b=0,c=0,d=0; scanf("%lld",&n); scanf("%s",num1); scanf("%s",num2); for(i=0;i<n;i++) { if(num1[i]=='1' && num2[i]=='1') a++; else if(num1[i]=='0' && num2[i]=='0') b++; else if(num1[i]=='1' && num2[i]=='0') c++; else if(num1[i]=='0' && num2[i]=='1') d++; } count=(b*(a+c))+(c*d); printf("%lld",count); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
6bc4082542f2f7904cc336b8e35af1e8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> int main(){ int n; scanf("%d",&n); char o,a[n+1],b[n+1]; int i; scanf("%c",&o); gets(a); gets(b); long long int y=0,z=0,yx=0,zx=0; for(i=0;i<n;i++){ if(a[i]=='0'){ y++; if(b[i]=='0') yx++; } else{ z++; if(b[i]=='0') zx++; } } printf("%I64d",yx*z+zx*(y-yx)); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
44f7d466e43f175642d93a1a3815b560
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int fun() { char c = getchar(); while(c != '0' && c != '1') { c = getchar(); } return (c-'0'); } int main() { long long a=0, b=0, c=0, d=0; int arr[100003]; int num; scanf("%d", &num); for (int i = 0; i < num; i++) { arr[i] = fun(); } for (int i = 0; i < num; i++) { int m ; m = fun(); if(m ==1 && arr[i] == 1) a++; else if(m == 1 && arr[i] == 0) c++; else if (m == 0 && arr[i] == 0) d++; else b++; } printf("%lld", a*d +c*b + b*d); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
51cfe03627e8ffd3bf1c1b5be7f2e562
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> #define ll long long int main() { ll n, z = 0, o = 0, res = 0, i, cnt = 0; scanf("%lld", &n); char a[n+2], b[n+2]; scanf("%s %s", a, b); for(i = 0; i < strlen(b); i++) { if(a[i] == '1')o++; else z++; } for(i = 0; i < n; i++) { if(b[i] == '0' && a[i] == '0'){res += o;cnt++;} } z -= cnt; for(i = 0; i < n; i++) { if(b[i] == '0' && a[i] == '1')res += z; } printf("%lld\n", res); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
987c395348fcd3d8e3fe06a4b78c39fc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main() { long long int n, z = 0, o = 0, res = 0, i, cnt = 0; scanf("%lld", &n); char a[n+2], b[n+2]; scanf("%s %s", a, b); for(i = 0; i < strlen(b); i++) { if(a[i] == '1')o++; else z++; } for(i = 0; i < n; i++) { if(b[i] == '0' && a[i] == '0'){res += o;cnt++;} } z -= cnt; for(i = 0; i < n; i++) { if(b[i] == '0' && a[i] == '1')res += z; } printf("%lld\n", res); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
ac4091c7d85fd94197e5438d97f62aff
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> #include<stdlib.h> int main() { long long int i, T = 0, l1= 0, l2 = 0, l3 =0, l4 = 0, sum ; scanf("%lld", &T); char s1[110000], s2[110000]; scanf("%s %s", s1, s2); for(i = 0; i < T; i++) { if(s1[i] == '1') ++l1; if(s2[i] == '0') ++l2; if(s1[i]== '0' && s2[i] == '0') ++l3; if(s1[i]== '1' && s2[i] == '0') ++l4; } sum = (l2 - l4) * (l1 - l4) + (l2 - l3) * (T - l1); printf("%lld", sum); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
a686fb40225ff3a50a3b4db2605a7755
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main(int argc, char const *argv[]) { long long int n; scanf("%lld",&n); char m[n+1],p[n+1]; long int a[n+2],b[n+2]; long long int c=0,d=0,e=0,f=0,g=0,h=0,swp=0 ; getchar(); for (int i = 1; i <=n ;i++) { scanf("%c",&m[i]); a[i] = (( long int)m[i] -48); } getchar(); for (int i = 1; i <=n ;i++) { scanf("%lc",&p[i]); b[i] = (( long int)p[i] -48); } for ( long long int i = 1; i <=n;i++) { if (a[i]==0 && b[i]==1) { c++; } if (a[i]==1 && b[i]==0) { d++; } if (a[i]==1 && b[i]==1) { e++; } if (a[i]==0 && b[i]==0) { f++; } } swp = swp + c*d +e*f +d*f; printf("%lld\n",swp); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
4485c3fb8d19c2c55cafd5676b0a4c3e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> #include<string.h> int main() { long long int n,a1=0,a2=0,a3=0,a4=0;int i; scanf("%lld",&n); char a[1000000],b[1000000]; scanf("%s",a); scanf("%s",b); for(i=0; i<n; i++) { if(a[i]=='1')a1++; } for(i=0; i<n; i++) { if(a[i]=='0'&&b[i]=='0')a2++; if(a[i]=='1'&&b[i]=='0')a3++; if(a[i]=='0'&&b[i]=='1')a4++; } long long int ans=a1*a2+a3*a4; printf("%lld\n",ans); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
0c1b64fceab2ddb5c562b8869eca64fb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> #include<string.h> int main() { long long int n,a1=0,a2=0,a3=0,a4=0;int i; scanf("%lld",&n); char a[1000000],b[1000000]; scanf("%s",a); scanf("%s",b); for(i=0; i<n; i++) { if(a[i]=='0'&&b[i]=='0')a1++; if(a[i]=='0'&&b[i]=='1')a2++; if(a[i]=='1'&&b[i]=='0')a3++; if(a[i]=='1'&&b[i]=='1')a4++; } long long int ans=(a1*a3)+(a1*a4)+(a2*a3); printf("%lld\n",ans); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
2d9840703c0858e5d9a911a56d77e91f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main() { int n, cntA0, cntA1, cntB0, cntAll0; char strA[100001]; char strB[100001]; long long ans = 0; scanf("%d %s %s", &n, strA, strB); cntA0 = cntA1 = cntB0 = cntAll0 = 0; for(int i = 0; i < n; ++i) { if(strA[i] == '0') { if(strB[i] == '0') { ++cntAll0; } ++cntA0; } else { ++cntA1; } } for(int i = 0; i < n; ++i) { if(strB[i] == '0') { ++cntB0; if(strA[i] == '0') { ans += cntA1; } else { ans += cntA0; ans -= cntAll0; } } } printf("%I64d\n", ans); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
789bf73c25e62081bfd125e7b7c6c990
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main(){ char b[1000000], c[1000000]; long long a, zero = 0,one = 0,zerozero = 0,onezero = 0, result = 0; scanf("%lld%s%s", &a,b,c); for(int i = 0; i < a; i++){ if(b[i] == '0') zero++; if(b[i] == '0' && c[i] == '0') zerozero++; if(b[i] == '1' && c[i] == '0') onezero++; } one = a - zero; result = zero * onezero + one * zerozero - zerozero * onezero; printf("%lld", result); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
9cac43b72c7a19747d3040bbe996d653
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> #include<stdlib.h> int main() { int n; char lda,ldb; long long one=0,zero=0,ones=0,zeros=0; scanf("%d",&n); char* a=(char*)malloc((n+1)*sizeof(char)); char* b=(char*)malloc((n+1)*sizeof(char)); scanf("%s",a); scanf("%s",b); int i=0; while(a[i]!='\0') { lda=a[i]; ldb=b[i]; if(lda=='1') one++; if(lda=='0') zero++; if(ldb=='0'&&lda=='1') ones++; if(ldb=='0'&&lda=='0') zeros++; i++; } long long temp= ones*zero+zeros*one - ((ones*zeros+zeros*ones)/2); printf("%lld",temp); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
c8318afaa7a836326d0a94fc9efed644
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> int main(void) { long long int n1=0,n0=0,ans=0; int n,i,pos[100000],k=0,ex=0; scanf("%i ",&n); char a[n+5],b[n+5]; gets(a); gets(b); for(i=0;i<n;i++) { if(b[i]=='0'){pos[k]=i;k++;} if(a[i]=='0')n0++; else n1++; if(b[i]=='0'&&a[i]=='0')ex++; } for(i=0;i<k;i++) { if(a[pos[i]]=='0')ans=ans+n1; else ans=ans+n0-ex; } printf("%I64d",ans); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
ef2396dcd17990b06b30237f08e9ec27
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main() { int n; scanf("%d\n", &n); int i; int a[123450], b[123450]; long long int cone = 0, czero = 0; for (i = 0; i < n; ++i) { a[i] = getchar() - '0'; if (a[i]) ++cone; else ++czero; } getchar(); // '\n' long long int eone = 0, ezero = 0; for (i = 0; i < n; ++i) { b[i] = getchar() - '0'; if (!b[i]) { if (a[i]) ++eone; else ++ezero; } } long long int count = 0; count = eone * czero + ezero * cone - eone * ezero; printf("%I64d\n", count); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
2b58e5fceb737254369345739efcc13b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> long long int n,j; long long t1=0,t0=0,s1=0,s0=0,sum=0,i; char a[100005]; char b[100005]; int main() { scanf ("%lld",&n); scanf ("%s",a); scanf ("%s",b); for (i=0;i<n;i++) { if (a[i]=='0'&&b[i]=='0') t1++; else if (a[i]=='1'&&b[i]=='1') t0++; else if (a[i]=='0'&&b[i]=='1') s1++; else s0++; } sum=t0*t1+s0*s1+t1*s0; printf ("%lld\n",sum); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
17ab13b098f3234d7ec4a75836bc33a1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> typedef long long ll; ll nc2(ll x) { return (x*(x-1))/2; } int main() { ll n; scanf("%lld",&n); char s1[n+1],s2[n+1]; scanf("%s %s",s1,s2); ll cnt_1,cnt_0,sum; cnt_1=cnt_0=sum=0; for(ll i=0;i<n;i++) { if(s1[i]=='1') cnt_1++; if(s1[i]=='0') cnt_0++; } sum+=nc2(cnt_1); sum+=nc2(cnt_0); cnt_1=cnt_0=0; for(ll i=0;i<n;i++) { if(s2[i]=='1') { if(s1[i]=='0') cnt_0++; if(s1[i]=='1') cnt_1++; } } sum+=cnt_1*cnt_0; sum=nc2(n)-sum; printf("%lld",sum); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
88d135cc51ebf27546bf3e7f98e9e533
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main(){ unsigned comb[2][2] = { {0,0}, {0,0} },n,i; scanf("%i",&n); char a[n+1],b[n+1]; int ia,ib; scanf("%s %s",a,b); for(i = 0; i < n; i++){ ia = a[i] - '0'; ib = b[i] - '0'; comb[ia][ib]++; } printf("%u",comb[0][0]*comb[1][0]+comb[0][0]*comb[1][1]+comb[0][1]*comb[1][0]); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
aa3f3dcbd6b4124e1e7536fd379e48a2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main() { long long int i,j,k,n,l=0,m=0,o=0,p=0; scanf("%lld",&n); char a[n+1],b[n+1]; scanf("%s",a); scanf("%s",b); for(i=0;i<n;i++){ if(a[i]=='0'&&b[i]=='0') l++; else if(a[i]=='1'&& b[i]=='0') m++; else if(a[i]=='0'&& b[i]=='1' ) o++; else if(a[i]=='1'&& b[i]=='1') p++; } n=l*m+l*p+m*o; printf("%lld\n",n); }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
0fba64e64579b4299787199b4da269bc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> int main() { unsigned long n,i,count0=0,count1=0,c1=0,c0=0; scanf("%lu",&n); char a[n+1],b[n+1]; scanf("%s%s",a,b); for (i=n;i>0;i--) { if (b[i-1]=='1') (a[i-1]=='0')?count0++:count1++; else (a[i-1]=='1')?c1++:c0++; } printf("%lu",count0*c1+count1*c0+c0*c1); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
59ca62bbb4e2e03809280b18a7bd6e8d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> int main() { int n; scanf("%d",&n); long long zeroone=0,onezero=0,zz=0,one=0; char a[n+1],b[n+1]; scanf("%s%s",a,b); a[n]='\0'; b[n]='\0'; for(int i=0;i<n;i++) { if(a[i]=='0'&&b[i]=='1') zeroone++; if(a[i]=='1'&&b[i]=='0') onezero++; if(a[i]=='0'&&b[i]=='0') zz++; if(a[i]=='1') one++; } //printf("%lld %lld %lld %lld",zeroone,onezero,zz,one); long long r=(one*zz)+(zeroone*onezero); printf("%lld",r); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
af18f17820e1e658ea196f55cc9a889a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main () { int n; scanf ("%d", &n); char a[100000] = {0}, b[100000] = {0}; scanf ("%s%s", a, b); long long d = 0; long long z00 = 0, z01 = 0, z10 = 0, z11 = 0; for (int i = 0; i < n; i++) { if (a[i] - '0') { if (b[i] - '0') z11++; else z10++; } else { if (b[i] - '0') z01++; else z00++; } } #ifdef mai printf ("00:%d 01:%d 10:%d 11:%d\n", z00, z01, z10, z11); #endif // mai if (z11 + z01 == n || z10 + z11 == n || z01 + z00 == n) { printf ("0"); return 0; } if (z11) d += z00*z11; if (z10) { d += z00*z10; if (z01) d+=z10*z01; } printf ("%I64d", d); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
df759f83b11e2e8a4e6e97124646be60
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include<stdio.h> int main() { long long int i,s=0,m=0,k=0,l=0,n,num=0; scanf("%lld",&num); char a[100050],b[100050]; scanf("%s%s",&a,&b); for(i=0;i<num;i++) { if(a[i]=='1') ++s; if(b[i]=='0') ++m; if(a[i]=='0'&&b[i]=='0') ++k; if(a[i]=='1'&&b[i]=='0') ++l; } n=(m-l)*(s-l)+(m-k)*(num-s); printf("%lld",n); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
fbc277259a07aa81eb44f0df6eba43f8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> #include <stdlib.h> int main() { unsigned long n; scanf("%lu",&n); char a[n+1],b[n+1]; scanf("%s",a); scanf("%s",b); unsigned long a0=0,a1=0,b0c=0,b1c=0; for(unsigned long i=0;i<n;i++){ (a[i]=='0')?a0++:a1++; if(b[i]=='0'){ (a[i]=='0')?b0c++:b1c++; } } unsigned long x=b0c*a1+b1c*a0-b1c*b0c; printf("%lu",x); return 0; }
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:Given two binary numbers $$$a$$$ and $$$b$$$ of length $$$n$$$. How many different ways of swapping two digits in $$$a$$$ (only in $$$a$$$, not $$$b$$$) so that bitwise OR of these two numbers will be changed? In other words, let $$$c$$$ be the bitwise OR of $$$a$$$ and $$$b$$$, you need to find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will not be equal to $$$c$$$.Note that binary numbers can contain leading zeros so that length of each number is exactly $$$n$$$.Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, $$$01010_2$$$ OR $$$10011_2$$$ = $$$11011_2$$$.Well, to your surprise, you are not Rudolf, and you don't need to help him$$$\ldots$$$ You are the security staff! Please find the number of ways of swapping two bits in $$$a$$$ so that bitwise OR will be changed.
Print the number of ways to swap two bits in $$$a$$$ so that bitwise OR will be changed.
C
621c82478be3dadcf60c383ba078a49e
8af5d848e836a8b9b3dc91eaa5d81e33
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "math" ]
1533737100
["5\n01011\n11001", "6\n011000\n010011"]
NoteIn the first sample, you can swap bits that have indexes $$$(1, 4)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, and $$$(3, 5)$$$.In the second example, you can swap bits that have indexes $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 4)$$$, $$$(3, 4)$$$, $$$(3, 5)$$$, and $$$(3, 6)$$$.
PASSED
1,200
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$2\leq n\leq 10^5$$$)Β β€” the number of bits in each number. The second line contains a binary number $$$a$$$ of length $$$n$$$. The third line contains a binary number $$$b$$$ of length $$$n$$$.
["4", "6"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int x,y,z; long long sum,fr[4],n,i; char a[100001],b[100001]; int main() { scanf("%d %s %s",&n,a,b); for(i=0;i<n;i++) { x=a[i]-'0'; y=b[i]-'0'; if(x==0 && y==1) z=-1; else z=x+y; fr[z+1]++; } sum=fr[0]*fr[2]+fr[1]*fr[2]+fr[1]*fr[3]; printf("%I64d",sum); return 0; }
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
C
b5f5fc50e36b2afa3b5f16dacdf5710b
0241f74cd04ce7bd329b13a345e4f6a3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
1304175600
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
PASSED
1,800
standard input
2 seconds
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
["12 4", "0 0", "5 5"]
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN 100055 #define MAXM 15 struct node { char s[MAXM]; int len; }; int main () { static char s[MAXN]; memset(s,0,sizeof(s)); scanf("%s\n",s); int N = strlen(s); int M; scanf("%d\n",&M); static struct node data[MAXM]; int i; for (i = 0; i < M; i++) { scanf("%s\n",data[i].s); data[i].len = strlen(data[i].s); } int res = 0; int resw = 0; int min = N; int j, k, temp; char flag; for (i = N-1; i >= 0; i--) { for (j = 0; j < M; j++) { flag = 1; for (k = 0; k < data[j].len; k++) { if (s[i+k] != data[j].s[k]) { flag = 0; break; } } if (flag) { temp = i + data[j].len - 1; if (temp < min) min = temp; } } temp = min - i; if (temp > res) { res = temp; resw = i; } } printf("%d %d\n",res,resw); return 0; }
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
C
b5f5fc50e36b2afa3b5f16dacdf5710b
ce17f8aa1ad9f619221ff360be4e63b4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
1304175600
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
PASSED
1,800
standard input
2 seconds
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
["12 4", "0 0", "5 5"]
#include <stdio.h> #include <string.h> int max(int a, int b) { if (a > b) { return a; } else { return b; } } int main() { int n, l = 0, p = 0, m = 0, i, j, k; char s[100001], b[10][11]; int c[10]; scanf("%s", s); scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s", b[i]); for (i = 0; i < n; i++) c[i] = strlen(b[i]); for (i = 0; i < strlen(s) - l; i++) { for (j = 0; i + j < strlen(s); j++) { int f = 0; for (k = 0; k < n; k++) { if (j < c[k] - 1) continue; if (strncmp(&s[i + j + 1 - c[k]], b[k], c[k]) == 0) { f = 1; m = c[k]; break; } } if (f == 1) { if (j > l) { l = j; p = i; } i = max(i, i + j - m + 1); break; } } if (i + j == strlen(s)) { if (j > l) { l = j; p = i; } } } printf("%d %d\n", l, p); return 0; }
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
C
b5f5fc50e36b2afa3b5f16dacdf5710b
d92a25f9dbbde539cfd0d1ca89137b5a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
1304175600
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
PASSED
1,800
standard input
2 seconds
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
["12 4", "0 0", "5 5"]
#include<stdio.h> #include<string.h> #define MAX 100032 int main(void){ char str[MAX],c,hate[16]; int i,j,k,n,lstr,pstr,maxlen=0,len,maxp,p,sub,count,check[MAX]={0}; fgets(str,sizeof(str)/sizeof(char),stdin); lstr=strlen(str); //printf("%d\n",lstr); scanf("%d",&n); for(i=0;i<n;i++){ scanf("%s%*c",hate); pstr=strlen(hate); //printf("%d\n",pstr); for(j=0;j<lstr-pstr;j++){ if(str[j]==hate[0]){ count=1; for(k=j+1;k<j+pstr;k++){ if(str[k]==hate[k-j]) count++; else break; } if(count==pstr && (!check[j] || check[j]>pstr)) check[j]=pstr; } } } len=0; //for(i=0;i<lstr-1;i++) printf("%d ",check[i]); //putchar('\n'); for(i=lstr-2;i>=0;i--){ len++; if(check[i] && len>check[i]-1) len=check[i]-1; if(maxlen<=len){ maxlen=len; maxp=i; } } printf("%d %d\n",maxlen,maxp); return 0; }
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
C
b5f5fc50e36b2afa3b5f16dacdf5710b
3806278cf593afbde707928e781b53c5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
1304175600
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
PASSED
1,800
standard input
2 seconds
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
["12 4", "0 0", "5 5"]
#include<stdio.h> #include<stdlib.h> #include<math.h> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) int get_len(char a[]){ int i; for(i=0;;i++) if(a[i]<' ') break; return i; } int is_same(char a[],char b[],int len){ int i; rep(i,len) if(a[i]!=b[i]) return 0; return 1; } int n; char in[111110]; int len; char dic[12][122]; int dic_len[12]; int res1, res2; int main(){ int i,j,k,l,m; int st, ed; while(scanf("%s%d",in,&n)==2){ res1 = res2 = 0; rep(i,n) scanf("%s",dic[i]); len = get_len(in); rep(i,n) dic_len[i] = get_len(dic[i]); st = 0; rep(ed,len){ rep(i,n){ if(ed-st+1 < dic_len[i]) continue; if(!is_same(dic[i],in+ed-dic_len[i]+1,dic_len[i])) continue; st = ed-dic_len[i]+2; } if(ed-st+1 > res1){ res1 = ed-st+1; res2 = st; } } printf("%d %d\n",res1,res2); } return 0; }
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.
C
b5f5fc50e36b2afa3b5f16dacdf5710b
f1b390bf1d489aa0f8637344418094ad
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "hashing", "greedy", "two pointers", "data structures", "strings" ]
1304175600
["Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "unagioisii\n2\nioi\nunagi"]
NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be Β«0 0Β», Β«0 1Β», Β«0 2Β», and so on.In the third sample, the solution is either nagio or oisii.
PASSED
1,800
standard input
2 seconds
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≀ n ≀ 10). Next n lines, there is a string bi (1 ≀ i ≀ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.
["12 4", "0 0", "5 5"]
#include <stdio.h> #define MAX 100010 int match[MAX], n, m, l, i, j, ok, len, pos; char str[MAX], buf[11]; int main() { scanf( "%s%d", str, &m ); while(str[n]) n++; while(m--) { scanf( "%s", buf ); for( l = 0; buf[l]; l++ ); for( i = 0; i + l <= n; i++ ) { ok = 1; for( j = 0; j < l; j++ ) if( str[i+j] != buf[j] ) ok = 0; if( ok && ( !match[i] || match[i] > l ) ) match[i] = l; } } l = 0; for( i = n-1; i >= 0; i-- ) { l++; if( match[i] && match[i] - 1 < l ) l = match[i] - 1; if( l >= len ) { len = l; pos = i; } } printf( "%d %d\n", len, pos ); return 0; }
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
C
6cf43241b14e4d41ad5b36572f3b3663
816bdde9031eeecdb278ffbd26cd02ed
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "graphs" ]
1481992500
["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3"]
NoteFor the first sample test, the graph looks like this: Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.For the second sample test, the graph looks like this: We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.
PASSED
1,500
standard input
2 seconds
The first line of input will contain three integers n, m and k (1 ≀ n ≀ 1 000, 0 ≀ m ≀ 100 000, 1 ≀ k ≀ n)Β β€” the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain k integers c1, c2, ..., ck (1 ≀ ci ≀ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world. The following m lines of input will contain two integers ui and vi (1 ≀ ui, vi ≀ n). This denotes an undirected edge between nodes ui and vi. It is guaranteed that the graph described by the input is stable.
["2", "0"]
#include <stdio.h> #include <string.h> int c[1005], p[1005], sz[1005], gov[1005]; int find_parent(int n) { if (p[n] == n) return n; return p[n] = find_parent(p[n]); } int get_full_size(int n) { return n * (n-1) / 2; } int main(int argc, char** argv) { int i, n, m, k, u, v, max_size, total_free, used, total_edge; scanf("%d%d%d", &n, &m, &k); for (i = 0; i < k; i++) scanf("%d", &c[i]); for (i = 1; i <= n; i++) { p[i] = i; sz[i] = 1; } for (i = 0; i < m; i++) { scanf("%d%d", &u, &v); if (find_parent(u) != find_parent(v)) { sz[p[v]] += sz[p[u]]; sz[p[u]] = 0; p[p[u]] = p[v]; } } memset(gov, 0, sizeof gov); max_size = 0; for (i = 0; i < k; i++) { c[i] = find_parent(c[i]); gov[c[i]] = 1; if (sz[c[i]] > max_size) max_size = sz[c[i]]; } total_free = 0; for (i = 1; i <= n; i++) if (!gov[i]) total_free += sz[i]; used = 0; total_edge = 0; for (i = 0; i < k; i++) { if (sz[c[i]] == max_size && !used) { total_edge += get_full_size(max_size+total_free); used = 1; } else total_edge += get_full_size(sz[c[i]]); } printf("%d\n", total_edge - m); return 0; }
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
C
6cf43241b14e4d41ad5b36572f3b3663
b51b1b60e2dd2a316e999a54b257725b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "graphs" ]
1481992500
["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3"]
NoteFor the first sample test, the graph looks like this: Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.For the second sample test, the graph looks like this: We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.
PASSED
1,500
standard input
2 seconds
The first line of input will contain three integers n, m and k (1 ≀ n ≀ 1 000, 0 ≀ m ≀ 100 000, 1 ≀ k ≀ n)Β β€” the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain k integers c1, c2, ..., ck (1 ≀ ci ≀ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world. The following m lines of input will contain two integers ui and vi (1 ≀ ui, vi ≀ n). This denotes an undirected edge between nodes ui and vi. It is guaranteed that the graph described by the input is stable.
["2", "0"]
#include<stdio.h> typedef long long unsigned llu; typedef unsigned u; u G[1111][1111],Gi[1111],V[1111],S[1111]; u D(u n) { if(V[n])return 0;u i,j=V[n]=1; for(i=Gi[n];i--;)j+=D(G[n][i]); return j; } int main() { u n,q,x,i=-1,j,k,e=0; for(scanf("%u%u%u",&n,&q,&x);++i<x;)scanf("%u",S+i); for(i=-1;++i<q;) { scanf("%u%u",&j,&k); G[j][Gi[j]++]=k; G[k][Gi[k]++]=j; } for(k=0;x--;e+=j*(j-1)>>1)k=k<(j=D(S[x]))?j:k; for(i=j=0;i++<n;)if(!V[i])e+=j++; printf("%u\n",e+k*j-q); return 0; }
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
C
6cf43241b14e4d41ad5b36572f3b3663
f75aac374b0dd7589c7e5913f3eadee0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "graphs" ]
1481992500
["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3"]
NoteFor the first sample test, the graph looks like this: Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.For the second sample test, the graph looks like this: We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.
PASSED
1,500
standard input
2 seconds
The first line of input will contain three integers n, m and k (1 ≀ n ≀ 1 000, 0 ≀ m ≀ 100 000, 1 ≀ k ≀ n)Β β€” the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain k integers c1, c2, ..., ck (1 ≀ ci ≀ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world. The following m lines of input will contain two integers ui and vi (1 ≀ ui, vi ≀ n). This denotes an undirected edge between nodes ui and vi. It is guaranteed that the graph described by the input is stable.
["2", "0"]
#ifdef ONLINE_JUDGE #define NDEBUG 1 #endif #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <limits.h> #include <string.h> #ifndef __cplusplus typedef int8_t bool; #define true 1 #define false 0 #endif #define long int64_t #define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i) #define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i) #define LIST_INIT_CAP 1024 #define HASH_INIT_CAP 1024 #define MAP_INIT_CAP 1024 #define TREE_INIT_CAP 1024 #define DEQUE_INIT_CAP 1024 #define HASH_SKIP 31 #define MAP_MAX_HEIGHT 32 #define TREE_MAX_HEIGHT 64 #define TAKEN 1 #define EMPTY 0 #define TOMB -1 #define max(a,b) (((a)>(b))?(a):(b)) bool city[1001] = { 0 }; bool graph[1001][1001] = { 0 }; bool visited[1001] = { 0 }; int n; int dfs(int node) { if (visited[node]) return 0; visited[node] = true; int count = 1; fore(i, 1, n) { if (graph[node][i]) count += dfs(i); } return count; } int main() { int m, k; scanf("%d %d %d", &n, &m, &k); fore(i, 1, k) { int c; scanf("%d", &c); city[c] = true; } fore(i, 1, m) { int u, v; scanf("%d %d", &u, &v); graph[u][v] = graph[v][u] = true; } int maxgroup = 0; int cumnodes = 0; int answer = 0; fore(i, 1, n) { int size = 0; if (city[i]) size = dfs(i); maxgroup = max(maxgroup, size); cumnodes += size; answer += (size * (size - 1)) / 2; } answer -= (maxgroup * (maxgroup - 1)) / 2; cumnodes = n - cumnodes + maxgroup; answer += (cumnodes * (cumnodes - 1)) / 2; answer -= m; printf("%d\n", answer); return 0; }
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
C
6cf43241b14e4d41ad5b36572f3b3663
ae2a5431b429a8bba259a09a5356fc8a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "graphs" ]
1481992500
["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3"]
NoteFor the first sample test, the graph looks like this: Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.For the second sample test, the graph looks like this: We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.
PASSED
1,500
standard input
2 seconds
The first line of input will contain three integers n, m and k (1 ≀ n ≀ 1 000, 0 ≀ m ≀ 100 000, 1 ≀ k ≀ n)Β β€” the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain k integers c1, c2, ..., ck (1 ≀ ci ≀ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world. The following m lines of input will contain two integers ui and vi (1 ≀ ui, vi ≀ n). This denotes an undirected edge between nodes ui and vi. It is guaranteed that the graph described by the input is stable.
["2", "0"]
#include<stdio.h> int parentOf(int parent[],int root) { if(parent[root]==-1) return root; else return parentOf(parent,parent[root]); } int max(int size[],int i,int j) { if(size[i]>size[j]) return i; else return j; } int main() { int n,m,k; scanf("%d %d %d",&n,&m,&k); int parent[n+1],special[n+1],size[n+1],i,temp,src,dest,parent_src,parent_dest,max_root,res=0; parent[0]=0; special[0]=-1; size[0]=0; for(i=1;i<n+1;i++) { parent[i]=-1; special[i]=0; size[i]=1; } for(i=0;i<k;i++) { scanf("%d",&temp); special[temp]=1; } max_root=temp; for(i=0;i<m;i++) { scanf("%d %d",&src,&dest); parent_src=parentOf(parent,src); parent_dest=parentOf(parent,dest); if(parent_dest!=parent_src) { if(special[parent_src]==0 && special[parent_dest]==0) { parent[parent_dest]=parent_src; size[parent_src]=size[parent_src]+size[parent_dest]; size[parent_dest]=0; } else if(special[parent_src]==1 && special[parent_dest]==0) { parent[parent_dest]=parent_src; size[parent_src]=size[parent_src]+size[parent_dest]; size[parent_dest]=0; max_root=max(size,max_root,parent_src); } else if(special[parent_dest]==1 && special[parent_src]==0) { parent[parent_src]=parent_dest; size[parent_dest]=size[parent_dest]+size[parent_src]; size[parent_src]=0; max_root=max(size,max_root,parent_dest); } } } for(i=1;i<n+1;i++) { if(special[i]==0) { size[max_root]=size[max_root]+size[i]; size[i]=0; } } for(i=1;i<n+1;i++) { if(size[i]!=0) res=res+((size[i]*(size[i]-1))/2); } printf("%d\n",res-m); return 0; }
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
C
6cf43241b14e4d41ad5b36572f3b3663
b2561f27643d81c0d2a395a237d4ee0c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "graphs" ]
1481992500
["4 1 2\n1 3\n1 2", "3 3 1\n2\n1 2\n1 3\n2 3"]
NoteFor the first sample test, the graph looks like this: Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.For the second sample test, the graph looks like this: We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.
PASSED
1,500
standard input
2 seconds
The first line of input will contain three integers n, m and k (1 ≀ n ≀ 1 000, 0 ≀ m ≀ 100 000, 1 ≀ k ≀ n)Β β€” the number of vertices and edges in the graph, and the number of vertices that are homes of the government. The next line of input will contain k integers c1, c2, ..., ck (1 ≀ ci ≀ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world. The following m lines of input will contain two integers ui and vi (1 ≀ ui, vi ≀ n). This denotes an undirected edge between nodes ui and vi. It is guaranteed that the graph described by the input is stable.
["2", "0"]
#include <stdio.h> #include <string.h> int n,m,k,sv[1010],se[1010],c[1010],vis[1010],map[1010][1010],d[1010]; void dfs(int u,int *sumv,int *sume); int main(void) { //freopen("nation.in","r",stdin); //freopen("nation.out","w",stdout); scanf("%d%d%d",&n,&m,&k); int i; for(i=1;i<=k;i++) scanf("%d",&c[i]); memset(map,0,sizeof(map)); memset(d,0,sizeof(d)); int u,v; for(i=1;i<=m;i++) { scanf("%d%d",&u,&v); map[u][v]=map[v][u]=1; d[u]++; d[v]++; } memset(vis,0,sizeof(vis)); int ans=0,t=0; sv[0]=0; for(i=1;i<=k;i++) { sv[i]=se[i]=0; dfs(c[i],&sv[i],&se[i]); se[i]/=2; ans+=sv[i]*(sv[i]-1)/2-se[i]; if(sv[i]>sv[t]) t=i; } int cnt=0; for(i=1;i<=n;i++) if(!vis[i]) { cnt++; sv[k+cnt]=se[k+cnt]=0; dfs(i,&sv[k+cnt],&se[k+cnt]); se[k+cnt]/=2; ans+=sv[k+cnt]*(sv[k+cnt]-1)/2-se[k+cnt]; } for(i=1;i<=cnt;i++) { ans+=sv[t]*sv[k+i]; sv[t]+=sv[k+i]; } printf("%d\n",ans); return 0; } void dfs(int u,int *sumv,int *sume) { vis[u]=1; (*sumv)++; (*sume)+=d[u]; int v; for(v=1;v<=n;v++) if( map[u][v] && !vis[v] ) dfs(v,sumv,sume); }
Offering the ABBYY Cup participants a problem written by the Smart Beaver is becoming a tradition. He proposed the following problem.You are given a monochrome image, that is, an image that is composed of two colors (black and white). The image is given in raster form, that is, as a matrix of pixels' colors, and the matrix's size coincides with the size of the image.The white color on the given image corresponds to the background. Also, the image contains several black geometric shapes. It is known that the image can contain only two types of shapes: squares and circles. Your task is to count the number of circles and the number of squares which the given image contains.The squares on the image can be rotated arbitrarily. In addition, the image can possibly contain some noise arranged as follows: each pixel of the original image can change its color to the opposite with the probability of 20%. An example of an image that has no noise and the sides of the squares are parallel to the coordinate axes (two circles and three squares). An example of an image that has no noise and the squares are rotated arbitrarily (two circles and three squares). An example of an image that has noise and the squares are rotated arbitrarily (one circle and three squares).
Print exactly two integers, separated by a single space β€” the number of circles and the number of squares in the given image, correspondingly.
C
06c7699523a9f8036330857660c0687e
ee23c39cdc2d96f13b62a994683f1a59
GNU C
standard output
256 megabytes
train_001.jsonl
[]
1335614400
[]
NoteYou are given a sample of original data for each difficulty level. The samples are available at http://codeforces.ru/static/materials/contests/178/e-samples.zip .
PASSED
1,900
standard input
5 seconds
The first input line contains a single integer n (1000 ≀ n ≀ 2000), which is the length and the width of the original image. Next n lines describe the matrix of colors of the image pixels. The i-th line contains exactly n integers aij (0 ≀ aij ≀ 1), separated by spaces. Value of aij = 0 corresponds to a white pixel and aij = 1 corresponds to a black one. It is guaranteed that the lengths of the sides of the squares and the diameters of the circles in the image are at least 15 pixels, and the distance between any two figures is at least 10 pixels. It is also guaranteed that a human can easily calculate the number of circles and squares in the original image. The total number of figures in the image doesn't exceed 50. The input limitations for getting 20 points are: These test cases have no noise and the sides of the squares are parallel to the coordinate axes. The input limitations for getting 50 points are: These test cases have no noise, but the squares are rotated arbitrarily. The input limitations for getting 100 points are: These test cases have noise and the squares are rotated arbitrarily.
[]
#include <stdio.h> int a[2002][2002]; void dfs(int x, int y) { if (a[x][y] == 0) return; a[x][y] = 0; dfs(x, y + 1); dfs(x, y - 1); dfs(x + 1, y); } int main() { int n, b = 0, c = 0, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &a[i + 1][j + 1]); } } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (a[i][j] == 1) { if (a[i][j + 1] == 0) { b++; } else { c++; } dfs(i, j); } } } printf("%d %d\n", b, c); return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
c318ab0f1d4d8c322b29eb770b8e153e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include <stdio.h> int main(void) { int i,ac=0,bc=0; char a[1005],b[1005]; gets(a); gets(b); i=0; while(a[i]!=NULL) { if(a[i]=='1') ac++; i++; } i=0; while(b[i]!=NULL) { if(b[i]=='1') bc++; i++; } if((ac>=bc)||(ac%2!=0&&bc-ac==1)) { printf("YES"); } else printf("NO"); return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
55254c29ff1116a8088ba03f1a6de09e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #include<string.h> main() { char a[1001],b[1001]; scanf("%s%s",a,b); int no_one=0,no_of_one=0,i; for(i=0;i<strlen(a);i++) { if(a[i]=='1') no_of_one++; } for(i=0;i<strlen(b);i++) { if(b[i]=='1') no_one++; } if(no_of_one%2==0) { if(no_one<=no_of_one) printf("YES"); else printf("NO"); } else { if(no_one<=no_of_one+1) printf("YES"); else printf("NO"); } return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
5dbad053a07a2412e9971708a897e619
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include <stdio.h> #include <string.h> #include <math.h> int main (){ char a[10000], b[10000]; int m=0, n=0, i; scanf ("%s %s", a, b); for (i=0;a[i]!='\0';i++) { if (a[i]==49){ m++; } } for (i=0;b[i]!='\0';i++) { if (b[i]==49){ n++; } } if (m>=n){ printf("YES\n"); } else if ( m<n && m%2==0){ if (n==m || n==(m-1)){ printf("YES\n"); } else { printf("NO\n"); } } else if (m<n && m%2==1) { if (n==m || n==(m+1)){ printf("YES\n"); } else { printf("NO\n"); } } return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
11f6c0e6f179b4ab34daa27561841cda
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #define MAX_L 1005 char iput[MAX_L], oput[MAX_L]; int main () { int i, nri, nro; scanf("%s", &iput); scanf("%s", &oput); i = 0; nri = 0; while(iput[i] != 0) { if(iput[i] - '0' == 1) { nri++; } //printf("%d", iput[i] - '0'); i++; } i = 0; nro = 0; while(oput[i] != 0) { if(oput[i] - '0' == 1) { nro++; } //printf("%d", oput[i] - '0'); i++; } if(nri % 2 == 1) { nri++; } if(nri >= nro) { printf("YES"); } else { printf("NO"); } return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
f93cc32f484f22bdc47c34c8aefe037b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> int main() { int i,cnta=0,cntb=0; char a[1001],b[1001]; scanf("%s%s",a,b); for(i=0;a[i]!='\0';i++) if(a[i]=='1')cnta++; for(i=0;b[i]!='\0';i++) if(b[i]=='1')cntb++; if(cnta&1) { if(cntb<=cnta+1) printf("YES"); else printf("NO"); } else { if(cntb<=cnta)printf("YES"); else printf("NO"); } return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
fab82049c18485d9608bca971252c5a6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #include<string.h> char a[1100]; char b[1100]; int main() { scanf("%s", a); scanf("%s", b); int alen = strlen(a); int blen = strlen(b); int aone = 0, bone = 0; int i; for(i = 0; i < alen; i++) { if(a[i] == '1') aone ++; } for(i = 0; i < blen; i++) { if(b[i] == '1') bone ++; } if(aone >= bone || (aone % 2 == 1 && aone == bone - 1)) printf("YES\n"); else printf("NO\n"); }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
d18a0bd850852ef39a6073b6a1c0ed93
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #include<string.h> int main() { int i,q1,q2; char a[1100],b[1100]; scanf("%s",a); scanf("%s",b); q1=0;q2=0; for(i=0;a[i]!=0;i++) if(a[i]=='1') q1++; for(i=0;b[i]!=0;i++) if(b[i]=='1') q2++; if(q1%2==1) q1++; if(q1<q2) printf("NO\n"); else printf("YES\n"); return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
6b9121bfd813adb2d025154830287e49
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #include<string.h> main() { char a[1002],b[1002]; int i,aone=0,bone=0; scanf("%s",a); scanf("%s",b); for(i=0;i<strlen(a);i++) if(a[i]=='1') aone++; for(i=0;i<strlen(b);i++) if(b[i]=='1') bone++; if(aone%2) aone++; if(aone>=bone) printf("YES"); else printf("NO"); return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
8114deb04667b921308bde8e09faba88
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #include<string.h> int main() { char str[1001]={'\0'},str2[1001]={'\0'}; gets(str); gets(str2); int i,a=0,b=0; for(i=0;str[i]!='\0';i++) { if(str[i]=='1') a++; } for(i=0;str2[i]!='\0';i++) { if(str2[i]=='1') b++; } if(a%2!=0) a++; if(b>a) printf("NO"); else printf("YES"); return 0; }
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to the end of a. For example, . Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.
C
cf86add6c92fa8a72b8e23efbdb38613
e357ab67f9079e08886a22272646345a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms" ]
1366385400
["01011\n0110", "0011\n1110"]
NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110
PASSED
1,700
standard input
1 second
The first line contains the string a and the second line contains the string b (1 ≀ |a|, |b| ≀ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.
["YES", "NO"]
#include<stdio.h> #include<string.h> int main() { char str[1001]={'\0'},str2[1001]={'\0'}; gets(str); gets(str2); int i,a=0,b=0; for(i=0;str[i]!='\0';i++) { if(str[i]=='1') a++; } for(i=0;str2[i]!='\0';i++) { if(str2[i]=='1') b++; } a=a+(a&1); if(b>a) printf("NO"); else printf("YES"); return 0; }
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β€” he wants to reach level n + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
C
6264405c66b2690ada9f8cc6cff55f0b
fd87fc2d888f87b14e9f0df5ce16e2ce
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1474119900
["3", "2", "4"]
NoteIn the first sample case:On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14Β·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16Β·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46Β·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10Β·3 = 36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998Β·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000Β·2 = 9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
PASSED
1,600
standard input
2 seconds
The first and only line of the input contains a single integer n (1 ≀ n ≀ 100 000), denoting that ZS the Coder wants to reach level n + 1.
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
#include<stdio.h> #include<math.h> int main() { long long level, i; scanf("%I64d",&level); printf("2\n"); if(level == 1) return 0; for(i=2; i<=level; i++) printf("%I64d\n", (i*(i+1)*(i+1))-i+1); return 0; }
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β€” he wants to reach level n + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
C
6264405c66b2690ada9f8cc6cff55f0b
e903aebeac6dbb667b8b5a4d1b6960b6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1474119900
["3", "2", "4"]
NoteIn the first sample case:On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14Β·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16Β·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46Β·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10Β·3 = 36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998Β·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000Β·2 = 9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
PASSED
1,600
standard input
2 seconds
The first and only line of the input contains a single integer n (1 ≀ n ≀ 100 000), denoting that ZS the Coder wants to reach level n + 1.
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
#include<stdio.h> #include<math.h> int main() { long long int level, i, k; scanf("%I64d",&level); printf("2"); if(level == 1) return 0; puts(""); for(i=2; i<level; i++) { k = i*(i+1)*(i+1)-i+1; printf("%I64d\n", k); } if(level == 1000000) k = 1000001000002; else k = i*(i+1)*(i+1)-i+1; printf("%I64d", k); return 0; }
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β€” he wants to reach level n + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
C
6264405c66b2690ada9f8cc6cff55f0b
41f8abe4e05f9b7354177af5f6a63b2f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1474119900
["3", "2", "4"]
NoteIn the first sample case:On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14Β·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16Β·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46Β·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10Β·3 = 36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998Β·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000Β·2 = 9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
PASSED
1,600
standard input
2 seconds
The first and only line of the input contains a single integer n (1 ≀ n ≀ 100 000), denoting that ZS the Coder wants to reach level n + 1.
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
#include<stdio.h> int main(void){ long long f=2,n,i,j,k,calc; scanf("%I64d",&n); for(i=1;i<=n;i++){ calc=i*(i+1)*(i+1)-f/i; printf("%I64d\n",calc); f=i*(i+1); } return 0; }
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can : Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the gameΒ β€” he wants to reach level n + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.
Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level i. Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
C
6264405c66b2690ada9f8cc6cff55f0b
9e77a28ff5efc50a8c1e7eea13591b77
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1474119900
["3", "2", "4"]
NoteIn the first sample case:On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14Β·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16Β·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46Β·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10Β·3 = 36, and when the '' button is pressed, the number becomes and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998Β·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000Β·2 = 9Β·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.
PASSED
1,600
standard input
2 seconds
The first and only line of the input contains a single integer n (1 ≀ n ≀ 100 000), denoting that ZS the Coder wants to reach level n + 1.
["14\n16\n46", "999999999999999998\n44500000000", "2\n17\n46\n97"]
#include<stdio.h> int main() { int n; unsigned long long int i,m=2,gmd; scanf("%d",&n); printf("2\n"); for(i=2;i<=n;i++) printf("%I64d\n",i*(i+1)*(i+1)-i+1); return 0; }
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7).
On the single line print the single number β€” the answer to the problem modulo prime number 1000000007 (109 + 7).
C
c421f47149e70240a02903d9d47de429
d43975959d7ad6357c93533e4b21ac50
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "combinatorics" ]
1327215600
["3 2\n10 10 10", "4 2\n4 4 7 7"]
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
PASSED
2,100
standard input
2 seconds
The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105). The next line contains n integers ai (1 ≀ ai ≀ 109) β€” the sequence a.
["3", "4"]
#include <stdio.h> #include <stdlib.h> int a[100000], b[50000], c[100000]; int dp[100001]; int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); } int lucky(int n) { while (n) { if (n % 10 != 4 && n % 10 != 7) { return 0; } n /= 10; } return 1; } int extgcd(int a, int b, int *x, int *y) { int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); *y -= (a / b) * (*x); } else { *x = 1; *y = 0; } return d; } int mod_inverse(int a, int m) { int x, y; extgcd(a, m, &x, &y); return (m + x % m) % m; } int main() { int n, k, p = 0, q = 0, m = 1000000007, i, j; long long sum = 0, a1 = 1, a2 = 1, a3 = 1; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) scanf("%d", &a[i]); qsort(a, n, sizeof(int), cmp); for (i = 0; i < n; i++) { if (lucky(a[i]) == 1) { for (j = i; j < n; j++) { if (a[j] != a[i]) break; } if (j - i > 1) b[q++] = j - i; i = j - 1; } p++; } if (p < k) { puts("0"); return 0; } for (i = 1; i <= p - q; i++) { a1 = a1 * i % m; a3 = a3 * i % m; c[i] = (int)a3; } c[0] = 1; for (i = 0; i <= k; i++) { if (i > p - q) break; dp[i] = a1 * mod_inverse((int)(a2 * a3 % m), m) % m; a2 = a2 * (i + 1) % m; a3 = c[p - q - i - 1]; } for (i = 0; i < q; i++) { for (j = k - 1; j >= 0; j--) { dp[j + 1] = ((long long)dp[j] * b[i] + dp[j + 1]) % m; } } printf("%d\n", dp[k]); return 0; }
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has sequence a consisting of n integers.The subsequence of the sequence a is such subsequence that can be obtained from a by removing zero or more of its elements.Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length n has exactly 2n different subsequences (including an empty subsequence).A subsequence is considered lucky if it has a length exactly k and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times).Help Petya find the number of different lucky subsequences of the sequence a. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109 + 7).
On the single line print the single number β€” the answer to the problem modulo prime number 1000000007 (109 + 7).
C
c421f47149e70240a02903d9d47de429
59c0aca6ac38670c9ee24d78e6c05133
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "combinatorics" ]
1327215600
["3 2\n10 10 10", "4 2\n4 4 7 7"]
NoteIn the first sample all 3 subsequences of the needed length are considered lucky.In the second sample there are 4 lucky subsequences. For them the sets of indexes equal (the indexation starts from 1): {1, 3}, {1, 4}, {2, 3} and {2, 4}.
PASSED
2,100
standard input
2 seconds
The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105). The next line contains n integers ai (1 ≀ ai ≀ 109) β€” the sequence a.
["3", "4"]
#include <stdio.h> #define maxn 100070 #define prime 10007 #define mod 1000000007 typedef long long int64; int cast[prime + maxn]; int key[prime + maxn]; int next[prime + maxn]; int a[maxn]; int64 b[maxn]; int is_lucky (int t) { for (; t; t /= 10) if (t % 10 != 4 && t % 10 != 7) return 0; return 1; } void hash (int t) { int p = t % prime, q; for (; (q = next[p]); p = q) if (cast[q] == t) return (void)(++key[q]); cast[q = next[p] = ++next[prime]] = t, key[q] = 1; } int64 fpm (int64 b, int64 e, int64 m) { int64 ret = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? ret = ret * b % m : 0; return ret; } int main () { // freopen ("E.in" , "r", stdin); // freopen ("E.out", "w", stdout); int n, k, i, j, bin = 0; scanf ("%d%d", &n, &k); next[prime] = prime; for (i = 1; i <= n; ++i) { scanf ("%d", &a[i]); if (is_lucky (a[i])) hash (a[i]); else ++bin; } b[0] = 1; for (i = 1; i <= k; ++i) b[i] = b[i - 1] * (bin - i + 1) % mod * fpm (i, mod - 2, mod) % mod; for (i = prime + 1; i <= next[prime]; ++i) for (j = i - prime + k; j; --j) b[j] = (b[j] + b[j - 1] * key[i]) % mod; printf ("%I64d\n", b[k]); return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
2f5de0af42d43d5c56098258bf46cd70
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main(){ int n,val,five=0,zero=0,i,j,flag=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&val); if( val==5) five+=1; if(val==0) zero+=1; } if(zero==0){ printf("-1"); } else { if(five%9==0) { for(i=0;i<five;i++) { printf("5"); } flag=1; } else { five=five-(five%9); for(i=0;i<five;i++){ printf("5"); flag=1; } } if(five<9) printf("0"); else { for(i=0;i<zero;i++) printf("0"); } } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
95f4744eb58556b3563385bdd6be85ca
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> int main(int argc, char ** argv) { int nZeros = 0, nFives = 0, n, i = 0; scanf("%i", &n); for (; i < n; ++i) { int a; scanf("%i", &a); if (a) { ++nFives; } else { ++nZeros; } } if ((nFives >= 9) && nZeros) { for (i = 0; i < nFives / 9; ++i) { printf("555555555"); } for (i = 0; i < nZeros; ++i) { printf("0"); } } else if (nZeros) { printf("0"); } else { printf("-1"); } printf("\n"); return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
ae45c09abe5e643b9ea37dc140146530
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d",&n); int arr[n]; int i; int noF=0; int noZ=0; for(i=0;i<n;i++){ scanf("%d",&arr[i]); if(arr[i]==5) noF++; if(arr[i]==0) noZ++; } if(noZ<1){ printf("-1"); return 0; } int div=noF/9; int rem=noF%9; int j; for(i=0;i<div;i++){ for(j=0;j<9;j++){ printf("5"); } } for(i=0;i<noZ&&div>0;i++){ printf("0"); } if(noZ>=1&&div==0){ printf("0"); } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
fc66cf8befa67eda78cf2afaeede91ea
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> #include<conio.h> int main() { int no; int i; int no_of_five=0; int no_of_zero=0; int nooftimes; scanf("%d",&nooftimes); for(i=0;i<nooftimes;i++) { scanf("%d",&no); if(no==5) no_of_five++; else no_of_zero++; } if(no_of_zero==0) { printf("-1"); return 0; } if(no_of_five<9&&no_of_zero>0) { printf("0"); return 0; } if(no_of_five>=9&&no_of_zero>0) { for(i=1;i<=no_of_five/9;i++){ printf("555555555"); } while(no_of_zero-->0) printf("0"); return 0; } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
75b5254ff2465881aa6f7273e52ae462
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int a,sum=0,count=0,p,i,j; scanf("%d",&a); int arr[a]; for(i=0;i<a;i++) scanf("%d",&arr[i]); for(i=0;i<a;i++) { if(arr[i]==5) count++; if(arr[i]==0) sum++; } if(count==0&&sum!=0) { printf("0"); return 0; } if(sum==0) { printf("-1"); return 0; } if(count<9) { printf("0"); return 0; } j=0; while(j<=count) j=j+9; j=j-9; for(i=1;i<=j;i++) printf("5"); while(sum!=0) { printf("0"); sum--; } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
4ba70ef0dbb776e85e8907868c737f7b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> #include<math.h> #define getchar getchar//_unlocked #define M 1000000007 int getint () { int n=0; char ch=getchar(); while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') { n=n*10+ch-'0'; ch=getchar(); } return n; } unsigned long long gcd(unsigned long long a, unsigned long long b) { unsigned long long div=a,did=b,rem; while((rem=did%div)!=0) { did=div; div=rem; } return div; } long long getlonglong () { long long n=0; char ch=getchar(); while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') { n=n*10+ch-'0'; ch=getchar(); } return n; } void sort(int a[] ,int start1 ,int end1 ,int start2 ,int end2) { int temp[end1-start1 +1 + end2-start2+1 ]; int i=start1,j=start2,count=0; while(i<=end1 && j<=end2) { if(a[i]>=a[j]) temp[count++]=a[i++]; else temp[count++]=a[j++]; } for(;i<=end1;++i) temp[count++]=a[i]; for(;j<=end2;++j) temp[count++]=a[j]; for(i=0;i<count;++i) a[i+start1]=temp[i]; } void mergesort(int a[] ,int start,int end) { if(start==end) return; int middle =(start+end)/2; mergesort(a,start,middle); mergesort(a,middle+1,end); sort(a,start,middle,middle+1,end); } long long Ceil(long long a , long long n) { if(a<0) return 0; if(a%n==0) return a/n; else return a/n +1 ; } int lucky(int num) { while(num) { if(num%10!=4 && num%10!=7) return 0; num=num/10; } return 1; } int main() { int f=0,z=0,n; n=getint(); while(n--) { switch(getint()) { case 5: ++f;break; case 0: ++z;break; } } if(z==0) printf("-1"); else { n=9*(f/9); while(n--) printf("5"); if(9*(f/9) ==0 ) printf("0"); else { while(z--) printf("0"); } } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
41440d33553127d862b27538955c8af3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int n,ct1=0,ct2=0,ct3=0,i; scanf("%d",&n); int a[n]; for(i=0;i<n;++i) { scanf("%d",&a[i]); if(a[i]==5) ct1++; else ct2++; } ct3=ct1/9; if(ct2==0) printf("-1"); else if(ct3==0 && ct2!=0) printf("0"); else {for(i=0;i<ct3;++i) printf("555555555"); for(i=0;i<ct2;++i) printf("0"); } return(0); }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
bb1e95fa9a6002bcb26de8f2adb2db65
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int n,i,j,b,s; int main() { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&j); if(!j) s++; else b++; } if(!s) printf("-1"); else { for(i=1;i<=(b/9)*9;i++) printf("5"); for(i=0;i<s && (b/9 || !i);i++) printf("0"); } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
4fd7021985d52a001762f21e3502bece
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int n,i,dig,zero,five,val; scanf("%d",&n); zero = five = 0; for (i = 0; i < n; i++) { scanf("%d",&dig); if (dig == 0) { zero++; } else { five++; } } if (zero == 0) { printf("-1\n"); return 0; } val = five / 9; if (val == 0) { printf("0\n"); return 0; } for (i = 0; i < val; i++) { printf("555555555"); } for (i = 0; i < zero; i++) { printf("0"); } printf("\n"); return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
d0e7a5374e62db3fdff79c14f425c405
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() {int n,count1=0,count2=0,i,count3=0,a; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a); if(a==5) count1++; if(a==0) count2++; } count3=count1*5; if(count3>=45 && count2>0 ) { while(count3%9!=0) { count3-=5; count1--; } for(i=0;i<count1;i++) printf("5"); for(i=0;i<count2;i++) printf("0"); } else if(count2==0) printf("-1"); else printf("0"); return 0;}
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
1ed4731a88b924cff525d94c94235067
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() {int n,count1=0,count2=0,i,count3=0,a; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a); if(a==5) count1++; if(a==0) count2++; } count3=count1*5; if(count3>=45 && count2>0 ) { count3-=count3%45; count1=count3/5; for(i=0;i<count1;i++) printf("5"); for(i=0;i<count2;i++) printf("0"); } else if(count2==0) printf("-1"); else printf("0"); return 0;}
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
19cd77c2cf17be7bb6989d57dba40ed2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> #include <string.h> int main() { int i,j,k,n,p=0,q=0,f; scanf("%d",&n); int ara[n]; for(i=0;i<n;i++) { scanf("%d",&ara[i]); } for(i=0;i<n;i++) { if(ara[i]==5) p=p+1; else q=q+1; } if(q==0) printf("-1"); else if(p<9) printf("0"); else { p=p/9; p=p*9; for(i=1;i<=(p+q);i++) { if(i<=p) printf("5"); else printf("0"); } } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
d97753d279a3efc86bbe184501f91b0b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> #include <string.h> int main() { int i,j,k,n,p=0,q=0; scanf("%d",&n); int ara[n]; for(i=0;i<n;i++) { scanf("%d",&ara[i]); } for(i=0;i<n;i++) { if(ara[i]==5) p=p+1; else q=q+1; } if(q==0) printf("-1"); else if(p<9) printf("0"); else { p=p/9; p=p*9; for(i=1;i<=(p+q);i++) { if(i<=p) printf("5"); else printf("0"); } } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
ba3c7c4eb6348f27415964a9b86d1f6e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int n,a[100000]; scanf("%d",&n); int i; for(i=0;i<n;i++) scanf("%d",&a[i]); int c=0; for(i=0;i<n;i++) if(a[i]==5) c++; int d; d=n-c; c=c/9; c=c*9; if(d==0) printf("-1"); else if(c==0) printf("0"); else { for(i=0;i<c;i++) printf("5"); for(i=0;i<d;i++) printf("0"); } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
0ac57b1ace6bd826e1c8932612700659
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> #include<string.h> int main() { int n,a[1010],i,c5=0,c0=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]==5) c5++; else c0++; } if(c0==0) printf("-1"); else { for(i=1;i<=c5/9;i++) { printf("555555555"); } if(c5<9) printf("0"); else for(i=1;i<=c0;i++) printf("0"); } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
401b29f59abe4e00a482c7ce131a5538
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int n,c5,c0,i,temp; c5=0; c0=0; scanf("%d",&n); for(i=0;i<n;i++) {scanf("%d",&temp); (temp==0?c0++:c5++);} if((c5>=9)&&(c0!=0)) {for(i=0;i<(c5-c5%9);i++) printf("%d",5); for(i=0;i<c0;i++) printf("%d",0);} else if(c0==0) printf("-1"); else printf("%d",0); return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
37749f7edaeb6cca700eea8a9f5d562d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> typedef int card[1001]; typedef struct { card kartu; int byk; } kkartu; void cek (kkartu X); int main() { kkartu X; int i; scanf ("%d", &X.byk); for (i = 1; i <= X.byk; i++) { scanf ("%d", &X.kartu[i]); } cek (X); return 0; } void cek (kkartu X) { int i,j; int lima; int nol; lima = 0; nol = 0; for (i = 1; i <= X.byk; i++) { if (X.kartu[i] == 5) lima += 1; if (X.kartu[i] == 0) nol += 1; } if (nol < 1) { printf ("-1"); } else if (lima < 9) { printf ("0"); } else { for (i = 1; i <= 9 * (lima/9); i++) printf ("5"); for (i = 1; i <= nol; i++) printf ("0"); } }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
d11c4d513b8f99166d8adaa88b68df49
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int n,count5,count0,i,t; while(scanf("%d",&n)!=EOF) { count5=0; count0=0; for(i=0;i<n;i++) { scanf("%d",&t); if(t==5) count5++; else count0++; } if(count0==0) { printf("-1\n"); continue; } if(count5<9||count0<1) printf("0\n"); else { if(count5>=18) { for(i=0;i<count5/9;i++) printf("555555555"); for(i=0;i<count0;i++) printf("0"); } else { for(i=0;i<9;i++) printf("5"); for(i=0;i<count0;i++) printf("0"); } } printf("\n"); } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
7d85eb1390aa494ff7a2bffc2d301612
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main(){ int five=0,zero=0; int i,n,aux; int times; scanf("%d",&n); for(i=0; i<n; i++){ scanf("%d",&aux); if(aux==5) five++; else zero++; } if(five>=9 && zero>0) { times = (five/9)*9; for(i=0; i<times; i++) printf("5"); for(i=0; i<zero; i++) printf("0"); } else if(zero>0) printf("0"); else printf("-1"); return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
83893cc4ca7fad36db4aa40846961a96
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> long long int Power(long long int a, long long int b) { long long int x=a,y=b,p=1; while(y--) p=p*x; return p; } int main() { long long int i,n,z=0,temp=0,ans=0,t=1; long long int A[1000]; scanf("%lld", &n); for(i=0;i<n;i++) { scanf("%lld", &A[i]); if(A[i]==5) temp++; else z++; if(temp==9) { ans++; temp=0; } } if(temp<9 && ans==0 && z==0) {puts("-1"); goto here;} if(z>0) { for(i=1 ; i<=9*ans ; i++) printf("5"); if(ans!=0) { for(i=0;i<z;i++) printf("0"); } else printf("0"); } else printf("-1"); here: return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
2efecc185c2c3b5fb967b084879b5914
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { unsigned short int n,count5=0,count0=0,dig; scanf("%hd",&n); while(n--) { scanf("%hd",&dig); if(dig==5) count5++; else count0++; } count5/=9; count5*=9; if(count5==0&&count0!=0) printf("0"); else if(count5==0&&count0==0||count5!=0&&count0==0) printf("-1"); else { while(count5--) printf("5"); while(count0--) printf("0"); } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
67c00253851cd0846cedae3154d81e5a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include<stdio.h> int main() { int n,i,c0=0,c5=0; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) {scanf("%d",&a[i]); if(a[i]==0) c0++; else c5++;} if(c5<9){ if(c0>0) printf("0"); else printf("-1"); } else {if(c0==0) printf("-1"); else{ for(i=0;i<c5-c5%9;i++) printf("5"); for(i=0;i<c0;i++) printf("0");}} return 0;}
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
57ece96d50b262af755e221a68dc66f2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> int main() { int a,b,zero=0,five=0,c,n,s[10001]; scanf("%d",&n); for(a=1;a<=n;a++){ scanf("%d",&s[a]); if(s[a]==0) zero++; else five++; } if(zero==0) printf("-1"); else if(five<9) printf("0"); else{ b=five/9; b=b*9; b+=zero; for(a=1;a<=b;a++){ if(a<=b-zero) printf("5"); else printf("0"); } } return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
899071e7c74d38f4228c45fb4ac2fa9e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> int main() { int n; scanf("%d",&n); int f=0,o=0,i,x; for(i=0;i<n;i++) { scanf("%d",&x); if(x==5) f++; else o++; } if(f<9 && o >0) printf("0\n"); else if(f>=9 && o>=1) { for(i=0;i<(f/9)*9;i++) printf("5"); for(i=0;i<o;i++) printf("0"); } else printf("-1\n"); return 0; }
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
C
409b27044d5ec97b5315c92d4112376f
6af1fa01b5d1cee9808f5ac45d8f19f5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "brute force", "math" ]
1380900600
["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5"]
NoteIn the first test you can make only one number that is a multiple of 90 β€” 0.In the second test you can make number 5555555550, it is a multiple of 90.
PASSED
1,000
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.
["0", "5555555550"]
#include <stdio.h> #include <string.h> int main () { int i, n, a[1100], c5 = 0, c0 = 0; scanf ("%d", &n); for (i=1; i<=n; i++) { scanf ("%d", &a[i]); if (a[i] == 5) { c5 += 1; } else { c0 += 1; } } c5 = c5 / 9; if (c0 == 0) { printf ("-1"); return 0; } if (c5 == 0) { c0 = 1; } for (i=1; i<=c5; i++) { printf ("555555555"); } for (i=1; i<=c0; i++) { printf ("0"); } return 0; }
Consider some set of distinct characters $$$A$$$ and some string $$$S$$$, consisting of exactly $$$n$$$ characters, where each character is present in $$$A$$$.You are given an array of $$$m$$$ integers $$$b$$$ ($$$b_1 &lt; b_2 &lt; \dots &lt; b_m$$$). You are allowed to perform the following move on the string $$$S$$$: Choose some valid $$$i$$$ and set $$$k = b_i$$$; Take the first $$$k$$$ characters of $$$S = Pr_k$$$; Take the last $$$k$$$ characters of $$$S = Su_k$$$; Substitute the first $$$k$$$ characters of $$$S$$$ with the reversed $$$Su_k$$$; Substitute the last $$$k$$$ characters of $$$S$$$ with the reversed $$$Pr_k$$$. For example, let's take a look at $$$S =$$$ "abcdefghi" and $$$k = 2$$$. $$$Pr_2 =$$$ "ab", $$$Su_2 =$$$ "hi". Reversed $$$Pr_2 =$$$ "ba", $$$Su_2 =$$$ "ih". Thus, the resulting $$$S$$$ is "ihcdefgba".The move can be performed arbitrary number of times (possibly zero). Any $$$i$$$ can be selected multiple times over these moves.Let's call some strings $$$S$$$ and $$$T$$$ equal if and only if there exists such a sequence of moves to transmute string $$$S$$$ to string $$$T$$$. For the above example strings "abcdefghi" and "ihcdefgba" are equal. Also note that this implies $$$S = S$$$.The task is simple. Count the number of distinct strings.The answer can be huge enough, so calculate it modulo $$$998244353$$$.
Print a single integer β€” the number of distinct strings of length $$$n$$$ with characters from set $$$A$$$ modulo $$$998244353$$$.
C
385ac4db5b0e7613b03fb4f1044367dd
a8f06a6f0c7264ba66e610e0a4368b5d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "strings" ]
1539269400
["3 1 2\n1", "9 2 26\n2 3", "12 3 1\n2 5 6"]
NoteHere are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in $$$A$$$ are different. "aaa" "aab" = "baa" "aba" "abb" = "bba" "bab" "bbb"
PASSED
2,300
standard input
2 seconds
The first line contains three integers $$$n$$$, $$$m$$$ and $$$|A|$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le m \le min(\frac n 2, 2 \cdot 10^5)$$$, $$$1 \le |A| \le 10^9$$$) β€” the length of the strings, the size of the array $$$b$$$ and the size of the set $$$A$$$, respectively. The second line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le \frac n 2$$$, $$$b_1 &lt; b_2 &lt; \dots &lt; b_m$$$).
["6", "150352234", "1"]
#include <stdio.h> #define mod 998244353 int n,m,k,z,i,ans=1,a[200005]; int fastpow(int x,int y) { int v=1; while (y) { if (y&1) v=1LL*v*x%mod; x=1LL*x*x%mod; y>>=1; } return v; } int main() { register int i; scanf("%d%d%d",&n,&m,&k); for (i=1;i<=m;i++) { scanf("%d",a+i); z=fastpow(k,a[i]-a[i-1]); ans=(1LL*z*(z+1)/2%mod*ans)%mod; } printf("%I64d\n",1LL*ans*fastpow(k,n-a[m]*2)%mod); return 0; }
Consider some set of distinct characters $$$A$$$ and some string $$$S$$$, consisting of exactly $$$n$$$ characters, where each character is present in $$$A$$$.You are given an array of $$$m$$$ integers $$$b$$$ ($$$b_1 &lt; b_2 &lt; \dots &lt; b_m$$$). You are allowed to perform the following move on the string $$$S$$$: Choose some valid $$$i$$$ and set $$$k = b_i$$$; Take the first $$$k$$$ characters of $$$S = Pr_k$$$; Take the last $$$k$$$ characters of $$$S = Su_k$$$; Substitute the first $$$k$$$ characters of $$$S$$$ with the reversed $$$Su_k$$$; Substitute the last $$$k$$$ characters of $$$S$$$ with the reversed $$$Pr_k$$$. For example, let's take a look at $$$S =$$$ "abcdefghi" and $$$k = 2$$$. $$$Pr_2 =$$$ "ab", $$$Su_2 =$$$ "hi". Reversed $$$Pr_2 =$$$ "ba", $$$Su_2 =$$$ "ih". Thus, the resulting $$$S$$$ is "ihcdefgba".The move can be performed arbitrary number of times (possibly zero). Any $$$i$$$ can be selected multiple times over these moves.Let's call some strings $$$S$$$ and $$$T$$$ equal if and only if there exists such a sequence of moves to transmute string $$$S$$$ to string $$$T$$$. For the above example strings "abcdefghi" and "ihcdefgba" are equal. Also note that this implies $$$S = S$$$.The task is simple. Count the number of distinct strings.The answer can be huge enough, so calculate it modulo $$$998244353$$$.
Print a single integer β€” the number of distinct strings of length $$$n$$$ with characters from set $$$A$$$ modulo $$$998244353$$$.
C
385ac4db5b0e7613b03fb4f1044367dd
b7f978bf4100cfa5a8971d0cd12a4670
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "strings" ]
1539269400
["3 1 2\n1", "9 2 26\n2 3", "12 3 1\n2 5 6"]
NoteHere are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in $$$A$$$ are different. "aaa" "aab" = "baa" "aba" "abb" = "bba" "bab" "bbb"
PASSED
2,300
standard input
2 seconds
The first line contains three integers $$$n$$$, $$$m$$$ and $$$|A|$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le m \le min(\frac n 2, 2 \cdot 10^5)$$$, $$$1 \le |A| \le 10^9$$$) β€” the length of the strings, the size of the array $$$b$$$ and the size of the set $$$A$$$, respectively. The second line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le \frac n 2$$$, $$$b_1 &lt; b_2 &lt; \dots &lt; b_m$$$).
["6", "150352234", "1"]
/** * Code by Van Linh */ #include <stdio.h> #include <stdint.h> #include <inttypes.h> // Modul #define MODULA 998244353 // Dau vao uint64_t n, m, A; uint64_t b[200001]; uint64_t powi(uint64_t a, uint64_t b) { uint64_t i, ret; if(b == 0) return 1; ret = powi(a, b/2); ret = (ret*ret) % MODULA; if(b % 2) ret = (ret * a) % MODULA; return ret; } int main() { uint64_t i, p, r; // doc du lieu scanf("%"PRId64"%"PRId64"%"PRId64, &n, &m, &A); for(i = 1; i <= m; i++) scanf("%"PRId64, b+i); // Xu li p = 1; for(i = 1; i <= m; i++) { r = powi(A, b[i]-b[i-1]); r = (r*(r+1)) % MODULA; r = (r*powi(2, MODULA-2)) % MODULA; p = (p*r) % MODULA; } p = (p * powi(A, n-2*b[m])) % MODULA; // Ghi ket qua printf("%"PRId64, p); }
Consider some set of distinct characters $$$A$$$ and some string $$$S$$$, consisting of exactly $$$n$$$ characters, where each character is present in $$$A$$$.You are given an array of $$$m$$$ integers $$$b$$$ ($$$b_1 &lt; b_2 &lt; \dots &lt; b_m$$$). You are allowed to perform the following move on the string $$$S$$$: Choose some valid $$$i$$$ and set $$$k = b_i$$$; Take the first $$$k$$$ characters of $$$S = Pr_k$$$; Take the last $$$k$$$ characters of $$$S = Su_k$$$; Substitute the first $$$k$$$ characters of $$$S$$$ with the reversed $$$Su_k$$$; Substitute the last $$$k$$$ characters of $$$S$$$ with the reversed $$$Pr_k$$$. For example, let's take a look at $$$S =$$$ "abcdefghi" and $$$k = 2$$$. $$$Pr_2 =$$$ "ab", $$$Su_2 =$$$ "hi". Reversed $$$Pr_2 =$$$ "ba", $$$Su_2 =$$$ "ih". Thus, the resulting $$$S$$$ is "ihcdefgba".The move can be performed arbitrary number of times (possibly zero). Any $$$i$$$ can be selected multiple times over these moves.Let's call some strings $$$S$$$ and $$$T$$$ equal if and only if there exists such a sequence of moves to transmute string $$$S$$$ to string $$$T$$$. For the above example strings "abcdefghi" and "ihcdefgba" are equal. Also note that this implies $$$S = S$$$.The task is simple. Count the number of distinct strings.The answer can be huge enough, so calculate it modulo $$$998244353$$$.
Print a single integer β€” the number of distinct strings of length $$$n$$$ with characters from set $$$A$$$ modulo $$$998244353$$$.
C
385ac4db5b0e7613b03fb4f1044367dd
0edd540006765b1e7625904d74c74a1b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "strings" ]
1539269400
["3 1 2\n1", "9 2 26\n2 3", "12 3 1\n2 5 6"]
NoteHere are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in $$$A$$$ are different. "aaa" "aab" = "baa" "aba" "abb" = "bba" "bab" "bbb"
PASSED
2,300
standard input
2 seconds
The first line contains three integers $$$n$$$, $$$m$$$ and $$$|A|$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le m \le min(\frac n 2, 2 \cdot 10^5)$$$, $$$1 \le |A| \le 10^9$$$) β€” the length of the strings, the size of the array $$$b$$$ and the size of the set $$$A$$$, respectively. The second line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le \frac n 2$$$, $$$b_1 &lt; b_2 &lt; \dots &lt; b_m$$$).
["6", "150352234", "1"]
#include <stdio.h> #define M 200000 #define MD 998244353 long long power(int a, int b) { long long p; if (b == 0) return 1; p = power(a, b / 2); p = p * p % MD; if (b % 2 == 1) p = p * a % MD; return p; } int main() { int n, m, a, b_, b; long long ans; scanf("%d%d%d", &n, &m, &a); ans = 1; b_ = 0; while (m--) { long long p; scanf("%d", &b); p = power(a, b - b_); ans = ans * (p * (p + 1) / 2 % MD) % MD; b_ = b; } ans = ans * power(a, n - b_ * 2) % MD; printf("%lld\n", ans); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
31d2af4a5761992894dc906c5d6fe535
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> #include <stdlib.h> int main () { int n, **a, i, j, co = 0, ch = 1, *b, k = 0; scanf("%d", &n); a = (int **)malloc(n * sizeof(int*)); b = (int *)malloc(n * sizeof(int)); for (i = 0; i < n; i++) a[i] = (int *)malloc(n * sizeof(int)); for(i = 0; i< n; i++) for(j = 0; j < n; j++){ scanf("%d", &a[i][j]); } putchar('\n'); for(i = 0; i< n; i++){ for(j = 0; j < n; j++) if(a[i][j] == 1 || a[i][j] == 3) ch = 0; if(ch) { co++; b[k] = i + 1; k++; } ch = 1; } printf("%d\n", co); for(k = 0; k < co; k++) printf("%d ", b[k]); for(i = 0; i < n; i++) free(a[i]); free(a); free(b); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
a32698eebcb36ba681b48448cdeefe22
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main(){ int n, a, good[100000], pass[100000] = {0}; int i, j, count; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &a); if (a == 0 || a == 2) { pass[i] += 1; } } } count = 0; for (i = 0; i < n; i++) { if (pass[i] == n-1) { good[count] = i; count += 1; } } printf("%d\n", count); if (count > 0) { for (i = 0; i < count; i++) { printf("%d ", good[i] + 1); } } printf("\n"); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
8a874df0d1407f5897e3d7e622f63100
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> #include <stdlib.h> int main(){ int n, x, count = 0; scanf("%d", &n); int** matrix = (int**) malloc(sizeof(int*)*n); int* bool = (int*) malloc(sizeof(int)*n); for(int i=0; i<n; i++){ matrix[i] = (int*) malloc(sizeof(int)*n); bool[i] = 0; for(int j=0; j<n; j++){ scanf("%d", &matrix[i][j]); if(i==j) continue; if(matrix[i][j] == 0){ continue; }else if(matrix[i][j] == 1){ bool[i]++; }else if(matrix[i][j] == 3){ bool[i]++; bool[j]++; }else if(matrix[i][j] == 2){ bool[j]++; } } } for(int i=0; i<n; i++){ if(bool[i] == 0) count++; } printf("%d\n",count); for(int i=0; i<n; i++){ if(bool[i] == 0) printf("%d ", i+1); } if(count > 0) printf("\n"); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
d07f7307a60861ab532f488e3da41ab5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int n, i, j, a, cars[101], res = 0; int main() { scanf("%d", &n); for(i = 1; i <= n; ++i) for(j = 1; j <= n; ++j) { scanf("%d", &a); switch(a) { case 1: ++cars[i]; break; case 2: ++cars[j]; break; case 3: ++cars[i]; ++cars[j]; break; } } for(i = 1; i <= n; ++i) if(cars[i] == 0) ++res; printf("%d\n", res); for(i = 1; i <= n; ++i) if(cars[i] == 0) printf("%d ", i); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
06f07856264cf1f6660d5788e55d0829
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdbool.h> #include <stdio.h> int main(void) { unsigned short cars; scanf("%hu", &cars); bool car_states[cars]; for (unsigned short i = 0; i < cars; ++i) car_states[i] = true; unsigned short counter = cars; for (unsigned short i = 0; i < cars; ++i) { for (unsigned short j = 0; j < cars; ++j) { short collision_result; scanf("%hd", &collision_result); if (collision_result == 3) { if (car_states[i]) { car_states[i] = false; --counter; } if (car_states[j]) { car_states[j] = false; --counter; } } else if (collision_result == 1 && car_states[i]) { car_states[i] = false; --counter; } else if (collision_result == 2 && car_states[j]) { car_states[j] = false; --counter; } } } printf("%hu\n", counter); for (unsigned short i = 0; i < cars; ++i) if (car_states[i]) printf("%d ", i + 1); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
dd5ed64af295e993bc4ed6cd3b22b750
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int n,r,c,check=1,i=0; scanf("%d",&n); int a[n][n],save[n]; for(r=0;r<n;++r) { check=1; for(c=0;c<n;++c) { scanf("%d",&a[r][c]); if(a[r][c]==1||a[r][c]==3) check=0; } if(check==1) { save[i]=r+1; ++i; } } printf("%d\n",i); for(r=0;r<i;++r) printf("%d ",save[r]); }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
f28e1014421f03f5cf244126c744b73f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main() { int n, i, j, m=0, k=0, p; int arr[103][103], arr2[103]; scanf("%d", &n); for(i=0; i<n; i++) { p=1; for(j=0; j<n; j++){ scanf("%d", &arr[i][j]); if(arr[i][j]==1 || arr[i][j]==3){ p=0; } } if(p==1){ k++; arr2[m]=i+1; m++; } } if(k==0){ printf("0\n"); }else{ printf("%d\n", k); for(i=0; i<m; i++){ printf("%d", arr2[i]); if(i!=m-1)printf(" "); } printf("\n"); } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
da1db6b25d81d2623b7e8c8410cf3091
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int ara2[101]; int main () { int n,i,j,count=0,p; scanf("%d",&n); int ara[n+1][n+1]; for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { scanf("%d",&ara[i][j]); if(ara[i][j]==3) ara2[i]=ara2[j]=1; else if(ara[i][j]==1) ara2[i]=1; else if(ara[i][j]==2) ara2[j]=1; } } for(i=1; i<=n; i++) { if(!ara2[i]) count++; } printf("%d\n",count); p=0; for(i=1; i<=n; i++) { if(!ara2[i]) { printf("%d ",i); p++; } if(p==count) break; } return 0; }