exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
5e682faa745fc9b4813774895758e20c
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Cf703a { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int mishka = 0; int chris = 0; for (int i = 0; i < n; i++) { StringTokenizer stk = new StringTokenizer(br.readLine()); int first = Integer.parseInt(stk.nextToken()); int second = Integer.parseInt(stk.nextToken()); mishka += first > second ? 1 : 0; chris += first < second ? 1 : 0; } if (chris == mishka) System.out.println("Friendship is magic!^^"); else if (chris > mishka) System.out.println("Chris"); else System.out.println("Mishka"); } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
54471c96865103b5aab27e050a7e955d
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.*; public class me{ public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); int m=0, c=0; for(int i=0; i<t; i++) { int a=in.nextInt(), b=in.nextInt(); if(a>b)m++; else if(b>a)c++; } if(m>c)System.out.println("Mishka"); else if(c>m)System.out.println("Chris"); else System.out.println("Friendship is magic!^^"); } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
da5a5ea223a8ac1ce9cbab7c6d9e963d
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.*; /** * * @author Razan */ public class JavaApplication64 { /** * @param args the command line arguments */ //import java.util.Scanner; /** * * @author Razan */ //import java.util.Scanner; /** * * @author Razan */ //import java.util.Scanner; /** * * @author Razan */ static class NewClass12 { Scanner s = new Scanner(System.in); Scanner ss = new Scanner(System.in); int res; int n = s.nextInt(); int[] a = new int[n*2]; int[] b = new int[n*2]; int[] bb = new int[n*2]; int [][]aa=new int[n][2]; List l=new ArrayList(); List ll=new ArrayList(); int i; int j; int m=0; int c=0; public void ss() { for(i=0;i<n;i++){ for(j=0;j<2;j++){ aa[i][j]=s.nextInt(); } } for(i=0;i<n;i++){ for(j=0;j<2;j++){ // System.out.println(aa[i][j]+"i"+i+"j"+j); // System.out.println("j"+j); if(aa[i][j]<aa[i][1]){ c++; } if(aa[i][j]>aa[i][1]){ m++; } } }//System.out.println(c); //for( i=0;i<n*2;i++){ //a[i]=s.nextInt(); // //} //for(i=0;i<a.length;i++){ // int j=i+1; // if(j%2!=0){ // //System.out.println(i+1); // l.add(j); // // System.out.println(b[i]); // } // // if(j%2==0){ // //System.out.println(i+1); // bb[i]=a[i]; // //System.out.println("c"+c); // //System.out.println(bb[i]); // ll.add(j); // } // //System.out.println(a[i]); ////System.out.println(b[i]); ////if(b[i]<bb[i]){System.out.println(bb[i]+">"+b[i]);c++;} ////}System.out.println(c); //m=(n)-c; //System.out.println(l.get(j)); //System.out.println("c"+c); // System.out.println("m"+m); if(m>c){ System.out.println("Mishka"); } else if(m==c){ System.out.println("Friendship is magic!^^"); } else{System.out.println("Chris");} // // // } } public static void main(String[] args) { // TODO code application logic here NewClass12 n = new NewClass12(); n.ss(); } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
84606c076e2c724a653c80420176707e
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.*; public class Code { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = 0, c = 0; for (int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); if (a>b){ m++; } else{ if(a<b){ c++; } } } if(c==m){ System.out.println("Friendship is magic!^^");} else{ if (c>m){ System.out.println("Chris"); } else{ System.out.println("Mishka"); } } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
b48a6f1a6c138feb10c7d3268d7e8bbf
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int m[]=new int[100]; int c[]=new int[100]; int co=0,co1=0; for(int i=0;i<n;i++) { m[i]=s.nextInt(); c[i]=s.nextInt(); } for(int i=0;i<n;i++) { if(m[i]>c[i]) { co++; } else if(m[i]<c[i]) { co1++; } } if(co>co1) { System.out.println("Mishka"); } else if(co<co1) { System.out.println("Chris"); } else { System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
63546f1c3f521a52c00929af1629744e
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class Codeforces703A { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(), total = 0; for(int i = 0; i < n; i++){ int m = scan.nextInt(), c = scan.nextInt(); if(m > c)total++; else if(m < c)total--; } if(total>0) System.out.println("Mishka"); else if(total<0) System.out.println("Chris"); else System.out.println("Friendship is magic!^^"); } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
8bb29b9eba2912b1254740ad5be04a24
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here Scanner input = new Scanner(System.in); int m = 0; int c = 0; int n = input.nextInt(); int[][] a=new int[n][2]; for(int i=0;i<n;i++){ for(int j=0;j<2;j++){ a[i][j]=input.nextInt(); } if(a[i][0]>a[i][1]) m++; else if(a[i][0]<a[i][1]) c++; } if(m>c) System.out.println("Mishka"); else if(c>m) System.out.println("Chris"); else System.out.println("Friendship is magic!^^"); } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
8995189bf77c4bbe92c61e4ab3452206
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class MishkaAndGame { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i <n; i++) { int m=in.nextInt(); int c=in.nextInt(); if(m>c){ count1++; } if(c>m){ count2++; } } if(count1>count2){ System.out.println("Mishka"); } if(count2>count1){ System.out.println("Chris"); } if(count1==count2){ System.out.println("Friendship is magic!^^"); } }}
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
ed0f68790be4d0ad30834ad19952f84f
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class MishkaAndGame { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i < n; i++) { int M=in.nextInt(); int C=in.nextInt(); if(M>C){ count1++; } if(M<C){ count2++; } } if(count1>count2){ System.out.println("Mishka"); } if(count1<count2){ System.out.println("Chris"); } if(count1==count2){ System.out.println("Friendship is magic!^^");} } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
d84118c04668f3d03d80c0444e47fadc
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class MishkaAndGame { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i < n; i++) { int M=in.nextInt(); int C=in.nextInt(); if(M>C){ count1++; } if(C>M){ count2++; } } if(count1>count2){ System.out.println("Mishka"); } if(count2>count1){ System.out.println("Chris"); } if(count1==count2){ System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
e9181618482a0132010b3b0c601f8e91
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class ASH { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int count1 = 0; int count2 = 0; for (int i = 0; i < n; i++) { int x = in.nextInt(); int y = in.nextInt(); if (x > y) { count1++; } else if (x < y) { count2++; } } if (count1 > count2) { System.out.println("Mishka"); } else if (count1 < count2) { System.out.println("Chris"); } else if (count1 == count2) { System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
9b8a56c8d86f811d18c2b10b39d11a4a
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class MishkaAndGame { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i <n; i++) { int M=in.nextInt(); int C=in.nextInt(); if(M>C){ count1++; } if(C>M){ count2++; } } if(count1>count2){ System.out.println("Mishka"); } if(count2>count1){ System.out.println("Chris");} if(count1==count2){ System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
164b9dd0cb2f846d02a26f6b2d92a44f
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class SolverToBe { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i < n; i++) { int x=in.nextInt(); int y=in.nextInt(); if(x>y){ count1++; } else if(x<y){ count2++; } } if(count1>count2){ System.out.println("Mishka"); } if(count1<count2) { System.out.println("Chris"); } if(count1==count2){ System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
76b6264a27576cd7bde4b1c44df93ce3
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class MishkaAndGame { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i < n; i++) { int M=in.nextInt(); int C=in.nextInt(); if(M>C){ count1++; } if(C>M){ count2++; } } if(count1>count2){ System.out.println("Mishka"); } if(count1<count2){ System.out.println("Chris"); } if(count1==count2){ System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
75d20d01d7451a8a075c1a7c9025b522
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class MishkaAndGame { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int count1=0; int count2=0; for (int i = 0; i < n; i++) { int M=in.nextInt(); int C=in.nextInt(); if(M>C){ count1++; } if(M<C){ count2++; } } if(count1>count2) { System.out.println("Mishka"); } if(count1<count2){ System.out.println("Chris"); } if(count1==count2){ System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
4cac5518824e721a543df8a1023d8bb4
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.*; public class MishkaAndGame { public static void main(String[] args) { Scanner in = new Scanner(System.in); int r = in.nextInt(); int winM = 0, winC = 0; int m=0; int c=0; for (int i = 0; i < r; i++) { m = in.nextInt(); c = in.nextInt(); if (m > c) { winM++; } else if(c > m) { winC++; } } if (winM > winC) { System.out.println("Mishka"); } else if (winC > winM) { System.out.println("Chris"); } else { System.out.println("Friendship is magic!^^"); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
57678339d7ec12265ead006df2c23249
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.util.Scanner; public class Test { public static Scanner kbd = new Scanner(System.in); public static void main(String args[]) { System.out.println(MishkaChris()); } public static String MishkaChris() { int total = Integer.parseInt(kbd.nextLine()); int mishka = 0, chris = 0; while (total > 0) { String in = kbd.nextLine(); String[] inS = in.split(" "); int one = Integer.parseInt(inS[0]); int two = Integer.parseInt(inS[1]); if (one > two) { mishka ++; } else if (two > one) { chris ++; } total --; } return mishka > chris ? "Mishka" : chris > mishka ? "Chris" : "Friendship is magic!^^"; } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
b8ddc66b19b4e9f7d6fb8c2f4dbf1485
train_004.jsonl
1470323700
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class MishkaAndGame { public static void main(String[] args) { // TODO Auto-generated method stub // Problem https://codeforces.com/contest/703/problem/A // https://github.com/jontiboss Reader scan = new Reader(); int round = scan.nextInt(); int mishka=0,chris=0; int temp1,temp2; int timeSaver = (int) round/2 ; for(int i =0;i<round;i++) { temp1= scan.nextInt(); temp2= scan.nextInt(); if(temp1>temp2) { mishka++; } if(temp1<temp2) { chris++; } //if one of the players have more than wins than half of the round, that player have already won,no need to check the rest. if(mishka>(timeSaver) || chris>(timeSaver)) { break; } } if(chris>mishka) { System.out.println("Chris"); } if(mishka>chris) { System.out.println("Mishka"); } if(mishka==chris){ System.out.println("Friendship is magic!^^"); } } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } }
Java
["3\n3 5\n2 1\n4 2", "2\n6 1\n1 6", "3\n1 5\n3 3\n2 2"]
1 second
["Mishka", "Friendship is magic!^^", "Chris"]
NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
Java 8
standard input
[ "implementation" ]
76ecde4a445bbafec3cda1fc421e6d42
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
800
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
standard output
PASSED
e13235da4ce4ebd8641a3e9ddd56efab
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public class EhAbAnDgCd { public static void main(String args[]) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++) { int n=s.nextInt(); int a=1; int b=n-1; while(a<=b) { int g=gcd(a,b); int l=(a*b)/gcd(a,b); //System.out.println(g+" asd "+l); if(g+l==n) { System.out.println(a+" "+b); break; } a++; b--; } } } public static int gcd(int a,int b) { if (b == 0) return a; return gcd(b, a % b); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
4f30fef3aacca9eb4f21dd52874fbf71
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); int t = sc.nextInt(); while (t-- > 0) { int x = sc.nextInt(); System.out.println((x - 1) + " " + 1); } } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
a711798e46993859d957d89ba307cd9f
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class GCDPlusLCMEqualNumber { public static void main(String[] args) { (new GCDPlusLCMEqualNumber()).findPair(); } private void findPair() { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t = 0; t < T; t++){ int x = sc.nextInt(); System.out.println(1 +" "+ (x-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
dd47228431699b2b4c7dc3d83ef183e5
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class GCDPlusLCMEqualNumber { public static void main(String[] args) { (new GCDPlusLCMEqualNumber()).findPair(); } private void findPair() { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t = 0; t < T; t++){ int x = sc.nextInt(); System.out.println(1 +" "+ (x-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
4080e89ff7ec2b8538ed2b2068edc8f5
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class Sollution { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int k = scanner.nextInt(); for (int i = 0; i < k; i++) { solve(); } } private static void solve() { int n = scanner.nextInt(); System.out.println("1 " + (n - 1)); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
3b1380ebcc1246f7708900dfe34a9f2f
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class hsaa { public static void main(String[] args) { Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t-->0) { int n=scn.nextInt(); int a=1; int b=1; int flag=0; for(int i=1;i<=n/2;i++) { int g=i; int l=n-i; int pr=g*l; int j=1; for( j=1;;j++) { double temp=(double)pr/j; if(j>(int)temp) { break; } if(temp==(int)temp) { // System.out.println(temp+" "+j); int cg=gcd((int)temp,j); int cl=lcm((int)temp,j); if(cg==g && cl==l) { a=(int)temp; b=j; flag=1; break; } } } if(flag==1) { break; } } System.out.println(a+" "+b); } } public static int gcd(int a,int b) { int gcd=1; for(int i = 1; i <= a && i <= b; ++i) { // Checks if i is factor of both integers if(a % i==0 && b % i==0) gcd = i; } return gcd; } public static int lcm(int a,int b) { int temp=a; for (int i = a; ; i += a) { if (i % b == 0) return i; } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
5dc1a999364e128367577035cbef79e8
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public class test1 { public static void main (String[] args) { Scanner s =new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++) { int x=s.nextInt(); System.out.println(1 +" "+(x-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
d6b9a4c645adeb8ac68c9bd5664a553f
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public final class EhabGCD { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { long x=sc.nextLong(); System.out.println(1+" "+(x-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
563569562431d0b5556bba86a4ba675a
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class c1 { public static void main(String[] args) { MyScanner scan = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t=scan.nextInt(); while(t-->0) { int x=scan.nextInt(); int a=1,b=1; out.println(1+" "+(x-1)); } out.close(); } //scanner public static PrintWriter out; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //methods public static int gcd(int a, int b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? gcd(a % b, b) : gcd(a, b % a); } public static int lcm(int a, int b) { return a * b / gcd(a, b); } public static boolean isprime(long a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
874d849ebd6c31f753783f52650c640f
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class c1 { public static FScanner scan; public static PrintWriter out; public static void main(String[] args) { scan=new FScanner(); out=new PrintWriter(new BufferedOutputStream(System.out)); // int t=1; int t=scan.nextInt(); while(t-->0) { int n=scan.nextInt(); out.println((n-1)+" "+1); } out.close(); } //------------------------------------------------------------------------------------------------------------------ //scanner public static class FScanner { BufferedReader br; StringTokenizer st; public FScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
c1795d1d8c0bb314dd83b1d856f45736
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.PrintWriter; import java.util.Random; public class Problem { static class Erickde { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public Erickde() { in = new BufferedInputStream(System.in, BS); } public Erickde(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } public static void quicksort(int[] a) { if (a == null) return; quicksort(a, 0, a.length - 1); } private static void quicksort(int[] a, int lo, int hi) { if (lo < hi) { int splitPoint = partition(a, lo, hi); quicksort(a, lo, splitPoint); quicksort(a, splitPoint + 1, hi); } } private static final double EPS = 0.00000001; private static int partition(int[] a, int lo, int hi) { int pivot = a[lo]; int i = lo - 1, j = hi + 1; while (true) { do { i++; } while (a[i] < pivot); do { j--; } while (a[j] > pivot); if (i < j) swap(a, i, j); else return j; } } static int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } private static void swap(int[] ar, int i, int j) { int tmp = ar[i]; ar[i] = ar[j]; ar[j] = tmp; } static Random RANDOM = new Random(); static int randInt(int min, int max) { return RANDOM.nextInt((max - min) + 1) + min; } public static void main(String[] args) throws Exception { Erickde scan = new Erickde(); PrintWriter out = new PrintWriter(System.out); int t = scan.nextInt(); while (t-- > 0) { System.out.println("1 " + (scan.nextInt() - 1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
b75d0a2ef116f5109320b79154ecd41c
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.IOException; import java.io.*; import java.io.*; public class EhabAndGcd { public static void main(String[] args) throws IOException { Reader r = new Reader(); Writer w = new Writer(); int t = r.nextInt(); for (int i = 0; i < t; ++i) { int x = r.nextInt(); w.println("1 " + (x - 1)); } w.close(); } } /** * Custom class used for fast input. */ class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } /** * Custom class used for fast output. */ class Writer { private final BufferedWriter bw; public Writer() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
ab6c5d8e4b095a505ab8e67df37a9cd4
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public class rc{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t--!=0){ int n = sc.nextInt(); if(n==2) System.out.println(1+" "+1); else{ List<Integer> list = new ArrayList<>(); int m=n-1; for(int i=2; i<Math.sqrt(m); i++){ if(m%i==0){ while(m%i==0){ list.add(i); m/=i; } } } if(m!=1) list.add(m); //System.out.println(list); System.out.println(1+" "+((n-1))); } } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
fadbf86ca1b1d3624714cc88915dc68a
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
//package codechef; import java.util.*; public class output { // static int gcd(int a, int b) // { // // Everything divides 0 // if (a == 0) // return b; // if (b == 0) // return a; // // // base case // if (a == b) // return a; // // // a is greater // if (a > b) // return gcd(a-b, b); // return gcd(a, b-a); // } // // static int LCM(int a, int b) // { // // int op= (a*b)/gcd(a,b); // return op; // // } // public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int x=sc.nextInt(); if(x%2==0) { System.out.println(x/2 +" "+x/2); } else { System.out.println(1+" "+(x-1)); } } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
dcc2c33fc19154da45e8bcfdc20254e1
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class A { public static void main(String... args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); if (n % 2 == 0) { int a = n / 2; System.out.println(a + " " + a); } else { int b = n - 1; System.out.println(b + " " + 1); } } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
ad471f91104b8b3c2f6b552c7c10c710
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class A { public static void main(String... args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { System.out.println(s.nextInt()-1 + " " + 1); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
b4f8de2c0edc1c76439abf473876732d
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; /** * Built using CHelper plug-in * Actual solution is at the top */ public class A1 { public static void main(String[] args) throws IOException { OutputStream outputStream = System.out; Reader in = new Reader(); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in.nextInt(), in, out); out.close(); } static class TaskA { long mod = (long)(1000000007); public void solve(int testNumber, Reader in, PrintWriter out) throws IOException { while(testNumber-->0){ long n = in.nextLong(); if(n==2) out.println("1 1"); else if(n%2==0) out.println(2 + " " + (n-2l)); else out.println(1 + " " + (n-1l)); } } public void swap(int a[] , int p1 , int p2){ int x = a[p1]; a[p1] = a[p2]; a[p2] = x; } public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) { if (start > end) { return; } int mid = (start + end) / 2; a.add(mid); sortedArrayToBST(a, start, mid - 1); sortedArrayToBST(a, mid + 1, end); } class Combine{ int value; int delete; Combine(int val , int delete){ this.value = val; this.delete = delete; } } class Sort2 implements Comparator<Combine>{ public int compare(Combine a , Combine b){ if(a.value > b.value) return 1; else if(a.value == b.value && a.delete>b.delete) return 1; else if(a.value == b.value && a.delete == b.delete) return 0; return -1; } } public int lowerLastBound(ArrayList<Integer> a , int x){ int l = 0; int r = a.size()-1; if(a.get(l)>=x) return -1; if(a.get(r)<x) return r; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a.get(mid) == x && a.get(mid-1)<x) return mid-1; else if(a.get(mid)>=x) r = mid-1; else if(a.get(mid)<x && a.get(mid+1)>=x) return mid; else if(a.get(mid)<x && a.get(mid+1)<x) l = mid+1; } return mid; } public int upperFirstBound(ArrayList<Integer> a , Integer x){ int l = 0; int r = a.size()-1; if(a.get(l)>x) return l; if(a.get(r)<=x) return r+1; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a.get(mid) == x && a.get(mid+1)>x) return mid+1; else if(a.get(mid)<=x) l = mid+1; else if(a.get(mid)>x && a.get(mid-1)<=x) return mid; else if(a.get(mid)>x && a.get(mid-1)>x) r = mid-1; } return mid; } public int lowerLastBound(int a[] , int x){ int l = 0; int r = a.length-1; if(a[l]>=x) return -1; if(a[r]<x) return r; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a[mid] == x && a[mid-1]<x) return mid-1; else if(a[mid]>=x) r = mid-1; else if(a[mid]<x && a[mid+1]>=x) return mid; else if(a[mid]<x && a[mid+1]<x) l = mid+1; } return mid; } public int upperFirstBound(int a[] , int x){ int l = 0; int r = a.length-1; if(a[l]>x) return l; if(a[r]<=x) return r+1; int mid = -1; while(l<=r){ mid = (l+r)/2; if(a[mid] == x && a[mid+1]>x) return mid+1; else if(a[mid]<=x) l = mid+1; else if(a[mid]>x && a[mid-1]<=x) return mid; else if(a[mid]>x && a[mid-1]>x) r = mid-1; } return mid; } public long log(float number , int base){ return (long) Math.floor((Math.log(number) / Math.log(base))); } public long gcd(long a , long b){ if(a<b){ long c = b; b = a; a = c; } if(a%b==0) return b; return gcd(b , a%b); } public void print2d(long a[][] , PrintWriter out){ for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++) out.print(a[i][j] + " "); out.println(); } out.println(); } public void print1d(long a[] , PrintWriter out){ for(int i=0;i<a.length;i++) out.print(a[i] + " "); out.println(); out.println(); } } static class Reader{ final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader(){ din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String next() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do{ ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
be45fb9b724006e39eb93e15b8f51a37
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public final class common{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); System.out.println(1+" "+(n-1)); t--; } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
687d4c471e79526f88c027f6be9bd6a6
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
//package CodeForces; import java.util.Scanner; public class EhabAndGcd { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0) { int x=s.nextInt(); System.out.println(1+" "+(x-1)); t--; } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
e4e9ef70b1861ebc5a58953a2be5adb2
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class EhAb_AnD_GcD { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int a=sc.nextInt(); System.out.println(1+" "+(a-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
ab113bc02fd23fed6373559ca0b2a4f9
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; /** * * @author Saju * */ public class Main { private static int dx[] = { 1, 0, -1, 0 }; private static int dy[] = { 0, -1, 0, 1 }; private static final long INF = (long) Math.pow(10, 16); private static final int INT_INF = Integer.MAX_VALUE; private static final long NEG_INF = Long.MIN_VALUE; private static final int NEG_INT_INF = Integer.MIN_VALUE; private static final double EPSILON = 1e-10; private static final long MAX = (long) 1e12; private static final long MOD = 1000000007; private static final int MAXN = 300005; private static final int MAXA = 1000007; private static final int MAXLOG = 22; private static final double PI = Math.acos(-1); public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); // Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); // InputReader in = new InputReader(new FileInputStream("src/test.in")); // PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out"))); /* */ int test = in.nextInt(); for (int t = 1; t <= test; t++) { long x = in.nextLong(); if(x % 2 == 0 && x != 2) { out.println(2 + " " + (x - 2)); } else { out.println(1 + " " + (x - 1)); } } in.close(); out.flush(); out.close(); System.exit(0); } /* * return the number of elements in list that are less than or equal to the val */ private static long upperBound(List<Long> list, long val) { int start = 0; int len = list.size(); int end = len - 1; int mid = 0; while (true) { if (start > end) { break; } mid = (start + end) / 2; long v = list.get(mid); if (v == val) { start = mid; while(start < end) { mid = (start + end) / 2; if(list.get(mid) == val) { if(mid + 1 < len && list.get(mid + 1) == val) { start = mid + 1; } else { return mid + 1; } } else { end = mid - 1; } } return start + 1; } if (v > val) { end = mid - 1; } else { start = mid + 1; } } if (list.get(mid) < val) { return mid + 1; } return mid; } private static boolean isPalindrome(String str) { StringBuilder sb = new StringBuilder(); sb.append(str); String str1 = sb.reverse().toString(); return str.equals(str1); } private static String getBinaryStr(long n, int j) { String str = Long.toBinaryString(n); int k = str.length(); for (int i = 1; i <= j - k; i++) { str = "0" + str; } return str; } private static long modInverse(long r) { return bigMod(r, MOD - 2, MOD); } private static long bigMod(long n, long k, long m) { long ans = 1; while (k > 0) { if ((k & 1) == 1) { ans = (ans * n) % m; } n = (n * n) % m; k >>= 1; } return ans; } private static long ceil(long n, long x) { long div = n / x; if(div * x != n) { div++; } return div; } private static int ceil(int n, int x) { int div = n / x; if(div * x != n) { div++; } return div; } private static int abs(int x) { if (x < 0) { return -x; } return x; } private static double abs(double x) { if (x < 0) { return -x; } return x; } private static long abs(long x) { if(x < 0) { return -x; } return x; } private static long lcm(long a, long b) { return (a * b) / gcd(a, b); } private static int lcm(int a, int b) { return (a * b) / gcd(a, b); } private static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } private static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } private static int log(long x, int base) { return (int) (Math.log(x) / Math.log(base)); } private static int log(long x, long base) { return (int) (Math.log(x) / Math.log(base)); } private static long min(long a, long b) { if (a < b) { return a; } return b; } private static int min(int a, int b) { if (a < b) { return a; } return b; } private static long max(long a, long b) { if (a < b) { return b; } return a; } private static int max(int a, int b) { if (a < b) { return b; } return a; } private static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (IOException e) { return null; } return tokenizer.nextToken(); } public String nextLine() { String line = null; try { tokenizer = null; line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } public boolean hasNext() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (Exception e) { return false; } return true; } public int[] nextIntArr(int n) { int arr[] = new int[n]; for(int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArr(int n) { long arr[] = new long[n]; for(int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } public int[] nextIntArr1(int n) { int arr[] = new int[n + 1]; for(int i = 1; i <= n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArr1(int n) { long arr[] = new long[n + 1]; for(int i = 1; i <= n; i++) { arr[i] = nextLong(); } return arr; } public void close() { try { if(reader != null) { reader.close(); } } catch(Exception e) { } } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
e4b63c3d3064cec57b9649e2d48708d2
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t--!=0) { long n=in.nextLong(); n--; System.out.println("1 "+ n); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
f95985754f12cf49284c25cf23d22cce
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); while (t > 0) { t--; int x = in.nextInt(); out.println("1 " + (x - 1)); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
341b063a3029b1f20450f42c93914e75
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; import java.io.*; public class codeforces { public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while(T>0) { int N = Integer.parseInt(br.readLine()); System.out.println("1 "+(N-1)); T--; } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
a96a3468732ef6500b936b78e7b79f65
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class Ehab { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); System.out.println("1 "+(a-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
43e80ee642023b20f57b4c16bf5272c8
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class EhAbAndgCd { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t=scan.nextInt(); for(int j=0;j<t;j++) { int x=scan.nextInt(); int a=1; int b=x-a; System.out.println(a+" "+b); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
cc40403ae80d47bd49aee76c9ed4a6fe
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class A { public static void main(String[] args) { Scanner nik = new Scanner(System.in); int t = nik.nextInt(); while (t-- > 0) { int n = nik.nextInt(); int sr = (int) Math.sqrt(n); if (n % 2 == 0) { System.out.println(n / 2 + " " + n / 2); } else { System.out.println(1 + " " + (n - 1)); } } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
c90bb1be1495590f0ebdb207f28c3e35
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class main { public static void main(String[] args){ ///Look at my previous attempt of this code ,,, i am a complete idiot Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i=0;i<t;i++){ long x = in.nextLong(); System.out.println(1+" "+(x-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
6bceed5bed77f4e50166f7a09390670e
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; import java.util.Arrays; import java.util.*; public class Main { static int a[] = new int[200005]; public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); while(t != 0){ t--; int n = input.nextInt(); System.out.println(1 + " "+ (n-1)); } System.exit(0); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
1e53dab9cf265eb1c0054fb026e54c39
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class EhAbAnDgCd { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tt = sc.nextInt(); while (tt-- >0) { int n = sc.nextInt(); System.out.println("1 " + (n - 1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
19846ddd91a7d58110ea433acb47d1d2
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class A { private void work() { Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in), 1 << 16)); int nc = sc.nextInt(); while (nc-- > 0) { int x = sc.nextInt(); System.out.printf("%d %d\n", 1, x - 1); } sc.close(); } public static void main(String[] args) { new A().work(); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
c00782f13f3d9541bb0b7548963960ed
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class s { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for(int i = 0; i < n; i++) { int k = in.nextInt(); getNum(k); } } public static void getNum(int i) { i--; System.out.println(1 + " " + i); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
48e8d92b0ac2b9ae996b7c6d29ae8e4a
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public class Gcd1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=1;i<=t;i++) { int n = sc.nextInt(); System.out.println(n%2==0?(n/2)+" "+(n/2):1+" "+(n-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
9175218197ee8b9f16c58f66578acbe4
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.*; public class C628_PA { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); //System.out.println(gcd(4,14)); int t = in.nextInt(); while(t-->0) { int n = in.nextInt(); boolean go = true; int a1 = 0; int b1 = 0; for(int i =1;i<n;i++) { int lcm = n-i; if(go==false) break; if(i>Math.sqrt(lcm)) { break; } if(lcm%i==0) { //System.out.println(i+"_"+lcm); int product =lcm/i; for(int a =1;a<=Math.sqrt(product);a++) { if(product%a==0) { int b = product/a; if(gcd(a,b)==i&&lcm(a,b)==lcm) { a1 =a; b1 =b; go = false; break; } } } } } System.out.println(a1+" "+b1); } } public static int gcd(int a, int b) { if(b==0) return a; return gcd(b,a%b); } static int lcm(int a, int b) { return (a * b) / gcd(a, b); } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
2447e7b7ec8a8b9cc6dccb4819b1a831
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.util.Scanner; public class Math { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t =sc.nextInt(); while(t-->0) { int x = sc.nextInt(); x=x-1; System.out.println("1 "+x); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
156f54d18ed50f7de0c8e833d7cca03f
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.*; public class Main { public static void main(String[] args) throws IOException{ BufferedReader b1 = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(b1.readLine()); while(t-->0) { int x = Integer.parseInt(b1.readLine()); System.out.println("1" + " " + (x-1)); } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
416c1db9a3767a84f35b061c9787cf69
train_004.jsonl
1584196500
You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; import java.util.ArrayList; import java.util.HashMap; import java.util.Arrays; import java.util.HashSet; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Alice */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { Scanner str = new Scanner(System.in); int t = str.nextInt(); for(int i = 0; i < t; i++) { System.out.println("1 "+(str.nextInt()-1)); } } } }
Java
["2\n2\n14"]
1 second
["1 1\n6 4"]
NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.
Java 8
standard input
[ "constructive algorithms", "number theory", "greedy" ]
2fa3e88688b92c27ad26a23884e26009
The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.
800
For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.
standard output
PASSED
993c45e13fd636d8f89877498676928a
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class Solutione{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int a = input.nextInt(); int[] ar = new int[a]; int output = 0; for(int i = 0; i < a; i++){ ar[i] = input.nextInt(); if(ar[i] == 1) output += 2; } for (int i = 0; i < a - 1; i++) { if(ar[i] == ar[i + 1] && ar[i] == 1) output--; } if(output == 0) System.out.print(0); else System.out.print(output - 1); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
f0333461563798ae8c84da9c1d6638f9
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.math.BigInteger; import java.util.Arrays; import java.util.InputMismatchException; /** * * @author Pradyumn Agrawal coderbond007 */ public class Codeforces{ public static InputStream inputStream = System.in; public static OutputStream outputStream = System.out; public static FastReader in = new FastReader(inputStream); public static PrintWriter out = new PrintWriter(outputStream); public static void main(String[] args)throws java.lang.Exception { new Codeforces().run(); out.close(); } void run() throws java.lang.Exception { int n = ni(); int[] a = na(n); int ans = 0; int ind = 0; for(int i=n-1;i>=0;i--){ if(a[i] == 1){ ind = i; break; } } boolean flag = false; for(int i=0;i<=ind;i++) { if(a[i] == 1){ ans++; flag = true; } else if(a[i] == 0){ if(flag) { flag = false; ans++; } } } out.println(ans); } private static int ni(){ return in.nextInt(); } private static long nl(){ return in.nextLong(); } private static String ns(){ return in.nextString(); } private static char nc(){ return in.nextCharacter(); } private static double nd(){ return in.nextDouble(); } private static char[] ns(int n) { char[] a = new char[n]; for(int i=0;i<n;i++) a[i] = nc(); return a; } private static char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i=0;i<n;i++) map[i] = ns(m); return map; } private static int[] na(int n) { int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = ni(); return a; } private static long[] nal(int n) { long[] a = new long[n]; for(int i=0;i<n;i++) a[i] = nl(); return a; } } class FastReader{ private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastReader(InputStream stream){ this.stream = stream; } public int read(){ if (numChars == -1){ throw new InputMismatchException (); } if (curChar >= numChars){ curChar = 0; try{ numChars = stream.read (buf); } catch (IOException e){ throw new InputMismatchException (); } if (numChars <= 0){ return -1; } } return buf[curChar++]; } public int peek(){ if (numChars == -1){ return -1; } if (curChar >= numChars){ curChar = 0; try{ numChars = stream.read (buf); } catch (IOException e){ return -1; } if (numChars <= 0){ return -1; } } return buf[curChar]; } public int nextInt(){ int c = read (); while (isSpaceChar (c)) c = read (); int sgn = 1; if (c == '-'){ sgn = -1; c = read (); } int res = 0; do{ if(c==','){ c = read(); } if (c < '0' || c > '9'){ throw new InputMismatchException (); } res *= 10; res += c - '0'; c = read (); } while (!isSpaceChar (c)); return res * sgn; } public long nextLong(){ int c = read (); while (isSpaceChar (c)) c = read (); int sgn = 1; if (c == '-'){ sgn = -1; c = read (); } long res = 0; do{ if (c < '0' || c > '9'){ throw new InputMismatchException (); } res *= 10; res += c - '0'; c = read (); } while (!isSpaceChar (c)); return res * sgn; } public String nextString(){ int c = read (); while (isSpaceChar (c)) c = read (); StringBuilder res = new StringBuilder (); do{ res.appendCodePoint (c); c = read (); } while (!isSpaceChar (c)); return res.toString (); } public boolean isSpaceChar(int c){ if (filter != null){ return filter.isSpaceChar (c); } return isWhitespace (c); } public static boolean isWhitespace(int c){ return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0(){ StringBuilder buf = new StringBuilder (); int c = read (); while (c != '\n' && c != -1){ if (c != '\r'){ buf.appendCodePoint (c); } c = read (); } return buf.toString (); } public String nextLine(){ String s = readLine0 (); while (s.trim ().length () == 0) s = readLine0 (); return s; } public String nextLine(boolean ignoreEmptyLines){ if (ignoreEmptyLines){ return nextLine (); }else{ return readLine0 (); } } public BigInteger nextBigInteger(){ try{ return new BigInteger (nextString()); } catch (NumberFormatException e){ throw new InputMismatchException (); } } public char nextCharacter(){ int c = read (); while (isSpaceChar (c)) c = read (); return (char) c; } public double nextDouble(){ int c = read (); while (isSpaceChar (c)) c = read (); int sgn = 1; if (c == '-'){ sgn = -1; c = read (); } double res = 0; while (!isSpaceChar (c) && c != '.'){ if (c == 'e' || c == 'E'){ return res * Math.pow (10, nextInt ()); } if (c < '0' || c > '9'){ throw new InputMismatchException (); } res *= 10; res += c - '0'; c = read (); } if (c == '.'){ c = read (); double m = 1; while (!isSpaceChar (c)){ if (c == 'e' || c == 'E'){ return res * Math.pow (10, nextInt ()); } if (c < '0' || c > '9'){ throw new InputMismatchException (); } m /= 10; res += (c - '0') * m; c = read (); } } return res * sgn; } public boolean isExhausted(){ int value; while (isSpaceChar (value = peek ()) && value != -1) read (); return value == -1; } public String next(){ return nextString(); } public SpaceCharFilter getFilter(){ return filter; } public void setFilter(SpaceCharFilter filter){ this.filter = filter; } public interface SpaceCharFilter{ public boolean isSpaceChar(int ch); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
f8bc32d154425bf64dd90402d11e8557
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
/** * Created by HaMzA on 06/01/2017. */ import java.util.*; import java.io.*; import java.lang.*; public class Inbox { public static void main(String[] args)throws Exception{ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); PrintStream ps=new PrintStream(System.out); //System.out.print(-1%2); int n=Integer.parseInt(bf.readLine()); String tmp=bf.readLine(); String[] l=tmp.split(" "); int[] a=new int[n]; ArrayList<Integer> p=new ArrayList<Integer>(); int last=0; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(l[i]); if(a[i]==1) p.add(i); } int[] t=new int[p.size()]; int k=0; for(int f:p) t[k++]=f; int ans=p.size()>0?1:0; for(int i=1;i<p.size();i++){ if(t[i]-t[i-1]>1) ans+=2; else ans++; } //ans--; //assert ans==1; ps.print(ans>0?ans:0); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
df88c636daea75ec232047d3cba4b6c4
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class inbox{ public static void main(String []args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int i=0,q=0,j=0; for(i=0;i<n;i++){ a[i]=sc.nextInt(); /*if(a[i]==1&&j==0){ q=i; j=i; }*/} int p=0; int c=0; int s=0; for(i=0;i<n;i++){ if(a[i]==1){ // System.out.println(i); p=i; int t=p-q; if(t<=1||s==0) c++; else c+=2; q=i; s++; } } System.out.println(c);}}
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
b571a8159c9a4f5e5adc37436539ba81
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CF { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br.readLine(); String line = br.readLine().replaceAll("\\s", "").replaceAll("^0*", "").replaceAll("0*$", ""); line = line.replaceAll("(?<=1)0", "1"); int count = 0; Matcher m = Pattern.compile("1").matcher(line); while (m.find()) count++; System.out.println(count); br.close(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
33d62ab869684ee188e23aed5a747ae3
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class C { public static void main(String[] a) { Scanner s = new Scanner(System.in); s.nextLine(); System.out.print(s.nextLine().replaceAll(" |^(0 ?)*|(0 ?)*$","").replaceAll("(?<=1)0","1").replaceAll("0","").length()); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
34abba58cd1cfa8607ee4d704683ea1e
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
/* / フフ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム / )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Y (⠀⠀| ( ͡° ͜ʖ ͡°)⠀⌒(⠀ ノ (⠀ ノ⌒ Y ⌒ヽ-く __/ | _⠀。ノ| ノ。 |/ (⠀ー '_人`ー ノ ⠀|\  ̄ _人'彡ノ ⠀ )\⠀⠀ 。⠀⠀ / ⠀⠀(\⠀ #⠀ / ⠀/⠀⠀⠀/ὣ====================D- /⠀⠀⠀/⠀ \ \⠀⠀\ ( (⠀)⠀⠀⠀⠀ ) ).⠀) (⠀⠀)⠀⠀⠀⠀⠀( | / |⠀ /⠀⠀⠀⠀⠀⠀ | / [_] ⠀⠀⠀⠀⠀[___] */ // Main Code at the Bottom import java.util.*; import java.lang.*; import java.io.*; public class Main { //Fast IO class static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { boolean env=System.getProperty("ONLINE_JUDGE") != null; if(!env) { try { br=new BufferedReader(new FileReader("src\\input.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } else br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long MOD=1000000000+7; //Euclidean Algorithm static long gcd(long A,long B){ if(B==0) return A; return gcd(B,A%B); } //Modular Exponentiation static long fastExpo(long x,long n){ if(n==0) return 1; if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD; return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD; } //Prime Number Algorithm static boolean isPrime(long n){ if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false; return true; } //Reverse an array static <T> void reverse(T arr[],int l,int r){ Collections.reverse(Arrays.asList(arr).subList(l, r)); } //Print array static <T> void print1d(T arr[]) { out.println(Arrays.toString(arr)); } static <T> void print2d(T arr[][]) { for(T a[]: arr) out.println(Arrays.toString(a)); } // Pair static class pair{ long x,y; pair(long a,long b){ this.x=a; this.y=b; } public boolean equals(Object obj) { if(obj == null || obj.getClass()!= this.getClass()) return false; pair p = (pair) obj; return (this.x==p.x && this.y==p.y); } public int hashCode() { return Objects.hash(x,y); } } static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); //Main function(The main code starts from here) public static void main (String[] args) throws java.lang.Exception { int test=1; while(test-->0) { int n=sc.nextInt(); int a[]=new int[n],ans=0; for(int i=0;i<n;i++) a[i]=sc.nextInt(); for(int i=0;i<n;i++) { if(a[i]==1) ans++; int j=i+1; while(j<n && a[j]==0) j++; if(j==n) break; if(j-i!=1 && a[i]==1) ans+=1; i=j-1; } out.println(ans); } out.flush(); out.close(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
d6b4feee65d5d3b17bea0ec0df540478
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
//package codeforces; import java.util.Scanner; public class BB { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int list[]=new int[n]; int count = 0; for(int i = 0 ; i < n ;i++){ list[i] = in.nextInt(); if(list[i] == 1){ if(i > 1){ if(list[i-1] == 0 && count > 0) count+=2; else count++; } else count++; } } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
1c09a8621554415d06f3603fbffa7710
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.*; import java.util.*; public class Main { private static StringBuilder data = new StringBuilder(); private final static FastReader in = new FastReader(); public static void main(String[] args) { int n = in.inT(), t; int answ = 0, c = 0; boolean r = false, o = false; for (int i = 0; i < n; i++) { t = in.inT(); if (t == 0) { if (c > 0) { answ += (c - 1); c = 0; o=true; r=false; } } else { c++; if(!r){ if(o){ answ++; o=false; } answ++; r=true; } if (i == n - 1) { if (c > 0) { answ += (c - 1); c = 0; } } } } System.out.println(answ); } static void fileOut(String s) { File out = new File("output.txt"); try { FileWriter fw = new FileWriter(out); fw.write(s); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String path) { try { br = new BufferedReader(new InputStreamReader(new FileInputStream(path))); } catch (FileNotFoundException e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int inT() { return Integer.parseInt(next()); } long lonG() { return Long.parseLong(next()); } float floaT() { return Float.parseFloat(next()); } double doublE() { return Double.parseDouble(next()); } String line() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
85a18af5bea9b39edbea9d83763c3812
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; int ones = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); ones += a[i]; } int l = 0, r = n - 1; while (l < n && a[l] == 0) {l++;} while (r >= 0 && a[r] == 0) {r--;} int res = 0; while (l < r) { l++; if (a[l] == 0 && (l == 0 || a[l - 1] == 1)) {res++;} } System.out.println(res + ones); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
96c68c596ddbfb6dc054786897d9f77c
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Code14 { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class pair implements Comparable<pair> { Integer x, y; pair(int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { return x.compareTo(o.x); } } public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = in.nextInt(); int[] a = new int[n]; int count = 0; for(int i=0;i<n;i++) { a[i] = in.nextInt(); if(a[i]==1) count++; } int ans = 0; if(a[0]==1) ans = 1; int x = 0; if(a[0]==1) x = 1; for(int i=1;x<count;i++) { if(a[i-1]==1 && a[i]==0) ans+=1; else if(a[i-1]==0 && a[i]==1) { ans+=1; x++; } else if(a[i-1]==1 && a[i]==1) { ans+=1; x++; } //System.out.println(i); } pw.println(ans); pw.flush(); pw.close(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
8996fa122e6e536bae45d98d45582a1b
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class pre139 { public static void main(String args[]) { Scanner obj = new Scanner(System.in); int n = obj.nextInt(),arr[] = new int[n]; for(int i=0;i<n;i++) arr[i] = obj.nextInt(); int count = 0; boolean flag = false,first = true; for(int i=0;i<n;i++) { if(arr[i]==1 && first) {count++;first = false; flag = true;continue;} if(arr[i]==1 && !flag && !first) { count += 2; flag = true; } else if(arr[i]==1 && flag && !first) count++; else flag = false; } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
b7a821460e7e36a6a68da1d91b561b99
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; /** * * @author kiyarash */ public class Email { public static void main(String[] args) { Scanner s = new Scanner(System.in); int moves = 0; int n = s.nextInt(); int[] array = new int[n]; // reading data for(int i =0 ; i<n ; i++ ){ array[i] = s.nextInt(); } int ind = 0; for(int i = 0; i<n ;){ int counter = 0 ; while( ind<n && ( array[ind] != 0 || (ind+1<n && array[ind+1] != 0 && ind!=0 && array[ind-1] != 0 ) ) ){ counter++; ind++; } if(counter == 0) ind++; else moves += counter-1 + 2; i = ind; } if(moves !=0) moves -=1; System.out.print(moves); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
b4e38b051977d2148657f68214c4484f
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
/** * Created by qicodeng on 11/22/16. */ import java.io.*; import java.util.StringTokenizer; public class Codeforces_round_265_div_2_Inbox { public static void main(String[] args) { FScanner input = new FScanner(); out = new PrintWriter(new BufferedOutputStream(System.out), true); int[] array = new int[input.nextInt()]; for (int i = 0; i < array.length; i++) { array[i] = input.nextInt(); } int total = 0; for (int i = 0; i < array.length; i++) { if (array[i] == 1) { int count = 1; i++; while (i < array.length) { if (array[i] == 1) { i++; count++; } else { break; } } total += count + 1; } } out.println(total == 0 ? 0 : total - 1); out.close(); } public static PrintWriter out; public static class FScanner { BufferedReader br; StringTokenizer st; public FScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } private String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
5bed69b36ca011391208c30acb4bf5b2
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.math.*; import java.util.*; public class BruteForce { public static Scanner in =new Scanner(System.in); public static BigInteger getN(String x){ StringBuilder build=new StringBuilder(x); x=build.reverse().toString(); BigInteger sum=new BigInteger("0"); for(int i=0;i<x.length();i++){ int c=Integer.parseInt(x.charAt(i)+""); int s=(int)(Math.pow(2,i)*c); BigInteger cur=new BigInteger(s+""); sum=sum.add(cur); } return sum; } public static String getB(int n){ String x=""; while(n > 0) { int a = n % 2; x = a + x; n = n / 2; } return x; } public static void main(String[] args){ ArrayList<Integer> list=new ArrayList<Integer>(); int n=in.nextInt(); int[]z=new int[n]; for(int i=0;i<n;i++) z[i]=in.nextInt(); for(int i=0;i<n;i++) if(z[i]==1) list.add(i); int c=0; if(list.size()==1) c=1; else if(list.size()==0) c=0; else{ for(int i=0;i<list.size()-1;i++){ int cur=list.get(i); int next=list.get(i+1); if(next-cur<=2){ int dif=next-cur; c+=dif; } else c+=2; } c++; } System.out.println(c); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
336ad7de230f7057e54a6401f1de0250
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.regex.*; import java.util.stream.LongStream; public class Main{ //public static ArrayList a[]=new ArrayList[3000001]; public static void main(String[] args) { InputReader in=new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n=in.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=in.nextInt(); boolean chk=false; int cnt=0; int ans=0; for(int i=0;i<n;i++) { if(a[i]==1) { cnt++; continue; } if(cnt>0) { ans+=(cnt+1); cnt=0; } } if(cnt>0) ans+=cnt; else ans--; pw.println(Math.max(0, ans)); pw.flush(); pw.close(); } private static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } static class tri implements Comparable<tri> { int p, c, l; tri(int p, int c, int l) { this.p = p; this.c = c; this.l = l; } public int compareTo(tri o) { return Integer.compare(l, o.l); } } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static long mod = 1000000007; public static int d; public static int p; public static int q; public static int[] suffle(int[] a,Random gen) { int n = a.length; for(int i=0;i<n;i++) { int ind = gen.nextInt(n-i)+i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static void swap(int a, int b){ int temp = a; a = b; b = temp; } /* public static long primeFactorization(long n) { HashSet<Integer> a =new HashSet<Integer>(); long cnt=0; for(int i=2;i*i<=n;i++) { while(a%i==0) { a.add(i); a/=i; } } if(a!=1) cnt++; //a.add(n); return cnt; }*/ public static void sieve(boolean[] isPrime,int n) { for(int i=1;i<n;i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for(int i=2;i*i<n;i++) { if(isPrime[i] == true) { for(int j=(2*i);j<n;j+=i) isPrime[j] = false; } } } public static int GCD(int a,int b) { if(b==0) return a; else return GCD(b,a%b); } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static void extendedEuclid(int A,int B) { if(B==0) { d = A; p = 1 ; q = 0; } else { extendedEuclid(B, A%B); int temp = p; p = q; q = temp - (A/B)*q; } } public static long LCM(long a,long b) { return (a*b)/GCD(a,b); } public static int LCM(int a,int b) { return (a*b)/GCD(a,b); } public static int binaryExponentiation(int x,int n) { int result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static long binaryExponentiation(long x,long n) { long result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static int modularExponentiation(int x,int n,int M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x%M*x)%M; n=n/2; } return result; } public static long modularExponentiation(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result%M * x%M)%M; x=(x%M * x%M)%M; n=n/2; } return result; } public static long modInverse(int A,int M) { return modularExponentiation(A,M-2,M); } public static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) { if (n%i == 0 || n%(i+2) == 0) return false; } return true; } public static long[] shuffle(long[] a, Random gen){ for(int i = 0, n = a.length;i < n;i++){ int ind = gen.nextInt(n-i)+i; long d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } static class pair implements Comparable<pair>{ Integer x; Integer y; pair(int x,int w){ this.x=x; this.y=w; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } public String toString(){ return (x+" "+y); } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
9c90897588d09bd376acf7a6d811aafe
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n = input.nextInt(); int[] array = new int[n]; boolean done = true; boolean last = false; for (int i = 0; i < n; i++) { array[i] = input.nextInt(); if (array[i] == 1) { done = false; if (i == n - 1) { last = true; } } } if (done) { System.out.println(0); } else { int c = 0; boolean list = true; int pos = 0; while (pos < n) { if (array[pos] == 1) { if (list) { c++; list = false; } if (pos < n - 1) { if (array[pos + 1] == 1) { c++; } else { c++; list = true; } } } pos++; } if (!last) { c--; } System.out.println(c); } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
1508c8504d1e1f03466a16d614045d4f
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; import java.io.*; //267630EY public class Main465B { static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=sc.nextIntArray(n); int count=0; boolean flag=true; for(int i=0;i<n;i++) { if(a[i]==1) { if(flag) { count++; flag=true; } else { count+=2; flag=true; } } else { if(count!=0) flag=false; } } out.println(count); out.flush(); } static class Scanner { BufferedReader br; StringTokenizer tk=new StringTokenizer(""); public Scanner(InputStream is) { br=new BufferedReader(new InputStreamReader(is)); } public int nextInt() throws IOException { if(tk.hasMoreTokens()) return Integer.parseInt(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextInt(); } public long nextLong() throws IOException { if(tk.hasMoreTokens()) return Long.parseLong(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextLong(); } public String next() throws IOException { if(tk.hasMoreTokens()) return (tk.nextToken()); tk=new StringTokenizer(br.readLine()); return next(); } public String nextLine() throws IOException { tk=new StringTokenizer(""); return br.readLine(); } public double nextDouble() throws IOException { if(tk.hasMoreTokens()) return Double.parseDouble(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextDouble(); } public char nextChar() throws IOException { if(tk.hasMoreTokens()) return (tk.nextToken().charAt(0)); tk=new StringTokenizer(br.readLine()); return nextChar(); } public int[] nextIntArray(int n) throws IOException { int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=nextInt(); return a; } public long[] nextLongArray(int n) throws IOException { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } public int[] nextIntArrayOneBased(int n) throws IOException { int a[]=new int[n+1]; for(int i=1;i<=n;i++) a[i]=nextInt(); return a; } public long[] nextLongArrayOneBased(int n) throws IOException { long a[]=new long[n+1]; for(int i=1;i<=n;i++) a[i]=nextLong(); return a; } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
8350d28612dcdb6d06ce29618cd30ec1
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = new int[n]; boolean contOne = false; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); if (a[i] == 1) contOne = true; } if (contOne) { int count = 0; boolean first = false; for (int i = 0; i < n; i++) { if (a[i] == 1) { if (!first) { count++; first = true; } else count += 2; int pos = i + 1; while (pos < n && a[pos] == 1) { count++; pos++; } i = pos; } } out.println(count); } else out.println(0); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
855497232d06b7fd8d6edf266d2977bd
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.*; import java.util.*; public class HackerCup1 { public static void main(String[] args) throws Throwable { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); ArrayList<Integer> arr = new ArrayList<Integer>(); StringTokenizer st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { int x = Integer.parseInt(st.nextToken()); if(x==1) arr.add(i); } int ans = 0; int ind = -1; for (int i = 0; i < arr.size(); i++) { if(ind==-1) { ans ++; ind = arr.get(i); } else { if(arr.get(i)!=ind+1) ans ++; ans++; ind = arr.get(i); } } System.out.println(ans); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
c2bc081d69421fb965e3e7e62cdc1421
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { int n; int ones=0; int operation=0; Scanner sc=new Scanner(System.in); n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); if (arr[i]==1) ones++; } for (int i=0;i<n-1;i++){ if (arr[i]==1){ operation++; ones--; if (ones>0 && arr[i+1]==0){ operation++; } } } if (arr[n-1]==1){ operation++; } System.out.println(operation); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
4e25fe063db8226b171e90a9b0cdba7a
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class Inbox{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for (int i=0;i<n;i++) { arr[i]=sc.nextInt(); } int count=0; int occ=0; for (int i=0;i<n;i++) { if(arr[i]==1){ occ=i; break; } } int flag=occ-1; for (int i=occ;i<n;i++) { if(arr[i]==1){ count++; if(flag!=(i-1)) count++; flag=i; } } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
ef484433cbb5ae609e215433bd04370d
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class Inbox{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; for (int i=0;i<n;i++) { arr[i]=sc.nextInt(); } int count=0; for (int i=0;i<n;i++) { int j=0; } int occ=0; for (int i=0;i<n;i++) { if(arr[i]==1){ occ=i; break; } } int flag=occ-1; for (int i=occ;i<n;i++) { if(arr[i]==1){ count++; if(flag!=(i-1)) count++; flag=i; } } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
46a9dea191cb3641432fe85436f758ad
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class readLetter{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=(int)sc.nextInt(); sc.nextLine(); int arr[]=new int[n]; int count=0; int tmp=0; boolean read=false; boolean flag=false;//on 0s for(int i = 0;i <n;i++){ tmp=sc.nextInt(); if(flag==false){ if(tmp==1){ read=true; count++; flag=true; } } else{//on1 if(tmp==0){ flag=false; count++; }else{ count++; } } //System.out.println("reading:"+tmp+",count:"+count); } if(tmp==0&&read==true){count--;} System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
60433268f822092aaacc1ab689faaa25
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; public class Main { public static void main(String[] args) throws IOException { // BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //(new FileReader("input.in")); // StringBuilder out = new StringBuilder(); // StringTokenizer tk; // Scanner s = new Scanner(System.in); // tk = new StringTokenizer(in.readLine()); Reader.init(System.in); int n = Reader.nextInt(),N=0,v=0; int[]a = new int[n]; for (int i = 0; i < n; i++) { a[i]=Reader.nextInt(); if(a[i]>N){ N=1; v=i; } } if(N==0){System.out.println("0");System.exit(0);} int c=0; boolean T = false; for (int i = v; i < n; i++) { if(a[i]==1){ c++; T=true; } else if(a[i]==0&&T&&i!=n-1&&a[i+1]==1){ c++; T=false; } } System.out.println(c); } } class Reader { static StringTokenizer tokenizer; static BufferedReader reader; public static void init(InputStream input) throws UnsupportedEncodingException { reader = new BufferedReader(new InputStreamReader(input, "UTF-8")); tokenizer = new StringTokenizer(""); } public static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static String nextLine() throws IOException { return reader.readLine(); } public static int nextInt() throws IOException { return Integer.parseInt(next()); } public static double nextDouble() throws IOException { return Double.parseDouble(next()); } public static long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
56a70e9e62892ec71bdfdc4dc9ae8b1d
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner scan = new Scanner(System.in); int n=scan.nextInt(); int[] arr=new int[n]; for (int i = 0; i <n ; i++) { arr[i]=scan.nextInt(); } int ans=0; for (int i = 0; i <n ; i++) { if (arr[i]==1){ ans++; for (int j = i+1; j <n ; j++) { if (arr[j]==1){ ans++; }else if (j!=n-1&&arr[j+1]==1){ ans+=2; j++; }else {break;} i=j; } ans++; } } System.out.println(ans==0?ans:ans-1); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
b336fd82611d8231eac099d755f84066
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; /** * Created by User on 15.02.2017. */ public class Inbox { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] a = new int[n]; int sum1 = 0; for (int i = 0; i < n; i++) { a[i] = scanner.nextInt(); if (a[i] == 1) sum1++; } int count = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { if (i != n - 1) count++; if (i != n - 1) { while (a[i + 1] == 1) { if (i == n - 2) break; i++; } } else { if (n != 1 && a[i - 1] == 0 && a[i] == 1) count++; } } } if (count != 0) System.out.println(count-1+sum1); else System.out.println(sum1); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
7f858b054889755099251790f19377b7
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int mails[] = new int[n]; for(int i=0; i<n; i++) mails[i]= sc.nextInt(); int counter = 0; boolean list = true; /*int before = mails[0]; if(before == 1) { list = false; counter++; }*/ int before = 1; for(int i=0; i<mails.length; i++) { if(mails[i]==1) { if(list == true) { counter+=1; list = false; } else { if(before==0) counter+=2; else counter+=1; } } before = mails[i]; } System.out.println(counter); sc.close(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
bc9b9f663483ec5c97291b1df5c94305
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int mails[] = new int[n]; for(int i=0; i<n; i++) mails[i]= sc.nextInt(); int counter = 0; boolean list = true; int before = 1; /*int before = mails[0]; if(before == 1) { list = false; counter++; }*/ for(int i=0; i<mails.length; i++) { if(mails[i]==1) { if(list == true) { counter+=1; list = false; } else { if(before==0) counter+=2; else counter+=1; } } before = mails[i]; } System.out.println(counter); sc.close(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
c1b2bbf346ef5e4e37324e551fd64f0d
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int mails[] = new int[n]; for(int i=0; i<n; i++) mails[i]= sc.nextInt(); // int res = count(mails, 0, false); /*int counter = 0; int before = mails[0]==0 ? 0:1; if(before==1) counter++; for(int i=1; i<mails.length-1; i++) { if(mails[i]==0 && mails[i+1]!=0) // if(mails[i]==0) { if(before==1) counter++; } else counter++; before = mails[i]; } if(mails[mails.length-1]==1) counter++;*/ int counter = 0; boolean list = true; int before = mails[0]; if(before == 1) { list = false; counter++; } for(int i=1; i<mails.length; i++) { if(mails[i]==1) { if(list == true) { counter+=1; list = false; } else { if(before==0) counter+=2; else counter+=1; } } before = mails[i]; } System.out.println(counter); sc.close(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
2751a2c20ed77d8e7a94929e37ea0992
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { // 0 1 0 1 0 // next; // 1 1 0 0 1 // back to inbox; // 1 1 1 0 0 // next // 0 1 1 1 0// next // 1 0 0 0 1 back to inbox // 1 1 1 1 1 next ; // 0 1 1 1 1 1 // 1 1 0 1 1 1 // 0 1 1 1 0 1 1 1 0 0 1 1 1 // 1 0 0 0 1 Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int count = 0; int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = scanner.nextInt(); } int i = 0; for (i = 0; i < array.length; i++) { if (array[i] == 1) { break; } } for (; i < array.length; i++) { if (array[i] == 1 || (i != array.length - 1 && array[i] == 0 && array[i + 1] == 1)) { count++; } } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
b4d0ef823b0bd737fd87b27e0a363c8b
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox100500 { //SolverToBe //Mohammad Abulawi public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt();//number of letters int[] arr = new int[n];//list of letters int ones = 0;//number of ones for (int i = 0; i < arr.length; i++) {//input the list arr[i] = in.nextInt(); if (arr[i]==1) {//check if it is = 1 ones++; } } int count = 0;//number of operations needed for (int i = 0; i <arr.length-1; i++) { if (arr[i]==1) { ones--; if (ones>0) { count += 2; if (arr[i+1]==1) { count--; } } else { count++;//for last unread letter } } } if (arr[n-1]==1) { //for last index count++; } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
714da14acad36ff297750227f54b1055
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox100500 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int[] arr=new int[n]; int ones=0; for(int i=0;i<arr.length;i++){ arr[i]=in.nextInt(); if(arr[i]==1) ones++; } int count=0; for(int i=0;i<arr.length-1;i++){ if(arr[i]==1){ ones--; if(ones>0){ count+=2; if(arr[i+1]==1) count--; } else count++; } } if(arr[n-1]==1) count++; System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
72b344214a7e1faf7a4ffc82fa79b815
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox100500 { //SolverToBe //Mohammad Abulawi public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; int ones = 0; for (int i = 0; i < arr.length; i++) { arr[i] = in.nextInt(); if (arr[i]==1) { ones++; } } int count = 0; for (int i = 0; i <arr.length-1; i++) { if (arr[i]==1) { ones--; if (ones>0) { count += 2; if (arr[i+1]==1) { count--; } } else { count++;//for last unread letter } } } if (arr[n-1]==1) { //for last index count++; } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
93b2156e52eab1033d075737b996b643
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; import java.io.*; import java.math.BigDecimal; public class Main { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int a=sc.nextInt(); int i=0; int it=0; int last=-1; for(i=0;i<a;i++) { int lol=sc.nextInt(); if(lol==1) { if(last==-1){it=1;last=i;} else { it+=Math.min(i-last, 2);last=i;} } } System.out.println(it); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
d1f099d657361445142f6a4ad6452f2e
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * @author khokharnikunj8 */ public class Main { public static void main(String[] args) throws Exception { Thread thread = new Thread(null, new TaskAdapter(), "khokharnikunj8", 1 << 27); thread.start(); thread.join(); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput(inputStream); FastOutput out = new FastOutput(outputStream); BInbox100500 solver = new BInbox100500(); solver.solve(1, in, out); out.close(); } } static class BInbox100500 { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.readInt(); int[] ar = new int[n]; for (int i = 0; i < n; i++) ar[i] = in.readInt(); int last = -1; int ans = 0; for (int i = 0; i < n; i++) { if (ar[i] == 1) { if (last == -1) { ans++; } else { if (last == i - 1) ans++; else ans += 2; } last = i; } } out.println(ans); } } static class FastInput { private final InputStream is; private final byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastInput(InputStream is) { this.is = is; } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { bufLen = -1; } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public int readInt() { int sign = 1; skipBlank(); if (next == '+' || next == '-') { sign = next == '+' ? 1 : -1; next = read(); } int val = 0; if (sign == 1) { while (next >= '0' && next <= '9') { val = val * 10 + next - '0'; next = read(); } } else { while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } } return val; } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private final Writer os; private final StringBuilder cache = new StringBuilder(1 << 20); public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } public FastOutput append(char c) { cache.append(c); return this; } public FastOutput append(int c) { cache.append(c); return this; } public FastOutput println(int c) { return append(c).println(); } public FastOutput println() { cache.append(System.lineSeparator()); return this; } public FastOutput flush() { try { os.append(cache); os.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
9f306a1a4c342e5364fb786d28628ef6
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; import java.io.*; import java.awt.Point; import java.math.BigDecimal; import java.math.BigInteger; import static java.lang.Math.*; // Solution is at the bottom of code public class B implements Runnable{ final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; OutputWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args){ new Thread(null, new B(), "", 128 * (1L << 20)).start(); } ///////////////////////////////////////////////////////////////////// void init() throws FileNotFoundException{ Locale.setDefault(Locale.US); if (ONLINE_JUDGE){ in = new BufferedReader(new InputStreamReader(System.in)); out = new OutputWriter(System.out); }else{ in = new BufferedReader(new FileReader("input.txt")); out = new OutputWriter("output.txt"); } } //////////////////////////////////////////////////////////////// long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } void debug(Object... objects){ if (ONLINE_JUDGE){ for (Object o: objects){ System.err.println(o.toString()); } } } ///////////////////////////////////////////////////////////////////// public void run(){ try{ timeBegin = System.currentTimeMillis(); Locale.setDefault(Locale.US); init(); solve(); out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } ///////////////////////////////////////////////////////////////////// String delim = " "; String readString() throws IOException{ while(!tok.hasMoreTokens()){ try{ tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null; } } return tok.nextToken(delim); } String readLine() throws IOException{ return in.readLine(); } ///////////////////////////////////////////////////////////////// final char NOT_A_SYMBOL = '\0'; char readChar() throws IOException{ int intValue = in.read(); if (intValue == -1){ return NOT_A_SYMBOL; } return (char) intValue; } char[] readCharArray() throws IOException{ return readLine().toCharArray(); } ///////////////////////////////////////////////////////////////// int readInt() throws IOException { return Integer.parseInt(readString()); } int[] readIntArray(int size) throws IOException { int[] array = new int[size]; for (int index = 0; index < size; ++index){ array[index] = readInt(); } return array; } int[] readSortedIntArray(int size) throws IOException { Integer[] array = new Integer[size]; for (int index = 0; index < size; ++index) { array[index] = readInt(); } Arrays.sort(array); int[] sortedArray = new int[size]; for (int index = 0; index < size; ++index) { sortedArray[index] = array[index]; } return sortedArray; } int[] readIntArrayWithDecrease(int size) throws IOException { int[] array = readIntArray(size); for (int i = 0; i < size; ++i) { array[i]--; } return array; } /////////////////////////////////////////////////////////////////// int[][] readIntMatrix(int rowsCount, int columnsCount) throws IOException { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArray(columnsCount); } return matrix; } int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) throws IOException { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArrayWithDecrease(columnsCount); } return matrix; } /////////////////////////////////////////////////////////////////// long readLong() throws IOException{ return Long.parseLong(readString()); } long[] readLongArray(int size) throws IOException{ long[] array = new long[size]; for (int index = 0; index < size; ++index){ array[index] = readLong(); } return array; } //////////////////////////////////////////////////////////////////// double readDouble() throws IOException{ return Double.parseDouble(readString()); } double[] readDoubleArray(int size) throws IOException{ double[] array = new double[size]; for (int index = 0; index < size; ++index){ array[index] = readDouble(); } return array; } //////////////////////////////////////////////////////////////////// BigInteger readBigInteger() throws IOException { return new BigInteger(readString()); } BigDecimal readBigDecimal() throws IOException { return new BigDecimal(readString()); } ///////////////////////////////////////////////////////////////////// Point readPoint() throws IOException{ int x = readInt(); int y = readInt(); return new Point(x, y); } Point[] readPointArray(int size) throws IOException{ Point[] array = new Point[size]; for (int index = 0; index < size; ++index){ array[index] = readPoint(); } return array; } ///////////////////////////////////////////////////////////////////// List<Integer>[] readGraph(int vertexNumber, int edgeNumber) throws IOException{ @SuppressWarnings("unchecked") List<Integer>[] graph = new List[vertexNumber]; for (int index = 0; index < vertexNumber; ++index){ graph[index] = new ArrayList<Integer>(); } while (edgeNumber-- > 0){ int from = readInt() - 1; int to = readInt() - 1; graph[from].add(to); graph[to].add(from); } return graph; } ///////////////////////////////////////////////////////////////////// static class IntIndexPair { static Comparator<IntIndexPair> increaseComparator = new Comparator<IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return value1 - value2; int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; static Comparator<IntIndexPair> decreaseComparator = new Comparator<IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return -(value1 - value2); int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; int value, index; public IntIndexPair(int value, int index) { super(); this.value = value; this.index = index; } public int getRealIndex() { return index + 1; } } IntIndexPair[] readIntIndexArray(int size) throws IOException { IntIndexPair[] array = new IntIndexPair[size]; for (int index = 0; index < size; ++index) { array[index] = new IntIndexPair(readInt(), index); } return array; } ///////////////////////////////////////////////////////////////////// static class OutputWriter extends PrintWriter { final int DEFAULT_PRECISION = 12; protected int precision; protected String format, formatWithSpace; { precision = DEFAULT_PRECISION; format = createFormat(precision); formatWithSpace = format + " "; } public OutputWriter(OutputStream out) { super(out); } public OutputWriter(String fileName) throws FileNotFoundException { super(fileName); } public int getPrecision() { return precision; } public void setPrecision(int precision) { precision = max(0, precision); this.precision = precision; format = createFormat(precision); formatWithSpace = format + " "; } private String createFormat(int precision){ return "%." + precision + "f"; } @Override public void print(double d){ printf(format, d); } public void printWithSpace(double d){ printf(formatWithSpace, d); } public void printAll(double...d){ for (int i = 0; i < d.length - 1; ++i){ printWithSpace(d[i]); } print(d[d.length - 1]); } @Override public void println(double d){ printlnAll(d); } public void printlnAll(double... d){ printAll(d); println(); } } ///////////////////////////////////////////////////////////////////// static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; static final int[][] steps8 = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, 1}, {1, -1}, {-1, 1} }; static final boolean check(int index, int lim){ return (0 <= index && index < lim); } ///////////////////////////////////////////////////////////////////// static final boolean checkBit(int mask, int bit){ return (mask & (1 << bit)) != 0; } ///////////////////////////////////////////////////////////////////// static final long getSum(int[] array) { long sum = 0; for (int value: array) { sum += value; } return sum; } static final Point getMinMax(int[] array) { int min = array[0]; int max = array[0]; for (int index = 0, size = array.length; index < size; ++index, ++index) { int value = array[index]; if (index == size - 1) { min = min(min, value); max = max(max, value); } else { int otherValue = array[index + 1]; if (value <= otherValue) { min = min(min, value); max = max(max, otherValue); } else { min = min(min, otherValue); max = max(max, value); } } } return new Point(min, max); } ///////////////////////////////////////////////////////////////////// final static int READ = 0, UNREAD = 1; void solve() throws IOException { int lettersCount = readInt(); int[] states = readIntArray(lettersCount); int segmentsCount = 0; boolean isOpen = false; int unreadCount = 0; for (int i = 0; i < lettersCount; ++i) { if (states[i] == UNREAD) { isOpen = true; ++unreadCount; } if (i == lettersCount - 1 || states[i] == READ) { if (isOpen) ++segmentsCount; isOpen = false; } } int answer = unreadCount + max(0, segmentsCount - 1); out.println(answer); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
4f747bc886419e892327829f0a486ed9
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox100500 { //SolverToBe //Mohammad Abulawi public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt();//number of letters int[] arr = new int[n];//list of letters int ones = 0;//number of ones for (int i = 0; i < arr.length; i++) {//input the list arr[i] = in.nextInt(); if (arr[i]==1) {//check if it is = 1 ones++; } } int count = 0;//number of operations needed for (int i = 0; i <arr.length-1; i++) { if (arr[i]==1) { ones--; if (ones>0) { count += 2; if (arr[i+1]==1) { count--; } } else { count++;//for last unread letter } } } if (arr[n-1]==1) { //for last index count++; } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
41ef53a4fc56d5c14290ce1af3c93e24
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class index{ public static void main(String[]args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int ones=0; int [] arr = new int[n]; for (int i=0; i<arr.length ; i++){ arr[i]= in.nextInt(); if(arr[i]==1){ ones++; } } int count =0; for (int i=0; i< arr.length-1;i++){ if (arr[i]==1){ ones--; if(ones>0){ count+=2; if(arr[i+1]==1){ count--; } }else{ count++; } } } if(arr[n-1]==1){ count++; } System.out.println(count); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
e6ea24c44b869fa1d594296ead638dd3
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()), lst = 0, crr = 0, cnt= 0, moves = 0; //int[] arr = new int[n]; st = new StringTokenizer(br.readLine()); for(int i=0; i<n; i++) { int lttr = Integer.parseInt(st.nextToken()); if(lttr == 1) { cnt++; crr = i; if(cnt == 1) moves++; else moves += crr - lst > 1? 2:1; lst = crr; } } System.out.println(moves); } static double getDistanceBetweenTwoPoints(int x1, int y1, int x2, int y2){ return Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2)); } static int[] countLetterFreqeuncy(String str){ int[] ltrs = new int[26]; for(int i=0; i<str.length(); i++) ltrs[(int) (str.charAt(i) - 'A')]++; return ltrs; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a*b)/ gcd(a, b); } // Arrays.sort(arr, new Comparator<Integer[]>() { // @Override // //arguments to this method represent the arrays to be sorted // public int compare(Integer[] arr1, Integer[] arr2) { // //get the item ids which are at index 0 of the array // Integer item1 = arr1[0]; // Integer item2 = arr2[0]; // // sort based on price // return item1.compareTo(item2); // } // }); //String.join("", Collections.nCopies(n-1, ""); //sort the String ArrayList (ignore the case) //Collections.sort(swStrArr, String.CASE_INSENSITIVE_ORDER); static int binarySearch(int left, int right, int find, int[] arr){ int mid = left + (right-left)/2; if(find == arr[mid]) return mid; else if(find < arr[mid]) return binarySearch(left,mid-1,find,arr); else return binarySearch(mid+1,right,find,arr); } static ArrayList<Integer> separateDigits(int num){ int pow = 0; ArrayList<Integer> arr = new ArrayList<>(); while(num != 0) { if(num % 10 != 0) { arr.add((num % 10) * (int) Math.pow(10, pow)); } num /= 10; pow++; } return arr; } //Find pattern using multiplication // static int countNumOfPattern(char[][] matrix) // { // //based on the size of pattern, nxm // int cnt = 0; // for(int i = 0; i<matrix.length; i++) // { // for(int j = 0; j<matrix[0].length; j++) // { // if(matrix[i][j] * matrix[i+1][j] * matrix[i][j+1] * matrix[i+1][j+1] == "The pattern") // cnt++; // } // } // } //Kadane’s Algorithm - find maximum subarray static int findMaxSubSum(int[] arr) { int crrMax = 0, fnlMax = 0; for(int i=0; i<arr.length; i++) { crrMax = Math.max(arr[i], arr[i] + crrMax); fnlMax = Math.max(crrMax, fnlMax); } return fnlMax; } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
46d1713ae04f216ff156cd68b996969a
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[1005]; int m = 0; for (int i = 1; i <= n; i++) { int k = sc.nextInt(); if (k == 1) { a[++m] = i; } } int ans = 0; boolean[] t = new boolean[m + 1]; for (int i = 1; i < m; i++) { if (a[i] == a[i + 1] - 1) { ans++; } else if (a[i + 1] - a[i] >= 2) { ans += 2; } } System.out.println(a[1] == 0 ? 0 : ans + 1); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
dbee8992597d4cae24c7139787a0ca65
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; import java.util.Locale; import java.util.StringTokenizer; public class r_265_b { static BufferedReader in; static PrintWriter out; static StringTokenizer st; public static void main(String[] args)throws IOException { Locale.setDefault(Locale.US); in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); //gfile(); int n=nextInt(); int a[]=new int[n+1]; for (int i = 1; i <=n; i++) { a[i]=nextInt(); } boolean used[]=new boolean[n+1]; int ans=0,i=1; while(i<=n){ if(a[i]==1){ if(!used[i]){ ans++; used[i]=true; } a[i]=0; for (int j = i+1; j <=n; j++) { if(a[j]==1){ if(j-i<=2){ if(!used[j]){ ans+=j-i; used[j]=true; } i=j; break; } else{ if(!used[j]){ ans+=2; used[j]=true; } i=j; break; } } } } else i++; } out.print(ans); out.close(); } private static void gfile() throws IOException{ in=new BufferedReader(new FileReader(new File("bureau.in"))); out=new PrintWriter(new BufferedWriter(new FileWriter("bureau.out"))); } private static long nextLong()throws IOException { return Long.parseLong(next()); } private static double nextDouble()throws IOException { return Double.parseDouble(next()); } private static int nextInt()throws IOException { return Integer.parseInt(next()); } private static String next()throws IOException{ while(st==null||!st.hasMoreTokens()) st=new StringTokenizer(in.readLine()); return st.nextToken(); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
2ffdf455726253e38c3d7c0b1b1bacc2
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox_100500 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int moves = 0; int state = -1; int tmp; for (int i = 0; i < n; i++) { tmp = sc.nextInt(); if (state == -1 && tmp == 1) { state = tmp; } if (state != -1) { if (tmp == 1) { if (state == 0) { moves++; } state = 1; moves++; } else if (tmp == 0) { state = 0; } } } System.out.println(moves); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
ea4f0d74d65e3594e73de86d033111a3
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.Scanner; public class Inbox_100500 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int moves = 0; int state = -1; int tmp; for (int i = 0; i < n; i++) { tmp = sc.nextInt(); if (state == -1 && tmp == 1) { state = tmp; } if (state != -1) { if (tmp == 1) { if (state == 0) { moves++; } state = 1; moves++; } else if (tmp == 0) { state = 0; } } } System.out.println(moves); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output
PASSED
6298d24f3cb180c989d90cf510177d00
train_004.jsonl
1410103800
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import static java.lang.Math.*; public class Main implements Runnable { void solve() throws Exception { int n = sc.nextInt(); int count = 1; int a[] = new int[10001]; for(int i = 1; i <= n; i++){ a[i] = sc.nextInt(); } for(int i = 1; i < n; i++){ if(a[i] == 1){ if(a[i+1] == 1) count++; else count+=2; } } if(a[n] != 1) count-=2; if(count < 0) count = 0; out.print(count); } BufferedReader in; PrintWriter out; FastScanner sc; static Throwable throwable; public static void main(String[] args) throws Throwable { Thread thread = new Thread(null, new Main(), "", (1 << 26)); thread.start(); thread.join(); thread.run(); if (throwable != null) throw throwable; } public void run() { try { //in = new BufferedReader(new FileReader(".in")); //out = new PrintWriter(new FileWriter(".out")); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new FastScanner(in); solve(); } catch (Exception e) { throwable = e; } finally { out.close(); } } } class FastScanner { BufferedReader reader; StringTokenizer strTok; FastScanner(BufferedReader reader) { this.reader = reader; } public String nextToken() throws Exception { while (strTok == null || !strTok.hasMoreTokens()) strTok = new StringTokenizer(reader.readLine()); return strTok.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
Java
["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0"]
1 second
["3", "4", "0"]
NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.
Java 8
standard input
[ "implementation" ]
0fbc306d919d7ffc3cb02239cb9c2ab0
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.
1,000
Print a single number — the minimum number of operations needed to make all the letters read.
standard output