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
sequencelengths
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
b46c8692c1795a32393cc049828a985d
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class teams { public static void main(String[]args) throws NumberFormatException, IOException{ BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); ArrayList<Integer> a=new ArrayList<Integer>(); int counter=0; for (int i = 0; i < n; i++) { StringTokenizer str=new StringTokenizer(br.readLine()); for (int j = 0; j < 3; j++) { int y=Integer.parseInt(str.nextToken()); if (y==1) { a.add(y); } } if (a.size()>1) { counter++; } a.clear(); } System.out.println(counter); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
449b92f39997e17b6b4f69349a5b92c2
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Team { public static void main (String[]args) throws NumberFormatException, IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int a [] = new int [n]; int count = 0 ; for (int i = 0; i < n; i++) { StringTokenizer str = new StringTokenizer(br.readLine()); for (int j = 0; j < 3; j++) { a[i]+=Integer.parseInt(str.nextToken()); if(a[i] == 2){ count++; break; } } } System.out.println(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
5a8de31ea426257d808794db54dc10c3
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
//231A import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int P, V, T, res = 0; // if (n >= 1 && n <= 100){ while (n > 0) { P = input.nextInt(); V = input.nextInt(); T = input.nextInt(); if ((P == 0 || P == 1 )&& (V == 0 || V == 1) && (T == 0 || T == 1)){ if (P == 1 && V == 1) { res++; } else if (P == 1 && T == 1){ res++; } else if (V == 1 && T == 1){ res++; } n--; } } System.out.println(res); } } //}
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
d94776c76f0f186b9790e10726f7c70f
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.*; import java.util.*; public class Problem_231A { static public void main(String[] args) throws java.lang.Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(in.readLine()); int res = 0; for(int i = 0; i < N; i++){ String[] temp = in.readLine().split(" "); int sum = 0; for(int j = 0; j < 3; j++){ sum += Integer.parseInt(temp[j]); } if(sum >= 2){ res += 1; } } System.out.println(res); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
1261ffb0ee398ad9c691e491c61b9913
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { public static void main(String args[]){ int a,counter=0; Team t = new Team(); Scanner in = new Scanner(System.in); a=in.nextInt(); int k[][]=new int[a][3]; for(int i=0;i<a;i++) for(int j=0;j<3;j++) k[i][j]=in.nextInt(); for(int i=0;i<a;i++) if((t.Compare(k[i][0],k[i][1]))||(t.Compare(k[i][0],k[i][2]))||t.Compare(k[i][1],k[i][2])) counter++; System.out.println(counter); } public boolean Compare(int a,int b){ if(a==0&&b==0) return false; if(a==1&&b==0) return false; if(a==0&&b==1) return false; if(a==1&&b==1) return true; return true; } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
6380f25d2f610d2c7c1498077d858254
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n =in.nextInt(); int problemSolved=0; for(int i=1;i<=n;i++){ if(in.nextInt()+in.nextInt()+in.nextInt()>=2){ problemSolved++; } } System.out.println(problemSolved); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
810b3c6017e6512685cc2ac6afbe0f1b
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int [] toCheck = new int [3]; int result = 0; int sum = 0; for(int p = 0; p < n; p++){ for(int i = 0; i < 3; i++) { toCheck[i] = in.nextInt(); sum = sum + toCheck[i]; } if(sum >= 2){ result++; } sum = 0; } System.out.println(result); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
f1402fc9b41caa3290b1fd3efdba00af
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /* * some cheeky quote */ public class Main { FastScanner in; PrintWriter out; public void solve() throws IOException { int test = in.nextInt(); int count = 0; while (test-- > 0) { int sum = in.nextInt() + in.nextInt() + in.nextInt(); if (sum >= 2) { count++; } } System.out.println(count); } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { new Main().run(); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
29afbc67bbb08f2782677098d0f375bc
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Team { public static void main(String arg[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numberProblems = Integer.parseInt(br.readLine()); int count = 0; int attempt = 0; while (numberProblems != 0) { count = 0; String sure = br.readLine(); while (sure.contains("1")) { count++; sure = sure.substring(sure.indexOf("1") + 1); } if (count >= 2) { attempt++; } numberProblems--; } System.out.println(attempt); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
c3970f03525897f2434ab05f636cdbe6
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { public static void main(String[] args) { Scanner teclado = new Scanner(System.in); int num,i,j,total=0; num = teclado.nextInt(); teclado.nextLine(); String[] problemas = new String[num]; int[] soluciones = new int[num]; for(i=0;i<num;i++){ problemas[i] = teclado.nextLine(); String[] s = problemas[i].split(" "); for(j=0;j<3;j++){ soluciones[i] = Integer.valueOf(s[0])+Integer.valueOf(s[1])+Integer.valueOf(s[2]); } } for(i=0;i<num;i++){ if (soluciones[i]>=2){ total+=1; } } System.out.println(total); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
0c2e787cacfd883d43fe0736bf15b7b0
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package Day131215; import java.util.Scanner; /** * * @author Saksham Rastogi */ public class ATeam { public static void main(String args[]) { int count=0; int cames=0; Scanner inp=new Scanner(System.in); String n1=inp.nextLine(); int n=new Integer(n1); int [][]a=new int[1000][3]; for(int i=0;i<n;i++) { String c=inp.nextLine(); String s[]=c.split(" "); for(int j=0;j<3;j++) { a[i][j]=new Integer(s[j]); } } for(int i=0;i<n;i=i+1) { for(int j=0;j<3;j++) { if(a[i][j]==1) { count++; } } if(count>=2) { cames++; } count=0; } System.out.println(cames); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
5854f909698cd065c1ccfe61a9213fa0
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package Day131215; import java.util.Scanner; /** * * @author Saksham Rastogi */ public class ATeam { public static void main(String args[]) { int count=0; int games=0; Scanner inp=new Scanner(System.in); String n1=inp.nextLine(); int n=new Integer(n1); int [][]a=new int[1000][3]; for(int i=0;i<n;i++) { String c=inp.nextLine(); String s[]=c.split(" "); for(int j=0;j<3;j++) { a[i][j]=new Integer(s[j]); } } for(int i=0;i<n;i=i+1) { for(int j=0;j<3;j++) { if(a[i][j]==1) { count++; } } if(count>=2) { games++; } count=0; } System.out.println(games); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
474cbdef4d1be8b2a617d65a7e1d8847
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.*; public class Team { public static void main(String[] args) { Team t = new Team(); t.go(); } public void go() { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); int answer = 0; for (int i = 0; i < n; i++) { int c = 0; String[] s = in.nextLine().split("\\s"); for (String st : s) if (st.equals("1")) c++; if (c > 1) answer++; } System.out.println(answer); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
08a87122d6d997ab8477e112d3d0e15d
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.*; public class team { public static void main(String args[])throws IOException { int a,b,c,i,n,flag=0,count=0; char ch; String p; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); n=Integer.parseInt(br.readLine()); for(i=1;i<=n;i++) { p=br.readLine(); ch=p.charAt(0); a=(int)ch-48; if(a==1) flag++; ch=p.charAt(2); b=(int)ch-48; if(b==1) flag++; ch=p.charAt(4); c=(int)ch-48; if(c==1) flag++; if(flag>=2) count++; flag=0; } System.out.println(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
a3e8f5f3c1a32414b7d47523170483f8
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; /** * * @author kai */ public class JavaApplication2 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a1 = new int[n * 3]; int counter = 0; int c = 0; int j=0; for (int i = 0; i < n * 3; i++) { a1[i] = in.nextInt(); } for (int i = 0; i < n*3; i++) { counter += a1[i]; j=i+1; if (j % 3 == 0) { if (counter >= 2) { c++; } counter=0; } } System.out.println(c); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
5b2af77c61dfed1c040356837fcdcd4e
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class CodeForces { static Scanner scanner = new Scanner(System.in); public static boolean sureSolution (){ int x = 0; for (int i = 0; i < 3; i++) { int y = scanner.nextInt(); if (y == 1) x++; } if (x >= 2 ) return true; return false; } public static void main(String[] args) { int n = scanner.nextInt(); int x = 0; for (int i = 0; i < n; i++) { if(sureSolution()) x++; } System.out.println(x); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
662e772fc12de7dd1ee822ddb34707f2
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
public class Main { public static void main(String[] args) throws java.io.IOException{ java.util.Scanner sc = new java.util.Scanner(new java.io.BufferedInputStream(System.in)); int p=sc.nextInt(); int s=0; for(int i=0;i<=p;i++) { String team=sc.nextLine(); if(team.contains("1 1")||team.contains("1 0 1")) { s +=1; } } System.out.println(s); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
a081216035577c3076e300387aa23c75
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
public class Main { public static void main(String[] args) throws java.io.IOException{ java.util.Scanner sc = new java.util.Scanner(new java.io.BufferedInputStream(System.in)); int p=sc.nextInt(); int s=0; for(int i=0;i<=p;i++) { String team=sc.nextLine(); if(team.contains("1 1")||team.contains("1 0 1")) { s +=1; } } System.out.println(s); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
345e4ffd3217e2b61816a0b9f2a09eb4
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
public class Main { public static void main(String[] args) throws java.io.IOException{ java.util.Scanner sc = new java.util.Scanner(new java.io.BufferedInputStream(System.in)); int p=sc.nextInt(); int s=0; for(int i=0;i<=p;i++) { String team=sc.nextLine(); if(team.contains("1 1")||team.contains("1 0 1")) { s +=1; } } System.out.println(s); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
219fdd428b88393455675a6c835cf408
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int c = Integer.parseInt(sc.nextLine()); int u = 0; for (int i = 0; i < c; i++) { String l = sc.nextLine(); int o = 0; if (l.charAt(0) == '1') { o++; } if (l.charAt(2) == '1') { o++; } if (l.charAt(4) == '1') { o++; } if (o >= 2) { u++; } } System.out.println(u); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
fdc41f6cd1d0378c1f31b763abe7ed25
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { static Scanner sc= new Scanner(System.in); public static void main(String args []){ int n =sc.nextInt(); int x,y,z,k=0; for(int i=0;i<n;i++){ x=sc.nextInt(2); y=sc.nextInt(2); z=sc.nextInt(2); if(x+y+z>1) k++; } System.out.println(k); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
9775e41a8acaf94ba75241e8051b3c5d
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int inCount = in.nextInt(); int tNum = 0; int p = 0; int q = 0; int c = 0; int d = 0; for (int i = 0; i < inCount; i++) { p = 0; q = in.nextInt(); if (q > 0) p++; c = in.nextInt(); if (c > 0) p++; d = in.nextInt(); if (d > 0) p++; if (p >= 2) tNum++; } out.println(tNum); out.flush(); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
5f6da54ce69d000b3dbf5cc8c34fd2f4
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner input=new Scanner(System.in); int m=input.nextInt(); int mat[][]= new int[1000][3]; int count=0; for(int i=0;i<m;i++) { int sum=0; for(int j=0;j<3;j++) { mat[i][j]=input.nextInt(); if(mat[i][j]==1) { sum++; } } if(sum>=2) { count++; } } System.out.print(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
af6eeca0141f9f7ca246fdcbf16ad03c
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; /** ** Created by Alik on 10/21/2015. */ public class Problem_231A { public static void main(String args[]){ Scanner in = new Scanner(System.in); int number = in.nextInt(); int first, second, third; int count = 0; for (int i = 0; i < number; i++){ first = in.nextInt(); second = in.nextInt(); third = in.nextInt(); if((first==1 && second==1) || (second==1 && third==1) || (first==1 && third==1)) count++; } System.out.println(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
9509fdf266323f932911dbe3c7eb5c1d
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; /** ** Created by Alik on 10/21/2015. */ public class Problem_231A { public static void main(String args[]){ Scanner in = new Scanner(System.in); int number = in.nextInt(); int first, second, third; int count = 0; for (int i = 0; i < number; i++){ first = in.nextInt(); second = in.nextInt(); third = in.nextInt(); if((first==1 && second==1) || (second==1 && third==1) || (first==1 && third==1)) count++; } System.out.print(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
0fad50f2989c45d1c3d807e8f397e9fb
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { public static void main(String[] args) { Scanner input = new Scanner(System.in); int problems = input.nextInt(); int membersValue [][] = new int[problems][3]; int count = 0; int sum = 0; // the sum of memberValue to each problem for (int i = 0; i < problems; i++) { for (int j = 0; j < 3; j++) { membersValue [i][j] = input.nextInt(); sum += membersValue[i][j]; } if (sum >= 2) count++; sum = 0; } System.out.println(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
7d30245b9d6b44211d88654d78df5fd4
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team { public static void main(String[] args) { Scanner input = new Scanner(System.in); int problems = input.nextInt(); int membersValue [][] = new int[problems][3]; int count = 0; int sum = 0; // the sum of memberValue to each problem for (int i = 0; i < problems; i++) { for (int j = 0; j < 3; j++) { membersValue [i][j] = input.nextInt(); sum += membersValue[i][j]; } if (sum >= 2) count++; sum = 0; } System.out.println(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
e737d558c938d7ca9cb325bc57383c9c
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { int a,b,c,d,flag=0; Scanner s= new Scanner(System.in); int n=s.nextInt(); for(int i=0;i<n;i++) { a=s.nextInt(); b=s.nextInt(); c=s.nextInt(); d=a+b+c; if((d==2)||(d==3)) { flag++; } } System.out.print(flag); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
0d9d367f511514fc846c51bde56ddf3f
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { int a,b,c,d,flag=0; Scanner s= new Scanner(System.in); int n=s.nextInt(); for(int i=0;i<n;i++) { a=s.nextInt(); b=s.nextInt(); c=s.nextInt(); d=a+b+c; if((d==2)||(d==3)) { flag++; } } System.out.print(flag); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
ef068c133e51549be727039dddd067ef
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Rounds { public static void main(String args []){ Scanner rr=new Scanner(System.in); int k=rr.nextInt(); int l=0; int s=0; for(int i=0;i<k;i++){ int a=rr.nextInt(); int b=rr.nextInt(); int c=rr.nextInt(); l++; if(a+b+c<2){ s++; } } System.out.println(l-s); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
49ac2dac00c74535b43ed256fe780111
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class A231 { public static void main(String args[]){ Scanner in = new Scanner(System.in); int count,total=0; int n = in.nextInt(); for(int i = 0; i < n; i++){ count=0; for(int j = 0; j<3;j++){ if(in.nextInt()==1) count++; } if(count>1) total++; } System.out.println(total); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
250fa532e0862dbf86bf573c35ef5a4f
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class A231 { public static void main(String args[]){ Scanner in = new Scanner(System.in); int total=0; int n = in.nextInt(); for(int i = 0; i < n; i++){ if((in.nextInt()+in.nextInt()+in.nextInt())>1) total++; } System.out.println(total); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
dcf32c7f6e07304debf1601bab1af095
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Problem_231A { public static void main(String[] arge) { new Problem_231A().run(); } void run() { IntReader intReader = new IntReader(System.in); int n = intReader.nextInt(); int solvedCount = 0; for (int i = 0; i < n; i++) { if (intReader.nextInt() + intReader.nextInt() + intReader.nextInt() >= 2) solvedCount++; } System.out.println(solvedCount); } class IntReader { BufferedReader br = null; StringTokenizer st = null; public IntReader(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { if (st == null || !st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
3e0431bab5c1168eaca2847ddb3ec6a3
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class Problem_231A { public static void main(String[] arge) { try (Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));) { int n = scan.nextInt(); int solvedCount = 0; for (int i = 0; i < n; i++) { if (scan.nextByte() + scan.nextByte() + scan.nextByte() >= 2) solvedCount++; } System.out.println(solvedCount); } catch (Exception e) { e.printStackTrace(); } } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
33f2ceda6161426e0af1b3f12b8c0822
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class Problem_231A { public static void main(String[] arge) { try (Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));) { int n = scan.nextInt(); int solvedCount = 0; int ansOfPetya = 0; int ansOfVasya = 0; int ansOfTonya = 0; for (int i = 0; i < n; i++) { ansOfPetya = scan.nextInt(); ansOfVasya = scan.nextInt(); ansOfTonya = scan.nextInt(); if (ansOfPetya + ansOfVasya + ansOfTonya >= 2) solvedCount++; } System.out.println(solvedCount); } catch (Exception e) { e.printStackTrace(); } } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
c07f51f812f5d1ac74bd5fd80ea6b91f
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class HelloWorld{ public static void main(String []args){ int a,b,c,d,sum=0; Scanner scann = new Scanner(System.in); a = scann.nextInt(); for(int i = 0; i < a; i++) { b = scann.nextInt(); c = scann.nextInt(); d = scann.nextInt(); if((b+c+d) > 1) { sum++; } } System.out.println(sum); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
02ad8d59dcf769f89731825207d5dbe8
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Team231A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int count=0; for (int i=0; i<n; i++) { int tot = s.nextInt() + s.nextInt() + s.nextInt(); if (tot >= 2) count ++; } System.out.println(count); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
dbb9063e1e98e2163dac07f20de58fc4
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(), sum = 0, counter = 0; while (t-- > 0) { sum = sc.nextInt() + sc.nextInt() + sc.nextInt(); if(sum > 1) counter++; } System.out.println(counter); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
3685b43067ef9cda4236089218264ac1
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.*; public class team { /** * @param args */ private static Scanner in; public static void main(String[] args) { // TODO Auto-generated method stub int[] a=new int[3]; int n,count,op=0; in=new Scanner(System.in); n=in.nextInt(); for(int i=0;i<n;i++) { count=0; for (int j = 0; j < a.length; j++) { a[j]=in.nextInt(); if(a[j]==1) count++; } if(count>=2) op++; } System.out.println(op); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
d5fb5fdbe3b311aea6280e8347575a52
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.*; public class A { public static void main(String[] arg) { Scanner sc = new Scanner(System.in); int n = sc.nextInt();sc.nextLine(); int c= 0; for (int i = 0; i < n; i++) { if (sc.nextLine().matches(".*1.*1.*")) c++; } System.out.println(c); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
b29079958bca38c50a55811d65a596de
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.io.*; import java.util.Scanner; /** * Created by Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½ on 23.08.2014. */ public class HelloWorld { public static void main(String args[]){ //Scanner in = new Scanner(new File("input.txt")); //PrintWriter out = new PrintWriter(new File("output.txt")); Scanner in = new Scanner(System.in); int n = in.nextInt(); int ans = 0; for(int i = 0; i < n; i++){ int cur = 0; for(int j = 0; j < 3; j++){ cur += in.nextInt(); } if(cur >= 2) ans++; } System.out.println(ans); } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
cdcf9462ff69974bb678a90a06694cbe
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class sample { public static void main(String[] args) { int i,e=0; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if(0<n && n<1001) {int a[]=new int[n]; int b[]=new int[n]; int c[]=new int[n]; int d[]=new int[n]; for(i=0; i<n;i++) { a[i] = sc.nextInt(); b[i] = sc.nextInt(); c[i] = sc.nextInt(); d[i] = a[i]+b[i]+c[i]; if(d[i]>1) ++e; } System.out.println(e); } } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
77ebdb9850e4929f59a90334ae0abf91
train_000.jsonl
1349623800
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
256 megabytes
import java.util.Scanner; public class codeforces_team { public static void main(String args[]) { int pro_no,output,count=0,n; int i,j; Scanner s1=new Scanner(System.in); pro_no=s1.nextInt(); n=pro_no; int input[][]=new int[pro_no][3]; if((pro_no>=1)&&(pro_no<=1000)) { for(i=0;i<pro_no;i++) { for(j=0;j<3;j++) { input[i][j]=s1.nextInt(); } } for(i=0;i<pro_no;i++) { for(j=0;j<3;j++) { if(input[i][j]==0) { count++; } if(count>=2) { n--; break; } } count=0; } System.out.println(n); } } }
Java
["3\n1 1 0\n1 1 1\n1 0 0", "2\n1 0 0\n0 1 1"]
2 seconds
["2", "1"]
NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
Java 7
standard input
[ "greedy", "brute force" ]
3542adc74a41ccfd72008faf983ffab5
The first input line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
800
Print a single integer β€” the number of problems the friends will implement on the contest.
standard output
PASSED
952097d378cb4a9d9e70f643b1fd82d6
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; public class E14B { static StringTokenizer st; static BufferedReader br; static PrintWriter pw; static char[] c = {'A', 'A', 'o', 'o', 'U', 'U', 'b', 'd', 'I', 'I', 'T', 'T', 'M', 'M', 'H', 'H', 'O', 'O', 'p', 'q', 'V', 'V', 'v', 'v', 'X', 'X', 'x', 'x', 'W', 'W', 'w', 'w', 'Y', 'Y'}; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); char[] s = next().toCharArray(); boolean b = true; for (int i = 0; i <= s.length / 2; ++i) { if (!check(s[i], s[s.length - i - 1])) b = false; } pw.println((b) ? "TAK" : "NIE"); pw.close(); } private static boolean check(char d, char e) { for (int i = 0; i < c.length; ++i) { if (c[i] == d) { if (i % 2 == 0) { if (e == c[i + 1]) return true; } else { if (e == c[i - 1]) return true; } } } return false; } private static int sumf(int[] fen, int id) { int summ = 0; for (; id >= 0; id = (id & (id + 1)) - 1) summ += fen[id]; return summ; } private static void addf(int[] fen, int id) { for (; id < fen.length; id |= id + 1) fen[id]++; } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } private static String next() throws IOException { while (st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
ba345b8202d522c5399fa265c379a381
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.*; //PrintWriter import java.math.*; //BigInteger, BigDecimal import java.util.*; //StringTokenizer, ArrayList public class Ed_2016_R14_B { FastReader in; PrintWriter out; public static void main(String[] args) { new Ed_2016_R14_B().run(); } void run() { in = new FastReader(System.in); out = new PrintWriter(System.out); solve(); out.close(); } void solve() { String s = in.next(); boolean pal = true; int n = s.length(); String mirror = "AHIMOoTUVvWwXxY"; for (int i = 0; i < n/2; i++) { char c1 = s.charAt(i); char c2 = s.charAt(n-1-i); if ((mirror.contains(c1+"") && c1 == c2) || c1 == 'b' && c2 == 'd' || c1 == 'd' && c2 == 'b' || c1 == 'p' && c2 == 'q' || c1 == 'q' && c2 == 'p') {} else pal = false; } if (n%2 == 1) { char c = s.charAt(n/2); if (!mirror.contains(c + "")) pal = false; } out.println(pal ? "TAK" : "NIE"); } //----------------------------------------------------- void runWithFiles() { in = new FastReader(new File("input.txt")); try { out = new PrintWriter(new File("output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } solve(); out.close(); } class FastReader { BufferedReader br; StringTokenizer tokenizer; public FastReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public FastReader(File f) { try { br = new BufferedReader(new FileReader(f)); tokenizer = null; } catch (FileNotFoundException e) { e.printStackTrace(); } } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) try { tokenizer = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } return tokenizer.nextToken(); } public String nextLine() { try { return br.readLine(); } catch(Exception e) { throw(new RuntimeException()); } } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(next()); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
48553cf2fe4c48f680b55ec66554c698
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class S_palindrome { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int x = 0; String s1 = ""; String s2 = ""; boolean flag = true; if(s.length() == 1){ x = 0 ; s1 = s.charAt(0)+""; s2 = s1; }else if(s.length() %2 ==1){ x = (s.length())/2; s1 = s.substring(0, x); s2 = s.substring(x+1,s.length()); }else{ x = (s.length())/2; s1 = s.substring(0, x); s2 = s.substring(x,s.length()); } if(s.length()%2 == 1) { char c = s.charAt(x); if(c != 'H' && c != 'I' && c != 'A' && c != 'M' &&c != 'o' && c != 'O' && c != 'x' && c != 'X' && c != 'T' &&c != 'U' &&c != 'V' && c != 'v' && c != 'W' &&c != 'w' && c != 'Y'){ flag = false; } } if(flag) for (int i = 0; i < s1.length(); i++) { if(s1.charAt(i) == s2.charAt(s1.length()-i-1)) { char c = s1.charAt(i); if(c != 'H' && c != 'I' && c != 'A' && c != 'M' &&c != 'o' && c != 'O' && c != 'x' && c != 'X' && c != 'T' &&c != 'U' &&c != 'V' && c != 'v' && c != 'W' &&c != 'w' && c != 'Y'){ flag = false; break; } }else{ char c1 = s1.charAt(i); char c2 = s2.charAt(s1.length()-i-1); if((c1 == 'b' && c2 == 'd') ||(c2 == 'b' && c1 == 'd') ||(c1 == 'n' && c2 == 'u')||(c1 == 'u' && c2 == 'n')|| (c1 == 'p' && c2 == 'q')||(c1 == 'q' && c2 == 'p')) continue; else { flag = false; break; } } } if(flag) System.out.println("TAK"); else System.out.println("NIE"); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
7e2ed850a826f86db6624543cbf8b413
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class S_palindrome { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int x = 0; String s1 = ""; String s2 = ""; boolean flag = true; if(s.length() == 1){ x = 0 ; s1 = s.charAt(0)+""; s2 = s1; }else if(s.length() %2 ==1){ x = (s.length())/2; s1 = s.substring(0, x); s2 = s.substring(x+1,s.length()); }else{ x = (s.length())/2; s1 = s.substring(0, x); s2 = s.substring(x,s.length()); } if(s.length()%2 == 1) { char c = s.charAt(x); if(c != 'H' && c != 'I' && c != 'A' && c != 'M' &&c != 'o' && c != 'O' && c != 'x' && c != 'X' && c != 'T' &&c != 'U' &&c != 'V' && c != 'v' && c != 'W' &&c != 'w' && c != 'Y'){ flag = false; } } if(flag) for (int i = 0; i < s1.length(); i++) { if(s1.charAt(i) == s2.charAt(s1.length()-i-1)) { char c = s1.charAt(i); if(c != 'H' && c != 'I' && c != 'A' && c != 'M' &&c != 'o' && c != 'O' && c != 'x' && c != 'X' && c != 'T' &&c != 'U' &&c != 'V' && c != 'v' && c != 'W' &&c != 'w' && c != 'Y'){ flag = false; break; } }else{ char c1 = s1.charAt(i); char c2 = s2.charAt(s1.length()-i-1); if((c1 == 'b' && c2 == 'd') ||(c2 == 'b' && c1 == 'd') ||(c1 == 'n' && c2 == 'u')||(c1 == 'u' && c2 == 'n')|| (c1 == 'p' && c2 == 'q')||(c1 == 'q' && c2 == 'p')) continue; else { flag = false; break; } } } if(flag) System.out.println("TAK"); else System.out.println("NIE"); // } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
6b3a39b3589414b3ac901a86f87ea621
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.InputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.IOException; import java.math.BigInteger; import java.util.*; import java.util.stream.Stream; /** * * @author Pradyumn Agrawal coderbond007 */ public class Codeforces{ public static InputStream inputStream = System.in; public static FastReader in = new FastReader(inputStream); public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args)throws java.lang.Exception { new Codeforces().run(); out.close(); } void run() throws java.lang.Exception { String mirr = "AHIMOTUVWXYovwx"; String pq = "bdpq"; String qp = "dbqp"; String s = ns(); for(int i=0,j=s.length() - 1;i<=j;i++,j--){ char c = s.charAt(i); int ind = mirr.indexOf(c); if(ind >= 0 && s.charAt(j) == c){ continue; } ind = pq.indexOf(c); if(ind >= 0 && qp.indexOf(s.charAt(j)) == ind){ continue; } out.println("NIE"); return; } out.println("TAK"); } 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; } //private void tr(Object... o) { if(o.length() > 0)System.out.println(Arrays.deepToString(o)); } } 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
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
ed47e273ad7821f972c873a138079933
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.InputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.IOException; import java.math.BigInteger; import java.util.*; import java.util.stream.Stream; /** * * @author Pradyumn Agrawal coderbond007 */ public class Codeforces{ public static InputStream inputStream = System.in; public static FastReader in = new FastReader(inputStream); public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static void main(String[] args)throws java.lang.Exception { new Codeforces().run(); out.close(); } void run() throws java.lang.Exception { String mirr = "AHIMOTUVWXYovwx"; String pq = "bdpq"; String qp = "dbqp"; char[] s = ns().toCharArray(); int n = s.length; for(int i=0,j=n-1;i<j;i++,j--){ if(mirr.indexOf(s[i]) != mirr.indexOf(s[j]) && mirr.indexOf(s[i]) != -1){ out.println("NIE"); return; } else if(pq.indexOf(s[i]) != qp.indexOf(s[j]) && pq.indexOf(s[i]) != -1){ out.println("NIE"); return; } else if(mirr.indexOf(s[i]) == -1 && pq.indexOf(s[i]) == -1){ out.println("NIE"); return; } } if(n%2 != 0){ if(mirr.indexOf(s[n/2]) != -1){ out.println("TAK"); } else { out.println("NIE"); } } else { out.println("TAK"); } } 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; } //private void tr(Object... o) { if(o.length() > 0)System.out.println(Arrays.deepToString(o)); } } 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
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
31db7c26bcd7a9cd42e83d6e2b72dd31
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /* JAVA JAVA JAVA JAVAJAVAJAVAJAVA JAVA JAVAJAVAJAVAJAVA JAVAJAVAJAVA JAVAJAVAJAVAJAVAJAVAJAVAJAVA JAVA JAVA JAVA JAVAJAVA JAVA JAVA JAVA JAVA */ 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(); int testCount = 1; for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class TaskA { String s1 = "AIMHOWVUTXxovYwbdpq", s2 = "AIMHOWVUTXxovYwdbqp"; char[] rev; public void solve(int testNumber, InputReader in, PrintWriter out) { String s = in.next(); int ans = 0, ans1 = 0; rev = new char[999]; for (int i = 0; i < s1.length(); i++) { rev[s1.charAt(i)] = s2.charAt(i); } for (int i = 0; i < s.length(); i++) { if (rev[s.charAt(i)] != s.charAt(s.length() - i - 1)) { out.println("NIE"); return; } } out.println("TAK");// else out.println("NIE"); } } 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()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
973fec00c416336900a4ba34705f5e30
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /* JAVA JAVA JAVA JAVAJAVAJAVAJAVA JAVA JAVAJAVAJAVAJAVA JAVAJAVAJAVA JAVAJAVAJAVAJAVAJAVAJAVAJAVA JAVA JAVA JAVA JAVAJAVA JAVA JAVA JAVA JAVA */ 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(); int testCount = 1; for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class TaskA { String s1 = "AIMHOWVUTXxovYwbdpq", s2 = "AIMHOWVUTXxovYwdbqp"; char[] rev; public void solve(int testNumber, InputReader in, PrintWriter out) { String s = in.next(); int ans = 0, ans1 = 0; rev = new char[999]; for (int i = 0; i < s1.length(); i++) { rev[s1.charAt(i)] = s2.charAt(i); } for (int i = 0; i < s.length(); i++) { if (rev[s.charAt(i)] != s.charAt(s.length() - i - 1)) { out.println("NIE"); return; } } out.println("TAK");// else out.println("NIE"); } } 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()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
cd95471a6d15933b4713a24668e3abe8
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; public class Main { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter writer = new PrintWriter(System.out,false); static int[][] a;static int count=0,k1,k2; static boolean[][] visited; static int[] row={-1,-1,0,1,1,1,0,-1}; static int[] col={0,1,1,1,0,-1,-1,-1}; static Stack s; @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException{ int t,n,m; //StringTokenizer st=new StringTokenizer(reader.readLine()); //t=Integer.parseInt(st.nextToken()); Scanner s=new Scanner(System.in); String str=s.nextLine(); HashSet hs =new HashSet(); hs.add("A"); hs.add("H"); hs.add("I"); hs.add("M"); hs.add("O"); hs.add("o"); hs.add("T"); hs.add("U"); hs.add("V"); hs.add("v"); hs.add("W"); hs.add("w"); hs.add("X"); hs.add("x"); hs.add("Y"); n=str.length(); int i; for( i=0;i<n;i++){ if(str.charAt(i)==str.charAt(n-i-1)&&hs.contains(str.charAt(i)+"")) continue; if(str.charAt(i)=='b'&&str.charAt(n-i-1)=='d'||str.charAt(i)=='p'&&str.charAt(n-i-1)=='q'||str.charAt(i)=='q'&&str.charAt(n-i-1)=='p'||str.charAt(i)=='d'&&str.charAt(n-i-1)=='b') continue; else break; } /* if(n%2==1){ if(hs.contains(str.charAt(n/2)+"")) i=n/2; else i=0; }*/ if(i==n) System.out.println("TAK"); else System.out.println("NIE"); writer.flush(); writer.close(); reader.close(); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
0c7fbc2c0611ed4e2c466eaa7e9313a5
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
//package main; import java.io.*; import java.util.*; import java.math.*; public final class Main { BufferedReader br; StringTokenizer stk; public static void main(String[] args) throws Exception { new Main().run(); } { stk = null; br = new BufferedReader(new InputStreamReader(System.in)); } long mod = 998244353; StringBuilder res = new StringBuilder(1000005); void run() throws Exception { char[] c = nc(); String s = "OMAHITUVWXYovwx"; boolean ok = true; for(int i = 0, j = c.length - 1; i <= j; i++, j--) { if(i == j) { if(!s.contains("" + c[i])) { //System.out.println("1"); ok = false; } break; } else { String t = "" + c[i] + c[j]; if(t.equals("bd") || t.equals("db") || t.equals("pq") || t.equals("qp")) { continue; } if(c[i] == 'p' && c[j] != 'q') { //System.out.println("2"); ok = false; } else if(c[i] == 'b' && c[j] != 'd') { //System.out.println("3"); ok = false; } else if(c[i] == 'q' && c[j] != 'p') { //System.out.println("4"); ok = false; } else if(c[i] == 'd' && c[j] != 'b') { //System.out.println("5"); ok = false; } else { if(c[i] == c[j] && s.contains("" + c[i])) { // accept } else { //System.out.println("6"); ok = false; } } } } System.out.println(ok ? "TAK" : "NIE"); } //Reader & Writer String nt() throws Exception { if (stk == null || !stk.hasMoreTokens()) stk = new StringTokenizer(br.readLine(), " "); return stk.nextToken(); } char[] nc() throws Exception { return nt().toCharArray(); } int ni() throws Exception { return Integer.parseInt(nt()); } long nl() throws Exception { return Long.parseLong(nt()); } double nd() throws Exception { return Double.parseDouble(nt()); } //Some Misc methods long get(int l, int r, long[] a) { return l == 0 ? a[r] : a[r] - a[l - 1]; } void shuffle(long[] a) { Random r = new Random(); for(int i = 0; i < a.length; i++) { int idx = r.nextInt(a.length); long temp = a[i]; a[i] = a[idx]; a[idx] = temp; } } void reverse(long[] a) { for(int i = 0, j = a.length - 1; i < j; i++, j--) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } } void print(int[] a) { System.out.println(Arrays.toString(a)); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
c24115ca937653e0c7901819eb27195a
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
/** * Created by 1 on 16.07.15. */ import java.io.*; import java.util.*; public class CF1 { private MyScanner in; private PrintWriter out; /* * Solution here */ private CF1 solve() { String s = in.next(); int l = s.length(); int n = s.length() / 2; boolean flag = true, flag2 = true; // // if (l%2==1) { // char c1 = s.charAt(n); // // if (c1 == 'A' || c1 == 'H' || c1 == 'I' || c1 == 'M' || c1 == 'O' || c1 == 'T' || c1 == 'U' || c1 == 'V' // || c1 == 'W' || c1 == 'X' || c1 == 'Y' || c1 == 'o' || c1 == 'v' || c1 == 'w' // || c1 == 'x') { // flag = true; // } // flag2 = false; // } // if (l%2 == 1 && flag || flag2) { for (int i = 0; i < n; i++) { char c1 = s.charAt(i); char c2 = s.charAt(l - i - 1); if (c1 == c2) { if (c1 == 'A' || c1 == 'H' || c1 == 'I' || c1 == 'M' || c1 == 'O' || c1 == 'T' || c1 == 'U' || c1 == 'V' || c1 == 'W' || c1 == 'X' || c1 == 'Y' || c1 == 'o' || c1 == 'v' || c1 == 'w' || c1 == 'x') { i = i; } else { flag = false; break; } } else if (c1 == 'b' && c2 == 'd' || c1 == 'd' && c2 == 'b' || c1 == 'q' && c2 == 'p' || c1 == 'p' && c2 == 'q') { i = i; } else { flag = false; break; } } // } if (l % 2 == 1) { char c1 = s.charAt(n); if (c1 == 'A' || c1 == 'H' || c1 == 'I' || c1 == 'M' || c1 == 'O' || c1 == 'T' || c1 == 'U' || c1 == 'V' || c1 == 'W' || c1 == 'X' || c1 == 'Y' || c1 == 'o' || c1 == 'v' || c1 == 'w' || c1 == 'x') { } else { flag = false; } } if (flag) { out.print("TAK"); } else { out.print("NIE"); } return this; } private CF1 init() { try { in = new MyScanner(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } catch (FileNotFoundException e) { throw new RuntimeException(); } return this; } private CF1 finish() { out.flush(); return this; } public static void main(String[] args) { new CF1().init().solve().finish(); } private static class MyScanner { private BufferedReader reader; private StringTokenizer tokenizer; private boolean hasNextTokenFlag = true; MyScanner(final Reader input) throws FileNotFoundException { reader = new BufferedReader(input); ensureTokenizer(); } MyScanner(final String filename) throws FileNotFoundException { this(new FileReader(filename)); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { if (!hasNextToken()) { throw new NoSuchElementException(); } return tokenizer.nextToken(""); } public String next() { if (!hasNextToken()) { throw new NoSuchElementException(); } return tokenizer.nextToken(); } public boolean hasNextToken() { ensureTokenizer(); return hasNextTokenFlag; } private void ensureTokenizer() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String buffer = getBuffer(); if (buffer == null) { tokenizer = null; hasNextTokenFlag = false; return; } tokenizer = new StringTokenizer(buffer); } } private String getBuffer() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(); } } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
5c291f19b2a17373920a57f5c36b50ac
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java .util.Scanner; public class B691 { public static void main (String []args){ Scanner input=new Scanner (System.in); String s= input.nextLine(); int same =0; if (s.length()==1 ) { if (s.charAt(0)!='A'&&s.charAt(0)!='H'&&s.charAt(0)!='I'&&s.charAt(0)!='M'&&s.charAt(0)!='o'&&s.charAt(0)!='O'&&s.charAt(0)!='T'&&s.charAt(0)!='U'&&s.charAt(0)!='V'&&s.charAt(0)!='v'&&s.charAt(0)!='W'&&s.charAt(0)!='w'&&s.charAt(0)!='X'&&s.charAt(0)!='x'&&s.charAt(0)!='Y') {System.out.println("NIE");} else System.out.println("TAK"); } else { for (int i=0;i<s.length()/2;i++){ if (s.length()%2==1 && (s.charAt(s.length()/2)!='A'&&s.charAt(s.length()/2)!='H'&&s.charAt(s.length()/2)!='I'&&s.charAt(s.length()/2)!='M'&&s.charAt(s.length()/2)!='o'&&s.charAt(s.length()/2)!='O'&&s.charAt(s.length()/2)!='T'&&s.charAt(s.length()/2)!='U'&&s.charAt(s.length()/2)!='V'&&s.charAt(s.length()/2)!='v'&&s.charAt(s.length()/2)!='W'&&s.charAt(s.length()/2)!='w'&&s.charAt(s.length()/2)!='X'&&s.charAt(s.length()/2)!='x'&&s.charAt(s.length()/2)!='Y')){ break; } if (s.charAt(i)!='d'&&s.charAt(i)!='p'&&s.charAt(i)!='b'&&s.charAt(i)!='q'&&s.charAt(i)!='A'&&s.charAt(i)!='H'&&s.charAt(i)!='I'&&s.charAt(i)!='M'&&s.charAt(i)!='o'&&s.charAt(i)!='O'&&s.charAt(i)!='T'&&s.charAt(i)!='U'&&s.charAt(i)!='V'&&s.charAt(i)!='v'&&s.charAt(i)!='W'&&s.charAt(i)!='w'&&s.charAt(i)!='X'&&s.charAt(i)!='x'&&s.charAt(i)!='Y'){ break; } else { if (s.charAt(i)=='b'){ if (s.charAt(s.length()-i-1)=='d')same++; else break; } else if (s.charAt(i)=='d'){ if (s.charAt(s.length()-i-1)=='b')same++; else break; } else if (s.charAt(i)=='p'){ if (s.charAt(s.length()-i-1)=='q')same++; else break; } else if (s.charAt(i)=='q'){ if (s.charAt(s.length()-i-1)=='p')same++; else break; } else if (s.charAt(s.length()-i-1)==s.charAt(i))same++; } } if (same == s.length()/2)System.out.println("TAK"); else System.out.println("NIE"); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
9659e6f320734277bc2f1436462ad857
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.*; import java.util.*; public class TaskB { public static boolean isSymetric(char a , char b){ if(a == 'p' && b == 'q')return true; if(a == 'b' && b == 'd')return true; if(a == 'A' && b == 'A')return true; if(a == 'H' && b == 'H')return true; if(a == 'Y' && b == 'Y')return true; else if(a == 'I' && b == 'I') return true; else if(a == 'o' && b == 'o' ||a == 'O' && b == 'O') return true; else if(a == 'U' && b == 'U') return true; else if(a == 'x' && b == 'x' ||a == 'X' && b == 'X') return true; else if(a == 'M' && b == 'M') return true; else if(a == 'w' && b == 'w' ||a == 'W' && b == 'W') return true; else if(a == 'v' && b == 'v' ||a == 'V' && b == 'V') return true; else if(a == 'T' && b == 'T') return true; return false; } public static void solve(Scanner sc, PrintWriter pw){ String s = sc.next(); if(s.length() == 1){ if(isSymetric(s.charAt(0),s.charAt(0))) pw.println("TAK"); else pw.println("NIE"); return ; } int i = 0 ; int j = s.length() - 1 ; boolean isPalindrom = true; while(i <= j){ if(!isSymetric(s.charAt(i),s.charAt(j)) && !isSymetric(s.charAt(j),s.charAt(i)) ){ isPalindrom = false; break; } i++; j--; } if(isPalindrom) pw.println("TAK"); else pw.println("NIE"); } public static void main(String[] args) throws Exception{ int t; Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); solve(sc,pw); pw.flush(); sc.close(); pw.close(); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
ce7badea57eab75eb174639c7e85d00a
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.io.*; import java.util.*; public class B { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/T"; FastScanner in; PrintWriter out; String P = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; String Q = "A------HI---M-O----TUVWXY--d-b----------oqp----vwx--"; public void solve() { String s = in.next(); int n = s.length(); boolean ok = true; for (int l = 0, r = n - 1; l <= r; l++, r--) { int idx = P.indexOf(s.charAt(l)); ok &= s.charAt(r) == Q.charAt(idx); } System.out.println(ok ? "TAK" : "NIE"); } public void run() { if (__FILE_DEBUG_FLAG__ == __t__) { try { is = new FileInputStream(__DEBUG_FILE_NAME__); } catch (FileNotFoundException e) { // TODO θ‡ͺε‹•η”Ÿζˆγ•γ‚ŒγŸ catch ブロック e.printStackTrace(); } System.out.println("FILE_INPUT!"); } else { is = System.in; } in = new FastScanner(is); out = new PrintWriter(System.out); solve(); } public static void main(String[] args) { new B().run(); } public void mapDebug(int[][] a) { System.out.println("--------map display---------"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.printf("%3d ", a[i][j]); } System.out.println(); } System.out.println("----------------------------"); System.out.println(); } public void debug(Object... obj) { System.out.println(Arrays.deepToString(obj)); } class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; //stream = new FileInputStream(new File("dec.in")); } 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++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { return nextIntArray(n, 0); } int[] nextIntArray(int n, int margin) { int[] array = new int[n + margin]; for (int i = 0; i < n; i++) array[i + margin] = nextInt(); return array; } int[][] nextIntMap(int n, int m) { int[][] map = new int[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextIntArray(m); } return map; } long nextLong() { return Long.parseLong(next()); } long[] nextLongArray(int n) { return nextLongArray(n, 0); } long[] nextLongArray(int n, int margin) { long[] array = new long[n + margin]; for (int i = 0; i < n; i++) array[i + margin] = nextLong(); return array; } long[][] nextLongMap(int n, int m) { long[][] map = new long[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextLongArray(m); } return map; } double nextDouble() { return Double.parseDouble(next()); } double[] nextDoubleArray(int n) { return nextDoubleArray(n, 0); } double[] nextDoubleArray(int n, int margin) { double[] array = new double[n + margin]; for (int i = 0; i < n; i++) array[i + margin] = nextDouble(); return array; } double[][] nextDoubleMap(int n, int m) { double[][] map = new double[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextDoubleArray(m); } return map; } String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) array[i] = next(); return array; } String nextLine() { int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
db626cdae099d882034d1d51f6a0d69c
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.util.Scanner; public class main { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String str=sc.nextLine(); char arr[]=str.toCharArray(); int f=0,l=arr.length-1; int count=0; while(f<=l){ count=0; if(arr[f]=='A' && arr[l]=='A'){ f++; l--; count=1; } else if(arr[f]=='H' && arr[l]=='H'){ f++; l--; count=1; } else if(arr[f]=='I' && arr[l]=='I'){ f++; l--; count=1; } else if(arr[f]=='M' && arr[l]=='M'){ f++; l--; count=1; } else if(arr[f]=='O' && arr[l]=='O'){ f++; l--; count=1; } else if(arr[f]=='o' && arr[l]=='o'){ f++; l--; count=1; } else if(arr[f]=='T' && arr[l]=='T'){ f++; l--; count=1; } else if(arr[f]=='U' && arr[l]=='U'){ f++; l--; count=1; } else if(arr[f]=='V' && arr[l]=='V'){ f++; l--; count=1; } else if(arr[f]=='v' && arr[l]=='v'){ f++; l--; count=1; } else if(arr[f]=='W' && arr[l]=='W'){ f++; l--; count=1; } else if(arr[f]=='w' && arr[l]=='w'){ f++; l--; count=1; } else if(arr[f]=='X' && arr[l]=='X'){ f++; l--; count=1; } else if(arr[f]=='x' && arr[l]=='x'){ f++; l--; count=1; } else if(arr[f]=='Y' && arr[l]=='Y'){ f++; l--; count=1; } else if(arr[f]=='b' && arr[l]=='d'){ f++; l--; count=1; } else if(arr[f]=='d' && arr[l]=='b'){ f++; l--; count=1; } else if(arr[f]=='q' && arr[l]=='p'){ f++; l--; count=1; } else if(arr[f]=='p' && arr[l]=='q'){ f++; l--; count=1; } if(count==0) break; } if(f<=l) System.out.println("NIE"); else System.out.println("TAK"); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
694a92aac4e64bf18970c33110304cd2
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.util.*; public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = sc.next(); int length = input.length(); if(length % 2 == 0){ printOutput(checkNumber(input,length)); } else{ char val = input.charAt(length/2); if(check(val)){ printOutput(checkNumber(input,length)); } else{ printOutput(false); } } } //return true if sym public static boolean checkNumber(String input, int length){ for(int i = 0; i < length/2; i++){ //System.out.println(input.charAt(i) + " : " + input.charAt(length-1-i)); if((input.charAt(i) == 'b' && input.charAt(length-1-i) == 'd') || (input.charAt(i) == 'd' && input.charAt(length-1-i) == 'b')){ //b and d case } else if((input.charAt(i) == 'p' && input.charAt(length-1-i) == 'q') || (input.charAt(i) == 'q' && input.charAt(length-1-i) == 'p')){ //p and q case } else if(input.charAt(i) == input.charAt(length-1-i)){ if(!check(input.charAt(i) ) || !check(input.charAt(length-1-i))){ //check if they are a symmetric pair return false; } } else{ return false; } } return true; } public static boolean check(char val){ if(val == 'A' || val == 'H' || val == 'I' || val == 'M' || val == 'O' || val == 'o' || val == 'T' || val == 'U' || val == 'V' || val == 'v' || val == 'W' || val == 'w' || val == 'X' || val == 'x' || val == 'Y'){ return true; } return false; } public static void printOutput(boolean response){ if(response){ System.out.println("TAK"); } else{ System.out.println("NIE"); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
1639c29109be83e4695a71267abdc911
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.util.*; public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = sc.next(); //System.out.println(input); //System.out.println(input.length()); int length = input.length(); if(length % 2 == 0){ //System.out.println(input.charAt(0) == 'a'); printOutput(checkNumber(input,length)); } else{ //System.out.println(input.charAt(length/2)); char val = input.charAt(length/2); if(check(val)){ printOutput(checkNumber(input,length)); } else{ printOutput(false); } } } //return true if sym public static boolean checkNumber(String input, int length){ for(int i = 0; i < length/2; i++){ if((input.charAt(i) == 'b' && input.charAt(length-1-i) == 'd') || (input.charAt(i) == 'd' && input.charAt(length-1-i) == 'b')){ // } else if((input.charAt(i) == 'p' && input.charAt(length-1-i) == 'q') || (input.charAt(i) == 'q' && input.charAt(length-1-i) == 'p')){ // // } else if(input.charAt(i) == input.charAt(length-1-i)){ if(!check(input.charAt(i) ) || !check(input.charAt(length-1-i))){ return false; } } else{ return false; } } return true; } public static boolean check(char val){ if(val == 'A' || val == 'H' || val == 'I' || val == 'M' || val == 'O' || val == 'o' || val == 'T' || val == 'U' || val == 'V' || val == 'v' || val == 'W' || val == 'w' || val == 'X' || val == 'x' || val == 'Y'){ return true; } return false; } public static void printOutput(boolean response){ if(response){ System.out.println("TAK"); } else{ System.out.println("NIE"); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
408a75ff332eedc7deaf26890f4db7f5
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
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.FileReader; import java.io.InputStreamReader; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author zodiacLeo */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, FastScanner in, PrintWriter out) { char a[] = in.next().toCharArray(); int n = a.length; for (int i = 0; i < n; i++) { if (!isS(a[i], a[n - 1 - i])) { out.println("NIE"); return; } } out.println("TAK"); } public boolean isS(char a, char b) { char min = (char) Math.min(a, b); char max = (char) Math.max(a, b); if (min == 'b' && max == 'd') { return true; } if (min == 'p' && max == 'q') { return true; } if (min != max) { return false; } String st = "AHOoTGHYVvUIWwXxYM"; for (int i = 0; i < st.length(); i++) { char ch = st.charAt(i); if (ch == min && ch == max) { return true; } } return false; } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public String next() { while (st == null || !st.hasMoreElements()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
49c1b94f76e97c2fe85b33098f43aca5
train_000.jsonl
1468425600
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. English alphabet You are given a string s. Check if the string is "s-palindrome".
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class SPalindrom { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); String s = scan.next(); ArrayList<Character> letters = new ArrayList<>() ; letters.add('A');letters.add('O');letters.add('o');letters.add('H');letters.add('I');letters.add('M'); letters.add('T');letters.add('U');letters.add('V');letters.add('W');letters.add('X');letters.add('v'); letters.add('x');letters.add('w');letters.add('Y'); int flag = 0 ; for (int i = 0; i <= s.length() / 2; i++) { if(s.charAt(i) == s.charAt(s.length()-1-i) && letters.contains(s.charAt(i))){} else if (s.charAt(i) == 'q' && s.charAt(s.length()-1-i) == 'p'){} else if (s.charAt(i) == 'p' && s.charAt(s.length()-1-i) == 'q'){} else if (s.charAt(i) == 'd' && s.charAt(s.length()-1-i) == 'b'){} else if (s.charAt(i) == 'b' && s.charAt(s.length()-1-i) == 'd'){} else { flag = 1 ; } } if(flag == 1) System.out.println("NIE"); else System.out.println("TAK"); } }
Java
["oXoxoXo", "bod", "ER"]
1 second
["TAK", "TAK", "NIE"]
null
Java 8
standard input
[ "implementation", "strings" ]
bec2349631158b7dbfedcaededf65cc2
The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters.
1,600
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
standard output
PASSED
2ca41bd2264f984fdac2d4b8d0b231f5
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.*; import java.io.*; public class Main { static BufferedReader br; static FileInputStream fis; static InputStreamReader isr; static FileWriter fw; public static void main(String[] args) throws IOException{ //fis = new FileInputStream("input.txt"); //isr = new InputStreamReader(fis); isr = new InputStreamReader(System.in); br = new BufferedReader(isr); //File file = new File("output.txt"); //fw = new FileWriter(file); solve(); //fis.close(); isr.close(); br.close(); //fw.close(); return; } // the followings are methods to take care of inputs. static int nextInt(){ return Integer.parseInt(nextLine()); } static long nextLong(){ return Long.parseLong(nextLine()); } static int[] nextIntArray(){ String[] inp = nextLine().split("\\s+"); int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){ ary[i] = Integer.parseInt(inp[i]); } return ary; } static int[] nextIntArrayFrom1(){ String[] inp = nextLine().split("\\s+"); int[] ary = new int[inp.length + 1]; for (int i = 0; i < inp.length; i++){ ary[i+1] = Integer.parseInt(inp[i]); } return ary; } static long[] nextLongArray(){ String[] inp = nextLine().split("\\s+"); long[] ary = new long[inp.length]; for (int i = 0; i < inp.length; i++){ ary[i] = Long.parseLong(inp[i]); } return ary; } static long[] nextLongArrayFrom1(){ String[] inp = nextLine().split("\\s+"); long[] ary = new long[inp.length + 1]; for (int i = 0; i < inp.length; i++){ ary[i+1] = Long.parseLong(inp[i]); } return ary; } static String nextLine(){ try { return br.readLine().trim(); } catch (Exception e){} return null; } static void write(String str){ try{ fw.write(str); }catch (Exception e){ System.out.println(e); } return; } static void solve(){ int n = nextInt(); int[] coin = nextIntArray(); int sum=0; for(int i=0;i<n;i++){ sum+=coin[i]; } boolean rmode=true; int i=0; while(true){ if(sum==0) break; if(i==0) rmode=true; if(i==n-1) rmode=false; if(coin[i]>0){ System.out.print("P"); coin[i]--; sum--; } if(rmode==true){ System.out.print("R"); i++; } else{ System.out.print("L"); i--; } } System.out.println(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
2793ea6905f35b98361b5a232282deef
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Yanhong Wu */ public class B { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); StringBuilder sb = new StringBuilder(); for (int i=0;i<n;i++){ int m = in.nextInt(); for (int j=0;j<m;j++){ if (j != m-1) if (i!=n-1) sb.append("PRL"); else sb.append("PLR"); else sb.append("P"); } if (i != n-1) sb.append('R'); } out.println(sb.toString()); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
fada42ef7cfa9053f25522f07af7f184
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = 0; try { n = Integer.parseInt(br.readLine()); } catch (IOException e) {} int[] wallets = new int[n]; try { String[] s = br.readLine().split(" "); for (int i = 0; i < n; i++) wallets[i] = Integer.parseInt(s[i]); } catch (IOException e) {} String res = ""; int idx = 0; boolean[] done = new boolean[n]; Arrays.fill(done, false); for (int i = 0; i < n; i++) if (wallets[i] == 0) done[i] = true; while (idx < n) { if (!done[idx]) { System.out.print("P"); if (--wallets[idx] == 0) done[idx] = true; } if (idx-1 >= 0 && !done[idx - 1] || idx + 1 >= n && !done[idx]) { System.out.print("L"); idx--; } else if (idx + 1 < n) { System.out.print("R"); idx++; } else idx++; } System.out.println(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
14c2ed54cbb3a5fcf519526312df3f75
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; /** * Created by Admin on 18.07.2016. */ public class B_379 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { while (a[i] > 0){ if ( i != n-1 ){ System.out.print("PRL"); a[i]--; }else { System.out.print("PLR"); a[i]--; } } if (i != n-1) System.out.print("R"); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
794dd761b4b7bd121a56d310557187ed
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class NYP { public static void main(String[] args) throws Exception { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int wallets = Integer.parseInt(st.nextToken()); long[] amounts = new long[wallets]; st=new StringTokenizer(br.readLine()); for(int i=0;i<wallets;i++){ amounts[i]=Long.parseLong(st.nextToken()); } int pos=0; while(pos<wallets-1){ if(amounts[pos]>0){ System.out.print("P"); if(amounts[pos]-1<amounts[pos+1]){ long temp=amounts[pos]-1; for(long i=0;i<temp;i++){ System.out.print("RPLP"); } amounts[pos+1]-=(amounts[pos]-1); } else{ long temp=amounts[pos+1]; for(long i=0;i<temp;i++){ System.out.print("RPLP"); } temp=amounts[pos]-amounts[pos+1]-1; for(long i=0;i<temp;i++){ System.out.print("RLP"); } amounts[pos+1]=0; } amounts[pos]=0; } System.out.print("R"); pos+=1; } if(amounts[pos]>0){ System.out.print("P"); for(int i=0;i<amounts[pos]-1;i++){ System.out.print("LRP"); } amounts[pos]=0; } //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("NYP.out"))); System.out.println(); System.out.flush(); System.out.close(); System.exit(0); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
dce30ebbde870a366158223b67acbd09
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.*; import java.util.*; public class Main { static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter writer; static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws IOException { return Long.parseLong(nextToken()); } static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } static String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static void main(String[] args) throws IOException { tokenizer = null; reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); banana(); reader.close(); writer.close(); } static void banana() throws IOException { int n = nextInt(); int[] mas = new int[n]; for (int i = 0; i < n; i++) { mas[i] = nextInt(); } for (int i = 0; i < n; i++) { if (i == n - 1) { for (int j = 0; j < mas[i]; j++) { writer.print("LRP"); } break; } else { for (int j = 0; j < mas[i]; j++) { writer.print("RLP"); } } writer.print("R"); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
1f6b2d056d6d91b30bebfd31c3cd4886
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class CF_Bye2013_II { public static void solve(int[] arr) { int len = arr.length; int[] cur = new int[len]; for(int i=0;i<len;i++) { cur[i] = 0; } int ind = 0; while(!equal(cur,arr)) { while(ind!=len-1) { if(cur[ind]<arr[ind]) { cur[ind]++; System.out.print("P"); } System.out.print("R"); ind++; } if(cur[ind]<arr[ind]) { cur[ind]++; System.out.print("P"); } while(ind!=0) { System.out.print("L"); ind--; } } } public static boolean equal(int[] arr1, int[] arr2) { for(int i=0;i<arr1.length;i++) { if(arr1[i]!=arr2[i]) return false; } return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int len = sc.nextInt(); int[] arr = new int[len]; for(int i=0;i<len;i++) { arr[i] = sc.nextInt(); } sc.close(); solve(arr); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
e772177349e39243a82e41dad193a216
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B379 { static FastScanner in; static FastPrinter out; public static void main(String[] args) throws IOException { in = new FastScanner(System.in); out = new FastPrinter(System.out); int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { String app = "PRL"; if (i == n - 1) app = "PLR"; for (int j = 0; j < arr[i]; j++) sb.append(app); if (i != n - 1) sb.append("R"); } out.println(sb.toString()); out.close(); } static class FastPrinter extends PrintWriter { public FastPrinter(File f) throws IOException { super(new BufferedWriter(new FileWriter(f))); } public FastPrinter(OutputStream out) throws IOException { super(new BufferedWriter(new OutputStreamWriter(out))); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public String next() throws IOException { if (st.hasMoreTokens()) return st.nextToken(); st = new StringTokenizer(br.readLine()); return next(); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
b7fa3e5014d9ffb339c95390a0da3686
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class NewYearPresent { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(in.readLine()); int arr[] = new int [n]; StringTokenizer st = new StringTokenizer(in.readLine()); for(int i =0;i<n;i++){ arr[i] = Integer.parseInt(st.nextToken()); if(i!=0){ out.print("R"); } while(arr[i]-->=1){ out.print("P"); if(arr[i]>=1){ if(i!=n-1){ out.print("RL"); } else{ out.print("LR"); } } } } out.println(); in.close(); out.close(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
5c12ccdab494ff033d4435969d62bfbc
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class NewYearPresent { /** * @param args */ public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; int n = 0; int[] a = null; try { if (br != null) { if ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); String token = ""; if (st.hasMoreTokens()) { token = st.nextToken(); if (token != null) { n = Integer.parseInt(token); } } } a = new int[n]; int cnt = 0; if ((line = br.readLine()) != null) { // System.out.println(line); StringTokenizer st = new StringTokenizer(line); String token = ""; while (st.hasMoreTokens()) { token = st.nextToken(); if (token != null) { a[cnt++] = Integer.parseInt(token); } } } NewYearPresent nyp = new NewYearPresent(); nyp.calculate(a); } } catch (Exception e) { System.err.println(e); } } public void calculate(int[] a) { boolean flag = false; int end = a.length - 1; for (int i = a.length - 1; i >= 0; i--) { if (a[i] > 0) { end = i; break; } } for (int i = 0; i <= end; i++) { while (a[i] > 0) { if (flag) { if (i == a.length - 1) System.out.print("LRP"); else System.out.print("RLP"); } else { System.out.print("P"); flag = true; } a[i]--; } if (i != end) { System.out.print("R"); flag = false; } } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
ed65bc9f2a38c87e5ffbc14e67662cf0
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; /** * <a href="http://codeforces.ru/problemset/problem/379/B"/> * * @author pvasilyev * @since 09 Jan 2014 */ public class Problem087 { public static void main(String[] args) { final Scanner reader = new Scanner(System.in); final PrintWriter writer = new PrintWriter(System.out); solve(reader, writer); reader.close(); writer.close(); } private static void solve(final Scanner reader, final PrintWriter writer) { final int n = reader.nextInt(); int[] a = new int[n]; long sum = 0; for (int i = 0; i < a.length; i++) { a[i] = reader.nextInt(); sum += a[i]; } final StringBuilder stringBuilder = new StringBuilder(); boolean goForth = true; int position = 0; while (sum != 0) { if (a[position] != 0) { stringBuilder.append('P'); sum--; a[position]--; } if (goForth) { if (position < n - 1) { position++; stringBuilder.append('R'); } else { goForth = false; position--; stringBuilder.append('L'); } } else { if (position > 0) { position--; stringBuilder.append('L'); } else { goForth = true; position++; stringBuilder.append('R'); } } } writer.println(stringBuilder); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
1260dbc421636a4055d003056ba02ef8
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++) { a[i] = input.nextInt(); } for(int i = 0; i < n - 1; i++) { while(a[i] != 0) { System.out.print("PRL"); a[i]--; } System.out.print("R"); } while(a[n - 1] != 0) { System.out.print("PLR"); a[n - 1]--; } System.out.println(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
5f7d549d23974ca32b32847a6cce04f2
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.*; import java.util.*; /** * * @author Altynbek.Nurgaziyev */ public class B { public void solution() throws Exception { int n = in.nextInt(); int f[] = new int[n]; for (int i = 0; i < n; i++) { f[i] = in.nextInt(); } char ans[] = new char[(int) (1e6)]; int l = 0; for (int i = 0; i < n - 1; i++) { if (f[i] == 0) { ans[l] = 'R'; l++; } else { while (true) { if (f[i] == 0) { break; } f[i]--; ans[l] = 'P'; l++; ans[l] = 'R'; l++; if (f[i] == 0) { break; } ans[l] = 'L'; l++; } } } if (f[n - 1] > 0) { while (true) { f[n - 1]--; ans[l] = 'P'; l++; if (f[n - 1] == 0) { break; } ans[l] = 'L'; l++; ans[l] = 'R'; l++; } } for (int i = 0; i < l; i++) { out.print(ans[i]); } out.println(); } Scanner in; PrintWriter out; String input, output; public void run() throws Exception { if (input != null) { in = new Scanner(new FileReader(input)); } else { in = new Scanner(System.in); } if (output != null) { out = new PrintWriter(new File(output)); } else { out = new PrintWriter(System.out); } solution(); out.close(); } public static void main(String[] args) throws Exception { new B().run(); } public class Scanner { private BufferedReader br; private StringTokenizer st; public Scanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public Scanner(FileReader fr) { br = new BufferedReader(fr); } public String next() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public Integer nextInt() throws Exception { return Integer.parseInt(next()); } public Long nextLong() throws Exception { return Long.parseLong(next()); } public Double nextDouble() throws Exception { return Double.parseDouble(next()); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
e7451212aa0edac6e50629c3fbc67011
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
//package GB2013; import java.io.*; import java.util.*; /** * * @coder Altynbek Nurgaziyev */ public class B { public void solution() throws Exception { int n = in.nextInt(), f[] = new int[n]; for (int i = 0; i < n; i++) { f[i] = in.nextInt(); } for (int i = 0; i < n - 1; i++) { while (f[i] > 0) { out.print("PRL"); f[i]--; } out.print("R"); } while (f[n - 1] > 0) { out.print("PLR"); f[n - 1]--; } out.println(); } Scanner in; PrintWriter out; String input, output; public void run() throws Exception { if (input != null) { in = new Scanner(new FileReader(input)); } else { in = new Scanner(System.in); } if (output != null) { out = new PrintWriter(new File(output)); } else { out = new PrintWriter(System.out); } solution(); out.close(); } public static void main(String[] args) throws Exception { new B().run(); } public class Scanner { private final BufferedReader br; private StringTokenizer st; public Scanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public Scanner(FileReader fr) { br = new BufferedReader(fr); } public String next() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public Integer nextInt() throws Exception { return Integer.parseInt(next()); } public Long nextLong() throws Exception { return Long.parseLong(next()); } public Double nextDouble() throws Exception { return Double.parseDouble(next()); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
52c10dfacb23da4aee6fd466865085f2
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; public class New_Year_Present { public static void main(String args[]){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int a[] = new int[n]; int cnt = 0; for(int i = 0 ; i < n ; i++){ a[i] = in.nextInt(); cnt+=a[i]; } int count = 0 , turn = 1 , ind = 0 ; int b[] = new int[n]; while(count!=cnt){ if(ind == n-1){ if(b[ind]<a[ind]){ b[ind]++; count++; System.out.print("P"); } if(count==cnt) break; turn = -1; ind+= turn; System.out.print("L"); }else if(ind == 0){ if(b[ind]<a[ind]){ b[ind]++; count++; System.out.print("P"); } if(count==cnt) break; turn = 1; ind+=turn; System.out.print("R"); }else{ if(b[ind]<a[ind]){ b[ind]++; count++; System.out.print("P"); } if(count==cnt) break; ind+=turn; if(turn == 1) System.out.print("R"); else System.out.print("L"); } } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
7bbed8d54c8e34b07b48c7b6d34ce055
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; public class B2013 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int a[] = new int[n]; int zeros = 0; for (int i = 0; i < n; i++) { a[i] = input.nextInt(); if (a[i] == 0) { zeros++; } } int flag = 1; int current = 0; StringBuilder sb = new StringBuilder(); while (true) { if (a[current] == 0) { if (current == 0) { if (zeros == n) { break; } sb.append("R"); if (flag == -1) { flag = 1; } } else if (current == n - 1) { if (zeros == n) { break; } sb.append("L"); if (flag == 1) { flag = -1; } } else { if (flag == 1) { sb.append("R"); } else { sb.append("L"); } } } else { a[current]--; if (a[current] == 0) { zeros++; } sb.append("P"); if (current == 0) { if (zeros == n) { break; } sb.append("R"); if (flag == -1) { flag = 1; } } else if (current == n - 1) { if (zeros == n) { break; } sb.append("L"); if (flag == 1) { flag = -1; } } else { if (flag == 1) { sb.append("R"); } else { sb.append("L"); } } } current += flag; } System.out.println(sb.toString()); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
80aa9412be44c505577d96a6d4901554
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; public class C_379B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [] mas = new int[n+1]; int sum = 0; for (int i = 1; i <= n; i++) { mas[i] = sc.nextInt(); sum += mas[i]; } A: while (sum > 0) { if (mas[1] > 0) { System.out.print("P"); mas[1]--; sum--; } for (int i = 2; i <= n; i++) { System.out.print("R"); if (mas[i] > 0) { System.out.print("P"); sum--; mas[i]--; } if(sum <= 0) break A; } for (int i = n-1; i >= 2; i--) { System.out.print("L"); if (mas[i] > 0) { System.out.print("P"); sum--; mas[i]--; } if(sum <= 0) break A; } System.out.print("L"); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
7d024bbe035e6aee6ee830840c0c864b
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
//package Codeforces.GoodBye2013_Div2B.Code1; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /* * some cheeky quote */ public class Main { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); int sum = 0; int left[] = new int[n]; for (int i = 0; i < n; i++) { left[i] = in.nextInt(); sum += left[i]; } StringBuffer result = new StringBuffer(); boolean isPut = false; int count = 0; while (sum > 0) { if (left[count] > 0 && !isPut) { result.append("P"); isPut = true; left[count]--; sum--; } else { isPut = false; if ((count > 0 && left[count - 1] > 0) || (count == n - 1)) { count--; result.append("L"); } else { count++; result.append("R"); } } } out.println(result); } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { new Main().run(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
bb336b90e226f4add6d27195f94390e3
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class NewYearPresent { public static void main(String [] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(br.readLine()); StringTokenizer st=new StringTokenizer(br.readLine()); int [] a=new int [n]; int sum=0; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(st.nextToken()); sum+=a[i]; } boolean prim=true; while(sum>0) { int i=1; if(prim)i=0; for(;i<n;i++) { if(a[i]>0) { pw.print("P"); sum--; a[i]--; } if(sum>0) { if(i<n-1)pw.print("R"); else pw.print("L"); } } prim=false; if(sum==0)break; for(i=n-2;i>=0;i--) { if(a[i]>0) { pw.print("P"); sum--; a[i]--; } if(sum>0) { if(i>0)pw.print("L"); else pw.print("R"); } } } pw.flush(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
4bfcfbd651fd21fd3511c7f600af717d
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
/******************************************************************* My love has gone away, quietly after a hundered days. This is what's she has always said she won't stay for more than what she can repay. I can still hear her say there that I'm not hearing tender play The day she let me kiss her was a display, of love to those who she betray. How can I put someone to the test, when I thought I got the best. Untill the taste of bitterness then I regret but still that I won't detest, the love I can't forget, like someone who has left. How can i leave someone for the rest when i'm alone facing the best Untill they take some try to reason i regret But still that i won't detest who i can never forget like someone i once met .. ******************************************************************/ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; public class B379 { public static void main(String[] args) { input(); solve(); } static void solve() { StringBuilder res = new StringBuilder(); for (int i = 0; i < n;) { if (a[i] != 0) { res.append("P"); a[i]--; } if (i > 0 && a[i - 1] != 0 || i == n - 1 && a[i] != 0) { res.append("L"); i--; continue; } if (i == n - 1) { break; } else { res.append("R"); i++; } } System.out.println(res); } /************************************************************************************/ static int n; static int[] a; static void input() { n = nextInt(); a = nextAi(n); } /************************************************************************************/ static InputStream is = System.in; static private byte[] buffer = new byte[1024]; static private int lenbuf = 0, ptrbuf = 0; static private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return buffer[ptrbuf++]; } static private boolean isSpace(int c) { return !(c >= 33 && c <= 126); } static private int read() { int b; while ((b = readByte()) != -1 && isSpace(b)) ; return b; } static private double nextDouble() { return Double.parseDouble(nextString()); } static private char nextChar() { return (char) read(); } static private String nextString() { int b = read(); StringBuilder sb = new StringBuilder(); while (!(isSpace(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } static private char[] nextString(int n) { char[] buf = new char[n]; int b = read(), p = 0; while (p < n && !(isSpace(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } static private int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } static private long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } static private int[] nextAi(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } static private Integer[] nextAi1(int n) { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
ca1ac23efee670de349d2a15fe4c0241
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; public class P379B { static int n; static int[] a; public static void give(int t) { if (t != n - 1) for (int i = 0; i < a[t]; i++) System.out.print("PRL"); else for (int i = 0; i < a[t]; i++) System.out.print("PLR"); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); for (int i = 0; i < n - 1; i++) { give(i); System.out.print("R"); } give(n - 1); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
4ad23a24e9c2d956a3dd3fffe44645a7
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; /** * Created with IntelliJ IDEA. * User: SBerdibekov * Date: 19.11.13 * Time: 15:09 * To change this template use File | Settings | File Templates. */ public class Main { PrintWriter pw; Scanner sc; private void task() throws Exception { int n = sc.nextInt(); int a; for(int i=0;i<n;i++) { a = sc.nextInt(); if(i > 0) pw.print('R'); for(int j=0;j<a;j++) { if(j > 0) { if(i + 1 == n) { pw.print("LRP"); } else { pw.print("RLP"); } } else { pw.print('P'); } } } } public static void main(String[] args) throws Exception { new Main().run(); } public void run() throws Exception { pw = new PrintWriter(System.out); sc = new Scanner(System.in); this.task(); pw.close(); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
fb58087847f0d4553454c96c79440f5a
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; public class main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(""); int n = sc.nextInt(); int[] input = new int[n]; int[] result = new int[n]; for (int i = 0; i < n; i++) { input[i] = sc.nextInt(); result[i] = 0; } sc.close(); for (int i = 0; i < n - 1; i += 2) { if (input[i] == result[i] && input[i + 1] == result[i + 1] && i + 1 < n - 1) sb.append("RR"); else if (input[i] == result[i] && input[i + 1] == result[i + 1] && i + 1 == n - 1) sb.append("R"); while (input[i + 1] > result[i + 1] || input[i] > result[i]) { if (input[i + 1] > result[i + 1] && input[i] > result[i]) { sb.append("PRP"); result[i + 1]++; result[i]++; if (input[i + 1] == result[i + 1] && input[i] == result[i] && i + 1 < n - 1) { sb.append("R"); } else if (input[i] > result[i] || input [i + 1] > result[i + 1]){ sb.append("L"); } } else if (input[i + 1] == result[i + 1] && input[i] > result[i]) { sb.append("P"); result[i]++; if (input[i] == result[i] && i + 1 < n - 1) { sb.append("RR"); } else if (input[i] > result[i]) { sb.append("RL"); } } else if (input[i + 1] > result[i + 1] && input[i] == result[i]) { sb.append("RP"); result[i + 1]++; if (input[i + 1] == result[i + 1] && i + 2 < n - 1) { sb.append("R"); } else if (input[i + 1] > result[i + 1]) { sb.append("L"); } } } } if (n % 2 != 0) { while (result[n - 1] < input[n - 1]) { sb.append("PLR"); result[n - 1]++; } } System.out.println(sb.toString()); // System.out.println(sb.toString().length()); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
df021be383b5d39d730e008c14de8dd3
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.math.BigInteger; import java.util.Scanner; import javax.swing.table.DefaultTableModel; public class Test { static void print(int[] a) { for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); System.out.println(); } static String space(int n) { String res=""; for(int i=0;i<n;i++) res+=" "; return res; } static int sum(int a[]) { int res=0; for(int i=0;i<a.length;i++) res+=a[i]; return res; } static int[] sort(int list[]) { for(int i=0;i<list.length-1;i++) { for(int j=0;j<list.length-i-1;j++) { if(list[j]>list[j+1]) { int t=list[j]; list[j]=list[j+1]; list[j+1]=t; } } } return list; } public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=in.nextInt(); int i=0; String res=""; for(i=0;i<n-1;i++) { if(a[i]>0) { for(int j=0;j<a[i]-1;j++) { if(res.isEmpty()) { if(a[i]==1) System.out.print("PR"); else System.out.print("PRL"); } else res+="PRL"; } System.out.print("PR"); } else System.out.print("R"); } //System.out.println(res); if(a[n-1]>0) { //System.out.println(res); for(i=0;i<a[n-1]-1;i++) { if(res.isEmpty()) { if(a[n-1]==1) System.out.print("P"); else System.out.print("PLR"); } else System.out.print("PLR"); } System.out.println("P"); } /* while(i<n) { //System.out.println(res); if(a[i]!=b[i]) { b[i]++; res+="P"; } if(i>0&&a[i-1]!=b[i-1]) { res+="L"; i--; continue; } if(i<n-1&&a[i+1]!=b[i+1]) { res+="R"; i++; continue; } if(a[i]==b[i]) { i++; if(i>=n) break; res+="R"; continue; } if(i<n-1&&a[i+1]==b[i+1]) { res+="R"; i++; continue; } if(i>0&&a[i-1]==b[i-1]) { res+="L"; i--; continue; } //i++; }*/ //System.out.println(res); //for(int i=0;i<255;i++) System.out.println(i+" : "+(char)i); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
13260d16bfeb46dcffb28ca36319d9db
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class Main { InputReader input; PrintWriter output; void run(){ output = new PrintWriter(new OutputStreamWriter(System.out)); input = new InputReader(System.in); solve(); output.flush(); } public static void main(String[] args){ new Main().run(); } void solve() { int n = input.ni(); int[] f = new int[n]; int[] a = new int[n]; for(int i = 0; i < n; i++) { f[i] = input.ni(); } StringBuilder res = new StringBuilder(); for(int i = 0; i < n; i++) { if(i > 0) res.append("R"); for(int j = 0; j < f[i]; j++) { if(i < n-1) res.append("PRL"); else res.append("PLR"); } } output.println(res.toString()); } class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(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 ni() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int 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 long nl() { 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 ns() { 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 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 readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) return readLine(); else return readLine0(); } public BigInteger readBigInteger() { try { return new BigInteger(ns()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public double readDouble() { 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, ni()); 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, ni()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean eof() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return ns(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
b1a1409fae961dc38fc27a4590f5febf
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.*; public class B379 { public static void main(String[] args){ Scanner br = new Scanner(System.in); int n = br.nextInt(); StringBuilder res = new StringBuilder(""); int[] left = new int[n]; for(int i = 0;i<n;i++){ left[i] = br.nextInt(); } int pos = 0; while(true){ if(left[pos] == 0){ if(pos == n-1){ break; } res.append("R"); pos++; continue; } res.append("P"); left[pos]--; if(left[pos] == 0){ if(pos == n-1){ break; } pos++; res.append("R"); continue; } int next = pos+1; if(pos == n-1){ next = pos-1; res.append("L"); } else{ res.append("R"); } if(left[next] > 0){ left[next]--; res.append("P"); } if(pos == n-1){ res.append("R"); } else{ res.append("L"); } } System.out.println(res); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
7648e88badf652c33fd7c8a309a8155d
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Queue; import java.util.Set; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.LinkedBlockingQueue; public class Main { public static void main(String[] argv) { MainRun mainSolve = new MainRun(); mainSolve.run(0, 0); } } class Task { private boolean left(int a[], int pos) { boolean ok = false; for (int p = pos - 1; p >= 1 && !ok; p--) if (a[p] != 0) ok = true; return ok; } public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); int a[] = in.nextIntArray(n); int sum = 0; for (int i = 1; i <= n; i++) sum += a[i]; int pos = 1; while(sum != 0) { if (a[pos] != 0) { out.print("P"); a[pos]--; sum--; } if (sum == 0) break; if (left(a, pos)) { out.print("L"); pos--; } else { if (pos != n) { out.print("R"); pos++; } else { out.print("L"); pos--; } } } } } class MainRun { void run(int inF, int outF) { // inF = outF = 0; String input = "input.txt"; // String input = "primes.in"; String output = "output.txt"; // String output = "primes.out"; InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in; PrintWriter out; if (inF == 1) in = new InputReader(input); else in = new InputReader(inputStream); if (outF == 1) out = getPrintWriter(output); else out = getPrintWriter(outputStream); Task solver = new Task(); solver.solve(in, out); out.close(); } public static PrintWriter getPrintWriter(OutputStream stream) { return new PrintWriter(stream); } public static PrintWriter getPrintWriter(String f) { try { return new PrintWriter(new File(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; } } class InputReader { BufferedReader reader; StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } InputReader(String f) { try { reader = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } 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 String getLine() { try { return (String)reader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; } public int nextInt() { return Integer.parseInt(next()); } public char nextChar() { return next().charAt(0); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int a[] = new int[n + 2]; for (int i = 1; i <= n; i++) a[i] = nextInt(); return a; } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
62f7061e49970ddf4cf7f12b454759b3
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.*; import java.math.*; import java.io.*; /** * * @author magzhankairanbay */ public class Code { public static boolean check(int[] a, int n) { for (int i = 0; i < n; i++) { if (a[i] != 0) { return false; } } return true; } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } boolean finish = false; while (true) { for (int i = 0; i < n - 1; i++) { if (a[i] != 0) { System.out.print("P"); a[i]--; if (a[i] == 0) { if (check(a, n)) { finish = true; break; } } System.out.print("R"); } else { if (check(a, n)) { finish = true; break; } else { System.out.print("R"); } } } if (finish) { break; } for (int i = n - 1; i >= 1; i--) { if (a[i] != 0) { System.out.print("P"); a[i]--; if (a[i] == 0) { if (check(a, n)) { finish = true; break; } } System.out.print("L"); } else { if (check(a, n)) { finish = true; break; } else { System.out.print("L"); } } } if (finish) { break; } } } catch(Exception ex) { System.out.println(ex.toString()); } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
055e5bc26fd67dd81548a546be3e72ab
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int A[] = new int[n]; for (int i = 0; i < n; i++) { A[i] = cin.nextInt(); } solve(n, A); } public static void solve(int n, int A[]) { int sum = 0; for (int i: A) { sum += i; } int fill = 0; int now = 0; int dir = 1; while (fill < sum) { if (A[now] > 0) { System.out.print("P"); A[now]--; fill++; } if (now + dir >= n || now + dir < 0) { dir *= -1; } now += dir; System.out.print(dir == 1 ? "R": "L"); } System.out.println(""); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
de49b887bdc0a23d5d4864a361f0f7c7
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.Scanner; public class ass { public static void main(String args[]) { Scanner in = new Scanner(System.in); int a[]; int n=in.nextInt(); a=new int[n]; for(int i=0;i<n;i++){ a[i] = in.nextInt();} for(int i=0;i<n;i++){ if(a[i]==0&&i!=n-1){ System.out.print("R"); }else if(i!=n-1){ for(int j=1;j<a[i];j++){ System.out.print("PRL"); } System.out.print("PR"); } else{ for(int j=1;j<a[i];j++){ System.out.print("PLR"); } if(a[i]!=0) System.out.print("P"); break; } } } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
f18251b9cc192fe2b34dffd3179752fb
train_000.jsonl
1388417400
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.
256 megabytes
import java.util.*; import java.math.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] t = new int[n]; for (int i=0; i<n; i++) t[i] = sc.nextInt(); StringBuilder sb = new StringBuilder(); int pos =0; while (true){ if(t[pos]>0){ t[pos]--; sb.append('P'); if (pos>0){sb.append("LR");} else {sb.append("RL");} } else { sb.append('R'); pos++; } if (pos==n){break;} } sb.deleteCharAt(sb.length()-1); System.out.println(sb); } }
Java
["2\n1 2", "4\n0 2 0 2"]
1 second
["PRPLRP", "RPRRPLLPLRRRP"]
null
Java 7
standard input
[ "constructive algorithms", "implementation" ]
50e88225d8b081d63eebe446f48057f4
The first line contains integer n (2 ≀ n ≀ 300) β€” the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 300). It is guaranteed that at least one ai is positive.
1,200
Print the sequence that consists of k (1 ≀ k ≀ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.
standard output
PASSED
35a098d6ad70820eb5de9d755facd722
train_000.jsonl
1404651900
DZY loves colors, and he enjoys painting.On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). The color of the i-th unit of the ribbon is i at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first.DZY loves painting, we know. He takes up a paintbrush with color x and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit i currently is y. When it is painted by this paintbrush, the color of the unit becomes x, and the colorfulness of the unit increases by |x - y|.DZY wants to perform m operations, each operation can be one of the following: Paint all the units with numbers between l and r (both inclusive) with color x. Ask the sum of colorfulness of the units between l and r (both inclusive). Can you help DZY?
256 megabytes
import java.io.*; import java.util.*; import java.math.BigInteger; import java.util.Collections.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.math.BigInteger.*; public class Main{ void run(){ Locale.setDefault(Locale.US); boolean my; try { my = System.getProperty("MY_LOCAL") != null; } catch (Exception e) { my = false; } try{ err = System.err; if( my ){ sc = new FastScanner(new BufferedReader(new FileReader("input.txt"))); // sc = new FastScanner(new BufferedReader(new FileReader("C:\\myTest.txt"))); out = new PrintWriter (new FileWriter("output.txt")); } else { sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new OutputStreamWriter(System.out)); } // out = new PrintWriter(new OutputStreamWriter(System.out)); }catch(Exception e){ MLE(); } if( my ) tBeg = System.currentTimeMillis(); solve(); if( my ) err.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 ); exit(0); } void exit( int val ){ err.flush(); out.flush(); System.exit(val); } double tBeg; FastScanner sc; PrintWriter out; PrintStream err; class FastScanner{ StringTokenizer st; BufferedReader br; FastScanner( BufferedReader _br ){ br = _br; } String readLine(){ try { return br.readLine(); } catch (IOException e) { return null; } } String next(){ while( st==null || !st.hasMoreElements() ) st = new StringTokenizer(readLine()); return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } } void MLE(){ int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024]; } void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); } void TLE(){ for(;;); } public static void main(String[] args) { new Main().run(); // new Thread( null, new Runnable() { // @Override // public void run() { // new Main().run(); // } // }, "Lolka", 256_000_000L ).run(); } //////////////////////////////////////////////////////////////// class Adder{ int n; long[] sum, add; Adder( int _n ){ n = _n; sum = new long[4*n]; add = new long[4*n]; } long getVal( int v, int tl, int tr ){ return sum[v] + (tr - tl + 1) * add[v]; } void add( int delta, int l, int r ){ add( delta, l, r, 1,0,n-1 ); } void add( long delta, int l, int r, int v, int tl, int tr ){ if( l > r ) return; if( l == tl && r == tr ){ add[v] += delta; } else{ // sum[v] = getVal(v,tl,tr); add[2*v ] += add[v]; add[2*v+1] += add[v]; add[v] = 0; int tm = (tl + tr) / 2; add( delta, l, min(r,tm), 2*v , tl, tm ); add( delta, max(tm+1,l), r, 2*v+1, tm+1, tr ); sum[v] = getVal(2*v,tl,tm) + getVal(2*v+1,tm+1,tr); } } long getSum( int l, int r ){ return getSum( l, r, 1,0,n-1 ); } long getSum( int l, int r, int v, int tl, int tr ){ if( l > r ) return 0; if( l == tl && r == tr ){ return getVal(v,tl,tr); } else{ sum[v] = getVal(v,tl,tr); add[2*v ] += add[v]; add[2*v+1] += add[v]; add[v] = 0; int tm = (tl + tr) / 2; return getSum( l, min(r,tm), 2*v , tl, tm ) + getSum( max(tm+1,l), r, 2*v+1, tm+1, tr ); } } } class Painter{ int n; int[] color; Adder add; Painter( int _n ){ n = _n; color = new int[4*n]; fill( color, -1 ); build( 1,0,n-1 ); add = new Adder(n); } void build( int v, int tl, int tr ){ if( tl == tr ){ color[v] = tl; } else{ int tm = (tl + tr) / 2; build( 2*v , tl, tm ); build( 2*v+1, tm+1, tr ); color[v] = -1; } } void pain( int clr, int l, int r ){ pain( clr, l, r, 1,0,n-1 ); } void pain( int clr, int l, int r, int v, int tl, int tr ){ if( l > r ) return; if( l == tl && r == tr && color[v] != -1 ){ add.add( abs( color[v] - clr ), l, r ); // err.printf( "%2d %2d: %2d\n", l, r, abs( color[v] - clr ) ); color[v] = clr; } else{ if( color[v] != -1 ){ color[2*v] = color[2*v+1] = color[v]; } int tm = (tl + tr) / 2; pain( clr, l, min(r,tm), 2*v , tl, tm ); pain( clr, max(tm+1,l), r, 2*v+1, tm+1, tr ); color[v] = color[2*v] == color[2*v+1]? color[2*v] : -1; } } } void solve(){ int n, m; Painter paint; n = sc.nextInt(); m = sc.nextInt(); paint = new Painter(n+1); for (int iter = 0; iter < m; iter++) { int op = sc.nextInt(); if ( op == 1 ){ int l = sc.nextInt(); int r = sc.nextInt(); int x = sc.nextInt(); paint.pain(x,l,r); } else if( op == 2 ){ int l = sc.nextInt(); int r = sc.nextInt(); out.println( paint.add.getSum(l,r) ); } else MLE(); } } }
Java
["3 3\n1 1 2 4\n1 2 3 5\n2 1 3", "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3", "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10"]
2 seconds
["8", "3\n2\n1", "129"]
NoteIn the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0].After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0].After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2].So the answer to the only operation of type 2 is 8.
Java 8
standard input
[ "data structures" ]
562656bfc27b7cf06f7c4a373c6bc029
The first line contains two space-separated integers n, mΒ (1 ≀ n, m ≀ 105). Each of the next m lines begins with a integer typeΒ (1 ≀ type ≀ 2), which represents the type of this operation. If type = 1, there will be 3 more integers l, r, xΒ (1 ≀ l ≀ r ≀ n;Β 1 ≀ x ≀ 108) in this line, describing an operation 1. If type = 2, there will be 2 more integers l, rΒ (1 ≀ l ≀ r ≀ n) in this line, describing an operation 2.
2,400
For each operation 2, print a line containing the answer β€” sum of colorfulness.
standard output
PASSED
dfbf5a7237180d50769714e22f731e0c
train_000.jsonl
1404651900
DZY loves colors, and he enjoys painting.On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). The color of the i-th unit of the ribbon is i at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first.DZY loves painting, we know. He takes up a paintbrush with color x and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit i currently is y. When it is painted by this paintbrush, the color of the unit becomes x, and the colorfulness of the unit increases by |x - y|.DZY wants to perform m operations, each operation can be one of the following: Paint all the units with numbers between l and r (both inclusive) with color x. Ask the sum of colorfulness of the units between l and r (both inclusive). Can you help DZY?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Don Li */ public class DZYLovesColors { void solve() { int n = in.nextInt(), m = in.nextInt(); SegmentTree seg = new SegmentTree(n); while (m-- > 0) { int t = in.nextInt(), l = in.nextInt() - 1, r = in.nextInt(); if (t == 1) { int x = in.nextInt(); seg.update(l, r, x); } else { out.println(seg.query(l, r)); } } } static class SegmentTree { int n; int[] color; long[] sum, lazy; SegmentTree(int m) { int x = 0; while ((1 << x) < m) x++; n = 1 << x; color = new int[2 * n - 1]; for (int i = 0; i < m; i++) { color[n - 1 + i] = i + 1; } sum = new long[2 * n - 1]; lazy = new long[2 * n - 1]; } void update(int a, int b, int x) { update(a, b, x, 0, 0, n); } void update(int a, int b, int x, int k, int l, int r) { if (a >= r || b <= l) return; if (color[k] == 0) { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); sum[k] = sum[2 * k + 1] + ((l + r) / 2 - l) * lazy[2 * k + 1] + sum[2 * k + 2] + (r - (l + r) / 2) * lazy[2 * k + 2]; if (a <= l && r <= b) color[k] = x; return; } if (a <= l && r <= b) { lazy[k] += Math.abs(x - color[k]); color[k] = x; return; } color[2 * k + 1] = color[k]; color[2 * k + 2] = color[k]; color[k] = 0; update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); sum[k] = sum[2 * k + 1] + ((l + r) / 2 - l) * lazy[2 * k + 1] + sum[2 * k + 2] + (r - (l + r) / 2) * lazy[2 * k + 2]; } long query(int a, int b) { return query(a, b, 0, 0, n); } long query(int a, int b, int k, int l, int r) { if (a >= r || b <= l) return 0; if (a <= l && r <= b) return sum[k] + lazy[k] * (r - l); lazy[2 * k + 1] += lazy[k]; lazy[2 * k + 2] += lazy[k]; lazy[k] = 0; long ans = query(a, b, 2 * k + 1, l, (l + r) / 2) + query(a, b, 2 * k + 2, (l + r) / 2, r); sum[k] = sum[k] = sum[2 * k + 1] + ((l + r) / 2 - l) * lazy[2 * k + 1] + sum[2 * k + 2] + (r - (l + r) / 2) * lazy[2 * k + 2]; return ans; } } public static void main(String[] args) { in = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); new DZYLovesColors().solve(); out.close(); } static FastScanner in; static PrintWriter out; static class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } } }
Java
["3 3\n1 1 2 4\n1 2 3 5\n2 1 3", "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3", "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10"]
2 seconds
["8", "3\n2\n1", "129"]
NoteIn the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0].After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0].After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2].So the answer to the only operation of type 2 is 8.
Java 8
standard input
[ "data structures" ]
562656bfc27b7cf06f7c4a373c6bc029
The first line contains two space-separated integers n, mΒ (1 ≀ n, m ≀ 105). Each of the next m lines begins with a integer typeΒ (1 ≀ type ≀ 2), which represents the type of this operation. If type = 1, there will be 3 more integers l, r, xΒ (1 ≀ l ≀ r ≀ n;Β 1 ≀ x ≀ 108) in this line, describing an operation 1. If type = 2, there will be 2 more integers l, rΒ (1 ≀ l ≀ r ≀ n) in this line, describing an operation 2.
2,400
For each operation 2, print a line containing the answer β€” sum of colorfulness.
standard output
PASSED
8a583c0201e9ba0a00695dcfd3d40d6b
train_000.jsonl
1404651900
DZY loves colors, and he enjoys painting.On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). The color of the i-th unit of the ribbon is i at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first.DZY loves painting, we know. He takes up a paintbrush with color x and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit i currently is y. When it is painted by this paintbrush, the color of the unit becomes x, and the colorfulness of the unit increases by |x - y|.DZY wants to perform m operations, each operation can be one of the following: Paint all the units with numbers between l and r (both inclusive) with color x. Ask the sum of colorfulness of the units between l and r (both inclusive). Can you help DZY?
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class E { static int n, b, bS; static long[][] blocks, colorfull; static long[] color, extra, total; static void fix(int b, int l, int r, int c) { if(color[b] != -1) { for (int j = 0; j < bS; j++) { blocks[b][j] = color[b]; colorfull[b][j] += extra[b]; } color[b] = -1; extra[b] = 0; } if(c != -1) { for (int j = l; j <= r; j++) { colorfull[b][j] += Math.abs(blocks[b][j] - c); total[b] += Math.abs(blocks[b][j] - c); blocks[b][j] = c; } } } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); n = sc.nextInt(); int q = sc.nextInt(); bS = (int) Math.sqrt(n + 1); b = (n + bS - 1) / bS; blocks = new long[b][bS]; colorfull = new long[b][bS]; color = new long[b]; Arrays.fill(color, -1); extra = new long[b]; total = new long[b]; for (int i = 0; i < b; i++) { for (int j = 0; j < bS && i * bS + j < n; j++) { blocks[i][j] = i * bS + j + 1; colorfull[i][j] = 0; } } for (int i = 0; i < q; i++) { int t = sc.nextInt(); int l = sc.nextInt() - 1; int r = sc.nextInt() - 1; int lB = l / bS; int rB = r / bS; int lI = l % bS; int rI = r % bS; if(t == 1) { int c = sc.nextInt(); if(lB == rB) { fix(lB, lI, rI, c); }else { fix(lB, lI, bS - 1, c); fix(rB, 0, rI, c); for (int j = lB + 1; j < rB; j++) { if(color[j] == -1) { fix(j, 0, bS - 1, c); color[j] = c; extra[j] = 0; }else { extra[j] += Math.abs(color[j] - c); total[j] += Math.abs(color[j] - c) * bS; color[j] = c; } } } }else { if(lB == rB) { fix(lB, lI, rI, -1); long ans = 0; for (int j = lI; j <= rI; j++) ans += colorfull[lB][j]; out.println(ans); }else { fix(lB, lI, bS - 1, -1); fix(rB, 0, rI, -1); long ans = 0; for (int j = lI; j < bS; j++) ans += colorfull[lB][j]; for (int j = 0; j <= rI; j++) ans += colorfull[rB][j]; for (int j = lB + 1; j < rB; j++) ans += total[j]; out.println(ans); } } } out.flush(); out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public Scanner(String file) throws FileNotFoundException{ br = new BufferedReader(new FileReader(file));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
Java
["3 3\n1 1 2 4\n1 2 3 5\n2 1 3", "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3", "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10"]
2 seconds
["8", "3\n2\n1", "129"]
NoteIn the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0].After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0].After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2].So the answer to the only operation of type 2 is 8.
Java 8
standard input
[ "data structures" ]
562656bfc27b7cf06f7c4a373c6bc029
The first line contains two space-separated integers n, mΒ (1 ≀ n, m ≀ 105). Each of the next m lines begins with a integer typeΒ (1 ≀ type ≀ 2), which represents the type of this operation. If type = 1, there will be 3 more integers l, r, xΒ (1 ≀ l ≀ r ≀ n;Β 1 ≀ x ≀ 108) in this line, describing an operation 1. If type = 2, there will be 2 more integers l, rΒ (1 ≀ l ≀ r ≀ n) in this line, describing an operation 2.
2,400
For each operation 2, print a line containing the answer β€” sum of colorfulness.
standard output
PASSED
b8391e612164eb525881bb9487e3ac12
train_000.jsonl
1291046400
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king.
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main { // 10:29 ~ 11:14 public static void main(String[] arg) { FastScanner scan = null; PrintWriter out = null; try{ scan = new FastScanner(new FileInputStream("input.txt")); out = new PrintWriter(new FileOutputStream("output.txt")); }catch(FileNotFoundException e){ scan = new FastScanner(System.in); out = new PrintWriter(System.out); } int n = scan.nextInt(); int m = scan.nextInt(); int x = 1, y = 1; List<Integer> ret = new ArrayList<Integer>(); if(m % 2 == 0){ for(int i = 1; i <= m; i++){ y = i; ret.add(x * 101 + y); } } else { for(int i = 1; i <= n; i++){ x = i; ret.add(x * 101 + y); } } if(m % 2 == 0){ int d = 1; for(int i = m; i >= 1; i--){ if(d == 1){ for(int j = 2; j <= n; j++){ x = j; ret.add(x * 101 + y); } d = -1; } else { for(int j = n; j >= 2; j--){ x = j; ret.add(x * 101 + y); } d = 1; } y--; } y++; x--; } else { int d = 1; for(int i = n; i >= 1; i--){ if(d == 1){ y++; for(; y <= m; y++){ ret.add(x * 101 + y); } d = -1; } else { y--; for(; y >= 2; y--){ ret.add(x * 101 + y); } d = 1; } x--; } x++; y--; } if(n == 1 || m == 1){ if((n == 1 && m == 2) || (n == 2 && m == 1)){ out.println("0"); } else { out.println("1"); if(n == 1) { out.println("1 " + m + " 1 1"); } else { out.println(n + " 1 1 1"); } } } else if((n % 2 == 0 || m % 2 == 0)) out.println("0"); else { out.println("1"); out.println(x + " " + y + " 1 1"); } for(Integer r : ret){ out.println((r / 101) + " " + (r % 101)); } out.println("1 1"); out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream is) { try { br = new BufferedReader(new InputStreamReader(is)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { return null; } } return st.nextToken(); } String nextLine() { try { return br.readLine(); } catch (Exception e) { return null; } } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.valueOf(next()); } } }
Java
["2 2", "3 3"]
2 seconds
["0\n1 1\n1 2\n2 2\n2 1\n1 1", "1\n3 3 1 1\n1 1\n1 2\n1 3\n2 3\n2 2\n2 1\n3 1\n3 2\n3 3\n1 1"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "brute force" ]
a98622d5b6d6d139df90b6fee3baa544
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀  n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m).
2,000
On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time.
standard output
PASSED
1c947a3009ec7a1f2500a71cb1f4ecb1
train_000.jsonl
1291046400
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king.
256 megabytes
import java.util.Scanner; public class d43 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x = in.nextInt(); int y = in.nextInt(); if (x == 1 && y !=2) { System.out.printf("1\n1 %d 1 1\n", y); for (int i = 1; i <= y; i++) { System.out.printf("1 %d\n", i); } } else if (y == 1 && x !=2) { System.out.printf("1\n%d 1 1 1\n", x); for (int i = 1; i <= x; i++) { System.out.printf("%d 1\n", i); } } else { boolean needTele = (x * y) % 2 == 1; boolean swapDir = !needTele && (x % 2 == 1); System.out.println(needTele ? 1 : 0); if (needTele) System.out.printf("1 %d 1 1\n", y); if (swapDir) { for (int i = 0; i < y; i++) { System.out.printf("1 %d\n", i + 1); } for (int i = 1; i < x; i++) { System.out.printf("%d %d\n", i + 1, y); } for (int i = 1; i < y; i++) { int currY = y - i; if (i % 2 == 0) { for (int j = 2; j <= x; j++) { System.out.printf("%d %d\n", j, currY); } } else { for (int j = x; j >= 2; j--) { System.out.printf("%d %d\n", j, currY); } } } } else { for (int i = 0; i < x; i++) { System.out.printf("%d 1\n", i + 1); } for (int i = 1; i < y; i++) { System.out.printf("%d %d\n", x, i + 1); } for (int i = 1; i < x; i++) { int currX = x - i; if (i % 2 == 0) { for (int j = 2; j <= y; j++) { System.out.printf("%d %d\n", currX, j); } } else { for (int j = y; j >= 2; j--) { System.out.printf("%d %d\n", currX, j); } } } } } System.out.println("1 1"); } }
Java
["2 2", "3 3"]
2 seconds
["0\n1 1\n1 2\n2 2\n2 1\n1 1", "1\n3 3 1 1\n1 1\n1 2\n1 3\n2 3\n2 2\n2 1\n3 1\n3 2\n3 3\n1 1"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "brute force" ]
a98622d5b6d6d139df90b6fee3baa544
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀  n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m).
2,000
On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time.
standard output
PASSED
87b705868183f22f6f3092b48feb071f
train_000.jsonl
1291046400
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king.
256 megabytes
import java.util.Scanner; public class P43D { public P43D() { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int m = sc.nextInt(); sc.close(); if (n == 1){ if (m == 2){ System.out.println(0); System.out.println(1 + " " + 1); System.out.println(1 + " " + 2); System.out.println(1 + " " + 1); } else { System.out.println(1); System.out.println(1 + " " + m + " " + 1 + " " + 1); for (int j = 1; j <= m; j++){ System.out.println(1 + " " + j); } System.out.println(1 + " " + 1); } } else if (m == 1){ if (n == 2){ System.out.println(0); System.out.println(1 + " " + 1); System.out.println(2 + " " + 1); System.out.println(1 + " " + 1); } else { System.out.println(1); System.out.println(n + " " + 1 + " " + 1 + " " + 1); for (int i = 1; i <= n; i++){ System.out.println(i + " " + 1); } System.out.println(1 + " " + 1); } } else if (m % 2 == 0){ System.out.println(0); System.out.println(1 + " " + 1); for (int j = 1; j <= m; j++){ if (j % 2 == 1){ for (int i = 2; i <= n; i++){ System.out.println(i + " " + j); } } else { for (int i = n; i >= 2; i--){ System.out.println(i + " " + j); } } } for (int j = m; j >= 1; j--){ System.out.println(1 + " " + j); } } else if (n % 2 == 0){ System.out.println(0); System.out.println(1 + " " + 1); for (int i = 1; i <= n; i++){ if (i % 2 == 1){ for (int j = 2; j <= m; j++){ System.out.println(i + " " + j); } } else { for (int j = m; j >= 2; j--){ System.out.println(i + " " + j); } } } for (int i = n; i >= 1; i--){ System.out.println(i + " " + 1); } } else { System.out.println(1); System.out.println(n + " " + m + " " + 1 + " " + 1); for (int j = 1; j <= m; j++){ if (j % 2 == 1){ for (int i = 1; i <= n; i++){ System.out.println(i + " " + j); } } else { for (int i = n; i >= 1; i--){ System.out.println(i + " " + j); } } } System.out.println(1+ " " + 1); } } public static void main (String []args){ new P43D(); } }
Java
["2 2", "3 3"]
2 seconds
["0\n1 1\n1 2\n2 2\n2 1\n1 1", "1\n3 3 1 1\n1 1\n1 2\n1 3\n2 3\n2 2\n2 1\n3 1\n3 2\n3 3\n1 1"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "brute force" ]
a98622d5b6d6d139df90b6fee3baa544
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀  n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m).
2,000
On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time.
standard output
PASSED
7642731c12a66741dce5d23c02cf2dcf
train_000.jsonl
1291046400
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king.
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Zyflair Griffane */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; PandaScanner in = new PandaScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); D solver = new D(); solver.solve(1, in, out); out.close(); } } class D { public void solve(int testNumber, PandaScanner in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); if ((n == 1 && m == 2) || (n == 2 && m == 1)) { out.println("0"); out.println("1 1"); out.println(n + " " + m); out.println("1 1"); } else if (n % 2 == 0 && m > 1) { out.println("0"); out.println("1 1"); for (int i = 1; i <= n; i += 2) { for (int j = 2; j <= m; j++) { out.printf("%d %d\n", i, j); } for (int j = m; j >= 2; j--) { out.printf("%d %d\n", i + 1, j); } } for (int i = n; i >= 1; i--) { out.println(i + " 1"); } } else if (m % 2 == 0 && n > 1) { out.println("0"); out.println("1 1"); for (int i = 1; i <= m; i += 2) { for (int j = 2; j <= n; j++) { out.printf("%d %d\n", j, i); } for (int j = n; j >= 2; j--) { out.printf("%d %d\n", j, i + 1); } } for (int i = m; i >= 1; i--) { out.println("1 " + i); } } else { out.println("1"); out.println(n + " " + m + " 1 1"); for (int i = 1; i <= n; i += 2) { for (int j = 1; j <= m; j++) { out.printf("%d %d\n", i, j); } if (i + 1 <= n) { for (int j = m; j >= 1; j--) { out.printf("%d %d\n", i + 1, j); } } } out.println("1 1"); } } } class PandaScanner { public BufferedReader br; public StringTokenizer st; public InputStream in; public PandaScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(this.in = in)); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { return null; } } public String next() { if (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(nextLine().trim()); return next(); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["2 2", "3 3"]
2 seconds
["0\n1 1\n1 2\n2 2\n2 1\n1 1", "1\n3 3 1 1\n1 1\n1 2\n1 3\n2 3\n2 2\n2 1\n3 1\n3 2\n3 3\n1 1"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "brute force" ]
a98622d5b6d6d139df90b6fee3baa544
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀  n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m).
2,000
On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time.
standard output