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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 0301a5005548ac3b6a1296d3bb23c559 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | // http://codeforces.com/problemset/problem/426/B
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
short n, m; // n -> rows & m -> columns
short minRows;
void cheak( unsigned long long arr[n][2] )
{
short i;
bool flag;
if( minRows % 2 == 1 )
{
return;
}
flag = 1;
for( i = 0; i < minRows / 2; i++ )
{
if( arr[i][0] != arr[ minRows - i - 1 ][0] ||
arr[i][1] != arr[ minRows - i - 1 ][1] )
{
flag = 0;
break;
}
}
if( flag == 1 )
{
minRows /= 2;
cheak( arr );
}
return;
}
int main( void )
{
short i, j;
short first, second;
short temp;
scanf( "%hi %hi", &n, &m );
unsigned long long arr[n][2];
if( m <= 64 )
{
first = m;
}
else
{
first = 64;
}
second = m - 64;
for( i = 0; i < n; i++ )
{
arr[i][0] = 0;
for( j = 0; j < first; j++ )
{
scanf( "%hi", &temp );
if( temp == 1 )
{
arr[i][0] |= ( 1 << j );
}
}
arr[i][1] = 0;
for( j = 0; j < second; j++ )
{
scanf( "%hi", &temp );
if( temp == 1 )
{
arr[i][1] |= ( 1 << j );
}
}
}
/*for( i = 0; i < n; i++ )
{
printf( "%I64 %I64\n", arr[i][0], arr[i][1] );
}*/
minRows = n;
cheak( arr );
printf( "%hi\n", minRows );
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | cb2f89a3992248c531c05e4d69b76144 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
#include<stdlib.h>
//int m;
int flag=0;
int main(){
int i,j,n,m;
scanf("%d %d",&n,&m);
int a[n][m];
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",&a[i][j]);
}}
while(1){
if(n%2==1){
printf("%d\n",n);
return 0;
}
else{
for(i=0;i<n/2;i++){
for(j=0;j<m;j++){
if(a[i][j]!=a[n-i-1][j]){
flag=1;
break;
}}}
if(flag==0){
n=n/2;
}
else{
printf("%d\n",n);
return 0;
}}}}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 092a1b3dc5b650d1c959ce09046f22ce | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.c
* Author: alulab14
*
* Created on 13 de mayo de 2017, 12:34 PM
*/
#include <stdio.h>
#include <stdlib.h>
#define N 100
/*
*
*/
int es_mirror(int M[N][N], int x, int y){
int med= x/2;
int i,j;
for(i=0; i<med; i++)
{
for(j=0; j<y; j++)
{
if(M[i][j] != M[x-1-i][j])
return 0;
}
}
return 1;
}
int solucion(int M[N][N], int x, int y){
if(x%2==0)
{
if(es_mirror(M, x, y))
return solucion(M, x/2, y);
else
return x;
}
return x;
}
int main(int argc, char** argv) {
int x, y;
scanf("%d %d", &x, &y);
int M[N][N];
int i,j;
for(i=0; i<x; i++)
for(j=0; j<y; j++)
scanf("%d", &M[i][j]);
int sol = solucion(M, x, y);
printf("%d\n", sol);
return (EXIT_SUCCESS);
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 3b23d72a249c8820a002faafd6d4a0bc | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.c
* Author: alulab14
*
* Created on 13 de mayo de 2017, 12:34 PM
*/
#include <stdio.h>
#include <stdlib.h>
#define N 100
/*
*
*/
int es_mirror(int M[N][N], int x, int y){
int med= x/2;
int i,j;
for(i=0; i<med; i++)
{
for(j=0; j<y; j++)
{
if(M[i][j] != M[x-1-i][j])
return 0;
}
}
return 1;
}
int solucion(int M[N][N], int x, int y){
if(x%2==0)
{
if(es_mirror(M, x, y))
return solucion(M, x/2, y);
else
return x;
}
return x;
}
int main(int argc, char** argv) {
int x, y;
scanf("%d %d", &x, &y);
int M[N][N];
int i,j;
for(i=0; i<x; i++)
for(j=0; j<y; j++)
scanf("%d", &M[i][j]);
int sol = solucion(M, x, y);
printf("%d\n", sol);
return (EXIT_SUCCESS);
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 9587923349ef406b30bff8baac8c417c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int Mat[100][100];
int M;
int Judge(int N)
{
int i, j, k;
for(i=0, j=N-1; i<(N>>1); ++i, --j)
{
for(k=0; k<M; ++k)
{
if(Mat[i][k] != Mat[j][k])
{
return 0;
}
}
}
return 1;
}
int main()
{
int N, i, j;
scanf("%d %d", &N, &M);
for(i=0; i<N; ++i)
{
for(j=0; j<M; ++j)
{
scanf("%d", &Mat[i][j]);
}
}
while(1)
{
if(N & 1)
{
printf("%d\n", N);
return 0;
}
if(Judge(N))
{
N >>= 1;
}
else
{
printf("%d\n", N);
return 0;
}
}
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 24373a18408e4a532ffe29a751805925 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int n,m;
int main()
{
int i,j,a;
int jz[100][100];
int judege(int [][100]);
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%d",&jz[i][j]);
}
for(;;)
{
a = judege(jz);
if(a==0)
break;
}
printf("%d",n);
return 0;
}
int judege(int sz[][100])
{
int k,v;
if(n%2==1)
return 0;
else
{
n = n/2;
for(v=0;v<n;v++){
for(k=0;k<m;k++)
{
if(sz[n-1-v][k]!=sz[n+v][k])
{n = n * 2;return 0;}
}}
return 1;
}
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 592310728d9538655d1cb0c03b77f2ff | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int main()
{
int m,n,i,a[1000],t,j;
while(scanf("%d%d",&n,&m)!=EOF){
memset(a,0,sizeof(a));
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",&t);
if(t==0)
a[i]=a[i]<<1;
else
a[i]=(a[i]<<1)+1;
}
}
int l=0,r=n-1;
while(l<=r){
int mid=(l+r)>>1;int flag=(r+1)%2;
// printf("%d %d %d %d",l,mid,r,flag);system("pause");
if(flag){
printf("%d\n",r+1);break;
}
int ans=1;
for(i=0;i<=mid;i++){
if(a[i]!=a[r-i]){
// printf("%d %d %d %d",i,a[i],i+mid+1,a[i+mid+1]);system("pause");
printf("%d\n",r+1);ans=0;break;
}
}
if(!ans)break;
r=mid;
}
}
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 49e1b48c724524e5c9e34fd9574fcc0e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int check(char **a,int n)
{
if(n%2==1)
{
// printf("one\n");
return n;
}
else
{
int i=0,j=n-1;
while(i<j)
{
if(strcmp(&a[i][0],&a[j][0])!=0)
{
//printf("two");
return n;}
i++;
j--;
}
return check(a,n/2);
}
}
int main()
{
int n,m,i,j;
scanf("%d %d",&n,&m);
getchar();
char **a,c;
a=(char **)malloc(sizeof(char *)*n);
for(i=0;i<n;i++)
{
a[i]=(char *)malloc(sizeof(char)*m);
c=getchar();
j=0;
while(c!='\n')
{
if(c!=' ')
{ a[i][j]=c;
j++;
}
c=getchar();
}
a[i][j]='\0';
}
printf("%d\n",check(a,n));
//for(i=0;i<n;i++)
// {
// printf("%s\n",a[i]);
// }
free(a);
return 0;
} | |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | fc5af2e4a9a6540cd78b88a890726fab | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int main()
{
int a,b,c,i,j,k,f=0;
int s[110][110];
scanf("%d %d",&a,&b);
for(i=1;i<=a;i++){
for(j=1;j<=b;j++){
scanf("%d",&s[i][j]);
}
}
if(a%2!=0) printf("%d",a);
else {
while(a){
c=a;
a=a/2;
for(i=a,j=a+1;i>=1&&j<=a*2;i--,j++){
for(k=1;k<=b;k++){
if(s[i][k]!=s[j][k]) {f=1;break;}
}
if(f==1) break;
}
if(f==1) break;
if(a%2!=0) break;
}
if(f==0) printf("%d",a);
else printf("%d",c);
}
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 4140b376238a8ceda5ccfa6d522a9148 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int a[100][100];
int s(int * n,int m){
if(*n%2)return 0;
int l=0,g=*n-1,x;
while(l<g){
for(x=0;x<m;x++)
if(a[l][x]!=a[g][x])return 0;
l++,g--;
}
*n/=2;
return 1;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
int y,x;
for(y=0;y<n;y++){
for(x=0;x<m;x++)
scanf("%d",&a[y][x]);
}
while(s(&n,m));
printf("%d",n);
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | e420fb39cbcf7b0df1915e2b0a2ad3c1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <string.h>
int main()
{
int n,m,i,j,flag,ans;
int a[105][105];
scanf("%d %d",&n,&m);
memset(a,0,sizeof(a));
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
scanf("%d",&a[i][j]);
ans=n;
do
{
if (ans%2==1) break;
ans=ans/2;
flag=1;
for (i=1;i<=ans;i++)
{
for (j=1;j<=m;j++)
if (a[i][j]!=a[ans*2+1-i][j]) { flag=0;break; }
}
if (flag==0) { ans=ans*2;break; }
}while(1);
printf("%d",ans);
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 47887708bfabcc4444aa9fff53c42d7f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<ctype.h>
#include<string.h>
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int arr[n][m],i,j;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&arr[i][j]);
if(n%2!=0)
printf("%d\n",n);
else{
int rows=n/2,flag=1;
while(1){
for(i=0;i<rows;i++){
for(j=0;j<m;j++){
if(arr[i][j]!=arr[(rows*2)-i-1][j])
flag=0;
}
}
if(flag && rows%2==0)
rows/=2;
else
break;
}
if(rows%2==0)
printf("%d\n",rows*2);
else if(rows%2!=0 && flag)
printf("%d\n",rows);
else if(!flag)
printf("%d\n",rows*2);
}
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | df0133a9845b16cb6c5efe63442e4e3f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int A[101][101];
int main()
{
int n,m,i,j,k,a,p,tem,t;
scanf("%d%d",&n,&m);
for(i=1; i<=n; i++)
for(j=1; j<=m; j++)
scanf("%d",&A[i][j]);
a=n;
if(a==1)
{
printf("%d\n",1);
return 0;
}
for(i=1; i<=n; i++)
{
t=0;
if(a%2!=0)
{
printf("%d\n",a);
break;
}
else
{
t=0;
// printf("sandhya\n");
for(j=a/2,k=a/2+1; j>=1; j--)
{
t=0;
// printf("dog\n");
for(p=1; p<=m; p++)
{
//printf("compare\n");
if(A[j][p]==A[k][p])
tem=1;
else
{
tem=0;
//printf("tem1\n");
// printf("%d\n",tem);
printf("%d\n",a);
break;
}
}
if(tem==0){
//printf("tem2\n");
j=1;}
k++;
}
}
if(tem==0){
//printf("tem3\n");
i=n/2;
//printf("%d\n",tem);
break;}
else{
a=a/2;
//printf("aa\n");
}
//if(t!=1)
// a=a/2;
//else
//break;
}
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | bfaef7110e1c8598b2cb8dfc64eabc9e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int n,m,k,i,t,j,s,arr[1000][1000];
int main(){
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&arr[i][j]);
if(n%2){printf("%d",n); return 0;}
while(1){
t=0;
if(n%2||!n){
printf("%d",n);
return 0;
}
for(i=0;i<n/2;i++)
for(j=0;j<m;j++)
if(arr[i][j]!=arr[n-i-1][j])
t++;
if(!t){n/=2; continue; }
if(n==0){
printf("1");
return 0;
}
if(t){
printf("%d",n);
return 0;
}
if(n%2||!n){
printf("%d",n);
return 0;
}
}
printf("%d",n);
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | fcce41342d627540b24dcf4933f38def | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int ar[102][102];
void call(int n,int m)
{
if(n&1)
{ printf("%d",n);
return;
}
int p=0,i,j;
for(i=0;i<n/2;i++)
{
for(j=0;j<m;j++)
{
if(ar[i][j]!=ar[n-i-1][j])
{
p=-1;
break;
}
}
if(p==-1)
break;
}
if(p==-1)
printf("%d",n);
else
call(n/2,m);
}
int main(void) {
int n,m,i,j;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&ar[i][j]);
call(n,m);
return 0;
}
| |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 2cdc6fb55a8a5aa5dab42c6c8e2b15ca | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int matrix[101][101];
int check(int a[],int b[],int length)
{
int i;
for(i=0;i<length;i++)
{
if(a[i]!=b[i])
return 0;
}
return 1;
}
int fun(int start,int length,int columns)
{
int i;
if(length%2)
return 0;
for(i=0;i<length/2;i++)
{
if(!check(matrix[i],matrix[length-1-i],columns))
return 0;
}
return 1;
}
int main()
{
int n,m,length;
scanf("%d%d",&n,&m);
int i,j;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&matrix[i][j]);
int cur=n,now;
while(cur%2==0)
{
//printf("%d\n",cur );
if(fun(0,cur,m))
cur=cur/2;
else
break;
}
printf("%d\n",cur );
return 0;
} | |
Let's assume that we are given a matrix b of size xβΓβy, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2xβΓβy matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from xβ+β1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and xβ+β1). Sereja has an nβΓβm matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem β the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 92c7dedb7f8cda4ddd226916009b26f1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2βΓβ3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1ββ€βn,βmββ€β100). Each of the next n lines contains m integers β the elements of matrix a. The i-th line contains integers ai1,βai2,β...,βaim (0ββ€βaijββ€β1) β the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
#include<string.h>
int a[110][110];
char c[110][110];
int main()
{
int n,m,i,j,ans,ok;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&a[i][j]);
ok=1;
do
{
if(n%2==1&&n>2) {printf("%d\n",n); return 0;}
ans=n; n/=2;
for(i=1;i<=n;i++){
if(!ok) break;
for(j=1;j<=m;j++)
if(a[i][j]!=a[2*n-i+1][j])
{ ok=0;break;}
}
}while(ok&&ans>1);
printf("%d\n",ans);
return 0;
}
| |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | bca70dfef64b64459ee1c9479054a196 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | #include <stdio.h>
long long int six[14], three[19];
int main(){
int n, j;
long long int num;
six[0] = 1;
int flag = 0;
for(int i = 0; i < 13; i ++)
six[i + 1] = six[i] * 6;
three[0] = 1;
for(int i = 0; i < 18; i ++)
three[i + 1] = three[i] * 3;
scanf("%d", &n);
for(int i = 0; i < n; i ++){
scanf("%lld", &num);
if(num == 1)
printf("0\n");
else if(num == 3)
printf("2\n");
else{
flag = 0;
for(j = 0; j < 14; j ++){
for(int k = 0; k < 19; k ++){
if(six[j] * three[k] == num){
flag = k + 1;
break;
}
else if(six[j] * three[k] > num)
break;
}
if(flag != 0)
break;
}
if(flag == 0)
printf("-1\n");
else
printf("%d\n", j + 2 * (flag - 1));
}
}
return 0;
} | |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | a2c6bc923dd2e2c2aa4a20dabc1657bd | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | main() {
int t, n1, n2, n;
scanf("%d", &t);
while(t--) {
n1 = n2 = 0;
scanf("%d", &n);
if(n == 1) printf("0\n");
else {
while(n % 2 == 0) {
n /= 2;
++n1;
}
while(n % 3 == 0) {
n /= 3;
++n2;
}
if(n != 1) printf("-1\n");
else if(n1 > n2) printf("-1\n");
else printf("%d\n", n1 + 2 * (n2 - n1));
}
}
} | |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | f61f16c685d1e7fc36cec0d4b758d44c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | main() {
int t, n1, n2, n;
scanf("%d", &t);
while(t--) {
n1 = n2 = 0;
scanf("%d", &n);
if(n == 1) printf("0\n");
else {
while(n % 2 == 0) {
n /= 2;
++n1;
}
while(n % 3 == 0) {
n /= 3;
++n2;
}
if(n != 1) printf("-1\n");
else if(n1 > n2) printf("-1\n");
else printf("%d\n", n1 + 2 * (n2 - n1));
}
}
} | |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | 3a2bcc52f0a2c4b3686c0d4372507748 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
for(t=t;t>0;t--)
{
int n,count=0;
scanf("%d",&n);
for(n=n;n>1;)
{
if(n%6==0)
{
n=n/6;
}
else
{
n=n*2;
if(n%6!=0)
{
count=-1;
break;
}
}
count=count+1;
}
printf("%d",count);
printf("\n");
}
return 0;
}
| |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | a989c14fe78dd60516d6d9cc19628cfe | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | #include"stdio.h"
#include"conio.h"
int main()
{
int t,c,n;
scanf("%d",&t);
while(t--)
{
c=0;
scanf("%d",&n);
while(n!=1)
{
if(n%6==0)
{
c+=1;
n=n/6;
}
else
{
if(n%3==0)
{
c+=1;
n=n*2;}
else
{
printf("-1\n");
c=-1;
break;
}
}
}if(c>-1)
printf("%d\n",c);
}
}
| |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | 10ab260613d3ca11ab0135bedffbf007 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | #include<stdio.h>
#include<math.h>
#include<malloc.h>
int main()
{
int rem,cases,k=2,z,count3=0,count2=0,num;
//long double x,n;
int *arr;int i;
scanf("%d",&cases);
arr=(int*)malloc(cases*sizeof(int));
for(i=0;i<cases;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<cases;i++)
{
num=arr[i];count2=0,count3=0;
while(num%3==0)
{
num=num/3;
count3++;
}
while(num%2==0)
{
num=num/2;
count2++;
}
//printf("count2=%ld\t%ld\n",count2,count3);
if(num!=1||count2>count3)
printf("-1\n");
//if(count2>count3)
//printf("-1\n");
else
printf("%d\n",(count3-count2)+count3);
}
return 0;
} | |
You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases. | For each test case, print the answer β the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$. | C | 3ae468c425c7b156983414372fd35ab8 | ffdd66d71d213406a4170dbe01e28949 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1593354900 | ["7\n1\n2\n3\n12\n12345\n15116544\n387420489"] | NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$: Divide by $$$6$$$ and get $$$2519424$$$; divide by $$$6$$$ and get $$$419904$$$; divide by $$$6$$$ and get $$$69984$$$; divide by $$$6$$$ and get $$$11664$$$; multiply by $$$2$$$ and get $$$23328$$$; divide by $$$6$$$ and get $$$3888$$$; divide by $$$6$$$ and get $$$648$$$; divide by $$$6$$$ and get $$$108$$$; multiply by $$$2$$$ and get $$$216$$$; divide by $$$6$$$ and get $$$36$$$; divide by $$$6$$$ and get $$$6$$$; divide by $$$6$$$ and get $$$1$$$. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) β the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$). | ["0\n-1\n2\n-1\n-1\n12\n36"] | #include <stdio.h>
int main(){
int t,n,p,k=0,r=0,c=0;
scanf("%d",&t);
while(t>0)
{
c=0;
r=0;
k=0;
scanf("%d",&n);
if(n==1)
{
printf("%d\n",0);
}
else if (!(n%3==0))
{
printf("%d\n",-1);
}
else{
p=n;
while((p%3==0 || p%2==0) && p!=0)
{
if(p%6==0)
{
p=p/6;
}
else if(p%3==0)
{
p=p/3;
r++;
}
else
{
p=p/2;
k++;
}
}
if(p==1 && r>=k){
while(n!=1)
{
if(n%6==0)
{
n=n/6;
c++;
}
else
{
n=n*2;
c++;
}
}
printf("%d\n",c);
}
else{
printf("%d\n",-1);
}
}
t--;
}
} | |
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. | If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$. | C | d9bd63e03bf51ed87ba73cd15e8ce58d | 44cf4602b648698e32ebcdf9687012a9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"binary search",
"math"
] | 1532617500 | ["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"] | NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth. | PASSED | 1,500 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. | ["10.0000000000", "-1", "85.4800000000"] | #include <stdio.h>
int main ()
{
int n, m, i;
double c = 1.0, x;
scanf ("%d%d", &n, &m);
for (i = 0; i < n * 2; i++)
{
scanf ("%lf", &x);
c *= 1 - 1 / x;
}
printf ("%.10f\n", c > 0 ? m / c - m : -1);
return 0;
}
| |
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. | If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$. | C | d9bd63e03bf51ed87ba73cd15e8ce58d | 25505ad7df84e87b3c917adf8842f031 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"binary search",
"math"
] | 1532617500 | ["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"] | NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth. | PASSED | 1,500 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. | ["10.0000000000", "-1", "85.4800000000"] | #include <stdio.h>
int main(void) {
// your code goes here
long int n,m;
scanf("%ld %ld",&n,&m);
long int a[n];
long int b[n];
for (int i=0;i<n;i++){
scanf("%ld",&a[i]);
if (a[i]==1){
printf("-1");
return 0;
}
}
for (int i=0;i<n;i++){
scanf("%ld",&b[i]);
if (b[i]==1){
printf("-1");
return 0;
}
}
long int an = 0;
long int bn = 1;
long int ab[2*n];
for (int i=0;i<2*n;i++){
if (i%2==0){
ab[i] = a[an++];
}
else{
if (bn==n){
ab[i] = b[0];
}
else{
ab[i] = b[bn++];
}
}
}
double result = (double)m;
for (int i=((2*n)-1);i>=0;i--){
double result1 = (double)result / ((double)ab[i] - 1);
result += result1;
}
result -= (double)m;
printf("%f\n",result);
return 0;
}
| |
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. | If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$. | C | d9bd63e03bf51ed87ba73cd15e8ce58d | 76745621016d898b658973bd47d1bd26 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"binary search",
"math"
] | 1532617500 | ["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"] | NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth. | PASSED | 1,500 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. | ["10.0000000000", "-1", "85.4800000000"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
double f,dumbv=1;
int nump,i,rocw8;
scanf("%d ",&nump);
scanf("%d ",&rocw8);
int tol[2*nump];
for(i=0;i<2*nump;i++)
{
scanf("%d",&tol[i]);
}
for(i=0;i<2*nump;i++)
{
dumbv=dumbv*(tol[i]-1)/tol[i];
}
if(!dumbv){
printf("-1");
exit(0);
}
dumbv=(rocw8)/dumbv;
dumbv=dumbv-rocw8;
printf("%.10f",dumbv);
return 0;
}
| |
Someone gave Alyona an array containing n positive integers a1,βa2,β...,βan. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.Formally, after applying some operations Alyona will get an array of n positive integers b1,βb2,β...,βbn such that 1ββ€βbiββ€βai for every 1ββ€βiββ€βn. Your task is to determine the maximum possible value of mex of this array.Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. | Print one positive integerΒ β the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | C | 482b3ebbbadd583301f047181c988114 | efb52cb5762f79c4ee5ee1e148075178 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"sortings"
] | 1466181300 | ["5\n1 3 3 3 6", "2\n2 1"] | NoteIn the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.To reach the answer to the second sample case one must not decrease any of the array elements. | PASSED | 1,200 | standard input | 1 second | The first line of the input contains a single integer n (1ββ€βnββ€β100β000)Β β the number of elements in the Alyona's array. The second line of the input contains n integers a1,βa2,β...,βan (1ββ€βaiββ€β109)Β β the elements of the array. | ["5", "3"] | #include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
return ( *(long long int*)a - *(long long int*)b );
}
int main()
{
long long arr[200005]={0},i,j,num=1,n;
scanf("%lld",&n);
for(i=0;i<n;i++)
scanf("%lld",&arr[i]);
qsort(arr,n,sizeof(long long int),cmpfunc);
for(i=0;i<n;i++){
if(num==arr[i])
num++;
else if(num<arr[i]){
arr[i]=num; num++;
}
else if(num>arr[i])
num=num;
}
printf("%lld\n",num);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6f6b68d57b12f622ec69a9919aa07712 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
int i, j, n, one = 0, two = 0, three = 0, a;
scanf("%d", &n);
for(i = 0; i <n; i++){
scanf("%d", &a);
if(a==1){
one++;
}
else if(a==2){
two++;
}
else{
three++;
}
}
if(three>= two && three >= one){
printf("%d", n-three);
}
else if( two>= three && two >= one){
printf("%d", n-two);
}
else{
printf("%d", n-one);
}
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6f3669ee0bfebefd2048c37aef7a6380 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],k=0,l=0,m=0,i;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
if(a[i]==1){
k++;
}
if(a[i]==2){
l++;
}
if(a[i]==3){
m++;
}
}
if(k>=l && k>=m){
printf("%d",l+m);
}
else if(l>=k && l>=m){
printf("%d",k+m);
}
else if(m>=k && m>=l){
printf("%d",k+l);
}
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 814877f25a7e7ee0038913d9a543ac32 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int max(int a, int b, int c)
{
int m = a;
if (b > m) m = b;
if (c > m) m = c;
return m;
}
int main()
{
int n, x, i;
int a[3] = {0};
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x);
a[x - 1]++;
}
printf("%d\n", a[0] + a[1] + a[2] - max(a[0], a[1], a[2]));
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 896c5eb13cdcdb23093960774e3853b7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main(void) {
// your code goes here
int n,j;
scanf("%d",&n);
int i,a=0,b=0,c=0;
for(i=0;i<n;i++)
{
scanf("%d",&j);
if(j==1)a++;
if(j==2)b++;
if(j==3)c++;
}
int max=0;
if(a>=b && a>=c)
max=a;
if(b>=a && b>=c)
max=b;
if(c>=a && c>=b) max=c;
printf("\n%d",n-max);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 602285cc87ffcf0c38614596b1d2a49a | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
long long int n,a,i,p=0,q=0,r=0;
scanf("%I64d",&n);
for(i=0;i<n;i++)
{
scanf("%I64d",&a);
if(a==1) p++;
else if(a==2) q++;
else if(a==3) r++;
}
if(p>=q&&p>=r) printf("%I64d ",q+r);
else if(q>=p&&q>=r) printf("%I64d ",p+r);
else if(r>=p&&r>=q) printf("%I64d ",p+q);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 023d908ab76c579d5c0a7da81a01de0c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n,i,on=0,tw=0,th=0,a;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(a==1)
on++;
else if(a==2)
tw++;
else
th++;
}
if(on>=tw && on>=th)
printf("%d",n-on);
else if(tw>=on && tw>=th)
printf("%d",n-tw);
else if(th>=tw && th>=on)
printf("%d",n-th);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 4a94627e529e862badf3db9e15dcb0ea | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main(){
int n, x, ans;
int ct[4];
ct[1] = ct[2] = ct[3] = 0;
scanf("%d", &n );
while( n-- ){
scanf("%d", &x );
ct[x]++;
}
ans = ct[1] + ct[2];
if( ct[1]+ct[3] < ans ) ans = ct[1] + ct[3];
if( ct[2]+ct[3] < ans ) ans = ct[2] + ct[3];
printf("%d\n", ans );
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | f012dfddde158470408b1d2f6ab77342 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | /*
Badhan Sen
Student of C.S.E
jessore University of Science & Technology
Mail: galaxybd9@gmail.com
*/
#include <stdio.h>
int array[10000000];
int main ()
{
int n, i, a=0, b=0, c=0;
scanf ("%d", &n);
for (i=0; i<n; i++){
scanf ("%d", &array[i]);
}
for (i=0; i<n; i++){
if (array[i]==1)
a++;
}
for (i=0; i<n; i++){
if (array[i]==2)
b++;
}
for (i=0; i<n; i++){
if (array[i]==3)
c++;
}
if (a>b && a>c)
printf ("%d", b+c);
else if (b>a && b>c)
printf ("%d", a+c);
else if (c>a && c>b)
printf ("%d", a+b);
else if (a==b && b==c)
printf ("%d", a+c);
else if ((a>b && a>c) && b==c)
printf ("%d", b+c);
else if ((b>a && b>c) && a==c)
printf ("%d", a+c);
else if ((c>a && c>b) && a==b)
printf ("%d", a+b);
else if (b==c && a<b)
printf ("%d", a+b);
else if (a==c && b<c)
printf ("%d", b+a);
else if (a==b && c<a)
printf ("%d", c+a);
else if (n==2)
printf ("1");
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 110ef01cd40390f564922c5de13f395a | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
#include<math.h>
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
int main()
{
long long n,i,x,a[3]={0};
scanf("%lld",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&x);
x--;
a[x]++;
}
printf("%d",n-(MAX(a[0],MAX(a[1],a[2]))));
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 66b307c3d04c1a35eb6fd6ace47c7288 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int a,n,i,p=0,q=0,r=0;
scanf("%d",&n);
//while(n!=0)
for(i=1;i<=n;i++) {
scanf("%d",&a);
if(a==1){
p++;
}
else if(a==2) {
q++;
}
else {
r++;
}
//n--;
}
if(p>=q&&p>=r) {
printf("%d",q+r);
}
else if(q>p&&q>=r) {
printf("%d",p+r);
}
else {
printf("%d",p+q);
}
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | d1b187ff1838236eb4211169a891d1bc | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main(){
int n, x, a[3];
a[0] = 0;
a[1] = 0;
a[2] = 0;
scanf("%d", &n);
for(; n > 0; n--){
scanf("%d", &x);
(a[x - 1])++;
}
if((a[0] <= a[2]) && (a[1] <= a[2])){
printf("%d\n", a[0] + a[1]);
}else if((a[1] <= a[0]) && (a[2] <= a[0])){
printf("%d\n", a[1] + a[2]);
}else if((a[2] <= a[1]) && (a[0] <= a[1])){
printf("%d\n", a[0] + a[2]);
}
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 77a8a02ca603e9d0d1337dd4fc87daf9 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,a[4]={0},s=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
a[x]++;
}
for(int i=1;i<=3;i++)
{
if(a[i]>s)
s=a[i];
}
printf("%d",n-s);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 80dc9045303f86d7d92529783e06510d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
#define For(X,Y,Z) for(int X=Y;X<Z;X++)
int max(int x,int y)
{
if(x>y) return x;
else return y;
}
int main()
{
int a[4]={0},n,m;
scanf("%d",&n);
a[1]=a[2]=a[3]=0;
For(i,0,n)
scanf("%d",&m),a[m]++;
n=a[1]+a[2]+a[3];
printf("%d\n",n-max(a[1],max(a[2],a[3])));
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | ac2d0414558b3fb97ddaea1e335034bf | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main(){
int n,c = 0;
scanf("%d",&n);
int a[3];
int i;
for(i = 0; i < 3; i++ ) a[i] = 0;
for ( i = 0; i < n ; i++){
int x;
scanf("%d", &x);
if(x == 1) a[0]++;
else if(x == 2) a[1]++;
else a[2]++;
}
int max = 0;
if(a[0] >= a[1] && a[0] >= a[2]) max = 0;
else if(a[1] >= a[0] && a[1] >= a[2]) max = 1;
else max = 2;
// printf("%d\n", max);
for(i = 0; i < 3; i++)
if(i != max) c += a[i];
printf("%d\n", c);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 719b6910af4743a048fb2ff1cd508404 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
int n,a,i,ara[1000005],max;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&ara[i]);
}
int count1=0,count2=0,count3=0;
for(i=0;i<n;i++){
if(ara[i]==1){
count1++;
}
else if(ara[i]==2){
count2++;
}
else{
count3++;
}
}
if(count1>count2){
if(count1>count3){
max=count1;
}
else{
max=count3;
}
}
else{
if(count2>count3){
max=count2;
}
else{
max=count3;
}
}
printf("%d\n",n-max);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | d2ec6e77e0fcf72c5d19054ac32b1130 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int n , a , i , j , k, num[4] ;
int main()
{
scanf("%d", &n ) ;
while( ++i <= n )
{
scanf("%d", &a ) ;
num[a]++ ;
}
for( i = 1 ; i < 4 ;i++) if ( k < num[i] ) k = num[i] ;
printf("%d", n - k ) ;
return 0 ;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | b6b67daf1da92b76f77566037ccb4701 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
int n,a=0,b=0,c=0,x,i;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&x);
if(x==1)a++;
else if(x==2)b++;
else c++;
}
if(a>b&&a>c)printf("%d",b+c);
else if(b>c&&b>a)printf("%d",a+c);
else if(c>a&&c>b)printf("%d",a+b);
else if(a==b&&b==c&&a==c) printf("%d",a+b);
else if(a==b)printf("%d",c+a);
else if(c==b)printf("%d",a+b);
else if(a==c)printf("%d",a+b);
else ;
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 3957edd037ef7b78c617bcfaa8378470 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
long int n,i,count1=0,count2=0,count3=0;
long int max,replace;
int a;
scanf("%ld",&n);
//printf("%ld",n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(a==1)
count1++;
else if(a==2)
count2++;
else count3++;
}
max=count1;
replace=count2+count3;
if(count2>max)
{
max=count2;
replace=count1+count3;
}
if(count3>max)
{
max=count3;
replace=count1+count2;
}
printf("%ld",replace);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 56ca3355bb494235a7f8d39bda8c5fe5 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n,count1=0,count2=0,count3=0,X=0,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]==1) count1++;
if(a[i]==2) count2++;
if(a[i]==3) count3++;
X=max(count1,count2,count3);
}
printf("%d",n-X);
return 0;
}
int max(int a,int b,int c)
{
int M;
if(a>=b && a>=c)
M=a;
else if(b>=a && b>=c)
M=b;
else if(c>=a && c>=b)
M=c;
return M;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 5db4456bd03a22e1a81c1fdcb5a82657 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main() {
int n,a,big,i,arr[4]={0};
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a);
arr[a]++;
}
big=arr[1];
for(i=1;i<=3;i++)
if(big<arr[i])
big=arr[i];
printf("%d",n-big);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6e89a2023c7908530ebb729d2633a9be | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
long long int n,i,c1=0,c2=0,c3=0,s1,s2,s3,max,a;
scanf("%lld", &n);
for (i=0;i<n;i++)
{
scanf("%lld", &a);
if (a==1) c1++;
if (a==2) c2++;
if (a==3) c3++;
}
if (c1>c2) max=c1;
else max=c2;
if (c3>max) max=c3;
if (max==c1) printf("%lld", c2+c3);
else if (max==c2) printf("%lld", c1+c3);
else if (max==c3) printf("%lld", c2+c1);
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 8e02ced36102363b378a3b1548c21b35 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main (void) {
int n, i, a=0, b=0, c=0;
scanf("%d", &n);
int ar[n];
for( i=0; i<n; i++) {
scanf("%d", &ar[i]);
if(ar[i]==1) a++;
if(ar[i]==2) b++;
if(ar[i]==3) c++;
}
if(b>=c && b>=a) printf("%d\n", n-b);
else if(c>=b && c>=a) printf("%d\n", n-c);
else if(a>=c && a>=b) printf("%d\n", n-a);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 067ca55954fc8778e448c575808b1b81 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int m,n,count=0,ara[1000000],i,o,j,l,cu=0,as=0;
//int ara[1000000];
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d",&ara[i]);
}
for(i=0,1<=n<=1000000;i<n;i++) {
if(ara[i]==1) {
count++;
}
else if(ara[i]==2) {
cu++;
}
else if(ara[i]==3) {
as++;
}
}
if(count>=cu && count>=as) {
printf("%d",n-count);
}
else if(cu>=count && cu>=as) {
printf("%d",n-cu);
}
else if(as>=count && as>=cu) {
printf("%d",n-as);
}
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | af2939a6147222bc395afb7ccef870e5 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
long long n;
scanf("%I64d",&n);
int s[n];
long a=0,b=0,c=0;
long long i;
for (i=0;i<n;i++)
{
scanf("%d",&s[i]);
if (s[i]!=2) b++;
if (s[i]!=1) a++;
if (s[i]!=3) c++;
}
long d=(a<b) ?(a<c) ? a : c : (b<c) ? b :c ;
printf("%ld",d);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 56fa0c9ffaadc15789c302d43fb1d230 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
main(){
int n,i;
scanf("%d",&n);
int a[n],o=0,t=0,tr=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]==1) o++;
if(a[i]==2) t++;
if(a[i]==3) tr++;
}
int max=o;
if(max<t) max=t;
if(max<tr) max=tr;
printf("%d",n-max);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 30ebd501d10f71dd2708308bdc3715f9 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int a;
long n,a1=0,a2=0,a3=0;
scanf("%ld",&n);
while(n--)
{
scanf("%d",&a);
if(a==1)
a1++;
else if(a==2)
a2++;
else a3++;
}
if(a3>=a1&&a3>=a2)
printf("%ld",a1+a2);
else if(a2>=a1&&a2>=a3)
printf("%ld",a1+a3);
else printf("%ld",a2+a3);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 53fdac89ee01c4babdced3d32e82fed3 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
int n, n1, n2, n3, c;
scanf("%d\n", &n);
n1 = n2 = 0; n3 = n;
while (n3--) {
c = getchar();
if (c == '1') ++n1;
if (c == '2') ++n2;
getchar();
}
n3 = n-n1-n2;
if (n1 < n2) n1 = n2;
if (n1 < n3) n1 = n3;
printf("%d\n", n-n1);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | e4f8b6d93d23e3d317b34d45bfa54ace | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int n, n1, n2, n3, c;
int main()
{
scanf("%d\n", &n);
n3 = n;
while (n3--) {
c = getchar();
if (c == '1') ++n1;
if (c == '2') ++n2;
getchar();
}
n3 = n-n1-n2;
if (n1 < n2) n1 = n2;
if (n1 < n3) n1 = n3;
printf("%d\n", n-n1);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6c1e71acf1e37ccdfc3e4c534db91af5 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n,i,max,x=0,y=0,z=0;
char a[1000000];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]==1)
x++;
else if(a[i]==2)
y++;
else
z++;
}
if(x>y)
max=x;
else
max=y;
if(z>max)
max=z;
printf("%d",n-max);
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 8ed4ab86c72b597e811b04f4b32be071 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n,a;
scanf("%d",&n);
long int i,arr[3]={0};
for(i=0;i<n;i++)
{
scanf("%d",&a);
arr[a-1]++;
}
long max=0;
for(i=0;i<3;i++) if(max<arr[i]) max=arr[i];
printf("%ld",n-max);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | c67749709ff8f37dd871c4829d32fea7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
int n,a=0,b=0,c=0,x,i;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&x);
if(x==1)a++;
else if(x==2)b++;
else c++;
}
if(a>b&&a>c)printf("%d",b+c);
else if(b>c&&b>a)printf("%d",a+c);
else if(c>a&&c>b)printf("%d",a+b);
else if(a==b&&b==c&&a==c) printf("%d",a+b);
else if(a==b)printf("%d",c+a);
else if(c==b)printf("%d",a+b);
else if(a==c)printf("%d",a+b);
else ;
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 49c4490a7ba007c86878ee8f8f692cc1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main(){
long int n;
scanf("%ld",&n);
int a=0,b=0,c=0,x;
while(n--){
scanf("%d",&x);
if (x==1){
a++;
}
else if (x==2){
b++;
}
else
c++;
}
int min=a+b;
if (min>b+c){
min=b+c;
}
if (min>c+a){
min=c+a;
}
printf("%d",min);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 05d4c4cb988dc1793029dc4715fa0987 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <assert.h>
#include <stdio.h>
int max(int a, int b, int c) {
if (a >= b && a >= c)
return a;
else if (b >= a && b >= c)
return b;
else
return c;
}
/*
* http://codeforces.com/problemset/problem/52/A
* A. 123-sequence
*/
int main(void) {
int ok, n, x, uno, dos, tres, i;
ok = scanf("%i", &n);
assert(ok == 1 && 1 <= n && n <= 1000000);
uno = 0;
dos = 0;
tres = 0;
for (i = 0; i < n; ++i) {
ok = scanf("%i ", &x);
assert(ok == 1 && 1 <= x && x <= 3);
if (x == 1)
++uno;
else if (x == 2)
++dos;
else
++tres;
}
printf("%i\n", n - max(uno, dos, tres));
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 847931aa5f7bfbbc6b74d0301749eff2 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main (void){
unsigned long int n,i,c1=0,c2=0,c3=0,z,max;
int num;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&num);
if(num==1)
c1++;
else if (num==2)
c2++;
else if(num==3)
c3++;
}
max = ( c1 > c2 )? c1 : c2;
max = (max > c3) ? max : c3;
z=n-max;
printf("%d",z);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 44127321a432da0f8cc38b275fe3d449 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main(){
unsigned int n, i, a, max, numbers[] = {0, 0, 0, 0};
scanf("%u", &n);
for(i=0; i < n; i++){
scanf("%d", &a);
numbers[a]++;
}
max = numbers[1] > numbers[2] ? numbers[1] : numbers[2];
max = numbers[3] > max ? numbers[3] : max;
printf("%u\n", n - max);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6f887972039f6ca30adabb1d5878f985 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i;scanf("%d",&n);long long int a[n],p,k,x,y,z,ma;x=y=z=0;
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==1)
x++;
else if(a[i]==2)
y++;
else
z++;
}
if(x>=y&&x>=z)
ma=x;
else if(y>=x&&y>=z)
ma=y;
else
ma=z;
printf("%lld",n-ma);
//printf("%d",x);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | e06e3c96320b78742f3c5f9c2350704f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n;
int a,x=0,y=0,z=0;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
if(a==1) x++;
else if(a==2) y++;
else z++;
}
if(x>=y&&x>=z) printf("%d",y+z);
else if(y>=x&&y>=z) printf("%d",x+z);
else printf("%d",x+y);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 056c10a9735d5559578811cc449d75f6 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
//#include<conio.h>
int main()
{
long int n,s=0,a,i,w=0,x=0,y=0,z;
scanf("%ld",&n);
for(i=1;i<=n;i++)
{ scanf("%ld",&a);
if(a==1) w++; else if(a==2) x++; else y++; }
z=(w>x?(w>y?w:y):(x>y?x:y));
printf("%ld",w+x+y-z);
// getch();
return(0);
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | f1a72c6da59e7e892a44d3a6aa1914f6 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
long long int i,j=0,k=0,m=0,n,rem,div,val,big;
scanf("%lld",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&val);
if(val==1) j++; else if(val==2) k++;else m++; //so j,k,m counts the number of 1,2,3 respectively
}
big=((j+k)+abs(j-k))/2;
big=((big+m)+abs(big-m))/2;
printf("%lld\n",n-big);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | ce1929dafc75c3fae835b466068db1ed | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main(int argc, char *argv[])
{
unsigned long n,i=0;
unsigned long count[3];
int num;
count[0]=count[1]=count[2]=0;
scanf("%ld", &n);
for(i=0; i<n; i++){
scanf("%d", &num); count[num-1]++;
}
if(count[0]>=count[1] && count[0]>=count[2])
printf("%ld", count[1]+count[2]);
else if(count[1]>=count[0] && count[1]>=count[2])
printf("%ld", count[0]+count[2]);
else
printf("%ld", count[0]+count[1]);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 975b13e94a37f9e28bee1d5b83837d5c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n,a=0,b=0,c=0,d;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&d);
if (d==1) a++;
if (d==2) b++;
if (d==3) c++;
}
if (a>=b && a>=c) {printf("%d",b+c); return 0;}
if (b>=a && b>=c) {printf("%d",a+c); return 0;}
if (c>=b && c>=a) printf("%d",b+a );
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | fce71c1cf2fabcf20071e7b08db3b967 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],i,x=0,y=0,z=0;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]==1)x++;
if(a[i]==2)y++;
if(a[i]==3)z++;
}
if(x>=y&&x>=z)printf("%d",n-x);
else if(y>=z&&y>=x)printf("%d",n-y);
else if(z>=x&&z>=y)printf("%d",n-z);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | c45aa828969ce43ec1c3f58215f673ea | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int min(int a, int b)
{
return a<b ? a : b;
}
int main()
{
int t[3] = {0, 0, 0}, n, m;
scanf("%d", &n);
while (n--) scanf("%d", &m), t[m-1]++;
int a = t[0]+t[1], b = t[2]+t[1], c = t[0]+t[2];
printf("%d\n", min(min(a, b), c));
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6b06bb95afdff002860706e230843032 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int arr[4];
int main(){
int n,d,maxi,in,i,sum=0;
scanf("%d",&n);
while(n--){
scanf("%d",&d);
arr[d]++;
}
maxi=arr[1];
in = 1;
for(i=1;i<=3;i++){
if(arr[i]>maxi){
maxi=arr[i];
in = i;
}
}
for(i=1;i<=3;i++)
if(i!=in) sum+=arr[i];
printf("%d",sum);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | f0cb4d52db2e928258f0c5e501bdab0d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{long int i,n,d=0,b=0,c=0,min; int a;
scanf("%ld",&n);
for(i=0;i<n;i++)
{scanf("%d",&a);
if(a!=1) b++;
if(a!=2) c++;
if(a!=3) d++;
}
min=d;
if(b<d && b<=c) min=b;
if(c<d && c<=b) min=c;
printf("%ld",min);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 142d6f8957f195ddf34c92e1559e345b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#define min(x,y) ((x)<(y)?(x):(y))
int main(void) {
int n, x[3] = {0, 0, 0};
scanf("%d", &n);
while (n--) {
getchar();
x[getchar() - '1']++;
}
printf("%d", min(x[0] + x[1], min(x[1] + x[2], x[0] + x[2])));
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 7937a00ec2deaf7a5729eda5977e61ec | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,one=0,two=0,three=0;
scanf("%d",&n);
int ara[n];
for(i=0;i<n;i++)
{
scanf("%d",&ara[i]);
if(ara[i]==1)
one++;
else if(ara[i]==2)
two++;
else
three++;
}
if(one>=two&&one>=three)
printf("%d",n-one);
else if(two>=one&&two>=three)
printf("%d",n-two);
else
printf("%d",n-three);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | cabfaf5d7e33e245c785bab4fb231651 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
long long int n,i,s1,s2,s3,mx,one=0,two=0,three=0;
scanf("%I64d",&n);
int a;
for(i=0;i<n;i++) {
scanf("%d",&a);
if(a==1)
one++;
if(a==2)
two++;
if(a==3)
three++;
}
s1 = one+two;
s2 = two+three;
s3 = three+one;
//printf("%I64d %I64d %I64d\n",s1,s2,s3);
if(s1<s2)
mx = s1;
else
mx = s2;
if(mx>s3)
mx = s3;
printf("%I64d",mx);
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 66566d8b2639caaee248a46a62fee0ee | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n,no,i,count_1=0,count_2=0,count_3=0;
scanf("%d",&n);
// int *a=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
scanf("%d",&no);
if(no==1)
count_1++;
else if(no==2)
count_2++;
else
count_3++;
}
if(count_1+count_2<=count_2+count_3 && count_1+count_2<=count_1+count_3)
printf("%d\n",count_1+count_2);
else if(count_2+count_3<=count_1+count_2 && count_2+count_3<=count_1+count_3)
printf("%d\n",count_2+count_3);
else if(count_1+count_3<=count_2+count_3 && count_1+count_3<=count_1+count_2)
printf("%d\n",count_1+count_3);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | a89be6a746a019e42ff40c2b77c62a11 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
main()
{
long long int a[1000000],i,j,n,c=0,c1=0,c2=0;
scanf("%I64d",&n);
for(i=1;i<=n;i++)
{
scanf("%I64d",&a[i]);
if(a[i]==1) c++;
if(a[i]==2) c1++;
if(a[i]==3) c2++;}
if(c>=c1&&c>=c2) printf("%I64d",n-c);
else if(c1>=c&&c1>=c2) printf("%I64d",n-c1);
else printf("%I64d",n-c2);
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 6dce4046ef3bd74c060e242db3041fd0 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
#include <string.h>
int min(int a, int b) {
return a < b ? a : b;
}
int main() {
int n; scanf("%d", &n);
int i, c[3];
memset(c, 0, sizeof(c));
for (i = 0; i < n; i++) {
int a; scanf("%d", &a); a--;
c[a]++;
}
printf("%d\n", min(c[0]+c[1], min(c[0]+c[2], c[1]+c[2])));
return 0;
}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 198b787069af1cec2bed04a8203a6817 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int n,a[1000005],i,max;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
int p=0,q=0,r=0;
for(i=0; i<n; i++)
{
if(a[i]==1)
p++;
else if(a[i]==2)
q++;
else r++;
}
if(p>q)
{
if(p>r)
{
max=p;
}
else
{
max=r;
}
}
else
{
if(q>r)
{
max=q;
}
else
{
max=r;
}
}
printf("%d",n-max);
return 0;}
| |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 08dea06f7d1485bc9f7aa1169d91a7b1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include <stdio.h>
int main()
{
int n,a,i,ara[1000005],max;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&ara[i]);
}
int count1=0,count2=0,count3=0;
for(i=0;i<n;i++){
if(ara[i]==1){
count1++;
}
else if(ara[i]==2){
count2++;
}
else{
count3++;
}
}
if(count1>count2){
if(count1>count3){
max=count1;
}
else{
max=count3;
}
}
else{
if(count2>count3){
max=count2;
}
else{
max=count3;
}
}
printf("%d\n",n-max);
return 0;
} | |
There is a given sequence of integers a1,βa2,β...,βan, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | C | fcb6a715dfe302d7ae5a6695ca8976aa | 3d7e7145af0f1e3abe63fd9c4cd4fe8e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1294160400 | ["9\n1 3 2 2 2 1 1 2 3"] | NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2. | PASSED | 900 | standard input | 2 seconds | The first line contains an integer n (1ββ€βnββ€β106). The second line contains a sequence of integers a1,βa2,β...,βan (1ββ€βaiββ€β3). | ["5"] | #include<stdio.h>
int main()
{
int a,i,p=0,q=0,r,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(a==1) p++;
else if(a==2) q++;
}
r=n-(p+q);
if(p<q) p=q;
if(p<r) p=r;
printf("\n%d",n-p);
return(0);
}
| |
Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "diβββti", that means "replace all digits di in string s with substrings equal to ti". For example, if sβ=β123123, then query "2βββ00" transforms s to 10031003, and query "3βββ" ("replace 3 by an empty string") transforms it to sβ=β1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007Β (109β+β7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero.Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him! | Print a single integer β remainder of division of the resulting number by 1000000007Β (109β+β7). | C | c315870f5798dfd75ddfc76c7e3f6fa5 | 87dc24d58ca1557c25ac96b47ebcec0b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp"
] | 1410103800 | ["123123\n1\n2->00", "123123\n1\n3->", "222\n2\n2->0\n0->7", "1000000008\n0"] | NoteNote that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample). | PASSED | 2,100 | standard input | 1 second | The first line contains string s (1ββ€β|s|ββ€β105), consisting of digitsΒ β the string before processing all the requests. The second line contains a single integer n (0ββ€βnββ€β105)Β β the number of queries. The next n lines contain the descriptions of the queries. The i-th query is described by string "di->ti", where di is exactly one digit (from 0 to 9), ti is a string consisting of digits (ti can be an empty string). The sum of lengths of ti for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed. | ["10031003", "1212", "777", "1"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define long long long
#define NN 501010
#define mod ((long)1e9 + 7)
int n;
char s[NN], t[NN], c[NN], * b[NN];
long p[10], len[10];
long mpow(long base, long m) {
long ans = 1;
for (; m > 0; m >>= 1) {
if (m & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
}
return ans;
}
void process(char* s, long* val, long* l) {
*val = *l = 0;
int i = 0; while (s[i]) ++i;
while (i --) {
*val = (*val + (p[s[i] - '0'] * mpow(10, *l)) % mod) % mod;
*l = (*l + len[s[i] - '0']) % (mod - 1);
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("transform.inp", "r", stdin);
freopen("transform.out", "w", stdout);
#endif
int i;
memset(t, 0, sizeof(t));
char *pt = t;
scanf("%s", s);
scanf("%d", &n);
b[0] = s;
c[0] = 0;
for (i = 1; i <= n; ++i) {
scanf("%s", pt);
c[i] = pt[0] - '0';
b[i] = pt + 3;
while (*pt) ++pt;
++pt;
}
for (i = 0; i < 10; ++i) {
p[i] = i;
len[i] = 1;
}
for (i = n; i >= 0; --i) {
long f, g;
process(b[i], &f, &g);
p[(int)c[i]] = f; len[(int)c[i]] = g;
}
printf("%d", (int)p[0]);
return 0;
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | 4bd80997888d7d014b2719f41b0ac053 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include<stdio.h>
#include<string.h>
int main()
{
int k,i,j,n,lm,l;
char mes[1010];
scanf("%s",mes);
scanf("%d",&k);
l=strlen(mes);
if(l%k!=0)
{
printf("NO");
return 0;
}
lm=l/k;
for(i=0;i<k;i++)
{
for(j=i*lm,n=((i+1)*(lm-1)+i);j<((i+1)*lm)/2,n>=(i*lm)+lm/2;j++,n--)
{
if(mes[j]!=mes[n])
{
printf("NO");
return 0;
}
}
}
printf("YES");
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | 4d2e3a64287f31001f885705bb7004d8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include <stdio.h>
#include <string.h>
int main()
{
char s[1010];
int n,l,i,j;
gets(s);
scanf("%d",&n);
if (strlen(s)% n > 0)
{
printf("NO\n");
return 0;
}
l = strlen(s) / n;
for (i = 0; i < n; i++)
for (j = 0; j < l / 2; j++)
if (s[j + i * l] != s[(i + 1) * l - j - 1])
{
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | f19fa801f81190e87b64b6beead6b6ab | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include <stdio.h>
#include <string.h>
int main()
{
int i,n,a=0,l,b,k,wl,j,m,cmp,count=0,g;
char str[1001],temp[1001],temp2[1001];
scanf("%s%d",str,&k);
l=strlen(str);
wl=l/k;
if((k>l)||(wl*k!=l))
{
printf("NO");
return 0;
}
for(i=0;i<l;i++)
{
for(j=0;j<wl;j++)
{
temp[j]=str[i+j];
}
temp[j]='\0';
g=strlen(temp);
for(j=g-1,m=0;m<g;j--,m++)
{
temp2[m]=temp[j];
}
temp2[m]='\0';
cmp=strcmp(temp2,temp);
if((cmp==0)&&(strlen(temp2)==wl))
{
if(count!=k)
{
count++;
i+=wl-1;
}
}
}
if(count==k)
{
printf("YES");
}
else
{
printf("NO");
}
return 0;
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | 8bbb5a0a17b985935de0a73427144036 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include<stdio.h>
#include<string.h>
int main()
{
char str[1002];
gets(str);
int n,l,x,sum=0,i=0,j,k,count=0;
scanf("%d",&n);
l=strlen(str);
x=l/n;
char ara1[x+1],ara2[x+1];
if((l%n)==0)
{
for(;str[i]!='\0';)
{
for(j=0,k=x-1;j<x,k>=0;j++,k--,i++)
{
ara1[j]=str[i];
ara2[k]=str[i];
}
for(j=0;j<x;j++)
{
if(ara1[j]==ara2[j])
{
sum++;
}
}
if(sum==x)
{
count++;
sum=0;
}
}
if(count==n)
{
printf("YES");
}
else
{
printf("NO");
}
}
else
{
printf("NO");
}
return 0;
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | 81ce18833e23069106ce214fca86592e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include<stdio.h>
#include<string.h>
int main()
{
int a,i,j,m,n,f,l,k,d,r;
char c[10000];
gets(c);
scanf(" %d", &n);
m=strlen(c);
f=0;
l=m/n;
r=l;
d=0;
if(m%n==0)
{
for(k=0; k<n; k++)
{
for(i=f,j=l-1; i<(f+l)/2; i++,j--)
{
if(c[i]!=c[j])
{
d=1;
}
if(d==1)
{
printf("NO\n");
break;
}
}
if(d==1)
{
break;
}
f=l;
l=l+r;
}
if(d==0)
{
printf("YES\n");
}
}
else
printf("NO\n");
return 0;
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | deba19ffe28e4a0c05091674de9b87e9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include <stdio.h>
int main()
{
int count = 0, check = 0, j = 0, k, lop, len = 0, t;
char str[1000];
scanf("%s", str);
scanf("%d", &t);
int i;
for(i = 0; str[i] != '\0'; i++) {
len++;
}
if(len%t != 0) {
check++;
}
lop = len/t;
k = j+lop-1;
for(i = 1; i <= t; i++) {
for(; count <= lop/2; j++, k--) {
if(str[j] != str[k]) {
check++;
break;
}
count++;
}
if(check >= 1) {
break;
}
count = 0;
j = i*lop;
k = j + lop-1;
}
if(check >= 1) {
printf("NO");
}
else {
printf("YES");
}
return 0;
}
| |
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length. | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | C | 43bb8fec6b0636d88ce30f23b61be39f | 5b7eb772c8ed6e51b65cdf739108f791 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"brute force",
"strings"
] | 1432658100 | ["saba\n2", "saddastavvat\n2"] | NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | PASSED | 1,100 | standard input | 1 second | The first line of input contains string s containing lowercase English letters (1ββ€β|s|ββ€β1000). The second line contains integer k (1ββ€βkββ€β1000). | ["NO", "YES"] | #include <stdio.h>
#include <string.h>
#include<stdlib.h>
int main()
{
int length,j=0,q,i,k,n=0,p,w=1,x,l=0,m;
char s[1002], word[1002],s2[1002];
scanf("%s",&s);
scanf("%d",&k);
m=k;
length=strlen(s);
p=length/k;
q=p*w;
i=0;
j=0;
if(length%k!=0)
{
n=1;
}
for(;j<length&&n!=1;j++)
{
word[i]=s[j];
i++;
if(j==(q)-1)
{
word[i]='\0';
strcpy(s2,word);
i=0;
w++;
j=p*(w-1)-1;
q=p*w;
strrev(word);
x=strcmp(s2,word);
if(x==0)
{
continue;
}
else
{
n=1;
break;
}
}
}
if(n==1){
printf("NO");
}
else{
printf("YES");
}
return 0;
}
| |
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.The forestThe Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example): MovesBreeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions: Do nothing. Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees. If you are located on the exit cell, you may leave the forest. Only you can perform this move β all other mikemon breeders will never leave the forest by using this type of movement. After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).Mikemon battleIf you and t (tβ>β0) mikemon breeders are located on the same cell, exactly t mikemon battles will ensue that time (since you will be battling each of those t breeders once). After the battle, all of those t breeders will leave the forest to heal their respective mikemons.Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders β there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).Your goalYou would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.Goal of other breedersBecause you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.Your taskPrint the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make. | A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. | C | 6e9c2236e24336fcca0723e656e664cc | 236e458b3b6c106aa0805825d48f3db9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dfs and similar",
"shortest paths"
] | 1374327000 | ["5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000", "1 4\nSE23"] | NoteThe following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog: The three breeders on the left side of the map will be able to battle you β the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.For the second example, you should post this sequence in your Blog: Here's what happens. First, you move one cell to the right. Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing. You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest. Finally, you make another move by leaving the forest. | PASSED | 1,500 | standard input | 2 seconds | The first line consists of two integers: r and c (1ββ€βr,βcββ€β1000), denoting the number of rows and the number of columns in Biridian Forest. The next r rows will each depict a row of the map, where each character represents the content of a single cell: 'T': A cell occupied by a tree. 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map. 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map. A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder). It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves. | ["3", "2"] | /* practice with Dukkha */
#include <stdio.h>
#include <string.h>
#define N 1000
#define M 1000
#define INF 0x3f3f3f3f
char cc[N][M + 1];
int dd[N][M], n, m;
int parse(int i, int j) {
char c;
if (i < 0 || i >= n || j < 0 || j >= m || dd[i][j] != INF)
return -1;
c = cc[i][j];
return c >= '0' && c <= '9' ? c - '0' : c == 'S' ? 0 : -1;
}
int di[4] = { -1, 1, 0, 0 };
int dj[4] = { 0, 0, -1, 1 };
int main() {
static int kk[N * M], qq[N * M * 2];
int h, i, i_, j, j_, k, d, head, cnt;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i][j] == 'E')
goto outE;
outE:
memset(dd, 0x3f, sizeof dd);
head = cnt = 0;
dd[i][j] = 0;
qq[head + cnt++] = i;
qq[head + cnt++] = j;
while (cnt > 0) {
i = qq[head++]; cnt--;
j = qq[head++]; cnt--;
d = dd[i][j] + 1;
for (h = 0; h < 4; h++) {
i_ = i + di[h];
j_ = j + dj[h];
k = parse(i_, j_);
if (k >= 0) {
kk[d] += k;
dd[i_][j_] = d;
qq[head + cnt++] = i_;
qq[head + cnt++] = j_;
}
}
}
for (d = 1; d < n * m; d++)
kk[d] += kk[d - 1];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i][j] == 'S')
goto outS;
outS:
printf("%d\n", kk[dd[i][j]]);
return 0;
}
| |
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.The forestThe Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example): MovesBreeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions: Do nothing. Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees. If you are located on the exit cell, you may leave the forest. Only you can perform this move β all other mikemon breeders will never leave the forest by using this type of movement. After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).Mikemon battleIf you and t (tβ>β0) mikemon breeders are located on the same cell, exactly t mikemon battles will ensue that time (since you will be battling each of those t breeders once). After the battle, all of those t breeders will leave the forest to heal their respective mikemons.Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders β there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).Your goalYou would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.Goal of other breedersBecause you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.Your taskPrint the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make. | A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. | C | 6e9c2236e24336fcca0723e656e664cc | 85c6aa247c05a865263bf4e9b3113195 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dfs and similar",
"shortest paths"
] | 1374327000 | ["5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000", "1 4\nSE23"] | NoteThe following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog: The three breeders on the left side of the map will be able to battle you β the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.For the second example, you should post this sequence in your Blog: Here's what happens. First, you move one cell to the right. Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing. You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest. Finally, you make another move by leaving the forest. | PASSED | 1,500 | standard input | 2 seconds | The first line consists of two integers: r and c (1ββ€βr,βcββ€β1000), denoting the number of rows and the number of columns in Biridian Forest. The next r rows will each depict a row of the map, where each character represents the content of a single cell: 'T': A cell occupied by a tree. 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map. 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map. A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder). It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves. | ["3", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
struct forest
{
char status;//'0'~'9' is breaders_num, 'T' is tree,'S is startpos ,'E' is exit
}Forest[1010][1010];//init 1000 * 1000
struct queue
{
int row;
int col;
int step;
struct queue *next;
};
int create_path(int start[2],int exit[2],int step_cond,int max_step);
int main(int argc, char const *argv[])
{
int row,col;
scanf("%d%d",&row,&col);
char get_endl;
int exit[2],start[2];
scanf("%c",&get_endl);
for (int i = 0; i < row+2; ++i)
{
if (i==0 || i==row+1){
for (int j = 0; j < col+2; ++j)
Forest[i][j].status='T';
continue;
}
Forest[i][0].status='T';
Forest[i][col+1].status='T';//set edge to tree
for (int j = 1; j < col+1; ++j){
scanf("%c",&(Forest[i][j].status));
// printf("get status : %c,%d,%d\n",Forest[i][j].status,i,j );
if(Forest[i][j].status=='S'){
start[0]=i;
start[1]=j;
}
if(Forest[i][j].status=='E'){
exit[0]=i;
exit[1]=j;
}
}
scanf("%c",&get_endl);
}
char walked_map[1010][1010]={{0}};//set zero
int step;
step=create_path(start,exit,0,0);
// printf("step is %d\n",step );
printf("%d\n",create_path(exit,exit,1,step));
return 0;
}
// using bfs
struct queue *add_queue(struct queue *start_Queue,int row,int col,int step){
if (start_Queue==NULL){
start_Queue=(struct queue*)malloc(sizeof(struct queue));
start_Queue->row=row;
start_Queue->col=col;
start_Queue->step=step;
start_Queue->next=NULL;
return start_Queue;
}
start_Queue->next=add_queue(start_Queue->next,row,col,step);
return start_Queue;
}
struct queue *init_queue(int row,int col,int step){
struct queue *start_Queue=(struct queue*)malloc(sizeof(struct queue));//init
// printf("init %p\n",start_Queue );
start_Queue->row=row;
start_Queue->col=col;
start_Queue->step=step;
start_Queue->next=NULL;
return start_Queue;
}
int create_path(int start[2],int exit[2],int step_cond,int max_step){
// printf("start[0] is %d,[1] is %d\n",start[0],start[1] );
char forest_walked[1010][1010]={{0}};
struct queue *start_Queue=(struct queue*)malloc(sizeof(struct queue));//init
start_Queue->row=start[0];
start_Queue->col=start[1];
(start_Queue->step)=0;
start_Queue->next=NULL;
struct queue *end_queue=start_Queue;
struct queue *last_queue;
int array[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
forest_walked[start[0]][start[1]]=1;//set walked
if (step_cond==1)
{
int battlers=0,now_step=0;
while((start_Queue->step)<max_step)
{
// printf("in\n");
for (int i = 0; i < 4; ++i)
{
int row=(start_Queue->row)+array[i][0],col=(start_Queue->col)+array[i][1];
if ((Forest[row][col].status)!='T' && forest_walked[row][col]==0){
if (isdigit(Forest[row][col].status)){//is 0 ~ 9
battlers+=((Forest[row][col].status)-'0');
// printf("add %d\n",(Forest[row][col].status)-'0' );
}
forest_walked[row][col]=1;
end_queue->next= init_queue(row,col,(start_Queue->step)+1);
end_queue=end_queue->next;
}
}
assert(start_Queue!=NULL);
last_queue=start_Queue;
start_Queue=start_Queue->next;
free(last_queue);
assert(start_Queue!=NULL);
}
return battlers;
}
for(;;)
{
assert(start_Queue!=NULL);
if (start_Queue->row==exit[0]&&start_Queue->col==exit[1])
return start_Queue->step;
for (int i = 0; i < 4; ++i)
{
// printf("ready\n");
int row=(start_Queue->row)+array[i][0],col=(start_Queue->col)+array[i][1];
// printf("now row: %d, col: %d\n",row,col );
// if ((Forest[row][col].status)=='T')
// printf("T\n");
// if (forest_walked[row][col]==1)
// printf("Walked\n");
if ((Forest[row][col].status)!='T' && forest_walked[row][col]==0){
// printf("get\n");
forest_walked[row][col]=1;
// for (int i = 0; i < 5; ++i)
// {
// for (int j = 0; j < 5; ++j)
// {
// printf("%d ",forest_walked[i][j] );
// }
// printf("\n");
// }
end_queue->next= init_queue(row,col,(start_Queue->step)+1);
end_queue=end_queue->next;
}
}
last_queue=start_Queue;
start_Queue=start_Queue->next;
free(last_queue);
}
printf("error! create_path\n");
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | e6b3042c931e40150555bc45c7b8ab39 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include<stdio.h>
int main()
{
int q,n,k,a,b,i,o=0,t[200001],j=0;
scanf("%d",&q);
while(q--)
{
scanf("%d%d",&n,&k);
for(i=0; i<n; i++)
{
scanf("%d",&a);
if(a&1)
o++,t[j++]=i+1;
}
if(o<k||((k+o)&1))
printf("NO\n");
else
{
printf("YES\n");
for(i=0; i<k-1; i++)
printf("%d ",t[i]);
printf("%d\n",n);
}
o=j=0;
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | 6daeabeaed22d6d32b75ddae564ed837 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include<stdio.h>
int main()
{
int x,y;
scanf("%d",&x);
for(y=1;y<=x;y++){
int a,b,s=0,i;
scanf("%d %d",&a,&b);
int aa[a];
for(i=0;i<a;i++)
{
scanf("%d",&aa[i]);
if(aa[i]%2==1)
{
s++;
}
}
if(s<b || (s-b)%2==1)
{
printf("NO\n");
continue;
}
printf("YES\n");
for(i=0;i<a && b>1;i++)
{
if((aa[i]%2)==1)
{
b--;
printf("%d\n",i+1);
}
}
printf("%d\n",a);
}
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | 9c65172a2f25ac57daab867ddd3fdef8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include<stdio.h>
#define TAM 200001
int main(){
int q, n, k, a, cont, impar[TAM];
scanf("%d", &q);
while(q--){
scanf("%d%d", &n, &k);
cont = 0;
for(int i=1; i<=n; i++){
scanf("%d", &a);
if(a%2)
impar[cont++] = i;
}
if(cont<k||(k%2 && cont%2==0)||(k%2==0 && cont%2)){
printf("NO\n");
continue;
}
printf("YES\n");
for(int i=0; i<k-1; i++)
printf("%d ", impar[i]);
printf("%d\n", n);
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | d97e74ac21e49a1e609305775a6b9467 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include <stdio.h>
void main()
{
int q,n,k,r[200000],i,j,b,s;
scanf("%d",&q);
for(;q>0;q--)
{
s = 0;
j = 1;
scanf("%d %d",&n,&k);
for(i=0;i<n;i++)
{
scanf("%d",&b);
s += b%2;
if (j < k && s % 2 == 1)
{
r[j-1] = i+1;
j++;
s = 0;
}
}
if (j < k || (j == k && s % 2 == 0))
printf("NO\n");
else
{
printf("YES\n");
for(i=0;i<k-1;i++)
printf("%d ", r[i]);
printf("%d\n", n);
}
}
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | 2704ac30cd60818fb25385f2274394f3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include <stdio.h>
int main(void) {
int i,j,q,n,k;
int index[200001],count=0,a;
scanf("%d",&q);
for(i=0;i<q;i++){
scanf("%d %d",&n,&k);
count=0;
for(j=0;j<n;j++){
scanf("%d",&a);
if(a%2==1){
index[count++]=j+1;
}
}
index[count-1]=n;
if(count<k || (count-k)%2==1) printf("NO\n");
else{
j=count-k;
printf("YES\n");
for(;j<count;j++){
printf("%d ",index[j]);
}
printf("\n");
}
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | 056eb32c4ec06b36cd12e04c3f93d9c1 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
unsigned long int q;
scanf("%ld",&q);
for (unsigned long int i = 0; i < q; ++i)
{
unsigned long int count_odd = 0;
unsigned long int indexer = 0;
unsigned long int n,k;
scanf("%ld %ld",&n,&k);
unsigned long long int arr[n];
int arr2[n];
for (unsigned long int i = 0; i < n; ++i)
{
scanf("%I64d",&arr[i]);
}
if (k == 1)
{
for (unsigned long int i = 0; i < n; ++i)
{
if (arr[i]%2 != 0)
{
count_odd ++;
}
}
if (count_odd %2 == 0)
{
printf("NO\n");
}
else
{
printf("YES\n");
printf("%ld\n",n);
}
continue;
}
else
{
for (unsigned long int i = 0; i < n; ++i)
{
if (arr[i]%2 != 0)
{
count_odd ++;
}
}
}
if ((count_odd >= k) && (count_odd - k) % 2 == 0)
{
printf("YES\n");
//printf("%ld %ld\n",count_odd,k);
}
else
{
printf("NO\n");
//printf("%ld %ld\n",count_odd,k);
continue;
}
for (unsigned long int i = 0; i < n; ++i)
{
if (arr[i] %2 != 0)
{
printf("%ld ",i+1);
indexer++;
}
if (indexer == k-1 )
{
break;
}
}
printf("%ld\n",n);
}
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | b2a16063c0b7139a2ab06d9e4a051b6d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k,od=0;
scanf("%d%d",&n,&k);
int ar[n];
for(int i=0;i<n;i++)
{
scanf("%d",&ar[i]);
if(ar[i]%2!=0)
od++;
}
if(k==1)
{
if(od%2!=0)
printf("YES\n%d\n",n);
else
printf("NO\n");
}
else
{
int cnt=0;
if(od==k)
{
printf("YES\n");
for(int i=0;i<n&&cnt<k-1;i++)
{
if(ar[i]%2!=0)
{
cnt++;
printf("%d ",i+1);
}
}
printf("%d\n",n);
}
else if(od>k)
{
int l=0,odcnt=0;
for(int i=0;i<n&&cnt<k-1;i++)
{
if(ar[i]%2!=0)
{
l=i;
cnt++;
}
}
for(int i=l+1;i<n;i++)
{
if(ar[i]%2!=0)
odcnt++;
}
if(odcnt%2!=0)
{
cnt=0;
printf("YES\n");
for(int i=0;i<n&&cnt<k-1;i++)
{
if(ar[i]%2!=0)
{
cnt++;
printf("%d ",i+1);
}
}
printf("%d\n",n);
}
else
printf("NO\n");
}
else
printf("NO\n");
}
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i.βe. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries. | For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway. | C | 7f5269f3357827b9d8682d70befd3de1 | 891b940bf276ada2e80d3ad672e383c3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"math"
] | 1563978900 | ["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"] | null | PASSED | 1,200 | standard input | 3 seconds | The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) β the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) β the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$). | ["YES\n1 3 5\nNO\nNO"] | #include<stdio.h>
int main()
{
int q,i;
scanf("%d",&q);
for(i=0;i<q;i++)
{
int n,j,k;
scanf("%d %d",&n,&k);
int a[n],even=0,x=0;
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
if(a[j]%2==0)
{
even++;
}
}
if((n-k)%2!=0)
{
if(even%2==0||even>n-k)
{
printf("NO\n");
}
else
{
printf("YES\n");
for(j=0;j<n;j++)
{
if(a[j]%2!=0&&x<k-1)
{
printf("%d ",j+1);
x++;
}
}
printf("%d",n);
printf("\n");
}
}
else
{
if(even%2!=0||even>n-k)
{
printf("NO\n");
}
else
{
printf("YES\n");
for(j=0;j<n;j++)
{
if(a[j]%2!=0&&x<k-1)
{
printf("%d ",j+1);
x++;
}
}
printf("%d",n);
printf("\n");
}
}
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.