exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
47490914c4a562dd95d753f3cbe3ebf2
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class Sample { static int[][][] dp; static int[] are; public static void main(String[] args) throws InterruptedException { Thread t=new Thread(null, null,"", 1<<28) { public void run() { m(); } }; t.start(); t.join(); } public static void m() { FastScanner in=new FastScanner(); int tt = in.nextInt(); while(tt-->0) { int n = in.nextInt(); int[] are = in.readArray(n); // if(n<2) { System.out.println("T"); continue; } // sort(are); int sum=0; for(int i=0; i<n; i++) sum+=are[i]; // if((2*are[n-1])>sum) {System.out.println("T");} else { if(sum%2==0) {System.out.println("HL");} else {System.out.println("T");} } } } /* 1 5 01101 10101 */ static void print(String[] are) { for(int i=0; i<are.length; i++) System.out.print(are[i]); System.out.println(); } static void sort(int[] a) { ArrayList<Integer> list=new ArrayList<>(); for (int i:a) list.add(i); Collections.sort(list); for (int i=0; i<a.length; i++) a[i]=list.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } public long nextLong() { return Long.parseLong(next()); } public long[] readLongArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
c50c103a6490fe6d9cd836400e007118
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.util.*; public class CF1397D extends PrintWriter { CF1397D() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1397D o = new CF1397D(); o.main(); o.flush(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int x = 0, s = 0, p = 0; while (n-- > 0) { int a = sc.nextInt(); x = Math.max(x, a); s += a; p ^= a & 1; } println(x + x > s || p == 1 ? "T" : "HL"); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
33505ffb4cf37d3458474842e54bbeb2
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { FastScanner in=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=in.nextInt(); while(t-->0) solve(in,out); out.close(); } static int gcd(int a,int b){ if(b==0) return a; else return gcd(b,a%b); } static void solve(FastScanner in,PrintWriter out){ int n=in.nextInt(); int a[]=new int[n]; long s=0,max=0; for(int i=0;i<n;i++){ a[i]=in.nextInt(); s+=a[i]; max=Math.max(max,a[i]); } if(s-max<max) out.println("T"); else{ if(s%2==0) out.println("HL"); else out.println("T"); } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
17adcb1f922771458a8e4c630ee48362
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; public class q2 { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int tt=0;tt<t;tt++) { int n=s.nextInt(); int a[]=new int[n]; int sum=0,max=Integer.MIN_VALUE; for(int i=0;i<n;i++) { a[i]=s.nextInt(); sum=sum+a[i]; if(a[i]>max) { max=a[i]; } } if(2*max>sum) { System.out.println("T"); }else { if(sum%2==0) { System.out.println("HL"); }else { System.out.println("T"); } } } s.close(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
da66ef963ef957908574b920397980cc
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; public class JavaApplication94 { public static void main(String[] args) { // TODO code application logic here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); int a[]=new int[n]; int sum=0; int max=0; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); if(a[i]>max) max=a[i]; sum+=a[i]; } if(n==1) System.out.println("T"); else if(n==2) { if(a[0]!=a[1]) System.out.println("T"); else System.out.println("HL"); } else { if(max>sum-max) System.out.println("T"); else if(sum%2==0) System.out.println("HL"); else System.out.println("T"); } } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
398517ddb65f80578ac9402d67640aa4
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } void solve(Scanner in, PrintWriter out) { int tests = in.nextInt(); for (int test = 0; test < tests; test++) { int n = in.nextInt(); long s = 0; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int value = in.nextInt(); s += value; max = Math.max(max, value); } if (s % 2 == 1 || (long) 2 * max > s) out.println("T"); else out.println("HL"); } } void run() { try ( Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out) ) { solve(in, out); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
7e159ff371fc3025f29b8a621d77161a
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int mod = (int)(1e9+7); public static long pow(long a,long b) { long ans = 1; while(b> 0) { if((b & 1)==1){ ans = (ans*a) % mod; } a = (a*a) % mod; b = b>>1; } return ans; } public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int t = in.nextInt(); while(t-- >0) { int n = in.nextInt(); int[] arr = in.nextIntArray(n); Arrays.sort(arr); int sum = Arrays.stream(arr).sum(); if(arr[n-1]+arr[n-1]>sum) { out.printLine("T"); } else { if(sum%2==0) { out.printLine("HL"); }else { out.printLine("T"); } } } out.flush(); out.close(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
6ceda298fc79eb72cd81215f04b65b70
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.PriorityQueue; import java.util.StringTokenizer; public class D { static boolean solve(int[] arr, int prev) { int max = 0; int maxInd = -1; for(int i = 0; i < arr.length; i++) { if(i == prev) continue; if(arr[i] > max) { max = arr[i]; maxInd = i; } } if(maxInd == -1) { return false; } arr[maxInd]--; return !solve(arr, maxInd); } public static void main(String[] args) { FastReader reader = new FastReader(); int tests = reader.nextInt(); for(int test = 1; test <= tests; test++) { int n = reader.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) { int v = reader.nextInt(); arr[i] = v; } if(solve(arr, -1)) { System.out.println("T"); } else { System.out.println("HL"); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
867e952e0e697aebc87eba43519e9c06
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
/** * @author vivek * programming is thinking, not typing */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class D { private static void solveTC(int __) { /* For Google */ // ans.append("Case #").append(__).append(": "); //code start int n= scn.nextInt(); PriorityQueue<Integer> queue=new PriorityQueue<>(n, Collections.reverseOrder()); for (int i = 0; i < n; i++) { queue.add(scn.nextInt()); } boolean turn=true; int saved=1; while (!queue.isEmpty()){ int tempSaved=queue.remove(); if (saved!=1){ queue.add(saved-1); } saved=tempSaved; turn=!turn; } print(turn?"HL":"T"); //code end print("\n"); } /** * Don't copy other's templates, make your own <br> * It would be much more beneficial */ public static void main(String[] args) { scn = new Scanner(); ans = new StringBuilder(); int t = scn.nextInt(); // int t = 1; // int limit= ; // sieve(limit); /* try { System.setOut(new PrintStream(new File("file_i_o\\output.txt"))); } catch (FileNotFoundException e) { e.printStackTrace(); } */ for (int i = 1; i <= t; i++) { solveTC(i); } System.out.print(ans); } //Stuff for prime start /** * List containing prime numbers <br> * <b>i<sup>th</sup></b> position contains <b>i<sup>th</sup></b> prime number <br> * 0th index is <b>null</b> */ private static ArrayList<Integer> listOfPrimes; /** * query <b>i<sup>th</sup></b> element to get if its prime of not */ private static boolean[] isPrime; /** * Performs Sieve of Erathosnesis and initialise isPrime array and listOfPrimes list * * @param limit the number till which sieve is to be performed */ private static void sieve(int limit) { listOfPrimes = new ArrayList<>(); listOfPrimes.add(null); boolean[] array = new boolean[limit + 1]; Arrays.fill(array, true); array[0] = false; array[1] = false; for (int i = 2; i <= limit; i++) { if (array[i]) { for (int j = i * i; j <= limit; j += i) { array[j] = false; } } } isPrime = array; for (int i = 0; i <= limit; i++) { if (array[i]) { listOfPrimes.add(i); } } } //stuff for prime end /** * Calculates the Least Common Multiple of two numbers * * @param a First number * @param b Second Number * @return Least Common Multiple of <b>a</b> and <b>b</b> */ private static long lcm(long a, long b) { return a * b / gcd(a, b); } /** * Calculates the Greatest Common Divisor of two numbers * * @param a First number * @param b Second Number * @return Greatest Common Divisor of <b>a</b> and <b>b</b> */ private static long gcd(long a, long b) { return (b == 0) ? a : gcd(b, a % b); } static void print(Object obj) { ans.append(obj.toString()); } static Scanner scn; static StringBuilder ans; //Fast Scanner static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); /* try { br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt")))); } catch (FileNotFoundException e) { e.printStackTrace(); } */ } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } Integer[] nextIntegerArray(int n) { Integer[] array = new Integer[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } String[] nextStringArray() { return nextLine().split(" "); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = next(); } return array; } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
af8104294d4cf9997b028bf2a80c4957
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.Scanner; public class D { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while (t-- > 0) { int n = scn.nextInt(); int arr[] = new int[n]; int max = Integer.MIN_VALUE; int sum = 0; for (int i = 0; i < n; i++) { arr[i] = scn.nextInt(); max = Math.max(max, arr[i]); sum += arr[i]; } if (max > sum - max) { System.out.println("T"); } else { if (sum % 2 == 1) System.out.println("T"); else System.out.println("HL"); } } scn.close(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
449b04c8354ceea8796d2cb0c82f21aa
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; public class Codeforces { static Scanner sc = new Scanner(System.in); void solve() { try { int rounds = sc.nextInt(); for (int i = 0; i < rounds; i++) { int length = sc.nextInt(); int arr[] = new int[length]; int sum = 0; for (int j = 0; j < length; j++) { arr[j] = sc.nextInt(); sum += arr[j]; } Arrays.sort(arr); int max = arr[length - 1]; if ((max > (sum - max)) || (sum % 2 != 0)) // if the number of stones is even, HL will try to make the // last pair equal to defeat T. System.out.println("T"); else System.out.println("HL"); } } catch (Exception e) { return; } } public static void main(String[] args) { Codeforces ob = new Codeforces(); ob.solve(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
53866009fc63008e9ead739d0c0793c7
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; import java.io.*; public class D { static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static void solve(){ int n = sc.nextInt(); int[] arr = new int[n]; int sum = 0; for (int i = 0; i < n; i ++){ arr[i] = sc.nextInt(); sum += arr[i]; } Arrays.sort(arr); if (arr.length == 1){ pw.println("T"); return; } if (arr.length == 2){ if (arr[0] == arr[1]){ pw.println("HL"); } else { pw.println("T"); } return; } int x = sum - arr[n - 1] - n + 1; if (arr[n - 1] - 1 > x){ if (arr[n - 1] - x > n - 1){ pw.println("T"); } else { if ((n - arr[n - 1] + 1) % 2 == 0){ pw.println("HL"); } else { pw.println("T"); } } } else { int turn = (sum - n) % 2; if (turn == 0 && n % 2 == 1){ pw.println("T"); } if (turn == 0 && n % 2 == 0){ pw.println("HL"); } if (turn == 1 && n % 2 == 1){ pw.println("HL"); } if (turn == 1 && n % 2 == 0){ pw.println("T"); } } } public static void main(String[] args){ int t = sc.nextInt(); for (int i = 0; i < t; i ++){ solve(); } // solve(); pw.close(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
05a9e29b6b3130d3793207987b263fcf
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class TaskD { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); // Start writing your solution here. ------------------------------------- /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String int result = 3*n; out.println(result); // print via PrintWriter */ // Stop writing your solution here. ------------------------------------- int tests = sc.nextInt(); outer: for (int x=0; x<tests; x++) { int n = sc.nextInt(); List<Integer> st = new ArrayList<>(n) ; for (int i=0; i<n; i++) { st.add(i, sc.nextInt()); } if (n == 1) { out.println("T"); continue outer; } // int lastT = -1; int lastHL = -1; while (true) { int max = 0; for (int i=0; i<n; i++) { if (st.get(i) > max && i != lastHL) { max = st.get(i); lastT = i; } } if (max == 0) { out.println("HL"); continue outer; } st.set(lastT, max-1); max = 0; for (int i=0; i<n; i++) { if (st.get(i) > max && i != lastT) { max = st.get(i); lastHL = i; } } if (max == 0) { out.println("T"); continue outer; } st.set(lastHL, max-1); } } out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
217e07eeb3ed55551e944706339f5513
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; import java.io.*; public class Q3 { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int z=0;z<t;z++){ int n = Integer.parseInt(br.readLine()); int arr[] = new int[n]; StringTokenizer st = new StringTokenizer(br.readLine()); for(int i =0;i<n;i++){ arr[i]=Integer.parseInt(st.nextToken()); } int res = play(arr); if(res==1) System.out.println("HL"); else System.out.println("T"); } } public static int play(int arr[]){ Arrays.sort(arr); int n = arr.length; if(n==1) return 0; if(arr[n-2]==0){ if(arr[arr.length-1]==0) return 1; else return 0; } if(arr[arr.length-1]==1){ int i = arr.length-1; int c = 0; while( i>=0 && arr[i]==1){ c++; i--; } if(c%2==0) return 1; else return 0; } int first = arr[n-1]; int second = n>=2?arr[n-2]:0; int third = n>=3?arr[n-3]:0; int reduce = Math.max(1,first-third); if(second<reduce) reduce = 1; arr[n-1]-=reduce; arr[n-2]-=reduce; return play(arr); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
d699cc353a2d23fee18410ad2ab537b7
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class Main { public static void main(String[] args) { var sc = new Scanner(System.in); int T = Integer.parseInt(sc.next()); var pw = new PrintWriter(System.out); for(int t = 0; t < T; t++){ int n = Integer.parseInt(sc.next()); var a = new int[n]; int sum = 0; int max = 0; for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(sc.next()); sum += a[i]; max = Math.max(a[i], max); } if(n >= 2){ if(sum%2 == 1){ pw.println("T"); }else if(max > (sum - max)){ pw.println("T"); }else{ pw.println("HL"); } }else{ pw.println("T"); } } pw.flush(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
3dde2b5aeb12d64ef35fa0e63e492ec2
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Round_666D2P4 { static final FS sc = new FS(); static final PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int[] a = sc.nextArray(n); int sum = 0; for(int i=0; i<n; i++) sum += a[i]; int sb2 = sum/2; int eo = sum%2; boolean isyes = false; for(int i=0; i<n; i++){ if(a[i]>sb2){ isyes = true; break; } } if((!isyes && eo==1) || isyes){ System.out.println("T"); } else{ System.out.println("HL"); } } } static class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception ignored) { } } return st.nextToken(); } int[] nextArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
8b177321a15599deeefe85e5260676f5
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.util.*; public class maxheap { int[][] heap; int size; public maxheap(int capacity){ size = 0; heap = new int[2][capacity+1]; for (int[] row : heap) Arrays.fill(row, -1); // Arrays.fill(heap,-1); } int getparentindex(int pos) { return (pos-1)/2;} int getleftindex(int pos) { return 2*pos+1;} int getrightindex(int pos) { return 2*pos+2;} int leftchild(int pos) { return heap[0][getleftindex(pos)];} int rightchild(int pos) { return heap[0][getrightindex(pos)];} int parent(int pos) { return heap[0][getparentindex(pos)];} boolean hasleftchild(int pos) { return getleftindex(pos)<size;} boolean hasrightchild(int pos) { return getrightindex(pos)<size;} boolean hasparent(int pos) {return getparentindex(pos)>=0;} void swap(int i1,int i2){ int temp=heap[0][i1]; heap[0][i1]=heap[0][i2]; heap[0][i2]=temp; int temp2=heap[1][i1]; heap[1][i1]=heap[1][i2]; heap[1][i2]=temp2; } int peek(){ if(size==0) throw new IllegalStateException(); return heap[0][0]; } int[] deletemax(){ if(size==0) throw new IllegalStateException(); int item[]=new int[2]; item[0]=heap[0][0]; item[1]=heap[1][0]; heap[0][0]=heap[0][size-1]; heap[1][0]=heap[1][size-1]; size--; heapifydown(); return item; } void insert(int value,int index){ heap[0][size]=value; heap[1][size]=index; size++; heapifyup(); } void heapifyup(){ int index=size-1; while(hasparent(index) && parent(index)<heap[0][index]){ swap(getparentindex(index),index); index=getparentindex(index); } } void heapifydown(){ int index=0; while(hasleftchild(index)){ int smaller=getleftindex(index); if(hasrightchild(index) && rightchild(index)>leftchild(index)){ smaller=getrightindex(index); } if(heap[0][index]>heap[0][smaller]) break; else{ swap(index,smaller); index=smaller; } } } public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int test=0;test<t;test++){ int n=sc.nextInt(); maxheap a=new maxheap(n); int arr[]=new int[n]; for(int i=0;i<n;i++){ int x=sc.nextInt(); a.insert(x,i); arr[i]=x; } int check=0; int flag=0; int a1=-1; int a2=-1; while(a.peek()!=0 && n!=1){ int y[]=a.deletemax(); if(check==0){ if(y[1]==a2){ int z[]=a.deletemax(); if(z[0]==0 && flag==0){ flag=2; } a1=z[1]; int count1=y[0]; a.insert(count1-1,y[1]); a.insert(z[0]-1,z[1]); } else{ a1=y[1]; int count1=y[0]; a.insert(count1-1,a1); } check=1; } else{ if(y[1]==a1){ int z[]=a.deletemax(); if(z[0]==0 && flag==0){ flag=1; } a2=z[1]; int count2=y[0]; a.insert(count2-1,y[1]); a.insert(z[0]-1,z[1]); } else{ a2=y[1]; int count2=y[0]; a.insert(count2-1,a2); check=0; } } } if(check==0 && n!=1 && (flag==0|| flag==2)){ System.out.println("HL"); } else{ System.out.println("T"); } } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
c854aa52c3b86c058cfcc4180dd27bf1
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.Scanner; public class D { static Scanner sc = new Scanner(System.in); static StringBuilder ans = new StringBuilder(); static int t; static int n; static int[] a; static int lastpick; static boolean PlayerA; public static void main(String[] args){ t = sc.nextInt(); for (int i=0;i<t;i++){ Solve(); } System.out.println(ans); } public static void Solve(){ n = sc.nextInt(); lastpick = -1; PlayerA = true; a = new int[n]; for (int i=0;i<n;i++){ a[i] = sc.nextInt(); } while (true){ // System.out.println("R"+ i++); if (!subMax()){ if (PlayerA){ System.out.println("HL"); break; }else { System.out.println("T"); break; } } PlayerA = !PlayerA; } } public static boolean subMax(){ int maxi =0; for (int i=0;i<n;i++){ if ((a[i]>a[maxi]&&i!=lastpick)||maxi==lastpick){ maxi = i; } } if (a[maxi]!=0&&maxi!=lastpick){ a[maxi]--; lastpick = maxi; return true; }else { return false; } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
d63d02a4623fe2a41561316410a4ed42
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.util.*; // Author- Prashant Gupta public class D { public static void main(String[] args) throws IOException { // write your code here PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); // Scanner sc = new Scanner(System.in); Reader sc = new Reader(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] a = new int[n]; int sum = 0; for (int i = 0; i < a.length; i++) { a[i] = sc.nextInt(); sum += a[i]; } if (n == 1) { out.println("T"); continue; } Arrays.sort(a); sum -= a[n - 1]; if (a[n - 1] > sum || (sum + a[n -1]) % 2 == 1) { out.println("T"); } else { out.println("HL"); } } out.close(); } /*-------------------------------------------------------------------------------------*/ public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long power(long x, long y) { long res = 1; while (x > 0) { if (y % 2 == 0) { x *= x; y /= 2; } else { res *= x; y--; } } return res; } public static long lcm(long x, long y) { return (x * y) / gcd(x, y); } public static int lowerBound(Vector<Integer> v, int e) { int start = 0, end = v.size() - 1, ind = -1; while (start <= end) { int mid = (start + end) / 2; if (v.get(mid) == e) { ind = mid; break; } else if (v.get(mid) < e) { ind = mid + 1; start = mid + 1; } else { end = mid - 1; } } return ind; } // Fast I/p static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
8616d6f56d53f02e06bc626d8ddb2db7
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; public class Solution { public static void main(String args[]) throws Exception { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-- > 0){ int n = scn.nextInt(); int arr[] = new int[n]; int max = Integer.MIN_VALUE; int sum = 0; for(int i = 0;i <n;i++){ arr[i] = scn.nextInt(); max = Math.max(max, arr[i]); sum += arr[i]; } if(max > sum - max){ System.out.println("T"); }else{ if(sum%2 == 1) System.out.println("T"); else System.out.println("HL"); } } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
2dbb0a3b1f014a8f781ecd8a6294b71a
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.StringTokenizer; public class B { private FastScanner in; private PrintWriter out; public B(FastScanner in, PrintWriter out) { this.in = in; this.out = out; } public static void main(String[] args) { try ( FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); ) { B solution = new B(in, out); solution.solve(); } catch (IOException e) { e.printStackTrace(); } } public void solve() throws IOException { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); List<Integer> a = new ArrayList<>(n); for (int i = 0; i < n; i++) { a.add(in.nextInt()); } int max = a.stream().max(Comparator.naturalOrder()).orElse(0); int sum = a.stream().mapToInt(Integer::intValue).sum(); if (max * 2 > sum) { out.println("T"); } else { out.println(sum % 2 == 0 ? "HL" : "T"); } } } public static class FastScanner implements Closeable { BufferedReader bufferedReader; StringTokenizer stringTokenizer; public FastScanner(InputStream inputStream) { this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); } public FastScanner(File file) throws FileNotFoundException { this(new FileInputStream(file)); } public String next() throws IOException { while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { String line = bufferedReader.readLine(); if (line == null) { throw new EOFException("End of input stream is reached."); } stringTokenizer = new StringTokenizer(line); } return stringTokenizer.nextToken(); } public String nextLine() throws IOException { stringTokenizer = null; return bufferedReader.readLine(); } 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()); } @Override public void close() throws IOException { bufferedReader.close(); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
cd784c4a2c2b4131b896224e8260264d
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { CP sc =new CP(); int tt = sc.nextInt(); while (tt-- > 0) { int n = sc.nextInt(); int[] a = new int[n]; int sum = 0, mx = 0; for (int i = 0; i < n; ++i){ a[i] = sc.nextInt(); sum += a[i]; mx = Math.max(mx, a[i]); } if ((sum - mx < mx) || (sum & 1)==1) System.out.println("T"); else System.out.println("HL"); } } /*****************************************************************************/ static class CP { BufferedReader bufferedReader; StringTokenizer stringTokenizer; public CP() { bufferedReader = new BufferedReader(new InputStreamReader(System.in)); } int nextInt() { return Integer.parseInt(NNNN()); } long nextLong() { return Long.parseLong(NNNN()); } double nextDouble() { return Double.parseDouble(NNNN()); } String NNNN() { while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) { try { stringTokenizer = new StringTokenizer(bufferedReader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return stringTokenizer.nextToken(); } String nextLine() { String spl = ""; try { spl = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } return spl; } } /*****************************************************************************/ }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
e8b9a8b94be8e8ef4244972c9b5f5162
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class D { private static final String INPUT_FILE_PATH = ""; void solve() { int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } Arrays.sort(a); int sum = 0; for (int x : a) { sum += x; } if (a[n - 1] > sum - a[n - 1]) { out.println("T"); continue; } out.println(sum % 2 == 1 ? "T" : "HL"); } } private final InputReader in; private final PrintWriter out; private D(InputReader in, PrintWriter out) { this.in = in; this.out = out; } private static class InputReader { private BufferedReader br; private StringTokenizer st; public InputReader(InputStream inputStream) { this.br = new BufferedReader(new InputStreamReader(inputStream), 32768); this.st = null; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } } public static void main(String[] args) throws Exception { InputStream inputStream = INPUT_FILE_PATH.isEmpty() ? System.in : new FileInputStream(new File(INPUT_FILE_PATH)); OutputStream outputStream = System.out; InputReader inputReader = new InputReader(inputStream); PrintWriter printWriter = new PrintWriter(outputStream); new D(inputReader, printWriter).solve(); printWriter.close(); } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
54fb363e3402a2e02cf890b3ea80e090
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; import java.io.*; public class D666 { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); Integer [] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); String first = "T"; String second = "HL"; int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } Arrays.sort(a, Comparator.reverseOrder()); if (a[0] > sum - a[0]) { out.println(first); } else { out.println(sum % 2 == 0 ? second : first); } } out.close(); } //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
b04b06677b71e0f7deebf7b79f597255
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.util.*; public class Rating { public static Scanner in=new Scanner(System.in); static public void main(String args[]) { int T_T=in.nextInt(); while(T_T-->0) { int n=in.nextInt(),mx=-1,sum=0; for(int i=1,x;i<=n;++i) { x=in.nextInt(); sum+=x;mx=Math.max(x, mx); } if(mx*2>sum||sum%2==1)System.out.println("T");else System.out.println("HL"); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
a32a073ec75d66ca2138126342f8a863
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
// Born Sinner // old but im not that old // fuck all you hoes get a grip import java.util.*; import java.lang.*; import java.io.*; public class Main { static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch (Exception e){ e.printStackTrace(); } return str; } } static int modPower(int x, int y, int mod){ int res = 1; x %= mod; if(x==0) return 0; while(y>0){ if(y%2==1){ res = (res*x)%mod; } y = y>>1; x = (x*x)%mod; } return res; } static class pair<T1, T2>{ T1 first; T2 second; pair(T1 first, T2 second){ this.first = first; this.second = second; } } public static void main (String[] args) throws java.lang.Exception { FastReader in = new FastReader(); int t = in.nextInt(); while(t-->0){ int n = in.nextInt(); int[] a = new int[n]; int s = 0, mx = 0; for(int i = 0; i < n; i++){ a[i] = in.nextInt(); s+=a[i]; mx=Math.max(mx,a[i]); } System.out.println((mx>(s-mx) || s%2==1)?"T":"HL"); } } }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
3f04cef731f46895fde6c4a690f796e7
train_003.jsonl
1598798100
T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.
256 megabytes
import java.io.*; import java.util.*; //import javafx.util.*; import java.math.*; //import java.lang.*; public class Main { // static long mod=1000000007; static HashSet<Integer> adj[]; static boolean vis[]; // static int n[]; // static ArrayList<Integer> arr[]; // // static long ans=0; // static boolean vis[][]; // static final long oo=(long)1e18; // static int par[]; // static long child[]; // static HashMap<String,Long> hm=new HashMap<>(); static int ver=0;static int edge=0; public static void main(String[] args) throws IOException { PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); br = new BufferedReader(new InputStreamReader(System.in)); int test=nextInt(); // int test=1; outer: while(test--!=0){ int n=nextInt(); int arr[]=new int[n]; PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder()); for(int i=0;i<n;i++){ arr[i]=nextInt(); pq.add(arr[i]); } while(true){ if(pq.isEmpty()){ pw.println("HL"); break; } int a=pq.remove(); if(pq.isEmpty()){ pw.println("T"); break; } int b=pq.remove(); // pw.println(a+" "+b); if(a-1>0) pq.add(a-1); if(b-1>0) pq.add(b-1); } } pw.close(); } static void dfs(int i){ vis[i]=true; ver++; for(int v:adj[i]){ edge++; if(!vis[v]){ dfs(v); } } } static class compare implements Comparable<compare>{ String s; compare(String s){ this.s=s; } public int compareTo(compare t){ return compareVersion(s,t.s); } public int compareVersion(String version1, String version2) { String[] nums1 = version1.split("\\."); String[] nums2 = version2.split("\\."); int n1 = nums1.length, n2 = nums2.length; // compare versions int i1, i2; for (int i = 0; i < Math.max(n1, n2); ++i) { i1 = i < n1 ? Integer.parseInt(nums1[i]) : 0; i2 = i < n2 ? Integer.parseInt(nums2[i]) : 0; if (i1 != i2) { return i1 > i2 ? 1 : -1; } } // the versions are equal return 0; } } static class Pair{ int a;int b; Pair(int a,int b){ // this.index=index; this.a=a; this.b=b; //this.z=z; } } static void update(long tree[],int idx,long val){ //println(idx); while(idx<1000006){ tree[idx]+=val; idx+=(idx)&(-idx); } } static long sum(long tree[],int idx){ long sum=0; while(idx>0){ sum+=tree[idx]; idx-=(idx)&(-idx); } return sum; } public static BufferedReader br; public static StringTokenizer st; public static String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } return st.nextToken(); } public static Integer nextInt() { return Integer.parseInt(next()); } public static Long nextLong() { return Long.parseLong(next()); } public static Double nextDouble() { return Double.parseDouble(next()); } // static class Pair{ // int x;int y; // Pair(int x,int y,int z){ // this.x=x; // this.y=y; // // this.z=z; // // this.z=z; // // this.i=i; // } // } // static class sorting implements Comparator<Pair>{ // public int compare(Pair a,Pair b){ // //return (a.y)-(b.y); // if(a.y==b.y){ // return -1*(a.z-b.z); // } // return (a.y-b.y); // } // } static long ncr(long n,long r){ if(r==0) return 1l; long val=ncr(n-1,r-1); val=(n*val); val=(val/r); return val; } public static int[] na(int n)throws IOException{ int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = nextInt(); return a; } static class query implements Comparable<query>{ int l,r,idx,block; static int len; query(int l,int r,int i){ this.l=l; this.r=r; this.idx=i; this.block=l/len; } public int compareTo(query a){ return block==a.block?r-a.r:block-a.block; } } // static class sorting implements Comparator<Pair>{ // public int compare(Pair a1,Pair a2){ // if(o1.a==o2.a) // return (o1.b>o2.b)?1:-1; // else if(o1.a>o2.a) // return 1; // else // return -1; // } // } static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } // To compute x^y under modulo m static long power(long x, long y, long m){ if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (p * p) % m; if (y % 2 == 0) return p; else return (x * p) % m; } static long fast_pow(long base,long n,long M){ if(n==0) return 1; if(n==1) return base; long halfn=fast_pow(base,n/2,M); if(n%2==0) return ( halfn * halfn ) % M; else return ( ( ( halfn * halfn ) % M ) * base ) % M; } static long modInverse(long n,long M){ return fast_pow(n,M-2,M); } // (1,1) // (3,2) (3,5) }
Java
["2\n1\n2\n2\n1 1"]
1 second
["T\nHL"]
NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Java 11
standard input
[ "implementation", "greedy", "games", "brute force" ]
5bfce6c17af24959b4af3c9408536d05
The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.
1,800
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
standard output
PASSED
2b16049b21ce69ffe7e1a347a4f3561e
train_003.jsonl
1428854400
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class CodeForces { private final BufferedReader reader; private final PrintWriter writer; private StringTokenizer tokenizer; private void solve() { int n = nextInt(); int start1 = 1; int start2 = (n + 1) / 2 + 1; if (n <= 2) { writer.printf("%d\n%d", 1, 1); } else if (n == 3) { writer.printf("%d\n%d %d", 2, 1, 3); } else if (n == 4) { writer.printf("%d\n%d %d %d %d", 4, 3, 1, 4, 2); } else { ArrayList<Integer> res = new ArrayList<>(); for (int i = 0; i < n; i++) { if (i % 2 == 0) res.add(start1++); else res.add(start2++); } writer.printf("%d\n", res.size()); for (Integer i: res) { writer.printf("%d ", i); } } } public static void main(String[] args) { new CodeForces(System.in, System.out); } private CodeForces(InputStream inputStream, OutputStream outputStream) { this.reader = new BufferedReader(new InputStreamReader(inputStream)); this.writer = new PrintWriter(outputStream); solve(); writer.close(); } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } private String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } private int nextInt() { return Integer.parseInt(next()); } private long nextLong() { return Long.parseLong(next()); } private double nextDouble() { return Double.parseDouble(next()); } public boolean hasNext() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String line = readLine(); if (line == null) { return false; } tokenizer = new StringTokenizer(line); } return true; } public BigInteger nextBigInteger() { return new BigInteger(next()); } public static int upperBinarySearch(int[] array, int start, int finish, int key) { int low = 0; int high = array.length - 1; if (high < 0) return -1; while (low < high) { int mid = (low + high + 1) >>> 1; if (array[mid] <= key) low = mid; else high = mid - 1; } if (array[low] != key) { if (array[low] < key) low++; low = -(low + 1); } return low; } }
Java
["6", "3"]
1 second
["6\n1 5 3 6 2 4", "2\n1 3"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "math" ]
a52ceb8a894809b570cbb74dc5ef76e1
A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.
1,100
In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.
standard output
PASSED
1d7bb5fb43c8668a5355637938efd1ea
train_003.jsonl
1428854400
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
256 megabytes
import java.util.Scanner; public class Solution{ public static void main(String args[]) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); if(n<=3&&n>=2) { n=n-1; } System.out.println(n); if(n==2) { System.out.println("1"+" "+"3"); } else if(n==4) { System.out.println("3"+" "+"1"+" "+"4"+" "+"2"); } else { int count=1; int counter=2; for(int i=1;i<=n;i++) { if(i<=(n%2==0?n/2:((n+1)/2))) { System.out.print(count+" "); count+=2; } else { System.out.print(counter+" "); counter+=2; } } } } }
Java
["6", "3"]
1 second
["6\n1 5 3 6 2 4", "2\n1 3"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "math" ]
a52ceb8a894809b570cbb74dc5ef76e1
A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.
1,100
In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.
standard output
PASSED
f4342beb616657ab73a7cacfa20934d4
train_003.jsonl
1428854400
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
256 megabytes
import java.util.Scanner; public class Exam { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 3) { System.out.println(2); System.out.print(1 + " " + 3); } else { if (n <= 2) { System.out.println(1); System.out.println(1); } else { System.out.println(n); for (int i = 1; i <= n / 2; i++) { System.out.print((n / 2 + i) + " " + i + " "); } if(n%2 != 0) { System.out.print(n); } } } } }
Java
["6", "3"]
1 second
["6\n1 5 3 6 2 4", "2\n1 3"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "math" ]
a52ceb8a894809b570cbb74dc5ef76e1
A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.
1,100
In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.
standard output
PASSED
3b2afb3131cdf502952e1f0f946ad646
train_003.jsonl
1428854400
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
256 megabytes
import java.util.Scanner; public class A534 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n; n = scanner.nextInt(); scanner.close(); if (n == 1) { System.out.println("1"); System.out.println("1"); return; } else if (n == 2) { System.out.println("1"); System.out.println("1"); return; } else if (n == 3) { System.out.println("2"); System.out.println("1 3"); return; } else { System.out.println(n); for (int i=2; i<=n; i+=2) { System.out.print(i + " "); } for (int i=1; i<=n; i+=2) { System.out.print(i + " "); } return; } } } // 2 4 6 1 3 5
Java
["6", "3"]
1 second
["6\n1 5 3 6 2 4", "2\n1 3"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "math" ]
a52ceb8a894809b570cbb74dc5ef76e1
A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.
1,100
In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.
standard output
PASSED
243ba61a263e84201c60d0b549c1beda
train_003.jsonl
1368363600
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m &gt; 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: .
256 megabytes
import java.util.*; import java.io.*; public class Main{ BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int nextInt() throws Exception{ return Integer.parseInt(next()); } public void run() throws Exception{ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int n = nextInt(), k = nextInt(); int []a = new int[n]; int MAX = 0; for(int i=0;i<n;i++){ a[i] = nextInt(); if (MAX < a[i]) { MAX = a[i]; } } ++MAX; int diff[] = new int[MAX]; int diffList[][] = new int[20][MAX]; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ int d = Math.abs(a[i] - a[j]); if (diff[d] < 20) diffList[diff[d]++][d] = j; } } Set<Integer> diffHere = new HashSet<Integer>(); for(int mod=1;mod<MAX;mod++){ diffHere.clear(); for(int i=mod;i<MAX;i+=mod){ for(int j=0;j<diff[i];j++){ diffHere.add(diffList[j][i]); if (diffHere.size() > k){ i = MAX + 1; break; } } } if (diffHere.size() <= k){ out.println(mod); out.close(); return; } } out.println(MAX); out.close(); } public static void main(String args[]) throws Exception{ new Main().run(); } }
Java
["7 0\n0 2 3 6 7 12 18", "7 1\n0 2 3 6 7 12 18"]
2 seconds
["13", "7"]
null
Java 6
standard input
[ "graphs", "number theory", "math" ]
656e44f1aa0202a3e8414bbce9381b09
The first line contains two integers n and k (1  ≤ n  ≤ 5000, 0 ≤ k ≤ 4), which we have mentioned above. The second line contains n distinct integers a1, a2, ..., an (0 ≤ ai ≤ 106).
2,400
Print a single positive integer — the minimum m.
standard output
PASSED
c586174562cdd1d6363e1ab1735c3c2d
train_003.jsonl
1368363600
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m &gt; 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: .
256 megabytes
import java.util.*; import java.io.*; public class Main{ BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int nextInt() throws Exception{ return Integer.parseInt(next()); } public void run() throws Exception{ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int n = nextInt(), k = nextInt(); int []a = new int[n]; int MAX = 0; for(int i=0;i<n;i++){ a[i] = nextInt(); if (MAX < a[i]) { MAX = a[i]; } } ++MAX; int diff[] = new int[MAX]; int diffList[][] = new int[5][MAX]; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ int d = Math.abs(a[i] - a[j]); if (diff[d] < 5) diffList[diff[d]++][d] = j; } } Set<Integer> diffHere = new HashSet<Integer>(); for(int mod=1;mod<MAX;mod++){ diffHere.clear(); for(int i=mod;i<MAX;i+=mod){ for(int j=0;j<diff[i];j++){ diffHere.add(diffList[j][i]); if (diffHere.size() > k){ i = MAX + 1; break; } } } if (diffHere.size() <= k){ out.println(mod); out.close(); return; } } out.println(MAX); out.close(); } public static void main(String args[]) throws Exception{ new Main().run(); } }
Java
["7 0\n0 2 3 6 7 12 18", "7 1\n0 2 3 6 7 12 18"]
2 seconds
["13", "7"]
null
Java 6
standard input
[ "graphs", "number theory", "math" ]
656e44f1aa0202a3e8414bbce9381b09
The first line contains two integers n and k (1  ≤ n  ≤ 5000, 0 ≤ k ≤ 4), which we have mentioned above. The second line contains n distinct integers a1, a2, ..., an (0 ≤ ai ≤ 106).
2,400
Print a single positive integer — the minimum m.
standard output
PASSED
6a0b371132ccd400523ddc29c0870be4
train_003.jsonl
1390231800
Iahub got lost in a very big desert. The desert can be represented as a n × n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≤ i, j ≤ n). Iahub can go from one cell (i, j) only down or right, that is to cells (i + 1, j) or (i, j + 1). Also, there are m cells that are occupied by volcanoes, which Iahub cannot enter. Iahub is initially at cell (1, 1) and he needs to travel to cell (n, n). Knowing that Iahub needs 1 second to travel from one cell to another, find the minimum time in which he can arrive in cell (n, n).
256 megabytes
import java.util.List; import java.io.IOException; import java.util.InputMismatchException; import java.util.TreeMap; import java.util.ArrayList; import java.util.Set; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Collections; import java.util.Collection; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author George Marcus */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int N = in.nextInt(); int M = in.nextInt(); Pair[] P = new Pair[M]; TreeMap<Integer, Integer> lines = new TreeMap<Integer, Integer>(); for(int i = 0; i < M; i++) { P[i] = new Pair(in.nextInt(), in.nextInt()); lines.put(P[i].x, 0); if(P[i].x + 1 <= N) lines.put(P[i].x + 1, 0); } int numLines = lines.size(); ArrayList<Integer>[] obstacles = new ArrayList[numLines]; for(int i = 0; i < numLines; i++) obstacles[i] = new ArrayList<Integer>(); int idx = 0; for(int x : lines.keySet()) { lines.put(x, idx); idx++; } for(int i = 0; i < M; i++) { int line = lines.get(P[i].x); obstacles[line].add(P[i].y); } ArrayList<Pair> last = new ArrayList<Pair>(); ArrayList<Pair> next = new ArrayList<Pair>(); ArrayList<Pair> cand = new ArrayList<Pair>(); if(lines.containsKey(1)) { int first = obstacles[0].get(0); last.add(new Pair(1, first - 1)); } else last.add(new Pair(1, N)); for(int i = 0; i < numLines; i++) { cand.clear(); next.clear(); obstacles[i].add(0); obstacles[i].add(N + 1); Collections.sort(obstacles[i]); for(int j = 1; j < obstacles[i].size(); j++) { int a = obstacles[i].get(j - 1) + 1; int b = obstacles[i].get(j) - 1; if(a <= b) cand.add(new Pair(a, b)); } if(cand.size() > 0) { for(Pair p : cand) { int pos = Collections.binarySearch(last, new Pair(-1, p.x)); if(pos < 0) pos = -pos - 1; if(pos == last.size()) pos = last.size() - 1; int px = last.get(pos).x; int py = last.get(pos).y; if(py >= p.x && px <= p.y) next.add(new Pair(Math.max(p.x, px), p.y)); } } last.clear(); last.addAll(next); if(last.size() == 0) break; } if(last.size() > 0 && last.get(last.size() - 1).y == N) out.println(2 * N - 2); else out.println(-1); } private class Pair implements Comparable<Pair> { public int x; public int y; private Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o) { if(y != o.y) return y - o.y; return x - o.x; } } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; 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 nextInt() { return Integer.parseInt(nextString()); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } }
Java
["4 2\n1 3\n1 4", "7 8\n1 6\n2 6\n3 5\n3 6\n4 3\n5 1\n5 2\n5 3", "2 2\n1 2\n2 1"]
1 second
["6", "12", "-1"]
NoteConsider the first sample. A possible road is: (1, 1)  →  (1, 2)  →  (2, 2)  →  (2, 3)  →  (3, 3)  →  (3, 4)  →  (4, 4).
Java 7
standard input
[ "two pointers", "binary search", "implementation", "sortings" ]
50a3dce28a479d140781a0db4eac363e
The first line contains two integers n (1 ≤ n ≤ 109) and m (1 ≤ m ≤ 105). Each of the next m lines contains a pair of integers, x and y (1 ≤ x, y ≤ n), representing the coordinates of the volcanoes. Consider matrix rows are numbered from 1 to n from top to bottom, and matrix columns are numbered from 1 to n from left to right. There is no volcano in cell (1, 1). No two volcanoes occupy the same location.
2,500
Print one integer, the minimum time in which Iahub can arrive at cell (n, n). If no solution exists (there is no path to the final cell), print -1.
standard output
PASSED
ff276de4d630561467dd01efdc9ad590
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.*; import java.util.*; public class Main { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws IOException { if(total<0) throw new InputMismatchException(); if(index>=total) { index=0; total=in.read(buf); if(total<=0) return -1; } return buf[index++]; } public int scanInt()throws IOException { int integer=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { integer*=10; integer+=n-'0'; n=scan(); } else throw new InputMismatchException(); } return neg*integer; } public double scanDouble()throws IOException { double doub=0; int n=scan(); while(isWhiteSpace(n)) n=scan(); int neg=1; if(n=='-') { neg=-1; n=scan(); } while(!isWhiteSpace(n)&&n!='.') { if(n>='0'&&n<='9') { doub*=10; doub+=n-'0'; n=scan(); } else throw new InputMismatchException(); } if(n=='.') { n=scan(); double temp=1; while(!isWhiteSpace(n)) { if(n>='0'&&n<='9') { temp/=10; doub+=(n-'0')*temp; n=scan(); } else throw new InputMismatchException(); } } return doub*neg; } public String scanString()throws IOException { StringBuilder sb=new StringBuilder(); int n=scan(); while(isWhiteSpace(n)) n=scan(); while(!isWhiteSpace(n)) { sb.append((char)n); n=scan(); } return sb.toString(); } private boolean isWhiteSpace(int n) { if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1) return true; return false; } } public static void main(String args[]) throws IOException { Scan input=new Scan(); int n=input.scanInt(); int arr[]=new int[n]; int diff[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=input.scanInt(); diff[i]=arr[i]-i; } for(int i=0;i<n/2;i++) { int l=(int)(Math.random()*(n-1)); int r=(int)(Math.random()*(n-1)); swap(arr,l,r); swap(diff,l,r); } heapSort(diff,arr,n); long max=0; for(int i=0;i<n;i++) { long sum=0; int j=i; while(j<n && diff[j]==diff[i]) { sum+=arr[j]; j++; } max=Math.max(max,sum); j--; i=j; } System.out.println(max); } static void buildMaxHeap(int arr[],int brr[] ,int n) { for (int i = 1; i < n; i++) { // if child is bigger than parent if (arr[i] > arr[(i - 1) / 2]) { int j = i; // swap child and parent until // parent is smaller while (arr[j] > arr[(j - 1) / 2]) { swap(arr, j, (j - 1) / 2); swap(brr, j, (j - 1) / 2); j = (j - 1) / 2; } } } } static void heapSort(int arr[], int brr[],int n) { buildMaxHeap(arr, brr, n); for (int i = n - 1; i > 0; i--) { // swap value of first indexed // with last indexed swap(arr, 0, i); swap(brr, 0, i); // maintaining heap property // after each swapping int j = 0, index; do { index = (2 * j + 1); // if left child is smaller than // right child point index variable // to right child if (index < (i - 1) && arr[index] < arr[index + 1]) index++; // if parent is smaller than child // then swapping parent with child // having higher value if (index < i && arr[j] < arr[index]) { swap(arr, j, index); swap(brr, j, index); } j = index; } while (index < i); } } public static void swap(int[] a, int i, int j) { int temp = a[i]; a[i]=a[j]; a[j] = temp; } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
3f742997daa49b4c74c1496f8bbf5b4b
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { int n; Scanner s = new Scanner(System.in); n = s.nextInt(); int[] b = new int[n]; for(int i=0;i<n;) b[i++]=s.nextInt(); HashMap<Integer, Long> groupsMap = new HashMap<>(); for(int i=0;i<n;i++) { long groupSum = groupsMap.getOrDefault(i-b[i],0L); groupsMap.put(i-b[i], groupSum+b[i]); } long max = Collections.max(groupsMap.values()); System.out.println(max); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
8f401481ce45d9ee0c22b89bffb3e3a2
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { FastReader scan = new FastReader(); //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("taming.out"))); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); Task solver = new Task(); //int t = scan.nextInt(); int t = 1; for(int i = 1; i <= t; i++) solver.solve(i, scan, out); out.close(); } static class Task { public void solve(int testNumber, FastReader sc, PrintWriter pw){ int n = sc.nextInt(); long[] sums = new long[800010]; for(int i=0;i<n;i++){ int t= sc.nextInt(); sums[t-i+400000]+=t; } long f = 0; for(long x : sums){ f=Math.max(x,f); } pw.println(f); } } static class tup implements Comparable<tup> { int a, b; tup() { } ; tup(int a, int b) { this.a=a; this.b=b; } @Override public int compareTo(tup o2) { return 0; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static void shuffle(int[] a,int l, int rb) { Random get = new Random(); for (int i = l; i < rb; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
79021efab37ecb6aaee05f1ced824218
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
/** * ******* Created on 1/3/20 6:19 PM******* */ import java.io.*; import java.util.*; public class B1321 implements Runnable { private static final int MAX = (int) (1E6 + 5); private static final int MAX1 = 4*(int) (1E5 + 5); private static final int MOD = (int) (1E9 + 7); private static final long Inf = (long) (1E14 + 10); private void solve() throws IOException { int n = reader.nextInt(); int[]a = new int[MAX]; for(int i=1;i<=n;i++){ a[i] =reader.nextInt(); } Map<Integer, Long> map = new HashMap<>(); for(int i=1;i<=n;i++) { int val =a[i]-i; if(map.containsKey(val)){ long x = map.get(val); map.put(val, x+a[i]); }else{ map.put(val, (long) a[i]); } } long max =0; for(int key: map.keySet()){ max = Math.max(max, map.get(key)); } writer.println(max); } public static void main(String[] args) throws IOException { try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) { new B1321().run(); } } StandardInput reader; PrintWriter writer; @Override public void run() { try { reader = new StandardInput(); writer = new PrintWriter(System.out); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } interface Input extends Closeable { String next() throws IOException; default int nextInt() throws IOException { return Integer.parseInt(next()); } default long nextLong() throws IOException { return Long.parseLong(next()); } default double nextDouble() throws IOException { return Double.parseDouble(next()); } default int[] readIntArray() throws IOException { return readIntArray(nextInt()); } default int[] readIntArray(int size) throws IOException { int[] array = new int[size]; for (int i = 0; i < array.length; i++) { array[i] = nextInt(); } return array; } default long[] readLongArray(int size) throws IOException { long[] array = new long[size]; for (int i = 0; i < array.length; i++) { array[i] = nextLong(); } return array; } } private static class StandardInput implements Input { private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer stringTokenizer; @Override public void close() throws IOException { reader.close(); } @Override public String next() throws IOException { if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { stringTokenizer = new StringTokenizer(reader.readLine()); } return stringTokenizer.nextToken(); } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
e05c0ac5d9b0397e3d46c28f79d4c05e
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.*; import java.util.*; public class cf{ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader in=new FastReader(); int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; HashMap<Integer,Long> h = new HashMap<Integer,Long>(); for (int i = 0;i<n ;i++ ) { a[i] = in.nextInt(); b[i]= a[i]-i; h.put(b[i],(long)0); } int p=0,q=0; long max = Integer.MIN_VALUE,c= Integer.MIN_VALUE; for (int i = 0;i<n ;i++) { long z =(long)h.get(b[i])+a[i]; h.put(b[i],z); } for (Map.Entry<Integer,Long> entry : h.entrySet()) { long value = entry.getValue(); if(max<value){ max=value; } } System.out.println(max); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
235740a75806eb0b1b4c50c5c87a82ae
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.Scanner; //@Map @merge public class JourneyPlanningB extends PrintWriter { //this trick improves performances JourneyPlanningB() { super(System.out); } public static void main(String[] $) { JourneyPlanningB o = new JourneyPlanningB(); o.main(); o.flush(); } void main() { Scanner sc = new Scanner(System.in); //int count = sc.nextInt(); //use this if just a single test int count = 1; main: while (count-- > 0) { int n = sc.nextInt(); long beautiest =0 ; Map<Integer, Long> map = new HashMap<>(); int value; for (int j = 1; j <= n; j++) { value=sc.nextInt(); map.merge(j-value, (long)value, (v1,v2) -> (long)v1+v2); beautiest = Math.max(beautiest, map.get(j-value)); } println(beautiest); } sc.close(); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
208ae546a17fc37d1c76aec618ed46f4
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
//package com.netease.music.codeforces.round625.div12; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.StringTokenizer; /** * Created by dezhonger on 2020/2/24 */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = new int[n]; Map<Integer, List<Integer>> m = new HashMap<>(); // Map<Integer, Integer> mp = new HashMap<>(); for (int i = 0; i < n; i++) { a[i] = in.nextInt(); int x = a[i] - i; List<Integer> orDefault = m.getOrDefault(x, new ArrayList<>()); orDefault.add(i); m.put(x, orDefault); // mp.put(x, mp.getOrDefault(x, 0) + 1); } long res = 0; for (Map.Entry<Integer, List<Integer>> entry : m.entrySet()) { long t = 0; for (Integer i : entry.getValue()) { t += a[i]; } res = Math.max(res, t); } System.out.println(res); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
1540852adb34c973aed55575de738741
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.util.*; public class devesh08 { public static void main(String args[]) throws Exception { FastReader in = new FastReader(System.in); int testcases=1,i,j; StringBuilder sb = new StringBuilder(); start:while(testcases-->0) { int x=0,y=0; int n=in.nextInt(); long max=0; int a[]=new int[n]; HashMap<Integer,Long> hm=new HashMap<>(); int vis[]=new int[n]; for(i=0;i<n;i++) { a[i]=in.nextInt(); if(hm.containsKey(a[i]-i)) hm.put(a[i]-i,(long)(hm.get(a[i]-i)+a[i])); else hm.put(a[i]-i,(long)a[i]); } for(Integer key : hm.keySet()) max=Math.max(max,hm.get(key)); System.out.println(max); } //System.out.print(sb); } } class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
4d1d61e7caec3f8e4ddaa920c40ca88b
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.HashMap; import java.util.ArrayList; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(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, Scanner in, PrintWriter out) { int n = in.nextInt(); int[] b = new int[n]; long ans = 0; List<TaskB.Bt> bts = new ArrayList<>(); for (int i = 0; i < n; i++) { b[i] = in.nextInt(); ans = Math.max(ans, b[i]); bts.add(new TaskB.Bt(b[i], i + 1)); } Map<Long, Integer> diffExists = new HashMap<>(); diffExists.put(bts.get(n - 1).B - (n - 1), n - 1); for (int i = bts.size() - 2; i >= 0; i--) { if (diffExists.containsKey(bts.get(i).B - i)) { int id = diffExists.get(bts.get(i).B - i); bts.get(id).sum += bts.get(i).B; } else { diffExists.put(bts.get(i).B - i, i); } } for (int i = 0; i < bts.size(); i++) { ans = Math.max(ans, bts.get(i).sum); } out.println(ans); } static class Bt { long B; int id; long sum; public Bt(long b, int id) { B = b; sum = b; this.id = id; } } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
f0ef54eee83662551b5d0f5509d21164
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
//package CodeForces; import java.io.*; import java.nio.file.Paths; import java.util.HashMap; import java.util.Scanner; public class Solution { private static final boolean onlineJudge = Boolean.parseBoolean(System.getProperty("ONLINE_JUDGE")); public static void main(String[] args) throws IOException { FileInputStream fileStream = null; Scanner scanner = new Scanner(onlineJudge ? System.in : (fileStream = new FileInputStream(Paths.get(System.getProperty("user.dir"), "src/res/input").toString()))); int n = scanner.nextInt(); int[] b = readArray(scanner, n); HashMap<Integer, Long> map = new HashMap<>(); for (int i = 0; i < n; i++) { if(!map.containsKey(b[i] - i)) { map.put(b[i] - i, (long) b[i]); } else { map.replace((b[i] - i), map.get(b[i] - i) + b[i]); } } long res = Long.MIN_VALUE; for (long s : map.values()) { res = Math.max(res, s); } System.out.println(res); if(fileStream != null) { fileStream.close(); } scanner.close(); } private static int[] readArray(Scanner scanner, int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = scanner.nextInt(); } return array; } private static void printArray(int[] a){ for (int i = 0; i < a.length; i++) { System.out.print(a[i]); System.out.print(i < a.length - 1 ? " " : "\n"); } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
9728177c2b26aea6659794064f75b786
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Codeforces { InputStream is; PrintWriter out; String INPUT = ""; /* isPrime(int) Vector<Integer> sieveOfEratosthenes(int n){PRIME NO <=n} swap(arr,i,j) HashMap sortByValue(map); long comb=nCr(5,2); int gcd(l,s); Pair p=new Pair(x,y); */ /*----------------------------------------------------------------------------------------------------*/ void solve() throws IOException { int n=ni(); int b[]=new int[n]; long max=0; Map<Integer,Long> map = new HashMap<>(); for (int i = 0; i < n; i++) { b[i]=ni(); int k=b[i]-i; map.put(k,map.getOrDefault(k,0L)+b[i]); } for (Integer k : map.keySet()) { max=Math.max(max, map.get(k)); } out.println(max); } /*----------------------------------------------------------------------------------------------------*/ long pow(long x, long y, int p) {//(x^y)%p long res = 1; if (p == 0) { while (y > 0) { if ((y & 1) == 1) { res = (res * x); } y = y >> 1; x = (x * x); } } else { x = x % p; while (y > 0) { if ((y & 1) == 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } } return res; } boolean isPrime(long n) { if (n <= 1) { return false; } for (long i = 2; i <= (long) Math.sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } Vector<Integer> sieveOfEratosthenes(int n) { boolean[] prime = new boolean[n + 1]; for (int i = 0; i < n; i++) { prime[i] = true; } for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int j = p * p; j <= n; j += p) { prime[j] = false; } } } Vector<Integer> v = new Vector<>(); for (int i = 2; i <= n; i++) { if (prime[i]) { v.add(i); } } return v; } void swap(int a[], int l, int r) { int temp = a[l]; a[l] = a[r]; a[r] = temp; } long nCr(int n, int k) { long C[] = new long[k + 1]; // nC0 is 1 C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = Math.min(i, k); j > 0; j--) { C[j] = C[j] + C[j - 1]; } } return C[k]; } public long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } public HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer>> list = new LinkedList<>(hm.entrySet()); //->change o1,o2 for reverseorder Collections.sort(list, (Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) -> (o1.getValue()).compareTo(o2.getValue())); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<>(); list.forEach((aa) -> { temp.put(aa.getKey(), aa.getValue()); }); return temp; } void run() throws Exception { is = System.in;//oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Codeforces().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) { throw new InputMismatchException(); } if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) { return -1; } } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); //WHEN U NEED to take spaces in a string (take the whole line as string change-> //c>=32 } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')//!(isSpaceChar(b)) sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private 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 int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } private int ni() { 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(); } } private long nl() { 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(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if (!oj) { System.out.println(Arrays.deepToString(o)); } } class Pair { /*SORTING PAIRS BY COMPARING Y OF PAIR. Pair[] p=new Pair[n]; p[i]=new Pair(i,ni()); Arrays.sort(p,( p1, p2) -> {return p1.y-p2.y;}); */ int x; int y; Pair(int u, int v) { x = u; y = v; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Pair)) { return false; } Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
8dbe2c5ce8a1e007b9df711eb7443470
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; import java.util.TreeMap; public class f { public static void print(String str,int val){ System.out.println(str+" "+val); } public long gcd(long a, long b) { if (b==0L) return a; return gcd(b,a%b); } public static void debug(long[][] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.println(Arrays.toString(arr[i])); } } public static void debug(int[][] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.println(Arrays.toString(arr[i])); } } public static void debug(String[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.println(arr[i]); } } public static void print(int[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } public static void print(String[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } public static void print(long[] arr){ int len = arr.length; for(int i=0;i<len;i++){ System.out.print(arr[i]+" "); } System.out.print('\n'); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String path) throws FileNotFoundException { br = new BufferedReader(new FileReader(path)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader s=new FastReader(); int n = s.nextInt(); int[] b = new int[n]; for(int i=0;i<n;i++){ b[i] = s.nextInt(); } int[] c = new int[n]; for(int i=0;i<n;i++){ c[i] = b[i]-i; } long[] sum = new long[(int)(1e6)]; for(int i=0;i<n;i++){ sum[c[i]+(int)(3*1e5)]+=b[i]; } long max =0; for(int i=0;i<1e6;i++){ max = Math.max(max,sum[i]); } System.out.println(max); } // OutputStream out = new BufferedOutputStream( System.out ); // for(int i=1;i<n;i++){ // out.write((arr[i]+" ").getBytes()); // } // out.flush(); // long start_time = System.currentTimeMillis(); // long end_time = System.currentTimeMillis(); // System.out.println((end_time - start_time) + "ms"); }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
8556a49c9ab89e528b0fa2411cd41acd
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
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.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.StringTokenizer; public class Solution{ static long mod = 998244353L; public static void main(String[] args) throws Exception{ FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n = fs.nextInt(); int[] b = fs.readArray(n); HashMap<Integer, Long> map = new HashMap<Integer, Long>(); long ans = 0L; for(int i=0;i<n;i++) { int cnst = b[i] - i; map.put(cnst, map.getOrDefault(cnst, 0L) + b[i]); ans = Math.max(ans, map.get(cnst)); } out.println(ans); out.close(); } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next(){ while(!st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt(){ return Integer.parseInt(next()); } public int[] readArray(int n){ int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } public long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
39703382fadb7456943065368411cd26
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.*;import java.io.*;import java.math.*; public class Main { static class City{ int ci,b,diff; public City(int ci,int b){ this.ci=ci; this.b=b; diff=ci-b; } } static class sortByDiff implements Comparator<City>{ public int compare(City A,City B) { return A.diff-B.diff; } } public static void process()throws IOException { int n=ni(); City arr[]=new City[n]; for(int i=0;i<n;i++) arr[i]=new City(i,ni()); if(n==1){ pn(arr[0].b); return; } Arrays.sort(arr,new sortByDiff()); int curr=arr[0].diff; long res=0l,sum=0l; for(int i=0;i<n;i++){ City c=arr[i]; if(c.diff!=curr){ res=Math.max(res, sum); curr=c.diff; sum=0l; } sum+=(c.b)*1l; } res=Math.max(res,sum); pn(res); } static AnotherReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc=new AnotherReader(); boolean oj = true; oj = System.getProperty("ONLINE_JUDGE") != null; if(!oj) sc=new AnotherReader(100); long s = System.currentTimeMillis(); int t=1; while(t-->0) process(); out.flush(); if(!oj) System.out.println(System.currentTimeMillis()-s+"ms"); System.out.close(); } static void pn(Object o){out.println(o);} static void p(Object o){out.print(o);} static void pni(Object o){out.println(o);System.out.flush();} static int ni()throws IOException{return sc.nextInt();} static long nl()throws IOException{return sc.nextLong();} static double nd()throws IOException{return sc.nextDouble();} static String nln()throws IOException{return sc.nextLine();} static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} static boolean multipleTC=false; ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class AnotherReader{BufferedReader br; StringTokenizer st; AnotherReader()throws FileNotFoundException{ br=new BufferedReader(new InputStreamReader(System.in));} AnotherReader(int a)throws FileNotFoundException{ br = new BufferedReader(new FileReader("input.txt"));} String next()throws IOException{ while (st == null || !st.hasMoreElements()) {try{ st = new StringTokenizer(br.readLine());} catch (IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt() throws IOException{ return Integer.parseInt(next());} long nextLong() throws IOException {return Long.parseLong(next());} double nextDouble()throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException{ String str = ""; try{ str = br.readLine();} catch (IOException e){ e.printStackTrace();} return str;}} ///////////////////////////////////////////////////////////////////////////////////////////////////////////// }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
20018299e6301abd67a06ba7c64bc651
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Map<Long, Long> dm = new HashMap<>(); long mb = 0; for (int i = 0; i < n; ++i) { Long b = sc.nextLong(); Long k = i - b; Long v = 0L; if (!dm.containsKey(k)) v = b; else v = dm.get(k) + b; dm.put(k, v); mb = Math.max(mb, v); } System.out.println(mb); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
6ebdfce0d3c09a2259f5ebe8c67edc78
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
// Working program with FastReader import java.io.*; import java.util.*; public class codeforces_1321B { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader ob=new FastReader(); int n=ob.nextInt(); int arr[]=new int[n+1]; HashMap<Integer,Long>map=new HashMap<Integer, Long>(); for (int i = 1; i <= n; i++) { int val=ob.nextInt(); int diff=i-val; if(!map.containsKey(diff)){ map.put(diff,(long)val); } else{ map.put(diff,map.get(diff)+(long)val); } } long max=Integer.MIN_VALUE; for(int i:map.keySet()){ max=Math.max(max,map.get(i)); } System.out.println(max); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
6ebe41ade238357a0d8972fe47c7683b
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.*; import java.util.*; /** * Only By Abhi_Valani */ 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); Unstoppable solver = new Unstoppable(); // int t=in.nextInt(); // while(t-->0) solver.solve(in, out); out.close(); } static class Unstoppable { public void solve(InputReader in, PrintWriter out) { int n=in.nextInt(); int a[]=new int[n]; long b[]=new long[400002]; long c[]=new long[400002]; for(int i=0;i<n;i++) { a[i]=in.nextInt(); if(a[i]-(i+1)>=0) b[a[i]-(i+1)]+=a[i]; else c[(i+1)-a[i]]+=a[i]; } long max=0; for(int i=0;i<=400001;i++) { if(b[i]>max) max=b[i]; } for(int i=0;i<=400001;i++) { if(c[i]>max) max=c[i]; } out.println(max); } } 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 long nextLong(){ return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
47805d5809ad0939479815514f3e5d6a
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) throws IOException { MScanner sc=new MScanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int[]in=sc.takearr(n); HashMap<Integer, Integer>map=new HashMap<Integer, Integer>(); long[]ans=new long[n]; for(int i=n-1;i>=0;i--) { int dif=in[i]-i; if(map.containsKey(dif)) { ans[i]=in[i]+ans[map.get(dif)]; } else { ans[i]=in[i]; } map.put(dif, i); } long max=0; for(long x:ans)max=Math.max(max, x); pw.println(max); pw.flush(); } static class MScanner { StringTokenizer st; BufferedReader br; public MScanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public MScanner(String file) throws Exception { 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[] takearr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public long[] takearrl(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public Integer[] takearrobj(int n) throws IOException { Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public Long[] takearrlobj(int n) throws IOException { Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
5e15f2900f4dbaf34b865ea8202eaf8c
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.*; public class CF_1321B { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = Integer.parseInt(s.nextLine()); int[] arr = new int[n]; StringTokenizer st = new StringTokenizer(s.nextLine()); for(int i = 0; i < n; i++) { arr[i] = Integer.parseInt(st.nextToken()); } HashMap<Integer, Long> hm = new HashMap<Integer, Long>(); for(int i = 0; i < n; i++) { if(hm.containsKey(arr[i]-i)) { long x = hm.remove(arr[i]-i); hm.put(arr[i]-i, x+arr[i]); continue; } hm.put(arr[i]-i, (long)arr[i]); } long max = 0; for(int i = -400000; i <= 400000; i++) { if(hm.containsKey(i)) { if(hm.get(i) > max) { max = hm.get(i); } } } System.out.println(max); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
a1bab91d53fd0f1d2f74ee69c9b55760
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { //IHIWYLML; Scanner sc=new Scanner(System.in); int n=sc.nextInt(),v=0; long mx=-1; long ans[]=new long[400010],nans[]=new long[400010]; for(int i=1 ; i<=n ; i++) { v=sc.nextInt(); if(v-i<0) { nans[i-v]+=v; mx=Math.max(nans[i-v],mx); } else { ans[v - i] += v; mx = Math.max(mx, ans[v - i]); } } System.out.println(mx); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
dcb4983d82a0ab2fdf496cf4111ed8e1
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class CP{ public static OutputStream out=new BufferedOutputStream(System.out); static Scanner sc=new Scanner(System.in); static long mod=1000000007l; //nl-->neew line; //l-->line; //arp-->array print; //arpnl-->array print new line public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes()); out.flush();} public static void l(Object o) throws IOException{out.write((o+"").getBytes());} public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());} public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());} public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();} public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();} public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();} // static long cnt; static TreeSet<Integer> ans; static int n,m; static boolean[][] dp,vis; static HashMap<Pair,Boolean> arrl; public static void main(String[] args) throws IOException{ long sttm=System.currentTimeMillis(); long mod=1000000007l; int n=sc.nextInt(); long[] b=new long[n]; for(int i=0;i<n;i++){ b[i]=sc.nextLong()-i; } HashMap<Long,Long> map=new HashMap<Long,Long>(); for(int i=0;i<n;i++){ if(!map.containsKey(b[i])){ map.put(b[i],0l); } map.put(b[i],map.get(b[i])+b[i]+i); } long sum=0; Iterator<Long> it=map.keySet().iterator(); while(it.hasNext()){ sum=Math.max(sum,map.get(it.next())); } nl(sum); out.flush(); } } class Pair{ int x,y; Pair(int x,int y){ this.x=x; this.y=y; } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
4802ee7ddf0beb8c5f0423cefa33a01e
train_003.jsonl
1583068500
Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 &gt; c_1$$$, then to some other city $$$c_3 &gt; c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k &gt; c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey: $$$c = [1, 2, 4]$$$; $$$c = [3, 5, 6, 8]$$$; $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class B { final int INF = 0x3f3f3f3f; BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; // int L = 200010; int n, m; int[] l = new int[L]; int[] ans = new int[L]; // public B() { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } public static void main(String[] args) { new B(); } private void solve() { n = nextInt(); Map<Integer, Long> ans = new HashMap<>(); for (int i = 0; i < n; i++) { int index = nextInt() - i; if (!ans.containsKey(index)) { ans.put(index, 0L); } ans.put(index, ans.get(index) + index + i); } long anss = 0; for (long an : ans.values()) { anss = Math.max(anss, an); } System.out.println(anss); } private void outln(Object o) { out.println(o); } private void out(Object o) { out.print(o); } public long[] nextLongArr(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } public int[] nextIntArr(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return null; } } return st.nextToken(); } public String nextString() { try { return br.readLine(); } catch (IOException e) { eof = true; return null; } } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } }
Java
["6\n10 7 1 9 10 15", "1\n400000", "7\n8 9 26 11 12 29 14"]
2 seconds
["26", "400000", "55"]
NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.
Java 11
standard input
[ "data structures", "sortings" ]
aab8d5a2d42b4199310f3f535a6b3bd7
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.
1,400
Print one integer — the maximum beauty of a journey Tanya can choose.
standard output
PASSED
8d52cfcd9ae8369a08a9d87ed35aa9c3
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Integer.*; //import static java.lang.Long.*; public class SF { public static void main(String[] args) throws IOException{ BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int t=parseInt(in.readLine()); StringBuilder sb=new StringBuilder(""); while(t-->0) { int n=parseInt(in.readLine()); if(n%2==0) { int c=n/2; while(c-->0) sb.append(1); } else { sb.append(7); int c=(n-3)/2; while(c-->0) sb.append(1); } sb.append("\n"); } out.println(sb); out.flush(); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
a541263de0f93e07bcfc55f4dca846f6
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 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 String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } 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<'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 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 String readString() { 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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } // if modulo is required set value accordingly public static long[][] matrixMultiply2dL(long t[][],long m[][]) { long res[][]= new long[t.length][m[0].length]; for(int i=0;i<t.length;i++) { for(int j=0;j<m[0].length;j++) { res[i][j]=0; for(int k=0;k<t[0].length;k++) { res[i][j]+=t[i][k]+m[k][j]; } } } return res; } static long combination(long n,long r) { long ans=1; for(long i=0;i<r;i++) { ans=(ans*(n-i))/(i+1); } return ans; } public static void main(String args[]) throws Exception { new Thread(null, new Main(),"Main",1<<27).start(); } public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int i = 0; int j = 0; if(n%2!=0){ w.print("7"); j = 3; } while(i+j<n) { w.print("1"); i+=2; } w.println(""); } System.out.flush(); w.close(); } } //https://codeforces.com/problemset/problem/1295/A
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
ffcc30eab9d8855a61f43bedfdbd0a30
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.DataInputStream; import java.io.IOException; public class Edu { private static class Reader { final private int BUFFER_SIZE = 1 << 512; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; private Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } private int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } } public static void main(String args[]) throws Exception { Reader reader=new Reader(); int T=reader.nextInt(); while(T-->0) { long N=reader.nextLong(); if(N%2==1) { System.out.print('7'); for(long i=0;i<(N/2)-1;i++) { System.out.print('1'); } } else { for(long i=0;i<(N/2);i++) { System.out.print('1'); } } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
c790f69173045cfe84bffc643620f0d7
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.Scanner; public class ProblemB { // This code is contributed by PrinciRaj1992 public static void solve() { Scanner sc=new Scanner(System.in); int count= sc.nextInt(); for(int i=0;i<count;i++) { StringBuilder s=new StringBuilder(""); int n=sc.nextInt(); if(n==3) {System.out.println("7"); continue;} if(n==2) {System.out.println("1"); continue;} if(n%2==0) { for(int j=0;j<n/2;j++) { s.append("1"); } } else { s.append("7"); for(int j=0;j<n/2-1;j++) { s.append("1"); } } System.out.println(s); } } public static void main(String [] args) { solve(); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
e2b3e5998bcfcc7d0addb6549728f638
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.math.BigInteger; import java.util.*; /** * Prime Words. * * @author Izhari Ishak Aksa */ public class Main { static boolean isDistinct(int N) { String S = N + ""; char A[] = S.toCharArray(); for (int I = 0; I <= A.length - 2; I++) { for (int J = I + 1; J <= A.length - 1; J++) { //System.out.println(A[J] + " " + A[J+1]); if (A[I] == A[J]) { return false; } } } return true; } static boolean isPrime(int N) { for (int I = 2; I * I <= N; I++) { if (N % I == 0) { return false; } } return true; } static long Square(long A) { return A * A; } static long Pow(long A, long Pow) { if (Pow == 0) { return 1; } else if (Pow == 1) { return 16; } for (long I = 1; I < Pow; I++) { A *= 16; } return A; } public static BigInteger Sqrt(BigInteger x, BigInteger f) { BigInteger div = BigInteger.ZERO.setBit(x.bitLength() / 2); BigInteger div2 = div; // Loop until we hit the same value twice in a row, or wind // up alternating. for (;;) { BigInteger y = div.add(x.divide(div)).shiftRight(1); if (y.equals(div) || y.equals(div2)) { return y; } div2 = div; div = y; } } public static void main(String[] args) { Scanner Input = new Scanner(System.in); int T = Input.nextInt(); for (int I = 0; I < T; I++) { int N = Input.nextInt(); if (N % 2 == 1) { System.out.print("7"); for (int J = 0; J < (N - 3) / 2; J++) { System.out.print("1"); } } else { //String S = ""; for (int J = 0; J < N / 2; J++) { System.out.print("1"); } } System.out.println(""); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
1a4d6e1903e8bab9a60098430b2ae63a
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub int[]arr = {6,2,5,5,4,5,6,3,7,6}; Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0){ int n = scn.nextInt(); res(n); } } public static void res(int n){ StringBuilder sb = new StringBuilder(); if(n%2==0){ int val=0; while(val<(n/2)){ sb.append(1); val++; } }else{ sb.append(7); int n1= n/2-1; int val=0; while(val<n1){ sb.append(1); val++; } } System.out.println(sb); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
78ccb6a0536a645d778b5530f86eadde
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); StringBuilder s=new StringBuilder(""); if(n%2==0){ for(int i=0;i<(n/2);i++){ s.append("1"); } } else{ s.append("7"); n=n-3; for(int i=0;i<(n/2);i++){ s.append("1"); } } bw.write(s+"\n"); } bw.flush(); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
e5b94a5358f0cf9b61792f1673b64c97
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.Scanner; //https://codeforces.com/contest/1295/problem/A public class Codeforces3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t =0; if(sc.hasNext()){t=sc.nextInt();} while(t-->0){ int num = sc.nextInt(); if(num%2==0){ int num1=num/2; while(num1-->0){ System.out.print(1); } } else{ num=num-3; System.out.print(7); for(int i =0;i<num/2;i++){ System.out.print(1); } } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
367966f9dda75b7bf7e2951f6a3d3d05
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) throws java.lang.Exception { // your code goes here FastReader scn=new FastReader(); int t=scn.nextInt(); StringBuilder sb=new StringBuilder(); while(t-->0) { int n=scn.nextInt(); if(n==2) { sb.append(1+"\n"); } else if(n==3) { sb.append(7+"\n"); } else { if(n%2==0) { int x=1; StringBuilder d=new StringBuilder(); while(x<=n/2) { d.append(1); x++; } sb.append(d+"\n"); } else { StringBuilder d=new StringBuilder(); int x=1; d.append(7); while(x<n/2) { d.append(1); x++; } sb.append(d+"\n"); } } } System.out.print(sb); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
7ad7054cfe994206a498233762d14089
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; public class S { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); //String res=""; if(n%2==0) { for(int j=0;j<n/2;j++) { // res=res+"1"; System.out.print("1"); } } else { //res="7"; System.out.print("7"); for(int j=0;j<(n-3)/2;j++) { //res=res+"1"; System.out.print("1"); } } System.out.println(""); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
d5f54f4fb2835a086fe9cc5945ddbe0c
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
//package codeforces; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); int t=scanner.nextInt(); for(int j=0;j<t;j++){ int n=scanner.nextInt(); StringBuilder stringBuilder=new StringBuilder(); // int te=n/2; // int tt=n/3; // int re=n%3; // tt+=re/2; if(n%2==0 ){ // int rem=re; // while (n>=3) { // stringBuilder.append(7); // rem=n%3; // n=n-3; // // } while(n>=2){ stringBuilder.append(1); n=n-2; } } else { if (n>=3){ stringBuilder.append(7); n=n-3; } while(n>=2){ stringBuilder.append(1); n=n-2; } } System.out.println(stringBuilder.toString()); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
526a7648dc6c7d617810daff326216f7
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author laxit */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { int test = in.nextInt(); while (test-- > 0) { int n = in.nextInt(); if (n % 2 == 0) { n = n / 2; } else { n = (n - 3) / 2; out.print(7); } while (n-- > 0) out.print(1); out.println(); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void println() { writer.println(); } public void close() { writer.close(); } public void print(int i) { writer.print(i); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.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 nextInt() { 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 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; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
a3e46a917a8a4667381e665766e0c002
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
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 { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); String s=""; if(n%2==0){ for(int i=0;i<n/2;i++){ System.out.print("1"); } } else{ System.out.print("7");n-=3; for(int i=0;i<n/2;i++){ System.out.print("1"); } } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
6df63ab6cfb1b146db42fe670f59ce41
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Random; import java.util.StringTokenizer; import java.util.Arrays; public class hello{ public static void main(String[] args){ FastScanner scanner = new FastScanner(System.in); int t=scanner.nextInt(); int n; String str=""; while(t-->0){ n=scanner.nextInt(); if(n%2==0){ for(int i=0;i<n/2;i++){ System.out.print("1"); } } else{ System.out.print("7"); for(int i=0;i<(n-3)/2;++i){ System.out.print("1"); } } System.out.println(); } } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream)); } catch (Exception e) { e.printStackTrace(); } } 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()); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
892dc3b8895f3ff363869db56b9c9ba5
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void solve(InputReader in) { int n = in.readInt(); if ( n % 2 != 0) { n -= 3; System.out.print(7); } for(int i = 0; i<n/2; i++) { System.out.print(1); } System.out.println(); } public static void main(String ...strings) { InputReader in = new InputReader(System.in); int t = in.readInt(); while(t-- > 0) { solve(in); } } } class InputReader{ 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 readInt() { 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 String readString() { 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 long readLong() { 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 boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
a64ff2185166b88cb6954ce72d5a2ac9
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.InputMismatchException; public class A { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub InputReader s = new InputReader(System.in); PrintWriter p = new PrintWriter(System.out); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int digits = n / 2; if (n < 2) { System.out.println(0); } StringBuilder ans = new StringBuilder(); for (int i = 0; i < digits; i++) { ans.append(1); } int rem = n % 2; if (rem == 1) { ans.replace(0, 1, "7"); } System.out.println(ans); } p.flush(); p.close(); } public static boolean checktwo(int div, int x) { for (int i = 2; i <= Math.sqrt(div); i++) { if (i == x) { continue; } if (div % i == 0) { if (div / i != i && div / i != x && div / i != 1) { int val = div / i; System.out.println("YES"); System.out.println(x + " " + i + " " + val); return true; } } } return false; } public static void sieveOfEratosthenes(boolean prime[]) { int n = prime.length - 1; for (int i = 0; i < n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } if (prime.length >= 2) prime[1] = false; } public static boolean prime(long n) { if (n == 1) { return false; } if (n == 2) { return true; } for (long i = 2; i <= (long) Math.sqrt(n); i++) { if (n % i == 0) return false; } return true; } public static ArrayList Divisors(long n) { ArrayList<Long> div = new ArrayList<>(); for (long i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { div.add(i); if (n / i != i) div.add(n / i); } } return div; } public static int BinarySearch(long[] a, long k) { int n = a.length; int i = 0, j = n - 1; int mid = 0; if (k < a[0]) return 0; else if (k >= a[n - 1]) return n; else { while (j - i > 1) { mid = (i + j) / 2; if (k >= a[mid]) i = mid; else j = mid; } } return i + 1; } public static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); } public static long LCM(long a, long b) { return (a * b) / GCD(a, b); } static class pair implements Comparable<pair> { Integer x, y; pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(pair o) { int result = x.compareTo(o.x); if (result == 0) result = y.compareTo(o.y); return result; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x - x == 0 && p.y - y == 0; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class CodeX { public static void sort(long arr[]) { merge_sort(arr, 0, arr.length - 1); } private static void merge_sort(long A[], long start, long end) { if (start < end) { long mid = (start + end) / 2; merge_sort(A, start, mid); merge_sort(A, mid + 1, end); merge(A, start, mid, end); } } private static void merge(long A[], long start, long mid, long end) { long p = start, q = mid + 1; long Arr[] = new long[(int) (end - start + 1)]; long k = 0; for (int i = (int) start; i <= end; i++) { if (p > mid) Arr[(int) k++] = A[(int) q++]; else if (q > end) Arr[(int) k++] = A[(int) p++]; else if (A[(int) p] < A[(int) q]) Arr[(int) k++] = A[(int) p++]; else Arr[(int) k++] = A[(int) q++]; } for (int i = 0; i < k; i++) { A[(int) start++] = Arr[i]; } } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
ceb0b1ff617aa5f566e965302a8fc2cb
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Cf182 implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 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 String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } 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<'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 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 String readString() { 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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Cf182(),"Main",1<<27).start(); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } // array sorting by colm static void sortbycolomn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } // gcd public static long findGCD(long arr[], int n) { long result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result); return result; } // fibonaci static int fib(int n) { int a = 0, b = 1, c; if (n == 0) return a; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } // sort a string public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int t = sc.nextInt(); int n; for(int k=0;k<t;k++) { n = sc.nextInt(); if(n==3) System.out.println("7"); else { if(n%2==0) { for(int i=0;i<n/2;i++) System.out.print("1"); System.out.println(); } else { System.out.print("7"); for(int i=0;i<n/2-1;i++) System.out.print("1"); System.out.println(); } } } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
d27e044f5f54082ddb2f287fefc75813
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; public class Cp { static String ret(int n,int m){ StringBuilder s = new StringBuilder(); if(m!=0){ s.append(String.valueOf(m)); } while(n>0){ s.append("1"); n--; } return s.toString(); } public static void main(String[] args) { Scanner in =new Scanner(System.in); int n = in.nextInt(); for(int j=0;j<n;j++){ int x = in.nextInt(); int m; int nf; nf = x/2; m = x%2; if(m==1){ nf = nf-1; m = 7; System.out.println(ret(nf,m)); }else { System.out.println(ret(nf,m)); } } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
40ebcb18a8ba25115c44285171885b4c
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
// 0 1 2 3 4 5 6 7 8 9 // 6 2 5 5 4 5 6 3 7 6 import java.util.*; import java.io.*; public class Display { public static void main (String[] args) throws IOException { Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); for(int i=0; i<testCases; i++) { int n = scan.nextInt(); if(n%2!=0) { System.out.print(7); n = n-3; } while(n>=2) { System.out.print(1); n = n-2; } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
b29cebd555a8c977234bcb687a05936e
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.io.*; public class Eric_Z_l2_lesson2 { public static void main (String[] args) throws IOException { //BufferedReader br = new BufferedReader (new FileReader("1.in")); // 0 1 2 3 4 5 6 7 8 9 // 6 2 5 5 4 5 6 3 7 6 Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); for(int i=0; i<testCases; i++) { int n = scan.nextInt(); if(n%2!=0) { System.out.print(7); n = n-3; } while(n>=2) { System.out.print(1); n = n-2; } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
48d25e9e9da745bc09d9eaca8e50dfb3
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.io.*; public class L2Lesson1{ public static void main(String[] arg){ // Change // { // Scanner scan = new Scanner(System.in); // int money = scan.nextInt(); // System.out.print(money+" cents requires "); // int quarters = money/25; // money = money%25; // if(quarters!=0){ // System.out.print(quarters+" quarters"); // } // int dimes = money/10; // money = money%10; // if(dimes!=0){ // if(quarters!=0){ // System.out.print(", "); // } // System.out.print(dimes+" dimes"); // } // int nickels = money/5; // money = money%5; // if(nickels!=0){ // if(dimes!=0 || quarters!=0){ // System.out.print(", "); // } // System.out.print(nickels+" nickels"); // } // int cents = money; // if(cents!=0){ // if(nickels!=0 || dimes!=0 || quarters!=0){ // System.out.print(", "); // } // System.out.print(cents+" cents"); // } // System.out.print("."); // } // Display The Number A { // 0 1 2 3 4 5 6 7 8 9 // 6 2 5 5 4 5 6 3 7 6 Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); for(int i=0; i<testCases; i++){ int n = scan.nextInt(); if(n%2!=0){ System.out.print(7); n = n - 3; } while(n>=2){ System.out.print(1); n = n-2; } System.out.println(); } } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
2c8d74332e8ee0559d4ef8df2bd1873b
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
// Greedy Algorithms import java.util.*; import java.io.*; public class li_l2_lesson1{ public static void main(String[] arg){ // Change // { // // Write a program that makes change for amounts less than one dollar with the least number of coins. // // Input // // Input will be a positive integer less than 100, representing an amount of money in cents. // // Output // // Output should be the original amount of money together with a minimal set of coins // // (quarters, nickels, dimes, cents) that could make up that amount. // // Sample Input // // 58 // // Sample Output // // 58 cents requires 2 quarters, 1 nickel, 3 cents. // // Note: // // 58 cents requires 2 quarters, 0 dimes, 1 nickels, 3 cents. // // will not be accepted. // Scanner scan = new Scanner(System.in); // int money = scan.nextInt(); // System.out.print(money + " cents requires "); // int q = money/25; // money = money%25; // if(q!=0){ // System.out.print(q + " quarters"); // } // int d = money/10; // money = money%10; // if(d!=0){ // if(q!=0){ // System.out.print(", "); // } // System.out.print(d + " dimes"); // } // int n = money/5; // money = money%5; // if(n!=0){ // if(q!=0 || d!=0){ // System.out.print(", "); // } // System.out.print(n + " nickels"); // } // if(money!=0){ // if(q!=0 || d!=0 || n!=0){ // System.out.print(", "); // } // System.out.print(money + " cents"); // } // System.out.print("."); // } // Display The Number { // https://codeforces.com/problemset/problem/1295/A // 0 1 2 3 4 5 6 7 8 9 // 6 2 5 5 4 5 6 3 7 6 Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); for(int i=0; i<testCases; i++){ int n = scan.nextInt(); if(n%2!=0){ System.out.print(7); n = n - 3; } while(n>=2){ System.out.print(1); n = n - 2; } System.out.println(); } } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
8eb9139188984e620c8625f7cde8d74a
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.io.*; public class testfile{ public static void main(String[] arg){ // Display The Number { // https://codeforces.com/problemset/problem/1295/A Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int[][] answers = new int[t][]; for (int i = 0; i < t; i++) { int n = scanner.nextInt(); answers[i] = maxInteger(n); } for (int j = 0; j < answers.length; j++) { for (int k = 0; k < answers[j].length; k++) { System.out.print(answers[j][k]); } System.out.println(); } } } public static int[] maxInteger(int n) { int count; int[] maxArr; if (n % 2 == 0) { count = n / 2; maxArr= new int[count]; Arrays.fill(maxArr, 1); return maxArr; } else { count = n / 2; maxArr = new int[count]; Arrays.fill(maxArr, 1); maxArr[0] = 7; return maxArr; } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
e94d15af76989df10618645107f1e68c
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.io.*; public class testfile{ public static void main(String[] arg){ // Display The Number { // https://codeforces.com/problemset/problem/1295/A Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int[][] answers = new int[t][]; for (int i = 0; i < t; i++) { int n = scanner.nextInt(); answers[i] = maxInteger(n); } for (int j = 0; j < answers.length; j++) { for (int k = 0; k < answers[j].length; k++) { System.out.print(answers[j][k]); } System.out.println(); } } } public static int[] maxInteger(int n) { int count; int[] maxArr; if (n % 2 == 0) { count = n / 2; maxArr= new int[count]; Arrays.fill(maxArr, 1); return maxArr; } else { count = n / 2; maxArr = new int[count]; Arrays.fill(maxArr, 1); maxArr[0] = 7; return maxArr; } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
602d55af4293ef392603f809710b23b5
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class A { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); InputReader re=new InputReader(System.in); int t=re.nextInt(); int []a=new int[]{6,2,5,5,4,5,6,3,7,6}; while (t-->0){ int n=re.nextInt(); int len=(n>>1); int res[]=new int[len]; for(int i=0;i<len;i++) res[i]=1; n-=(len<<1); int index=0; while (index<len&&n>0){ int i; for(i=a.length-1;i>=0;i--) if(a[i]-2<=n)break; if(i>=0){ n-=(a[i]-2); res[index]=i; } index++; } StringBuilder s=new StringBuilder(); for(int i=0;i<res.length;i++) s.append(res[i]); out.println(s); out.println(); } out.flush(); } static class InputReader{ private BufferedReader in; private StringTokenizer tokenizer; public InputReader(InputStream stream){ in = new BufferedReader(new InputStreamReader(stream),32768); tokenizer = null; } public String next() throws IOException{ while(tokenizer==null || !tokenizer.hasMoreTokens()){ tokenizer = new StringTokenizer(in.readLine()); } return tokenizer.nextToken(); } public Long nextLong() throws IOException { String next = next(); return Long.valueOf(next); } public int nextInt() throws IOException{ return Integer.valueOf(next()); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
bcb469bdafd2494b4698f5f15172e6fc
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int test=sc.nextInt(); String s = new String(); s=""; while(test-->0) { int n=sc.nextInt(); if(n%2==1) { System.out.print("7"); for(int i = 0; i < n / 2 - 1; ++i) System.out.print("1"); System.out.println(); } else { for(int i = 0; i < n / 2; ++i) System.out.print("1"); System.out.println(); } } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
e7bd9df64735fca038fa72d0928f0eec
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class sol { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); if((n&1) !=0) { System.out.print(7); n -= 3; } while(n>0) { System.out.print(1); n -= 2; } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
8e7aefc0938fb24c83b755584dc7cf58
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
// package EducationalRound81; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class ProblemA { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int test=Integer.parseInt(br.readLine()); StringBuilder print=new StringBuilder(); int a[]=new int[8]; a[2]=1;a[3]=7;a[4]=11; while(test--!=0){ int n=Integer.parseInt(br.readLine()); StringBuilder temp=new StringBuilder(); if(n%2!=0){ temp.append(7); n-=3; } while(n!=0){ if(n>=2){ n-=2; temp.append(a[2]); continue; } } print.append(temp.toString()+"\n"); } System.out.println(print.toString()); } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
63a091ca2a150d94d957f4fea2a838a2
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.*; public class A{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t= sc.nextInt(); while(t>0){ int n = sc.nextInt(); int x=1;int y=7; if(n==3){ System.out.println(y); }else if(n%2==0){ int val=n/2; while(val>0){ System.out.print(x); val--; } System.out.println(); }else{ int val = n/2; System.out.print(y); val--; while(val>0){ System.out.print(x); val--; } System.out.println(); } t--; } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
4ec2dde84979cbfb5fcee87338705084
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.Scanner; public class A{ public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- >0) { int n = s.nextInt(); StringBuilder out = new StringBuilder(); if(n%2==1) { out.append("7"); n=n-3; } n = n/2; while(n-- >0) out.append("1"); System.out.println(out); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
9b3e51e67b1b23d4ed8e24ace6f3c4a0
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Demo09 { private static String findAns(int n) { if(n==3) { return "7"; } else { if(n%2==0) { int num = n/2; char[] charArray = new char[num]; Arrays.fill(charArray,'1'); return new String(charArray); } else { int num = n/2; char[] charArray = new char[num-1]; Arrays.fill(charArray,'1'); return "7"+new String(charArray); } } } public static void main(String [] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i =0;i<t;i++) { int n = in.nextInt(); System.out.println(findAns(n)); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
847a7e51403407656bc160f272a48396
train_003.jsonl
1580308500
You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.
256 megabytes
import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0;i<t;i++) { int n=scan.nextInt(); while(n%2==1) { System.out.print(7); n-=3; } while (n>0) { System.out.print(1); n-=2; } System.out.println(); } } }
Java
["2\n3\n4"]
1 second
["7\n11"]
null
Java 8
standard input
[ "greedy" ]
07db573b0db736d798b6c18c06c32f3d
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.
900
For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.
standard output
PASSED
2f471e1351be275ab5b66cca0ecb374e
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main{ public static int[] readInts(String cad) { String read[] = cad.split(" "); int res[] = new int[read.length]; for (int i = 0; i < read.length; i++) { res[i] = Integer.parseInt(read[i]); } return res; } public static long[] readLongs(String cad) { String read[] = cad.split(" "); long res[] = new long[read.length]; for (int i = 0; i < read.length; i++) { res[i] = Long.parseLong(read[i]); } return res; } static void printArrayInt(int[] array) { if (array == null || array.length == 0) return; for (int i = 0; i < array.length; i++) { if (i > 0) System.out.print(" "); System.out.print(array[i]); } System.out.println(); } static void printMatrixInt(int[][] array) { if (array == null || array.length == 0) return; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[0].length; j++) { if (j > 0) System.out.print(" "); System.out.print(array[i][j]); } System.out.println(); } } public static int max(int arr[]) { int max = arr[0]; for (int i = 1; i < arr.length; i++) { max = Math.max(max, arr[i]); } return max; } public static int min(int arr[]) { int min = arr[0]; for (int i = 1; i < arr.length; i++) { min = Math.min(min, arr[i]); } return min; } public static int arr[]; public static int a, b; public static class Node implements Comparable<Node> { int init; public Node(int init) { this.init = init; } @Override public int compareTo(Node o) { for (int i = 1; i < arr.length; i++) { if (arr[(i + init) % arr.length] < arr[(init) % arr.length]) { a = 10 - (arr[(init) % arr.length] - arr[(i + init) % arr.length]); } else { a = arr[(i + init) % arr.length] - arr[(init) % arr.length]; } if (arr[(i + o.init) % arr.length] < arr[(o.init) % arr.length]) { b = 10 - (arr[(o.init) % arr.length] - arr[(i + o.init) % arr.length]); } else { b = arr[(i + o.init) % arr.length] - arr[(o.init) % arr.length]; } if (a > b) { return 1; } else if (a < b) return -1; } return 0; } } public static void main(String[] args) throws IOException { BufferedReader in; StringBuilder out = new StringBuilder(); File f = new File("entrada"); if (f.exists()) { in = new BufferedReader(new FileReader(f)); } else in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); arr = new int[n]; char c[] = in.readLine().toCharArray(); for (int i = 0; i < arr.length; i++) { arr[i] = c[i] - '0'; } Node nodos[] = new Node[arr.length]; for (int i = 0; i < arr.length; i++) { nodos[i] = new Node(i); } Arrays.sort(nodos); int index = nodos[0].init; int dif = arr[index]; for (int i = 0; i < arr.length; i++) { if (arr[(i + index) % arr.length] < dif) { out.append((10 - (dif - arr[(i + index) % arr.length]))); } else { out.append(arr[(i + index) % arr.length] - dif); } } System.out.print(out); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
92fa4014e971d346500a56d6be6e87f7
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; import java.util.TreeSet; public class Main { static class MyString implements Comparable<MyString> { String s ; MyString (String ss) { s = ss; } @Override public int compareTo(MyString myString) { String s1 = s , s2 = myString.s; int start1 = 0 , start2 = 0; for (int i = 0 ; i < s1.length() ; ++ i) { if (s1.charAt(i) != '0') { start1 = i; break; } } for (int i = 0 ; i < s2.length() ; ++ i) { if (s2.charAt(i) != '0') { start2 = i; break; } } if (start1 < start2) return 1; else if (start2 < start1) return - 1; else { for (int i = start1 ; i < s1.length() ; ++ i) { if (s1.charAt(i) != s2.charAt(i)) { return s1.charAt(i) - s2.charAt(i); } } } return 0; } } public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char [] res = sc.next().toCharArray(); TreeSet<MyString> treeSet = new TreeSet<>(); int idx = 1; do { String cur = "" ; for (int i = 0 ; i < res.length ; ++ i) { cur += res[i]; } treeSet.add(new MyString(cur)); for (int i = 0 ; i < res.length ; ++ i) { cur = cur.charAt(cur.length() - 1) + cur.substring(0 , cur.length() - 1); treeSet.add(new MyString(cur)); } for (int i = 0 ; i < res.length ; ++ i) { res[i] = (char)(((res[i] + 1) % ('9' + 1))); if ((int)res[i] == 0) res[i] = '0'; } } while (idx ++ < 10); System.out.println(treeSet.first().s); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
7e7469d1e1758591fb1902faf9386698
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; /** * * @author bassem */ public class Main { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int x = Integer.parseInt(input.readLine()); String lock = input.readLine(); char[] work = lock.toCharArray(); String[] saved = new String[10]; for (int i = 0; i < 10; i++) { for (int j = 0; j < x; j++) { if (work[j] != '9') { work[j]++; } else { work[j] = '0'; } } String saved1 = ""; for (int j = 0; j < work.length; j++) { saved1 += work[j]; } saved[i] = saved1; } String[] saves = new String[x * 10]; int ind = 0; for (int j = 0; j < 10; j++) { saves[ind++] = saved[j]; for (int i = 1; i < x; i++) { //System.out.println("sssss"); saves[ind] = saves[ind - 1].substring(1) + saves[ind - 1].charAt(0); ind++; } } Arrays.sort(saves); System.out.println(saves[0]); //System.out.println(locknow); //StringTokenizer line = new StringTokenizer(input.readLine()); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
078e4fc297768cb42d2f74bdc8d4dc17
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public final class Solution { public static void main(String[] args) { Reader input = new Reader(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int n = input.nextInt(); char[] s = input.next().toCharArray(); int[] arr = new int[n]; for(int i = 0 ; i < n ; i++) arr[i] = s[i] - '0'; int[] min = new int[n]; for(int i = 0 ; i < n ; i++) min[i] = arr[i]; for(int i = 0 ; i < 10 ; i++) { int[] temp = new int[n]; for(int j = 0 ; j < n ; j++) { temp[j] = (arr[j] + i) % 10; } for(int j = 0 ; j < n ; j++) { int t = temp[n-1]; for(int k = n - 1 ; k >= 1 ; k--) { temp[k] = temp[k-1]; } temp[0] = t; for(int f = 0 ; f < n ; f++) { if(temp[f] < min[f]) { for(int m = 0 ; m < n ; m++) min[m] = temp[m]; break; } else if(temp[f] > min[f]) break; } } } for(int i = 0 ; i < n ; i++) out.print(min[i]); out.close(); } public static int z(int n) { /*finds the number of trailing zeros in factorial */ int count = 0; for(int i = 5 ; i <= n ; i *= 5) { count += n / i; } return count; } public static int gcd(int a , int b) { if(b == 0) return a; return gcd(b , a %b); } public static class Pair implements Comparable<Pair> { int a , b; public Pair(int a , int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair t) { // TODO Auto-generated method stub if(t.a == this.a) { if(this.b < t.b) return -1; else if(this.b > t.b) return 1; else return 0; } else if(this.a < t.a) return -1; else return 1; } } public static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { try { if(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); } catch(IOException ex) { ex.printStackTrace(); System.exit(1); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextLine() { try { return br.readLine(); } catch(IOException ex) { ex.printStackTrace(); System.exit(1); } return ""; } } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
350656785213b4b271178b06a5ddc90b
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(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, Scanner in, PrintWriter out) { int n = in.nextInt(); int minI = 0; int minJ = 0; String s = in.next(); for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { boolean bigger = false; for (int k = 0; k < n; k++) { int modif = ((s.charAt((k - i + n) % n) - '0') + j) % 10; int orig = ((s.charAt((k - minI + n) % n) - '0') + minJ) % 10; if (modif < orig) { minI = i; minJ = j; break; } else if (modif > orig) break; } } } for (int k = 0; k < n; k++) { int orig = ((s.charAt((k - minI + n) % n) - '0') + minJ) % 10; out.print(orig); } } } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
aef7f93d467cd4cae8b7eb7f71a4fabf
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(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, Scanner in, PrintWriter out) { /*int n = in.nextInt(); int minI = 0; int minJ = 0; String s = in.next(); for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { boolean bigger = false; for (int k = 0; k < n; k++) { int modif = ((s.charAt((k - i + n) % n) - '0') + j) % 10; int orig = ((s.charAt((k - minI + n) % n) - '0') + minJ) % 10; if (modif < orig) { minI = i; minJ = j; break; } else if (modif > orig) break; } } } for (int k = 0; k < n; k++) { int orig = ((s.charAt((k - minI + n) % n) - '0') + minJ) % 10; out.print(orig); }*/ int n = in.nextInt(); String s = in.next(); char[][] pos = new char[10][n]; pos[0] = s.toCharArray(); for (int i = 0; i < n; i++) { for (int j = 1; j < 10; j++) { pos[j][i] = (char) (((pos[j - 1][i] - '0' + 1) % 10) + '0'); } } String[] posMin = new String[10]; for (int j = 0; j < 10; j++) { posMin[j] = min_cyclic_shift(pos[j]); } int minInd = 0; for (int j = 0; j < 10; j++) { for (int i = 0; i < n; i++) { if (posMin[minInd].charAt(i) > posMin[j].charAt(i)) { minInd = j; break; } if (posMin[minInd].charAt(i) < posMin[j].charAt(i)) { break; } } } out.println(posMin[minInd]); } String min_cyclic_shift(char[] ca) { String s = (new String(ca)) + (new String(ca)); int n = s.length(); int i = 0, ans = 0; while (i < n / 2) { ans = i; int j = i + 1, k = i; while (j < n && s.charAt(k) <= s.charAt(j)) { if (s.charAt(k) < s.charAt(j)) k = i; else ++k; ++j; } while (i <= k) i += j - k; } return s.substring(ans, ans + n / 2); } } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
47796fc2001e2df47cddc7a120f1f456
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } } class Task { public void solve(int testNumber, InputReader in, OutputWriter out) { int n=in.readInt(); char[] str=in.readString().toCharArray(); List<String> list=new ArrayList<>(); for (int i=0; i<n; i++) { StringBuilder aux=new StringBuilder(); int d='9'+1-str[i]; for (int j=0; j<n; j++) { int x=str[(j+i)%n]+d; if (x>'9') x-=10; aux.append((char)x); } list.add(aux.toString()); } Collections.sort(list); out.printLine(list.get(0)); } } 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 readInt() { 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 readLong() { 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 readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) 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 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(readString()); } 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, readInt()); 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, readInt()); 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 readString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter( outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(char[] array) { writer.print(array); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void print(int[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) writer.print(' '); writer.print(array[i]); } } public void print(long[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) writer.print(' '); writer.print(array[i]); } } public void print(Collection<Integer> collection) { boolean first = true; for (int i : collection) { if (first) first = false; else writer.print(' '); writer.print(i); } } public void printLine(int[] array) { print(array); writer.println(); } public void printLine(long[] array) { print(array); writer.println(); } public void printLine(Collection<Integer> collection) { print(collection); writer.println(); } public void printLine() { writer.println(); } public void printLine(Object... objects) { print(objects); writer.println(); } public void print(char i) { writer.print(i); } public void printLine(char i) { writer.println(i); } public void printLine(char[] array) { writer.println(array); } public void printFormat(String format, Object... objects) { writer.printf(format, objects); } public void close() { writer.close(); } public void flush() { writer.flush(); } public void print(long i) { writer.print(i); } public void printLine(long i) { writer.println(i); } public void print(int i) { writer.print(i); } public void printLine(int i) { writer.println(i); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
227d317638dd9d24901fdbbd39ffbd4c
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.*; public class cf_496B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] disp = br.readLine().toCharArray(); int[][] combi = new int[10][n]; int[] temp = new int[n]; int[] flag = new int[n]; int[] max_index_min_index = new int[10]; for(int i = 0; i < n; i++) temp[i] = Character.getNumericValue(disp[i]); int y = 0, z = 1; int[][] min_index = new int[10][n]; for(int c = 0; c < 10; c++) { for(int i = 0; i < n; i++) { flag[i] = temp[i]; temp[i]++; if(temp[i] == 10) temp[i] = 0; } combi[c][0] = flag[0]; min_index[c][0] = 0; for(int i = 1; i < n; i++) { combi[c][i] = flag[i]; if(combi[c][i] < combi[c][min_index[c][0]]) { min_index[c] = new int[n]; min_index[c][0] = i; } else if(combi[c][i] == combi[c][min_index[c][0]]) { min_index[c][z] = i; z++; } } max_index_min_index[c] = z; z = 1; } int[][] min = new int[10][n]; for(int j = 0; j < 10; j++) { int[][] ans = new int[max_index_min_index[j]][n]; for(int a = 0; a < max_index_min_index[j]; a++) { y = 0; for(y = min_index[j][a]; y < n; y++) ans[a][y - min_index[j][a]] = combi[j][y]; for(int i = 0; i < min_index[j][a]; i++) ans[a][y - min_index[j][a] + i] = combi[j][i]; } min[j] = ans[0]; for(int a = 1; a < max_index_min_index[j]; a++) { for(int i = 0; i < n; i++) { if(min[j][i] < ans[a][i]) break; else if(min[j][i] == ans[a][i]) continue; else { min[j] = ans[a]; break; } } } } int[] password = min[0]; for(int a = 1; a < 10; a++) { for(int i = 0; i < n; i++) { if(password[i] < min[a][i]) break; else if(password[i] == min[a][i]) continue; else { password = min[a]; break; } } } for(int i = 0; i < n; i++) System.out.print(password[i]); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
a77c056125c217d71106ad402b5d89cd
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.util.*; import java.io.*; public class Div2B { public static void main(String[] args) throws IOException { new Div2B().run(); } FastScanner in; PrintWriter out; void run() throws IOException { in = new FastScanner(System.in); out = new PrintWriter(System.out, true); solve(); out.close(); } void solve() throws IOException { int n = in.nextInt(); StringBuilder num = new StringBuilder(in.next()); StringBuilder result = new StringBuilder(num); for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { num = add(num); if (lower(num, result)) result = new StringBuilder(num); } num = shift(num); } out.println(result); } StringBuilder add(StringBuilder num) { for (int i = 0; i < num.length(); i++) { int digit = Character.digit(num.charAt(i), 10); digit = (digit + 1) % 10; num.setCharAt(i, Character.forDigit(digit, 10)); } return num; } StringBuilder shift(StringBuilder num) { return num.append(num.charAt(0)).deleteCharAt(0); } boolean lower(StringBuilder a, StringBuilder b) { for (int i = 0; i < a.length(); i++) if (a.charAt(i) != b.charAt(i)) return a.charAt(i) < b.charAt(i); return false; } static class FastScanner { BufferedReader bf; StringTokenizer st; FastScanner(InputStream in) { bf = new BufferedReader(new InputStreamReader(in)); st = null; } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
33206d80fceb06c5eec5fffa6142bca8
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.*; import java.util.*; public class Main { private static List<List<Integer>> subsets; public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream); int n = in.nextInt(); String s = in.next(); char [] c = s.toCharArray(); PriorityQueue<String> q = new PriorityQueue<>(); for (int i = 0; i < c.length; i++) { c = shift(c); for (int j = 0; j <=9; j++) { c = convert(c); q.add(new String(c)); } } out.println(q.peek()); out.flush(); } static char [] convert(char [] c) { for (int i = 0; i < c.length; i++) { char current = c[i]; if (current == '9') { c[i] = '0'; } else { c[i] = ++c[i]; } } return c; } static char [] shift(char [] c) { char temp = c[c.length - 1]; for (int i = 0; i < c.length;i++) { char current = c[i]; c[i] = temp; temp = current; } c[0] = temp; return c; } static void subsets(int [] a, int index, List<Integer> list) { subsets.add(new ArrayList<>(list)); for (int i = index; i < a.length; i++) { list.add(a[i]); subsets(a,i+1,list); list.remove(list.size() - 1); } } static long sum(long n) { return n*(n+1)/2; } static int gcd(int a,int b) { return b==0 ? a : gcd(b,a%b); } static int lcm(int a,int b,int gcd) { return a*b/gcd; } } class Point { int x; int y; public int getX() { return x; } public int getY() { return y; } public Point(int x,int y) { this.x = x; this.y = y; } } class InputReader extends BufferedReader { StringTokenizer tokenizer; public InputReader(InputStream inputStream) { super(new InputStreamReader(inputStream), 32768); } public InputReader(String filename) { super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(readLine()); } catch (IOException e) { throw new RuntimeException(); } } return tokenizer.nextToken(); } public Integer nextInt() {return Integer.valueOf(next());} public Long nextLong() {return Long.valueOf(next());} public Double nextDouble() {return Double.valueOf(next());} static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream outputStream) { super(outputStream); } public OutputWriter(Writer writer) { super(writer); } public OutputWriter(String filename) throws FileNotFoundException { super(filename); } public void close() { super.close(); } } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
08591a40d56d93e0ad3c110194fed0c8
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; 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); TaskB solver = new TaskB(); solver.solve(in, out); out.close(); } } class TaskB { TaskB() {} public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); String s = in.next(); String[] yo = new String[n]; for (int i=0; i<n; i++) { yo[i] = foo(s, i); } Arrays.sort(yo); out.println(yo[0]); } private String foo(String s, int j) { String s1 = s.substring(j) + s.substring(0, j); char[] a = new char[s1.length()]; int r = s1.charAt(0)-'0'; a[0] = '0'; for (int i = 1; i<s1.length(); i++) { a[i] = (char)(s1.charAt(i)-r); if (a[i] < '0') { a[i] = (char)(a[i]+10); } } return new String(a); } } class InputReader { BufferedReader reader; StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output
PASSED
d9d34f9b77839b51a57c0a28f654f9b9
train_003.jsonl
1418833800
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
256 megabytes
import java.math.BigInteger; import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) { // test(); solver(); } private static void test() { } private static void solver() { Scanner in = new Scanner(System.in); int t = in.nextInt(); StringBuffer s = new StringBuffer(in.next()); BigInteger ans = new BigInteger(s.toString()); for (int number = 0; number <= 9; number++) { StringBuffer temp = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char ch = (char)(s.charAt(i)+number); if (ch > '9') { ch -= 10; } temp.append(ch); } temp = new StringBuffer (temp.toString() + temp.toString()); for (int i = 0; i < s.length(); i++) { BigInteger n = new BigInteger(temp.substring(i,i+s.length())); ans = ans.min(n); } } StringBuffer out = new StringBuffer(ans.toString()); if (out.length() < s.length()) { out.reverse(); while(out.length() < s.length()) out.append('0'); out.reverse(); } System.out.println(out); } }
Java
["3\n579", "4\n2014"]
2 seconds
["024", "0142"]
null
Java 8
standard input
[ "constructive algorithms", "implementation", "brute force" ]
6ee356f2b3a4bb88087ed76b251afec2
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display. The second line contains n digits — the initial state of the display.
1,500
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
standard output