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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Given an array a1,βa2,β...,βan of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that xβ=βy2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 7afcd7579cc2246d61aee311c8b7efe1 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β1000)Β β the number of elements in the array. The second line contains n integers a1,βa2,β...,βan (β-β106ββ€βaiββ€β106)Β β the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
int main()
{
int n,i,max,k,j;
int a[1005];
while(~scanf("%d",&n))
{
max=-1000005;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<0&&a[i]>max) max=a[i];
if(a[i]>=0)
{
for(j=0;j<=1000;j++)
if(j*j==a[i]) break;
if(j==1001) max=max<a[i]?a[i]:max;
}
}
printf("%d\n",max);
}
return 0;
} | |
Given an array a1,βa2,β...,βan of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that xβ=βy2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 337b876603724d2234ce19eb5b034331 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β1000)Β β the number of elements in the array. The second line contains n integers a1,βa2,β...,βan (β-β106ββ€βaiββ€β106)Β β the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int i , a[1000] , n,x,j,k,temp,a1;
float b;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
x=0;
for(j=0;j<n;j++)
{
b=sqrt(a[j]);
if(b!=(int)b)
{
a[x]=a[j];
x++;
}
}
a1=x;
for(k=0;k<a1;k++)
{
for(j=k+1;j<a1;j++)
{
if(a[k]<a[j])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
}
}
if(k==a1)
{
printf("%d\n",a[0]);
}
return 0;
}
| |
Given an array a1,βa2,β...,βan of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that xβ=βy2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | fe58d08ecfc5ba54073d8fa4875bbc21 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β1000)Β β the number of elements in the array. The second line contains n integers a1,βa2,β...,βan (β-β106ββ€βaiββ€β106)Β β the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int i , a[1000] , n,x,j,k,temp,a1;
float b;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
x=0;
for(j=0;j<n;j++)
{
b=sqrt(a[j]);
if(b!=(int)b)
{
a[x]=a[j];
x++;
}
}
a1=x;
for(k=0;k<a1;k++)
{
for(j=k+1;j<a1;j++)
{
if(a[k]<a[j])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
}
}
if(k==a1)
{
printf("%d\n",a[0]);
}
return 0;
}
| |
Given an array a1,βa2,β...,βan of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that xβ=βy2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | d2bea945cf0ae32a9c438c6ea29773fa | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β1000)Β β the number of elements in the array. The second line contains n integers a1,βa2,β...,βan (β-β106ββ€βaiββ€β106)Β β the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int n,i;
int d=-1000000;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if((a[i]>0)&&((int)(sqrt(a[i]))!=sqrt(a[i]))&&(d<a[i]))
d=a[i];
else if((a[i]<0)&&(d<a[i])){
d=a[i];}
}
printf("%d",d);
return 0;
}
| |
Given an array a1,βa2,β...,βan of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that xβ=βy2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | e342d74c8296204628185739f77e5245 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β1000)Β β the number of elements in the array. The second line contains n integers a1,βa2,β...,βan (β-β106ββ€βaiββ€β106)Β β the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int i,m;
float l;
signed n=-1000000;
signed x;
scanf("%d",&x);
int arr[x];
for(i=0;i<x;i++){
scanf("%d",&arr[i]);
}
for(i=0;i<x;i++){
l=sqrt(arr[i]);
m=sqrt(arr[i]);
if(l!=m){
if(arr[i]>n)
n=arr[i];
}
}
printf("%d",n);
}
| |
There is a square matrix nβΓβn, consisting of non-negative integer numbers. You should find such a way on it that starts in the upper left cell of the matrix; each following cell is to the right or down from the current cell; the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | C | 13c58291ab9cf7ad1b8c466c3e36aacf | 8db5d9a1e692383c8e119b7e457b079f | GNU C | standard output | 64 megabytes | train_001.jsonl | [
"dp",
"math"
] | 1267117200 | ["3\n1 2 3\n4 5 6\n7 8 9"] | null | PASSED | 2,000 | standard input | 2 seconds | The first line contains an integer number n (2ββ€βnββ€β1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109). | ["0\nDDRR"] | #include <stdio.h>
int x=-1;
int compute(int (*a)[1001],int (*b)[1001],char (*c)[1001],int n)
{
int i,j;
b[0][0]=a[0][0];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(j-1<0 && i-1<0) continue;
if(j-1<0) goto down;
if(i-1<0) goto right;
if(b[i][j-1]<b[i-1][j]) goto right;
else goto down;
right:
{
b[i][j]=a[i][j] + b[i][j-1];
c[i][j]='R';
continue;
}
down:
{
b[i][j]=a[i][j] + b[i-1][j];
c[i][j]='D';
continue;
}
}
}
return b[n-1][n-1];
}
void see(char c[][1001],int a,int b)
{
if(a==0 && b==0) return;
if(c[a][b]=='D')
{
see(c,a-1,b);
printf("D");
}
else
{
see(c,a,b-1);
printf("R");
}
}
int main()
{
int a[1001][1001]={0},i,ct,cf,j,n,m,q,p=0;
int b[1001][1001]={0};
int f[1001][1001]={0};
char c[1001][1001]={'0'};
char d[1001][1001]={'0'};
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&m);
if(m==0){x=j;a[i][j]=10;f[i][j]=10;continue;}
q=m;
while(m%2==0){p++;m=m/2;}
a[i][j]=p;
p=0;
while(q%5==0){p++;q=q/5;}
f[i][j]=p;
p=0;
}
}
ct=compute(a,b,c,n);
cf=compute(f,b,d,n);
if(ct<cf)
{
if(x>=0 && ct>1)
{
printf("1\n");
for(i=0;i<x;i++) printf("R");
for(i=0;i<n-1;i++) printf("D");
for(i=x;i<n-1;i++) printf("R");
}
else
{
printf("%d\n",ct);
see(c,n-1,n-1);
}
}
else
{
if(x>=0 && cf>1)
{
printf("1\n");
for(i=0;i<x;i++) printf("R");
for(i=0;i<n-1;i++) printf("D");
for(i=x;i<n-1;i++) printf("R");
}
else
{
printf("%d\n",cf);
see(d,n-1,n-1);
}
}
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 0536d8670abb204217de2cd32a8113ab | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
int count[300];
int main()
{
int i=0;
char myarray[1000000];
while(1)
{
scanf("%c",&myarray[i]);
if(myarray[i]=='\n')
{
myarray[i]='\0';
break;
}
else
{
count[myarray[i]]++;
}
i++;
}
int j=0;
long long sum=0;
for(j=0; j<i; j++)
{
sum+=count[myarray[j]];
}
printf("%I64d",sum);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | ed50612e04551da26ef1bb7b1c96df3a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <string.h>
int main() {
int i, l;
long long sum;
static char s[100001];
static int cnt[128];
scanf("%s", s);
l = strlen(s);
for (i = 0; i < l; i++)
cnt[s[i] - '0']++;
sum = 0;
for (i = 0; i < l; i++)
sum += cnt[s[i] - '0'];
printf("%lld\n", sum);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 22c24fc89aa3d590f5b46e49b469b71b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <string.h>
int main() {
int i, l;
long long sum;
static char s[100001];
static int cnt[128];
scanf("%s", s);
l = strlen(s);
for (i = 0; i < l; i++)
cnt[s[i] - '0']++;
sum = 0;
for (i = 0; i < l; i++)
sum += cnt[s[i] - '0'];
printf("%lld\n", sum);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 85b32db7fd0b16da1e94e0149ade7d22 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <string.h>
char s[100001];
long long int flit[30];
long long int fcif[15];
int main()
{
long long int n,i,total=0;
gets(s);
n=strlen(s);
for(i=0;i<n;i++)
{
if(s[i]>='a' && s[i]<='z')
flit[s[i]-'a']++;
else
{
if(s[i]>='0' && s[i]<='9')
fcif[s[i]-'0']++;
}
}
for(i=0;i<28;i++)
{
if(flit[i]>0)
total=total+flit[i]*flit[i];
}
for(i=0;i<11;i++)
{
if(fcif[i]>0)
total=total+fcif[i]*fcif[i];
}
printf("%I64d",total);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | de19d39407ac2ff57efe697c12b72cc6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
char str[100001];
int cnt[128];
long long s;
int main(int argc, char *argv[])
{
int i;
gets(str);
for(i = 0; str[i]; i ++)
cnt[str[i]] ++;
for(i = '0'; i <= '9'; i ++)
s += (long long) cnt[i] * cnt[i];
for(i = 'a'; i <= 'z'; i ++)
s += (long long) cnt[i] * cnt[i];
printf("%I64d\n", s);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | aea2e09b7c3df3c462aa230c89e1ada8 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
int main()
{
long long i,j,k=0,counter=0;
char arr[1000000];
scanf("%s",arr);
long long spare[1000];
for(i=0;arr[i]!='\0';i++)
{counter=0;
if(arr[i]!='*')
{
for(j=i+1;arr[j]!='\0';j++)
{
if(arr[i]==arr[j])
{
counter++;
arr[j]='*';
}
}
spare[k]=counter+1;
k++;
}
}
long long sum=0;
for(i=0;i<k;i++)
{
sum=sum+(spare[i]*spare[i]);
}
printf("%I64d",sum);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 5d9668e8f9d889fe642074a6e3f7a940 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #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,x2,y2) ((x1)*(y2)-(x2)*(y2))
#define dj(x1,y1,x2,y2) ((x1)*(y1)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
char str[100005]={0};
long sum[300]={0};
int main()
{
long i;
long long ans=0;
gets(str+1);
for (i=1;str[i];i++)
sum[str[i]]++;
for (i=1;i<=127;i++)
ans+=(long long)sum[i]*sum[i];
printf("%I64d\n",ans);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 998e5113510ec334f9ede70261c33c00 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <string.h>
#include <math.h>
int main(){
char string[100001];
long asciiNumbers[10], asciiLowercase[26], i;
long long numPairs;
numPairs = 0;
for(i = 0; i < 10; i++){
asciiNumbers[i] = 0;
asciiLowercase[i] = 0;
}
for(i = 10; i < 26; i++)
asciiLowercase[i] = 0;
scanf("%s", string);
for(i = 0; i < strlen(string); i++){
if(((int)string[i] >= 97) && ((int)string[i] <= 122))
asciiLowercase[(int)string[i] - 97]++;
else if(((int)string[i] >= 48) && ((int)string[i] <= 57))
asciiNumbers[(int)string[i] - 48]++;
}
for(i = 0; i < 10; i++){
if(asciiNumbers[i] != 0)
numPairs += pow(asciiNumbers[i], 2);
if(asciiLowercase[i] != 0)
numPairs += pow(asciiLowercase[i], 2);
}
for(i = 10; i < 26; i++)
if(asciiLowercase[i] != 0)
numPairs += pow(asciiLowercase[i], 2);
printf("%I64d\n", numPairs);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | aff1a80acfb18ae5a301edcdd0bb6715 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#include<string.h>
int t[125];
int main()
{
int i,l;
char s[100004];
while(scanf("%s",s)!=EOF)
{
l=strlen(s);
memset(t,0,sizeof(t));
for(i=0; i<l; i++)
{
t[s[i]]++;
}
double ans=0;
for(i='0'; i<='z'; i++)
{
ans+=(double)t[i]*t[i];
}
printf("%.0lf\n",ans);
}
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 11794f1a2633234b12f5240fad19061b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#include<string.h>
int t[125];
int main()
{
int i,l;
char s[100004];
while(scanf("%s",s)!=EOF)
{
l=strlen(s);
memset(t,0,sizeof(t));
for(i=0; i<l; i++)
{
t[s[i]]++;
}
double ans=0;
for(i='0'; i<='z'; i++)
{
ans+=(double)t[i]*t[i];
}
printf("%.0lf\n",ans);
}
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | c8d848b8cb8209795b066a0efe523498 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#include<string.h>
long long a[256];
char s[100001];
int main()
{
scanf("%s",s);
long long ans=0,i,l=strlen(s);
for(i=0;i<l;++i)
++a[s[i]];
for(i=0;i<256;++i)
ans+=a[i]*a[i];
printf("%lld",ans);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 07cb031f14d80a8fc16db68d15991025 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <stdlib.h>
char str[1000000+5];
int main()
{
scanf("%s",str);
long long arr[500]={0};
long long i,sum=0;
for(i=0;str[i]!='\0';i++){
arr[(int)str[i]]++;
}
for(i=0;i<500;i++){
sum+=arr[i]*arr[i];
}
printf("%lld\n",sum);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | d1ed87536018bc4363f8c2df389a3d6b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
int main()
{
long long int i,a[200]={0},c=0;
char s[100001];
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
a[(int)s[i]]++;
}
for(i=0;i<200;i++)
{
c+=a[i]*a[i];
}
printf("%I64d\n",c);
return(0);
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | d75786834df89d138bffab4b75f77c16 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <string.h>
#include <math.h>
int main(){
char string[100001];
long asciiNumbers[10], asciiLowercase[26], i;
long long numPairs;
numPairs = 0;
for(i = 0; i < 10; i++){
asciiNumbers[i] = 0;
asciiLowercase[i] = 0;
}
for(i = 10; i < 26; i++)
asciiLowercase[i] = 0;
scanf("%s", string);
for(i = 0; i < strlen(string); i++){
if(((int)string[i] >= 97) && ((int)string[i] <= 122))
asciiLowercase[(int)string[i] - 97]++;
else if(((int)string[i] >= 48) && ((int)string[i] <= 57))
asciiNumbers[(int)string[i] - 48]++;
}
for(i = 0; i < 10; i++){
if(asciiNumbers[i] != 0)
numPairs += pow(asciiNumbers[i], 2);
if(asciiLowercase[i] != 0)
numPairs += pow(asciiLowercase[i], 2);
}
for(i = 10; i < 26; i++)
if(asciiLowercase[i] != 0)
numPairs += pow(asciiLowercase[i], 2);
printf("%lli\n", numPairs);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | ecfe8d46bd81ff71dc0f1c20a5f2a89e | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
long long int s = 0LL;
long long int arr [100];
int i;
for (i = 0; i < 100; i++) arr[i] = 0LL;
int t;
char c;
scanf("%c", &c);
while ((c != ' ') && (c != '\n') && (c != '\t')){
t = c;
s += 1 + 2 * arr[t -'0']++;
scanf("%c", &c);
}
printf("%I64d", s);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 9706471e77619124dac7f3206c6c6930 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
long long soma;
int i, *letras, codletra, tamanho, metade, resto;
char palavra[100010];
//char *palavra;
i = 0;
letras = calloc(90, sizeof(int));
//while (i < 50){
// letras[i] = 0;
// i++;
// }
//while (scanf("%s", palavra) != EOF){
scanf("%s", palavra);
i = 0;
soma = 0;
tamanho = strlen(palavra);
// printf("TAMANHO DA PALAVRA: %d\n", tamanho);
resto = tamanho%2;
// printf("RESTO DA PALAVRA: %d\n", resto);
metade = tamanho/2;
// printf("METADE DA PALAVRA: %d\n", metade);
tamanho = strlen(palavra)-1;
while (i < tamanho/2+1){
codletra = palavra[i];
// printf("Processando letra %c...\n", palavra[i]);
codletra = codletra-48;
letras[codletra]++;
if (tamanho > 1){
codletra = palavra[tamanho-i];
// printf("Processando letra %c...\n", palavra[tamanho-i]);
codletra = codletra-48;
letras[codletra]++;
}
i++;
if ((resto != 0) && (i == tamanho/2)) break;
}
if ((resto != 0) && (tamanho > 1)){
// printf("Palavra impar!!!");
codletra = palavra[metade];
// printf("%c", palavra[metade]);
codletra = codletra-48;
letras[codletra]++;
}
i = 0;
while (i < 90){
//printf("c");
// printf("Valor posicao %d: %d\n", i, letras[i] );
soma = soma + pow(letras[i],2);
//letras[i] = 0;
i++;
}
free(letras);
//printf("%ld\n", soma);
printf("%I64d",soma);
//}
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | bdbbb28610af9ad2052268839233e784 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
int main()
{
long int i,j,a[257]={0};
unsigned long long int sum=0,p;
char s[100001];
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
a[(int)(s[i])]++;
for(i=0;i<257;i++)
{
p=a[i];
sum=sum+p*p;
}
printf("%I64u\n",sum);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 5e249328191d407271949e0b7836b231 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
int main()
{
long long int i,a[200]={0},c=0;
char s[100001];
gets(s);
for(i=0;s[i]!='\0';i++)
a[(int)s[i]]++;
for(i=0;i<200;i++)
c+=a[i]*a[i];
printf("%I64d",c);
return(0);}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | cf21ba96bc6288b63a43bc1beb2ec94d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
long long int factorial(int n)
{
long long int a[n+1];
a[0]=1;
int i;
for(i=1;i<=n;i++)
{
a[i]=a[i-1]*i;
}
return a[n];
}
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int cmpi(const void *a,const void *b) {
return ((const int *)a)[0] - ((const int *)b)[0];
}
int min(int a,int b)
{
return (a>b?b:a);
}
int max(int a,int b)
{
return (a<b?b:a);
}
int main()
{
long long int n;
long long int i,j,a[207]={0},r[107],k;
long long int m=0;
char s[100001],t[100001];
char f[8][20]={"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"};
scanf("%s",s);
n=strlen(s);
for(i=0;i<n;i++)
{
j=(int)s[i];
a[j-48]++;
//printf("hiugkb->%d",j-48);
}
for(i=0;i<207;i++)
{
if(a[i]!=0)
m+=a[i]*(a[i]);
}
printf("%I64d\n",m);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 38d73b7ddb4c513f21fbbad036a4ac4d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <string.h>
int main()
{
long long int i,j,k=0,w,s,t,f;
char str[100001];
char ch[100001];
scanf("%s",str);
w=strlen(str);
for (i=0;i<w-1;i++){
f=0;
for (j=i+1;j<w;j++){
if (str[i]==str[j]){
f=1;
break;
}
}
if (f==0){
ch[k]=str[i];
k++;
}
}
ch[k]=str[w-1];
k++;
s=0;
for (i=0;i<k;i++){
t=0;
for (j=0;j<w;j++){
if (ch[i]==str[j]){
t=t+1;
}
}
s=s+t*t;
}
printf("%lld",s);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 3978ab6c9f76fa36c90f2b8ba79c0d1a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#include<string.h>
long long count[300];
int main()
{
int i=0,j,k;
char a[1000000];
while(1){
scanf("%c",&a[i]);
if(a[i]=='\n'){a[i]='\0';break;}
else{
count[a[i]]++;
}
i++;
}
long long sum=0;
for(j=0;j<i;j++){
sum+=count[a[j]];
}
printf("%I64d",sum);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | b5267e1f6d944ba593932e16f32fa902 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long long sum = 0 , i=0 ;
char word[100001] = {'/0'};
long long a[100001]={0};
gets(word);
long long length = strlen(word);
for (i=0 ; i< length ; i++)
{
a[word[i]]++ ;
}
for (i=0 ; i< 300 ; i++)
{
sum += a[i]*a[i];
}
printf("%I64d",sum);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 384e7c3a3bca79b30f25757c621e6e3d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | int s[260];
char str[100005];
int main()
{
int i;
long long ans=0;
gets(str+1);
for(i=1;str[i];i++) s[str[i]]++;
for(i=1;i<=260;i++) ans+=(long long)s[i]*s[i];
printf("%lld\n",ans);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 18cb4651d53688319b590cd4a6856e3c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | int s[260];
char str[100005];
main()
{
int i;
long long ans=0;
gets(str+1);
for(i=1;str[i];i++) s[str[i]]++;
for(i=1;i<=260;i++) ans+=(long long)s[i]*s[i];
printf("%lld\n",ans);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 36381a8e0f7bbad8b2f1d2bde3320ef8 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#define N 100001
int main()
{
char str[N];
int i,j;
unsigned long long sum,flag[270];
sum = 0;
scanf("%s",str);
for(i=0;i<270;i++)
flag[i] = (unsigned long long)0;
i = 0;
while(str[i])
{
flag[str[i]] += (unsigned long long)1;
i++;
}
i = 0;
for(i=0;i<270;i++)
sum += flag[i] * flag[i];
printf("%llu",sum);
return 0;
} | |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 54858768accad696dc8010ea34e1afe7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
char s[100001];
double arr[100001];
int len,i;
double n=0;
scanf("%s",s);
len=strlen(s);
memset(arr,0,sizeof(arr));
for(i=0;i<len;i++)
arr[s[i]]++;
for(i=0;i<100001;i++)
{
if(arr[i])
n+=arr[i]*arr[i];
}
printf("%.0lf\n",n);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | d3aa3448382c370e42e8fd1d88fb5d3c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | #include <stdio.h>
int s[333];
char str[100005];
int main()
{
int i;
long long ans=0;
gets(str+1);
for (i=1;str[i];i++)
s[str[i]]++;
for (i=1;i<=300;i++)
ans+=(long long)s[i]*s[i];
printf("%I64d\n",ans);
return 0;
}
| |
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1ββ€βi,βjββ€βN2. S[i]β=βS[j], that is the i-th symbol of string S is equal to the j-th. | Print a single number which represents the number of pairs i and j with the needed property. Pairs (x,βy) and (y,βx) should be considered different, i.e. the ordered pairs count. | C | 6bb2793e275426eb076972fab69d0eba | 8be5bb251abe4f2bdb11793b31456968 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"strings"
] | 1292862000 | ["great10", "aaaaaaaaaa"] | null | PASSED | 1,500 | standard input | 2 seconds | The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. | ["7", "100"] | int s[260];
char str[100005];
int main()
{
int i;
long long ans=0;
gets(str+1);
for(i=1;str[i];i++) s[str[i]]++;
for(i=1;i<=260;i++) ans+=(long long)s[i]*s[i];
printf("%I64d\n",ans);
return 0;
} | |
You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ integers.You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform the aforementioned operation no more than $$$k$$$ times. | Print the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform the aforementioned operation no more than $$$k$$$ times. | C | 51113dfdbf9f59152712b60e7a14368a | d922d0edf3d417817e70640f3fafcab5 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"constructive algorithms",
"two pointers",
"sortings",
"binary search",
"ternary search"
] | 1570957500 | ["4 5\n3 1 7 5", "3 10\n100 100 100", "10 9\n4 5 5 7 5 4 5 2 4 3"] | NoteIn the first example you can increase the first element twice and decrease the third element twice, so the sequence becomes $$$[3, 3, 5, 5]$$$, and the difference between maximum and minimum is $$$2$$$. You still can perform one operation after that, but it's useless since you can't make the answer less than $$$2$$$.In the second example all elements are already equal, so you may get $$$0$$$ as the answer even without applying any operations. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 10^{5}, 1 \le k \le 10^{14})$$$ β the number of elements in the sequence and the maximum number of times you can perform the operation, respectively. The second line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{9})$$$. | ["2", "0", "1"] | #include <stdio.h>
#define MX 100008
void swap(long long *a,long long *b){
long long t = *a;
*a = *b;
*b = t;
}
int maxChild(long long *a,int n,int r,int x,int y){
if(x<n && a[r]<a[x]) r = x;
if(y<n && a[r]<a[y]) r = y;
return r;
}
void heapify(long long *a,int n,int r){
int c = maxChild(a, n, r, 2*r+1, 2*r+2);
if(c!=r){
swap(&a[r],&a[c]);
heapify(a,n,c);
}
}
void sort(long long *a,int n){
for(int i = (n-2)/2;i>=0;i--){
heapify(a, n,i);
}
for(int i = n-1;i>=0;i--){
swap(&a[i],&a[0]);
heapify(a, i, 0);
}
}
long long min(long long x,long long y){return (x<y)?x:y;}
long long k, a[MX];
int main(){
int n;
scanf("%lld%lld",&n,&k);
for(int i = 0;i<n;i++){
scanf("%lld",a+i);
}
sort(a, n);
long long Ans = a[n-1] - a[0];
long long l = a[0],r = a[n-1];
int i = 0, j = n-1;
long long c1=1,c2 = 1;
while(i<j && k>0){
while(i<n-1 && l==a[i+1]) i++, c1++;
while(j>0 && r==a[j-1]) j--, c2++;
if(i>j) break;
if(c1<=c2){
long long t = min(k/c1, (a[i+1]-a[i]));
if(t==0) break;
l += t;
k -= (t*c1);
}
else{
long long t = min(k/c2, (a[j]-a[j-1]));
if(t==0) break;
r -= t;
k -= (t*c2);
}
}
Ans = (Ans>(r-l))? (r-l):Ans;
printf("%lld\n",Ans>0?Ans:0);
return 0;
} | |
You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ integers.You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform the aforementioned operation no more than $$$k$$$ times. | Print the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform the aforementioned operation no more than $$$k$$$ times. | C | 51113dfdbf9f59152712b60e7a14368a | 90c2fb00faf98326992083ce0cc0c16a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"constructive algorithms",
"two pointers",
"sortings",
"binary search",
"ternary search"
] | 1570957500 | ["4 5\n3 1 7 5", "3 10\n100 100 100", "10 9\n4 5 5 7 5 4 5 2 4 3"] | NoteIn the first example you can increase the first element twice and decrease the third element twice, so the sequence becomes $$$[3, 3, 5, 5]$$$, and the difference between maximum and minimum is $$$2$$$. You still can perform one operation after that, but it's useless since you can't make the answer less than $$$2$$$.In the second example all elements are already equal, so you may get $$$0$$$ as the answer even without applying any operations. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 10^{5}, 1 \le k \le 10^{14})$$$ β the number of elements in the sequence and the maximum number of times you can perform the operation, respectively. The second line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{9})$$$. | ["2", "0", "1"] | #include<stdio.h>
#include<math.h>
long long int a,b,sb1,sb2,i,j,k,l,times,shit,ass,n,cnm1,cnm2,cnm11,cnm22,mag,c,d,excited,ctmlgb=0,fuck[10000000],fuck2[300000];
int main()
{
scanf("%lld%lld",&a,&mag);
b=log2(a)+1;
for(i=0;i<=a-1;i++)
{
scanf("%lld",&fuck[i]);
}
for(i=1;i<=b;i++)
{
shit=pow(2,i);
times=a/shit;
ass=200000*(i-1);k=0;
for(j=1;j<=times;j++)
{
sb1=shit*(j-1);sb2=sb1+shit/2;n=sb1;
while(!(n==shit*(j-1)+shit))
{
if(fuck[sb1+ass]>=fuck[sb2+ass]){fuck[n+200000+ass]=fuck[sb2+ass];sb2++;n++;}
else{fuck[n+200000+ass]=fuck[sb1+ass];sb1++;n++;}
if(sb1>shit*(j-1)+shit/2-1){sb1--;fuck[sb1+ass]=999999999999;}
if(sb2>shit*(j-1)+shit-1){sb2--;fuck[sb2+ass]=999999999999;}
}
k++;
}
l=a-times*shit;if(k!=0){sb1=sb1+1+shit/2;sb2=sb2+1+shit/2;}else{sb1=shit*(j-1);sb2=sb1+shit/2;n=sb1;}
while(l>0)
{
if(fuck[sb1+ass]==0){fuck[sb1+ass]=999999999999;}
if(fuck[sb2+ass]==0){fuck[sb2+ass]=999999999999;}
if(fuck[sb1+ass]>=fuck[sb2+ass]){fuck[n+200000+ass]=fuck[sb2+ass];sb2++;n++;}
else{fuck[n+200000+ass]=fuck[sb1+ass];sb1++;n++;}
if(sb1>shit*(j-1)+shit/2-1){sb1--;fuck[sb1+ass]=999999999999;}
if(sb2>shit*(j-1)+shit-1){sb2--;fuck[sb2+ass]=999999999999;}
l--;
}
}
for(i=1;i<=a-1;i++)
{
fuck2[i-1]=fuck[200000+ass+i]-fuck[200000+ass+i-1];
}
cnm1=0;cnm2=a-2;cnm11=1;cnm22=1;excited=fuck[200000+ass+a-1]-fuck[200000+ass];
while(cnm1<=cnm2)
{
if(mag>=cnm11*fuck2[cnm1]){excited-=fuck2[cnm1];mag-=cnm11*fuck2[cnm1];cnm1++;cnm11++;}
else{excited-=(mag/cnm11);break;}
if(mag>=cnm22*fuck2[cnm2]){excited-=fuck2[cnm2];mag-=cnm22*fuck2[cnm2];cnm2--;cnm22++;}
else{excited-=(mag/cnm22);break;}
}
excited*=(excited>=0);
printf("%lld",excited);
return 0;
} | |
You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ integers.You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.Calculate the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform the aforementioned operation no more than $$$k$$$ times. | Print the minimum possible difference between the maximum element and the minimum element in the sequence, if you can perform the aforementioned operation no more than $$$k$$$ times. | C | 51113dfdbf9f59152712b60e7a14368a | 9cd724c01516e1b5dde4ff337174088f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"constructive algorithms",
"two pointers",
"sortings",
"binary search",
"ternary search"
] | 1570957500 | ["4 5\n3 1 7 5", "3 10\n100 100 100", "10 9\n4 5 5 7 5 4 5 2 4 3"] | NoteIn the first example you can increase the first element twice and decrease the third element twice, so the sequence becomes $$$[3, 3, 5, 5]$$$, and the difference between maximum and minimum is $$$2$$$. You still can perform one operation after that, but it's useless since you can't make the answer less than $$$2$$$.In the second example all elements are already equal, so you may get $$$0$$$ as the answer even without applying any operations. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 10^{5}, 1 \le k \le 10^{14})$$$ β the number of elements in the sequence and the maximum number of times you can perform the operation, respectively. The second line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{9})$$$. | ["2", "0", "1"] | #include<string.h>
#include<stdio.h>
#include<stdlib.h>
void merge(long long* arr, long long p, long long q, long long r) {
long long i = 0, j = 0;
long long* L = (long long*)malloc(sizeof(long long) * (q - p + 1));
long long* R = (long long*)malloc(sizeof(long long)*(r - q));
for (i = 0; i < q - p + 1; i++) {
L[i] = arr[p + i];
}
for (j = 0; j < r - q ; j++) {
R[j] = arr[q + 1 + j];
}
i = 0;
j = 0;
while (i < q - p + 1 && j < r - q) {
if (L[i] <= R[j]) {
arr[p + i + j] = L[i];
i++;
}
else {
arr[p + i + j] = R[j];
j++;
}
}
while (i < q - p + 1) {
arr[p + i + j] = L[i];
i++;
}
while (j < r - q) {
arr[p + i + j] = R[j];
j++;
}
free(L);
free(R);
L = NULL;
R = NULL;
}
void merge_sort(long long* arr, long long p, long long r) {
if (p < r) {
long long q = (p + r) / 2;
merge_sort(arr, p, q);
merge_sort(arr, q + 1, r);
merge(arr, p, q, r);
}
}
int main()
{
long long n;
long long k;
scanf("%lld%lld",&n,&k);
long long a[n+1];
for(long long i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
merge_sort(a,1,n);
int c1=1,c2=n;
for(long long i=1;i<=n;i++)
{
if(a[i]==a[c1])
{
c1=i;
}
else break;
}
for(long long i=n;i>0;i--)
{
if(a[i]==a[c2])
{
c2=i;
}
else break;
}
long long t=0;
while(c1<c2)
{
if(c1>n-c2+1)
{
if(k>=(n-c2+1)*(a[c2]-a[c2-1]))
{
k-=(n-c2+1)*(a[c2]-a[c2-1]);
c2--;
for(long long i=c2;i>=1;i--)
{
if(a[i]==a[c2])
{
c2=i;
}
else break;
}
}
else
{
t=k/(n-c2+1);
break;
}
}
else
{
if(k>=(c1)*(a[c1+1]-a[c1]))
{
k-=(c1)*(a[c1+1]-a[c1]);
c1++;
for(long long i=c1;i<=n;i++)
{
if(a[i]==a[c1])
{
c1=i;
}
else break;
}
}
else
{
t=k/c1;
break;
}
}
}
if(c1>=c2) printf("0\n");
else printf("%lld\n",a[c2]-a[c1]-t);
return 0;
} | |
DZY loves Physics, and he enjoys calculating density.Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: where v is the sum of the values of the nodes, e is the sum of the values of the edges.Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.An induced subgraph G'(V',βE') of a graph G(V,βE) is a graph that satisfies: ; edge if and only if , and edge ; the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node. Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected. | Output a real number denoting the answer, with an absolute or relative error of at most 10β-β9. | C | ba4304e79d85d13c12233bcbcce6d0a6 | e660470a55a8a67b20c52a7c5b092ff4 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"math"
] | 1404651900 | ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63"] | NoteIn the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.In the second sample, choosing the whole graph is optimal. | PASSED | 1,600 | standard input | 1 second | The first line contains two space-separated integers nΒ (1ββ€βnββ€β500), . Integer n represents the number of nodes of the graph G, m represents the number of edges. The second line contains n space-separated integers xiΒ (1ββ€βxiββ€β106), where xi represents the value of the i-th node. Consider the graph nodes are numbered from 1 to n. Each of the next m lines contains three space-separated integers ai,βbi,βciΒ (1ββ€βaiβ<βbiββ€βn;Β 1ββ€βciββ€β103), denoting an edge between node ai and bi with value ci. The graph won't contain multiple edges. | ["0.000000000000000", "3.000000000000000", "2.965517241379311"] | #include <stdio.h>
#include <stdlib.h>
int nodes[500];
struct edge
{
int a;
int b;
double value;
};
struct edge edges[124750];
int cmp(const void* a,const void* b)
{
struct edge *c,*d;
c=(struct edge*)a;
d=(struct edge*)b;
return d->value-c->value;
}
int main()
{
int n,m;
int i;
double max;
memset(nodes,sizeof(int),500);
memset(edges,sizeof(struct edge),124750);
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
scanf("%d",&nodes[i]);
if(m==0)
{
printf("0.000000000000000\n");
return 0;
}
max=0;
for(i=0;i<m;i++)
{
scanf("%d %d %lf",&edges[i].a,&edges[i].b,&edges[i].value);
edges[i].value=(nodes[edges[i].a-1]+nodes[edges[i].b-1])/edges[i].value;
if(edges[i].value>max)
max=edges[i].value;
}
printf("%.*lf\n",15,max);
return 0;
}
| |
DZY loves Physics, and he enjoys calculating density.Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: where v is the sum of the values of the nodes, e is the sum of the values of the edges.Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.An induced subgraph G'(V',βE') of a graph G(V,βE) is a graph that satisfies: ; edge if and only if , and edge ; the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node. Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected. | Output a real number denoting the answer, with an absolute or relative error of at most 10β-β9. | C | ba4304e79d85d13c12233bcbcce6d0a6 | 3172a4e3137f8e6da35bbf95e756d477 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"math"
] | 1404651900 | ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63"] | NoteIn the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.In the second sample, choosing the whole graph is optimal. | PASSED | 1,600 | standard input | 1 second | The first line contains two space-separated integers nΒ (1ββ€βnββ€β500), . Integer n represents the number of nodes of the graph G, m represents the number of edges. The second line contains n space-separated integers xiΒ (1ββ€βxiββ€β106), where xi represents the value of the i-th node. Consider the graph nodes are numbered from 1 to n. Each of the next m lines contains three space-separated integers ai,βbi,βciΒ (1ββ€βaiβ<βbiββ€βn;Β 1ββ€βciββ€β103), denoting an edge between node ai and bi with value ci. The graph won't contain multiple edges. | ["0.000000000000000", "3.000000000000000", "2.965517241379311"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define me(x) (memset(x,0,sizeof(x)))
long n,m,va[505];
double max(double x,double y)
{
return x>y?x:y;
}
int main()
{
long i,a,b,c;
double ans=0;
scanf("%ld %ld",&n,&m);
if (m==0) {printf("%.15lf",0.0); return 0;}
for (i=1;i<=n;i++) scanf("%ld",&va[i]);
for (i=1;i<=m;i++)
{
scanf("%ld %ld %ld",&a,&b,&c);
ans=max(ans,(double)(va[a]+va[b])/c);
}
printf("%.15lf",ans);
return 0;
}
| |
DZY loves Physics, and he enjoys calculating density.Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: where v is the sum of the values of the nodes, e is the sum of the values of the edges.Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.An induced subgraph G'(V',βE') of a graph G(V,βE) is a graph that satisfies: ; edge if and only if , and edge ; the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node. Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected. | Output a real number denoting the answer, with an absolute or relative error of at most 10β-β9. | C | ba4304e79d85d13c12233bcbcce6d0a6 | 1e7299009ac2f60fa8d055cfa7d4273b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"math"
] | 1404651900 | ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63"] | NoteIn the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.In the second sample, choosing the whole graph is optimal. | PASSED | 1,600 | standard input | 1 second | The first line contains two space-separated integers nΒ (1ββ€βnββ€β500), . Integer n represents the number of nodes of the graph G, m represents the number of edges. The second line contains n space-separated integers xiΒ (1ββ€βxiββ€β106), where xi represents the value of the i-th node. Consider the graph nodes are numbered from 1 to n. Each of the next m lines contains three space-separated integers ai,βbi,βciΒ (1ββ€βaiβ<βbiββ€βn;Β 1ββ€βciββ€β103), denoting an edge between node ai and bi with value ci. The graph won't contain multiple edges. | ["0.000000000000000", "3.000000000000000", "2.965517241379311"] | #include<stdio.h>
double a[501];
int main()
{
int x,y,n,m,i;
double max=0,c;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
scanf("%lf",a+i);
while(m--)
{
scanf("%d%d%lf",&x,&y,&c);
if((a[x]+a[y])/c>max)
max=(a[x]+a[y])/c;
}
printf("%0.9lf",max);
return 0;
}
| |
DZY loves Physics, and he enjoys calculating density.Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: where v is the sum of the values of the nodes, e is the sum of the values of the edges.Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.An induced subgraph G'(V',βE') of a graph G(V,βE) is a graph that satisfies: ; edge if and only if , and edge ; the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node. Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected. | Output a real number denoting the answer, with an absolute or relative error of at most 10β-β9. | C | ba4304e79d85d13c12233bcbcce6d0a6 | 967874c0e34dac4d29fb6678ae17ac95 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"greedy",
"math"
] | 1404651900 | ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63"] | NoteIn the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.In the second sample, choosing the whole graph is optimal. | PASSED | 1,600 | standard input | 1 second | The first line contains two space-separated integers nΒ (1ββ€βnββ€β500), . Integer n represents the number of nodes of the graph G, m represents the number of edges. The second line contains n space-separated integers xiΒ (1ββ€βxiββ€β106), where xi represents the value of the i-th node. Consider the graph nodes are numbered from 1 to n. Each of the next m lines contains three space-separated integers ai,βbi,βciΒ (1ββ€βaiβ<βbiββ€βn;Β 1ββ€βciββ€β103), denoting an edge between node ai and bi with value ci. The graph won't contain multiple edges. | ["0.000000000000000", "3.000000000000000", "2.965517241379311"] | #include<stdio.h>
double max(double a,double b){return a>b?a:b;}
main()
{
int n,m,i,u,v;double ans=0,edge_val;
scanf("%d%d",&n,&m);
double a[n+1]; for(i=1; i<=n; i++) scanf("%lf",&a[i]);
for(i=0; i<m; i++)
{
scanf("%d%d%lf",&u,&v,&edge_val);
ans = max(ans,(a[u]+a[v])/edge_val);
}
printf("%.12lf",ans);return 0;
}
| |
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and mβ-β1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x,βy) either yβ=β0, or there is a cube with coordinates (xβ-β1,βyβ-β1), (x,βyβ-β1) or (xβ+β1,βyβ-β1).Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109β+β9. | In the only line print the answer to the problem. | C | 9f36d49541e6dd7082e37416cdb1949c | 76b0328be1a0747b6ca63c00105fa6a4 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"greedy",
"games"
] | 1425279600 | ["3\n2 1\n1 0\n0 1", "5\n0 0\n0 1\n0 2\n0 3\n0 4"] | null | PASSED | 2,100 | standard input | 3 seconds | The first line contains number m (2ββ€βmββ€β105). The following m lines contain the coordinates of the cubes xi,βyi (β-β109ββ€βxiββ€β109, 0ββ€βyiββ€β109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable. No two cubes occupy the same place. | ["19", "2930"] | #include <stdio.h>
#include <stdlib.h>
typedef long long ll;
typedef int pair[2];
#define TAM ((1<<17)+5)
#define MOD 1000000009LL
#define add(a,b) (((a)+(b))%MOD)
#define prod(a,b) (((a)*(b))%MOD)
#define assign(a,b) memcpy(a,b,sizeof(a))
int cmp_int ( int a, int b ) {
return ( a < b ? -1 : ( a == b ? 0 : 1 ) );
}
int cmp ( const pair a, const pair b ) {
if ( a[0] != b[0] )
return cmp_int(a[0],b[0]);
return cmp_int(a[1],b[1]);
}
int n;
pair init_a[TAM], a[TAM];
int ans[TAM], new_index[TAM], old_index[TAM], out[TAM];
int bit[TAM];
void update ( int i, int x ) {
for ( i++; i <= TAM; i += (i&(-i)) )
bit[i] += x;
}
int query ( int i ) {
int r = 0;
for ( i++; i; i -= (i&(-i)) )
r += bit[i];
return r;
}
int is_on ( int i ) {
return query(i)-query(i-1);
}
int get_min ( ) {
int ans = 0, p = 1<<16;
for ( ; p ; p >>= 1 )
if ( bit[ans+p] == 0 )
ans += p;
return ans;
}
int get_max ( ) {
int ans = 0, p = 1<<16;
int wanted = bit[1<<17];
for ( ; p; p >>= 1 )
if ( bit[ans+p] < wanted ) {
wanted -= bit[ans+p];
ans += p;
}
return ans;
}
int get ( const pair x ) {
int lo = 0, hi = n-1, mi;
while ( lo < hi ) {
mi = (lo+hi)/2;
if ( cmp(a[mi],x) < 0 ) lo = mi+1;
else hi = mi;
}
if ( cmp(a[lo],x) )
return -1;
return lo;
}
int falls_without ( int i, int wo ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != wo && ni != -1 && !out[ni] )
return 0;
p[0] -= d0;
}
return 1;
}
int can_remove ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]++;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] && falls_without(ni,i) )
return 0;
p[0] -= d0;
}
return 1;
}
void recheck ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
for ( d0 = -2; d0 <= 2; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] )
if ( is_on(old_index[ni]) && !can_remove(ni) )
update(old_index[ni],-1);
p[0] -= d0;
}
return 1;
}
int main ( )
{
int turn, i;
scanf ( "%d", &n );
for ( i = 0; i < n; ++i )
scanf ( "%d%d", &a[i][0], &a[i][1] );
assign ( init_a, a );
qsort ( a, n, sizeof(pair), cmp );
for ( i = 0; i < n; ++i ) {
new_index[i] = get ( init_a[i] );
old_index[new_index[i]] = i;
}
for ( i = 0; i < n; ++i )
if ( can_remove(i) )
update ( old_index[i], 1 );
for ( turn = 0; turn < n; ++turn )
{
if ( turn&1 ) i = get_min();
else i = get_max();
ans[turn] = i;
update ( i, -1 );
i = new_index[i];
out[i] = 1;
recheck ( i );
int d0, ni;
pair p;
assign ( p, a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && can_remove(ni) && !out[ni] && !is_on(old_index[ni]) )
update ( old_index[ni], 1 );
p[0] -= d0;
}
}
ll r = 0, b = 1;
for ( i = n-1; i >= 0; --i ) {
r = add ( r, prod(b,(ll)ans[i]) );
b = prod(b,(ll)n);
}
printf ( "%d\n", (int) r );
return 0;
}
| |
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and mβ-β1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x,βy) either yβ=β0, or there is a cube with coordinates (xβ-β1,βyβ-β1), (x,βyβ-β1) or (xβ+β1,βyβ-β1).Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109β+β9. | In the only line print the answer to the problem. | C | 9f36d49541e6dd7082e37416cdb1949c | cfbb3896e1257977462b2f2cfcf38833 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"greedy",
"games"
] | 1425279600 | ["3\n2 1\n1 0\n0 1", "5\n0 0\n0 1\n0 2\n0 3\n0 4"] | null | PASSED | 2,100 | standard input | 3 seconds | The first line contains number m (2ββ€βmββ€β105). The following m lines contain the coordinates of the cubes xi,βyi (β-β109ββ€βxiββ€β109, 0ββ€βyiββ€β109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable. No two cubes occupy the same place. | ["19", "2930"] | #include <stdio.h>
#include <stdlib.h>
typedef long long ll;
typedef int pair[2];
#define TAM 100100
#define MOD 1000000009LL
#define add(a,b) (((a)+(b))%MOD)
#define prod(a,b) (((a)*(b))%MOD)
#define assign(a,b) memcpy(a,b,sizeof(a))
int cmp_int ( int a, int b ) {
return ( a < b ? -1 : ( a == b ? 0 : 1 ) );
}
int cmp ( const pair a, const pair b ) {
if ( a[0] != b[0] )
return cmp_int(a[0],b[0]);
return cmp_int(a[1],b[1]);
}
int n;
pair init_a[TAM], a[TAM];
int ans[TAM], new_index[TAM], old_index[TAM], out[TAM];
int bit[TAM];
void update ( int i, int x ) {
for ( i++; i < TAM; i += (i&(-i)) )
bit[i] += x;
}
int query ( int i ) {
int r = 0;
for ( i++; i; i -= (i&(-i)) )
r += bit[i];
return r;
}
int is_on ( int i ) {
return query(i)-query(i-1);
}
int get_min ( ) {
int lo = 0, hi = n-1, mi;
while ( lo < hi ) {
mi = (lo+hi)/2;
if ( query(mi) == 0 ) lo = mi+1;
else hi = mi;
}
return lo;
}
int get_max ( ) {
int lo = 0, hi = n-1, mi, total = query(n-1);
while ( lo < hi ) {
mi = (lo+hi)/2;
if ( query(mi) < total ) lo = mi+1;
else hi = mi;
}
return lo;
}
int get ( const pair x ) {
int lo = 0, hi = n-1, mi;
while ( lo < hi ) {
mi = (lo+hi)/2;
if ( cmp(a[mi],x) < 0 ) lo = mi+1;
else hi = mi;
}
if ( cmp(a[lo],x) )
return -1;
return lo;
}
int falls_without ( int i, int wo ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != wo && ni != -1 && !out[ni] )
return 0;
p[0] -= d0;
}
return 1;
}
int can_remove ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]++;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] && falls_without(ni,i) )
return 0;
p[0] -= d0;
}
return 1;
}
void recheck ( int i ) {
if ( is_on(old_index[i]) && !can_remove(i) )
update(old_index[i],-1);
}
void recheck_sons ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] )
recheck ( ni );
p[0] -= d0;
}
return 1;
}
void recheck_cousins ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]++;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] )
recheck_sons ( ni );
p[0] -= d0;
}
return 1;
}
int main ( )
{
int turn, i;
scanf ( "%d", &n );
for ( i = 0; i < n; ++i )
scanf ( "%d%d", &a[i][0], &a[i][1] );
assign ( init_a, a );
qsort ( a, n, sizeof(pair), cmp );
for ( i = 0; i < n; ++i ) {
new_index[i] = get ( init_a[i] );
old_index[new_index[i]] = i;
}
for ( i = 0; i < n; ++i )
if ( can_remove(i) )
update ( old_index[i], 1 );
for ( turn = 0; turn < n; ++turn )
{
if ( turn&1 ) i = get_min();
else i = get_max();
ans[turn] = i;
update ( i, -1 );
i = new_index[i];
out[i] = 1;
recheck_cousins ( i );
int d0, ni;
pair p;
assign ( p, a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && can_remove(ni) && !out[ni] && !is_on(old_index[ni]) )
update ( old_index[ni], 1 );
p[0] -= d0;
}
}
ll r = 0, b = 1;
for ( i = n-1; i >= 0; --i ) {
r = add ( r, prod(b,(ll)ans[i]) );
b = prod(b,(ll)n);
}
printf ( "%d\n", (int) r );
return 0;
}
| |
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and mβ-β1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (x,βy) either yβ=β0, or there is a cube with coordinates (xβ-β1,βyβ-β1), (x,βyβ-β1) or (xβ+β1,βyβ-β1).Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the m-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109β+β9. | In the only line print the answer to the problem. | C | 9f36d49541e6dd7082e37416cdb1949c | e0c4b370a4135ed1e37db5758de13392 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"greedy",
"games"
] | 1425279600 | ["3\n2 1\n1 0\n0 1", "5\n0 0\n0 1\n0 2\n0 3\n0 4"] | null | PASSED | 2,100 | standard input | 3 seconds | The first line contains number m (2ββ€βmββ€β105). The following m lines contain the coordinates of the cubes xi,βyi (β-β109ββ€βxiββ€β109, 0ββ€βyiββ€β109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable. No two cubes occupy the same place. | ["19", "2930"] | #include <stdio.h>
#include <stdlib.h>
typedef long long ll;
typedef int pair[2];
#define TAM (1<<18)
#define MOD 1000000009LL
#define add(a,b) (((a)+(b))%MOD)
#define prod(a,b) (((a)*(b))%MOD)
#define assign(a,b) memcpy(a,b,sizeof(a))
int cmp_int ( int a, int b ) {
return ( a < b ? -1 : ( a == b ? 0 : 1 ) );
}
int cmp ( const pair a, const pair b ) {
if ( a[0] != b[0] )
return cmp_int(a[0],b[0]);
return cmp_int(a[1],b[1]);
}
int n;
pair init_a[TAM], a[TAM];
int ans[TAM], new_index[TAM], old_index[TAM], out[TAM];
int bit[TAM];
void update ( int i, int x ) {
for ( i++; i < TAM; i += (i&(-i)) )
bit[i] += x;
}
int query ( int i ) {
int r = 0;
for ( i++; i; i -= (i&(-i)) )
r += bit[i];
return r;
}
int is_on ( int i ) {
return query(i)-query(i-1);
}
int get_min ( ) {
int ans = 0, p = (TAM>>1);
for ( ; p ; p >>= 1 )
if ( bit[ans+p] == 0 )
ans += p;
return ans;
}
int get_max ( ) {
int ans = 0, p = (TAM>>1);
int wanted = bit[p];
for ( p >>= 1; p; p >>= 1 )
if ( bit[ans+p] < wanted ) {
wanted -= bit[ans+p];
ans += p;
}
return ans;
}
int get ( const pair x ) {
int lo = 0, hi = n-1, mi;
while ( lo < hi ) {
mi = (lo+hi)/2;
if ( cmp(a[mi],x) < 0 ) lo = mi+1;
else hi = mi;
}
if ( cmp(a[lo],x) )
return -1;
return lo;
}
int falls_without ( int i, int wo ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != wo && ni != -1 && !out[ni] )
return 0;
p[0] -= d0;
}
return 1;
}
int can_remove ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
p[1]++;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] && falls_without(ni,i) )
return 0;
p[0] -= d0;
}
return 1;
}
void recheck ( int i ) {
int d0, ni;
pair p;
assign ( p , a[i] );
for ( d0 = -2; d0 <= 2; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && !out[ni] )
if ( is_on(old_index[ni]) && !can_remove(ni) )
update(old_index[ni],-1);
p[0] -= d0;
}
return 1;
}
int main ( )
{
int turn, i;
scanf ( "%d", &n );
for ( i = 0; i < n; ++i )
scanf ( "%d%d", &a[i][0], &a[i][1] );
assign ( init_a, a );
qsort ( a, n, sizeof(pair), cmp );
for ( i = 0; i < n; ++i ) {
new_index[i] = get ( init_a[i] );
old_index[new_index[i]] = i;
}
for ( i = 0; i < n; ++i )
if ( can_remove(i) )
update ( old_index[i], 1 );
for ( turn = 0; turn < n; ++turn )
{
if ( turn&1 ) i = get_min();
else i = get_max();
ans[turn] = i;
update ( i, -1 );
i = new_index[i];
out[i] = 1;
recheck ( i );
int d0, ni;
pair p;
assign ( p, a[i] );
p[1]--;
for ( d0 = -1; d0 <= 1; ++d0 ) {
p[0] += d0;
ni = get(p);
if ( ni != -1 && can_remove(ni) && !out[ni] && !is_on(old_index[ni]) )
update ( old_index[ni], 1 );
p[0] -= d0;
}
}
ll r = 0, b = 1;
for ( i = n-1; i >= 0; --i ) {
r = add ( r, prod(b,(ll)ans[i]) );
b = prod(b,(ll)n);
}
printf ( "%d\n", (int) r );
return 0;
}
| |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. | Print a single integerΒ β the minimum number of beacons that could be destroyed if exactly one beacon is added. | C | bcd689387c9167c7d0d45d4ca3b0c4c7 | 3896d7eefd92316bba01f358b0153d9c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp"
] | 1450888500 | ["4\n1 9\n3 1\n6 1\n7 4", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1"] | NoteFor the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | PASSED | 1,600 | standard input | 2 seconds | The first line of input contains a single integer n (1ββ€βnββ€β100β000) β the initial number of beacons. The i-th of next n lines contains two integers ai and bi (0ββ€βaiββ€β1β000β000, 1ββ€βbiββ€β1β000β000)Β β the position and power level of the i-th beacon respectively. No two beacons will have the same position, so aiββ βaj if iββ βj. | ["1", "3"] | #include<stdio.h>
int arr[2][100005],brr[2][100005];
int dp[1000003];
void merge(int b[][100005],int start,int mid ,int end)
{
int lctr=start,rctr=mid,k=0;
for(k=start;lctr<mid&&rctr<end;k++)
{
if(b[0][lctr]<b[0][rctr])
{
brr[1][k]=b[1][lctr];
brr[0][k]=b[0][lctr];
lctr++;
}
else
{
brr[1][k]=b[1][rctr];
brr[0][k]=b[0][rctr];
rctr++;
}
}
while(lctr<mid)
{
brr[1][k]=b[1][lctr];
brr[0][k]=b[0][lctr];
lctr++;
k++;
}
while(rctr<end)
{
brr[1][k]=b[1][rctr];
brr[0][k]=b[0][rctr];
rctr++;
k++;
}
for(int i=start;i<end;i++)
{
b[1][i]=brr[1][i];
b[0][i]=brr[0][i];
}
}
void mergesort(int ar[][100005],int start, int end)
{
int size=end-start;
if(size==1)
return;
int mid=size/2;
//printf("Sizesssss %d %d %d\n",start,mid,end);
//getchar();
mergesort(ar,start,start+mid);
mergesort(ar,start+mid,end);
merge(ar,start,start+mid,end);
}
int main()
{
int n,i,j,k,ctr=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d %d",&arr[0][i],&arr[1][i]);
}
mergesort(arr,0,n);
if(arr[0][0]==0)
dp[0]=1;
else
dp[0]=0;
if(arr[0][0]==0)
ctr++;
for(int i=1;i<=arr[0][n-1];i++)
{
if(arr[0][ctr]!=i)
{
dp[i]=dp[i-1];
}
else
{
if(i-arr[1][ctr]>0)
{
dp[i]=dp[i-arr[1][ctr]-1]+1;
}
else
{
dp[i]=1;
}
ctr++;
}
}
int max=dp[0];
for(i=1;i<=arr[0][n-1];i++)
{
if(dp[i]>max)
max=dp[i];
}
printf("%d\n",n-max);
return 0;
}
| |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. | Print a single integerΒ β the minimum number of beacons that could be destroyed if exactly one beacon is added. | C | bcd689387c9167c7d0d45d4ca3b0c4c7 | 2d49e926f09cef71a1562996fefaeb3d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp"
] | 1450888500 | ["4\n1 9\n3 1\n6 1\n7 4", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1"] | NoteFor the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | PASSED | 1,600 | standard input | 2 seconds | The first line of input contains a single integer n (1ββ€βnββ€β100β000) β the initial number of beacons. The i-th of next n lines contains two integers ai and bi (0ββ€βaiββ€β1β000β000, 1ββ€βbiββ€β1β000β000)Β β the position and power level of the i-th beacon respectively. No two beacons will have the same position, so aiββ βaj if iββ βj. | ["1", "3"] | #include<stdio.h>
typedef unsigned u;
u D[1111111],B[1111111];
int main()
{
u n,i=-1,j,k,l,s,r=-1;
for(scanf("%u",&n);++i<n;D[j]=k)scanf("%u%u",&j,&k);
for(i=-1;++i<1111111;)if(D[i])
{
B[i]=(k=i?B[i-1]:0)+1;
j=D[i];
l=i>j?i-j-1:-1u;
if(l==-1u)s=k;
else s=k-B[l]+D[l];
D[i]=s;
if(r>(s+=n-k-1))r=s;
}
else if(i){D[i]=D[i-1];B[i]=B[i-1];}
printf("%u\n",r);
return 0;
}
| |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated.Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. | Print a single integerΒ β the minimum number of beacons that could be destroyed if exactly one beacon is added. | C | bcd689387c9167c7d0d45d4ca3b0c4c7 | d2059931afc48ac51a90ae2b7ec9f13c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp"
] | 1450888500 | ["4\n1 9\n3 1\n6 1\n7 4", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1"] | NoteFor the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | PASSED | 1,600 | standard input | 2 seconds | The first line of input contains a single integer n (1ββ€βnββ€β100β000) β the initial number of beacons. The i-th of next n lines contains two integers ai and bi (0ββ€βaiββ€β1β000β000, 1ββ€βbiββ€β1β000β000)Β β the position and power level of the i-th beacon respectively. No two beacons will have the same position, so aiββ βaj if iββ βj. | ["1", "3"] | #include<stdio.h>
#include<stdlib.h>
typedef struct __BEAM{
int ind;
int p;
}BEAM;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int cmpfunc(const void *a,const void *b){
return ((BEAM *)a)->ind-((BEAM *)b)->ind;
}
int main(){
int n,left[1000006],dp[100005],i,j;
BEAM ar[100005];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&ar[i].ind,&ar[i].p);
}
qsort(ar,n,sizeof(BEAM),cmpfunc);
// for(i=0;i<n;i++)printf("%d %d\n",ar[i].ind,ar[i].p);
j=-1;
for(i=0;i<1000006&&j<n+1;i++){
if(ar[j+1].ind<=i)j++;
left[i]=j;
}
for(i=0;i<n;i++){
j=ar[i].ind-ar[i].p-1;
if(j<0||left[j]<0){
// printf("%d zero\n",j);
dp[i]=1;
}
else{
// printf("j=%d left=%d\n",j,left[j]);
dp[i]=1+dp[left[j]];
}
}
//for(i=0;i<n;i++)printf("dp=%d\n",dp[i]);
j=dp[n-1]+1;
for(i=0;i<n;i++){
j=max(j,1+dp[i]);
}
printf("%d\n",n+1-j);
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 1f8e6d2bf52bb1ebbbece640244907bb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include <math.h>
// #include <bits/stdc++.h>
// #define RET(_x) return std::cout << (_x) << '\n', 0;
// #define endl "\n"
// using namespace std;
// using ll = int64_t;
int main() {
// ios_base::sync_with_stdio(false);
// std::cin.tie(nullptr);
int n;
scanf("%d", &n);
int min0 = 1e9;
int min1 = 1e9;
int max1 = -1;
int max0 = -1;
int cur0 = 0;
int cur1 = 0;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
if (x == 1) {
if (cur0) {
max0 = fmax(max0, cur0);
min0 = fmin(min0, cur0);
}
cur0 = 0;
++cur1;
} else {
if (cur1) {
max1 = fmax(max1, cur1);
min1 = fmin(min1, cur1);
}
cur1 = 0;
++cur0;
}
}
if (cur0) {
max0 = fmax(max0, cur0);
min0 = fmin(min0, cur0);
}
if (cur1) {
max1 = fmax(max1, cur1);
min1 = fmin(min1, cur1);
}
if (min1 == max1 && max0 == min0 && min0 == min1 || max1 == -1 || max0 == -1) {
puts("YES");
} else {
puts("NO");
}
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 13680060a6794ba4f99ea9bb293ff3bd | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include "stdio.h"
int main(void) {
int n;
scanf("%d",&n);
int i;
int first_num;
int j = 0;
scanf("%d",&first_num);
int per = 0;
for(i = 1;i < n;i++)
{
int k;
scanf("%d",&k);
if(k != first_num)
{
if(!per)
{
per = i;
}
first_num = k;
if(i-j == per)
j = i;
else
{
printf("NO\n");
return 0;
}
}
}
if(n-j == per || !per)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 5ac2cd9c73972a86b7899e8009b41d06 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include<stdio.h>
#include <conio.h>
#include <math.h>
#define M_PI 3.14159265358979323846
#pragma comment (linker, "/STACK:5000000000")
#define ll long long
#define sc(a) scanf("%d", &(a));
#define scl(a) scanf("%I64d", &(a));
#define mp make_pair
#define pb push_back
//const long long m = 1000000007;
const int INF = 1000000000;
const double esp = 1e-10;
//ll bin_pow(ll a, ll n) {
// if (n == 0) return 1;
// if (n == 1) return a;
// if (n % 2 == 0) {
// ll b = bin_pow(a, n / 2);
// return ((b%m)*(b%m)) % m;
// }
// else return ((a%m)*(bin_pow(a, n - 1) % m) % m);
//
//}
int main(){
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
int n, w1=0, w2=-1, t=0, l=-1;
sc( n);
for (int i = 0; i < n; i++) {
int q;
sc( q);
if (l == -1) {
l = q;
}
if (q != l ) {
if (w2 != -1) {
if (w1 != w2) {
printf("NO"); return 0;
}
else {
w1 = 1;
l = q;
}
}
else {
w2 = w1;
w1 = 1;
l = q;
}
}
else w1++;
}
if (w2 != w1 && w2!=-1) { printf("NO"); return 0; }
printf("YES");
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | e01482e75e347ae18d2bfdc9bc0a62f1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | //
// main.cpp
// test
//
// Created by ΠΠ°ΠΊΡΠΈΠΌ ΠΠ°ΡΡΡΠΈΠ½ on 04.02.17.
// Copyright Β© 2017 ΠΠ°ΠΊΡΠΈΠΌ ΠΠ°ΡΡΡΠΈΠ½. All rights reserved.
//
#include <stdio.h>
//using namespace std;
int mas[100005];
char func(int d, int r, char zero) {
char good = 1;
for(int j = 0; j < d; j++) {
for(int t = 0; t < r; t++) {
if(mas[j*r + t]==zero) {
good = 0;
break;
}
}
zero = !zero;
if(!good)
break;
}
return good;
}
int main(){
//freopen(FILE".in", "r", stdin);
//freopen(FILE".out", "w", stdout);
//ios_base::sync_with_stdio(0);
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", &mas[i]);
}
char zero;
if(mas[0])
zero = 0;
else
zero = 1;
for(int i = 1; i * i <= n; i++) {
if(n%i == 0) {
int d = i, r = n/i;
if(func(d, r, zero) || func(r, d, zero)) {
printf("YES");
return 0;
}
}
}
printf("NO");
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 10111c5e25c974420eab3a4400aa074d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include<stdio.h>
#include<stdlib.h>
struct pair {
int first, second;
};
struct pair a[100005];
int point = 0;
void push(int x, int y) {
a[point].first = x;
a[point].second = y;
point++;
}
int main() {
long n;
scanf("%ld", &n);
int ar[n];
for(int i = 0; i < n; ++i) scanf("%d", &ar[i]);
for(int i = 0; i < n; ++i) {
if(!point || a[point - 1].first != ar[i]) {
push(ar[i], 1);
} else {
a[point - 1].second++;
}
}
for(int i = point - 1; i >= 1; --i) {
if(a[i].second != a[i - 1].second) {
return puts("NO");
}
}
puts("YES");
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 08ba85c8b875d557110f6c800e138ce1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
int mn = 100005;
int a[10005];
int main()
{
int n, i, x, p = 0, len=-1, cur = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x);
if (i == 0) {
cur = 1;
} else {
if (x == p) {
cur = cur + 1;
} else {
if (len == -1) {
len = cur;
cur = 1;
} else {
if (len == cur) {
cur = 1;
} else {
printf("NO");
return 0;
}
}
}
}
p = x;
}
if (len == -1) {
len = cur;
cur = 1;
} else {
if (len == cur) {
cur = 1;
} else {
printf("NO");
return 0;
}
}
printf("YES");
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | ed2ba5d33533f8722c967ef349556436 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
#pragma warning(disable : 4996)
int main()
{
int n;
scanf("%i", &n);
int col0 = 1, col1 = 0, maxCol = 0;
int a;
int last;
scanf("%i", &last);
int q = 1;
for (q; q < n; q++)
{
scanf("%i", &a);
if (a == last)
col0++;
else break;
}
last = a;
maxCol = col0;
if (q == n)
{
printf("%s", "YES");
return 0;
}
col1 = 1;
q++;
for (q; q < n; q++)
{
scanf("%i", &a);
if (a == last)
col1++;
else
{
if (col1 != maxCol)
{
printf("%s", "NO");
return 0;
}
else
{
last = a;
col1 = 1;
}
}
}
if (col1 != maxCol)
printf("NO");
else printf("YES");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 0cd76c7453983328f74ba70fdf0c8448 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include "stdio.h"
#include "stdlib.h"
int main(){
int w;
scanf("%d", &w);
// int* p = malloc(sizeof(int) * w);
int counting = 1;
int c = 0;
int acc = 0;
int first_col;
int curr_col;
int fail = 0;
for(int i = 0; i < w; ++i){
int x;
scanf("%d", &x);
if(i==0){
first_col = x;
++c;
++acc;
}
else
{
if(counting){
if(x == first_col){
++c;
++acc;
}
else
{
counting = 0;
curr_col = x;
acc = 1;
}
}
else
{
if(x == curr_col){
++acc;
}
else
{
if(c == acc){
curr_col = x;
acc = 1;
}
else
{
fail = 1;
break;
}
}
}
}
}
if(acc != c){
fail = 1;
}
if(fail){
printf("NO\n");
}
else
{
printf("YES\n");
}
// free(p);
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | a3fe2ac014f1d7b4e7986bc9a44fcdf9 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int t;
int arr[100000];
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d", &arr[i]);
}
int bil = 0;
int blak = 0;
int tmp = 1;
if (arr[0] == 1)
{
int i = 0;
while (i < t && arr[i] == 1)
{
blak++;
i++;
}
while (i < t && arr[i] == 0)
{
bil++;
i++;
}
if (blak != bil && blak != 0 && bil != 0)
{
printf("NO");
return 0;
}
for (int i = 1; i < t; i++)
{
if (arr[i - 1] == arr[i])
{
tmp++;
}
else
{
if (arr[i - 1] == 0)
{
if (bil != tmp)
{
printf("NO");
return 0;
}
}
else
{
if (blak != tmp)
{
printf("NO");
return 0;
}
}
tmp = 1;
}
}
}
if (arr[0] == 0)
{
int i = 0;
while (i < t && arr[i] == 0)
{
bil++;
i++;
}
while (i < t && arr[i] == 1)
{
blak++;
i++;
}
if (blak != bil && blak != 0 && bil != 0)
{
printf("NO");
return 0;
}
for (int i = 1; i < t; i++)
{
if (arr[i - 1] == arr[i])
{
tmp++;
}
else
{
if (arr[i - 1] == 0)
{
if (bil != tmp)
{
printf("NO");
return 0;
}
}
else
{
if (blak != tmp)
{
printf("NO");
return 0;
}
}
tmp = 1;
}
}
}
if (arr[t - 1] == 0)
{
if (bil != tmp)
{
printf("NO");
return 0;
}
}
else
{
if (blak != tmp)
{
printf("NO");
return 0;
}
}
printf("YES");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | bb931fa7303bca244d5eff42063d0cdd | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int main() {
// your code goes here
long int n;
scanf("%ld",&n);
int num;
int last=-1,lwidth=-1,cwidth=0;
int pos=1;
for(long int i=0;i<n;i++){
scanf("%d",&num);
if(pos==0)
continue;
if(last==-1 || last==num)
cwidth++;
else{
if(lwidth==-1){
lwidth=cwidth;
cwidth=1;
}
else{
if(lwidth==cwidth)
cwidth=1;
else
pos=0;
}
}
last=num;
}
if(cwidth!=0 && lwidth!=-1 && cwidth!=lwidth)
pos=0;
if(pos==1)
printf("YES");
else
printf("NO");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 64d518245f320030540e69f615954b87 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] |
#include <stdio.h>
#define FOR(i, s, f) for (int (i) = (s); (i) < (f); ++(i))
#define forn(i, f) FOR((i), 0, (f))
#define sci(a) scanf("%d", &(a))
#define scid(a) int (a); sci(a)
#define scvin(a, n) forn(IT_FOR_SCANNING, (n)) sci((a)[IT_FOR_SCANNING])
int a[300000];
int main()
{
scid(n);
scvin(a, n);
int cnt = 1;
for (int i = 1; i < n && a[i] == a[i - 1]; ++i, ++cnt) {}
if (n % cnt) {
puts("NO");
return 0;
}
int prev = a[0] ^ 1;
for (int i = 0; i < n; i += cnt) {
if (a[i] == prev) {
puts("NO");
return 0;
}
for (int j = i + 1; j < i + cnt; ++j) {
if (a[j] != a[j - 1]) {
puts("NO");
return 0;
}
}
prev = a[i];
}
puts("YES");
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 7781e47f8c6e2ae0cc9bc2ec1cb0f19a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int main()
{
int n;
int a[100007];
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int cur = a[0];
int p1 = 0;
int i = 0;
int fl = 1;
int len = -1;
while (i < n)
{
cur = a[i];
while (i < n && a[i] == cur)
i++;
if (len == -1)
len = i - p1;
else
{
if (i - p1 != len)
{
fl = 0;
break;
}
}
p1 = i;
}
if (fl)
printf("YES");
else printf("NO");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 211f1ecf44527c9e7a5664ef4b417c3f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int a[100009];
int main()
{
int n;
scanf("%d", &n);
int cnt = 1, pr, tcnt = 0, f = 0, ans = 1;
scanf("%d", &pr);
for (int i = 1; i < n; ++i) {
int x;
scanf("%d", &x);
if (x == pr) {
if (!f) ++cnt;
else ++tcnt;
}
else {
if (!f) f = 1;
else if (tcnt != cnt) {
ans = 0;
}
tcnt = 1;
pr = x;
}
}
if (tcnt != cnt && f) ans = 0;
if (ans) printf("YES\n");
else printf("NO\n");
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 175bb5ffd7a8ad11a56a19d37efd29e0 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#define ACCEPTED return 0;
int A[100001];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
int color = A[0];
int len = 0, cur = 1;
for (int i = 1; i < n; i++)
if (A[i] == color) cur++;
else {
if (len == 0) len = cur;
else if (len != cur) {
printf("NO");
ACCEPTED
}
cur = 1;
color = A[i];
}
if (len == 0) len = cur;
else if (len != cur) {
printf("NO");
ACCEPTED
}
printf("YES");
ACCEPTED
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 377ad361ac474e937014f35a9d995ab3 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int main()
{
int n, a[100010], pref[100010];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i == 0)
pref[i] = a[i];
else
pref[i] = pref[i - 1] + a[i];
}
for (int len = 1; len <= n; len++)
if (n % len == 0) {
int can = pref[len - 1] == 0 || pref[len - 1] == len;
if (can == 1) {
int last;
if (pref[len - 1] == 0)
last = 0;
else
last = 1;
for (int i = 2 * len - 1; i < n; i += len) {
int cur;
if (pref[i] - pref[i - len] == len)
cur = 1;
else if (pref[i] - pref[i - len] == 0)
cur = 0;
else
can = 0;
can &= cur != last;
last = cur;
}
}
if (can) {
puts("YES");
return 0;
}
}
puts("NO");
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 848d33dd24c7a2e358d218959a0750fb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; ++i)
{
scanf("%d", &a[i]);
}
int i = 1;
while (i < n && a[i] == a[i - 1])
{
++i;
}
if (i == n)
{
printf("YES");
return 0;
}
int best = i;
while (i < n)
{
int count = 1;
++i;
while (i < n && a[i] == a[i - 1])
{
++i;
++count;
}
if (count != best)
{
printf("NO");
return 0;
}
}
printf("YES");
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 1bc18b76fbf675895fe7c404b40a65c9 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] |
#include <stdio.h>
//#include <algorithm>
//#include <math.h>
//#define ll long long
// #define ld long double
int main()
{
int n,m,k,l,p=-1,a[100005]={};
scanf("%d",&n);
for (int i=1; i<=n; i++)
scanf("%d",&a[i]);
a[0]=a[1];
a[n+1]=a[n]+1;
for (int i=1; i<=n+1; i++)
{
if (a[i]!=a[i-1])
if (p==-1)
{
p=i;
m=i-1;
} else
{
if (i-p!=m) {
printf("NO");
return 0;
}
p=i;
}
}
printf("YES");
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 044e8e233c6692f44e88dd4b895815f0 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | int main()
{
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i<n; i++) scanf("%d", &a[i]);
int temp = 0;
int idx = 0;
int kek = 1;
while ((idx<n-1)&&(a[idx]==a[idx+1]))
{
idx++;
temp++;
}
idx++;
while (idx<n)
{
int temp1 = 0;
while ((idx<n-1)&&(a[idx]==a[idx+1]))
{
idx++;
temp1++;
}
idx++;
if (temp1!=temp) kek = 0;
}
if (kek==1) printf("YES");
else printf("NO");
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 1f1dfa538340f2c4a2c2c54dfd7a2325 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
int main(void) {
int size, min = -1, max = -1, count = 0;
scanf("%d", &size);
for (int i = 0, loc, st = -1; i < size; i++) {
scanf("%d", &loc);
if (st == -1)
st = loc;
if (loc != st) {
if (min == -1 || count < min)
min = count;
if (max == -1 || count > max)
max = count;
count = 0;
st = loc;
}
count++;
}
if (min == -1 || count < min)
min = count;
if (max == -1 || count > max)
max = count;
if (min == max)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 7afe691d8e3c66aad7ec02a488f0700a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int result = 1;
int currentColor = 0;
int requiredLength = 0;
int currentLength = 0;
int i = 0;
for ( ; i < n; ++i )
{
int cur;
scanf("%d", &cur);
if ( cur == currentColor )
{
++currentLength;
}
else
{
if ( requiredLength == 0 )
{
requiredLength = currentLength;
}
else if ( currentLength != requiredLength )
{
result = 0;
break;
}
currentColor = cur;
currentLength = 1;
}
}
if ( requiredLength && currentLength != requiredLength )
{
result = 0;
}
printf(( result ? "YES\n" : "NO\n" ));
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | c3ece7e15a9db69380e99226df78c684 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | //#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int n, k, a[100100], b[100100], frr;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &k);
a[i] = k;
}
int q = 0, l = 0;
for (int i = 0; i < n; ++i) {
if (q == 0)
if (a[i] == 1) {
l = 1;
q = 1;
}
else {
l = 1;
q = -1;
}
else if (q == 1) {
if (a[i] != 1) {
b[frr] = l;
frr += 1;
q = -1;
l = 1;
}
else {
l += 1;
}
}
else {
if (a[i] != 0) {
b[frr] = l;
frr += 1;
q = 1;
l = 1;
}
else {
l += 1;
}
}
}
b[frr] = l;
int i = 1;
while (b[i] != 0) {
if (b[i] != b[i - 1]) {
printf("NO");
return 0;
}
i += 1;
}
printf("YES");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 05537b6b30ae0271ae62967706837f2d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; ++i)
{
scanf("%d", &a[i]);
}
int have=-1, cnt=1;
for (int i = 1; i < n; ++i)
{
if(a[i]==a[i-1])
{
cnt++;
}
else
{
if(have==-1)
have=cnt;
else if(have!=cnt)
{
printf("No\n");
return 0;
}
cnt=1;
}
}
if(have==-1)
have=cnt;
else if(have!=cnt)
{
printf("No\n");
return 0;
}
printf("Yes\n");
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | b12d61e8e512548dcb5a395455f599be | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include <memory.h>
#include <math.h>
#include <stdlib.h>
#define int64_t long long
int64_t nxt() {
int64_t x;
scanf("%I64d", &x);
return x;
}
// please, accepted!
int main()
{
int64_t n = nxt();
int64_t mas[n];
for(int i = 0; i < n; i++) {
mas[i] = nxt();
}
int i = 0;
int64_t tp = -1;
int f = 1;
while(i < n) {
int64_t t = mas[i];
int64_t fix = 0;
while(mas[i] == t && i < n) {
i++;
fix++;
}
if(tp == -1) {
tp = fix;
}
else {
if(tp != fix)
f = 0;
}
}
if(f == 1) {
printf("YES");
}
else printf("NO");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 18e18d67133a38b76fcd5f111fb1203a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include<stdio.h>
int main() {
int t=1;
//cin>>t;
while(t--){
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int len=1;len<=n;len++){
if(n%len!=0)
continue;
int i=0,j=0;
int turn=a[0];
while(i<n){
if(a[j]!=turn)
break;
j++;
if(j-i==len){
turn=1-turn;
i=j;
}
}
if(i==n){
printf("YES");
return 0;
}
}
printf("NO");
}
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 474f095476fce4cf51f2459078ae1f82 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int n, a[100002], nr, ans[100002], db;
int main()
{
scanf("%d",&n);//cin >> n;
for(int i = 1; i <= n; i++) scanf("%d",&a[i]);//cin >> a[i];
a[0] = -1; a[n + 1] = -1;
nr = -1; db = 0;
for(int i = 1; i <= n + 1; i++){
if(a[i] != a[i - 1]){
nr = nr + 1; ans[nr] = db;
db = 1;
}
else db = db + 1;
}
int ok = 1;
for(int i = 1; i < nr; i++)
if(ans[i] != ans[i + 1]) ok = 0;
if(ok) printf("YES");
else printf("NO");
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 7f6c0c91c5d82e0a2d393c14f7268888 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int a[100005];
int main(){
int i;
int n;
scanf("%d", &n);
for (i=0;i<n;i++)
scanf("%d", &a[i]);
int c[100005][2], mxi=0;
int cur=1;
for (i=1;i<n;i++){
if (a[i]==a[i-1]) cur++;
else{
c[mxi][0]=cur;
c[mxi][1]=a[i-1];
mxi++;
cur=1;
}
}
c[mxi][0]=cur;
c[mxi][1]=a[i-1];
mxi++;
for (i=0;i<mxi;i++){
if (c[i][0]!=c[0][0]){
printf("NO");
return 0;
}
}
printf("YES");
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 7bf91b565ef7a0cf03918d9b018df7ee | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdlib.h>
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[n];
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
int cur = a[0], counter = 0;
for(int i = 0; i < n; i++)
if(a[i] != cur)
break;
else
counter++;
if(n % counter != 0)
{
printf("NO");
return 0;
}
cur = a[0] ^ 1;
for(int i = 0; i < n; i += counter)
{
cur ^= 1;
for(int j = i; j < i + counter; j++)
if(a[j] != cur)
{
printf("NO");
return 0;
}
}
printf("YES");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | e523caba684e9b5999e0e157d403c34c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int main()
{
int all[100001];
int n;
scanf("%d", &n);
for (int i=0; i<n; i++){
scanf("%d", &all[i]);
}
int first = 1;
int z = 1;
int line;
int count = 0;
for (int i=0; i<n-1; i++){
if ((all[i] != all[i+1])){
if (first == 1){
first = 0;
line = count;
} else if(count != line){
z = 0;
break;
}
count = 0;
} else{
count++;
}
}
if(((count != line)&&(first == 0))||((n != 1)&&(line != 0)&&(all[n-1]!=all[n-2]))){
z = 0;
}
if(z == 1){
printf("YES");
} else{
printf("NO");
}
return 0;
}
| |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | c1e97054fbe6ccc0d212913107f00251 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int digits;
scanf("%d\n", &digits);
int length = digits*2;
char* str;
str = calloc(sizeof(char), length);
fgets(str, digits*2, stdin);
int comboFound = 0;
int currCombo = 1;
int targetCombo = 1;
char lastChar;
lastChar = str[0];
for (int i = 2; i < length; i += 2) {
if (str[i] == lastChar) currCombo++;
else {
if (comboFound == 0) {
targetCombo = currCombo;
comboFound = 1;
} else {
if (targetCombo != currCombo) {
printf("NO");
free(str);
return 0;
}
}
lastChar = str[i];
currCombo = 1;
}
}
if (currCombo == targetCombo || comboFound == 0)
printf("YES");
else
printf("NO");
free(str);
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | c48091d3ef88adaa07bc3e7eaaa2ef6c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include <stdio.h>
int a[100001], used[100001];
int main ()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
int first = a[1], j = 1;
for(int i = 1; i <= n; i++)
{
if(a[i] == first) used[j]++;
else first = a[i], j++, used[j]++;
}
for(int k = 1; k <= j - 1; k++)
{
if(used[k] != used[k + 1] && used[k + 1] != 0)
{
printf("NO"); return 0;
}
}
printf("YES");
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 0a20afdd0eaa5dccaf4ca085298c5bab | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] | #include<stdio.h>
int main(){
int n,cnt,i,num,prev,max=0;
cnt=1;
scanf("%d %d",&n,&prev);
n--;
while(n--){
scanf("%d",&num);
if(prev==num){
cnt++;
}
else{
if(max==0){
max=cnt;
cnt=1;
prev=num;
}
else{
if(cnt!=max){
printf("NO");
return 0;
}
prev = num;
cnt=1;
}
}
}
if(max==0 || cnt==max) printf("YES");
else printf("NO");
return 0;
} | |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,β0,β0,β1,β1,β1,β0,β0,β0] can be a photo of zebra, while the photo [0,β0,β0,β1,β1,β1,β1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? | If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). | C | 75a00d8a614fd0bcb8504b0268a121e0 | 2244513ddc9f6525b042a391b64df40a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [] | 1521300900 | ["9\n0 0 0 1 1 1 0 0 0", "7\n0 0 0 1 1 1 1", "5\n1 1 1 1 1", "8\n1 1 1 0 0 0 1 1", "9\n1 1 0 1 1 0 1 1 0"] | NoteThe first two examples are described in the statements.In the third example all pixels are white, so the photo can be a photo of zebra.In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra. | PASSED | 1,700 | standard input | 1 second | The first line contains a single integer n (1ββ€βnββ€β100β000) β the width of the photo. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β1) β the description of the photo. If ai is zero, the i-th column is all black. If ai is one, then the i-th column is all white. | ["YES", "NO", "YES", "NO", "NO"] |
#include <stdio.h>
#include <stddef.h>
#include <locale.h>
#define MAXN 100010
int main()
{
int n, i, j, k;
scanf("%d", &n);
int a[MAXN];
for (i = 0; i < n; i++) scanf("%d", &a[i]);
int solved = 0;
for (i = 1; i <= n; i++) {
if (n % i != 0) continue;
int valid = 1;
if (a[0] == 0) {
for (j = 0; j < n; j++) {
if (a[j] != (j / i) % 2) {
valid = 0;
break;
}
}
}
else {
for (j = 0; j < n; j++) {
if (a[j] == (j / i) % 2) {
valid = 0;
break;
}
}
}
if (valid) {
solved = 1;
break;
}
}
if (solved) printf("YES\n");
else printf("NO\n");
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 3346566721736a09fa95e6bd2464513b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include "stdio.h"
#include "stdlib.h"
int t, n, start_dist, end_dist;
char s[101];
int main() {
scanf("%d", &t);
// printf("t = %d\n", t);
for (int i = 0; i < t; i++) {
scanf("%d", &n);
// printf("n = %d\n", n);
scanf("%s", s);
// printf("s = %s\n", s);
start_dist = 0;
end_dist = 0;
for (int j = 0; j < n; j++) {
if (s[j] != '>') start_dist++;
else break;
}
for (int j = n - 1; j >= 0; j--) {
if (s[j] != '<') end_dist++;
else break;
}
printf("%d\n", (start_dist < end_dist) ? start_dist : end_dist);
}
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 1086f3504f410f1c0f0d7abee61960fb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
char s[n+1];
scanf(" %[^\n]",s);
int len=(int)strlen(s),flag=0,flag_prim=0;
if(s[0]=='>' || s[len-1]=='<')
{
flag=0;
}
else
{
for(int i=0;i<len && s[i]!='>';i++,flag++);
for(int i=len-1;i>=0 && s[i]!='<';i--,flag_prim++);
if(flag>flag_prim)
flag=flag_prim;
}
printf("%d\n",flag); }
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 127ef08b2f96e425ac54c84fb6eb54a9 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include <stdio.h>
int main(int argc, char const *argv[]) {
int t;
scanf("%d", &t);
while (t--) {
int n, ans;
scanf("%d", &n);
char str[n + 1];
scanf(" %s", str);
for (int i = 0; i <= n / 2; i++)
if (str[i] == '>' || str[n - i - 1] == '<') {
ans = i;
break;
}
printf("%d\n", ans);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 937996f1c3844c8de9cf731c50caaf07 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
int t, n, ss,ee;
char s[101];
int main()
{
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
scanf("%s", s);
ss=ee=0;
for (int i = 0; i < n; i++) {
if (s[i] == '>') {
ss = i; break;
}
}
for (int i = n-1; i >=0; i--) {
if (s[i] == '<') {
ee = i; break;
}
}
if (!ss || ee == n - 1) {
printf("0\n");
continue;
}
printf("%d\n", (ss > n - 1 - ee ? n - 1 - ee : ss));
}
return 0;
} | |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | a3c63dce625af39a629e0814dfda8f88 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
for(int i=0; i<t; i++)
{
int n=0, j, k;
scanf("%d", &n);
char s[n+1];
scanf("%s", s);
if((s[0] == '<') && (s[n-1] == '>'))
{
for(j=0; j<n; j++)
{
if(s[j]=='<') continue;
else break;
}
for(k=0; k<n; k++)
{
if(s[n-1-k]=='>') continue;
else break;
}
if(j<=k) printf("%d\n", j);
else printf("%d\n", k);
}
else printf("0\n");
}
return 0;
} | |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 1d71c25672f90e2c4a939edf30cc5048 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char str[1000000];
int main(){
int i,j,k,l,t,n,x,y,count,a,b;
char c;
scanf("%d",&t);
while(t--){
a=0;b=0;
scanf("%d",&n);
scanf("%s",str);
for(i=0;i<n;i++){
if(str[i]=='>')
break;
else
a++;
}
for(i=n-1;i>=0;i--){
if(str[i]=='<')
break;
else
b++;
}
if(a<b) count = a;
else count = b;
printf("%d\n",count);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 2cfd08e0798148446800f199f74a3b56 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
int main()
{
int t, n;
char s[100];
scanf("%d",&t);
while(t--)
{
scanf("%d %s",&n,s);
int res = n - 1;
for(int i = 0; i < n; i++)
if(s[i] == '>' || s[n - 1 - i] == '<')
res = MIN(res, i);
printf("%d\n",res);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 1a0a8451662addf906adb7f662cdd14a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#define MIN(X, Y) ((X < Y) ? X : Y)
int main()
{
int t, n;
char s[100];
scanf("%d",&t);
while(t--)
{
scanf("%d %s",&n,s); /* n -> length of string s
s -> string with characters "<" or ">" */
int min_char_deleted = n - 1; // let min_char_deleted -> assingned with n - 1
for(int i=0;i<n;i++)
if(s[i]=='>'||s[n-1-i]=='<')
min_char_deleted=MIN(min_char_deleted, i);// the min_char_deleted is compared with the index of the strings
printf("%d\n",min_char_deleted);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 43326b57985068d01d4c1b089a8b8463 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
int main()
{
int t, n;
char s[100];
scanf("%d",&t);
while(t--)
{
scanf("%d %s",&n,s);
int res = n - 1;
for(int i = 0; i < n; i++)
if(s[i] == '>' || s[n - 1 - i] == '<')
res = MIN(res, i);
printf("%d\n",res);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | b706b31f6d16cc6e121e56d049edc681 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#define MIN(X, Y) ((X < Y) ? X : Y)
int main()
{
int t, n;//the test case and the length of the string s (t=1,n=2)
char s[100];// we declare the string s;(s="<>")
scanf("%d",&t);// we input the number of test cases
while(t--)
{
scanf("%d %s",&n,s); /* n -> length of string s
s -> string with characters "<" or ">" */
int x = n - 1; // let x -> assingned with n - 1 (x= length of the sting - 1)
for(int i=0;i<n;i++)/*i=0,1 n=2*/
if(s[i]=='>'||s[n-1-i]=='<')//><
x=MIN(x, i);// the x is compared with the index of the strings
printf("%d\n",x);//output is 1
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 53adf2cc1e263068fb31dde7e69d6b36 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int m;
scanf("%d",&m);
getchar();
char a[1000]={'\0'};
for(int i=0;i<m;i++)
{
scanf("%c",&a[i]);
}
int flag1=0;
for(int i=0;i<m;i++)
{
if(a[i]=='>')
{
flag1=i;
break;
}
}
int flag2=0;
for(int i=m-1;i>=0;i--)
{
if(a[i]=='<')
{
flag2=i;
break;
}
}
printf("%d\n",min(flag1,m-1-flag2));
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 679e26747c6695f6b3de10184e51c857 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
int main()
{
int t,n,k,l,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
char s[n];
k=100;
l=100;
scanf("%s",&s);
for(i=0;i<n;i++)
{
if(s[i]=='>')
{
k=i;
break;
}
}
for(i=n-1;i>=0;i--)
{
if(s[i]=='<')
{
l=i;
break;
}
}
if(l!=100)
l=n-l-1;
k=k<l?k:l;
printf("%d\n",k);
}
return 0;
} | |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 0c2b8afcef40dbcd81c669a634698437 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
int t, n, i, l, r;
char a[105];
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
scanf("%s", a);
l = 0;
r = n - 1;
while(a[l] != '>' && l < n)
{
l++;
}
while(a[r] != '<' && r >= 0)
{
r--;
}
r = n - r - 1;
if(l < r)
printf("%d\n", l);
else
printf("%d\n", r);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | b696adddb514f71a9c628c156062631e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#include<string.h>
enum { maxn = 105 };
char s[maxn];
int main() {
int kase; scanf("%d", &kase);
while(kase--) {
int len; scanf("%d", &len);
memset(s, 0, sizeof(s));
fgets(s, maxn, stdin); // purge '\n'
fgets(s, maxn, stdin);
if (s[0] == s[len-1] ||
(s[0] == '>' && s[len-1] == '<')) printf("0\n");
else {
int cnt1 = 0, cnt2 = 0;
while(s[cnt1++] == '<');
while(s[len-1-cnt2++] == '>');
printf("%d\n", cnt1 > cnt2 ? cnt2-1 : cnt1-1);
}
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | ea92369266e776f7e97692f9b700701d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include <stdio.h>
char s[101];
int main() {
int t;
scanf("%d", &t);
while(t-->0) {
int n;
scanf("%d", &n);
scanf("%s", s);
int k1=0, k2=0;
for(k1=0; k1<n && s[k1] == '<'; ++k1);
for(k2=0; k2<n && s[n-1-k2] == '>'; ++k2);
printf("%d\n", (k1 < k2 ? k1 : k2));
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 35df997394e39314ed3b89fee4598b08 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
int main()
{
int i,j,count=0,k,count1=0;
scanf("%d",&j);
for(i=1;i<=j;i++)
{
int a;
scanf("%d ",&a);
char b[a];
gets(b);
b[a]='\0';
for(k=0;k<a;k++)
{
if(b[k]=='>')
{
break;
}
else
{
count++;
}
}
for(k=a-1;k>=0;k--)
{
if(b[k]=='<')
{
break;
}
else
{
count1++;
}
}
if(count1<count)
{
count=count1;
}
printf("%d\n",count);
count=0;
count1=0;
}
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 675dff88e81028bb9b7279e6cb6e6654 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#define min(a,b) (a>b ? b:a)
int main()
{
int first_right,last_left;
int t,i;
char line[1000];
int count;
scanf("%d",&t);
while(t--)
{
scanf("%d",&count);
first_right=count-1;
last_left=0;
scanf("%s",line);
//printf("the line is %s\n",line);
for(i=0;i<count;i++)
{
if(line[i]=='>')
{
first_right=i;
break;
}
}
for(i=count-1;i>=0;i--)
{
if(line[i]=='<')
{
last_left=i;
break;
}
}
printf("%d\n",min(first_right,count-last_left-1));
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | 6fd7a6cd6039343eba8883efb2b29356 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
int t, n, i, num, left, right;
char s[105];
scanf ( "%d", &t );
for ( i = 0; i < t; i++ )
{
left = right = num = 0;
scanf ( "%d %s", &n, s );
if ( s[0] != '<' && s[n-1] != '>' )
;
else
{
left = right = 0;
while ( s[left] == '<' )
left++;
while ( s[n-1-right] == '>' )
right++;
if ( left <= right )
num = left;
else
num = right;
}
printf ( "%d\n", num );
}
return 0;
} | |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | cbb91e1c0784260dee0fe6c09dbcb0c8 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
#include<string.h>
int main()
{
int test;
scanf("%d",&test);
int num;
char s[10000]={};
for(int i=0;i<test;i++)
{
scanf("%d",&num);
scanf(" %s",s);
int a=0,b=num-1;
int found1=0,found2=0;
for(int i=0,j=num-1;i<num;i++,j--)
{
if(s[j]=='>')
{
found1=1;
b=j;
}
if(s[i]=='<')
{
found2=1;
a=i;
}
}
if(found1==0||found2==0)
{
printf("0\n");
}
else
{
b<num-1-a?printf("%d\n",b):printf("%d\n",num-1-a);
}
}
return 0;
} | |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | e9cb6c051cf27655e4c22a18e8fd80bc | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
char ch[105];
int a[105];
int ans=0;
int main()
{
int n,i,j,p,q;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
getchar();
for(j=0,p=0,q=0;j<a[i];j++)
{
scanf("%c",&ch[j]);
}
j--;
while(ch[j]=='>'){
p++;
j--;
}
j=0;
while(ch[j]=='<'){
q++;
j++;
}
ans=p;
if(q<p) ans=q;
printf("%d\n",ans);
}
return 0;
}
| |
You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good. | C | 0ba97bcfb5f539c848f2cd097b34ff33 | fda9f84150d06637d04fb0061a72dd45 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1553267100 | ["3\n2\n<>\n3\n><<\n1\n>"] | NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) β the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) β the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <. | ["1\n0\n0"] | #include<stdio.h>
int a[200];
int main(){
int t,n,i=0,x,y;
char s[200];
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d",&n);
scanf("%s",s);
x=y=0;
if(s[0]=='<'&&s[n-1]=='>'){
while(s[x]=='<') x++;
while(s[n-1-y]=='>') y++;
a[i]=(x>y)? y:x;
}
}
for(i=0;i<t;i++){
printf("%d\n",a[i]);
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.