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
sequencelengths 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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | c80620e849d28d5bc7d44090de656281 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
long long a[n];
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
long long temp,temp1,temp2;
for(int i=0;i<n;i++)
{
int d=2;
if(a[i]%2!=0)
{
temp=a[i]+1;
while(d--)
{
for(int j=0;j<n;j++)
{
if(a[i]==a[j]) a[j]=temp;
}
temp=a[i]-1;
}
}
else
{
temp=a[i]-1;
for(int j=0;j<n;j++)
{
if(a[i]==a[j]) a[j]=temp;
}
}
}
for(int i=0;i<n;i++)
{
printf("%lld ",a[i]);
}
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 304df0f67bc29ecdd03fc4cf4fee2164 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main()
{
int n,a;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a);
if(a%2==0)
{
printf("%d ",a-1);
}
else
{
printf("%d ",a);
}
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 14fc10cef7a064547c96d11ec8768533 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main()
{
int n,a;
scanf("%d",&n);
while(n--)
{
scanf("%d",&a);
if(a%2!=0)
{
printf("%d ",a);
}
else
{
printf("%d ",a-1);
}
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 6ba042e1645aee920434f8ef562cb472 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int arr[n];
for(int i=0; i<n; i++)
scanf("%d",&arr[i]);
for(int i=0; i<n; i++)
{
if(arr[i]%2==0)
arr[i]=arr[i]-1;
}
for(int i=0; i<n; i++)
printf("%d ",arr[i]);
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 83447d9d484a125b1988ec79e6e4a0ce | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include <stdio.h>
int main() {
int n,k,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
a[i] -=1;
}
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
return 0;
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 574505b89fcf29390f23c06c6da2b3fb | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main()
{
int i,j,k,t,a[1002];
scanf("%d",&t);
for(i=0; i<t; i++)
{
scanf("%d",&a[i]);
if(a[i]%2==0)
{
a[i]-=1;
}
}
for(i=0;i<t;i++)
{
printf("%d ",a[i]);
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | f59d958464b71cf774ae9dcc9b70dda3 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main()
{
int i,j,k,n;
scanf("%d",&n);
long int a[n];
for(i=0;i<n;i++){
scanf("%ld",&a[i]);
}
for(i=0;i<n;i++){
if(a[i]%2==0)
printf("%ld ",a[i]-1);
else
printf("%ld ",a[i]);
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 069e9554ecdc763cc49871199f5ae54e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main ()
{
int n;
int a[1000];
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
if (a[i] % 2 == 0)
a[i]--;
}
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
return 0 ;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 24b28a0f8fdb3ad719bda84b16af3e60 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
long int arr[n];
for(i=0;i<n;i++)
{
scanf("%ld",&arr[i]);
if(arr[i]%2==0)
arr[i]= arr[i]-1;
}
for(i=0;i<n;i++)
printf(" %ld",arr[i]);
return 0;
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | ff092e8743cc7ce14554fec09572fbdd | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main(){
int n,i;
scanf("%d",&n);
int a[1000];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
if(a[i]%2==0)
printf("%d ",a[i]-1);
else
printf("%d ",a[i]);
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 1d17c3d0f6fdb8890d29b24bef6ff8fe | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main(){
int n,i;
scanf("%d",&n);
int a[1000];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
if(a[i]%2==0)
printf("%d ",a[i]-1);
else
printf("%d ",a[i]);
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 6eb340c04277008b21e8e6fb07bb6e76 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include <stdio.h>
int main(void) {
int t;
scanf("%d",&t);
while(t--)
{
long n;
scanf("%ld",&n);
n -= (!(n%2));
printf("%ld ",n);
}
return 0;
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 717d4610cf378880be989e5adf61ec15 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include <stdio.h>
#define MAXN 1000
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a, p;
scanf("%d", &a);
printf("%d ", a - (a + 1) % 2);
}
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 3d7cd79f6cfd0bfbf35a26958e9155d4 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main(){
long long int a[1010],b[1010],n,i;
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld",&a[i]);
if(a[i]%2==0){
b[i]=a[i]-1;
}
else{
b[i]=a[i];
}
}
for(i=0;i<n;i++){
printf("%lld ",b[i]);
}
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 7eef14be971c4d5a365c73f6b9620805 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main() {
int i, j, n;
scanf ("%d", &n);
long int a[n];
for (i=0; i<n; i++) {
scanf("%ld", &a[i]);
}
for (i=0; i<n; i++) {
if (a[i]%2==0) {
a[i]= a[i]-1;
}
printf ("%ld ",a[i]);
}
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | dc5b600a4555d9d432a5fa6fa71ac624 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include <stdio.h>
int main(){
int n;
int num;
scanf("%d",&n);
while(n--){
scanf("%d",&num);
if(num%2 == 0)
printf("%d ",num-1);
else
printf("%d ",num);
}
printf("\n");
} | |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 10483092ce4f2fd2f33f4fb0cfe74221 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main(){
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]%2==0){
a[i]=a[i]-1;
}
}
printf("%d",a[0]);
for(i=1;i<n;i++){
printf(" %d",a[i]);
}
printf("\n");
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 68f3fee7b9266b118fdc3fe3669156de | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
int main(){
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]%2==0){
a[i]=a[i]-1;
}
}
printf("%d",a[0]);
for(i=1;i<n;i++){
printf(" %d",a[i]);
}
printf("\n");
return 0;
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | 94da7e50ac2b21f11c52b1e4b2542b4b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n,i,j,max=-1;
scanf("%d",&n);
int *a=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(max<a[i])
max=a[i];
}
for(i=0;i<n;i++)
{
/*int ele;
if(i%2==0)
ele=i-1;
else ele=i+1;
for(j=0;j<n;j++)
{
if(a[j]==i)
{
a[j]=ele;
}
}*/
if(a[i]%2==0)
a[i]=a[i]-1;
}
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
| |
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!).Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: Replace each occurrence of $$$1$$$ in the array $$$a$$$ with $$$2$$$; Replace each occurrence of $$$2$$$ in the array $$$a$$$ with $$$1$$$; Replace each occurrence of $$$3$$$ in the array $$$a$$$ with $$$4$$$; Replace each occurrence of $$$4$$$ in the array $$$a$$$ with $$$3$$$; Replace each occurrence of $$$5$$$ in the array $$$a$$$ with $$$6$$$; Replace each occurrence of $$$6$$$ in the array $$$a$$$ with $$$5$$$; $$$\dots$$$ Replace each occurrence of $$$10^9 - 1$$$ in the array $$$a$$$ with $$$10^9$$$; Replace each occurrence of $$$10^9$$$ in the array $$$a$$$ with $$$10^9 - 1$$$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($$$2i - 1, 2i$$$) for each $$$i \in\{1, 2, \ldots, 5 \cdot 10^8\}$$$ as described above.For example, for the array $$$a = [1, 2, 4, 5, 10]$$$, the following sequence of arrays represents the algorithm: $$$[1, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$1$$$ with $$$2$$$) $$$\rightarrow$$$ $$$[2, 2, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$2$$$ with $$$1$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$3$$$ with $$$4$$$) $$$\rightarrow$$$ $$$[1, 1, 4, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$4$$$ with $$$3$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$5$$$ with $$$6$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 6, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$6$$$ with $$$5$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ $$$\dots$$$ $$$\rightarrow$$$ $$$[1, 1, 3, 5, 10]$$$ $$$\rightarrow$$$ (replace all occurrences of $$$10$$$ with $$$9$$$) $$$\rightarrow$$$ $$$[1, 1, 3, 5, 9]$$$. The later steps of the algorithm do not change the array.Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. | Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array. | C | d00696cb27c679dda6e2e29314a8432b | d0edc9cd35d50159cd26a11a56e7c5b5 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1531751700 | ["5\n1 2 4 5 10", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000"] | NoteThe first example is described in the problem statement. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. | ["1 1 3 5 9", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"] | #include<stdlib.h>
#include <stdio.h>
#include<string.h>
int main(void) {
unsigned long long int n,i;
scanf("%llu",&n);
unsigned long long int a[1000005];
for(i=1;i<=n;i++)
{
scanf("%llu",&a[i]);
if(a[i]%2==0)
{
a[i]=a[i]-1;
}
else
{
a[i]=a[i];
}
printf("%llu ",a[i]);
}
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 25fa2efff54a9744b985f1cd96f5e6ef | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | # include<stdio.h>
int a[200005];
int main()
{
int i,n,ans = 1,flag = 0;
scanf("%d",&n);
for( i = 0;i<n;++i)
scanf("%d",&a[i]);
int max = 0;
for(i=0;i<n;++i)
{
if(a[i] == 1)
flag = 1;
}
for(i = 0;i<n-1;++i)
{
if(a[i] == 1 && a[i+1] == 1)
{
ans++;
flag =1;
if(ans > max)
max = ans;
}
else
ans = 1;
}
int t=1;
if(a[n-1]==1 && a[0]==1)
{
for(i = 1;i<n;++i)
{
if(a[i] == 1){
t++;
flag = 1;
}
else
break;
}
if(i!=n)
{
int j;
for(j=n-1;j>=0;--j)
{
if(a[j] == 1){
t++;
flag = 1;}
else
break;
}
}
}
if(t>max)
max = t;
if(flag==1)
printf("%d",max);
else
printf("0");
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | dc1ef1255daab7e112eb2dd45b9626c4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int i,n,a[500000],len = 0,max = 0;
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
for(i = 0; i < 2*n; i++)
{
if(a[i%n] == 1)
{
len++;
}
if(a[i%n] == 0)
{
len = 0;
}
if(max < len )
{
max = len;
}
}
printf("%d\n",max);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 37c4136f40d6ff3c3d157ff5a19d24c6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main(){
int n,i,arr[200009];
while(scanf("%d",&n)!=EOF){
for(i=1;i<=n;i++){
scanf("%d",&arr[i]);
}
int a=0,max=0;
for(i=1;i<=n;i++){
if(arr[i]==1){
a++;
if(a>max){
max=a;
}
}
else
{
a=0;
}
}
int x,x1=0,x2=0;
for(i=1;i<=n;i++){
if(arr[i]==1){
x1++;
}
else
{
break;
}
}
for(i=n;i>=1;i--){
if(arr[i]==1){
x2++;
}
else
{
break;
}
}
x=x1+x2;
if(max>x){
printf("%d\n",max);
}
else{
printf("%d\n",x);
}
}
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 39b88e5df43235ac162acd580ea7821c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main(){
long long n, arr[4000000], rest=0, x=0, i, j=0;
scanf("%I64d", &n);
for(i=0; i<n; i++) scanf("%I64d", &arr[i]);
for(i=0; i<n; i++){
if(arr[i]==1) {arr[n+j]=1; j++;}
else break;
}
n=n+j;
for(i=0; i<n; ){
if(arr[i]==1) {
x++;
i++;
}
else {
if(x>rest)rest=x;
x=0;
i+=1;
}
}
if(x>rest) rest=x;
printf("%I64d", rest);
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | cc1706c752225482926a029d62a80bff | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int n,i,c,m=0,m1=0,m2=0;
scanf("%d",&n);
int arr[n];
for(i=0; i<n; i++)
scanf("%d",&arr[i]);
for(i=0; i<n; i++)
{
if(arr[i]== 1)
{
while(arr[i]!= 0 && i< n)
{
m++;
i++;
}
if(m>m1)
m1= m;
if(i >= n-1)
m2= m;
m=0;
}
}
if(arr[n-1]== 1)
{
m= m2;
i=0;
while(arr[i]!= 0 && i<n)
{
m++;
i++;
}
if(m>m1)
m1=m;
}
printf("%d",m1);
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 07a316feebb4465cf9bf3835a1069dd0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
int count_max, count_begin, count_end, count;
int main()
{
int a[200001];
int n, i;
scanf("%d", &n);
a[n] = 0;
for (i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for (i=0; i<=n; i++)
{
if (a[i]==1)
{
count++;
continue;
}
if (a[i]==0)
{
count_max = count>count_max ? count : count_max;
count = 0;
}
}
if (a[0]==1 && a[n-1]==1)
{
for (i=0; i<n; i++)
{
if (a[i]==1)
{
count_begin++;
}
else
{
break;
}
}
for (i=(n-1); i>=0; i--)
{
if (a[i]==1)
{
count_begin++;
}
else
{
break;
}
}
}
count_max = count_begin>count_max ? count_begin : count_max;
if (count_max>n)
{
count_max = n;
}
printf("%d\n", count_max);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 930896abfc50c6c1891ff79b7f087c6d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
int main(){
int n,st=0,end=0,max=0,f=1,prev_a;
scanf("%i%i",&n,&prev_a);
if(prev_a==1){
st++;
end++;
max = end;
}
else
f=0;
n--;
while(n){
int a;
scanf("%i",&a);
if(a){
if(f){
st++;
end++;
}
else
end++;
}
else{
f=0;
end=0;
}
if(end>max)
max = end;
n--;
}
if(st+end>max)
max = st+end;
printf("%i",max);
return 0-0-0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 706681445af593c9653a2ddb7f9ab1f9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int n,i,c=1,j=0,m;
scanf("%d",&n);
int a[n];
int b[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{if(a[i]==1 &&a[i+1]==1)
{
c++;
}
else{
c=1;
}
b[i]=c;
}
int p=0;
for(i=0;i<n;i++)
{
if(a[i]==0)
{
p++;
}
}
int t=0;
for(i=0;i<n-1;i++)
{
if(a[i]==1 && a[i+1]==1)
{
t++;
}
if(a[i]==0)
{
break;
}
}
m=b[0];
for(i=0;i<n-1;i++)
{
if(b[i+1]>m)
{
m=b[i+1];
} }
if(p==n)
{
printf("0");
}
else if((b[n-2]+t+1)>m && a[n-1]==1 && a[0]==1)
{
printf("%d",b[n-2]+t+1);
}
else if(m>1)
{
printf("%d",m);
}
else{
printf("1");
} }
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | a529c498ee703fc26ba9a974dcb08f34 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int n,c=0,d=0,s,e=1,f=0,g=1;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;++i)
scanf("%d",&a[i]);
for(int j=0;j<n;++j)
{
if(a[j]==1)
++c;
else
break;
}
for(int l=n-1;l>=0;--l)
{
if(a[l]==1)
++d;
else
break;
}
for(int p=0;p<n;++p)
{
if(a[p]==1)
++f;
}
s=c+d;
if(s>n)
s=n;
for(int m=0;m<n-1;++m)
{
if(a[m]==1&&a[m+1]==1)
++e;
else
{
if(g<e)
g=e;
e=1;
}
}
if(f==0)
printf("0\n");
else if(s>=g)
printf("%d\n",s);
else
printf("%d\n",g);
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | f9ed6e3e9b547d11e5112816204f4d99 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
int main()
{
int i, len = 0, n, max = 0;
scanf("%d", &n);
int arr[n];
for(i = 0; i < n; i++)
scanf("%d", &arr[i]);
for(i = 0; i < 2 * n; i++)
{
if(arr[i % n])
{
len++;
if(len > max)
max = len;
}
else
len = 0;
}
printf("%d", max);
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | f1f64e4742124b1cc51b83cd3963713a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
#define N 200000
int main() {
static int aa[N];
int n, i, cnt, max;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
cnt = 0;
for (i = 0; i < n && aa[i] == 1; i++)
cnt++;
for (i = n - 1; i >= 0 && aa[i] == 1; i--)
cnt++;
max = cnt;
cnt = 0;
for (i = 0; i < n; i++)
if (max < (cnt = aa[i] == 0 ? 0 : cnt + 1))
max = cnt;
printf("%d\n", max);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 1edc4c4558056e92debdf8b18d88c07e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | /* https://codeforces.com/contest/1141/submission/53826745 (Dukkha) */
#include <stdio.h>
#define N 200000
int main() {
static int aa[N];
int n, i, cnt, max;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
cnt = 0;
for (i = 0; i < n && aa[i] == 1; i++)
cnt++;
for (i = n - 1; i >= 0 && aa[i] == 1; i--)
cnt++;
max = cnt;
cnt = 0;
for (i = 0; i < n; i++)
if (max < (cnt = aa[i] == 0 ? 0 : cnt + 1))
max = cnt;
printf("%d\n", max);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | fc94cc822d90ec6d0b749b4197a7c524 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
main()
{
int i,j,num=0,flag=1,flag1=1,max=0;
long n;
scanf("%ld",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n&&flag!=0;i++)
{
if(a[i]==1)
{
num++;
if(i==n-1)
{
i=-1;
flag1=0;
}
}
else
{
if(num>max)
max=num;
num=0;
if(flag1==0)
flag=0;
}
}
printf("%d",max);
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 4b25ad359571104d8774c43cf43b8bfa | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
main()
{
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int max=0;
int rest=0;
for(int i=0;i<n;i++)
{
if(a[i]==1)
{ rest++;
if(rest>max)
max=rest;
}
else if(a[i]==0)
{
if(rest>max)
max=rest;
rest=0;
}
}
if(a[n-1]==1 && a[0]==1)
{
int i=0;
while(a[i]==1)
{ rest++;
i++;
}
if(rest>max)
max=rest;
}
printf("%d\n",max);
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | a8892c22738de9529ea7c6283f044db5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int n, x, i, f=0, c=0, y, z=0, k=0;
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d", &x);
if(x==1)
{
c++;
f=1;
}
else
{
if(k==0){
y=c;
}
if(c>=z){
z=c;
}
c=0;
k=1;
f=0;
}
}
if(f==1 && c+y>z)
{
printf("%d", c+y);
}
else
{
printf("%d", z);
}
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 760c59efb63890ee30c609890ddbfd08 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int n,i,temp=0,max=0;
int *ptr;
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
arr[i]=-1;
ptr=arr;
for(i=0;i<n*2;i++){
if(*ptr==-1)
ptr=arr;
if(*ptr==1){
temp++;
}
if(*ptr==0){
if(temp > max)
max=temp;
temp=0;
}
ptr++;
}
printf("%d",max);
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 0c121337b4c87c541acf0db6f3eb2392 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
#include <math.h>
int main()
{
int n,m,num=0,k=0,i,a[200000],head=0,end=0,max=0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
if (a[0] == 1)num++;
for (i = 1; i < n; i++) {
if (a[i - 1] == 0) {
num = 0;
}
if (a[i] == 1)num++;
if (num > max)max = num;
}
if (a[0] == 1 && a[n - 1] == 1) {
for (i = 0; i < n; i++) {
if (a[i] == 1)num++;
else break;
}
}
if (num > max)max = num;
printf("%d", max);
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | f3ef51aa6c269df28771b83c5b7eae4f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
int main()
{
int n,count=0,max=0,flag=0;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
}
for(int i=0;;i++)
{
if(i>=n)
{
flag=1;
i-=n;
}
if(a[i]==0)
{
if(count>max)
{
max=count;
}
count = 0;
if(flag)
break;
}
else
{
count++;
}
}
if(count>max)
max=count;
printf("%d",max);
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 2db895be23b1d16f0b6a9d53add474f0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
int main()
{
int n,i,count=0,t=0;
scanf("%d",&n);
long int a[n+n];
for(i=0;i<n;i++)
{
scanf("%ld",&a[i]);
}
for(i=0;i<n;i++)
{
a[n+i]=a[i];
}
for (i=0;i<n+n;i++)
{
if(a[i]==1)
{
count=count+1;
if(t<count)
{
t=count;
}
}
else
{
count =0;
}
}
printf("%d",t);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | d5b374dde9e1d07b30a588c85625ce92 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main(){
int i,j=0;
int n;
scanf("%d",&n);
int arr[n*2];
int count[n*2];
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
arr[i+n]=arr[i];
count[i]=0;
}
arr[n]=arr[0];
count[n]=0;
for(i=0;i<=2*n;i++){
if(arr[i]==1){
count[j]++;
}
else{
j++;
}
}
int max=count[0];
for(i=0;i<n;i++){
if(count[i]>max){
max=count[i];
}
}
printf("%d",max);
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 3330502a6de8b8eb2c68d19253eeb68d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int i, j, n;
scanf("%d", &n);
int a[n * 2 + 2], max = 0, c = 0, d = 0;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = n; i < 2 * n; i++)
a[i] = a[d++];
for (i = 0; i < 2 * n; i++)
{
if (a[i] == 1)
c++;
else
{
if (c >= max)
max = c;
c = 0;
}
}
printf("%d", max);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 92a492d1061ff1a0636c941e93679596 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int h,i,j,k,l,c,p,v,ind=0;
scanf("%d",&h);
c = 0;
l = 0;
k = 0;
v = 0;
for(i=0;i<h;i++){
scanf("%d",&p);
if(p==1){
c = c + 1;
if(i==0){
k = 1;
}
else if(i+1==h){
c = c+ind;
if(c>l){
l = c;
}
}
}
else if(p==0){
if(v==0){
ind = i;
v = 1;
}
if(c>l){
l = c;
}
c = 0;
}
}
printf("%d",l);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 4d8c98814a2bb7ff71a2f032ff4efc4a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n*2],c=0,d=0,i,j=n,m=n;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
a[j] = a[i];
j++;
}
for(i=0;i<n*2;i++)
{
if(a[i]==1)
{
c = c+1;
if(c>d)
d = c;
}
else if(a[i]==0)
c = 0;
}
printf("%d\n",d);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | caf59cebf7009c46e83e76719d85319b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int i,n,a[200000],c=0,max=0;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==1)c++;
else
{
if(max<=c)max=c;
c=0;
}
}
if(a[n-1]==1)
{
for(i=0;a[i]==1;i++)c++;
}
if(max<=c)max=c;
printf("%d",max);
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 88da6ebd2df7f35387cf7d6198d990e9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,count=0,j=0,a,k,temp,max=0;
int b[200001];
int c[200001];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&b[i]);
}
for(i=0;i<2*n;i++){
if(b[i%n]==1){
count++;
}
else{
if(count>max){
max=count;
}
count=0;
}
}
printf("%d\n",max);
return 0;
} | |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 6ca26a01643f3ef5daa3ce0f2c54e773 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
#include<stdlib.h>
int main(){
int n;
scanf("%d",&n);
int *a=(int *)malloc(sizeof(int)*n);
int i,j;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
i=0;
int maxCounter=0;
int counter;
while(i<n){
j=i+1;
if(a[i]==1){
//printf("i = %d: ",i);
counter=1;
while(j<n){
if(a[j]==a[i]){
counter++;
j++;
}else{
break;
}
}
//printf("counter = %d\n",counter);
if(counter>maxCounter){
maxCounter=counter;
}
}
i=j;
}
counter=0;
if(a[0]==1 && a[n-1]==1){
for(i=0;i<n;i++){
if(a[i]==1){
counter++;
}else{
break;
}
}
for(j=n-1;j>=0;j--){
if(a[j]==1){
counter++;
}else{
break;
}
}
if(j<i){
counter=n;
}
}
//printf("counter = %d\n",counter);
if(counter>maxCounter){
maxCounter=counter;
}
printf("%d\n",maxCounter);
free(a);
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 6b07fa1c5164a4d60ed2421f2684722b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main()
{
int a[200001];
int n,y=0,z=0;
int i;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
int ans=0;
int x;
for(i=1;i<=n;i++)
{
if(a[i]==0)
{
x=0;
continue;
}
else
{
x++;
if(x>ans)
ans=x;
}
}
for(i=1;a[i]!=0;i++)
{
if(a[i]==1)
y++;
}
for(i=n;a[i]!=0;i--)
{
if(a[i]==1)
z++;
}
if(y+z>ans)
ans=y+z;
printf("%d",ans);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 6a6e11529b056afc923c3bcd9edd29b7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main(void)
{
int d,r, i, k=0;
scanf("%d", &d);
int h[2*d];
for(i=0; i<d; i++)
{
scanf("%d", &h[i]);
h[d+i]=h[i];
}
for(i=0; i<d*2; i++)
{
r=0;
while(h[i]==1)
{
r++;
i++;
}
if (r>k)
k=r;
}
printf("%d\n", k);
return 0;
}
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | b0901a940131c1e3f898d454e0835742 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include<stdio.h>
int main(void)
{
int n;
int mc=0;
scanf("%d",&n);
int arr[2*n];
for(int i=0; i<n; i++)
{
scanf("%d",&arr[i]);
arr[n+i]= arr[i];
}
for(int i=0; i<2*n; i++)
{
int c=0;
while(arr[i]==1)
{
c++;
i++;
}
if(c>mc)
{
mc=c;
}
}
printf("%d\n",mc);
}
/*
int d, h[100000],r, i, k=0;
scanf("%d", &d);
for(i=0; i<d; i++)
{
scanf("%d", &h[i]);
h[d+i]=h[i];
}
for(i=0; i<d*2; i++)
{
r=0;
while (h[i]==1)
{
r++;
i++;
}
if (r>k)
k=r;
}
printf("%d\n", k);
return 0;
}
*/
| |
Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day. | Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day. | C | fcd88c7b64da4b839cda4273d928429d | 45353066444c03f399a4b25562d2d775 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553006100 | ["5\n1 0 1 0 1", "6\n0 1 0 1 1 0", "7\n1 0 1 1 1 0 1", "3\n0 0 0"] | NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all. | PASSED | 900 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$. | ["2", "2", "3", "0"] | #include <stdio.h>
#define sf scanf
#define pf printf
int main(void) {
int x,first,ans1,ans2,ans=0;
sf("%d",&x);
sf("%d",&first);
if(first==1)ans1=1;
else ans1=0;
ans2=ans1;
int ans3=ans1;
int k=0;
for(int i=1;i<x;i++){
int y;
sf("%d",&y);
if(y==0){
if(k==0 && first==1 )ans3=ans1;
if(ans1>ans) ans=ans1;
ans1=0;
k++;
}
else ans1++;
}
if(ans1+ans3>ans) ans=ans1+ans3;
pf("%d",ans);
return 0;
}
| |
Let $$$c$$$ be some positive integer. Let's call an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers $$$c$$$-array, if for all $$$i$$$ condition $$$1 \leq a_i \leq c$$$ is satisfied. Let's call $$$c$$$-array $$$b_1, b_2, \ldots, b_k$$$ a subarray of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$, if there exists such set of $$$k$$$ indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ that $$$b_j = a_{i_j}$$$ for all $$$1 \leq j \leq k$$$. Let's define density of $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$ as maximal non-negative integer $$$p$$$, such that any $$$c$$$-array, that contains $$$p$$$ numbers is a subarray of $$$a_1, a_2, \ldots, a_n$$$.You are given a number $$$c$$$ and some $$$c$$$-array $$$a_1, a_2, \ldots, a_n$$$. For all $$$0 \leq p \leq n$$$ find the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$, such that density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. Find these numbers by modulo $$$998\,244\,353$$$, because they can be too large. | Print $$$n + 1$$$ numbers $$$s_0, s_1, \ldots, s_n$$$. $$$s_p$$$ should be equal to the number of sequences of indices $$$1 \leq i_1 < i_2 < \ldots < i_k \leq n$$$ for all $$$1 \leq k \leq n$$$ by modulo $$$998\,244\,353$$$, such that the density of array $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$ is equal to $$$p$$$. | C | 95c277d67c04fc644989c3112c2b5ae7 | 60b7b18cca72d9d0672b38fae6d10114 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"math"
] | 1557671700 | ["4 1\n1 1 1 1", "3 3\n1 2 3", "5 2\n1 2 1 2 1"] | NoteIn the first example, it's easy to see that the density of array will always be equal to its length. There exists $$$4$$$ sequences with one index, $$$6$$$ with two indices, $$$4$$$ with three and $$$1$$$ with four.In the second example, the only sequence of indices, such that the array will have non-zero density is all indices because in other cases there won't be at least one number from $$$1$$$ to $$$3$$$ in the array, so it won't satisfy the condition of density for $$$p \geq 1$$$. | PASSED | 3,500 | standard input | 6 seconds | The first line contains two integers $$$n$$$ and $$$c$$$, separated by spaces ($$$1 \leq n, c \leq 3\,000$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces ($$$1 \leq a_i \leq c$$$). | ["0 4 6 4 1", "6 1 0 0", "10 17 4 0 0 0"] | /* https://codeforces.com/contest/1158/submission/54045740 (ecnerwala) */
/* upsolve with Dukkha */
#include <stdio.h>
#include <string.h>
#define N 3000
#define C 3000
#define MD 998244353
#define L 11
long long power(int a, int k) {
long long p;
if (k == 0)
return 1;
p = power(a, k / 2);
p = p * p % MD;
if (k % 2 == 1)
p = p * a % MD;
return p;
}
int main() {
static int p2m1[N + 1], p2m1_[N + 1], p2[N + 1];
static int aa[N], kk[C], dp[N + 1][N + 1], dq[1 << L][N + 1], ans[N + 1];
int n, c, p, i, j, b, b_, l, bad, x;
long long w;
scanf("%d%d", &n, &c);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]), aa[i]--;
for (i = 0, p = 1; i <= n; i++) {
p2m1_[i] = power(p2m1[i] = (p2[i] = p) - 1, MD - 2);
p = p * 2 % MD;
}
dp[0][0] = 1;
if (c > L) {
for (j = 0; j < n; j++) {
memset(kk, 0, sizeof kk);
w = 1;
bad = c - 1;
for (i = j; i >= 0; i--) {
if (aa[i] != aa[j]) {
if (kk[aa[i]] == 0)
bad--;
else
w = w * p2m1_[kk[aa[i]]] % MD;
w = w * p2m1[++kk[aa[i]]] % MD;
}
if (bad == 0)
for (l = 0; l <= i / c; l++) {
x = dp[i][l];
if (x)
dp[j + 1][l + 1] = (dp[j + 1][l + 1] + w * x) % MD;
}
}
}
} else {
dq[0][0] = 1;
for (j = 0; j < n; j++) {
for (b = (1 << c) - 1; b >= 0; b--) {
b_ = b | 1 << aa[j];
for (l = 0; l <= j / c; l++)
dq[b_][l] = (dq[b_][l] + dq[b][l]) % MD;
}
for (l = 0; l < (j + 1) / c; l++) {
x = dq[(1 << c) - 1][l];
if (x) {
dp[j + 1][l + 1] = x;
dq[0][l + 1] = (dq[0][l + 1] + x) % MD;
dq[(1 << c) - 1][l] = 0;
}
}
}
}
for (i = 0; i <= n; i++)
for (l = 0; l <= n / c; l++)
ans[l] = (ans[l] + (long long) dp[i][l] * p2[n - i]) % MD;
ans[0] = (ans[0] - 1 + MD) % MD;
for (i = 0; i < n; i++)
ans[i] = (ans[i] - ans[i + 1] + MD) % MD;
for (i = 0; i <= n; i++)
printf("%d ", ans[i]);
printf("\n");
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 8de797fd10f5eef2f1b97fea40c96b22 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==0)
{
int i,j=1,k,a[n];
for(i=1;i<=n;i+=2)
{
a[j]=i+1;
a[j+1]=i;
j+=2;
}
for(k=1;k<=n;k++)
{
printf("%d ",a[k]);
}
}
else
printf("-1");
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 28bb567ecbc53ad3f56a5f225a43dcd6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
#include<math.h>
#include<stdlib.h>
long long int cmpp( const void * a,const void *b ){
return ( *(long long int *)a-*(long long int*)b);
}
char cmp(const void * a,const void *b){
return (*(char*)a-*(char*)b);
}
int main(void)
{
long long int test, i, j,flag = 0,n, o1 = 0, o2 = 0, x, m, l, max,y,temp,c, sum2, min, f,count=0, r, o, sum1, sum = 0;
long long int b[1000000]={0};
char a[1000000];
scanf("%lld",&n);
if(n%2==1){
printf("-1");
}else{
for(i=2;i<=n;i+=2){
printf("%lld %lld ",i,i-1);
}
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | ac1d44e9789ce8ed7606f13a69220884 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include<string.h>
#include<math.h>
int main(void){
// Your code here!
int test,n,c,o,d,e,r,i,fflag=0,flag=0,index,sum,m,l,j,z,b,k,count=0,a;
scanf("%d",&n);
if(n%2==1){
printf("-1");
}else{
//printf("%d %d %d %d",a,b,c,d);
for(i=2;i<=n;i+=2){
printf("%d %d ",i,i-1);
}
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 8b585330966ce4a4bbc0247f8180b9b4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,p=0,q=0,i,j;
scanf("%d",&n);
int b[n],a[n];
if(n%2!=0)
printf("-1");
else
{
for(int i=1;i<=n;i++)
{
if(i%2==0)
a[p++]=i;
else
b[q++]=i;
}
for(i=0,j=0;i<p,j<q;i++,j++)
{
printf(" %d %d",a[i],b[j]);
}
}
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | e036f10ab3819d2012268c86843708f5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int t;
scanf("%d",&t);
int a[t];
if(t==1||t%2!=0){
printf("-1");
}
else if(t%2==0){
for(int i=1;i<t;i+=2){
a[i]=i+1;
a[i+1]=i;
}
for(int j=1;j<=t;j++){
printf("%d ",a[j]);
}}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | c54085d5a98008da25874db36f2ad905 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2!=0){
printf("-1");
}
else{
for(i=n;i>=1;i--){
printf("%d ",i);
}
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 5c89fe887ac6dd1829b041f459199b9e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main() {
long long int i,c=0,e=0,f=0,d=0,k=0,g=0,n,sum=0,s,MaiorAB;
scanf("%lld",&n);
if(n%2==1){
printf("-1");
}
else if(n%2==0){
for(i=2;i<=n;i=i+2){
printf("%lld %lld ",i,i-1);
}}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 39ebd1fd2468dd7f712b814003a559d4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==1)
printf("-1");
else if(n%2==0)
{
for(i=n;i>0;i--)
{
printf("%d ",i);
}
}
/*else
{
for(i=n-1;i>=n/2;i--)
{printf("%d ",i);}
printf("%d ",n);
for(i=n/2-1;i>0;i--)
{printf("%d ",i);}
}
*/
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 06b264d5db7c9557768fe26ac63797d5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <string.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==1)
{
printf("-1\n");
}
else{
int i;
int b=n;
for(i=1;i<=n;i++)
{
printf("%d ",b);
b--;
}
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 4f679ad85ac135da3141184ec21b18b7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
if (n % 2 != 0) {
printf("-1\n");
return 0;
}
for (i = 2; i <= n; i += 2)
printf("%d %d ", i, i - 1);
printf("\n");
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 6b99287bac9943a1f5df89ee7328099f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==0)
{for(int i=1;i<=n;i++)
{
if(i%2==0)
printf("%d ",i-1);
else
printf("%d ",i+1);
}}
else
printf("-1");
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | a6dd39854aa0fb37123f0f302495a178 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main()
{
int i,j,a,b;
scanf("%d",&a);
if(a%2==1)
printf("-1");
else
for(i=1;i<=a;i+=2)
{
printf("%d %d ",i+1,i);
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 26200985931af3554a008f23be43a5da | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i;
scanf("%d", &n);
if (n%2 == 1)
printf("-1");
else
{
for (i = 0; i < n; i++)
{
if (i%2 == 0)
printf("%d ", i+2);
else
printf("%d ", i);
}
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | b5a97ecd88ee8c3ef11271e167fa00ac | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==1)
{
printf("-1");
return 0;
}
if(n%2==0)
{
for(i=n;i>=1;i--)
{
printf("%d ",i);
}
}
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 0005127f2d2b79ea8b5a28954300fd85 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main(void)
{
int n;
scanf("%d",&n);
if(n%2)
printf("-1");
else
{
int arr[105];
for(int i=0;i<n;i++)
arr[i]=i+1;
for(int i=0;i<n-1;i+=2)
{
arr[i]++;
arr[i+1]--;
}
for(int i=0;i<n;i++)
printf("%d ",arr[i]);
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 9e419f8395dbf2d107b2526c739629d8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main(void)
{
int n;
scanf("%d",&n);
if(n%2)
printf("-1");
else
{
for(int i=2;i<=n;i+=2)
printf("%d %d ",i,i-1);
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 61f2c1029401c1df20d877cc0aabb897 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
void swap(int*a,int*b)
{
int temp=*a;
*a=*b;
*b=temp;
}
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==0)
{
int a[n];
for(i=0;i<n;i++)
a[i]=i+1;
for(i=0;i<n;i=i+2)
swap(&a[i],&a[i+1]);
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
else
printf("-1");
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 783962c313068e6ee9738e75a3f4c274 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int i,n,d[100],m;
scanf("%d",&n);
if(n%2==1)
{
printf("-1");
}
else
{
for(i=1; i<=n; i++)
{
if(i%2==1)
{
if(i!=n)
{
d[i]=i+1;
}
else if(i==n)
{
m=d[i-2];
d[i-2]=i;
d[i]=m;
}
}
else if(i%2==0)
{
d[i]=i-1;
}
}
for(i=1; i<=n; i++)
{
printf("%d ",d[i]);
}
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | b482fda62d5105bb7ccba3968ab85436 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main(void)
{
int n,i;
scanf("%d",&n);
if(n%2) printf("-1");
else
{
for(i=0;i<n;i++)
{
if(i%2) printf("%d ",i);
else printf("%d ",i+2);
}
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | a33d383d817f6a7fe4265ca66559d2e8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i,temp;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
a[i]=i+1;
for(i=0;i<n-1;i++)
{
if(a[i]<a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
i++;
}
}
if(n==0 || n%2==1)
printf("-1");
else
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 2a0d01c2ab75a34b335b8a752ad98406 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d",&n);
int i;
if(n%2!=0){
printf("-1\n");
}else{
if(n>2){
for(i=1;i<=n-2;i++){
printf("%d ",i+1);
printf("%d ",i);
i++;
}
}
printf("%d ",n);
printf("%d\n",n-1);
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | bf1db99611c08f7c44dc09aa53d4d413 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int n;
scanf("%d",&n);
int i;
if(n%2!=0){
printf("-1\n");
}else{
if(n>2){
for(i=1;i<=n-2;i++){
printf("%d ",i+1);
printf("%d ",i);
i++;
}
}
printf("%d ",n);
printf("%d\n",n-1);
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 7f6000059dab7d485a07fbea479929f6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2!=0) printf("-1\n");
else
{
for(i=1;i<=n;i++)
{
if(i%2==0) printf("%d ",i-1);
else printf("%d ",i+1);
}
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 5b8d21281751c354813bd4046cd8f5af | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
int permu[100]={0};
int len,i,temp;
scanf("%d",&len);
if (len%2==0)
{
for (i=0;i<len;i++)
{
permu[i]=i+1;
}
for(i=0;i<len;i=i+2)
{
temp=permu[i];
permu[i]=permu[i+1];
permu[i+1]=temp;
}
for(i=0;i<len;i++)
{
printf("%d ", permu[i]);
}
}
else
printf("-1");
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 5d8f596ed88d0f261cc27e09759e00c2 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main() {
int n;
scanf("%d",&n);
if(n%2 == 1) {
printf("%d\n",-1);
}
else {
for(int i=n;i>0;i--) {
printf("%d ",i);
}
printf("\n");
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 15b5220bfb22ebf8cf15673ffb80f13d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i,j,k,m;
scanf("%d",&n);
if(n%2!=0)
{
printf("-1");
}
else
{
printf("2 1");
for(i=3;i<=n;i+=2)
printf(" %d %d", i+1, i);
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | aab8c03c17894f645d3bf940a9ff0405 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2 == 1){
printf("-1\n");
return 0;
}
int output[102] = {0}, i, j;
for(i = 1, j= 1; i <= n; ){
if(i == j){
output[++j] = i;
output[j-1] = ++i;
j++;
}
else output[j] = i++;
}
for(i = 1; i <= n; i++) if(output[i] != 0) printf("%d ",output[i]);
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 3ebfb38723a8656e9161ebf984de5317 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main()
{
int n,i,j;
scanf("%d",&n);
if(n%2!=0)
printf("-1");
else{
for(i=1;i<=n;i+=2)
printf("%d %d ",i+1,i);
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | d3529a3673eafda521ef8ae399499733 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
int main()
{
int n,i,j;
scanf("%d",&n);
if(n%2!=0)
printf("-1");
else{
for(i=n/2+1;i<=n;i++)
printf("%d ",i);
for(i=1;i<=n/2;i++)
printf("%d ",i);
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 6e494fb4e48128d285b33dafcf4113ec | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
main()
{
int n,i;
scanf("%d",&n);
if(n%2 ==1) printf("-1\n");
else
{
printf("2 1 ");
for(i=3;i<n;i+=2)
printf("%d %d ",i+1,i);
}
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 840576a8a359e40d85ce451a0c769b4e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n; //p(2k)=2k+1 :: p(2k+1)=2k
scanf("%d",&n);
if(n%2)
printf("-1");
else
{
for(int i=n;i>0;i--)
{
printf("%d ",i);
}
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 8065633311e89e175f466344ebc00edc | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int a,b,c,d,e,x,y,ara[100000],i,j;
scanf("%d",&a);
if(a%2!=0)
{
printf("-1");
}
else
{
for(i=1;i<=a-1;i=i+2)
{
printf("%d ",i+1);
printf("%d ",i);
}
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 52cc54ee910056d1ec965c40796cc087 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
int arr[n+1],i=1,ele=2;
for(i=0;i<=n;i++)
arr[i]=0;
i=1;
if(n%2==1)
printf("-1");
else{
while(i<=n&&ele<=n)
{
arr[i]=ele;
if(i%2==0)
ele+=3;
else
ele--;
i++;
}
for(i=1;i<=n;i++)
printf("%d ",arr[i]);
printf("\n");
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 18d0e477495e2431afab33c696cae27c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,i,j;
scanf("%d",&n);
if(n%2==0){
for(i=1;i<=n;i++){
if(i%2==0)
printf("%d %d ",i,i-1);
}
}
else
printf("-1\n");
return 0;
} | |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | a3373348ea7996eea0e1260c10375e20 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==1)
printf("-1");
else{
for(i=1;i<n;i=i+2)
printf("%d %d ",i+1,i);
}
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | edcfe4921086264e67e4d94e69f9e910 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==1)
{
printf("-1");
}
else
{ printf("2 1 ");
for(i=3;i<n;i=i+2)
{
printf("%d %d",i+1,i);
printf(" ");
}
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 8401dac5a86247bc237a340cfb0ec18a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
if(n%2==1)
{
printf("-1\n");
}
else
{
for(i=n;i>0;i--)
{
printf("%d ",i);
}
}
return 0;
}
| |
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n. | If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces. | C | 204ba74195a384c59fb1357bdd71e16c | 2931fcc464c0405edae8007d5ab7fd3a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"math"
] | 1349969400 | ["1", "2", "4"] | null | PASSED | 800 | standard input | 2 seconds | A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size. | ["-1", "2 1", "2 1 4 3"] | #include<stdio.h>
int main()
{
int n,k=1;
scanf("%d",&n);
if(n%2==1)
printf("-1");
else
{
for(int i=0;i<n;i++)
{
if(i%2==0)
{
printf("%d ",2*k);
k++;
}
else
printf("%d ",i);
}
}
return 0;
} | |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | ce7fcefddfdddd4926e8797ac54b1d4b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include <stdio.h>
long long Sum[200001];
int main()
{
int n, m;
long long a, b;
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i) {
scanf("%I64d", &a);
Sum[i] = Sum[i - 1] + a;
}
while(m--) {
scanf("%I64d", &b);
int l = 0;
int r = n;
while(l <= r) {
int mid = (l + r) / 2;
if(b <= Sum[mid] && b > Sum[mid - 1]) {
printf("%d %I64d\n", mid, b - Sum[mid - 1]);
break;
} else if(b > Sum[mid]) {
l = mid + 1;
} else {
r = mid;
}
}
}
return 0;
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | bf61923d19e234bdd248c75e508f1e48 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
#define N 200002
int main(){
int n,m;
scanf("%d%d",&n,&m);
int i,j;
long long sum[N];
long long a[N];
sum[0]=0;
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
}
/*
for(i=0;i<=n;i++){
printf(" %d:%lld",i,sum[i]);
}
printf("\n");
*/
long long b;
int f=0;
int l=0;
int r=n-1;
long long k=0;
j=1;
for(i=0;i<m;i++){
scanf("%lld",&b);
while(1){
if(j>n)break;
if(b>sum[j-1] && b<=sum[j]){
//printf("%lld %lld %lld\n",sum[j-1],b,sum[j]);
f=j;
k=b-sum[j-1];
break;
}
j++;
}
j--;
printf("%d %lld\n",f,k);
//printf("------\n");
}
return 0;
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | 3dc973896a4744435767c732f279a1a4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r", stdin);
freopen("output.txt","w", stdout);
#endif
int n,m,i,j;
scanf("%d%d",&n,&m);
int long long dorm[n+1],letter[m];
dorm[0]=0;
for (i=1;i<=n;i++)
{
scanf("%lld",&dorm[i]);
dorm[i]+=dorm[i-1];
}
for(i=0;i<m;i++)
scanf("%lld",&letter[i]);
i=1;
for(j=0;j<m;j++)
{
if (dorm[i]-letter[j]>=0)
{
printf("%d %lld\n",i,letter[j]-dorm[i-1]);
i--;
}
else
j--;
i++;
}
return 0;
} | |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | 463f6e05827481e90e13a2ec2172d555 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
int main()
{
int n,m,i,j,a=1;
scanf("%d %d",&n,&m);
long long int x[n+1],y[m]; x[0]=0;
for(i=1;i<=n;i++)
{
scanf("%lld",&x[i]);
x[i]+=x[i-1];
}
for(i=0;i<m;i++)
{
scanf("%lld",&y[i]);
for(j=a;y[i]>x[j];j++); a=j;
printf("%d %lld\n",a,y[i]-x[j-1]);
}
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | 69374ef0371e1136b51730d116d6b314 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m;
long long x,k=0;
long long dorm[200001]={0},lett[200001]={0},d[200001]={0};
scanf("%d %d",&n,&m);
for (int i=0; i<n; i++)
{
scanf("%I64d",&x);
if (i==0)
dorm[i]=x;
else
dorm[i]=dorm[i-1]+x;
}
for (int i=0; i<m; i++)
{
scanf("%I64d",&x);
for (int j=k; dorm[j]<x; j++,k++);
d[i]=k;
if (k>0)
lett[i]=x-dorm[k-1];
else
lett[i]=x;
}
for (int i=0; i<m; i++)
{
printf("%I64d %I64d\n",d[i]+1,lett[i]);
}
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | 9662c31c87c4c1cb91fb761bbe4b4a25 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdbool.h>
#include<math.h>
#define INFINI 10000000
#define LLD "%l" "ld"
struct element
{
int value;
int pos;
};
typedef struct element element;
element tab[1001];
int compare(const void * p1,const void * p2)
{
element * p=(element *)p1;
element * q=(element *)p2;
return p->pos-q->pos;
}
int main ()
{
long long numofbuilding,numoflettres;
scanf("%lld %lld",&numofbuilding,&numoflettres);
long long nbrofrooms[numofbuilding+1];
nbrofrooms[0]=0;
for(long long i=1;i<=numofbuilding;i++)
{
long long in;
scanf("%lld",&in);
nbrofrooms[i]=nbrofrooms[i-1]+in;
}
long long j=1;
for(long long i=0;i<numoflettres;i++)
{
long long lettre;
scanf("%lld",&lettre);
while(lettre>nbrofrooms[j]&&j<=numofbuilding)
j++;
printf("%lld %lld\n",j,lettre-nbrofrooms[j-1]);
}
printf("\n");
return 0;
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | 6966aaa4bce6b2719d7d903df55cfa49 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
int main()
{
long long int n,m,i,comp,p,ara[200005],low,high,mid,ans;
scanf("%lld%lld",&n,&m);
ara[0]=0;
for(i=1;i<=n;i++){
scanf("%lld",&ara[i]);
ara[i]=ara[i]+ara[i-1];
}
ara[n+1]=ara[n]+1;
for(i=1;i<=m;i++){
scanf("%lld",&comp);
low=1;
high=n;
ans=low;
while(low<high){
mid =(low + high)/2;
if(ara[mid]<comp){
low=mid+1;
ans=low;
}
else {
high=mid;
ans=high;
}
}
printf("%lld %lld\n",ans,comp-ara[ans-1]);
}
return 0;
} | |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | ec28f4ccf4c2fe8d7d50ade151f856d4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
int main()
{
int n,m,i,x,y,j;
scanf("%d %d",&n,&m);
long long int a[n],p,b[m],s=0;
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
a[n]=0;
for(i=0;i<m;i++)
scanf("%lld",&b[i]);
i=0;
s=0;
for(j=0;j<m;j++){
while(i<n+1){
if(s<b[j]){
p=s;
s=s+a[i];
i++;
}
if(s>=b[j]){
x=i;
printf("%d %lld\n",x,b[j]-p);
break;
}
}
}
} | |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | d061edcd3eec9ac3749c29182ce98681 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include<stdio.h>
#define MAX 200000
typedef long long ll;
ll main()
{
ll n,m,a[MAX],b,add=0,l=0;
scanf("%lld %lld %lld",&n,&m,&a[0]);
for(ll i=1;i<n;i++)
{
scanf("%lld",&add);
a[i]=a[i-1]+add;
}
while(m--)
{
scanf("%lld",&b);
ll r=n-1,mid;
while(r>l)
{
mid=(l+r)/2;
if(a[mid]>b)
r=mid-1;
else if(a[mid]<b)
l=mid+1;
else
{
r=mid;
l=mid;
}
}
if(b>a[l])
l++;
if(l==0)
printf("%lld %lld\n",l+1,b);
else
printf("%lld %lld\n",l+1,b-a[l-1]);
}
return 0;
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | e44fd4c31e04f90ff8200416326115da | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int binsearch(int n, long long int size[], long long int room) {
int lo = 0;
int hi = n;
while (hi > lo) {
int mid = (hi+lo)/2;
if (size[mid] >= room) {
hi = mid;
} else {
lo = mid+1;
}
}
if (size[lo] >= room) {
lo--;
}
return lo;
}
int main(void) {
int n, m;
scanf("%d%d", &n, &m);
long long int size[n+1];
size[0] = 0;
long long int sum = 0;
for (int i = 1; i <= n; i++) {
long long int s;
scanf("%lld", &s);
sum += s;
size[i] = sum;
}
for (int i = 0; i < m; i++) {
long long int room;
scanf("%lld", &room);
int dorm = binsearch(n, size, room)+1;
//printf("room: %lld; dorm: %d\n", room, dorm);
room -= size[dorm-1];
printf("%d %lld\n", dorm, room);
}
}
| |
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered. | Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ — the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter. | C | 56bdab2019ee12e18d4f7e17ac414962 | c6f3b80a408487cfa16b7c6d58ec41e0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"two pointers",
"binary search",
"implementation"
] | 1526202300 | ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"] | NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory | PASSED | 1,000 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ — the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order. | ["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"] | #include <stdio.h>
int main(void)
{
long long int n,i,j,sum=0,m,e=0;
scanf("%lld%lld",&n,&m);
long long int a[n],b[m],d,c=0;
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(i=0;i<m;i++)
{
scanf("%lld",&b[i]);
}
sum=a[0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(b[i]<=sum)
{
d=b[i]-c;
if(d==0)
d=a[j+1];
printf("\n%lld %lld ",e+1,d);
break;
}
else
{
sum+=a[e+1];
c+=a[e];
e++;
}
}
// printf("%d ",sum);
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.