prob_desc_description
stringlengths
63
3.8k
prob_desc_output_spec
stringlengths
17
1.47k
lang_cluster
stringclasses
2 values
src_uid
stringlengths
32
32
code_uid
stringlengths
32
32
lang
stringclasses
7 values
prob_desc_output_to
stringclasses
3 values
prob_desc_memory_limit
stringclasses
19 values
file_name
stringclasses
111 values
tags
listlengths
0
11
prob_desc_created_at
stringlengths
10
10
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_notes
stringlengths
4
3k
exec_outcome
stringclasses
1 value
difficulty
int64
-1
3.5k
prob_desc_input_from
stringclasses
3 values
prob_desc_time_limit
stringclasses
27 values
prob_desc_input_spec
stringlengths
28
2.42k
prob_desc_sample_outputs
stringlengths
2
796
source_code
stringlengths
42
65.5k
hidden_unit_tests
stringclasses
1 value
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
34f3f9951bbba90c280194ef4c29c3b8
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> #include<stdlib.h> long int partition(long int a[],long int l,long int u) { long int v,i,j,temp; v=a[l]; i=l; j=u+1; do { do i++; while(a[i]<v&&i<=u); do j--; while(v<a[j]); if(i<j) { temp=a[i]; a[i]=a[j]; a[j]=temp; } }while(i<j); a[l]=a[j]; a[j]=...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
8f7d7988cf593c7f7580c0da1441756e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> long long int count; void merge(long long int arr[],long long int l,long long int m,long long int r) { long long int i,j,k,a; long long int x = m-l+1; long long int y = r-m; long long int left[x],right[y]; for(i=0;i<x;i++) { left[i] = arr[l+i]; } for(i=0;i<y...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
7ca1fdcf960a56f5720ffc49755a940d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> #include<string.h> int arr[200005]; int temp[200005]; void merge(int l, int r, int m) { int count1=0,count2=0,count3=0; while(count1<m-l+1 && count2<r-m) { if(arr[l+count1]<arr[m+1+count2]) { temp[count3]=arr[l+count1]; count1++; count3++; } else { temp[count3]=arr[m+1+count2]...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
b8af1b4c7fe791771f570a9e9f51960c
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> typedef long long int ll; void merge(ll arr[], ll l, ll m, ll r) { ll i, j, k; ll n1 = m - l + 1; ll n2 = r - m; /* create temp arrays */ ll L[n1], R[n2]; /* Copy data to temp arrays L[] and R[] */ for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
5fae256d3dcdb7b72508275c1d170f1b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> #include<stdlib.h> # define lli long long int int a[200007]={0},b[200007]={0}; int compare(const void* a, const void* b) { const int* x = (int*) a; const int* y = (int*) b; if (*x > *y) return 1; else if (*x < *y) return -1; return 0; } void merge(int arr[],lli start,lli mid,lli end) { ...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
360a8fd0dee0d0ae27b3908e4ff3b09f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include <stdio.h> #include <stdlib.h> int compare(const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main () { int n, k; int *arr; scanf("%d %d", &n, &k); arr = calloc(n, sizeof(int)); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } qsort(arr, n...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
10299592e895cd4085d052cbbf261d72
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include <stdio.h> #include <stdlib.h> void bubble_sort(int arr[], int n){ int i, j; for (i=0;i<n;i++){ for(j=0;j<n-i-1;j++){ if (arr[j]>arr[j+1]){ swap_element(&arr[j],&arr[j+1]); } } } } void swap_element(int *a, int *b){ int temp = *a; ...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
c6ece58a8fd9a11684eb8b73f5a92cf5
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> #include<stdlib.h> int comp(const void*first,const void*second) { return (*(int*)first-*(int*)second); } int main() { long long int a[200005]={},n,k,i,j; scanf("%lld %lld",&n,&k); for(i=0;i<n;i++) { scanf("%lld",&a[i]); } qsort(a, n, sizeof(long long int), comp); ...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
078504522c223fa51d3be27e56d6661f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> #include<limits.h> void sort(long long int arr[],int n) { long long int min,temp,index; for(int i=0;i<n-1;i++) { min = arr[i]; index = i; for(int j=i+1;j<n;j++) { if(min>arr[j]) { min = arr[j]; ...
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal ele...
Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes).
C
55297e2a65144323af4d6abd6a6ef050
6a3cbfb3a549626acafb13a9fcc1ffa9
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings" ]
1567258500
["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"]
NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this...
PASSED
1,200
standard input
2 seconds
The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.
["6", "-1"]
#include<stdio.h> #include<limits.h> void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int arr1[n1], arr2[n2]; for(int i=0;i<n1;i++) { arr1[i] = arr[l + i]; } for(int j=0;j<n2;j++) { arr2[j] = arr[m+1+j]; } ...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
d931c667c2d542051875147432f6d375
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #define N 110 int emp, lan, ans = 0, non = 0; int num_lan[N][N], lan_link[N][N], marked[N], emp_lan[N]; void dfs (int x) { int j; marked[x] = 1; for (j = 0; j < lan; j++) { if (lan_link[x][j] && !marked[j]) { dfs (j); } } } int main() { int i, j, k, l; scanf("%d %d", &emp...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
ee16c86468f6a6614880349fb7f5f60d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> #include<string.h> int lang[105],re[105],p[105]; int fin(int x) { if(re[x]==x) return x; else return fin(re[x]); } int main() { int n,m; int i,j,flg; int k,a; int sum1=0,sum2=0; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) re[i]=i; for(i=1;i<=n;i++) { ...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
62365fec84d26ad061907d04ab47962f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> #include<stdlib.h> #include<string.h> struct node { int val; struct node* next; }; typedef struct node node; node* insert(node* head, int data) { node* newnode=(node*)malloc(sizeof(node)); newnode->val=data; newnode->next=NULL; if(!head) head=newnode; else {...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
a1a1628a9a83980be8633e44d61cfdfc
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> int f[105]; int fa(int x) { int z=x,y; while (f[z]!=z) z=f[z]; while (x!=z) { y=f[x]; f[x]=z; x=y; } } int main() { int i,j,n,m,ans=0; int b[105][105]={0}; scanf("%d%d",&n,&m); for (i=1;i<=n;i++) { int x,y; scanf("%d",&x); for (j=1;j<=x;j++) { scanf("%d",&y); b[i][y]=1; ...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
ec756c2647277615b7493921ebe798e3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define NO_ID 0 static unsigned langs[101]; static bool seen[101]; int main() { unsigned n_employees, n_langs, n_cur_langs, *cur_langs, id, my_id, cur_id, cost, graphs, i, j, k; cost = 0; graphs = 0; id = NO_ID; sca...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
0cc9c2d7a4e5ef11ef361de18fa0cf79
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> int n; char lang[128][128], mat[128][128]; char mark[128]; int dfs(int x) { int i; if ( mark[x] ) return 0; mark[x] = 1; for ( i = 0; i < n; ++i ) if ( mat[x][i] ) dfs(i); return 0; } int main() { int i, j, k, m, nol = 1; scanf("%d%d", &n, &m); for ( i = 0; i < n; ++i ) { scanf("...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
da394ca1bfa85263bc773e1754505054
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> #include<stdlib.h> #define M 100 int main(){ int **graph,n,m,k,i,j,val,*l,*w,found2, found,count; scanf("%d",&n); scanf("%d",&m); if(n<1||n>100||m<1||m>100) return -1; graph=malloc(n*sizeof(int *)); for(i=0; i<n; i++){ graph[i]=malloc(m*sizeof(int)); } ...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
d847f9a0fea1ba0972eff05f12bbf71b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct _node *link; typedef struct _node { link next; int value; } node; typedef struct _vertex { link adj; int set; } vertex; void dfsColor(vertex arr[], int colored[], int length, int start); int numDisjoint(vertex arr[], int lengt...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
4865c7a0f09527eecdfa0b4501978549
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int n, m; int a[101][101]; int v[101]; int visit(int x) { int i, j; if (v[x] == 1) return 0; v[x] = 1; for (j=1; j<=m; j++) { if (a[x][j] == 1) { for (i=1; i<=n; i++) { if (a[i][j] == 1) { visit(i); } } ...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
1541f3959a75bc2e8f2e013b25b481d3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
// contest 277 problem A - round 170 #include<stdio.h> #define MAX_V 110 #define MAX_E 10010 // knowsLanguage[i][j] is set if person i knows language j int knowsLanguage[MAX_V][MAX_V]; // observe the 110's, generally declare slightly more memory than is necessary // For constructing the graph int to[MAX_E], next[MA...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
4f9d070fde5c3ff1b0e65086513e55e2
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> typedef struct { int k; char visit; unsigned int flag[4]; } Employee_t; Employee_t A[100]; int InSet(int i, int j) { int res = 0; res |= A[i].flag[0] & A[j].flag[0]; res |= A[i].flag[1] & A[j].flag[1]; res |= A[i].flag[2] & A[j].flag[2]; res |= A[i].flag[3] & A[j].fl...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
5c60e843455e0ea5edccae9a444c3fde
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#define N 101 #include<stdio.h> //对于某一个人一个语言都不懂的情况,需要单独处理! int n,m; int connection[N][N]; int visited[N]; void bfs(int who){ int start=0; int end=0; int queue[N]; int i; queue[end]=who; visited[queue[end]]=1; end++; while(start<end){ int top=queue[start]; start++; for(i=0;i<n;i++){ if(connection[i][top...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
9e93cd3cef94370ddcb2fdda1c8d424f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#define N 101 #include<stdio.h> //对于某一个人一个语言都不懂的情况,需要单独处理! int n,m; int connection[N][N]; int visited[N]; void bfs(int who){ int start=0; int end=0; int queue[N]; int i; queue[end]=who; visited[queue[end]]=1; end++; while(start<end){ int top=queue[start]; start++; for(i=0;i<n;i++){ if(connection[i][top...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
b49d871f1e818e32f2dbc7e64f66a2fd
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define MOD 1000000007 struct nod { int val,d,par,finish_time,weight,num; char color; struct nod *next,*par_node; }; void init(int num_v,struct nod *p[num_v],struct nod *vr[num_v]){ int i=1; while(i<num_...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
89b225dc617ac66cf9a2a841c2b72ff4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> typedef struct link1 { int d; struct link1 *next; }node; node *a[100005],*b[100005],*c[100005]; int n,m,s,d; int top=-1; //int front,rear; int visited[100005]; int stack[100005]; void print() { int i; for(i=1;i<=n;i++) { node *v=a[i]; whi...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
9c1da095ff7529b3158bc93d46a25caa
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #define N 110 int n, m; int e[N][N], l[N][N], ln[N], v[N]; void dfs(int x) { int i; v[x] = 1; for (i = 0; i < m; ++i) { if (e[x][i] && !v[i]) { dfs(i); } } } int main(void) { int i, j, k; int ans = 0, non = 0; scanf("%d%d", &n, &m); for (i = 0; i < n; ++i) { sc...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
85e5574fff990edfe5da312c78814f44
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #define SIZE 100 int link (int lang[][SIZE], int m, int a, int b) { int i; for (i = 0; i < m && (lang[a][i] != 1 || lang[b][i] != 1); i++) ; return i < m; } void dfs (int v, int n, int m, int lang[][SIZE], int clr[SIZE]) { int i = 0; clr[v] = 1; for (i = 0; i < n; i++) if (clr[i] == 0...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
afd0f825d3250261f19c06db8747bdb7
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> int t[101][101]; typedef struct { int to , nextid; }lang; lang LE[1001000]; int L[101]; int visited[101]; void dfs (int a) { visited[a]=1; int i; for(i=L[a];i!=-1;i=LE[i].nextid) { if(!visited[LE[i].to]){ ;dfs(LE[i].to);} } } int main() { int n,...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
63b64f82844e6776c77c8d5bd6dc3234
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> int t[101][101]; typedef struct { int to , nextid; }lang; lang LE[1001000]; int L[101]; int visited[101]; void dfs (int a) { visited[a]=1; int i; for(i=L[a];i!=-1;i=LE[i].nextid) { if(!visited[LE[i].to]){ ;dfs(LE[i].to);} } } int main() { int n,...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
6a0cf4bcdd82e679dc32782547b3665c
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> int v[110]; int e[110][110]; int l[110][110]; int visit(int i); int main(){ int i,j,n,m,r,o; scanf("%d %d",&n,&m); for(i=1,o=0;i<=n;i++){ scanf("%d",e[i]); o|=e[i][0]; for(j=1;j<=e[i][0];j++){ scanf("%d",e[i]+j); l[e[i][j]][++l[e[i][j]][0]]=i...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
b9a5e30f1480713f02f50ad08e3a027b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> int n,m; int v[110]; int k[110][110]; int visit(int i); int main(){ int i,j,l,p,b; scanf("%d %d",&n,&m); b=p=0; for(i=1;i<=n;i++){ scanf("%d",&l); b|=l; while(l--){ scanf("%d",&j); k[i][j]=1; } } for(i=1;i<=n;i++){ ...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
e6ae1ec1a7a9a9ca31452f95491815af
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { static int ID_linguaggi[100]; static int *linguaggi_curr; int N, M; int temp,i,t; int temp2; int curr; int graph_names=0; int grafi=0; int monete=0; scanf("%d %d", &N, &M); //memset(ID_linguaggi,-1,sizeof(i...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
45aaf75a1cac747c2355596ac36697b5
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include<stdio.h> int i,j,n,m,x,y,s,t,d,h[102],hh[102],hhh[102],u,uu,p; int a[102][102]; void parca(int i) { int j,k; h[i]=1; if(!hh[i]) s++; else return; hh[i]=1; for(j=1;j<=m;j++) { if(a[i][j] && !hhh[j]) hhh[j]=1; } for(j=1;j<=n;j++) { if(!h[j]) { d=0; for(k=1;k<=m;k++) { if(a[j]...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
a8f297274a75acac54d6dcb255f69431
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
/* Problem: 277A - Learning Languages */ /* Solver: Gusztav Szmolik */ #include <stdio.h> struct stack { unsigned short r; unsigned short c; }; unsigned short t[100][100]; unsigned short v[100]; struct stack st[99]; int main () { unsigned short n; unsigned short m; unsigned short...
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language...
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
C
e2836276aee2459979b232e5b29e6d57
95dcc14251758aed345fe786ece6ec33
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "dfs and similar" ]
1362065400
["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0"]
NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.
PASSED
1,400
standard input
2 seconds
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki intege...
["0", "2", "1"]
#include <stdio.h> #define MAXV 111 int parent[MAXV],rank[MAXV]; void init(int n) { int i; for(i=0;i<n;i++) { parent[i] = i; rank[i] = 1; } } int root(int x) { if(parent[x] != x) parent[x] = root(parent[x]); return parent[x]; } void connect(int x,int y) { int rx = root(x); int ry = root(y); if(rx == ...
Let's call two strings $$$s$$$ and $$$t$$$ anagrams of each other if it is possible to rearrange symbols in the string $$$s$$$ to get a string, equal to $$$t$$$.Let's consider two strings $$$s$$$ and $$$t$$$ which are anagrams of each other. We say that $$$t$$$ is a reducible anagram of $$$s$$$ if there exists an integ...
For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise.
C
eb5c93620709436493b2e560a63dbb02
8447d0422d3123391494a31411a1507a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "two pointers", "data structures", "binary search", "strings" ]
1580652300
["aaaaa\n3\n1 1\n2 4\n5 5", "aabbbbbbc\n6\n1 2\n2 4\n2 2\n1 9\n5 7\n3 5"]
NoteIn the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itsel...
PASSED
1,800
standard input
2 seconds
The first line contains a string $$$s$$$, consisting of lowercase English characters ($$$1 \le |s| \le 2 \cdot 10^5$$$). The second line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$)  — the number of queries. Each of the following $$$q$$$ lines contain two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le...
["Yes\nNo\nYes", "No\nYes\nYes\nYes\nNo\nNo"]
#include<stdio.h> #include<string.h> int main() { char s[200005]; scanf("%s", s); int n = strlen(s); int i, j; int count[200005][30]; for (j = 0; j < 30; j++) count[0][j] = 0; for (i = 0; i < n; i++) { for (j = 0; j < 30; j++) count[i + 1][j] = count[i][j]; count[i + 1][s[i] - 'a']++; } int q; scanf...
Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation , where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permutation p in the lexicographical order.For example, Perm(0) = (0, 1, ..., n - 2, n -...
Print n distinct integers from 0 to n - 1, forming the sum of the given permutations. Separate the numbers by spaces.
C
ade941d5869b9a0cb18dad1e6d52218b
451eeb1561bb746e7f28e4ec0658acd7
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "data structures", "binary search", "math" ]
1421053200
["2\n0 1\n0 1", "2\n0 1\n1 0", "3\n1 2 0\n2 1 0"]
NotePermutations of numbers from 0 to 1 in the lexicographical order: (0, 1), (1, 0).In the first sample Ord(p) = 0 and Ord(q) = 0, so the answer is .In the second sample Ord(p) = 0 and Ord(q) = 1, so the answer is .Permutations of numbers from 0 to 2 in the lexicographical order: (0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2...
PASSED
2,000
standard input
2 seconds
The first line contains an integer n (1 ≤ n ≤ 200 000). The second line contains n distinct integers from 0 to n - 1, separated by a space, forming permutation p. The third line contains n distinct integers from 0 to n - 1, separated by spaces, forming permutation q.
["0 1", "1 0", "1 0 2"]
/* practice with Dukkha */ #include <stdio.h> #define N 200000 #define N_ (1 << 18) /* N_ = pow2(ceil(log2(N))) */ int tr[N_ + N_], n_; void build() { int i; for (i = n_; i < n_ + n_; i++) tr[i] = 1; for (i = n_ - 1; i >= 0; i--) tr[i] = tr[i << 1] + tr[i << 1 | 1]; } int query(int l, int r) { int x = 0; ...
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number t equals xa1 + a2 + ... + an. Now Simon wants to r...
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
C
4867d014809bfc1d90672b32ecf43b43
ba2f884b2cc31c29b315012446e33cc9
GNU C
standard output
256 megabytes
train_002.jsonl
[ "number theory", "math" ]
1383379200
["2 2\n2 2", "3 3\n1 2 3", "2 2\n29 29", "4 5\n0 0 0 0"]
NoteIn the first sample . Thus, the answer to the problem is 8.In the second sample, . The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.In the fourth sample . Thus, the answer to the problem is 1.
PASSED
1,900
standard input
1 second
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
["8", "27", "73741817", "1"]
#include<stdio.h> #define MOD 1000000007 typedef unsigned long long llu; llu arr[100009]; llu expmod(llu a, llu x, llu n){ if(n==0)return a % MOD; else if(n%2==0)return expmod(a, x*x%MOD, n/2); else return expmod(a*x%MOD, x, n-1); } // ([x,arr,n] + k*x^a) / (x^sum) llu g(llu arr[], llu n, llu a, llu k, llu su...
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an.Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number t equals xa1 + a2 + ... + an. Now Simon wants to r...
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
C
4867d014809bfc1d90672b32ecf43b43
3067b588ea805229f1fe2b3886424a7f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "number theory", "math" ]
1383379200
["2 2\n2 2", "3 3\n1 2 3", "2 2\n29 29", "4 5\n0 0 0 0"]
NoteIn the first sample . Thus, the answer to the problem is 8.In the second sample, . The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.In the fourth sample . Thus, the answer to the problem is 1.
PASSED
1,900
standard input
1 second
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
["8", "27", "73741817", "1"]
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) #define ll long long #define M 1000000007 void intSort(int d[],int s){int i=-1,j=s,k,t;if(s<=1)return;k=(d[0]+d[s-1])/2;for(;;){while(d[++i]<k);while(d[--j]>k);if(i>=j)break;t=d[i];d...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
9c2de92c57c1f64d7c57f68e947e9362
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. ***********************************************...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
aedcfe5937aa1ea1e50ced47e9ac2e3f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include<stdio.h> char str[2000001]; int main() { int i,n,k; scanf("%d%d",&n,&k); int s=k; getchar(); gets(str); if(k>0&&str[0]!='1') { str[0]='1'; k--; } for(i=1;(i<n&&k>0);i++) { if(str[i]!='0') { str[i]='0'; k--; ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
46214ee69962ac1d4dce26a862624361
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include<stdio.h> int main() { long long int n,m,i,j,ara[10000],count=0; char ch[500000]; scanf("%I64d %I64d",&n,&m); getchar(); gets(ch); if(m==0) { for(i=0;i<n;i++) { printf("%c",ch[i]); } } else if(n==1 && m!=0) { printf("0"); } else if(n>1 && m...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
4e798996f2771345fcf3e0a5274d1872
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { int n, k; scanf("%d %d", &n, &k); char num[n]; scanf("%s", num); if(n==1 && k>=1) { printf("%c\n", '0'); return 0; } else { if(num[0]!='1' && k>0) { num[0]='1'; ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
0753bdf54ccfd8f29e8ccf5c465d9a2e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> // Problem URL: https://codeforces.com/contest/1230/problem/B int main() { unsigned long n, k; scanf("%lu%lu", &n, &k); // Allocating extra char for negative sign. // Problem did not say one way or another // whether th...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
5bdcfa7bb9681fadfed3943b4b2cfbf8
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> #include <string.h> int main() { char s[200001]; int n, k; scanf("%d %d %s", &k, &n, s); if (strlen(s)==1) { if (n==0) printf("%s", s); else printf("0\n"); } else { int c; if (s[0]=='1') c=0; else { if (n!=0) { s[0]='1'; c=1; } } for (int i=1;s[i]!='\0'&&c<n;i++) { ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
bc1306bf4b06ef63803f123aadd6197e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> int main() { char a[200010]; int p,n,k,h,j,i; scanf("%d %d",&n,&k); scanf("%s",a); if(k!=0){ if(n>1){ if(a[0]!='1') { a[0]='1'; k--; } for(int j=1;j<n && k>0;j++) { if(a[j]!='0') { a[j]='0'; k--; } } } else { a[0]='0'; a[1]='\...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
6bd89bee1e03b863d1c44ec204727cbc
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> int main(void) { char s[200005]; int n,j=0,k; scanf("%d %d %s",&k,&n,s); if(k==1 && n==1) s[0]='0'; else for(int i=0;i<n;i++){ for(;s[j]!='\0';j++){ if(j==0 && s[j]!='1'){ s[j]='1'; break; } else if(j!=0 && s[j]!='0'){ ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
b4dcf1dfc25443b04d4f36a953a784bd
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> char a[200001]; int n,k, i, count; int main() { scanf("%d %d", &n, &k); scanf("%s", &a); if (k == 0){ printf("%s",a); return 0; } if (a[1] != '\0') { if (a[0] != '1') { a[0] = '1'; count = 1;} else count = 0; i = 0; while (count < k && i < n-1) { ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
6467f0c742d7493a06885d8e9e175eae
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include<stdio.h> int main() { int n,k,i,j; char s[200000]; scanf("%d %d",&n,&k); j=k; scanf("%s",s); if((s[0]!= '1')&&(k>0)) { s[0]='1'; k--; } for(i=1;(k>0)&&(i<n);i++) { if(s[i]!= '0') { s[i]='0'; k--; } } ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
192e9988c6301086e98bde1dedb1dfb0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> //#include "yusr.c" //#define TEST //take input as char // replace first with 1 and following ones with 0 int main() { char digit[2000000]; int x; int l; int c; x= scanf("%d %d",&l,&c); getchar(); #ifdef TEST SHOWi(x); #endif x= scanf("%s",digit); getchar(); #ifdef TEST...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
99043a64de170f0ad98e6f169ad641cc
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include<stdio.h> int main() { int n,k,i,j; scanf("%d%d",&n,&k); char a[n+1]; scanf("%s",a); if(n==1 && k!=0) printf("0\n"); else { if(a[0]>'1' && k) { a[0]='1'; k--; } for(i=0,j=1;i<k;i++,j++) { if(a[j]=='\0') ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
0c320398ccb4a73d2860b9fc187a10cb
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> long long cmpfunc (const void * a, const void * b) { return ( *(long long*)a - *(long long*)b ); } int main(void){ long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a1,a2,a3,a4; char a...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
c7be7ac1f08dfd97bd10763b2a586715
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n, k; scanf ("%d %d\n", &n, &k); char str[200001]; scanf ("%s", str); int count = 0, i; if (k == 0) printf ("%s", str); else{ if (n == 1) {str[0] = '0'; printf ("%s", str);} else { if (str[0] == '1'){ ...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
21441bce043c5a1a759eec50ef50682a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include<stdio.h> int main() { int n,k; scanf("%d%d",&n,&k); char s[n]; scanf("%s",s); if(k){ if(n==1){ printf("0"); return 0; } int cnt=0; for(int i=0;i<k&&cnt<n;i++,cnt++){ //printf("\n%d",cnt); if(cnt==0){ if(s[0]=='1'){ i--; cont...
Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania ...
Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.
C
0515ac888937a4dda30cad5e2383164f
b46129ff30ddc9c28a4e28c650c5fd60
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "greedy" ]
1569247500
["5 3\n51528", "3 2\n102", "1 1\n1"]
NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.
PASSED
1,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ ...
["10028", "100", "0"]
#include<stdio.h> int main() { int n,k; char s; scanf("%d %d\n",&n,&k); int p=0;//counter till n int q=0;//counter till k if((n==1)&&(k==1)) { printf("0"); } else { while(p<n) { scanf("%c",&s); if((p==0)&&(s!='1')&&(q<k)) { s='1'; q++; } if((p!=0)&&(q<k)&&(s!='0')) { s='0';...
You are given two strings $$$s$$$ and $$$t$$$ both of length $$$n$$$ and both consisting of lowercase Latin letters.In one move, you can choose any length $$$len$$$ from $$$1$$$ to $$$n$$$ and perform the following operation: Choose any contiguous substring of the string $$$s$$$ of length $$$len$$$ and reverse it; a...
For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings $$$s$$$ and $$$t$$$ equal after some (possibly, empty) sequence of moves and "NO" otherwise.
C
7cf9bb97385ee3a5b5e28f66eab163d0
81af505ab896d118f1d2c17469f78522
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "sortings", "strings" ]
1572873300
["4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc"]
null
PASSED
2,000
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases. Then $$$q$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of $$$s$$$ and $$$t$$$. The second line of the test case contains one s...
["NO\nYES\nNO\nYES"]
#include <stdio.h> #define MAX 200010 int main() { int q,n; int timeOfExchange=0; scanf("%d",&q); char str1[MAX]; char str2[MAX]; int check[26] = {0}; int check2[26] = { 0 }; char temp; int skip = 0; int LocalPos; int todo = 0; for(int i = 0; i < q; i++) { for (int j = 0; j < 26; j++) { check[j] = 0; ...
Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective story books. You are not informed on what crime was committed, when and where the corpse was found and other details. We only ...
Print "YES" (without quotes) if the second arrangement can result from the first one, otherwise, print "NO".
C
52b13cca189853e6af02bea8d3d85276
d2a3afb944c04b9fc3b19ce11ecd7553
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dsu", "graphs" ]
1291536000
["2 1 2\n1 2\nDmitry 1 1 1\nNatalia 2 0\nNatalia 1 1 1\nDmitry 2 0", "4 4 3\n1 3\n1 2\n2 3\n3 4\nArtem 1 1 4\nDmitry 1 1 2\nEdvard 4 2 1 3\nArtem 2 0\nDmitry 1 0\nEdvard 4 4 1 2 3 4"]
null
PASSED
2,300
standard input
2 seconds
The first line contains three preset integers n, m и k (1 ≤ n, m, k ≤ 1000) — the number of rooms, the number of doors and the number of house residents respectively. The next m lines contain pairs of room numbers which join the doors. The rooms are numbered with integers from 1 to n. There cannot be more that one door...
["YES", "NO"]
#include<math.h> #include<time.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #define oo 1000000000 #define pi 3.14159265359 #define zero(a) (abb(a)<=1e-7) #define lowbit(a) ((a)&(-(a))) #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abb(a) ((a)>0?(a):(-(a))) #define cj(x1,y1,...
The Bitlandians are quite weird people. They have their own problems and their own solutions. They have their own thoughts and their own beliefs, they have their own values and their own merits. They have their own dishes and their own sausages!In Bitland a sausage is an array of integers! A sausage's deliciousness is ...
Print a single integer — the maximum pleasure BitHaval and BitAryo can get from the dinner.
C
02588d1e94595cb406d92bb6e170ded6
f36f88016c84947847e9001bb05386ca
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "data structures", "bitmasks", "trees" ]
1363188600
["2\n1 2", "3\n1 2 3", "2\n1000 1000"]
null
PASSED
2,200
standard input
2 seconds
The first line contains an integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 1012) — Mr. Bitkoch's sausage. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
["3", "3", "1000"]
/* practice with Dukkha */ #include <stdio.h> #define N 100000 long long max(long long a, long long b) { return a > b ? a : b; } long long pp[N + 1], qq[N + 1]; int partition(long long *aa, int i, int j, int b) { while (1) { long long tmp; while (i <= j && (aa[i] & 1LL << b) == 0) i++; while (i <= j && (...
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is...
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
f9a2ab31a76c936fc6fe362d769a2c0e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "greedy" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larg...
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> #include <stdlib.h> #define INIT_CAP 10 typedef struct { int u, d; } Range; typedef struct { Range *ary; int cap, size; } Vector; Vector vec[101]; void initVec(Vector *p) { p->ary = malloc(sizeof(Range) * INIT_CAP); p->cap = INIT_CAP; p->size = 0; } void initVecAry(int n...
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is...
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
256fe1eb2587f1ac58973bc6877ad875
GNU C
standard output
256 megabytes
train_002.jsonl
[ "greedy" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larg...
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> int main(void){ int N; int M; scanf("%i %i", &N, &M); char Pole[N][M]; int i; int j; char c; for(i=0;i<N;i++){ scanf("%c", &c); for(j=0;j<M;j++){ scanf("%c", &Pole[i][j]); } } /*for(i=0;i<N;i++){ for(j=0;j<M;j++){ ...
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is...
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
f64fc35f5d102a019a0f221b13c4445f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "greedy" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larg...
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> #define MAXN 1111 #define MAXM MAXN int N,M; char word[MAXN][MAXM]; char sep[MAXN]; int main() { int i,j,k; int result; scanf("%d %d\n", &N, &M); for(i=0; i<N; i++) scanf("%s\n", &word[i][0]); for(i=0; i<N; i++) sep[i] = 0; result = 0; for(i=0; i<M; i++){ for(j=0; j<N-1; j...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
859982d1822078f423fb9e820a4ae94a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> int main(){ int n; scanf("%d",&n); getchar(); char a[n+1]; gets(a); int dem=0; for(int i=0;i<n;i+=2){ if(a[i]==a[i+1]&&a[i]=='a'){ a[i]='b'; dem++; } else if(a[i]==a[i+1]&&a[i]=='b'){ a[i]='a'; dem++; } } printf("%d\n%s",dem,a); return 0; }
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
ff48844b0803d098e8dabe0ffe21664b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include <stdio.h> #include <string.h> int main() { int n,i,count=0; char srt[200000]; scanf("%d %s",&n,srt); for(i=0;i<n;i+=2) { if(srt[i]=='a' && srt[i+1]=='a') { srt[i]='b'; count=count+1; } else if(srt[i]=='b' && srt[i+1]=='b') { srt[i]='a'; count=count+1; } } ...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
1f19365f772f9b43331a5634d071d1fa
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> int main() { int n; scanf("%d",&n); char str[1000000]; scanf("%s",str); int i=0,d=strlen(str),s=0; while (i<d) { if (!(((str[i]=='a') && (str[i+1]=='b')) || ((str[i]=='b') && (str[i+1]=='a')))) { if (str[i]=='a') { ...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
c628f46b74fafa04e14fade7fff44715
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> int main() { int i,n,res=0; scanf("%d",&n); char str[n]; scanf("%s",str); for(i=0;i<n;i+=2) { if(!((str[i]=='a' && str[i+1]=='b')||(str[i]=='b' && str[i+1]=='a'))) { if(str[i]=='a') str[i]='b'; else str[i...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
7ad4128893139c82ec6a7d629627a4a3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> int main() { int i,n,res=0; scanf("%d",&n); char str[n]; scanf("%s",str); for(i=0;i<n;i+=2) { if(!((str[i]=='a' && str[i+1]=='b')||(str[i]=='b' && str[i+1]=='a'))) { if(str[i]=='a') str[i]='b'; else str[i]...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
3181cc7c664fc1baee496ca66afb1ff0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> int main() { int n,i,j,count=0; scanf("%d",&n); char arr[n]; getchar(); gets(arr); for(i=0;i<n;i+=2) { if((arr[i]=='a')&&(arr[i+1]=='a')) { arr[i+1]='b'; count++; } if((arr[i]=='b') && (arr[i+1]==...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
71e7d6f2752761f79d13c878639d389f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> int main() { int n,j,k,l=0; scanf("%d",&n); char a[n]; scanf("%s",a); for(int i=0;a[i]!=0;i=i+2) { k=a[i+1]-a[i]; if((a[i]=='a' || a[i]=='b') && abs(k)==1) { } else { if(a[i]=='a') a[...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
b0de4de424343f81020700c49e5c618d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> int main() { int n,i,c=0; scanf("%d",&n); char s[n+1]; scanf("%s",&s); for(i=0;i<n;i=i+2) { if(s[i]==s[i+1]) c++; } printf("%d\n",c); for(i=0;i<n;i=i+2) { if(s[i]==s[i+1]) printf("ab"); if(s[i]!=s[i+1]) ...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
1f39275c12f0c39e632fe3f9a3e634f5
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include <stdio.h> int main() { int a,i,e=0; scanf("%d",&a); char bha[a],c,d; scanf("%s",bha); for(i=1;i<a;i+=2) { c=bha[i]; d=bha[i-1]; if(c==d) { e++; if(d=='a') { bha[i-1]='b'; } else...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
6e1e231d5ac3f62f20413e713dbc1579
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include <stdio.h> int main(int argc, const char * argv[]) { int num, i; int nflip=0; //printf("Enter the number of digits"); scanf("%d", &num); char string[num+1]; scanf("%s", string); for (i=1; i<num; i+=2) { if(string[i]==string[i-1]) ...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
11ee443102d4dd86fdcff38eda63b788
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> int check(int n,int *arr,int k){ for(int i=0;i<k;i++){ if(arr[i]==n)return 1; } return 0; } int main() { int n,sum=0; scanf("%d",&n); char a[n]; char f,m; scanf("%s",a); if(a[0]=='a'){f='a';m='b';} else{f='b';m='a';} for(int i=0;i<n;i+=2){ if(a[i]==a[i+1]){ a[i+1...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
12b652d1f2d65b3e0444dce267946c3d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> char ch[1000000]; int main(void) { int n; int i; scanf("%d",&n); scanf("%s",ch); int count = 0; for(i = 0;i<n;i+=2) { if(ch[i] == ch[i+1]) { count++; if(ch[i] == 'a') ch[i]+=1; else ch[i]-=1; } } printf("%d\n%s\n",count,ch); return 0; }
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
53cdd3858d77de682b8b0ecd83ec0bb4
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> int main(){ int n; scanf("%d",&n); char s[n]; scanf("%s",s); int c=0; for(int i=0;i<n;i+=2){ if(!(s[i]=='a'&& s[i+1]=='b'|| s[i]=='b' && s[i+1]=='a')){ if(s[i]=='a') s[i]='b'; else s[i]='a'; c=c+1; } } printf("%d",c); printf("\n%s",s); return 0;}
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
db3c54343af5fdfd6149fb6e798f9f26
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include <stdio.h> #include <stdlib.h> typedef long long ll; int main() { ll n,c=0,i; scanf("%I64d",&n); char str[n]; scanf("%s",str); for(i=0;i<n;i+=2) { if(str[i]=='a'&&str[i+1]=='a' || str[i]=='b'&&str[i+1]=='b') { c++; str[i]='a'; str[i+1]=...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
0563139943128f376bc119d404a0f7af
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include <stdio.h> void ler_array(int i,int n,char a[]) {int aux; if(i == n) { return; } else { scanf(" %c",&a[i]); ler_array(i+1,n,a); } } void escolher(int i,int n,char a[],int cont) { if(i == n) { printf("%d\n",cont); return; } else if(i == 0) { if(a[i] == 'a') { if(a[i+1] == 'b') { escolher(i+2,...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
eeefe55297190342cf9f033a3bfa819f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> int main() { int n, cnt = 0, i; char a[200000]; scanf("%d", &n); getchar(); gets(a); int p; p=strlen(a)-1; for (i = 0; i < p;i=i+2) { if (a[i] == a[i + 1]) { if (a[i] == 'a') a[i] = 'b'; else a[i] = 'a'; cnt++; } } printf("%d\n", cnt); puts(a); r...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
00054cdf3904c227ed2e385a01e3827e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include <stdio.h> int main(){ char s[200001]; int n,k=0; scanf("%d",&n); scanf("%s",s); for(int i=0;i<n;i=i+2){ if(s[i]==s[i+1]&&s[i]=='a') { s[i]='b'; k++; } else if(s[i]==s[i+1]&&s[i]=='b') { s[i]='a'; k++; } } printf("%d\n",k); puts(s); return 0; }
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
780043cd475449fa97aca9144abd1a0b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> #include<stdlib.h> #define A 'a' #define B 'b' int main(){ int i; int n, m; scanf("%d",&n); char s[n]; scanf("%s",s); m = 0; for(i = 0; i < n; i += 2){ if(s[i] == 'a' && s[i + 1] == 'a') m++, s[i] = 'b'; else if(s[i] == 'b' && s[i + 1] == 'b') m++, s[i] = 'a'; ...
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
f40a4e51159532f003f0fc6a5d860f90
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> int main() { int n,i,j,c; scanf("%d",&j); char x[j]; scanf("%s",x); c=0; for(i=0;i<j;i=i+2) { if(x[i]=='a'&&x[i+1]=='a') { x[i+1]='b'; c++; } if(x[i]=='b'&&x[i+1]=='b') { x[i+1]='a'; c++; } } printf("%d\n",c); printf("%s",x); return 0; }
Nikolay got a string $$$s$$$ of even length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $$$1$$$ to $$$n$$$.He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the f...
In the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'. In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, y...
C
8ad06ac90b258a8233e2a1cf51f68078
a3c76910bee8b0c3ddd5b6c0bbea60d0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "strings" ]
1569049500
["4\nbbbb", "6\nababab", "2\naa"]
NoteIn the first example Nikolay has to perform two operations. For example, he can replace the first 'b' with 'a' and the last 'b' with 'a'. In the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters 'a' and 'b'.
PASSED
800
standard input
1 second
The first line of the input contains one even integer $$$n$$$ $$$(2 \le n \le 2\cdot10^{5})$$$ — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters 'a' and 'b'.
["2\nabba", "0\nababab", "1\nba"]
#include<stdio.h> #include<string.h> int main() { int n,i,c=0; char s[200000]; scanf("%d %s",&n,s); for(i=0;i<n;i+=2) { if(s[i]=='a' && s[i+1]=='a') { s[i]='b'; c++; } else if(s[i]=='b' && s[i+1]=='b') { s[i]='a'; c++; } } printf("%d\n%s",c,s); return 0; }
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: Add the integer xi to the first ai elements of the sequence. Append an integer ki to the end of the sequence. (And he...
Output n lines each containing the average of the numbers in the sequence after the corresponding operation. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.
C
d43d4fd6c1e2722da185f34d902ace97
8132847917fec10b193d1353366c06ec
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "dp", "constructive algorithms", "data structures" ]
1363534200
["5\n2 1\n3\n2 3\n2 1\n3", "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3"]
NoteIn the second sample, the sequence becomes
PASSED
1,600
standard input
1.5 seconds
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer ti (1 ≤ ti ≤ 3), denoting the type of the operation (see above). If ti = 1, it will be followed by two integers ai, xi (|xi| ≤ 103; 1 ≤ ai). If ti = 2, it...
["0.500000\n0.000000\n1.500000\n1.333333\n1.500000", "0.500000\n20.500000\n14.333333\n12.333333\n17.500000\n17.000000"]
#include <stdio.h> #define MAXN 200005 int stk[MAXN]; int d[MAXN]; int main(int argc, char** argv) { int q; scanf(" %d", &q); long long tot = 0; int p = 1; for (int i = 0; i < q; ++i) { int t; scanf(" %d", &t); if (t == 1) { int x, v; scanf(" %d %d"...
We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".Given a string, you have to find two values: the number of good substrings of even length; the number of good substrings o...
Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.
C
4ebbda2fc1a260e9827205a25addd9c4
02c6081ea19f57ed001bd3d4fdb51f07
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "math" ]
1406215800
["bb", "baab", "babb", "babaa"]
NoteIn example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.In example 3, there are seven good substr...
PASSED
2,000
standard input
2 seconds
The first line of the input contains a single string of length n (1 ≤ n ≤ 105). Each character of the string will be either 'a' or 'b'.
["1 2", "2 4", "2 5", "2 7"]
#include<stdlib.h> #include<stdio.h> #include<string.h> typedef long long int lli; typedef struct bst bst; #define TRUE (1==1) #define FALSE (!(TRUE)) #define in32(x) scanf("%d", &(x)) #define in64(x) scanf("%I64d", &(x)) #define instr(x) scanf("%s", (x)) #define out32(x) printf("%d\...
We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".Given a string, you have to find two values: the number of good substrings of even length; the number of good substrings o...
Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.
C
4ebbda2fc1a260e9827205a25addd9c4
3da9b8ecd475df37a3bb8e9461306958
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "math" ]
1406215800
["bb", "baab", "babb", "babaa"]
NoteIn example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.In example 3, there are seven good substr...
PASSED
2,000
standard input
2 seconds
The first line of the input contains a single string of length n (1 ≤ n ≤ 105). Each character of the string will be either 'a' or 'b'.
["1 2", "2 4", "2 5", "2 7"]
/* practice with Dukkha */ #include <stdio.h> #include <string.h> #define N 100000 int main() { static char cc[N + 1]; int n, i, a0, a1, b0, b1; long long ao, ae, bo, be, e, o; scanf("%s", cc), n = strlen(cc); a0 = a1 = b0 = b1 = 0; for (i = 0; i < n; i++) if (cc[i] == 'a') { if (i % 2 == 0) a0++; ...
Berland SU holds yet another training contest for its students today. $$$n$$$ students came, each of them brought his laptop. However, it turned out that everyone has forgot their chargers!Let students be numbered from $$$1$$$ to $$$n$$$. Laptop of the $$$i$$$-th student has charge $$$a_i$$$ at the beginning of the con...
Print a single non-negative integer — the minimal possible power output the charger should have so that all the students are able to successfully finish the contest. If no such charger exists, print -1.
C
6dee11f19439e5f437604bc61257c8a5
df29aabcb3a1cc6c906831b71887c21b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "binary search", "greedy" ]
1551798300
["2 4\n3 2\n4 2", "1 5\n4\n2", "1 6\n4\n2", "2 2\n2 10\n3 15"]
NoteLet's take a look at the state of laptops in the beginning of each minute on the first example with the charger of power $$$5$$$: charge: $$$[3, 2]$$$, plug the charger into laptop 1; charge: $$$[3 - 4 + 5, 2 - 2] = [4, 0]$$$, plug the charger into laptop 2; charge: $$$[4 - 4, 0 - 2 + 5] = [0, 3]$$$, plug the ch...
PASSED
2,300
standard input
3 seconds
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 2 \cdot 10^5$$$) — the number of students (and laptops, correspondigly) and the duration of the contest in minutes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) ...
["5", "1", "2", "-1"]
#include <stdio.h> #include <stdlib.h> #define maxn 200001 typedef struct laptop_tag { long long power, change; } laptop_tag; typedef struct heap_tag { int sz; int elements[maxn]; } heap_tag; int n, k; long long value[maxn], valuea[maxn]; laptop_tag arr[maxn], brr[maxn]; heap_tag heap, cheap; int cmp(int x,...
Berland SU holds yet another training contest for its students today. $$$n$$$ students came, each of them brought his laptop. However, it turned out that everyone has forgot their chargers!Let students be numbered from $$$1$$$ to $$$n$$$. Laptop of the $$$i$$$-th student has charge $$$a_i$$$ at the beginning of the con...
Print a single non-negative integer — the minimal possible power output the charger should have so that all the students are able to successfully finish the contest. If no such charger exists, print -1.
C
6dee11f19439e5f437604bc61257c8a5
5453615f531df8bfce4590626194a593
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "binary search", "greedy" ]
1551798300
["2 4\n3 2\n4 2", "1 5\n4\n2", "1 6\n4\n2", "2 2\n2 10\n3 15"]
NoteLet's take a look at the state of laptops in the beginning of each minute on the first example with the charger of power $$$5$$$: charge: $$$[3, 2]$$$, plug the charger into laptop 1; charge: $$$[3 - 4 + 5, 2 - 2] = [4, 0]$$$, plug the charger into laptop 2; charge: $$$[4 - 4, 0 - 2 + 5] = [0, 3]$$$, plug the ch...
PASSED
2,300
standard input
3 seconds
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 2 \cdot 10^5$$$) — the number of students (and laptops, correspondigly) and the duration of the contest in minutes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) ...
["5", "1", "2", "-1"]
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N 200000 #define K 200000 #define INF (K * 10000000LL + 1) void init_rand() { struct timeval tv; gettimeofday(&tv, NULL); srand(tv.tv_sec ^ tv.tv_usec); } struct P { long long a, b; } pp[N]; int compare(const void *a, const void *b) { int ia...
Berland SU holds yet another training contest for its students today. $$$n$$$ students came, each of them brought his laptop. However, it turned out that everyone has forgot their chargers!Let students be numbered from $$$1$$$ to $$$n$$$. Laptop of the $$$i$$$-th student has charge $$$a_i$$$ at the beginning of the con...
Print a single non-negative integer — the minimal possible power output the charger should have so that all the students are able to successfully finish the contest. If no such charger exists, print -1.
C
6dee11f19439e5f437604bc61257c8a5
9f833551c5e0a1a53588c9dc8e29f8af
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "binary search", "greedy" ]
1551798300
["2 4\n3 2\n4 2", "1 5\n4\n2", "1 6\n4\n2", "2 2\n2 10\n3 15"]
NoteLet's take a look at the state of laptops in the beginning of each minute on the first example with the charger of power $$$5$$$: charge: $$$[3, 2]$$$, plug the charger into laptop 1; charge: $$$[3 - 4 + 5, 2 - 2] = [4, 0]$$$, plug the charger into laptop 2; charge: $$$[4 - 4, 0 - 2 + 5] = [0, 3]$$$, plug the ch...
PASSED
2,300
standard input
3 seconds
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 2 \cdot 10^5$$$) — the number of students (and laptops, correspondigly) and the duration of the contest in minutes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) ...
["5", "1", "2", "-1"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<inttypes.h> #include<string.h> typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i...
Berland SU holds yet another training contest for its students today. $$$n$$$ students came, each of them brought his laptop. However, it turned out that everyone has forgot their chargers!Let students be numbered from $$$1$$$ to $$$n$$$. Laptop of the $$$i$$$-th student has charge $$$a_i$$$ at the beginning of the con...
Print a single non-negative integer — the minimal possible power output the charger should have so that all the students are able to successfully finish the contest. If no such charger exists, print -1.
C
6dee11f19439e5f437604bc61257c8a5
7faabdc659e70078f4c249c9cedff56b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "binary search", "greedy" ]
1551798300
["2 4\n3 2\n4 2", "1 5\n4\n2", "1 6\n4\n2", "2 2\n2 10\n3 15"]
NoteLet's take a look at the state of laptops in the beginning of each minute on the first example with the charger of power $$$5$$$: charge: $$$[3, 2]$$$, plug the charger into laptop 1; charge: $$$[3 - 4 + 5, 2 - 2] = [4, 0]$$$, plug the charger into laptop 2; charge: $$$[4 - 4, 0 - 2 + 5] = [0, 3]$$$, plug the ch...
PASSED
2,300
standard input
3 seconds
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 2 \cdot 10^5$$$) — the number of students (and laptops, correspondigly) and the duration of the contest in minutes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) ...
["5", "1", "2", "-1"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<inttypes.h> typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i64 read_int(void){i...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
ae8d76dcf9b279ea5b675a6103d0f664
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include <stdio.h> int main() { int n, min = 10000, i; char s[2001]; scanf("%d", &n); scanf("%s", s); for (i = 0; i < n; i++) { int p = i, q, sum = 0; for (q = n + i - 1; q >= p; q--) { if (s[q] != s[i]) break; } while (1) { for (; p < q; p++) { if (s[p] !...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
1518a5bead1c78d233036ddbf218cffa
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include <stdio.h> #define gmin(a,b) ((a)<(b)?(a):(b)) int main() { long n,i,tot=0,op,j,min; char ch[2005]={'\0'}; scanf("%ld\n",&n); for(i=1;i<=n;i++) { scanf("%c",&ch[i]); if(ch[i]=='H') tot++; } min=1000000000; for(i=1;i<n;i++) ch[i+n]=ch[i]; for...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
902e30c819e7423f6beac99f7b954c06
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include <stdio.h> #define oo 200000000 char str[1006]={'\0'}; long s1=0,s2=0; int main() { long n,j; long i; long min=oo; long s=0; scanf("%ld",&n); scanf("%s",str+1); for(i=1;i<=n;i++) { if(str[i]=='H') s1++; } s2=n-s1; if(s1==0||s2==0) { printf("0\n"); return 0; } for(i=...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
81febeb7d91c73a32a648523af19cf1c
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include<stdio.h> #include<stdlib.h> #include<math.h> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) int main(){ int i,j,k,l,m,n; int res, tmp, cnt; char in[1200]; while(scanf("%d%s",&n,in)==2){ res=1000000000; cnt=0; rep(i,n) if(in[i]=='T') cnt++; rep(k,n){ tmp = 0; r...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
df5ac988dde2bd8271f88593743e6463
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
/* Hamsters and Tigers */ #include <stdio.h> #include <stdlib.h> int main (int argc, char** argv) { int n; int ri; int i; char* animals; int totalTigers = 0; fscanf (stdin, "%i", &n); animals = (char*) malloc (n+3); /* Just in case... */ /* for (i = 0; i < n; i++) { */ fscanf (stdin, "%s", anima...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
5e352efef855dd96ab7e9a0e4a4684ed
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include <stdio.h> #define sc(a) scanf(" %c", &a) #define s(a) scanf("%d", &a) int main() { int i,j,k,l, c, h = 0, swp, x; int ans = (int) 1e7; char seq[1020]; s(c); for (i = 0; i < c; i++) { sc(seq[i]); h += (seq[i] == 'H'); } for ( j = 0; j < i; j++) { swp = 0; ...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
f78d2dd89d0656f6d096d35823cf65e1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include<stdio.h> int main(){ int until,ha=0,ti=0,i,j,k,l,n,m,st=0,en,last,min=1000000; char c[3005]; scanf("%d",&n); en = n-1; scanf(" %s",c); for(i=0;i<n;i++) if(c[i]=='H') ha++; else ti++; for(i=0;i<n;i++){ last = until = 0; for(j=st;j<=en;j++){ if(c[j]=='H'){ until++; last++; } ...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
3009db4110cb05b1891e05feca6f5773
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include<stdio.h> #define maxn 1111 #define INF 1<<30 char c[maxn],temp[maxn]; int main(){ int n,i,j; while(~scanf("%d",&n)){ getchar(); scanf("%s",c); int ch=0,ct=0; for(i=0;i<n;i++){ if(c[i]=='H'){ ch++; } else{ ...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
C
0fce263a9606fbfc3ec912894ab1a8f8
822c84c343b80558e55e42ba87fa9647
GNU C
standard output
256 megabytes
train_002.jsonl
[ "two pointers" ]
1291536000
["3\nHTH", "9\nHTHTHTHHT"]
NoteIn the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
PASSED
1,600
standard input
2 seconds
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one ...
["0", "2"]
#include<math.h> #include<time.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #define oo 1000000000 #define pi 3.14159265359 #define zero(a) (abb(a)<=1e-7) #define lowbit(a) ((a)&(-(a))) #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abb(a) ((a)>0?(a):(-(a))) #define cj(x1,y1,...
Bob is playing with $$$6$$$-sided dice. A net of such standard cube is shown below.He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.For examp...
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
C
840a4e16454290471faa5a27a3c795d9
18d2bb1e89b5f6c9dc33dd3997fda54d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "math" ]
1576595100
["4\n29 34 19 38"]
NoteThe first example is mentioned in the problem statement.In the second example, one can build the tower by flipping the top dice from the previous tower.In the third example, one can use a single die that has $$$5$$$ on top.The fourth example is impossible.
PASSED
1,000
standard input
1 second
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of favourite integers of Bob. The second line contains $$$t$$$ space-separated integers $$$x_i$$$ ($$$1 \leq x_i \leq 10^{18}$$$) — Bob's favourite integers.
["YES\nYES\nYES\nNO"]
#include<stdio.h> int main() { int n; scanf("%d",&n); long long int a[n],j,i; for(i=0;i<n;i++) { scanf("%lld",&a[i]);} for(j=0;j<n;j++) { if(a[j]>14&&a[j]%14<=6&&a[j]%14>=1) printf("YES\n"); else printf("NO\n");} return 0; }
Bob is playing with $$$6$$$-sided dice. A net of such standard cube is shown below.He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.For examp...
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
C
840a4e16454290471faa5a27a3c795d9
aebfc1df3f518d5b83cd5c19e9b0ad8c
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "math" ]
1576595100
["4\n29 34 19 38"]
NoteThe first example is mentioned in the problem statement.In the second example, one can build the tower by flipping the top dice from the previous tower.In the third example, one can use a single die that has $$$5$$$ on top.The fourth example is impossible.
PASSED
1,000
standard input
1 second
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of favourite integers of Bob. The second line contains $$$t$$$ space-separated integers $$$x_i$$$ ($$$1 \leq x_i \leq 10^{18}$$$) — Bob's favourite integers.
["YES\nYES\nYES\nNO"]
#include<stdio.h> int main() { long long n,i,j,t,c; scanf("%lld",&t); for(i=0;i<t;i++) { scanf("%lld",&n); c=n%14; //printf("%lld\n",c); if(c>=1&&c<=6&&n>=15) { printf("YES\n"); } else printf("NO\n"); } return 0; ...
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number ...
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
8cb705645d8e747ff4600a1ee1cc4f6b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$...
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int n; scanf("%d", &n); int i, j; int ans[302][302]; for (j = 0; j < n; j++) { if (j % 2 == 0) { for (i = 0; i < n; i++) ans[i][j] = n * j+ i + 1; } else { for (i = 0; i < n; i++) ans[n - i - 1][j] = n * j + i + 1; } } for (i = 0; i < n; i++) { for (j ...