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
51f8f87977fa8530b87cd0e1f4c38325
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.lang.reflect.Array; import java.math.BigInteger; import java.util.*; /** * Created by ruan0408 on 6/09/15. */ public class Main { public static void main(String[] args) { InputReader reader = new InputReader(System.in); int n = reader.readInt(); String s = reader.readString(); ArrayList<Integer> x = new ArrayList<>(s.length()); for (int i = 0; i < s.length(); i++) x.add(Integer.parseInt("" + s.charAt(i))); // System.out.println(Arrays.toString(x.toArray(new Integer[0]))); // rotate(x); // System.out.println(Arrays.toString(x.toArray(new Integer[0]))); // add(x); // System.out.println(Arrays.toString(x.toArray(new Integer[0]))); // ArrayList<Integer> a = new ArrayList<>(); a.add(0);a.add(2);a.add(4); // ArrayList<Integer> b = new ArrayList<>(); b.add(4);b.add(0);b.add(2); // System.out.println(lessThan(a,b)); ArrayList<Integer> min = null; for (int i = 0; i < 10; i++) { for (int j = 0; j < n; j++) { //System.out.println(Arrays.toString(x.toArray(new Integer[0]))); if (min == null || lessThan(x, min)) { //System.out.println(Arrays.toString(x.toArray(new Integer[0]))); min = new ArrayList<>(x); } rotate(x); } add(x); } String res = ""; for(Integer i : min) res += i; System.out.println(res); } public static boolean lessThan(ArrayList<Integer> a, ArrayList<Integer> b) { for (int i = 0; i < a.size(); i++) { if (a.get(i) < b.get(i)) return true; else if(a.get(i) > b.get(i)) return false; } return false; } public static void rotate(ArrayList<Integer> x) { Integer last = x.remove(x.size()-1); x.add(0, last); } public static void add(ArrayList<Integer> x) { for (int i = 0; i < x.size(); i++) x.set(i, (x.get(i)+1)%10); } } 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 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); } } 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(); } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } }
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
8bcd2877aa039e7c85605d0a7ebc0499
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 secretCombination { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); String s = sc.next(); char C[] = s.toCharArray(); StringBuilder sb = new StringBuilder(""); for(int i = 0; i < 1000; i++) sb.append('9'); StringBuilder s1 = new StringBuilder(""); StringBuilder s2 = new StringBuilder(""); for(int i = 0; i < s.length(); i++){ int x = 57 - C[i] + 1; // System.out.println(x); for(int j = 0; j < s.length(); j++){ if(j < i){ s1.append((C[j] - 48 + x) % 10); } else if(j >= i){ s2.append((C[j] - 48 + x) % 10); } } s2 = s2.append(s1); // System.out.println(s2 + " " + sb); if(String.valueOf(s2).compareTo(String.valueOf(sb)) < 0) sb = s2; s1 = new StringBuilder(""); s2 = new StringBuilder(""); } System.out.println(sb); } }
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
07b1e0c63b1fbffe9139e9ed0f061514
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.util.concurrent.ArrayBlockingQueue; import java.awt.List; import java.io.*; import java.lang.*; import java.lang.reflect.Array; public class code2 { public static long INF = Long.MAX_VALUE/100; public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); // Code starts.. int n = in.nextInt(); ArrayList<Integer> list= new ArrayList<>(); StringBuilder sb = new StringBuilder(); String tmp =""; tmp = in.nextLine(); sb.append(tmp); //pw.println(sb.toString()); String ans = sb.toString(); for(int k=0; k<10; k++) { // pw.println(sb.toString()); for(int i=0; i<n; i++) { char c = (char)(sb.charAt(i)+1); if(c>'9') c = (char)'0'; sb.setCharAt(i, c); } for(int i=0; i<n; i++) { tmp = sb.toString().substring(i, n) + sb.toString().substring(0, i); if(tmp.compareTo(ans)<0) ans = tmp; } } pw.println(ans); pw.flush(); pw.close(); //Code ends... } public static String toString(ArrayList<Integer> c) { String s = ""; for(int i=0; i<c.size(); i++) s += c.get(i); return s; } public static ArrayList<Integer> intersect(final ArrayList<Integer> A, final ArrayList<Integer> B) { int p1 = 0; int p2 = 0; ArrayList<Integer> list = new ArrayList<>(); System.out.println(p1+" "+p2+" "+A.get(p1)); while(p1<A.size() && p2<B.size()) { if(A.get(p1)-B.get(p2)==0) { list.add(A.get(p1)); p1++; p2++; } else if(A.get(p1)>B.get(p2)) { p2++; } else p1++; } while(++p1<A.size() && p2-1<B.size()) { if(A.get(p1)==B.get(p2-1)) { list.add(A.get(p1)); break; } } while(++p2<B.size() && p1-1<A.size()) { if(B.get(p2)==A.get(p1-1)) { list.add(B.get(p2)); break; } } // System.out.println(list); return list; } 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); } } public static long c = 0; public static long mod = (long)Math.pow(10, 6)+3; public static int d; public static int p; public static int q; public static boolean flag; //public static long INF = Long.MAX_VALUE; public static void factSieve(int[] fact, long n) { for (int i = 2; i <= n; i += 2) fact[i] = 2; for (int i = 3; i <= n; i += 2) { if (fact[i] == 0) { fact[i] = i; for (int j = i; (long) j * i <= n; j++) { fact[(int) ((long) i * j)] = i; } } } /* * int k = 1000; while(k!=1) { System.out.print(a[k]+" "); k /= a[k]; * * } */ } public static long floorsqrt(long n) { long ans = 0; long l = 0; long r = n; long mid = 0; while (l <= r) { mid = (l + r) / 2; if (mid * mid == n) return mid; if (mid * mid > n) { r = mid - 1; } else { ans = mid; l = mid + 1; } } return ans; } public static long[][] matmul(long[][] a, long[][] b){ int n = a.length; int m = b[0].length; long[][] c = new long[n][m]; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { long tmp = 0; for(int k=0; k<a[0].length; k++) tmp =( (tmp+mod)%mod+(a[i][k]*b[k][j]+mod)%mod)%mod; c[i][j] = (tmp+mod)%mod; } return c; } public static long[][] matpow(long[][] a,int n) { long[][] res = a; while(n>0) { if(n%2==1) { res = matmul(a, res); } a = matmul(a, a); n/=2; } return res; } public static int gcd(int p2, int p22) { if (p2 == 0) return (int) p22; return gcd(p22 % p2, p2); } public static int findGCD(int arr[], int n) { int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result); return result; } public static void nextGreater(long[] a, int[] ans) { Stack<Integer> stk = new Stack<>(); stk.push(0); for (int i = 1; i < a.length; i++) { if (!stk.isEmpty()) { int s = stk.pop(); while (a[s] < a[i]) { ans[s] = i; if (!stk.isEmpty()) s = stk.pop(); else break; } if (a[s] >= a[i]) stk.push(s); } stk.push(i); } return; } public static long lcm(int[] numbers) { long lcm = 1; int divisor = 2; while (true) { int cnt = 0; boolean divisible = false; for (int i = 0; i < numbers.length; i++) { if (numbers[i] == 0) { return 0; } else if (numbers[i] < 0) { numbers[i] = numbers[i] * (-1); } if (numbers[i] == 1) { cnt++; } if (numbers[i] % divisor == 0) { divisible = true; numbers[i] = numbers[i] / divisor; } } if (divisible) { lcm = lcm * divisor; } else { divisor++; } if (cnt == numbers.length) { return lcm; } } } public static long fact(long n) { long factorial = 1; for (int i = 1; i <= n; i++) { factorial *= i; } return factorial; } public static long choose(long total, long choose) { if (total < choose) return 0; if (choose == 0 || choose == total) return 1; return (choose(total - 1, choose - 1) + choose(total - 1, choose)) % mod; } public static int[] suffle(int[] a, Random gen) { int n = a.length; for (int i = 0; i < n; i++) { int ind = gen.nextInt(n - i) + i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static int floorSearch(int arr[], int low, int high, int x) { if (low > high) return -1; if (x > arr[high]) return high; int mid = (low + high) / 2; if (mid > 0 && arr[mid - 1] < x && x < arr[mid]) return mid - 1; if (x < arr[mid]) return floorSearch(arr, low, mid - 1, x); return floorSearch(arr, mid + 1, high, x); } public static void swap(int a, int b) { int temp = a; a = b; b = temp; } public static ArrayList<Integer> primeFactorization(int n) { ArrayList<Integer> a = new ArrayList<Integer>(); for (int i = 2; i * i <= n; i++) { while (n % i == 0) { a.add(i); n /= i; } } if (n != 1) a.add(n); return a; } public static void sieve(boolean[] isPrime, int n) { for (int i = 1; i < n; i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i < n; i++) { if (isPrime[i] == true) { for (int j = (2 * i); j < n; j += i) isPrime[j] = false; } } } public static int lowerbound(ArrayList<Long> net, long c2) { int i = Collections.binarySearch(net, c2); if (i < 0) i = -(i + 2); return i; } public static int lowerboundArray(int[] dis, int c2) { int i = Arrays.binarySearch(dis, c2); if (i < 0) i = -(i + 2); return i; } public static int uperbound(ArrayList<Integer> list, int c2) { int i = Collections.binarySearch(list, c2); if (i < 0) i = -(i + 1); return i; } public static int uperboundArray(int[] dis, int c2) { int i = Arrays.binarySearch(dis, c2); if (i < 0) i = -(i + 1); return i; } public static long[] sort(long[] a) { Random gen = new Random(); int n = a.length; for (int i = 0; i < n; i++) { int ind = gen.nextInt(n - i) + i; long temp = a[ind]; a[ind] = a[i]; a[i] = temp; } Arrays.sort(a); return a; } public static int[] sort(int[] a) { Random gen = new Random(); int n = a.length; for (int i = 0; i < n; i++) { int ind = gen.nextInt(n - i) + i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } Arrays.sort(a); return a; } public static int GCD(int a, int b) { if (b == 0) return a; else return GCD(b, a % b); } public static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); } public static void extendedEuclid(int A, int B) { if (B == 0) { d = A; p = 1; q = 0; } else { extendedEuclid(B, A % B); int temp = p; p = q; q = temp - (A / B) * q; } } public static long LCM(long a, long b) { return (a * b) / GCD(a, b); } public static int LCM(int a, int b) { return (a * b) / GCD(a, b); } public static int binaryExponentiation(int x, int n) { int result = 1; while (n > 0) { if (n % 2 == 1) result = result * x; x = x * x; n = n / 2; } return result; } public static int[] countDer(int n) { int der[] = new int[n + 1]; der[0] = 1; der[1] = 0; der[2] = 1; for (int i = 3; i <= n; ++i) der[i] = (i - 1) * (der[i - 1] + der[i - 2]); // Return result for n return der; } static long binomialCoeff(int n, int k) { long C[][] = new long[n + 1][k + 1]; int i, j; // Calculate value of Binomial Coefficient in bottom up manner for (i = 0; i <= n; i++) { for (j = 0; j <= Math.min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value using previosly stored values else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } return C[n][k]; } public static long binaryExponentiation(long x, long n) { long result = 1; while (n > 0) { if (n % 2 == 1) result = result * x; x = (x % mod * x % mod) % mod; n = n / 2; } return result; } public static int modularExponentiation(int x, int n, int M) { int result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } public static long modularExponentiation(long x, long n, long M) { long result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } public static int modInverse(int A, int M) { return modularExponentiation(A, M - 2, M); } public static long sie(long A, long M) { return modularExponentiation(A, M - 2, M); } public static boolean checkYear(int year) { if (year % 400 == 0) return true; if (year % 100 == 0) return false; if (year % 4 == 0) return true; return false; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } 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 && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } } static class triplet implements Comparable<triplet> { Integer x, y, z; triplet(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public int compareTo(triplet o) { int result = x.compareTo(o.x); if (result == 0) result = y.compareTo(o.y); if (result == 0) result = z.compareTo(o.z); return result; } public boolean equlas(Object o) { if (o instanceof triplet) { triplet p = (triplet) o; return x == p.x && y == p.y && z == p.z; } return false; } public String toString() { return x + " " + y + " " + z; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode() + new Long(z).hashCode(); } } static class query implements Comparable<query> { Integer l,r, x, idx, tp; query(int l, int r, int x, int id, int tp) { this.l = l ; this.r = r; this.x = x; this.idx = id; this.tp = tp; } public int compareTo(query o) { int result = x.compareTo(o.x); return result; } } /* * static class node implements Comparable<node> * * { Integer x, y, z; node(int x,int y, int z) { this.x=x; this.y=y; this.z=z; } * * public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) * result = y.compareTo(o.y); if(result==0) result = z.compareTo(z); return * result; } * * @Override public int compareTo(node o) { // TODO Auto-generated method stub * return 0; } } */ }
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
a0c3063772ea0ad6b53d473e0429f2eb
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.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author minhthai */ 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 { int N; public void solve(int testNumber, InputReader in, PrintWriter out) { N = in.nextInt(); String input = in.nextLine(); //State = toNumber(toArray(input)); String min = input; String tmp = input; for(int i = 0; i < 10; ++i) { int[] arr = toArray(tmp); String sh = tmp; for(int j = 0; j < N; ++j) { sh = shift(sh); if(sh.compareTo(min) < 0) min = sh; } plus1(arr); tmp = toString(arr); if(tmp.compareTo(min) < 0) min = tmp; } String s = min; //int limit = Math.min(N - min.length(), N - 1); //for(int i = 0; i < limit; ++i) // s = "0" + s; out.println(s); } String shift(String s) { return s.substring(1) + s.charAt(0); } void plus1(int []arr) { for(int i = 0; i < N; ++i) { if(arr[i] == 9) arr[i] = 0; else arr[i]++; } } int[] toArray(String s) { int[] rs = new int[N]; for(int i = 0; i < N; ++i) rs[i] = (int)s.charAt(i) - (int)'0'; return rs; } String toString(int[] arr) { String rs = ""; for(int i = 0; i < arr.length; ++i) rs += String.valueOf(arr[i]); return rs; } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public 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 String nextLine() { if (tokenizer != null) { while (tokenizer.hasMoreTokens()) tokenizer.nextToken(); } try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } 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
7cb8f6ed099607640cfe3e5c7e0c9942
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.IOException; import java.io.PrintWriter; import java.util.Arrays; public class CF_283B { static Reader sc = new Reader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int n = sc.nextInt(); int[] nums = new int[n]; int min = Integer.MAX_VALUE; String s = sc.next(); for (int i = 0; i < n; i++) { nums[i] = s.charAt(i)-'0'; min = Math.min(min, nums[i]); } String res = s; for (int k = 0; k < 10; k++) { for (int i = 0; i < n; i++) { nums[i] = (nums[i]+1)%10; } for (int i = 0; i < n; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < n; j++) { sb.append(nums[(i+j)%n]); } String act = sb.toString(); if(res.compareTo(act) > 0) { res = act; } } } out.println(res); out.close(); } static class Reader { final private int BUFFER_SIZE = 1 << 16;private byte[] buffer;private int bufferPointer, bytesRead; public Reader(){buffer=new byte[BUFFER_SIZE];bufferPointer=bytesRead=0; }private void fillBuffer() throws IOException{bytesRead=System.in.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 String next() throws IOException{StringBuilder sb = new StringBuilder();byte c;while((c=read())<=' '){if(c==-1) return null;};do{sb.append((char)c);}while((c=read())>' ');if (sb.length()==0) return null;return sb.toString(); }public String nextLine() throws IOException{StringBuilder sb = new StringBuilder();byte c;boolean read = false;while((c=read())!=-1){if(c=='\n') {read = true;break;}if(c>=' ')sb.append((char)c);}if (!read) return null;return sb.toString(); }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*10L+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; }public int[] na(int n) throws IOException{int[] a = new int[n];for(int i = 0;i < n;i++)a[i] = nextInt();return a; }public int[][] nm(int n, int m) throws IOException{int[][] map = new int[n][m];for(int i = 0;i < n;i++)map[i] = na(m);return map; }public void close() throws IOException{if(System.in==null) return;System.in.close();} } static void print(int[] A) {for(int i=0;i<A.length;i++){if(i!=0) out.print(' ');out.print(A[i]);}out.println();} static <T> void print(Iterable<T> A) {int i = 0;for(T act : A){if(i!=0)out.print(' ');out.print(act);i++;}out.println();} static void printPlus1(Iterable<Number> A) {int i = 0;for(Number act : A){if(i!=0)out.print(' ');out.print(act.longValue() + 1L);i++;}out.println();} static void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } /* long s = System.currentTimeMillis(); debug(System.currentTimeMillis()-s+"ms"); */ }
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
64cdc5b3f8ef942f3c71a2e898d128cf
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.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; 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); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt() ; String s = in.next() ; BigInteger b2 = new BigInteger(s) ; String result = s ; String z = s ; for (int i = 0; i <s.length(); i++) { String x = s.substring(n-i, n) + s.substring(0,n-i) ; z=x; int c = z.charAt(0) ; c=10-c ; c%=10 ; String y = "" ; for (int ii = 0; ii < z.length(); ii++) { y+=(c+z.charAt(ii))%10 ; } BigInteger b1 = new BigInteger(y); if(b1.compareTo(b2)<0) {b2 =b1 ; result = y ; } } out.println(result); } public static int binarySearch(int []arr , int target) { int low = 0, high = arr.length; while (low != high) { int mid = (low + high) / 2; if (arr[mid] <= target) { low = mid + 1; } else { high = mid; } } return arr[low] ; } public static boolean isPrime (long num){ if (num < 2) return false; if (num == 2) return true; if (num % 2 == 0) return false; for (long i = 3*1l; i * i <= num; i += 2) if (num % i == 0) return false; return true; } } 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()); } } static class Vertix{ int x ; ArrayList<Vertix> children; Vertix parent; public Vertix(int x){ this.x = x ; this.children= new ArrayList<Vertix>(); } } static class Pair implements Comparable<Pair> { int x ; int y ; public Pair(int x, int y) { this.x = x ; this.y = y ; } @Override public int compareTo(Pair p) { if (this.x < p.x) return -1; else if (this.x > p.x) return 1; else return 0; } // } }
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
9260e49a0b85e82a31eae8de4ea4c8a8
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.InputMismatchException; import java.io.IOException; import java.util.Collections; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn Agrawal coderbond007 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(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, FastReader in, PrintWriter out) { ArrayList<String> list = new ArrayList<>(); in.nextInt(); char[] s = in.nextString().toCharArray(); int n = s.length; for (int i = 0; i < 10; i++) { char[] temp = s.clone(); for (int j = 0; j < n; j++) { temp[j] += i; if (temp[j] > '9') temp[j] -= 10; } ArrayList<String> strings = new ArrayList<>(); String string = new String(temp); strings.add(string); for (int j = 0; j < n; j++) { String t = string.substring(j) + string.substring(0, j); strings.add(t); } Collections.sort(strings); list.add(strings.get(0)); } Collections.sort(list); out.println(list.get(0)); } } static class FastReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar; private int pnumChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (pnumChars == -1) { throw new InputMismatchException(); } if (curChar >= pnumChars) { curChar = 0; try { pnumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (pnumChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c == ',') { c = read(); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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
52392693fd1d4359ce57e56f3751f1be
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.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; import javax.swing.text.html.HTMLDocument.Iterator; public class HelloWorld { public static String plus(String a) { String result = ""; char[] save = new char[a.length()]; for (int i = 0; i < save.length; i++) { save[i] = a.charAt(i); } for (int i = 0; i < save.length; i++) { if (save[i] == '9') save[i] = '0'; else save[i] += 1; result += save[i]; } return result; } public static String getMin(String a) { String min = "999999999999999999999999999999999"; for (int i = a.length() - 1; i >= 0; i--) { String temp = a.substring(i) + a.substring(0, i); if (temp.compareTo(min) < 0) min = temp; } return min; } public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); String input = in.next(); String min = "999999999999999999999999999999999"; int count = 0; while (count < 10) { String temp = getMin(input); if (temp.compareTo(min) < 0) { min = temp; } input = plus(input); count++; } System.out.println(min); } }
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
af1ec18236a311c5e2f1677cadee11ec
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 B { FastScanner in; PrintWriter out; int i = 0, j = 0; void solve() { /**************START**************/ int n = in.nextInt(); if (n == 1) { out.println("0"); return; } ArrayDeque<Integer> num = new ArrayDeque<Integer>(n); int low = Integer.MAX_VALUE; char[] cur = in.next().toCharArray(); for (i = 0; i < n; i++) { num.add(cur[i] - '0'); } PriorityQueue<String> orderedNums = new PriorityQueue<String>(); for (i = 0; i < n; i++) { StringBuilder sb = new StringBuilder(); int dist = (10 - num.peekFirst()) % 10; for (j = 0; j < n; j++) { int head = num.removeFirst(); head += dist; head %= 10; sb.append(head); num.addLast(head); } orderedNums.offer(sb.toString()); int tail = num.removeFirst(); num.addLast(tail); } out.println(orderedNums.peek()); /***************END***************/ } public static void main(String[] args) { new B().runIO(); } void runIO() { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } //This will empty out the current line (if non-empty) and return the next line down. If the next line is empty, will return the empty string. String nextLine() { st = null; String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { 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
e30d9a0b1d309055a8aa4f80aa58371f
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.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.net.ssl.SSLContext; public class Main { static long mod=(long)(1e+9) + 7; static int[] sieve;static int ans=0; static ArrayList<Integer> primes; public static StringBuilder minimum(StringBuilder x,StringBuilder y) { String a=x.toString(); String b=y.toString(); for(int i=0;i<a.length();i++) { int p=Character.getNumericValue(a.charAt(i)); int q=Character.getNumericValue(b.charAt(i)); if(p<q) return x; if(q<p) return y; } return x; } public static void main(String[] args) throws java.lang.Exception { fast s = new fast(); PrintWriter out=new PrintWriter(System.out); Scanner sc=new Scanner(System.in); StringBuilder fans = new StringBuilder(); int n=s.nextInt(); String str=s.nextLine(); int a[]=new int[n]; for(int i=0;i<str.length();i++) a[i]=str.charAt(i)-48; StringBuilder temp=null; StringBuilder ans=new StringBuilder(); int flag=1; for(int i=1;i<=10;i++) { for(int j=0;j<n;j++) a[j]=(a[j]+1)%10; temp=new StringBuilder(""); for(int j=0;j<n;j++) temp.append(a[j]); for(int k=0;k<n;k++) { int temp1=a[n-1];int prev=a[0]; for(int j=1;j<n;j++) {int temp10=a[j];a[j]=prev; prev=temp10;} a[0]=temp1; StringBuilder temp2=new StringBuilder(""); for(int j=0;j<n;j++) temp2.append(a[j]); if(flag==1) {ans=minimum(temp,temp2); flag=0;} else {ans=minimum(ans,temp2);} } } System.out.println(ans); } static class fast { private InputStream i; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public static boolean next_permutation(int a[]) { int i=0,j=0;int index=-1; int n=a.length; for(i=0;i<n-1;i++) if(a[i]<a[i+1]) index=i; if(index==-1) return false; i=index; for(j=i+1;j<n && a[i]<a[j];j++); int temp=a[i]; a[i]=a[j-1]; a[j-1]=temp; for(int p=i+1,q=n-1;p<q;p++,q--) { temp=a[p]; a[p]=a[q]; a[q]=temp; } return true; } public static void division(char ch[],int divisor) { int div=Character.getNumericValue(ch[0]); int mul=10;int remainder=0; StringBuilder quotient=new StringBuilder(""); for(int i=1;i<ch.length;i++) { div=div*mul+Character.getNumericValue(ch[i]); if(div<divisor) {quotient.append("0");continue;} quotient.append(div/divisor); div=div%divisor;mul=10; } remainder=div; while(quotient.charAt(0)=='0')quotient.deleteCharAt(0); System.out.println(quotient+" "+remainder); } public static void sieve(int size) { sieve=new int[size+1]; primes=new ArrayList<Integer>(); sieve[1]=1; for(int i=2;i<=Math.sqrt(size);i++) { if(sieve[i]==0) { for(int j=i*i;j<size;j+=i) sieve[j]=1; } } for(int i=2;i<=size;i++) { if(sieve[i]==0) primes.add(i); } } public static long pow(long n, long b, long MOD) { long x=1;long y=n; while(b > 0) { if(b%2 == 1) { x=x*y; if(x>MOD) x=x%(MOD); } y = y*y; if(y>MOD) y=y%(MOD); b >>= 1; } return x; } public static int lower(Integer[] a,int start,int end,int key) { int mid=(start+end)>>1; if(start==end && a[mid]<key) {return -1;} if(start>end) return -1; if(a[mid]>=key && (((mid-1)>=0 && a[mid-1]<key) || (mid-1)==0)) return mid; else if(a[mid]== key && (mid-1)>=0 && a[mid-1]==key) return lower(a,start,mid-1,key); else if(key>a[mid]) return lower(a,mid+1,end,key); else return lower(a,start,mid-1,key); } public static int upper(Integer a[],int start,int end,int key) { int mid=(start+end)>>1; if(start==end && a[mid]>key) {return -1;} if(start>end) return -1; if(a[mid]<=key && (((mid+1)<a.length && a[mid+1]>key) || (mid+1)==a.length)) return mid; else if(a[mid]== key && (mid+1)<a.length && a[mid+1]==key) return upper(a,mid+1,end,key); else if(key>=a[mid]) return upper(a,mid+1,end,key); else return upper(a,start,mid-1,key); } public int gcd(int a,int b) { if(a==0) return b; return gcd(b%a,a); } public fast() { this(System.in); } public fast(InputStream is) { i = is; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = i.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public 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 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) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
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
99cd00a6862925ad4882430c56ce46b2
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; public class B283 { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String s=br.readLine(); int[] in=new int[n]; for(int i=0;i<n;i++) in[i]=s.charAt(i)-'0'; int[] cur=new int[n]; int[] min=new int[n]; Arrays.fill(min, 9); for(int i=0;i<10;i++){ for(int j=0;j<n;j++){ cur[j]=(in[j]+i)%10; } int[] per=new int[n]; for(int t=0;t<n;t++){ int p=0; for(int k=t;k<n;k++){ per[p]=cur[k]; p++; } int done=p; for(int k=0;k<n-done;k++){ per[p]=cur[k]; p++; } for(int k=0;k<n;k++){ if(per[k]==min[k]){ }else if(per[k]>min[k]){ break; }else{ System.arraycopy(per, 0, min, 0, n); break; } } } } for(int i=0;i<n;i++) System.out.print(min[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
c3fcdbf2164c73aeddbbc05e479aae6c
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.*; public class contest { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); String ans=s; s=s+s; for(int i=0;i<n;i++){ String s1=s.substring(i, i+n); char[] st=s1.toCharArray(); int k='9'-st[0]+1; for(int j=0;j<st.length;j++){ st[j]=(char)('0'+(st[j]-'0'+k)%10); } s1=new String(st); if(ans.compareTo(s1)>0){ ans=s1; } } System.out.println(ans); } }
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
b9203817db489b2020689c837a6f7545
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
// Main Code at the Bottom import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; public class Main{ //Fast IO class static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { boolean env=System.getProperty("ONLINE_JUDGE") != null; if(!env) { try { br=new BufferedReader(new FileReader("src\\input.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } else br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long MOD=1000000000+7; //debug static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } // Pair static class pair{ long x,y; pair(long a,long b){ this.x=a; this.y=b; } public boolean equals(Object obj) { if(obj == null || obj.getClass()!= this.getClass()) return false; pair p = (pair) obj; return (this.x==p.x && this.y==p.y); } public int hashCode() { return Objects.hash(x,y); } } static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); //Global variables and functions //Main function(The main code starts from here) public static void main (String[] args) throws java.lang.Exception { int test=1; //test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); String str=sc.nextLine(); int a[]=new int[n],ans[]=new int[n]; for(int i=0;i<n;i++) a[i]=str.charAt(i)-'0'; Arrays.fill(ans, 9); for(int i=0;i<n;i++) { int tmp[]=new int[n]; for(int j=0;j<n;j++) tmp[(j-i+n)%n]=a[j]; int moves=10-tmp[0]; for(int j=0;j<n;j++) tmp[j]=(tmp[j]+moves)%10; int f=0; for(int j=0;j<n;j++) { if(tmp[j]==ans[j]) continue; if(tmp[j]<ans[j]) f=1; break; } if(f==1) ans=tmp; } for(int x: ans) out.print(x); } out.flush(); out.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
75b2086cdc451557a3f95e76948e29ae
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 { FastScanner in; PrintWriter out; static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = null; } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { if (st == null || !st.hasMoreTokens()) return br.readLine(); StringBuilder result = new StringBuilder(st.nextToken()); while (st.hasMoreTokens()) { result.append(" "); result.append(st.nextToken()); } return result.toString(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } void run() throws IOException { in = new FastScanner(System.in); out = new PrintWriter(System.out, false); solve(); out.close(); } public static void main(String[] args) throws IOException{ new Main().run(); } public void printArr(int[] arr){ for(int i = 0; i < arr.length; i++){ out.print(arr[i] + " "); } out.println(); } public long gcd(long a, long b){ if(a == 0) return b; return gcd(b % a, a); } public void solve() throws IOException{ int n = in.nextInt(); char[] carr = in.next().toCharArray(); String minStr = new String(carr); for(int i = 0; i < n; i++){ String s = "0"; int start = (i + 1) % n; int move = (10 - (carr[i] - '0')) % 10; for(int j = 0; j < n - 1; j++){ int num = (move + (carr[start] - '0')) % 10; s += Integer.toString(num); start = (start + 1) % n; } if(s.compareTo(minStr) < 0){ minStr = s; } } out.println(minStr); 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
9a9b5c28ce9d0e18c7ee1aa355aa36b5
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.Scanner; import java.util.LinkedList; import java.util.ListIterator; import java.lang.StringBuilder; import java.math.BigInteger; public class Lock { private LinkedList<Integer> list; private int value; private int digits; public Lock() { list = new LinkedList<Integer>(); digits = 0; value = 0; } public void addDigit(int n){ list.addLast(n); digits++; } public LinkedList<Integer> solve(){ int n = digits; LinkedList<Integer> min = this.firstDigitasZero(); this.rotate(); while(n > 1) { // find minimum min = compareList(min, this.firstDigitasZero()); //System.out.println("Minimum " + minimum); this.rotate(); n--; } return min; } public LinkedList<Integer> compareList(LinkedList<Integer> a, LinkedList<Integer> b) { ListIterator<Integer> itera = a.listIterator(); ListIterator<Integer> iterb = b.listIterator(); while(itera.hasNext()) { int x = itera.next(); int y = iterb.next(); if(x < y) { return a; } else if (y < x){ return b; } } return a; } public LinkedList<Integer> firstDigitasZero() { int diff = 10 - list.getFirst(); LinkedList<Integer> val = new LinkedList<Integer>(); //System.out.println("Diff " + diff); ListIterator<Integer> iter = list.listIterator(); int i, y; int count = digits-1; while(iter.hasNext()) { i = iter.next(); y =((i+diff)%10) ; val.addLast(y); //System.out.println("val " + y); count--; } return val; } public void rotate() { int mostSig = list.removeFirst(); list.addLast(mostSig); } public static void main(String[] args) { Scanner in = new Scanner(System.in); Lock myLock = new Lock(); int d = in.nextInt(); String line = in.nextLine(); line = in.nextLine(); // System.out.println("d is " + d); // System.out.println("line is " + line); for(int i=0;i<line.length();i++) { myLock.addDigit((int) line.charAt(i) - 48); } //System.out.println(myLock); LinkedList<Integer> min = myLock.solve(); // System.out.println(min); ListIterator<Integer> minIter = min.listIterator(); while(minIter.hasNext()) System.out.print(minIter.next()); } public String toString() { StringBuilder str = new StringBuilder(20); ListIterator<Integer> iter = list.listIterator(0); while(iter.hasNext()) { str.append(iter.next()); } return str.toString(); } }
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
dd739fcbbeba8e9c07e5e24060cac7cb
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 { static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st = new StringTokenizer(""); static String next() { try { while(!st.hasMoreTokens()) { String s = br.readLine(); if(s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } catch(Exception e) { return null; } } public static void main(String[] args) { int n = Integer.parseInt( next() ); int[] less = new int[ n ]; Arrays.fill(less, Integer.MAX_VALUE); String word = next(); for (int i = 0; i < 10; i++) { int[] row = new int[ n ]; for (int j = 0; j < n; j++) row[ j ] = (word.charAt( j ) - '0' + i) % 10; for (int p = 0; p < n; p++) { for (int j = 0; j < n; j++) { int at = (p + j) % n; if (row[ at ] == less[ j ]) continue; if (row[ at ] > less[ j ]) break; for (int x = 0; x < n; x++) less[ x ] = row[ (p + x) % n ]; break; } } } for (int i = 0; i < n; i++) System.out.print(less[ i ]); out.flush(); System.exit(0); } }
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
72459b88ac2352fd2cc8b54818c2d075
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.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class SecretCombination { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; static void solve() throws Exception { int n = nextInt(); char[] c = next().toCharArray(); String ans = new String(c); for (int i = 0; i < n; i++) { String s = trans(c, i, n); if (ans.compareTo(s) > 0) ans = s; } out.println(ans); } static String trans(char[] c, int i, int n) { char[] d = new char[n]; for (int j = 0; j < n; j++) d[j] = c[(j + i) % n]; int diff = d[0] - '0'; for (int j = 0; j < n; j++) { int e = d[j] - '0'; d[j] = (char) (e >= diff ? d[j] - diff : d[j] + 10 - diff); } return new String(d); } public static void main(String args[]) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); System.exit(1); } } static int nextInt() throws IOException { return Integer.parseInt(next()); } static int[] nextIntArray(int len, int start) throws IOException { int[] a = new int[len]; for (int i = start; i < len; i++) a[i] = nextInt(); return a; } static long nextLong() throws IOException { return Long.parseLong(next()); } static long[] nextLongArray(int len, int start) throws IOException { long[] a = new long[len]; for (int i = start; i < len; i++) a[i] = nextLong(); return a; } static String next() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } }
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
781bddd7071f56feb7575b8c5adc661d
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.*; public class B { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n=sc.nextInt(); String str=sc.next(); ArrayList<Integer> l= new ArrayList<Integer>(str.length()); for(int i=0;i<n;i++) { l.add(Integer.parseInt("" + str.charAt(i))); } ArrayList<Integer> min= null; for(int i=0;i<10;i++) { for(int j=0;j<n;j++) { if(min == null || less(l,min)) min=new ArrayList<Integer>(l); rotate(l); } add(l); } String ans=""; for(int i:min) ans+=i; System.out.print(ans); } static boolean less(ArrayList<Integer> a ,ArrayList<Integer> b) { for(int i=0;i<a.size();i++) { if(a.get(i)<b.get(i)) return true; else if(a.get(i)>b.get(i)) return false; } return false; } static void rotate(ArrayList<Integer> a) { int last=a.remove(a.size()-1); a.add(0, last); } static void add(ArrayList<Integer> a) { for(int i=0;i<a.size();i++) { a.set(i, (a.get(i)+1)%10); } } }
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
3c595b07523b150321d4b7f74ca5423b
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.lang.*; public class Code85 { private static long mod = 1000000007; static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class pair implements Comparable<pair> { Integer x, y; pair(int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } } public static int[] suffle(int[] a,Random gen) { int n = a.length; for(int i=0;i<n;i++) { int ind = gen.nextInt(n-i)+i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static void swap(int a, int b){ int temp = a; a = b; b = temp; } public static ArrayList<Integer> primeFactorization(int n) { ArrayList<Integer> a =new ArrayList<Integer>(); for(int i=2;i*i<=n;i++) { while(n%i==0) { a.add(i); n/=i; } } if(n!=1) a.add(n); return a; } public static int GCD(int a,int b) { if(b==0) return a; else return GCD(b,a%b); } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static long LCM(long a,long b) { return (a*b)/GCD(a,b); } public static int LCM(int a,int b) { return (a*b)/GCD(a,b); } public static int binaryExponentiation(int x,int n) { int result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static long binaryExponentiation(long x,long n) { long result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static int modularExponentiation(int x,int n,int M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } public static long modularExponentiation(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } public static int modInverse(int A,int M) { return modularExponentiation(A,M-2,M); } public static long modInverse(long A,long M) { return modularExponentiation(A,M-2,M); } public static int[] shift(int[] a,int i) { int[] c = new int[a.length]; for(int j=0;j<a.length;j++) { c[j] = a[i%a.length]; i++; } return c; } public static String convert(int[] a) { String result = ""; for(int i=0;i<a.length;i++) result+=(char)((char)a[i]+'0'); return result; } public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = in.nextInt(); String s = in.nextLine(); int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = s.charAt(i) - '0'; String ans = convert(a); for(int i=0;i<n;i++) { int req = (10-a[i])%10; int[] b = a; for(int j=0;j<n;j++) b[j] = (b[j]+req)%10; int[] c = shift(b, i); String t = convert(c); if(t.compareTo(ans)<0) ans = t; } pw.println(ans); pw.flush(); pw.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
ceb08b72ba3193d4b0d32e637104dc92
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.Scanner; public class Secret{ public static void main(String[] args){ Secret exe = new Secret(); exe.begin(); } private void begin(){ Scanner l = new Scanner(System.in); int N = l.nextInt(); char[] arr = new char[N<<1]; copy(arr, l.next(), N); String output = solve(arr, N); while(output.length()<N) output = "0"+output; System.out.println(output); } private String solve(char[] arr, int N){ int i,j; String min="", temp; for(i=0;i<N;i++){ temp = ""; for(j=0;j<N-1;j++){ temp+= diff(arr[j+i+1]-arr[i]); //System.out.println("building "+temp); } //System.out.println(i+" "+temp); if(min.equals("") || min.compareTo(temp)>0) min = temp; } return min; } private int diff(int a){ return (a>=0)?a:diff(a+10); } private void copy(char[] arr, String cad, int N){ for(int i=0;i<N;i++) arr[i] = arr[i+N] = cad.charAt(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
85cc7711d45d60b8a1c0a223f62a7003
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.PrintWriter; import java.util.Arrays; import java.util.Locale; import java.util.Scanner; /** * Created by sementry on 23-Dec-14. */ public class CF283DIV2B { Scanner in; PrintWriter out; public static void main(String[] args) { new CF283DIV2B().run(); } public void run() { Locale.setDefault(Locale.US); in = new Scanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } String shl(int pos, String s) { return s.substring(pos) + s.substring(0, pos); } String add(int j, String s) { char[] ans = new char[s.length()]; for (int i = 0; i < s.length(); i++) { ans[i] = (char) (((s.charAt(i) - '0') + j) % 10 + '0'); } return new String(ans); } void solve() { int n = in.nextInt(); String code = in.next(); String[] codes = new String[10 * n]; for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { codes[10 * i + j] = shl(i, add(j, code)); } } Arrays.sort(codes); out.println(codes[0]); } }
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
a9a15ecafad4c736ec97f053cc6f8866
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.lang.*; public class CF{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); int i, j, k=0, n; char copy; boolean flag = false; n = cin.nextInt(); cin.nextLine(); StringBuffer work = new StringBuffer(cin.nextLine()); StringBuffer answer = new StringBuffer(work); for(i=0; i<n; i++) { copy = work.charAt(n-1); for(k=n-1; k>0; k--) { work.setCharAt(k, work.charAt(k-1)); } work.setCharAt(0, copy); for(j=0; j<10; j++) { for(k=0; k<n; k++) { switch(work.charAt(k)) { case '0' : work.setCharAt(k, '1'); break; case '1' : work.setCharAt(k, '2'); break; case '2' : work.setCharAt(k, '3'); break; case '3' : work.setCharAt(k, '4'); break; case '4' : work.setCharAt(k, '5'); break; case '5' : work.setCharAt(k, '6'); break; case '6' : work.setCharAt(k, '7'); break; case '7' : work.setCharAt(k, '8'); break; case '8' : work.setCharAt(k, '9'); break; case '9' : work.setCharAt(k, '0'); break; }; } flag = false; if(answer.toString().compareTo(work.toString()) > 0) { flag = true; } if(flag) { for(k=0; k<n; k++) { answer.setCharAt(k, work.charAt(k)); } } } } System.out.print(answer); } }
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
98d4fd123850fa5fc1e5d78b28a152d7
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
//package com.company; import java.util.*; public class Main { public static int[] button1(int[] x) { for(int i=0; i<x.length ;i++) { x[i]++; if(x[i] ==10) { x[i]=0; } } return x; } public static int[] button2(int[] y) { int k = y.length; int[] arr = new int[k]; for (int i = 0; i < k-1 ; i++) { arr[i+1] = y[i]; } arr[0]= y[k-1]; return arr; } public static boolean numbermaker(int[] z,int[] r) { int n=z.length; for(int i=0; i < n; i++) if(z[i] < r[i]) return true; else if(z[i] > r[i]) return false; return false; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); // write your code here int n; n= scan.nextInt(); scan.nextLine(); String str = scan.nextLine(); int[] arr = new int[n]; int[] res = new int[n]; for(int m=0;m<n;m++) { arr[m] = str.charAt(m)-'0'; } res[0]=9; int[] arrw = new int[n]; for(int q=0; q<=11;q++) { for(int w=0;w<=n+1;w++) { if(numbermaker(arr,res)) { res = arr; } arr = button2(arr); } arr = button1(arr); } for(int f=0;f<n;f++) { System.out.print(res[f]); } } }
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
55b2a9ae7cf38c3e0b29a03f57d38b34
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.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeSet; import static java.lang.Math.*; public class SecretCombination implements Closeable { private InputReader in = new InputReader(System.in); private PrintWriter out = new PrintWriter(System.out); public void solve() { int n = in.ni(); String key = in.next(); String[] shift = new String[10]; shift[0] = key; for (int i = 1; i < 10; i++) { shift[i] = shift(shift[i - 1]); } for (int i = 0; i < 10; i++) { shift[i] = shift[i] + shift[i]; } TreeSet<String> set = new TreeSet<>(); for (String s : shift) { for (int i = 0; i <= s.length() - n; i++) { set.add(s.substring(i, i + n)); } } out.println(set.first()); } private String shift(String x) { int n = x.length(); char[] result = new char[n]; for (int i = 0; i < n; i++) { char c = x.charAt(i); if (c == '9') c = '0'; else c++; result[i] = c; } return new String(result); } @Override public void close() throws IOException { in.close(); out.close(); } 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 ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public void close() throws IOException { reader.close(); } } public static void main(String[] args) throws IOException { try (SecretCombination instance = new SecretCombination()) { instance.solve(); } } }
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
16332416d0d1dbc3b74218c9e2760c74
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.ArrayList; import java.util.List; import java.util.Scanner; public class B { private static int x = 0; private static int y = 0; public static void main(String args[]) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); String line = scanner.next(); int[] arr = new int[n]; int[] minArr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = line.charAt(i) - 48; minArr[i] = arr[i]; } for (int i = 0; i < 10; i++) { int[] tmp = new int[arr.length]; for (int j = 0; j < arr.length; j++) { tmp[j] = (arr[j] + i) % 10; } for (int j = 0; j < arr.length; j++) { int[] curr = new int[tmp.length]; System.arraycopy(tmp, j, curr, 0, tmp.length - j); System.arraycopy(tmp, 0, curr, tmp.length - j, j); for (int k = 0; k < curr.length; k++) { if (minArr[k] > curr[k]) { System.arraycopy(curr, 0, minArr, 0, curr.length); break; } else if (minArr[k] < curr[k]) { break; } } } } for (int k = 0; k < minArr.length; k++) System.out.print(minArr[k]); System.out.println(); } private static void increase(StringBuilder tmp) { for (int i = 0; i < tmp.length(); i++) { tmp.replace(i, i+1, (tmp.charAt(i) == '9') ? "0": "" + (tmp.charAt(i) + 1)); } } }
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
d2393b06401d0aaff47aa910d4c8ff71
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.awt.Point; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int n=sc.nextInt(); String s=sc.next(); int chr[]=new int[n]; // System.out.println(check(min,chr)); for (int i=0;i<n;i++){ chr[i]=s.charAt(i)-'0'; } int min[]=Arrays.copyOf(chr,chr.length); for (int i=0;i<10;i++){ for (int j=0;j<n;j++){ chr[j]=(chr[j]+1)%10; } for (int j=0;j<n;j++) { int tmp=chr[0]; for (int k=0;k<n-1;k++){ chr[k]=chr[k+1]; } chr[n-1]=tmp; if (!check(min, chr)) { min = Arrays.copyOf(chr, n); } } } for (int i=0;i<n;i++){ System.out.print(min[i]); } } static boolean check(int min[],int chr[]){ boolean f=false; for (int i=0;i<chr.length;i++){ if (chr[i]>min[i])f=true; if (chr[i]<min[i] && !f)return false; } return true; } } 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
["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
32697dce4e87bad671e3418712866873
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 Combination { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int size=Integer.parseInt(br.readLine()); int l=0; int m=0; String f=br.readLine(); int a[]=new int[size]; int b[]=new int[size]; int c []=new int[size]; BigInteger minimumNumber=new BigInteger(f); for(int i=0;i<size;i++) { char h=f.charAt(i); a[i]=(int)h-48; b[i]=a[i]; } // for(int s=0;s<size;s++) // { // System.out.println(a[s]); // } for(int i=0;i<size;i++) { int n=10-a[i]; for(int j=0;j<size;j++) { a[j]=(a[j]+n)%10; } String newNumber=""; for(int j=i;j<size;j++) { newNumber+=a[j]; } for(int j=0;j<i;j++) { newNumber+=a[j]; } BigInteger minimumNumber2=new BigInteger(newNumber); if(minimumNumber2.compareTo(minimumNumber)<0){ f = newNumber; minimumNumber =minimumNumber2; } for(int s=0;s<size;s++) { a[s]=b[s]; } } System.out.print(f); } }
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
d234498585ce574f4eb33c7f3a21e859
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; public class BB { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader bfr = new BufferedReader((new InputStreamReader( System.in))); int n = Integer.parseInt(bfr.readLine()); String s = bfr.readLine(); String a = s; String min = s; String st = s; for (int j = 0; j < n; j++) { st = shift(st); if (min.compareTo(st) > 0) min = st; } for (int i = 0; i < 9; i++) { a = add1(a); String b = a; for (int j = 0; j < n; j++) { b = shift(b); if (min.compareTo(b) > 0) min = b; } } System.out.println(min); } static String add1(String s) { String result = ""; for (int i = 0; i < s.length(); i++) { int value = Integer.parseInt(s.charAt(i) + ""); if (value == 9) { result += 0; } else result += (value + 1); } return result; } static String shift(String s) { String result = ""; result += s.charAt(s.length() - 1); result += (s.substring(0, s.length() - 1)); return result; } }
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
3ea9a6e12bcab740fb076171785962fb
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.Scanner; public class B283 { public void run() { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next(); String ans = s; for (int i = 0; i <= 10; i++) { StringBuilder sb = new StringBuilder(s); for (int j = 0; j < sb.length(); j++) { int dig = sb.charAt(j) - 48; dig += i; int newd = dig % 10; char newc = (char) (newd + 48); sb.setCharAt(j, newc); } // System.out.println(sb.toString()); if (sb.toString().compareTo(ans) < 0) { ans = sb.toString(); } for (int j = 1; j < n; j++) { String pt1 = sb.substring(j, n); pt1 = pt1 + sb.substring(0, j); if (pt1.compareTo(ans) < 0) { ans = pt1; } } } System.out.println(ans); in.close(); } public static void main(String[] args) { // TODO Auto-generated method stub new B283().run(); } }
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
f6c85ea81bcb1c4bd39885ff3ed1ab0a
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 B { void solve() throws IOException { int n = nextInt(); String str = nextToken(); int[] arr = new int[n]; for (int i = 0; i < n; ++i) { arr[i] = Integer.parseInt(str.charAt(i) + ""); } int min_i = 0; int min_off = (10 - arr[0]) % 10; for (int i = 1; i < n; ++i) { int off = (10 - arr[i]) % 10; for (int j = 0; j < n; ++j) { int f_index = (min_i + j) % n; int s_index = (i + j) % n; int f_value = (arr[f_index] + min_off) % 10; int s_value = (arr[s_index] + off) % 10; if (f_value != s_value) { if (f_value < s_value) { break; } else { min_i = i; min_off = off; } } } } for (int j = 0; j < n; ++j) { int index = (min_i + j) % n; int value = (arr[index] + min_off) % 10; out.print(value); } out.print("\n"); } void run() throws IOException { reader = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); // reader = new BufferedReader(new FileReader("file.in")); // out = new PrintWriter(new FileWriter("file.out")); tokenizer = null; solve(); reader.close(); out.flush(); } public static void main(String[] args) throws IOException { new B().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter out; int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } }
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
471e0646367f5eaf9ec9cf194c30f4ab
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
// refernced from ashcodish import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); String s = input.next(); String z = s; for(int i=0; i<n;i++){ int p = (10-(int)(s.charAt(0))); p = p%10; String num = ""; //System.out.println(p); for(int j=0; j<s.length();j++){ char tr=s.charAt(j); num+=(char)((int)(s.charAt(j))+p)%10; //System.out.println(num); } int j=0; //System.out.println(num); while(j<n && z.charAt(j)==num.charAt(j))j++; if(j<n && z.charAt(j)>num.charAt(j)){ z = num; } s = s.charAt(s.length()-1)+s.substring(0,s.length()-1); } System.out.println(z); } }
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
484c8249d9e246bf3a665aea81803321
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 A { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); // String[] split = f.readLine().split(" "); String min = ""; for(int i = 0; i < 1000; i++) min+="9"; int n = Integer.parseInt(f.readLine()); String line = f.readLine(); //shift current string n times --> increment n times for(int i = 0; i < 10; i++) { //num of increments if(compare(line, min)) min = line; for(int j = 0; j < n-1; j++) { //num of shifts line = shift(line); if(compare(line, min)) min = line; } line = shift(line); line = increment(line); } out.println(min); out.close(); } static String increment(String one) { StringBuilder inc = new StringBuilder(one.length()); for(int i = 0; i < one.length(); i++) { if(one.charAt(i)=='9') inc.append('0'); else inc.append((char)(one.charAt(i)+1)); } return inc.toString(); } static String shift(String one) { StringBuilder shift = new StringBuilder(one.length()); shift.append(one.charAt(one.length()-1)); for(int i = 0; i < one.length()-1; i++) { shift.append(one.charAt(i)); } return shift.toString(); } //two being current min and one being potential min static boolean compare(String one, String two) { if(one.compareTo(two) < 0) return true; return false; } }
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
7e782f0bf4a6e19aaac0d96b258f21ea
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.*; public class CF496B { static Arrangement[][] memo; static class Arrangement { int head; int inc; Arrangement(int head, int inc) { this.head = head; this.inc = inc; } int getDigit(String num, int i) { char digit = num.charAt((head + i) % num.length()); return (digit - '0' + inc) % 10; } static boolean lessThan(String num, Arrangement a, Arrangement b) { for (int i = 0; i < num.length(); i++) { int aDigit = a.getDigit(num, i); int bDigit = b.getDigit(num, i); if (aDigit < bDigit) { return true; } else if (aDigit > bDigit) { return false; } } return false; } void print(String num) { for (int i = 0; i < num.length(); i++) { System.out.print(getDigit(num, i)); } } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String num = in.next(); memo = new Arrangement[num.length()][10]; solve(new Arrangement(0, 0), num).print(num); in.close(); } static Arrangement solve(Arrangement a, String num) { if (a.head >= memo.length || a.inc >= memo[a.head].length) { return null; } if (memo[a.head][a.inc] != null) { return memo[a.head][a.inc]; } Arrangement min = a; Arrangement shift = solve(new Arrangement(a.head + 1, a.inc), num); if (shift != null && Arrangement.lessThan(num, shift, min)) { min = shift; } Arrangement inc = solve(new Arrangement(a.head, a.inc + 1), num); if (inc != null && Arrangement.lessThan(num, inc, min)) { min = inc; } return memo[a.head][a.inc] = min; } }
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
177cde206c2449ec9772f48c706a82d8
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class NextTest { public static void main(String[] args) { Scanner in=new Scanner(System.in); while(in.hasNext()){ int t=in.nextInt(); int []m=new int[t]; for (int i = 0; i < m.length; i++) { m[i]=in.nextInt(); } Arrays.sort(m); int k=0; for (int i = 1; i <=m.length; i++) { if(i!=m[i-1]){ k=i; break; } } if(k==0){ System.out.println(m[m.length-1]+1); }else{ System.out.println(k); } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
1e1f00e90bee1c5b5712482ccf0376fb
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // Set<Integer> set = new TreeSet<Integer>(); List<Integer> list = new ArrayList<Integer>(); for(int i=0; i<n; ++i) { list.add(sc.nextInt()); } Collections.sort(list); for(int i=1; i<=n; ++i) { if(list.get(i-1)!=i) { System.out.println(i); return; } } System.out.println(n+1); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
60ca4badcd273e92b46f46e7c0b5d940
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Diego Huerfano ( diego.link ) */ 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(); } } class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { final int n=in.readInt(); boolean used[]=new boolean[3001]; for( int i=0; i<n; i++ ) { used[in.readInt()]=true; } int answer=1; while( answer<=3000 && used[answer] ) answer++; out.printLine( answer ); } } 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 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); } } 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(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
d390cf863e50d10910068df367b0e6a4
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import static java.util.Arrays.deepToString; import java.io.*; import java.math.*; import java.util.*; public class Main { static void solve() { int n = nextInt(); boolean[] a = new boolean[3001]; for (int i = 0; i < n; i++) { int m = nextInt() - 1; a[m] = true; } for (int i = 0; i < a.length; i++) { if (!a[i]) { System.out.println(i + 1); return; } } } public static void main(String[] args) throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); setTime(); solve(); printTime(); printMemory(); writer.close(); } static BufferedReader reader; static PrintWriter writer; static StringTokenizer tok = new StringTokenizer(""); static long systemTime; static void debug(Object... o) { System.err.println(deepToString(o)); } static void setTime() { systemTime = System.currentTimeMillis(); } static void printTime() { System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime)); } static void printMemory() { System.err.println("Memory consumed: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime() .freeMemory()) / 1000 + "kb"); } static String next() { while (!tok.hasMoreTokens()) { String w = null; try { w = reader.readLine(); } catch (Exception e) { e.printStackTrace(); } if (w == null) return null; tok = new StringTokenizer(w); } return tok.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static BigInteger nextBigInteger() { return new BigInteger(next()); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
54ba5ac2db6754cae236d7a7554a2236
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; public class nextTest { static int [] arr; public static void mergeSort(int[] a) { if (a.length<=1) return; int[] front = new int[a.length / 2]; int[] tail = new int[a.length - front.length]; System.arraycopy(a, 0, front, 0, front.length); System.arraycopy(a, front.length, tail, 0, tail.length); mergeSort(front); mergeSort(tail); merge(front, tail, a); } public static void merge(int [] left, int [] right,int [] arr){ int count=0; int lpointer=0; int rpointer=0; while(lpointer < left.length && rpointer < right.length) { if(left[lpointer] < right[rpointer]){ arr[count]=left[lpointer]; lpointer++; } else{ arr[count]=right[rpointer]; rpointer++; } count++; } for(int i=lpointer;i<left.length;i++){ arr[count]=left[i]; count++; } for(int i=rpointer;i<right.length;i++){ arr[count]=right[i]; count++; } } public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); arr = new int [n]; for(int i =0;i<n;i++){ arr[i]=sc.nextInt(); } mergeSort(arr); boolean found=false; for(int i=0;i<arr.length;i++) { if((arr[i]-i)>1){ System.out.println((i+1)); found=true; break; } } if(found==false){ System.out.println((arr[arr.length-1]+1)); } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
9227d4cd07b9762528136de69469eae6
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A_Div2_27 { public static void main(String[]arg) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n,i,ans = 0; n = Integer.parseInt(in.readLine()); StringTokenizer st = new StringTokenizer(in.readLine()); boolean[]is = new boolean[3002]; for(i = 0; i < n; i++) { is[Integer.parseInt(st.nextToken())] = true; } boolean end = false; for(i = 1; i <= 3001 && !end; i++) { if(!is[i]) { end = true; ans = i; } } System.out.println(ans); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
9f55e4a17325091d1e267cf517bc7c12
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.*; import java.util.*; public class next { static BufferedReader br; static StringTokenizer st; static PrintWriter out; public static void main(String[] args) throws IOException { InputStream input = System.in; //InputStream input = new FileInputStream("fileIn.in"); OutputStream output = System.out; //OutputStream output = new FileOutputStream("fileOut.out"); br = new BufferedReader(new InputStreamReader(input)); out = new PrintWriter(output); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); ArrayList<Integer> nums = new ArrayList<Integer>(); for (int i = 0; i < n; i++) nums.add(Integer.parseInt(st.nextToken())); for (int i = 1; i < n; i++) for (int j = 0; j < i; j++) if (nums.get(i) < nums.get(j)) { int c = nums.get(i); nums.set(i,nums.get(j)); nums.set(j,c); } int ans = 1; while (nums.contains(ans)) ans++; out.println(ans); out.close(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
299cad22191a5319b1fbadd4f018711b
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class JavaApplication156 { public static void main(String[] args) { Scanner reader=new Scanner(System.in); int n=reader.nextInt(); int array[]=new int[n]; for (int i = 0 ; i<n ; i++) { array[i]=reader.nextInt(); } boolean u=false; Arrays.sort(array); if(array[0]<1) { array[0]=1; } for (int i = 0 ; i<n;i++) { if (array[i]!=(i+1)) { System.out.println((i+1)); u=true; break; } } if (!u) System.out.println((n+1)); }}
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
76d589be8e52e475fe0a72e423e6280c
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws IOException { BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); int[] nume = new int[4000]; for (int i = 0; i < 4000; i++) { nume[i]=i+1; } String num = s.readLine(); String cad[] = s.readLine().split("\\s+"); for (int i = 0; i < Integer.parseInt(num); i++) { for (int j = 0; j < 4000; j++) { if(Integer.parseInt(cad[i])==nume[j]){ nume[j]=0; } } } for (int i = 0; i < 4000; i++) { if(nume[i]!=0){ System.out.println(nume[i]); break; } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
20c2a3a4458f8bffe5a8af7c62ddf70e
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws IOException { BufferedReader bufer = new BufferedReader(new InputStreamReader(System.in)); int[] numeros = new int[4000]; for (int i = 0; i < 4000; i++) { numeros[i]=i+1; } String num = bufer.readLine(); String cad[] = bufer.readLine().split("\\s+"); for (int i = 0; i < Integer.parseInt(num); i++) { for (int j = 0; j < 4000; j++) { if(Integer.parseInt(cad[i])==numeros[j]){ numeros[j]=0; } } } for (int i = 0; i < 4000; i++) { if(numeros[i]!=0){ System.out.println(numeros[i]); break; } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
9cc773de2bf51fb9db3d694a9b1e2d6a
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws IOException { BufferedReader bufer = new BufferedReader(new InputStreamReader(System.in)); int[] nume = new int[4000]; for (int i = 0; i < 4000; i++) { nume[i]=i+1; } String num = bufer.readLine(); String cad[] = bufer.readLine().split("\\s+"); for (int i = 0; i < Integer.parseInt(num); i++) { for (int j = 0; j < 4000; j++) { if(Integer.parseInt(cad[i])==nume[j]){ nume[j]=0; } } } for (int i = 0; i < 4000; i++) { if(nume[i]!=0){ System.out.println(nume[i]); break; } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
474c1f093bc8ad1625d0944cc4b357aa
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; import java.util.Set; import java.util.TreeSet; /** * Created by tdph5945 on 2016-06-27. */ public class NextTest { public static void main(String... args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); Set<Integer> set = new TreeSet<Integer>(); while (n-- > 0) { set.add(scanner.nextInt()); } Integer[] items = set.toArray(new Integer[0]); if (items[0] != 1) { System.out.println(1); return; } for (int i = 0; i < items.length - 1; i++) { if (items[i] + 1 != items[i + 1]) { System.out.println(items[i] + 1); return; } } System.out.println(items[items.length - 1] + 1); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
aafe48a2ba1592582fe8356fc84c31de
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; import java.util.Set; import java.util.TreeSet; /** * Created by tdph5945 on 2016-06-27. */ public class NextTest { public static void main(String... args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); Set<Integer> set = new TreeSet<Integer>(); while (n-- > 0) { set.add(scanner.nextInt()); } Integer[] items = set.toArray(new Integer[0]); if (items.length == 1) { if (items[0] == 1) { System.out.println(2); } else { System.out.println(1); } } else { if (items[0] != 1) { System.out.println(1); return; } for (int i = 0; i < items.length - 1; i++) { if (items[i] + 1 != items[i + 1]) { System.out.println(items[i] + 1); return; } } System.out.println(items[items.length - 1] + 1); } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
f727eb1dd130a1fc6ba43b8ec0726e1d
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; public class a27 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); boolean[] used = new boolean[3003]; for (int i = 0; i < n; i++) { used[in.nextInt()] = true; } for (int i = 1; i < used.length; i++) { if (!used[i]) { System.out.println(i); break; } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
edd0c42100b32096610a67febba62948
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class NextTest { public static void bubbleSort(int[] array, int Size) { for (int i = 0; i < Size; i++) { for (int j = 0; j < Size - i - 1; j++) { if (array[j] > array[j + 1]) { int temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } } } public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader( System.in)); int s = Integer.parseInt(input.readLine()); StringTokenizer sc = new StringTokenizer(input.readLine()); int[] x = new int[s]; for (int i = 0; i < s; i++) { x[i] = Integer.parseInt(sc.nextToken()); } bubbleSort(x, x.length); int a = 1; for (int i = 0; i < x.length; i++) { if (x[i] == a) { a = x[i] + 1; } } System.out.println(a); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
99a8d037e1dc135346e457aa06b0bcd1
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; import java.lang.reflect.Array; import java.math.*; import java.io.*; import java.awt.*; import java.awt.geom.AffineTransform; public class Main{ static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(System.out); static final int maxn = (int)3e3 + 11; static int inf = (1<<30) - 1; static int n,m; static int a[][] = new int[maxn][maxn]; static boolean u[] = new boolean [maxn]; public static void main(String[] args) throws Exception { n = in.nextInt(); for (int i=1; i<=n; i++) { u[in.nextInt()] = true; } for (int i=1; i<maxn; i++) { if (!u[i]) { out.println(i); break; } } out.close(); } } class Pair implements Comparable<Pair> { int l,r; public Pair (int l, int r) { this.l = l; this.r = r; } @Override public int compareTo(Pair p) { if (this.l<p.l) { return -1; } else if (this.l == p.l) { return 0; } else { return 1; } } @Override public boolean equals(Object p) { if (((Pair)p).l == this.l && ((Pair)p).r==this.r) { return true; } return false; } } class FastReader { BufferedReader bf; StringTokenizer tk = null; String DELIM = " "; public FastReader(BufferedReader bf) { this.bf = bf; } public String nextToken() throws Exception { if(tk==null || !tk.hasMoreTokens()) { tk = new StringTokenizer(bf.readLine(),DELIM); } return tk.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
1285fb9e029e140648d6fa16f579188c
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Div2_27_A { public static void main(String[] args) { Scanner input = new Scanner (System.in); int n = input.nextInt(); int [] arr = new int [n]; for (int i = 0 ; i <n ; i ++) { arr[i]=input.nextInt(); } Arrays.sort(arr); if (arr[0] > 1) { System.out.print ("1"); return ; } if (n==1) { System.out.print (arr[0]+1); return ; } for (int i = 1 ; i < n ; i ++) { if (arr[i]-arr[i-1]>1){ System.out.print(arr[i-1]+1); return;} } System.out.print (arr[n-1]+1); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
bc5b893958f3f2e341b0b8ee0d3bc847
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(System.in); int n = in.nextInt(); int a[] = new int[300000]; for(int i = 0; i < n; ++i){ int x = in.nextInt(); a[x]++; } for(int i = 1; i < 30000; ++i){ if(a[i] == 0){ out.println(i); break; } } out.close(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
18779a8dd740f0a45b698fe3a9ded7d0
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.StringTokenizer; public class NextTest { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int N = Integer.parseInt(br.readLine()); int[] index = new int[N]; StringTokenizer st = new StringTokenizer(br.readLine()); for(int i = 0; i < N; i++) { index[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(index); int res = 1; int i = 0; while(i < N && res == index[i]) { res++; i++; } bw.write(Integer.toString(res)); bw.flush(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
29d81abb2ff4cb72663ec808c88a87d3
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int N = Integer.parseInt(br.readLine()); int[] index = new int[N]; StringTokenizer st = new StringTokenizer(br.readLine()); for(int i = 0; i < N; i++) { index[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(index); int res = 1; int i = 0; while(i < N && res == index[i]) { res++; i++; } bw.write(Integer.toString(res)); bw.flush(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
758769d5ffaaa029bf1ffcfab314d5ae
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; import java.io.InputStream; import java.io.PrintStream; public class NextTest { public static void main(String[] args) { InputStream in = System.in; PrintStream out = System.out; Scanner input = new Scanner(in); int n = input.nextInt(); int num = 2; int min = 3001; int max = 0; int[] array = new int[n]; boolean ind = false; for(int i = 0; i < n; i++) { int a = input.nextInt(); array[i] = a; if(a < min) min = a; if(a > max) max = a; } if(min != 1) { out.println(1); System.exit(0); }else { for(num = 2; num < max; num++) { for(int j = 0; j < n; j++) { if(num == array[j]) { ind = true; break; }else { ind = false; } } if(!ind) { out.println(num); System.exit(0); } } } out.println(max+1); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
1cc8ae0b8812cf737e86d33dd5211894
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class P27A { public P27A() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < n; i++){ indexes.add(sc.nextInt()); } sc.close(); Collections.sort(indexes); if (indexes.get(0) > 1){ System.out.println(1); return; } for (int i = 0; i < n-1; i++){ if (indexes.get(i) + 1 < indexes.get(i+1)){ System.out.println(indexes.get(i) + 1); return; } } System.out.println(indexes.get(n-1) + 1); } public static void main (String []args){ new P27A(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
ee35547fa808c3fd97bcaf629ac41def
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Arrays; import java.util.Collections; import java.util.Scanner; import java.util.Vector; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Vector<Integer>v=new Vector<Integer>(); for(int i = 0 ; i < n ;++i)v.add(sc.nextInt()); Collections.sort(v); for(int i = 1; i <=100000;++i) { int index = Collections.binarySearch(v, i); if(index<0){System.out.println(i);break;} } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
50ad73701d415ff35a4cc4c984ebd55f
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { final int MAX = 3001; int n = in.nextInt(); boolean[] cnt = new boolean[MAX+1]; for (int i = 0; i < n; i++) { cnt[in.nextInt()] = true; } for (int i = 1; i <= MAX; i++) { if(!cnt[i]){ out.println(i); return; } } } } 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
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
236a3375f5f9a3b8f7d32843831f18a4
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.*; import java.util.*; public class j { public static void main(String a[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); int t=0,j=0,n=0,i=0; String s,r; n=Integer.parseInt(b.readLine()); int d[]; r=b.readLine(); StringTokenizer c=new StringTokenizer(r); d=new int[n]; for(i=0;i<n;i++) d[i]=Integer.parseInt(c.nextToken()); for(j=0;j<n-1;j++) { for(i=j+1;i<n;i++) { if(d[j]>d[i]) { t=d[j]; d[j]=d[i]; d[i]=t; } } } t=d[0]; if(t!=1) System.out.print("1"); else { for(i=0;i<n;i++) { if(d[i]==t+i) continue; else break; } System.out.print(t+i); } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
9bf2f7f6325116b096da252d3d391951
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author nasko */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); boolean[] used = new boolean[3002]; Arrays.fill(used, false); for(int i = 0; i < n; ++i) { used[in.nextInt()] = true; } for(int i = 1; i <= 3001; ++i) { if(!used[i]) { out.println(i); return; } } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public 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\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
a57a4c164af627475ee4a1657f1ed4f7
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
/* * @Author: steve * @Date: 2015-04-07 22:32:42 * @Last Modified by: steve * @Last Modified time: 2015-04-07 22:37:09 */ import java.io.*; import java.util.*; public class NextTest { public static void main(String[] args) throws Exception{ BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(entrada.readLine()); boolean[] esta = new boolean[3001]; String[] cads = entrada.readLine().split(" "); for(int i=0;i<n;i++) esta[Integer.parseInt(cads[i])]=true; int i=0; for(i=1;i<esta.length;i++) if(!esta[i]) break; System.out.println(i); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
8e73b63e81cb66dfca86a200366998e0
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TaskA { static Scanner scn = new Scanner(System.in); public static void main(String[] argc) { int n = scn.nextInt(); boolean used[] = new boolean[30000]; Arrays.fill(used, false); for (int i = 0; i < n; i++) { int x = scn.nextInt(); used[x] = true; } for (int i = 1; i <= 3001; i++) { if (used[i] == false) { System.out.println(i); System.exit(0); } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
f12f3357e038ce4252c3d405cb0d8fa9
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Task027A { public static void main(String... args) throws NumberFormatException, IOException { Solution.main(System.in, System.out); } static class Solution { public static void main(InputStream is, OutputStream os) throws NumberFormatException, IOException { PrintWriter pw = new PrintWriter(os); Scanner s = new Scanner(is); int n = s.nextInt(); Set<Integer> indexes = new TreeSet<>(); for (int i = 0; i < n; i++) { indexes.add(s.nextInt()); } for (int i = 1;; i++) { if (!indexes.contains(i)) { pw.println(i); break; } } pw.flush(); s.close(); } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
be5c82a65a7c49d5a17fbcd60bc9f1bd
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = ""; StringBuilder out = new StringBuilder(); while ((line = in.readLine()) != null && line.length() != 0) { int size = Integer.parseInt(line.trim()); int[] v = retInts(in.readLine()); Arrays.sort(v); HashSet<Integer> set = new HashSet<Integer>(); for (int i = 0; i < v.length; i++) set.add(v[i]); for (int i = 1; i < 10000; i++) if(!set.contains(i)){ out.append(i+"\n"); break; } } System.out.print(out); } public static int[] retInts(String line) { String[] w = line.trim().split(" "); int[] a = new int[w.length]; for (int i = 0; i < w.length; i++) a[i] = Integer.parseInt(w[i].trim()); return a; } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
ec8d09d8086076040a3a88778bd29c11
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Zyflair Griffane */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; PandaScanner in = new PandaScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); A solver = new A(); solver.solve(1, in, out); out.close(); } } class A { public void solve(int testNumber, PandaScanner in, PrintWriter out) { int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } Arrays.sort(arr); int res = 1; for (int i = 0; i < n; i++) { if (arr[i] > res) { out.println(res); return; } if (arr[i] == res) { res++; } } out.println(res); } } class PandaScanner { public BufferedReader br; public StringTokenizer st; public InputStream in; public PandaScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(this.in = in)); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { return null; } } public String next() { if (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(nextLine().trim()); return next(); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
d407ba69c9a78e59baa6741caad420af
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Task27A { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); int[] a = new int[n + 1]; StringTokenizer st = new StringTokenizer(in.readLine()); for (int i = 1; i <= n; i++) { a[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(a); for (int i = 1; i <= n; i++) { if (a[i] != i) { System.out.println(i); return; } } System.out.println(n + 1); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
b13a772705553f7266e423d82b5d18d6
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.lang.*; import java.util.*; import java.io.*; public class Test { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } } class TaskA { public final static int maxn = 3005; boolean[] visit = new boolean[maxn]; public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); int i, j, k; for (i=0; i<n; ++i) visit[in.nextInt()] = true; for (i=1; i<maxn; ++i) { if (!visit[i]) { out.println(i); break; } } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer==null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
50c151ec2033438f984c66ad24dcdaa2
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class code { public static void main(String[] args) { Scanner k=new Scanner(System.in); int test=k.nextInt(); int[] array=new int[test]; for (int i = 0; i < array.length; i++) { array[i]=k.nextInt(); } int min=1; for (int i = 0; i < array.length; i++) { if (min==array[i]) { min++; i=-1; } } System.out.println(min); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
5fff56e651e6bfafb78cf53673c6e4d3
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Next_Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] inexes=new int[n]; int index; for (int i = 0; i < n; i++) { int a=input.nextInt(); inexes[i]=a; } Arrays.sort(inexes); index=1; for (int i = 0; i < inexes.length; i++,index++) { if(index<inexes[i]){ System.out.println(index); return; } } System.out.println(index); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
c35a0225b50a698d45edec423233af92
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; public class nexttest { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int x=Integer.parseInt(in.readLine()); int a[]=new int[x]; String u=in.readLine(); String k[]=u.split(" "); for (int i = 0; i < x; i++) { a[i]=Integer.parseInt(k[i]); } Arrays.sort(a); int i; for ( i = 0; i < x; i++) { if(a[i]!=i+1){ break; } } out.println(i+1); out.close(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
80b2570d6879169a8f25a70ac6e9d703
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; public class NextTest { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nextIndex = 1; int num = in.nextInt(); int arr[] = new int[num]; for (int i = 0; i < num; i++) { arr[i] = in.nextInt(); } for (int i = 0; i < arr.length; i++) { for (int j = i; j < arr.length; j++) { if (arr[i] > arr[j]) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } for (int i = 0; i < arr.length; i++) { if (nextIndex == arr[i]) { nextIndex += 1; } } System.out.println(nextIndex); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
9fc02013b4ce77c416383710468e00ba
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.io.*; import java.util.*; public class CF28A { private static BufferedReader br; private static StringTokenizer st; private static PrintWriter pw; // private static Timer t = new Timer(); public CF28A() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); } String next() throws IOException { while (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } boolean hasNext() { if (st != null && st.hasMoreElements()) return true; try { while (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine()); } catch (Exception e) { return false; } return true; } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } void solve() throws IOException { int n = nextInt(); int max = Integer.MIN_VALUE; ArrayList<Integer> list = new ArrayList<>(); for(int i = 0; i < n; i++) { int a = nextInt(); list.add(a); max = Math.max(max, a); } int ans = max+1;; for(int i = 1; i <= max; i++) { if(!list.contains(i)) { ans = i; break; } } pw.println(ans); pw.flush(); } public static void main(String[] args) throws IOException{ new CF28A().solve(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
78a448090203f42dd7734aa8995a4b5c
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int input = in.nextInt(); int[] A = new int[input]; int max = 0; for (int i = 0; i < input; i++) { A[i] = in.nextInt(); if (max < A[i]) { max = A[i]; } } in.close(); int count = 0; int count1 = 0; for (int i = 1; i < max; i++) { for (int j = 0; j < A.length; j++) { if (A[j] == i) { break; } else { count++; } } if (count == input) { System.out.println(i); count1 = 1; break; } count = 0; } if (count1 != 1) { System.out.println(max + 1); } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
875012cccb521234c4ea2ff1e28038f2
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; import java.util.Vector; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author KHALED */ public class NextTest { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); Vector<Integer>vec=new Vector<Integer>(); int max=Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int k=scan.nextInt(); vec.add(k); if(k>max) max=k; } for (int i = 1; i <= max+1; i++) { if(!vec.contains(i)) { System.out.println(i); return; } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
1ab5a7210d3b526480d76e9f829a37fd
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; public class NextTest { public static void main(String[] args) { Scanner h = new Scanner(System.in); // Scanner Sc =new Scanner(System.in);; String x = h.nextLine(); String y = h.nextLine(); String[] z = y.split(" "); int[] r = new int[z.length]; for (int i = 0; i < r.length; i++) { int w = Integer.parseInt(z[i]); r[i] = w; } int min = r[0]; for (int i = 0; i < r.length; i++) { if (r[i] < min) { min = r[i]; } } if (min>1) { System.out.println(1); } else { boolean check = true; for (int k = 0; k < r.length; k++) { for (int i = 0; i < r.length; i++) { if (min + 1 == r[i]) { check = false; } } if (check == true) { System.out.println(min + 1); break; } else { min++; check = true; } } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
a155387294de40de0be1b16565c67539
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; import java.io.*; public class Main { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringBuilder out = new StringBuilder(); public static void main(String[] args){ solve(); return; } // the followings are methods to take care of inputs. static int nextInt(){ return Integer.parseInt(nextLine()); } static long nextLong(){ return Long.parseLong(nextLine()); } static int[] nextIntArray(){ String[] inp = nextLine().split("\\s+"); int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){ ary[i] = Integer.parseInt(inp[i]); } return ary; } static int[] nextIntArrayFrom1(){ String[] inp = nextLine().split("\\s+"); int[] ary = new int[inp.length + 1]; for (int i = 0; i < inp.length; i++){ ary[i+1] = Integer.parseInt(inp[i]); } return ary; } static long[] nextLongArray(){ String[] inp = nextLine().split("\\s+"); long[] ary = new long[inp.length]; for (int i = 0; i < inp.length; i++){ ary[i] = Long.parseLong(inp[i]); } return ary; } static long[] nextLongArrayFrom1(){ String[] inp = nextLine().split("\\s+"); long[] ary = new long[inp.length + 1]; for (int i = 0; i < inp.length; i++){ ary[i+1] = Long.parseLong(inp[i]); } return ary; } static String nextLine(){ try { return reader.readLine().trim(); } catch (Exception e){} return null; } static void solve(){ int n = nextInt(); int[] tmp = nextIntArray(); Arrays.sort(tmp); int count=1; for(int i=0;i<n;i++){ if(count<tmp[i]) break; count++; } System.out.println(count); return; } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
6dfdfd46c2ef81ae6b28aa1839273fac
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [] z = new int[4001]; for(int i = 0 ; i < n ; i++){ z[sc.nextInt() - 1] = 1; } int ans = 0; for(int i = 0 ; i < 4000 ; i++){ if(z[i] == 0){ ans = i + 1; break; } } System.out.print(ans); sc.close(); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
ea9c57ac8f00d12ee7a36212db024e6c
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class NextAnswer { public static void main(String [] args){ int cnt=0; Scanner in = new Scanner(System.in); int n = in.nextInt(); int array[]=new int[n]; for(int i=0;i<n;i++){ int a = in.nextInt(); array[i]=a; } Arrays.sort(array); for(int i=1;i<=n;i++){ if(array[i-1]!=i){ cnt++; System.out.print(i); break; } } if(cnt==0) System.out.print((n+1)); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
66f9a07c9c10952ec20523f2d5d526c6
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.Collections; import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan= new Scanner(System.in); int n=Integer.parseInt(scan.nextLine()); String[] temp = scan.nextLine().split(" "); int [] values=new int[n]; for (int i = 0; i < temp.length; i++) { values[i] =Integer.parseInt(temp[i]); } int [] sorted=sort(values); int min=1; if(sorted[0]>1){ System.out.println("1"); }else{ for (int i = 0; i < sorted.length; i++) { if(i == sorted.length-1) { System.out.println(sorted[i]+1); break; } if((sorted[i]+1) < (sorted[i+1])){ System.out.println(sorted[i]+1); break; } } } } private static int[] sort(int[] arr) { // TODO Auto-generated method stub int i, j, minIndex, tmp; int n = arr.length; for (i = 0; i < n - 1; i++) { minIndex = i; for (j = i + 1; j < n; j++) if (arr[j] < arr[minIndex]) minIndex = j; if (minIndex != i) { tmp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = tmp; } } return arr; } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
7658918612807d409fbc30b26328976f
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.awt.Point; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.PriorityQueue; import java.util.StringTokenizer; import sun.misc.Queue; /** * * @author Mojtaba */ public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); //String str = reader.readLine(); PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n = Integer.parseInt(reader.readLine()); StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = Integer.parseInt(tokenizer.nextToken()); } Arrays.sort(a); sb.append(F(a)); writer.println(sb.toString().trim()); writer.close(); reader.close(); } private static int F(int[] a) { if (a[0] != 1) { return 1; } for (int i = 0; i < a.length - 1; i++) { if (a[i + 1] - a[i] > 1) { return a[i] + 1; } } return a[a.length - 1] + 1; } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
c853fb33a9b9202aaed3c11c2e1b4533
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner lee=new Scanner(System.in); int n=lee.nextInt(); int []v=new int[n]; for (int i = 0; i <n; i++) { v[i]=lee.nextInt(); } Arrays.sort(v); if(v[0]>1){ System.out.println(1); } else{ int pd=0; for (int i = 0; i < v.length-1; i++) { if(v[i]-v[i+1]!=-1){ System.out.println(v[i]+1); pd=1; break; } } if(pd==0){ System.out.println(v[v.length-1]+1); } } } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
a7ad4cca9df6b78d19e0ff397ce5f414
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; import java.io.*; public class poligocod{ public static void main(String args[]) throws IOException{ BufferedReader lector = new BufferedReader(new InputStreamReader(System.in)); int tmp = Integer.parseInt(lector.readLine()); String t[] = lector.readLine().split(" "); int tt[]= new int[tmp]; for(int n =0;n<tt.length;n++)tt[n]=Integer.parseInt(t[n]); Arrays.sort(tt); int y = 1; for(int n = 0;n<tt.length;n++){ if(tt[n]!=y){ System.out.println(y); return; } y++; } System.out.println(y); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
ba22ea5ee842194caf6903b11f3664cc
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); boolean []ok=new boolean [3005]; for(int i=0;i<n;i++) ok[sc.nextInt()]=true; int j=0; for(int i=1;i<3005;i++) if(!ok[i]) { j=i; break; } System.out.println(j); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
b7634f18221db8abc82eef1304b0f6c9
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Boolean> arr = new ArrayList<Boolean>(4000); arr.add(true); for (int i = 0; i < 4000; i++) arr.add(false); while (n-- != 0) arr.set(sc.nextInt(), true); System.out.println(arr.indexOf(false)); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
9529677ddcc39063ea5e6999f6df0e0e
train_003.jsonl
1284130800
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
256 megabytes
import java.util.*; public class a27 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int tc=sc.nextInt(); int c=0; int a[]=new int[tc]; for(int i=0;i<tc;i++) a[i]=sc.nextInt(); Arrays.sort(a); for(int i=0;i<tc;i++) { if(a[i]!=i+1) { c=i+1; break; } } if(c==0) System.out.println(tc+1); else System.out.println(c); } }
Java
["3\n1 7 2"]
2 seconds
["3"]
null
Java 7
standard input
[ "implementation", "sortings" ]
5e449867d9fcecc84333b81eac9b5d92
The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.
1,200
Output the required default value for the next test index.
standard output
PASSED
c773232133870452fffaf37bdd590274
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.Scanner; public class Main { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int n = scanner.nextInt(), k = scanner.nextInt(); int a = 0; for (int i = 0; i < n; i++) { int x, y; x = scanner.nextInt(); y = scanner.nextInt(); a += (y - x + 1); } if (a % k == 0) { System.out.println(a % k); } else { System.out.println(Math.abs((a % k) - k)); } } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
f72c03b220239faab5eac8af5cde2c0e
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.*; public class PoloThePenguinAndSegments { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n=input.nextInt(); int k=input.nextInt(); int x=0; int count=0; for(int i=0;i<n;i++) { int l=input.nextInt(); int r=input.nextInt(); x+=r-l+1; } if(x%k==0) { System.out.println(0); return; }else { while(x%k!=0) { count++; x++; } } System.out.println(count); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
29aa7a1a6a5a81687212ce7d81780b2d
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.Scanner; public class PoloThePenguinAndSegments { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int k = cin.nextInt(); int result=0; int x1,x2; while(n!=0){ n--; x1=cin.nextInt(); x2=cin.nextInt(); result+=x2-x1 +1; } if(result%k!=0) System.out.println(k-result%k); else System.out.println(0); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
451f3be6a4f6e63f0c00dc0aa90d0c0f
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.Scanner; public class Main { private static Scanner in = new Scanner(System.in); public static void main(String[] args) { // write your code here int covered = 0, end, start; int number = in.nextInt(), k = in.nextInt(); while (number-- > 0) { start = in.nextInt(); end = in.nextInt(); covered += end - start + 1; } covered = covered % k; if (covered != 0) { covered = k - covered; } System.out.println(covered); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
4ad236c950fc01cc46d6cfc6e3496755
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.Scanner; import java.io.*; public class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); int sum=0; int cover=inp.nextInt(); int k=inp.nextInt(); for (int i = 0; i < cover; i++) { int j=inp.nextInt(); int b=inp.nextInt(); sum+=(b-j+1); } sum%=k; if(sum!=0){ sum=k-sum; } System.out.println(sum); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
4f17424580e059974df7d8467468568b
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Main { 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(); } } public static void main(String[] args)throws IOException { Reader scn = new Reader(); StringBuilder res = new StringBuilder(); int n = scn.nextInt(); int k = scn.nextInt(); int x = 0; for(int i = 0 ; i < n ; i++){ int a = scn.nextInt(); int b = scn.nextInt(); x += (b - a + 1); } if(x % k == 0){ res.append(0); }else{ int i = x / k; while(true){ if(k * i > x){ break; } i++; } res.append(k * i - x); } System.out.println(res); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
cc273415d1105e2067a2242de02c8abd
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.Scanner; public class Sheet_A { public static boolean goodNumber(String num, int k) { for (char i = '0'; i <= '0' + k; i++) if(num.indexOf(i) == -1) return false; return true; } public static boolean isPrime(long n) { for (long i = n / 2; i >= 2; i--) if (n % i == 0) return false; return true; } public static boolean isCoPrime(long a, long b) { if (isPrime(a) && b % a != 0 || isPrime(b) && a % b != 0) return true; return false; } public static boolean isValid(int a1, int r1, int c1, int d1) { return (r1 - a1 <= 9 && r1 - a1 > 0 && c1 - a1 <= 9 && c1 - a1 > 0 && d1 - a1 <= 9 && d1 - a1 > 0 && a1 != d1 - a1 && a1 != c1 - a1 && a1 != r1 - a1 && r1 - a1 != d1 - a1 && r1 - a1 != c1 - a1 && d1 - a1 != c1 - a1); } public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int k = input.nextInt(); long count = 0; for (int i = 0; i < n; i++) { int first = input.nextInt(); int second = input.nextInt(); count += (second - first + 1); } System.out.println((count % k == 0) ? 0 : k - count % k); } } /* int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = input.nextInt(); */ //Arrays.sort(arr); /*for (int i = 0; i < n; i++) System.out.print(arr[i] + " "); */ /* * int n = input.nextInt(); int t = input.nextInt(); int k = (int) ((Math.pow(10 % t, n) % t) * -1 + 12); System.out.print(k + Math.pow(10, n)); */
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
cd651dcb9906fea3a96aed31f1b85220
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.HashSet; import java.util.Scanner; import java.util.Arrays; import java.util.Set; public class CP { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); int k =sc.nextInt(); int c=0; while(n--!=0) { int l = sc.nextInt(); int r = sc.nextInt(); c += (r - l) + 1; } if(c%k==0) { System.out.println(0); return; } System.out.println(k-c%k); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
f8452ec2c1315bd6637cb742c892089a
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
/** * Online Judge: CodeForces. * Problem Code: CF289-D2-A. * Problem Name: Polo the Penguin and Segments. * Date : 14/06/2020. * @author Andrew */ import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int k = input.nextInt(); int coverdArea = 0; for (int i = 0; i < n; i++) { int l = input.nextInt(); int r = input.nextInt(); coverdArea += r - l + 1; } System.out.println((((coverdArea / k) + 1) * k - coverdArea) % k); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
23ba4da0ebc58e9a587bc2729a3028e3
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
/** * Online Judge: CodeForces. * Problem Code: CF289-D2-A. * Problem Name: Polo the Penguin and Segments. * Date : 14/06/2020. * @author Andrew */ import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int k = input.nextInt(); int coveredArea = 0; for (int i = 0; i < n; i++) { int l = input.nextInt(); int r = input.nextInt(); coveredArea += r - l + 1; } System.out.println((k - coveredArea % k) % k); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
850f9408b0d627df35cafac67998897e
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
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 * * @author mprodev */ 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); APoloThePenguinAndSegments solver = new APoloThePenguinAndSegments(); solver.solve(1, in, out); out.close(); } static class APoloThePenguinAndSegments { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(), k = in.nextInt(); int[] left = new int[n]; int[] right = new int[n]; for (int i = 0; i < n; i++) { left[i] = in.nextInt(); right[i] = in.nextInt(); } int sum = 0; for (int i = 0; i < n; i++) { sum += (right[i] - left[i] + 1); } if (sum % k == 0) out.println(0); else out.println(k - sum % k); } } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
4536ab7e120c3a839f0afac0d5984699
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class JavaApplication30 { private static Scanner in=new Scanner(System.in); public static void main(String[] args) { int num=in.nextInt(); int k=in.nextInt(); int l,r,sum=0; for(int i=0;i<num;i++) { l=in.nextInt(); r=in.nextInt(); for(int j=l;j<=r;j++) { sum++; } } if(sum%k==0) System.out.println(sum%k); else System.out.println(k-(sum%k)); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
abaabdc63b0ff8ff456096fea658e2e3
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.*; public class PoloThePenguinAndSegments { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n=input.nextInt(); int k=input.nextInt(); int x=0; int count=0; for(int i=0;i<n;i++) { int l=input.nextInt(); int r=input.nextInt(); x+=r-l+1; } if(x%k==0) { System.out.println(0); return; }else { while(x%k!=0) { count++; x++; } } System.out.println(count); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
93df5309ef7ab23d36fc5a8d4ff67c0e
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.lang.*; import java.io.*; import java.util.*; import java.util.ArrayList; public class MyClass { public static void main(String args[])throws Exception { Scanner sc=new Scanner(System.in); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); long n=sc.nextLong(); long k=sc.nextLong(); long s=0; for(int i=0;i<n;i++) { long a=sc.nextLong(); long b= sc.nextLong(); s+=b-a+1; } s=s%k; if(s==0) System.out.println(0); else System.out.println(k-s); } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
8bdb215ddd6be8fb76ffc4abd5890bf4
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class input2 { public static int id[] = new int[60005]; public static void init() { for (int i = 0; i < 60005; i++) { id[i] = i; } } public static int root(int x) { while (id[x] != x) { id[x] = id[id[x]]; x = id[x]; } return x; } public static void union(int x, int y) { int p = root(x); int q = root(y); id[p] = id[q]; } public static long kruskal(ArrayList<ArrayList<Integer>> A) { long min = 0; Collections.sort(A, new sort()); int x, y; int cost = 0; for (int i = 0; i < A.size(); i++) { x = A.get(i).get(0); y = A.get(i).get(1); cost = A.get(i).get(2); System.out.println("I am cost : " + cost); System.out.println("I am root x : " + x + " " + root(x)); System.out.println("I am root y : " + root(y)); if (root(x) != root(y)) { min += cost; union(x, y); } } return min; } public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); long v = 0; for(int i=0;i<n;i++){ st = new StringTokenizer(br.readLine()); long a = Long.parseLong(st.nextToken()); long b = Long.parseLong(st.nextToken()); long dif = b-a+1; v+=dif; } long mod = v%m; if(mod == 0){ System.out.println(0); } else{ System.out.println(m-mod); } } static class sort implements Comparator<ArrayList<Integer>> { @Override public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) { int c = o1.get(2).compareTo(o2.get(2)); return c; } } }
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output
PASSED
d97d384d326c8882c16ff739a5453de6
train_003.jsonl
1364916600
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
256 megabytes
import java.util.Scanner; public class acm { public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(),k=in.nextInt(),l,r,store=0,counter=0; for(int i=0;i<n;i++) { l=in.nextInt();r=in.nextInt(); if(l==0&&r==0) store+=1; else if(l>0&&r>0||(l>=0&&r>0)) store+=r-l+1; else if(l<0&&r<0||l<0&&r==0) store+=Math.abs(l)-Math.abs(r)+1; else if(l<0&&r>0) store+=Math.abs(l)+r+1; } if(store%k==0) System.out.println(counter); else if(store<k) { counter+=k-store; System.out.println(counter); } else if(store>k) { while(true) { store+=1; counter++; if(store%k==0) { System.out.println(counter); break; } } } }}
Java
["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7"]
2 seconds
["2", "0"]
null
Java 11
standard input
[ "implementation", "brute force" ]
3a93a6f78b41cbb43c616f20beee288d
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i &lt; j ≤ n) the following inequality holds, min(ri, rj) &lt; max(li, lj).
1,100
In a single line print a single integer — the answer to the problem.
standard output