language
stringclasses
1 value
dataset
stringclasses
1 value
id
stringlengths
10
10
code
stringlengths
220
26.6k
test_IO
list
Java
codenet
s780275612
import java.util.Scanner; public class s780275612 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int intA = sc.nextInt(); double dbAncer = Math.pow(intA, 3); int intAncer = (int) dbAncer; System.out.println(intAncer); } }
[ { "input": "2\n", "output": "8\n" } ]
Java
codenet
s175590171
import java.io.*; import java.util.*; public class s175590171 { public static void main(String[] args) { FastScanner fs = new FastScanner(); int n = fs.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = fs.nextInt(); } Arrays.sort(a); long sum = 0; int count = 0; for (int i = 0; i < n - 1; i++) { sum += a[i]; if (a[i + 1] <= 2 * sum) { count++; } else { count = 0; } } System.out.println(count + 1); } static class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr; private int buflen; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) { ptr++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } } }
[ { "input": "3\n3 1 4\n", "output": "2\n" } ]
Java
codenet
s500433274
import java.math.*; import java.util.Scanner; public class s500433274 { public static void main(String[] args) { BigInteger a; BigInteger b; BigInteger c; Scanner cin = new Scanner(System.in); while (cin.hasNext()) { a = cin.nextBigInteger(); b = cin.nextBigInteger(); c = a.max(b); if (a.equals(c) && !b.equals(c)) { System.out.println("GREATER"); } else if (b.equals(c) && !a.equals(c)) { System.out.println("LESS"); } else { System.out.println("EQUAL"); } } cin.close(); } }
[ { "input": "36\n24\n", "output": "GREATER\n" } ]
Java
codenet
s314813282
import java.util.*; public class s314813282 { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); int m = scan.nextInt(); int n = scan.nextInt(); int x = scan.nextInt(); int y = scan.nextInt(); int[] a = new int[m]; for (int i = 0; i < a.length; i++) { a[i] = scan.nextInt(); } int[] b = new int[n]; for (int i = 0; i < b.length; i++) { b[i] = scan.nextInt(); } int xMax = MaxInt(x, a); int yMin = MinInt(y, b); CheckWar(xMax, yMin); } static int MaxInt(int x, int[] a) { int bignum = x; for (int i = 0; i < a.length; i++) { bignum = Math.max(bignum, a[i]); } return bignum; } static int MinInt(int y, int[] b) { int smallnum = y; for (int i = 0; i < b.length; i++) { smallnum = Math.min(smallnum, b[i]); } return smallnum; } static void CheckWar(int a, int b) { if (a >= b) { System.out.println("War"); } else { System.out.println("No War"); } } }
[ { "input": "3 2 10 20\n8 15 13\n16 22\n", "output": "No War\n" } ]
Java
codenet
s173032907
import java.util.Scanner; public class s173032907 implements Runnable { private static final Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Thread(null, new s173032907(), "", 128 * 1024 * 1024).start(); } public void run() { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } long cost1 = 0; long cost2 = 0; int current1 = 0; int current2 = 0; long[] dp1 = new long[n]; long[] dp2 = new long[n]; for (int i = 0, j = n - 1; i < n; i++, j--) { cost1 += Math.abs(a[i] - current1); current1 = a[i]; dp1[i] = cost1; cost2 += Math.abs(a[j] - current2); current2 = a[j]; dp2[j] = cost2; } for (int i = 0; i < n; i++) { if (i == 0) { System.out.println(dp2[i + 1] + Math.abs(a[1])); } else if (i == n - 1) { System.out.println(dp1[i - 1] + Math.abs(a[i - 1])); } else { System.out.println(dp1[i - 1] + dp2[i + 1] + Math.abs(a[i - 1] - a[i + 1])); } } } }
[ { "input": "3\n3 5 -1\n", "output": "12\n8\n10\n" } ]
Java
codenet
s898738430
import java.util.*; public class s898738430 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int ans = 0; for (int i = 1; i < n - 1; i++) { if (a[i] != Math.min(a[i - 1], Math.min(a[i], a[i + 1])) && a[i] != Math.max(a[i - 1], Math.max(a[i], a[i + 1]))) { ans++; } } System.out.println(ans); sc.close(); } }
[ { "input": "5\n1 3 5 4 2\n", "output": "2\n" } ]
Java
codenet
s527301188
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class s527301188 { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] strs = reader.readLine().split(" "); int[] nums = new int[strs.length]; int top = 0; for (int i = 0; i < strs.length; i++) { switch (strs[i].charAt(0)) { case '+': top--; nums[top - 1] = nums[top - 1] + nums[top]; break; case '-': top--; nums[top - 1] = nums[top - 1] - nums[top]; break; case '*': top--; nums[top - 1] = nums[top - 1] * nums[top]; break; default: nums[top] = Integer.parseInt(strs[i]); top++; break; } } System.out.println(nums[0]); } }
[ { "input": "1 2 +\n", "output": "3\n" } ]
Java
codenet
s356471394
import java.util.Scanner; public class s356471394 { static Scanner sc = new Scanner(System.in); static String[] nums = sc.nextLine().split(" "); static int N = Integer.parseInt(nums[0]); static int M = Integer.parseInt(nums[1]); static char[][] room = new char[N][M]; static int D = Integer.parseInt(nums[2]); static int num; public static void main(String[] args) { inputRoom(); if (M >= D) { setWE(); } if (N >= D) { setNS(); } System.out.println(num); sc.close(); } private static void setWE() { boolean canPut = true; for (int i = 0; i < N; i++) { for (int j = 0; j < M - D + 1; j++) { canPut = true; for (int k = 0; k < D; k++) { if (s356471394.room[i][j + k] == '#') { canPut = false; break; } } if (canPut) { num++; } } } } private static void setNS() { boolean canPut = true; for (int i = 0; i < M; i++) { for (int j = 0; j < N - D + 1; j++) { canPut = true; for (int k = 0; k < D; k++) { if (s356471394.room[j + k][i] == '#') { canPut = false; break; } } if (canPut) { num++; } } } } private static void inputRoom() { String strRoom = ""; for (int i = 0; i < N; i++) { strRoom = sc.nextLine(); s356471394.room[i] = strRoom.toCharArray(); } } }
[ { "input": "3 5 2\n...#.\n#...#\n....#\n", "output": "12\n" } ]
Java
codenet
s275359315
import java.util.*; public class s275359315 { public static void main(String... args) { Scanner scan = new Scanner(System.in); int r = scan.nextInt(); int res = (int) Math.pow(r, 2); System.out.println(res); } }
[ { "input": "2\n", "output": "4\n" } ]
Java
codenet
s640163137
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class s640163137 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] a = new int[n]; String[] elements = br.readLine().split(" "); for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(elements[i]); } int swapCount = 0; for (int i = 0; i < a.length; i++) { int mini = i; for (int j = i; j < a.length; j++) { if (a[j] < a[mini]) { mini = j; } } if (mini != i) { int v = a[mini]; a[mini] = a[i]; a[i] = v; swapCount++; } } String ans = String.valueOf(a[0]); for (int i = 1; i < a.length; i++) { ans += " " + a[i]; } System.out.println(ans); System.out.println(swapCount); } }
[ { "input": "6\n5 6 4 2 1 3\n", "output": "1 2 3 4 5 6\n4\n" } ]
Java
codenet
s077706488
import java.util.Scanner; public class s077706488 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int N = stdIn.nextInt(); int X = stdIn.nextInt(); int[] m = new int[N]; m[0] = stdIn.nextInt(); X -= m[0]; int min = m[0]; for (int i = 1; i < N; i++) { m[i] = stdIn.nextInt(); X -= m[i]; if (m[i] < min) { min = m[i]; } } System.out.println(N + X / min); } }
[ { "input": "3 1000\n120\n100\n140\n", "output": "9\n" } ]
Java
codenet
s476581255
import java.util.Scanner; public class s476581255 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int count = bubbleSort(a, n); for (int i = 0; i < n; i++) { if (i < n - 1) { System.out.print(a[i] + " "); } else { System.out.println(a[i]); } } System.out.println(count); } public static int bubbleSort(int[] a, int n) { boolean flag = true; int count = 0; while (flag) { flag = false; for (int j = n - 1; j > 0; j--) { if (a[j] < a[j - 1]) { int free = a[j]; a[j] = a[j - 1]; a[j - 1] = free; count++; flag = true; } } } return count; } }
[ { "input": "5\n5 3 2 4 1\n", "output": "1 2 3 4 5\n8\n" } ]
Java
codenet
s490798303
import java.util.*; public class s490798303 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); Map<Integer, List<Integer>> map = new HashMap<>(); for (int i = 0; i < k; i++) { int d = scanner.nextInt(); for (int j = 0; j < d; j++) { int person = scanner.nextInt(); if (!map.containsKey(person)) { map.put(person, new ArrayList<>()); } map.get(person).add(d); } } int count = 0; for (int i = 1; i <= n; i++) { if (!map.containsKey(i)) { count++; } } System.out.println(count); } }
[ { "input": "3 2\n2\n1 3\n1\n3\n", "output": "1\n" } ]
Java
codenet
s307170605
import java.io.*; import java.util.*; public class s307170605 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); for (int i = 0; i < 5; i++) { if (sc.nextInt() == 0) { System.out.println(i + 1); break; } } } }
[ { "input": "0 2 3 4 5\n", "output": "1\n" } ]
Java
codenet
s100570405
import static java.lang.System.out; import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class s100570405 { public static void main(String[] args) { new s100570405().run(); } MyInput in = new MyInput(); public void run() { String sd = in.next(); String T = in.next(); int count = 0; char c; boolean ok = false; int first = -1; int end = -1; for (int j = 0; j < sd.length(); j++) { count = 0; for (int i = 0; i + j < sd.length(); i++) { c = sd.charAt(i + j); if (c == '?' || c == T.charAt(count)) { count++; if (count == T.length()) { first = i + j - T.length() + 1; end = i + j; ok = true; break; } } else { count = 0; } } } if (ok) { for (int i = 0; i < sd.length(); i++) { if (first <= i && i <= end) { out.print(T.charAt(i - first)); } else { if (sd.charAt(i) == '?') { out.print("a"); } else { out.print(sd.charAt(i)); } } } out.println(); } else { out.println("UNRESTORABLE"); } } } class MyInput { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr; private int buflen; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } public int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) { ptr++; } } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } }
[ { "input": "?tc????\ncoder\n", "output": "atcoder\n" } ]
Java
codenet
s399184958
import java.util.*; class s399184958 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int B = sc.nextInt(); int C = sc.nextInt(); if (A == B && B == C && C == A) { System.out.println("Yes"); } else { System.out.println("No"); } } }
[ { "input": "2 2 2\n", "output": "Yes\n" } ]
Java
codenet
s888667117
import java.io.*; import java.util.*; import java.util.stream.*; public class s888667117 { public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); public static final PrintStream out = System.out; public static final PrintStream err = System.err; public static void main(String[] args) { String si = in.next(); char[] S = new StringBuilder(si).reverse().toString().toCharArray(); long[] dp = new long[13]; dp[0] = 1; for (int i = 0, d = 1; i < S.length; i++, d = d * 10 % 13) { long[] nd = new long[13]; err.println("d: " + d + ", i: " + i + ", S[i]: " + S[i]); char c = S[i]; if (Character.isDigit(c)) { int x = (c - '0') * d; for (int j = 0; j < 13; j++) { nd[(j + x) % 13] = dp[j]; } } else { for (int xi = 0; xi < 10; xi++) { int x = xi * d; for (int j = 0; j < 13; j++) { int ni = (j + x) % 13; nd[ni] = (nd[ni] + dp[j]) % 1000000007; } } } err.println(Arrays.toString(nd)); dp = nd; } out.println(dp[5]); } }
[ { "input": "??2??5\n", "output": "768\n" } ]
Java
codenet
s684030429
import java.io.*; import java.math.*; import java.util.*; public class s684030429 { Scanner sc; int max; int cur; void solve() { int a = ni(); int b = ni(); System.out.println(Math.max(0, a - 2 * b)); } s684030429() { try { sc = new Scanner(System.in); } catch (Exception e) { System.out.println(e); } } public static void main(String[] args) { new s684030429().solve(); } int ni() { return sc.nextInt(); } long nl() { return sc.nextLong(); } float nf() { return sc.nextFloat(); } double nd() { return sc.nextDouble(); } String ns() { return sc.nextLine(); } StringTokenizer nst(String s) { return new StringTokenizer(s); } void ia(int[] a) { for (int i = 0; i < a.length; i++) { a[i] = sc.nextInt(); } } void la(long[] a) { for (int i = 0; i < a.length; i++) { a[i] = sc.nextLong(); } } void fa(float[] a) { for (int i = 0; i < a.length; i++) { a[i] = sc.nextFloat(); } } void da(double[] a) { for (int i = 0; i < a.length; i++) { a[i] = sc.nextDouble(); } } void sa(String[] a, boolean empty) { if (empty) { for (int i = 0; i < a.length; i++) { a[i] = ""; } } else { for (int i = 0; i < a.length; i++) { a[i] = ns(); } } } void ida(int[][] a, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = ni(); } } } void lda(long[][] a, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nl(); } } } void dda(double[][] a, int n, int m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nd(); } } } int stoi(String s) { return Integer.parseInt(s); } double stod(String s) { return Double.parseDouble(s); } long lmin(long[] a) { long min = Long.MAX_VALUE; for (int i = 0; i < a.length; i++) { if (min > a[i]) { min = a[i]; } } return min; } int imin(int[] a) { int min = Integer.MAX_VALUE; for (int i = 0; i < a.length; i++) { if (min > a[i]) { min = a[i]; } } return min; } long lmax(long[] a) { long max = Long.MIN_VALUE; for (int i = 0; i < a.length; i++) { if (max < a[i]) { max = a[i]; } } return max; } int imax(int[] a) { int max = Integer.MIN_VALUE; for (int i = 0; i < a.length; i++) { if (max < a[i]) { max = a[i]; } } return max; } boolean ibs(int[] a, int toFind) { Arrays.sort(a); int min = 0; int max = a.length - 1; boolean found = false; while (min <= max && !found) { int mid = min + (max - min) / 2; if (a[mid] == toFind) { found = true; } else if (toFind > a[mid]) { min = mid + 1; } else { max = mid - 1; } } return found; } boolean lbs(long[] a, long toFind) { Arrays.sort(a); int min = 0; int max = a.length - 1; boolean found = false; while (min <= max && !found) { int mid = min + (max - min) / 2; if (a[mid] == toFind) { found = true; } else if (toFind > a[mid]) { min = mid + 1; } else { max = mid - 1; } } return found; } int stb(String s) { int sum = 0; int k = 0; for (int i = s.length() - 1; i >= 0; i--) { sum += stoi(s.charAt(i) + "") * Math.pow(2, k++); } return sum; } }
[ { "input": "12 4\n", "output": "4\n" } ]
Java
codenet
s799002881
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; public class s799002881 { public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); String[] str = in.readLine().split(" "); int n = Integer.parseInt(str[0]); double d = Integer.parseInt(str[1]); int cnt = 0; for (int i = 0; i < n; i++) { str = in.readLine().split(" "); double x = Integer.parseInt(str[0]); double y = Integer.parseInt(str[1]); if (Math.sqrt(x * x + y * y) <= d) { cnt++; } } System.out.println(cnt); } }
[ { "input": "4 5\n0 5\n-2 4\n3 4\n4 -4\n", "output": "3\n" } ]
Java
codenet
s514557145
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; public class s514557145 { static final long MOD1 = 1000000007; static final long MOD2 = 998244353; static long[] tenmod; static final long inv9 = modInv(9); public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); InputReader sc = new InputReader(System.in); int N = sc.nextInt(); int Q = sc.nextInt(); tenmod = new long[N + 1]; tenmod[0] = 1; for (int j = 1; j <= N; j++) { tenmod[j] = (tenmod[j - 1] * 10L) % MOD2; } S[] dat = new S[N]; Arrays.setAll(dat, i -> new S(tenmod[N - i - 1], i, i)); LazySegTree<S, F> lazySegTree = new LazySegTree<>(dat, S::op, S.E, S::map, F::composite, F.I); for (int j = 0; j < Q; j++) { int l = sc.nextInt() - 1; int r = sc.nextInt() - 1; long D = sc.nextLong(); lazySegTree.apply(l, r + 1, new F(D, N)); out.println(lazySegTree.allProd().sum); } out.flush(); } static class S { static final S E = new S(0, Integer.MAX_VALUE / 2, Integer.MIN_VALUE / 2); long sum; int l; int r; public S(long sum, int l, int r) { super(); this.sum = sum; this.l = l; this.r = r; } public static S op(S s1, S s2) { long sum = s1.sum + s2.sum; if (sum >= MOD2) { sum -= MOD2; } return new S(sum, Math.min(s1.l, s2.l), Math.max(s1.r, s2.r)); } static S map(F f, S s) { long c = tenmod[(f.N - s.l)] - tenmod[(f.N - s.r - 1)]; if (c < 0) { c += MOD2; } return new S(((f.D * c) % MOD2 * inv9) % MOD2, s.l, s.r); } } static class F { static final F I = new F(0, 0); long D; int N; public F(long D, int N) { super(); this.D = D; this.N = N; } public static F composite(F f, F g) { return new F(f.D, f.N); } } static long modInv(long x) { return modPow(x, MOD2 - 2); } static long modPow(long x, long y) { long z = 1; while (y > 0) { if (y % 2 == 0) { x = (x * x) % MOD2; y /= 2; } else { z = (z * x) % MOD2; y--; } } return z; } static class LazySegTree<S, F> { final int MAX; final int N; final int Log; final java.util.function.BinaryOperator<S> Op; final S E; final java.util.function.BiFunction<F, S, S> Mapping; final java.util.function.BinaryOperator<F> Composition; final F Id; final S[] Dat; final F[] Laz; @SuppressWarnings("unchecked") public LazySegTree( int n, java.util.function.BinaryOperator<S> op, S e, java.util.function.BiFunction<F, S, S> mapping, java.util.function.BinaryOperator<F> composition, F id) { this.MAX = n; int k = 1; while (k < n) { k <<= 1; } this.N = k; this.Log = Integer.numberOfTrailingZeros(N); this.Op = op; this.E = e; this.Mapping = mapping; this.Composition = composition; this.Id = id; this.Dat = (S[]) new Object[N << 1]; this.Laz = (F[]) new Object[N]; java.util.Arrays.fill(Dat, E); java.util.Arrays.fill(Laz, Id); } public LazySegTree( S[] dat, java.util.function.BinaryOperator<S> op, S e, java.util.function.BiFunction<F, S, S> mapping, java.util.function.BinaryOperator<F> composition, F id) { this(dat.length, op, e, mapping, composition, id); build(dat); } private void build(S[] dat) { int l = dat.length; System.arraycopy(dat, 0, Dat, N, l); for (int i = N - 1; i > 0; i--) { Dat[i] = Op.apply(Dat[i << 1 | 0], Dat[i << 1 | 1]); } } private void push(int k) { if (Laz[k] == Id) { return; } int lk = k << 1 | 0; int rk = k << 1 | 1; Dat[lk] = Mapping.apply(Laz[k], Dat[lk]); Dat[rk] = Mapping.apply(Laz[k], Dat[rk]); if (lk < N) { Laz[lk] = Composition.apply(Laz[k], Laz[lk]); } if (rk < N) { Laz[rk] = Composition.apply(Laz[k], Laz[rk]); } Laz[k] = Id; } private void pushTo(int k) { for (int i = Log; i > 0; i--) { push(k >> i); } } private void pushTo(int lk, int rk) { for (int i = Log; i > 0; i--) { if (((lk >> i) << i) != lk) { push(lk >> i); } if (((rk >> i) << i) != rk) { push(rk >> i); } } } private void updateFrom(int k) { k >>= 1; while (k > 0) { Dat[k] = Op.apply(Dat[k << 1 | 0], Dat[k << 1 | 1]); k >>= 1; } } private void updateFrom(int lk, int rk) { for (int i = 1; i <= Log; i++) { if (((lk >> i) << i) != lk) { int lki = lk >> i; Dat[lki] = Op.apply(Dat[lki << 1 | 0], Dat[lki << 1 | 1]); } if (((rk >> i) << i) != rk) { int rki = (rk - 1) >> i; Dat[rki] = Op.apply(Dat[rki << 1 | 0], Dat[rki << 1 | 1]); } } } public void set(int p, S x) { exclusiveRangeCheck(p); p += N; pushTo(p); Dat[p] = x; updateFrom(p); } public S get(int p) { exclusiveRangeCheck(p); p += N; pushTo(p); return Dat[p]; } public S allProd() { return Dat[1]; } public void apply(int p, F f) { exclusiveRangeCheck(p); p += N; pushTo(p); Dat[p] = Mapping.apply(f, Dat[p]); updateFrom(p); } public void apply(int l, int r, F f) { if (l > r) { throw new IllegalArgumentException(String.format("Invalid range: [%d, %d)", l, r)); } inclusiveRangeCheck(l); inclusiveRangeCheck(r); if (l == r) { return; } l += N; r += N; pushTo(l, r); for (int l2 = l, r2 = r; l2 < r2; ) { if ((l2 & 1) == 1) { Dat[l2] = Mapping.apply(f, Dat[l2]); if (l2 < N) { Laz[l2] = Composition.apply(f, Laz[l2]); } l2++; } if ((r2 & 1) == 1) { r2--; Dat[r2] = Mapping.apply(f, Dat[r2]); if (r2 < N) { Laz[r2] = Composition.apply(f, Laz[r2]); } } l2 >>= 1; r2 >>= 1; } updateFrom(l, r); } public int maxRight(int l, java.util.function.Predicate<S> g) { inclusiveRangeCheck(l); if (!g.test(E)) { throw new IllegalArgumentException("Identity element must satisfy the condition."); } if (l == MAX) { return MAX; } l += N; pushTo(l); S sum = E; do { l >>= Integer.numberOfTrailingZeros(l); if (!g.test(Op.apply(sum, Dat[l]))) { while (l < N) { push(l); l = l << 1; if (g.test(Op.apply(sum, Dat[l]))) { sum = Op.apply(sum, Dat[l]); l++; } } return l - N; } sum = Op.apply(sum, Dat[l]); l++; } while ((l & -l) != l); return MAX; } public int minLeft(int r, java.util.function.Predicate<S> g) { inclusiveRangeCheck(r); if (!g.test(E)) { throw new IllegalArgumentException("Identity element must satisfy the condition."); } if (r == 0) { return 0; } r += N; pushTo(r - 1); S sum = E; do { r--; while (r > 1 && (r & 1) == 1) { r >>= 1; } if (!g.test(Op.apply(Dat[r], sum))) { while (r < N) { push(r); r = r << 1 | 1; if (g.test(Op.apply(Dat[r], sum))) { sum = Op.apply(Dat[r], sum); r--; } } return r + 1 - N; } sum = Op.apply(Dat[r], sum); } while ((r & -r) != r); return 0; } private void exclusiveRangeCheck(int p) { if (p < 0 || p >= MAX) { throw new IndexOutOfBoundsException( String.format("Index %d is not in [%d, %d).", p, 0, MAX)); } } private void inclusiveRangeCheck(int p) { if (p < 0 || p > MAX) { throw new IndexOutOfBoundsException( String.format("Index %d is not in [%d, %d].", p, 0, MAX)); } } private int indent = 6; public void setIndent(int newIndent) { this.indent = newIndent; } @Override public String toString() { return toString(1, 0); } private String toString(int k, int sp) { if (k >= N) { return indent(sp) + Dat[k]; } String s = ""; s += toString(k << 1 | 1, sp + indent); s += "\n"; s += indent(sp) + Dat[k] + "/" + Laz[k]; s += "\n"; s += toString(k << 1 | 0, sp + indent); return s; } private static String indent(int n) { StringBuilder sb = new StringBuilder(); while (n-- > 0) { sb.append(' '); } return sb.toString(); } } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte() { if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) { return buffer[curbuf++]; } else { return -1; } } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private void skip() { while (hasNextByte() && isSpaceChar(buffer[curbuf])) { curbuf++; } } public boolean hasNext() { skip(); return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { if (!hasNext()) { throw new NoSuchElementException(); } int c = readByte(); while (isSpaceChar(c)) { c = readByte(); } boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return minus ? -res : res; } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } int c = readByte(); while (isSpaceChar(c)) { c = readByte(); } boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return minus ? -res : res; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public char[][] nextCharMap(int n, int m) { char[][] map = new char[n][m]; for (int i = 0; i < n; i++) { map[i] = next().toCharArray(); } return map; } } }
[ { "input": "8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1\n", "output": "11222211\n77772211\n77333333\n72333333\n72311333\n" } ]
Java
codenet
s629237879
import java.io.*; import java.util.Arrays; public class s629237879 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String sc = br.readLine(); int n = Integer.parseInt(sc); String[] str = new String[n]; for (int i = 0; i < n; i++) { str[i] = br.readLine(); } String[] mark = {"S", "H", "C", "D"}; for (String ma : mark) { for (int i = 1; i <= 13; i++) { String s = Integer.toString(i); String st = ma + " " + s; if (!Arrays.asList(str).contains(st)) { System.out.println(st); } } } } }
[ { "input": "47\nS 10\nS 11\nS 12\nS 13\nH 1\nH 2\nS 6\nS 7\nS 8\nS 9\nH 6\nH 8\nH 9\nH 10\nH 11\nH 4\nH 5\nS 2\nS 3\nS 4\nS 5\nH 12\nH 13\nC 1\nC 2\nD 1\nD 2\nD 3\nD 4\nD 5\nD 6\nD 7\nC 3\nC 4\nC 5\nC 6\nC 7\nC 8\nC 9\nC 10\nC 11\nC 13\nD 9\nD 10\nD 11\nD 12\nD 13\n", "output": "S 1\nH 3\nH 7\nC 12\nD 8\n" } ]
Java
codenet
s749703010
import java.io.*; import java.util.*; public class s749703010 { static class Pair { int l; int r; Pair(int a, int b) { l = a; r = b; } @Override public String toString() { return l + " " + r; } } static int[][][] memo; static int[][] a; static int n; static int dp(int fliped, int idx, int msk) { if (msk == (1 << n) - 1) { return 0; } if (memo[fliped][idx][msk] != -1) { return memo[fliped][idx][msk]; } int x = Integer.bitCount(msk); int ff = 0; int ans = (int) 1e9; for (int i = 0; i < n; i++) { if ((msk & (1 << i)) == 0) { int nf = x % 2; if (idx == n || a[fliped][idx] <= a[(nf + (ff % 2)) % 2][i]) { ans = Math.min(ans, ff + dp((nf + (ff % 2)) % 2, i, msk | 1 << i)); } ff++; } else { x--; } } return memo[fliped][idx][msk] = ans; } public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); n = sc.nextInt(); a = new int[2][n]; for (int i = 0; i < n; i++) { a[0][i] = sc.nextInt(); } for (int i = 0; i < n; i++) { a[1][i] = sc.nextInt(); } memo = new int[2][n + 1][1 << n]; for (int[][] z : memo) for (int[] x : z) Arrays.fill(x, -1); int ans = dp(0, n, 0); pw.println(ans >= 1e8 ? -1 : ans); pw.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0; double f = 1; boolean dec = false; boolean neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) { if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) { f *= 10; } } } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } }
[ { "input": "3\n3 4 3\n3 2 3\n", "output": "1\n" } ]
Java
codenet
s301480578
import java.util.Scanner; public class s301480578 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] h = new int[n]; for (int i = 0; i < n; i++) { h[i] = sc.nextInt(); } int max = 0; for (int l = 0; l < n - 1; l++) { int count = 0; while (l < n - 1 && h[l] >= h[l + 1]) { l++; count++; } max = Math.max(max, count); } System.out.println(max); } }
[ { "input": "5\n10 4 8 7 3\n", "output": "2\n" } ]
Java
codenet
s196249385
import java.io.*; import java.util.*; public class s196249385 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } long[] cumsum = new long[n + 1]; for (int i = 0; i < n; i++) { cumsum[i + 1] = cumsum[i] + a[i]; } List<Long> b = new ArrayList<>(n * (n + 1) / 2); long max = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { b.add(cumsum[j + 1] - cumsum[i]); max = Math.max(max, cumsum[j + 1] - cumsum[i]); } } long mask = Long.highestOneBit(max); while (mask > 0) { List<Long> tmp = new ArrayList<>(); for (long e : b) { if ((e & mask) != 0) { tmp.add(e); } } if (tmp.size() >= k) { b = tmp; } mask >>= 1; } if (b.size() < k) { pr.println(0); } else { long ans = -1L; for (long e : b) { ans &= e; } pr.println(ans); } } public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }
[ { "input": "4 2\n2 5 2 5\n", "output": "12\n" } ]
Java
codenet
s918182055
import java.io.*; import java.util.*; public class s918182055 { public static void main(String[] args) { MyWriter out = new MyWriter(System.out); MyScanner sc = new MyScanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); LinkedList<Integer>[] list = new LinkedList[100001]; for (int i = 0; i < N; i++) { int a = sc.nextInt(); int b = sc.nextInt(); if (list[a] == null) { list[a] = new LinkedList<>(); } list[a].add(b); } int res = 0; PriorityQueue<Integer> pqueue = new PriorityQueue<>(Collections.reverseOrder()); for (int i = 1; i <= M; i++) { if (list[i] != null) { pqueue.addAll(list[i]); } if (!pqueue.isEmpty()) { res += pqueue.poll(); } } out.println(res); out.flush(); } static final class MyScanner { static final int BUFFER_SIZE = 8192; private final InputStream in; private final byte[] buffer = new byte[BUFFER_SIZE]; private int point; private int readLength; MyScanner(InputStream in) { this.in = in; } private int readByte() { if (point < readLength) { int result = buffer[point]; point += 1; return result; } try { readLength = in.read(buffer); } catch (IOException e) { throw new AssertionError(null, e); } if (readLength == -1) { return -1; } point = 1; return buffer[0]; } private static boolean isPrintableCharExceptSpace(int c) { return 33 <= c && c <= 126; } String next() { int c = readByte(); while (!(c == -1 || isPrintableCharExceptSpace(c))) { c = readByte(); } if (c == -1) { throw new NoSuchElementException(); } StringBuilder b = new StringBuilder(); do { b.appendCodePoint(c); c = readByte(); } while (c != -1 && isPrintableCharExceptSpace(c)); return b.toString(); } long nextLong() { int c = readByte(); while (!(c == -1 || isPrintableCharExceptSpace(c))) { c = readByte(); } if (c == -1) { throw new NoSuchElementException(); } boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long result = 0L; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } result = result * 10L + (c - '0'); c = readByte(); } while (c != -1 && isPrintableCharExceptSpace(c)); return minus ? -result : result; } int nextInt() { long n = nextLong(); if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE) { throw new InputMismatchException(); } return (int) n; } double nextDouble() { return Double.parseDouble(next()); } int[] nextIntArray(int n) { int[] result = new int[n]; for (int i = 0; i < n; i++) { result[i] = nextInt(); } return result; } private static boolean allSameLength(int[] a, int[] b, int[]... c) { if (a.length != b.length) { return false; } for (int[] element : c) { if (a.length != element.length) { return false; } } return true; } private static boolean allSameLength(char[] a, char[] b, char[]... c) { if (a.length != b.length) { return false; } for (char[] element : c) { if (a.length != element.length) { return false; } } return true; } void nextVerticalIntArrays(int[] a, int[] b, int[]... c) { if (!allSameLength(a, b, c)) { throw new IllegalArgumentException(); } for (int i = 0; i < a.length; i++) { a[i] = nextInt(); b[i] = nextInt(); for (int[] d : c) { d[i] = nextInt(); } } } long[] nextLongArray(int n) { long[] result = new long[n]; for (int i = 0; i < n; i++) { result[i] = nextLong(); } return result; } char nextChar() { int c = readByte(); while (!(c == -1 || isPrintableCharExceptSpace(c))) { c = readByte(); } if (c == -1) { throw new NoSuchElementException(); } return (char) c; } char[] nextCharArray(int n) { char[] result = new char[n]; for (int i = 0; i < n; i++) { result[i] = nextChar(); } return result; } char[][] next2dCharArray(int n, int m) { char[][] result = new char[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { result[i][j] = nextChar(); } } return result; } void nextVerticalCharArrays(char[] a, char[] b, char[]... c) { if (!allSameLength(a, b, c)) { throw new IllegalArgumentException(); } for (int i = 0; i < a.length; i++) { a[i] = nextChar(); b[i] = nextChar(); for (char[] d : c) { d[i] = nextChar(); } } } } static final class MyWriter extends PrintWriter { MyWriter(OutputStream out) { super(out); } void joinAndPrintln(int[] x) { joinAndPrintln(x, " "); } void joinAndPrintln(int[] x, String delimiter) { StringBuilder b = new StringBuilder(); if (x.length > 0) { b.append(x[0]); for (int i = 1; i < x.length; i++) { b.append(delimiter).append(x[i]); } } println(b.toString()); } void joinAndPrintln(long[] x) { joinAndPrintln(x, " "); } void joinAndPrintln(long[] x, String delimiter) { StringBuilder b = new StringBuilder(); if (x.length > 0) { b.append(x[0]); for (int i = 1; i < x.length; i++) { b.append(delimiter).append(x[i]); } } println(b.toString()); } void joinAndPrintln(Iterable<?> iterable) { joinAndPrintln(iterable, " "); } void joinAndPrintln(Iterable<?> iterable, String delimiter) { StringBuilder b = new StringBuilder(); for (Iterator<?> i = iterable.iterator(); i.hasNext(); ) { b.append(i.next()); while (i.hasNext()) { b.append(delimiter).append(i.next()); } } println(b.toString()); } } }
[ { "input": "3 4\n4 3\n4 1\n2 2\n", "output": "5\n" } ]
Java
codenet
s192812966
import java.util.Scanner; public class s192812966 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int w = scanner.nextInt(); int h = scanner.nextInt(); int n = scanner.nextInt(); int[] x = new int[n]; int[] y = new int[n]; int[] a = new int[n]; int xmax = w; int xmin = 0; int ymax = h; int ymin = 0; for (int i = 0; i < n; i++) { x[i] = scanner.nextInt(); y[i] = scanner.nextInt(); a[i] = scanner.nextInt(); switch (a[i]) { case 1: xmin = Math.max(xmin, x[i]); break; case 2: xmax = Math.min(xmax, x[i]); break; case 3: ymin = Math.max(ymin, y[i]); break; case 4: ymax = Math.min(ymax, y[i]); break; } } w = Math.max(xmax - xmin, 0); h = Math.max(ymax - ymin, 0); System.out.println(w * h); } }
[ { "input": "5 4 2\n2 1 1\n3 3 4\n", "output": "9\n" } ]
Java
codenet
s561914763
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class s561914763 { static Set<String> ODD = new HashSet<>(); static Set<String> EVE = new HashSet<>(); static { ODD.add("R"); ODD.add("U"); ODD.add("D"); EVE.add("L"); EVE.add("U"); EVE.add("D"); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String N = sc.nextLine(); char[] tap = N.toCharArray(); boolean isGood = true; for (int i = 0; i < N.length(); i++) { if ((i + 1) % 2 == 0) { if (!isMatch(EVE, tap[i])) { isGood = false; break; } } else { if (!isMatch(ODD, tap[i])) { isGood = false; break; } } } System.out.println(isGood ? "Yes" : "No"); } private static boolean isMatch(Set<String> set, char c) { return set.contains(String.valueOf(c)); } }
[ { "input": "RUDLUDR\n", "output": "Yes\n" } ]
Java
codenet
s442273167
import java.util.Scanner; public class s442273167 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] l = new int[n]; int[] r = new int[n]; for (int i = 0; i < n; i++) { l[i] = sc.nextInt(); r[i] = sc.nextInt(); } int sum = 0; for (int i = 0; i < n; i++) { sum += r[i] - l[i] + 1; } System.out.println(sum); } }
[ { "input": "1\n24 30\n", "output": "7\n" } ]
Java
codenet
s440824480
import java.util.*; class s440824480 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int c = 0; int flg = 0; while (n-- > 0) { int x = sc.nextInt(); int y = sc.nextInt(); if (x == y) { c++; if (c >= 3) { flg = 1; } } else { c = 0; } } if (flg == 0) { System.out.println("No"); } else { System.out.println("Yes"); } } }
[ { "input": "5\n1 2\n6 6\n4 4\n3 3\n3 2\n", "output": "Yes\n" } ]
Java
codenet
s481865042
import java.util.Scanner; public class s481865042 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); long k = sc.nextLong(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { if ((26 - (s.charAt(i) - 'a')) <= k && s.charAt(i) != 'a') { k -= 26 - (s.charAt(i) - 'a'); sb.append('a'); } else { sb.append(s.charAt(i)); } } if (k > 0) { char t = sb.charAt(s.length() - 1); sb.delete(s.length() - 1, s.length()); sb.append((char) ('a' + (t - 'a' + k) % 26)); } System.out.println(sb); } }
[ { "input": "xyz\n4\n", "output": "aya\n" } ]
Java
codenet
s443066739
import java.io.*; import java.math.*; import java.util.*; import java.util.concurrent.*; class s443066739 { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static FastScanner sc = new FastScanner(br); static PrintWriter out = new PrintWriter(System.out); static Random rnd = new Random(); public static void main(String[] args) throws Exception { int n = sc.nextInt(); long[] pre = new long[n + 1]; for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + sc.nextLong(); } long min = Long.MAX_VALUE; for (int i = 1; i < n; i++) { long val1 = pre[i]; long val2 = pre[n] - pre[i]; min = Math.min(min, Math.abs(val1 - val2)); } out.println(min); out.close(); } } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public String next() throws Exception { return nextToken().toString(); } 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()); } }
[ { "input": "6\n1 2 3 4 5 6\n", "output": "1\n" } ]
Java
codenet
s960387817
import java.util.HashSet; import java.util.Scanner; import java.util.Set; import java.util.stream.IntStream; public class s960387817 { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { int n = scanner.nextInt(); Set<Integer> set = new HashSet<>(); IntStream.range(0, n).forEach(i -> set.add(scanner.nextInt())); System.out.println(set.size()); } } }
[ { "input": "4\n10\n8\n8\n6\n", "output": "3\n" } ]
Java
codenet
s832608243
import java.util.Scanner; public class s832608243 { public static void main(final String[] args) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); int b = scanner.nextInt(); boolean flag = false; for (int i = 1; i <= 100000; i++) { if (Math.floor(1. * i * .08) == a && b == Math.floor(.1 * i)) { System.out.println(i); flag = true; break; } } if (!flag) { System.out.println(-1); } } }
[ { "input": "2 2\n", "output": "25\n" } ]
Java
codenet
s336166208
public class s336166208 { public static void main(String[] args) { int[][][] info = new int[4][3][10]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 10; k++) { info[i][j][k] = 0; } } } java.util.Scanner sc = new java.util.Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { int built = sc.nextInt(); int floor = sc.nextInt(); int room = sc.nextInt(); int num = sc.nextInt(); info[built - 1][floor - 1][room - 1] += num; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 10; k++) { System.out.print(" " + info[i][j][k]); } System.out.print("\n"); } if (i != 4 - 1) { System.out.print("####################\n"); } } } }
[ { "input": "3\n1 1 3 8\n3 2 2 7\n4 3 8 1\n", "output": " 0 0 8 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0\n####################\n 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0\n####################\n 0 0 0 0 0 0 0 0 0 0\n 0 7 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0\n####################\n 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0\n" } ]
Java
codenet
s416486483
import java.util.*; public class s416486483 { private static long split(long n, long k) { long sum = 0; while (n > 0) { sum += n % k; n /= k; } return sum; } private static long solve(long n, long s) { long k; for (k = 2; k * k <= n || k < 100; k++) { if (split(n, k) == s) { return k; } } while (k <= n) { long a = n / k; long b = n % k; if ((a + b - s) % a == 0) { long dk = (a + b - s) / a; if (dk >= 0 && b - dk * a >= 0) { return k + dk; } } k = n / a + 1; } if (n == s) { return n + 1; } return -1; } public static void main(String[] args) { Scanner s = new Scanner(System.in); long nl = s.nextLong(); long sl = s.nextLong(); System.out.println(solve(nl, sl)); } }
[ { "input": "87654\n30\n", "output": "10\n" } ]
Java
codenet
s821112618
import java.util.Scanner; class s821112618 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] s = ".,!? :abc:def:ghi:jkl:mno:pqrs:tuv:wxyz".split(":"); char[][] k = new char[9][]; for (int i = 0; i < 9; i++) { k[i] = s[i].toCharArray(); } while (n-- > 0) { char[] c = sc.next().toCharArray(); int l = -1; int a = 0; for (int i = 0; i < c.length; i++) { if (c[i] != '0') { a = c[i] - '1'; l = (l + 1) % k[a].length; } else if (l >= 0) { System.out.print(k[a][l]); l = -1; } } System.out.println(); } } }
[ { "input": "5\n20\n220\n222220\n44033055505550666011011111090666077705550301110\n000555555550000330000444000080000200004440000\n", "output": "a\nb\nb\nhello, world!\nkeitai\n" } ]
Java
codenet
s452855095
import java.io.PrintWriter; import java.util.Scanner; public class s452855095 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int cnt = 0; boolean flag = true; while (true) { for (int i = 0; i < n; i++) { if (arr[i] % 2 != 0) { flag = false; break; } else { arr[i] = arr[i] / 2; } } if (flag) { cnt++; } else { break; } } out.println(cnt); out.flush(); } }
[ { "input": "3\n8 12 40\n", "output": "2\n" } ]
Java
codenet
s916993080
import java.io.*; import java.util.*; public class s916993080 { public static void main(String[] args) throws IOException { int n = sc.nextInt(); int[][] arr = new int[n][3]; for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2; ++j) { arr[i][j] = sc.nextInt(); } } int[][] dp = new int[n][3]; dp[0][0] = arr[0][0]; dp[0][1] = arr[0][1]; dp[0][2] = arr[0][2]; for (int i = 1; i < n; ++i) { for (int j = 0; j < 3; ++j) { if (j == 0) { dp[i][j] = Math.max(arr[i][0] + dp[i - 1][1], arr[i][0] + dp[i - 1][2]); } if (j == 1) { dp[i][j] = Math.max(arr[i][1] + dp[i - 1][0], arr[i][1] + dp[i - 1][2]); } if (j == 2) { dp[i][j] = Math.max(arr[i][2] + dp[i - 1][1], arr[i][2] + dp[i - 1][0]); } } } int max = -1; for (int i = 0; i < 3; ++i) { if (dp[n - 1][i] > max) { max = dp[n - 1][i]; } } System.out.println(max); } } class sc { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer tokenizer = new StringTokenizer(""); static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static float nextFloat() throws IOException { return Float.parseFloat(next()); } }
[ { "input": "3\n10 40 70\n20 50 80\n30 60 90\n", "output": "210\n" } ]
Java
codenet
s577060895
import java.util.Scanner; public class s577060895 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = Long.parseLong(sc.nextLine()); double sqrt = Math.sqrt(n); double nearNum = Math.floor(sqrt); long ans = (long) Math.pow(nearNum, 2); System.out.println(ans); sc.close(); } }
[ { "input": "10\n", "output": "9\n" } ]
Java
codenet
s681118763
import java.util.Scanner; public class s681118763 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String c = in.next(); Character letter = c.charAt(0); letter++; System.out.println(letter); } }
[ { "input": "a\n", "output": "b\n" } ]
Java
codenet
s321983475
import java.util.*; public class s321983475 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); int answer = Math.max(a, b) - Math.min(a, b) - w; if (answer < 0) { System.out.println(0); } else { System.out.println(answer); } } }
[ { "input": "3 2 6\n", "output": "1\n" } ]
Java
codenet
s933313035
import java.util.Scanner; public class s933313035 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); Node tree = null; for (int i = 0; i < m; i++) { String command = sc.next(); if ("insert".equals(command)) { long key = sc.nextLong(); if (tree == null) { tree = new Node(); tree.value = key; } else { tree.insert(key); } } else { if (tree != null) { tree.printInOrder(); System.out.println(); tree.printPreOrder(); System.out.println(); } } } } static class Node { long value; Node left; Node right; void insert(long newValue) { if (newValue < this.value) { if (left == null) { left = new Node(); left.value = newValue; } else { left.insert(newValue); } } else { if (right == null) { right = new Node(); right.value = newValue; } else { right.insert(newValue); } } } void printInOrder() { if (left != null) { left.printInOrder(); } System.out.print(" " + value); if (right != null) { right.printInOrder(); } } void printPreOrder() { System.out.print(" " + value); if (left != null) { left.printPreOrder(); } if (right != null) { right.printPreOrder(); } } } }
[ { "input": "8\ninsert 30\ninsert 88\ninsert 12\ninsert 1\ninsert 20\ninsert 17\ninsert 25\nprint\n", "output": " 1 12 17 20 25 30 88\n 30 12 1 20 17 25 88\n" } ]
Java
codenet
s257593977
import java.util.Scanner; public class s257593977 { private static final int BASE = 3; public static void main(String[] args) { System.out.println((int) Math.pow(new Scanner(System.in).nextInt(), BASE)); } }
[ { "input": "2\n", "output": "8\n" } ]
Java
codenet
s081988820
import java.io.IOException; import java.io.InputStream; import java.util.*; import java.util.stream.IntStream; public class s081988820 { public static void main(String[] args) { s081988820 main = new s081988820(); main.solve(); } private void solve() { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); int[][] c = new int[10][10]; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { c[i][j] = sc.nextInt(); } } int[] min = new int[10]; for (int i = 0; i < 10; i++) { min[i] = c[i][1]; } for (int tc = 0; tc < 10; tc++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { min[i] = Math.min(min[i], c[i][j] + min[j]); } } } int ans = 0; for (int h = 1; h <= H; h++) { for (int w = 1; w <= W; w++) { int A = sc.nextInt(); if (A >= 0) { ans += min[A]; } } } System.out.println(ans); } class Scanner { private InputStream in; private byte[] buffer = new byte[1024]; private int index; private int length; public Scanner(InputStream in) { this.in = in; } private boolean isPrintableChar(int c) { return '!' <= c && c <= '~'; } private boolean isDigit(int c) { return '0' <= c && c <= '9'; } private boolean hasNextByte() { if (index < length) { return true; } else { try { length = in.read(buffer); index = 0; } catch (IOException e) { e.printStackTrace(); } return length > 0; } } private boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[index])) { index++; } return hasNextByte(); } private int readByte() { return hasNextByte() ? buffer[index++] : -1; } public String next() { if (!hasNext()) { throw new RuntimeException("no input"); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new RuntimeException("no input"); } long value = 0L; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } while (isPrintableChar(b)) { if (isDigit(b)) { value = value * 10 + (b - '0'); } b = readByte(); } return minus ? -value : value; } public int nextInt() { return (int) nextLong(); } public double nextDouble() { return Double.parseDouble(next()); } } interface CombCalculator { long comb(int n, int m); } interface MobiusFunction { int get(int n); } class SieveMobiusFunction implements MobiusFunction { int size; int[] mobiusFunctionValues; public SieveMobiusFunction(int size) { this.size = size; mobiusFunctionValues = new int[size]; mobiusFunctionValues[0] = 0; mobiusFunctionValues[1] = 1; for (int i = 2; i < size; i++) { mobiusFunctionValues[i] = 1; } for (int i = 2; i * i < size; i++) { for (int k = 1; i * i * k < size; k++) { mobiusFunctionValues[i * i * k] *= 0; } } for (int i = 2; i < size; i++) { if (mobiusFunctionValues[i] == 1) { for (int k = 1; i * k < size; k++) { mobiusFunctionValues[i * k] *= -2; } } if (mobiusFunctionValues[i] > 1) { mobiusFunctionValues[i] = 1; } if (mobiusFunctionValues[i] < -1) { mobiusFunctionValues[i] = -1; } } } @Override public int get(int n) { if (n > size) { throw new RuntimeException("n is greater than size."); } if (n < 0) { return 0; } return mobiusFunctionValues[n]; } } class PrimeFactorizationMobiusFunction implements MobiusFunction { @Override public int get(int n) { if (n <= 0) { return 0; } if (n == 1) { return 1; } int num = 0; for (int i = 2; i < n; i++) { if (n % i == 0) { n /= i; num++; if (n % i == 0) { return 0; } } } return num % 2 == 0 ? -1 : 1; } } class FactorialTableCombCalculator implements CombCalculator { int size; long[] factorialTable; long[] inverseFactorialTable; long mod; public FactorialTableCombCalculator(int size, long mod) { this.size = size; factorialTable = new long[size + 1]; inverseFactorialTable = new long[size + 1]; this.mod = mod; factorialTable[0] = 1L; for (int i = 1; i <= size; i++) { factorialTable[i] = (factorialTable[i - 1] * i) % mod; } inverseFactorialTable[size] = inverse(factorialTable[size], mod); for (int i = size - 1; i >= 0; i--) { inverseFactorialTable[i] = (inverseFactorialTable[i + 1] * (i + 1)) % mod; } } private long inverse(long n, long mod) { return pow(n, mod - 2, mod); } private long pow(long n, long p, long mod) { if (p == 0) { return 1L; } long half = pow(n, p / 2, mod); long ret = (half * half) % mod; if (p % 2 == 1) { ret = (ret * n) % mod; } return ret; } @Override public long comb(int n, int m) { if (n > size) { throw new RuntimeException("n is greater than size."); } if (n < 0 || m < 0 || n < m) { return 0L; } return (((factorialTable[n] * inverseFactorialTable[m]) % mod) * inverseFactorialTable[n - m]) % mod; } } class TableCombCalculator implements CombCalculator { long[][] table; int size; public TableCombCalculator(int size, long mod) { this.size = size; table = new long[size + 1][]; table[0] = new long[1]; table[0][0] = 1L; for (int n = 1; n <= size; n++) { table[n] = new long[n + 1]; table[n][0] = 1L; for (int m = 1; m < n; m++) { table[n][m] = (table[n - 1][m - 1] + table[n - 1][m]) % mod; } table[n][n] = 1L; } } @Override public long comb(int n, int m) { if (n > size) { throw new RuntimeException("n is greater than size."); } if (n < 0 || m < 0 || n < m) { return 0L; } return table[n][m]; } } interface Graph { void link(int from, int to, long cost); Optional<Long> getCost(int from, int to); int getVertexNum(); } interface FlowResolver { long maxFlow(int from, int to); } class ArrayGraph implements Graph { private Long[][] costArray; private int vertexNum; public ArrayGraph(int n) { costArray = new Long[n][]; for (int i = 0; i < n; i++) { costArray[i] = new Long[n]; } vertexNum = n; } @Override public void link(int from, int to, long cost) { costArray[from][to] = Long.valueOf(cost); } @Override public Optional<Long> getCost(int from, int to) { return Optional.ofNullable(costArray[from][to]); } @Override public int getVertexNum() { return vertexNum; } } class DfsFlowResolver implements FlowResolver { private Graph graph; public DfsFlowResolver(Graph graph) { this.graph = graph; } public long maxFlow(int from, int to) { long sum = 0L; long currentFlow; do { currentFlow = flow(from, to, Long.MAX_VALUE / 3, new boolean[graph.getVertexNum()]); sum += currentFlow; } while (currentFlow > 0); return sum; } private long flow(int from, int to, long current_flow, boolean[] passed) { passed[from] = true; if (from == to) { return current_flow; } for (int id = 0; id < graph.getVertexNum(); id++) { if (passed[id]) { continue; } Optional<Long> cost = graph.getCost(from, id); if (cost.orElse(0L) > 0) { long nextFlow = current_flow < cost.get() ? current_flow : cost.get(); long returnFlow = flow(id, to, nextFlow, passed); if (returnFlow > 0) { graph.link(from, id, cost.get() - returnFlow); graph.link(id, from, graph.getCost(id, from).orElse(0L) + returnFlow); return returnFlow; } } } return 0L; } } class BinaryIndexedTree { private long[] array; public BinaryIndexedTree(int size) { this.array = new long[size + 1]; } public void add(int index, long value) { for (int i = index; i < array.length; i += i & -i) { array[i] += value; } } public long getSum(int index) { long sum = 0L; for (int i = index; i > 0; i -= i & -i) { sum += array[i]; } return sum; } } class BinaryIndexedTree2D { private long[][] array; public BinaryIndexedTree2D(int size1, int size2) { this.array = new long[size1 + 1][]; for (int i = 1; i <= size1; i++) { this.array[i] = new long[size2 + 1]; } } public void add(int index1, int index2, long value) { for (int i1 = index1; i1 < array.length; i1 += i1 & -i1) { for (int i2 = index2; i2 < array.length; i2 += i2 & -i2) { array[i1][i2] += value; } } } public long getSum(int index1, int index2) { long sum = 0L; for (int i1 = index1; i1 > 0; i1 -= i1 & -i1) { for (int i2 = index2; i2 > 0; i2 -= i2 & -i2) { sum += array[i1][i2]; } } return sum; } } interface UnionFind { void union(int A, int B); boolean judge(int A, int B); Set<Integer> getSet(int id); } class SetUnionFind extends ArrayUnionFind { Map<Integer, Set<Integer>> map; public SetUnionFind(int size) { super(size); map = new HashMap<>(); for (int i = 0; i < size; i++) { map.put(i, new HashSet<>()); map.get(i).add(i); } } @Override protected void unionTo(int source, int dest) { super.unionTo(source, dest); map.get(dest).addAll(map.get(source)); } @Override public Set<Integer> getSet(int id) { return map.get(root(id)); } } class ArrayUnionFind implements UnionFind { int[] parent; int[] rank; int size; public ArrayUnionFind(int size) { parent = new int[size]; for (int i = 0; i < size; i++) { parent[i] = i; } rank = new int[size]; this.size = size; } @Override public void union(int A, int B) { int rootA = root(A); int rootB = root(B); if (rootA != rootB) { if (rank[rootA] < rank[rootB]) { unionTo(rootA, rootB); } else { unionTo(rootB, rootA); if (rank[rootA] == rank[rootB]) { rank[rootA]++; } } } } protected void unionTo(int source, int dest) { parent[source] = dest; } @Override public boolean judge(int A, int B) { return root(A) == root(B); } @Override public Set<Integer> getSet(int id) { Set<Integer> set = new HashSet<>(); IntStream.range(0, size).filter(i -> judge(i, id)).forEach(set::add); return set; } protected int root(int id) { if (parent[id] == id) { return id; } parent[id] = root(parent[id]); return parent[id]; } } class PrimeNumberUtils { boolean[] isPrimeArray; List<Integer> primes; public PrimeNumberUtils(int limit) { if (limit > 10000000) { System.err.println("上限の値が高すぎるため素数ユーティリティの初期化でTLEする可能性が大変高いです"); } primes = new ArrayList<>(); isPrimeArray = new boolean[limit]; if (limit > 2) { primes.add(2); isPrimeArray[2] = true; } for (int i = 3; i < limit; i += 2) { if (isPrime(i, primes)) { primes.add(i); isPrimeArray[i] = true; } } } public List<Integer> getPrimeNumberList() { return primes; } public boolean isPrime(int n) { return isPrimeArray[n]; } private boolean isPrime(int n, List<Integer> primes) { for (int prime : primes) { if (n % prime == 0) { return false; } if (prime > Math.sqrt(n)) { break; } } return true; } } interface BitSet { void set(int index, boolean bit); boolean get(int index); void shiftRight(int num); void shiftLeft(int num); void or(BitSet bitset); void and(BitSet bitset); } class LongBit implements BitSet { long[] bitArray; public LongBit(int size) { bitArray = new long[((size + 63) / 64)]; } @Override public void set(int index, boolean bit) { int segment = index / 64; int inIndex = index % 64; if (bit) { bitArray[segment] |= 1L << inIndex; } else { bitArray[segment] &= ~(1L << inIndex); } } @Override public boolean get(int index) { int segment = index / 64; int inIndex = index % 64; return (bitArray[segment] & (1L << inIndex)) != 0L; } @Override public void shiftRight(int num) { int shiftSeg = num / 64; int shiftInI = num % 64; for (int segment = 0; segment < bitArray.length; segment++) { int sourceSeg = segment + shiftSeg; if (sourceSeg < bitArray.length) { bitArray[segment] = bitArray[sourceSeg] >>> shiftInI; if (shiftInI > 0 && sourceSeg + 1 < bitArray.length) { bitArray[segment] |= bitArray[sourceSeg + 1] << (64 - shiftInI); } } else { bitArray[segment] = 0L; } } } @Override public void shiftLeft(int num) { int shiftSeg = num / 64; int shiftInI = num % 64; for (int segment = bitArray.length - 1; segment >= 0; segment--) { int sourceSeg = segment - shiftSeg; if (sourceSeg >= 0) { bitArray[segment] = bitArray[sourceSeg] << shiftInI; if (shiftInI > 0 && sourceSeg > 0) { bitArray[segment] |= bitArray[sourceSeg - 1] >>> (64 - shiftInI); } } else { bitArray[segment] = 0L; } } } public long getLong(int segment) { return bitArray[segment]; } @Override public void or(BitSet bitset) { if (!(bitset instanceof LongBit)) { return; } for (int segment = 0; segment < bitArray.length; segment++) { bitArray[segment] |= ((LongBit) bitset).getLong(segment); } } @Override public void and(BitSet bitset) { if (!(bitset instanceof LongBit)) { return; } for (int segment = 0; segment < bitArray.length; segment++) { bitArray[segment] &= ((LongBit) bitset).getLong(segment); } } } }
[ { "input": "2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 9 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8\n", "output": "12\n" } ]
Java
codenet
s063482767
import java.util.*; public class s063482767 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); PriorityQueue<Integer> queue = new PriorityQueue<>(); for (int i = 0; i < n; i++) { queue.add(sc.nextInt()); } int sum = 0; for (int i = 0; i < n - 1; i++) { sum += queue.poll(); } System.out.println(queue.poll() < sum ? "Yes" : "No"); } }
[ { "input": "4\n3 8 5 1\n", "output": "Yes\n" } ]
Java
codenet
s321216487
import java.util.*; public class s321216487 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); String S = sc.next(); String begin; String end; String answer; for (int i = 0; i < S.length(); i++) { for (int j = 0; j < S.length(); j++) { begin = S.substring(0, i); end = S.substring(j, S.length()); answer = begin + end; if ("keyence".equals(answer)) { System.out.println("YES"); return; } else if ("keyence".equals(begin)) { System.out.println("YES"); return; } else if ("keyence".equals(end)) { System.out.println("YES"); return; } } } System.out.println("NO"); } }
[ { "input": "keyofscience\n", "output": "YES\n" } ]
Java
codenet
s125837071
import java.util.Scanner; public class s125837071 { @SuppressWarnings("resource") public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); long ans = 1; int mod = (int) Math.pow(10, 9) + 7; for (int i = 2; i <= n; i++) { for (int j = 2; (i % j != 0 && j < i) || j == i; j++) { if (j == i) { int s = 0; for (int k = 1; k <= n; k++) { s += findS(k, i); } ans = (ans * (s + 1)) % mod; } } } System.out.println(ans); } private static int findS(int k, int i) { int s = 0; for (int j = k; j % i == 0; j /= i) { s++; } return s; } }
[ { "input": "3\n", "output": "4\n" } ]
Java
codenet
s937747608
import java.util.Scanner; public class s937747608 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); if (a * b >= c * d) { System.out.println(a * b); } else if (a * b <= c * d) { System.out.println(c * d); } } }
[ { "input": "3 5 2 7\n", "output": "15\n" } ]
Java
codenet
s221078931
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class s221078931 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); IntegralRect[] rects = new IntegralRect[40000]; for (int i = 0; i < 200; i++) { for (int j = 0; j < 200; j++) { rects[i * 200 + j] = new IntegralRect(i + 1, j + 1); } } Arrays.sort(rects); while (true) { String[] tmpArray = br.readLine().split(" "); int h = Integer.parseInt(tmpArray[0]); int w = Integer.parseInt(tmpArray[1]); if (h == 0 && w == 0) { break; } IntegralRect tmpRect = new IntegralRect(h, w); int diag = tmpRect.diagonal(); for (int i = 0; i < rects.length; i++) { if (rects[i].compareTo(tmpRect) > 0) { System.out.println(rects[i].height + " " + rects[i].width); break; } } } } } class IntegralRect implements Comparable<IntegralRect> { int height; int width; public IntegralRect(int h, int w) { this.height = h; this.width = w; } public int diagonal() { if (height >= width) { return Integer.MAX_VALUE; } return this.height * this.height + this.width * this.width; } @Override public int compareTo(IntegralRect o) { int d1 = this.diagonal(); int d2 = o.diagonal(); return d1 == d2 ? this.height - o.height : d1 - d2; } }
[ { "input": "1 2\n1 3\n2 3\n1 4\n2 4\n5 6\n1 8\n4 7\n98 100\n99 100\n0 0\n", "output": "1 3\n2 3\n1 4\n2 4\n3 4\n1 8\n4 7\n2 8\n3 140\n89 109\n" } ]
Java
codenet
s847387793
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; class s847387793 { static class Solver { final FastScanner sc; final PrintWriter writer; Solver(final FastScanner sc, final PrintWriter writer) { this.sc = sc; this.writer = writer; } int n; int m; int q; int max; int[] a; int[] b; int[] c; int[] d; void run() { n = sc.nextInt(); m = sc.nextInt(); q = sc.nextInt(); a = new int[q]; b = new int[q]; c = new int[q]; d = new int[q]; for (int i = 0; i < q; i++) { a[i] = sc.nextInt(); b[i] = sc.nextInt(); c[i] = sc.nextInt(); d[i] = sc.nextInt(); } dfs(new int[] {1}); writer.println(max); } private void dfs(int[] array) { if (array.length > n) { int score = 0; for (int i = 0; i < q; i++) { if (array[b[i]] - array[a[i]] == c[i]) { score += d[i]; } } max = Math.max(max, score); return; } int[] newArray = new int[array.length + 1]; System.arraycopy(array, 0, newArray, 0, array.length); System.arraycopy(new int[] {array[array.length - 1]}, 0, newArray, array.length, 1); while (newArray[newArray.length - 1] <= m) { dfs(newArray); newArray[newArray.length - 1] += 1; } } } public static void main(final String[] args) { final FastScanner sc = new FastScanner(); try (final PrintWriter w = new PrintWriter(System.out)) { new Solver(sc, w).run(); w.flush(); } } static class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr; private int buflen; public FastScanner() {} private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (final IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private boolean isPrintableChar(final int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) { ptr++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } final StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { final long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(final int n) { final int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(final int n) { final long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } } }
[ { "input": "3 4 3\n1 3 3 100\n1 2 2 10\n2 3 2 10\n", "output": "110\n" } ]
Java
codenet
s962361667
import java.util.Scanner; public class s962361667 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] values = new int[w]; for (int i = 0; i < values.length; i++) { values[i] = i + 1; } for (int i = 0; i < n; i++) { int x = 0; String str = sc.next(); String[] ab = str.split(","); int a = Integer.parseInt(ab[0]) - 1; int b = Integer.parseInt(ab[1]) - 1; x = values[a]; values[a] = values[b]; values[b] = x; } for (int i = 0; i < w; i++) { System.out.println(values[i]); } } }
[ { "input": "5\n4\n2,4\n3,5\n1,2\n3,4\n", "output": "4\n1\n2\n5\n3\n" } ]
Java
codenet
s432314829
import java.util.Scanner; public class s432314829 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n = stdIn.nextInt(); int m = stdIn.nextInt(); int[] dp = new int[n + 2]; dp[n + 1] = 0; dp[n] = 1; for (int i = 0; i < m; i++) { dp[stdIn.nextInt()] = -1; } for (int i = n - 1; i >= 0; i--) { if (dp[i] == -1) { dp[i] = 0; } else { dp[i] = (dp[i + 1] + dp[i + 2]) % 1000000007; } } System.out.println(dp[0]); } }
[ { "input": "6 1\n3\n", "output": "4\n" } ]
Java
codenet
s505375619
import java.util.Scanner; public class s505375619 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = Integer.parseInt(s.next()); int[] v = new int[n]; int[] c = new int[n]; int[] dp = new int[n]; for (int i = 0; i < n; i++) { dp[i] = 0; } for (int i = 0; i < n; i++) { v[i] = Integer.parseInt(s.next()); } for (int i = 0; i < n; i++) { c[i] = Integer.parseInt(s.next()); } dp[0] = 0; for (int i = 1; i < n; i++) { int tmp = dp[i - 1] + (v[i - 1] - c[i - 1]); dp[i] = tmp > dp[i - 1] ? tmp : dp[i - 1]; } int tmp = dp[n - 1] + (v[n - 1] - c[n - 1]); dp[n - 1] = tmp > dp[n - 1] ? tmp : dp[n - 1]; System.out.println(dp[n - 1]); } }
[ { "input": "3\n10 2 5\n6 3 4\n", "output": "5\n" } ]
Java
codenet
s000087391
import java.util.ArrayList; import java.util.Scanner; public class s000087391 { public static void main(String[] args) { ArrayList<Integer> result = new ArrayList<>(); Scanner insert = new Scanner(System.in); int n = -1; while (true) { String line = insert.nextLine(); n = Integer.parseInt(line); if (n == 0) { break; } for (int i = 0; i < n; i++) {} line = insert.nextLine(); String[] array2 = line.split(" "); int[] input = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { input[i] = Integer.parseInt(array2[i]); sum += input[i]; } double avg = (double) sum / (double) n; int num = 0; for (int i = 0; i < n; i++) { if (input[i] <= avg) { num++; } } result.add(num); } for (int i = 0; i < (result.size()); i++) { if (result.get(i) == -1) { System.out.println("NONE"); } else { System.out.println(result.get(i)); } } } }
[ { "input": "7\n15 15 15 15 15 15 15\n4\n10 20 30 60\n10\n1 1 1 1 1 1 1 1 1 100\n7\n90 90 90 90 90 90 10\n7\n2 7 1 8 2 8 4\n0\n", "output": "7\n3\n9\n1\n4\n" } ]
Java
codenet
s380356166
import static java.util.Comparator.*; import java.io.*; import java.util.AbstractMap; public class s380356166 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; MyInput in = new MyInput(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { public void solve(int testNumber, MyInput in, PrintWriter out) { int ans = 0; int K = in.nextInt(); int S = in.nextInt(); int wk = 0; for (int x = 0; x <= K; x++) { for (int y = 0; y <= K; y++) { wk = S - x - y; if (wk >= 0 && wk <= K) { ans++; } } } out.println(ans); } } static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> { private static final long serialVersionUID = 6411527075103472113L; public Pair(final K key, final V value) { super(key, value); } public String getString() { return "[" + getKey() + "] [" + getValue() + "]"; } } static class MyInput { private final BufferedReader in; private static int pos; private static int readLen; private static final char[] buffer = new char[1024 * 8]; private static char[] str = new char[500 * 8 * 2]; private static boolean[] isDigit = new boolean[256]; private static boolean[] isSpace = new boolean[256]; private static boolean[] isLineSep = new boolean[256]; static { for (int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; } public MyInput(InputStream is) { in = new BufferedReader(new InputStreamReader(is)); } public int read() { if (pos >= readLen) { pos = 0; try { readLen = in.read(buffer); } catch (IOException e) { throw new RuntimeException(); } if (readLen <= 0) { throw new MyInput.EndOfFileRuntimeException(); } } return buffer[pos++]; } public int nextInt() { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if (str[0] == '-') { i = 1; } for (; i < len; i++) { ret = ret * 10 + str[i] - '0'; } if (str[0] == '-') { ret = -ret; } return ret; } public long nextLong() { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0L; if (str[0] == '-') { i = 1; } for (; i < len; i++) { ret = ret * 10 + str[i] - '0'; } if (str[0] == '-') { ret = -ret; } return ret; } public String nextString() { return new String(nextDChar()).trim(); } public char[] nextDChar() { int len = 0; len = reads(len, isSpace); char[] ret = new char[len + 1]; for (int i = 0; i < len; i++) { ret[i] = str[i]; } ret[len] = 0x00; return ret; } public char nextChar() { while (true) { final int c = read(); if (!isSpace[c]) { return (char) c; } } } int reads(int len, boolean[] accept) { try { while (true) { final int c = read(); if (accept[c]) { break; } if (str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char) c; } } catch (MyInput.EndOfFileRuntimeException e) { } return len; } static class EndOfFileRuntimeException extends RuntimeException {} } }
[ { "input": "2 2\n", "output": "6\n" } ]
Java
codenet
s682242794
import java.util.Scanner; public class s682242794 { int high; int low; int sa; public void solve() { Scanner sc = new Scanner(System.in); for (int i = 0; i < 7; i++) { high = sc.nextInt(); low = sc.nextInt(); sa = high - low; System.out.println(sa); } } public static void main(String[] args) { s682242794 obj = new s682242794(); obj.solve(); } }
[ { "input": "30 19\n39 20\n19 18\n25 20\n22 21\n23 10\n10 -10\n", "output": "11\n19\n1\n5\n1\n13\n20\n" } ]
Java
codenet
s936984238
import java.util.*; public class s936984238 { static Scanner sc = new Scanner(System.in); static int[] score; static int number; public static void main(String[] args) { while (read()) { slove(); } } static boolean read() { number = sc.nextInt(); if (number == 0) { return false; } score = new int[number]; for (int i = 0; i < number; i++) { score[i] = sc.nextInt(); } return true; } static void slove() { java.util.Arrays.sort(score); int sum = 0; for (int i = 1; i < number - 1; i++) { sum = sum + score[i]; } System.out.println(sum / (number - 2)); } }
[ { "input": "3\n1000\n342\n0\n5\n2\n2\n9\n11\n932\n5\n300\n1000\n0\n200\n400\n8\n353\n242\n402\n274\n283\n132\n402\n523\n0\n", "output": "342\n7\n300\n326\n" } ]
Java
codenet
s650785519
import java.util.Scanner; public class s650785519 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); sc.close(); int ans = (2199 - x) / 200; System.out.println(ans); } }
[ { "input": "725\n", "output": "7\n" } ]
Java
codenet
s851323333
import java.util.LinkedList; import java.util.Scanner; public class s851323333 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); LinkedList<Integer> list = new LinkedList<>(); while (scan.hasNextInt()) { int a = scan.nextInt(); if (a == 0) { System.out.println(list.pop()); } else { list.push(a); } } } }
[ { "input": "1\n6\n0\n8\n10\n0\n0\n0\n", "output": "6\n10\n8\n1\n" } ]
Java
codenet
s606985261
import java.util.Scanner; public class s606985261 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int total = 0; for (int i = 0; i < s.length(); i++) { for (int j = i + 1; j < s.length(); j++) { if (s.charAt(i) == s.charAt(j)) { total++; } } } System.out.println(total == 2 ? "Yes" : "No"); } }
[ { "input": "ASSA\n", "output": "Yes\n" } ]
Java
codenet
s295587559
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class s295587559 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] num = new int[in.nextInt()]; for (int i = 0; i < num.length; i++) { num[i] = i + 1; } int count = in.nextInt(); Pattern pt = Pattern.compile("(\\d+),(\\d+)"); int[] line = new int[2]; for (int i = 0; i < count; i++) { String next = in.next(pt); for (int j = 0; j < line.length; j++) { Matcher matcher = pt.matcher(next); matcher.matches(); line[j] = Integer.parseInt(matcher.group(j + 1)) - 1; } int change = num[line[0]]; num[line[0]] = num[line[1]]; num[line[1]] = change; } for (int i = 0; i < num.length; i++) { System.out.println(num[i]); } } }
[ { "input": "5\n4\n2,4\n3,5\n1,2\n3,4\n", "output": "4\n1\n2\n5\n3\n" } ]
Java
codenet
s720527488
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class s720527488 { static final InputStream in = System.in; static final PrintWriter out = new PrintWriter(System.out); static final int INF = Integer.MAX_VALUE / 2; static final long LINF = Long.MAX_VALUE / 2; public static void main(String[] args) throws IOException { InputReader ir = new InputReader(in); int m = ir.nextInt(); int n = ir.nextInt(); int[] manju = ir.toIntArray(m); int[] boxlen = new int[n]; int[] boxcost = new int[n]; for (int i = 0; i < n; i++) { boxlen[i] = ir.nextInt(); boxcost[i] = ir.nextInt(); } sort(manju); int[][] dp = new int[m + 1][n + 1]; for (int i = m - 1; i >= 0; i--) { for (int j = n - 1; j >= 0; j--) { int len = i + boxlen[j] >= m ? m : i + boxlen[j]; int cnt = 0; for (int k = i; k < len; k++) { cnt += manju[m - 1 - k]; } dp[i][j] = Math.max(dp[i][j], dp[len][j + 1] + cnt - boxcost[j]); dp[i][j] = Math.max(dp[i][j], dp[i][j + 1]); } } out.println(dp[0][0]); out.flush(); } public static void sort(int[] a) { for (int i = a.length - 1; i >= 1; i--) { int t = (int) Math.random() * i; int temp = a[i]; a[i] = a[t]; a[t] = temp; } Arrays.sort(a); } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; } public int readByte() { if (lenbuf == -1) { throw new InputMismatchException(); } if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) { return -1; } } return buffer[curbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) { continue; } return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { int c = readByte(); while (isSpaceChar(c)) { c = readByte(); } boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return minus ? -res : res; } public long nextLong() { int c = readByte(); while (isSpaceChar(c)) { c = readByte(); } boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return minus ? -res : res; } public int[] toIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } } }
[ { "input": "4 3\n180\n160\n170\n190\n2 100\n3 120\n4 250\n", "output": "480\n" } ]
Java
codenet
s022285498
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class s022285498 { static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] countArr = new int[n + 1]; for (int x = 1; x <= 100; x++) { for (int y = 1; y <= 100; y++) { for (int z = 1; z <= 100; z++) { int value = x * x + y * y + z * z + x * y + x * z + y * z; if (value > n) { break; } countArr[value]++; } } } for (int i = 1; i <= n; i++) { out.println(countArr[i]); } } } private static void sort(double[] arr) { Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[i]; } } private static void sort(int[] arr) { Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[i]; } } private static void sort(long[] arr) { Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new); Arrays.sort(objArr); for (int i = 0; i < arr.length; i++) { arr[i] = objArr[i]; } } private static void solve() { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task task = new Task(); task.solve(1, in, out); out.close(); } public static void main(String[] args) { new Thread(null, s022285498::solve, "1", 1 << 26).start(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
[ { "input": "20\n", "output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n" } ]
Java
codenet
s162740530
import java.util.Scanner; public class s162740530 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] a = new int[m + 1]; int[] cnt = new int[n + 1]; cnt[0] = 1; final int mod = 1000000007; for (int i = 1; i < a.length; i++) { a[i] = sc.nextInt(); } int num = 1; if (m > 0) { if (a[1] == 1) { cnt[1] = 0; if (num < m) { num++; } } else { cnt[1] = 1; } } else { cnt[1] = 1; } for (int i = 2; i < cnt.length; i++) { cnt[i] = cnt[i - 2] + cnt[i - 1]; cnt[i] %= mod; if (m > 0) { if (i == a[num]) { cnt[i] = 0; if (num < m) { num++; } } } } System.out.println(cnt[n]); sc.close(); } }
[ { "input": "6 1\n3\n", "output": "4\n" } ]
Java
codenet
s863488345
import java.util.*; public class s863488345 { static int mapNum; static int h; static int w; static char[][] battleTown; static int bomberActNum; static char[] bomberAct; static int[] tank = new int[2]; static int xOfTank; static int yOfTank; static int xOfBomber; static int yOfBomber; static int s; static int k; static int a; static int b; static int x; static int y; public static void main(String[] args) { Scanner sc = new Scanner(System.in); mapNum = sc.nextInt(); for (int i = 0; i < mapNum; i++) { if (1 <= i && i < mapNum) { System.out.println(""); } h = sc.nextInt(); w = sc.nextInt(); battleTown = new char[h][w]; for (int j = 0; j < h; j++) { char[] c = sc.next().toCharArray(); for (int k = 0; k < w; k++) { battleTown[j][k] = c[k]; if ('^' == battleTown[j][k] || 'v' == battleTown[j][k] || '<' == battleTown[j][k] || '>' == battleTown[j][k]) { x = j; y = k; } } } bomberActNum = sc.nextInt(); bomberAct = sc.next().toCharArray(); if (0 <= x && x <= h && 0 <= y && y <= w) { for (int l = 0; l < bomberActNum; l++) { if (bomberAct[l] == 'U') { battleTown[x][y] = '^'; if (x - 1 >= 0 && battleTown[x - 1][y] == '.') { battleTown[x - 1][y] = '^'; battleTown[x][y] = '.'; x--; } } if (bomberAct[l] == 'D') { battleTown[x][y] = 'v'; if (x + 1 < h && battleTown[x + 1][y] == '.') { battleTown[x + 1][y] = 'v'; battleTown[x][y] = '.'; x++; } } if (bomberAct[l] == 'L') { battleTown[x][y] = '<'; if (y - 1 >= 0 && battleTown[x][y - 1] == '.') { battleTown[x][y - 1] = '<'; battleTown[x][y] = '.'; y--; } } if (bomberAct[l] == 'R') { battleTown[x][y] = '>'; if (y + 1 < w && battleTown[x][y + 1] == '.') { battleTown[x][y + 1] = '>'; battleTown[x][y] = '.'; y++; } } if (bomberAct[l] == 'S') { xOfBomber = x; yOfBomber = y; moveBomber(xOfBomber, yOfBomber); } } for (s = 0; s < h; s++) { for (k = 0; k < w; k++) { System.out.print(battleTown[s][k]); } System.out.println(); } } } } public static void moveBomber(int a, int b) { if (0 <= a && a <= h && 0 <= b && b <= w) { if ('^' == battleTown[a][b]) { for (int i = a - 1; i >= 0; i--) { if (a <= 0) { return; } else if (battleTown[a - 1][b] == '*') { battleTown[a - 1][b] = '.'; return; } else if (battleTown[a - 1][b] == '#') { return; } else { a--; if (a == 0) { return; } } } } if ('v' == battleTown[a][b]) { for (int i = a + 1; i < h; i++) { if (battleTown[a + 1][b] == '*') { battleTown[a + 1][b] = '.'; return; } else if (battleTown[a + 1][b] == '#') { return; } else { a++; if (a == h) { return; } } } } if ('<' == battleTown[a][b]) { for (int i = b - 1; i >= 0; i--) { if (battleTown[a][b - 1] == '*') { battleTown[a][b - 1] = '.'; return; } else if (battleTown[a][b - 1] == '#') { return; } else { b--; if (b == 0) { return; } } } } if ('>' == battleTown[a][b]) { for (int i = b + 1; i < w; i++) { if (battleTown[a][b + 1] == '*') { battleTown[a][b + 1] = '.'; return; } else if (battleTown[a][b + 1] == '#') { return; } else { b++; if (b == w) { return; } } } } } } }
[ { "input": "4\n4 6\n*.*..*\n*.....\n..-...\n^.*#..\n10\nSRSSRRUSSR\n2 2\n<.\n..\n12\nDDSRRSUUSLLS\n3 5\n>-#**\n.-*#*\n.-**#\n15\nSSSDRSSSDRSSSUU\n5 5\nv****\n*****\n*****\n*****\n*****\n44\nSSSSDDRSDRSRDSULUURSSSSRRRRDSSSSDDLSDLSDLSSD\n", "output": "*....*\n......\n..-...\n..>#..\n\n<.\n..\n\n^-#**\n.-.#*\n.-..#\n\n.....\n.***.\n..*..\n..*..\n....v\n" } ]
Java
codenet
s853705214
import java.util.*; public class s853705214 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = sc.nextInt(); } int min = Integer.MAX_VALUE; int countNegatives = 0; long sum = 0; for (int num : nums) { int abs = Math.abs(num); sum += abs; min = Math.min(min, abs); if (num < 0) { countNegatives++; } } System.out.println(countNegatives % 2 == 0 ? sum : sum - (min * 2)); } }
[ { "input": "3\n-10 5 -4\n", "output": "19\n" } ]
Java
codenet
s545439898
import java.util.Scanner; public class s545439898 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = Integer.parseInt(sc.next()); int[] givingNumbers = new int[count]; for (int i = 0; i < count; i++) { givingNumbers[i] = Integer.parseInt(sc.next()); } for (int i = count - 1; 0 <= i; i--) { System.out.print(givingNumbers[i]); if (i > 0) { System.out.print(" "); } } System.out.println(); sc.close(); } }
[ { "input": "5\n1 2 3 4 5\n", "output": "5 4 3 2 1\n" } ]
Java
codenet
s059841225
import java.util.*; class s059841225 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String str = sc.next(); String[] strArr = str.split(","); int[] l = new int[10]; int d = 0; for (int i = 0; i < 10; i++) { l[i] = Integer.parseInt(strArr[i]); d += l[i]; } int[] v = {Integer.parseInt(strArr[10]), Integer.parseInt(strArr[11])}; double t = (double) d / (v[0] + v[1]); d = 0; for (int i = 0; i < 11; i++) { if (v[0] * t <= d) { System.out.println(i); break; } else { d += l[i]; } } } } }
[ { "input": "1,1,1,1,1,1,1,1,1,1,40,60\n1,1,1,1,1,3,3,3,3,3,50,50\n10,10,10,10,10,10,10,10,10,10,50,49\n", "output": "4\n7\n6\n" } ]
Java
codenet
s318252319
import java.util.*; public class s318252319 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int n = Integer.parseInt(s.substring(s.length() - 1, s.length())); if (n == 3) { System.out.println("bon"); } else if (n == 0 || n == 1 || n == 6 || n == 8) { System.out.println("pon"); } else { System.out.println("hon"); } sc.close(); } }
[ { "input": "16\n", "output": "pon\n" } ]
Java
codenet
s773621585
import java.util.HashMap; import java.util.Scanner; public class s773621585 { public static void main(String[] args) { HashMap<String, String> map = new HashMap<>(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String str = sc.nextLine(); for (int i = 0; i < n; i++) { map.put(sc.nextLine(), ""); } sc.close(); System.out.println(map.size()); } }
[ { "input": "3\napple\norange\napple\n", "output": "2\n" } ]
Java
codenet
s609591310
import java.util.*; public class s609591310 { public static void main(String[] args) { int ans = 0; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] list = new int[n]; for (int i = 0; i < n; i++) { list[i] = sc.nextInt(); } int[] numlist1 = new int[100000]; int[] numlist2 = new int[100000]; for (int i = 0; i < 100000; i++) { numlist1[i] = 0; numlist2[i] = 0; } for (int i = 0; i < n; i += 2) { numlist1[list[i] - 1] += 1; numlist2[list[i + 1] - 1] += 1; } int max11 = 0; int max12 = 0; int max21 = 0; int max22 = 0; int val1 = 0; int val2 = 0; for (int i = 0; i < 100000; i++) { if (numlist1[i] >= max11) { max12 = max11; max11 = numlist1[i]; val1 = i; } else if (numlist1[i] >= max12) { max12 = numlist1[i]; } if (numlist2[i] >= max21) { max22 = max21; max21 = numlist2[i]; val2 = i; } else if (numlist2[i] >= max22) { max22 = numlist2[i]; } } if (val1 != val2) { ans = n - max11 - max21; } else { ans = n - Math.max(max12 + max21, max11 + max22); } System.out.println(ans); } }
[ { "input": "4\n3 1 3 2\n", "output": "1\n" } ]
Java
codenet
s283652523
import java.io.*; import java.util.*; @SuppressWarnings("unused") public class s283652523 { FastScanner in; PrintWriter out; static final int MOD = (int) 1e9 + 7; void solve() { int N = in.nextInt(); int[] A = in.nextIntArray(N); long ans = 0; long sum = A[N - 1]; for (int i = N - 2; i >= 0; i--) { ans += (sum * A[i]) % MOD; ans %= MOD; sum += A[i]; sum %= MOD; } out.println(ans); } public static void main(String[] args) { new s283652523().m(); } private void m() { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.flush(); in.close(); out.close(); } static class FastScanner { private Reader input; public FastScanner() { this(System.in); } public FastScanner(InputStream stream) { this.input = new BufferedReader(new InputStreamReader(stream)); } public void close() { try { this.input.close(); } catch (IOException e) { e.printStackTrace(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public long nextLong() { try { int sign = 1; int b = input.read(); while ((b < '0' || '9' < b) && b != '-' && b != '+') { b = input.read(); } if (b == '-') { sign = -1; b = input.read(); } else if (b == '+') { b = input.read(); } long ret = b - '0'; while (true) { b = input.read(); if (b < '0' || '9' < b) { return ret * sign; } ret *= 10; ret += b - '0'; } } catch (IOException e) { e.printStackTrace(); return -1; } } public double nextDouble() { try { double sign = 1; int b = input.read(); while ((b < '0' || '9' < b) && b != '-' && b != '+') { b = input.read(); } if (b == '-') { sign = -1; b = input.read(); } else if (b == '+') { b = input.read(); } double ret = b - '0'; while (true) { b = input.read(); if (b < '0' || '9' < b) { break; } ret *= 10; ret += b - '0'; } if (b != '.') { return sign * ret; } double div = 1; b = input.read(); while ('0' <= b && b <= '9') { ret *= 10; ret += b - '0'; div *= 10; b = input.read(); } return sign * ret / div; } catch (IOException e) { e.printStackTrace(); return Double.NaN; } } public char nextChar() { try { int b = input.read(); while (Character.isWhitespace(b)) { b = input.read(); } return (char) b; } catch (IOException e) { e.printStackTrace(); return 0; } } public String nextStr() { try { StringBuilder sb = new StringBuilder(); int b = input.read(); while (Character.isWhitespace(b)) { b = input.read(); } while (b != -1 && !Character.isWhitespace(b)) { sb.append((char) b); b = input.read(); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); return ""; } } public String nextLine() { try { StringBuilder sb = new StringBuilder(); int b = input.read(); while (b != -1 && b != '\n') { sb.append((char) b); b = input.read(); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); return ""; } } public int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public int[] nextIntArrayDec(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt() - 1; } return res; } public int[] nextIntArray1Index(int n) { int[] res = new int[n + 1]; for (int i = 0; i < n; i++) { res[i + 1] = nextInt(); } return res; } public long[] nextLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } public long[] nextLongArrayDec(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextLong() - 1; } return res; } public long[] nextLongArray1Index(int n) { long[] res = new long[n + 1]; for (int i = 0; i < n; i++) { res[i + 1] = nextLong(); } return res; } public double[] nextDoubleArray(int n) { double[] res = new double[n]; for (int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; } } }
[ { "input": "3\n1 2 3\n", "output": "11\n" } ]
Java
codenet
s393796709
import java.io.*; import java.util.*; public class s393796709 { long MOD = 1000000007; void solve(BufferedReader in) throws Exception { int[] xx = toInts(in.readLine()); int min = Math.min(xx[0], xx[1]); int max = Math.max(xx[0], xx[1]); long res; if (min == max) { long f = f(min); res = (2 * f * f) % MOD; } else if (min + 1 == max) { long f = f(min); res = (f * ((f * max) % MOD)) % MOD; } else { res = 0; } System.out.println(res); } long f(int n) { long res = 1; for (int i = 2; i <= n; i++) { res = (res * i) % MOD; } return res; } int toInt(String s) { return Integer.parseInt(s); } int[] toInts(String s) { String[] a = s.split(" "); int[] o = new int[a.length]; for (int i = 0; i < a.length; i++) { o[i] = toInt(a[i]); } return o; } void e(Object o) { System.err.println(o); } public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); (new s393796709()).solve(in); } }
[ { "input": "2 2\n", "output": "8\n" } ]
Java
codenet
s998094687
import java.lang.Math.*; import java.util.Arrays; import java.util.Scanner; class s998094687 { public static void main(String[] args) { final Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[3]; for (int i = 0; i < n; i++) { a[0] = sc.nextInt(); a[1] = sc.nextInt(); a[2] = sc.nextInt(); Arrays.sort(a); if (Math.pow(a[2], 2) == Math.pow(a[0], 2) + Math.pow(a[1], 2)) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
[ { "input": "3\n4 3 5\n4 3 6\n8 8 8\n", "output": "YES\nNO\nNO\n" } ]
Java
codenet
s409580149
import java.io.*; import java.util.*; public class s409580149 { static int n; static int[] a; static double[][][] dp; static void solve() { n = ni(); a = na(n); dp = new double[n + 1][n + 1][n + 1]; for (int i = 0; i < n + 1; i++) { fill(dp[i], -1); } dp[0][0][0] = 0; int[] cnt = new int[3]; for (int i = 0; i < n; i++) { cnt[a[i] - 1]++; } double ans = rec(cnt[0], cnt[1], cnt[2]); out.println(ans); } static double rec(int i, int j, int k) { if (dp[i][j][k] != -1) { return dp[i][j][k]; } double ret = 0; double p = ((double) i + j + k) / n; double pi = (double) i / n; double pj = (double) j / n; double pk = (double) k / n; ret += 1 / p; if (i > 0) { ret += pi / p * rec(i - 1, j, k); } if (j > 0) { ret += pj / p * rec(i + 1, j - 1, k); } if (k > 0) { ret += pk / p * rec(i, j + 1, k - 1); } return dp[i][j][k] = ret; } static final long mod = (long) 1e9 + 7; static final int[] dx = {-1, 0, 1, 0}; static final int[] dy = {0, -1, 0, 1}; static final int[] dx8 = {-1, -1, -1, 0, 0, 1, 1, 1}; static final int[] dy8 = {-1, 0, 1, -1, 1, -1, 0, 1}; static final int inf = Integer.MAX_VALUE / 2; static final long linf = Long.MAX_VALUE / 3; static final double dinf = Double.MAX_VALUE / 3; static final double eps = 1e-10; static final double pi = Math.PI; static StringBuilder sb = new StringBuilder(); static InputStream is; static PrintWriter out; static String INPUT = ""; static void reverse(int[] ar) { int len = ar.length; for (int i = 0; i < len / 2; i++) { int t = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = t; } } static void reverse(long[] ar) { int len = ar.length; for (int i = 0; i < len / 2; i++) { long t = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = t; } } static void reverse(double[] ar) { int len = ar.length; for (int i = 0; i < len / 2; i++) { double t = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = t; } } static void reverse(char[] ar) { int len = ar.length; for (int i = 0; i < len / 2; i++) { char t = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = t; } } static String getReverse(String s) { char[] c = s.toCharArray(); reverse(c); s = String.valueOf(c); return s; } static <T> void reverse(List<T> ls) { int sz = ls.size(); for (int i = 0; i < sz / 2; i++) { T t = ls.get(i); ls.set(i, ls.get(sz - 1 - i)); ls.set(sz - 1 - i, t); } } static <T> void reverse(T[] ar) { int len = ar.length; for (int i = 0; i < len / 2; i++) { T t = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = t; } } static void sbnl() { sb.append("\n"); } static int lowerBound(int[] a, int x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] < x) { l = c; } else { r = c; } } return r; } static int upperBound(int[] a, int x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] <= x) { l = c; } else { r = c; } } return r; } static int rlowerBound(int[] a, int x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] > x) { l = c; } else { r = c; } } return r; } static int rupperBound(int[] a, int x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] >= x) { l = c; } else { r = c; } } return r; } static int lowerBound(long[] a, long x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] < x) { l = c; } else { r = c; } } return r; } static int upperBound(long[] a, long x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] <= x) { l = c; } else { r = c; } } return r; } static int rlowerBound(long[] a, long x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] > x) { l = c; } else { r = c; } } return r; } static int rupperBound(long[] a, long x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] >= x) { l = c; } else { r = c; } } return r; } static int lowerBound(double[] a, double x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] < x) { l = c; } else { r = c; } } return r; } static int upperBound(double[] a, double x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] <= x) { l = c; } else { r = c; } } return r; } static int rlowerBound(double[] a, double x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] > x) { l = c; } else { r = c; } } return r; } static int rupperBound(double[] a, double x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] >= x) { l = c; } else { r = c; } } return r; } static int lowerBound(char[] a, char x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] < x) { l = c; } else { r = c; } } return r; } static int upperBound(char[] a, char x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] <= x) { l = c; } else { r = c; } } return r; } static int rlowerBound(char[] a, char x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] > x) { l = c; } else { r = c; } } return r; } static int rupperBound(char[] a, char x) { int l = -1; int r = a.length; while (r - l > 1) { int c = (l + r) / 2; if (a[c] >= x) { l = c; } else { r = c; } } return r; } static <T> int lowerBound(List<T> ls, T x) throws RuntimeException { if (ls.isEmpty()) { return -1; } if (ls.get(0) instanceof Integer) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) >= 0 ? 1 : -1); } else if (ls.get(0) instanceof Long) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) >= 0 ? 1 : -1); } else if (ls.get(0) instanceof Double) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) >= 0 ? 1 : -1); } else { System.err.println( String.format( "%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName())); throw new RuntimeException(); } } static <T> int upperBound(List<T> ls, T x) throws RuntimeException { if (ls.isEmpty()) { return -1; } if (ls.get(0) instanceof Integer) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) > 0 ? 1 : -1); } else if (ls.get(0) instanceof Long) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) > 0 ? 1 : -1); } else if (ls.get(0) instanceof Double) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) > 0 ? 1 : -1); } else { System.err.println( String.format( "%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName())); throw new RuntimeException(); } } static <T> int rupperBound(List<T> ls, T x) throws RuntimeException { if (ls.isEmpty()) { return -1; } if (ls.get(0) instanceof Integer) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) < 0 ? 1 : -1); } else if (ls.get(0) instanceof Long) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) < 0 ? 1 : -1); } else if (ls.get(0) instanceof Double) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) < 0 ? 1 : -1); } else { System.err.println( String.format( "%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName())); throw new RuntimeException(); } } static <T> int rlowerBound(List<T> ls, T x) { if (ls.isEmpty()) { return -1; } if (ls.get(0) instanceof Integer) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) <= 0 ? 1 : -1); } else if (ls.get(0) instanceof Long) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) <= 0 ? 1 : -1); } else if (ls.get(0) instanceof Double) { return ~Collections.binarySearch( ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) <= 0 ? 1 : -1); } else { System.err.println( String.format( "%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName())); throw new RuntimeException(); } } static int[] concat(int x, int[] arr) { int[] ret = new int[arr.length + 1]; System.arraycopy(arr, 0, ret, 1, ret.length - 1); ret[0] = x; return ret; } static int[] concat(int[] arr, int x) { int[] ret = new int[arr.length + 1]; System.arraycopy(arr, 0, ret, 0, ret.length - 1); ret[ret.length - 1] = x; return ret; } static long[] concat(long x, long[] arr) { long[] ret = new long[arr.length + 1]; System.arraycopy(arr, 0, ret, 1, ret.length - 1); ret[0] = x; return ret; } static long[] concat(long[] arr, long x) { long[] ret = new long[arr.length + 1]; System.arraycopy(arr, 0, ret, 0, ret.length - 1); ret[ret.length - 1] = x; return ret; } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int max(int x, int y, int z) { x = Math.max(x, y); x = Math.max(x, z); return x; } static int min(int x, int y, int z) { x = Math.min(x, y); x = Math.min(x, z); return x; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } static long max(long x, long y, long z) { x = Math.max(x, y); x = Math.max(x, z); return x; } static long min(long x, long y, long z) { x = Math.min(x, y); x = Math.min(x, z); return x; } static double max(double x, double y) { return Math.max(x, y); } static double min(double x, double y) { return Math.min(x, y); } static double max(double x, double y, double z) { x = Math.max(x, y); x = Math.max(x, z); return x; } static double min(double x, double y, double z) { x = Math.min(x, y); x = Math.min(x, z); return x; } static void sort(int[] ar) { Arrays.sort(ar); } static void sort(long[] ar) { Arrays.sort(ar); } static void sort(double[] ar) { Arrays.sort(ar); } static void sort(char[] ar) { Arrays.sort(ar); } static void rsort(int[] ar) { Arrays.sort(ar); int len = ar.length; for (int i = 0; i < len / 2; i++) { int tmp = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = tmp; } } static void rsort(long[] ar) { Arrays.sort(ar); int len = ar.length; for (int i = 0; i < len / 2; i++) { long tmp = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = tmp; } } static void rsort(double[] ar) { Arrays.sort(ar); int len = ar.length; for (int i = 0; i < len / 2; i++) { double tmp = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = tmp; } } static void rsort(char[] ar) { Arrays.sort(ar); int len = ar.length; for (int i = 0; i < len / 2; i++) { char tmp = ar[i]; ar[i] = ar[len - 1 - i]; ar[len - 1 - i] = tmp; } } static void fill(int[] arr, int x) { Arrays.fill(arr, x); } static void fill(long[] arr, long x) { Arrays.fill(arr, x); } static void fill(boolean[] arr, boolean x) { Arrays.fill(arr, x); } static void fill(double[] arr, double x) { Arrays.fill(arr, x); } static void fill(int[][] arr, int x) { for (int i = 0; i < arr.length; i++) { Arrays.fill(arr[i], x); } } static void fill(long[][] arr, long x) { for (int i = 0; i < arr.length; i++) { Arrays.fill(arr[i], x); } } static void fill(double[][] arr, double x) { for (int i = 0; i < arr.length; i++) { Arrays.fill(arr[i], x); } } static void fill(boolean[][] arr, boolean x) { for (int i = 0; i < arr.length; i++) { Arrays.fill(arr[i], x); } } static long plus(long x, long y) { long res = (x + y) % mod; return res < 0 ? res + mod : res; } static long sub(long x, long y) { long res = (x - y) % mod; return res < 0 ? res + mod : res; } static long mul(long x, long y) { long res = (x * y) % mod; return res < 0 ? res + mod : res; } static long div(long x, long y) { long res = x * pow(y, mod - 2) % mod; return res < 0 ? res + mod : res; } static long pow(long x, long y) { if (y < 0) { return 0; } if (y == 0) { return 1; } if (y % 2 == 1) { return (x * pow(x, y - 1)) % mod; } long root = pow(x, y / 2); return root * root % mod; } public static void main(String[] args) throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); } private static final byte[] inbuf = new byte[1024]; static int lenbuf; static int ptrbuf; private static int readByte() { if (lenbuf == -1) { throw new InputMismatchException(); } if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) { return -1; } } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private static int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) { continue; } return b; } @SuppressWarnings("unused") private static double nd() { return Double.parseDouble(ns()); } @SuppressWarnings("unused") private static char nc() { return (char) skip(); } private static String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] ns(int n) { char[] buf = new char[n]; int b = skip(); int p = 0; while (p < n && !isSpaceChar(b)) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } @SuppressWarnings("unused") private static char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) { map[i] = ns(m); } return map; } @SuppressWarnings("unused") private static int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } @SuppressWarnings("unused") private static long[] nla(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nl(); } return a; } private static int ni() { int num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) { continue; } if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } @SuppressWarnings("unused") private static long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) { continue; } if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } }
[ { "input": "3\n1 1 1\n", "output": "5.5\n" } ]
Java
codenet
s656827329
import java.util.*; public class s656827329 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int count = 1; int now = 0; int bef = 0; for (int i = 1; i < n; i++) { if (a[i - 1] < a[i]) { now = 1; } else if (a[i - 1] > a[i]) { now = -1; } else { continue; } if (bef == 0) { bef = now; } if (bef != now) { count++; bef = 0; } } System.out.println(count); } }
[ { "input": "6\n1 2 3 2 2 1\n", "output": "2\n" } ]
Java
codenet
s965025950
import java.util.Scanner; public class s965025950 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int z = sc.nextInt(); System.out.println(z + " " + x + " " + y); sc.close(); } }
[ { "input": "1 2 3\n", "output": "3 1 2\n" } ]
Java
codenet
s214067324
import java.util.Scanner; public class s214067324 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = Integer.parseInt(sc.next()); System.out.println(x < 1200 ? "ABC" : "ARC"); } }
[ { "input": "1000\n", "output": "ABC\n" } ]
Java
codenet
s685734377
import java.io.*; import java.util.StringTokenizer; public class s685734377 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, FastScanner in, PrintWriter out) { int n = in.nextInt(); char[][] a = new char[n][n]; long P = 37; long Q = 47; long[] powP = new long[n + 1]; long[] powQ = new long[n + 1]; powP[0] = powQ[0] = 1; for (int i = 1; i <= n; i++) { powP[i] = powP[i - 1] * P; powQ[i] = powQ[i - 1] * Q; } for (int i = 0; i < n; i++) { a[i] = in.next().toCharArray(); } long[][] hashRow = new long[n][n]; long[][] hashCol = new long[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { hashRow[i][k] += a[i][j] * powP[(j - k + n) % n]; hashCol[j][k] += a[i][j] * powP[(i - k + n) % n]; } } } int ans = 0; for (int A = 0; A < n; A++) { for (int B = 0; B < n; B++) { boolean ok = true; for (int i = 0; i < n; i++) { ok &= hashRow[(i + A) % n][B] == hashCol[(i + B) % n][A]; } ans += ok ? 1 : 0; } } out.println(ans); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } public int nextInt() { return Integer.parseInt(next()); } public String next() { while (st == null || !st.hasMoreElements()) { String line = null; try { line = br.readLine(); } catch (IOException e) { } st = new StringTokenizer(line); } return st.nextToken(); } } }
[ { "input": "2\nab\nca\n", "output": "2\n" } ]
Java
codenet
s989561778
import java.io.IOException; import java.util.Scanner; class s989561778 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(""); int a; int b; int digit; while (sc.hasNextInt()) { a = sc.nextInt(); b = sc.nextInt(); digit = (int) Math.log10(a + b) + 1; sb.append(digit); sb.append('\n'); } System.out.print(sb); } }
[ { "input": "5 7\n1 99\n1000 999\n", "output": "2\n3\n4\n" } ]
Java
codenet
s151517960
import java.util.*; public class s151517960 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); if (map.containsKey(a)) { map.put(a, map.get(a) + 1); } else { map.put(a, 1); } } int ans = 0; for (int key : map.keySet()) { if ((map.get(key) % 2) == 1) { ans++; } } System.out.println(ans); } }
[ { "input": "3\n6\n2\n6\n", "output": "1\n" } ]
Java
codenet
s466963472
import java.util.*; public class s466963472 { static Scanner sc = new Scanner(System.in); static int d; static boolean read() { if (!sc.hasNextInt()) { return false; } d = sc.nextInt(); return true; } static int solve() { int ans; int n; ans = 0; for (int i = 1; i * d < 600; i++) { int x = i * d; int y = x * x; ans += y * d; } return ans; } public static void main(String[] args) { while (read()) { System.out.println(solve()); } } }
[ { "input": "20\n10\n", "output": "68440000\n70210000\n" } ]
Java
codenet
s393629232
import java.util.Scanner; public class s393629232 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int maxv = Integer.MIN_VALUE; int minv = sc.nextInt(); for (int i = 1; i < n; i++) { int ri = sc.nextInt(); maxv = Math.max(maxv, ri - minv); minv = Math.min(minv, ri); } System.out.println(maxv); sc.close(); } }
[ { "input": "6\n5\n3\n1\n3\n4\n3\n", "output": "3\n" } ]
Java
codenet
s016010007
import static java.lang.Integer.parseInt; import java.awt.geom.Point2D.Double; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class s016010007 { public static void main(String[] args) { new s016010007().run(); } public void run() { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { Point2D p0; Point2D p1; Point2D p2; String[] line = br.readLine().split(" "); p0 = new Point2D(parseInt(line[0]), parseInt(line[1])); p1 = new Point2D(parseInt(line[2]), parseInt(line[3])); int q = parseInt(br.readLine()); StringBuilder buf = new StringBuilder(); for (int i = 0; i < q; i++) { line = br.readLine().split(" "); p2 = new Point2D(parseInt(line[0]), parseInt(line[1])); buf.append(jadgeClockwise(p0, p1, p2)).append("\n"); } System.out.print(buf); } catch (IOException e) { System.out.println(e); } } public String jadgeClockwise(Point2D p0, Point2D p1, Point2D p2) { Vector v = new Vector(); Point2D a = p1.diff(p0); Point2D b = p2.diff(p0); if (v.cross(a, b) > v.EPS) { return "COUNTER_CLOCKWISE"; } if (v.cross(a, b) < -v.EPS) { return "CLOCKWISE"; } if (v.dot(a, b) < -v.EPS) { return "ONLINE_BACK"; } if (a.norm() < b.norm()) { return "ONLINE_FRONT"; } return "ON_SEGMENT"; } private class Point2D extends Double { private static final long serialVersionUID = 1L; double EPS = 1e-10; public Point2D() { super(); } public Point2D(double x, double y) { super(x, y); } public boolean equals(double a, double b) { return Math.abs(a - b) < EPS; } public Point2D sum(Point2D b) { return new Point2D(x + b.x, y + b.y); } public Point2D diff(Point2D b) { return new Point2D(x - b.x, y - b.y); } public Point2D multiple(double k) { return new Point2D(x * k, y * k); } public double norm() { return x * x + y * y; } public double abs(Point2D a) { return Math.sqrt(a.norm()); } @Override public String toString() { return String.format("%.10f %.10f", x, y); } } private class Vector extends Point2D { private static final long serialVersionUID = 1L; public Vector() { super(); } public Vector(double x, double y) { super(x, y); } public Vector(Point2D p) { super(p.x, p.y); } public double dot(Point2D a, Point2D b) { return a.x * b.x + a.y * b.y; } public double cross(Point2D a, Point2D b) { return a.x * b.y - a.y * b.x; } public boolean isOrthogonal(Point2D a, Point2D b) { return equals(dot(a, b), 0.0); } public boolean isOrthogonal(Point2D a1, Point2D a2, Point2D b1, Point2D b2) { return isOrthogonal(a1.diff(a2), b1.diff(b2)); } public boolean isParallel(Point2D a, Point2D b) { return equals(cross(a, b), 0.0); } public boolean isParallel(Point2D a1, Point2D a2, Point2D b1, Point2D b2) { return isParallel(a1.diff(a2), b1.diff(b2)); } public Point2D project(Point2D sp1, Point2D sp2, Point2D p) { Vector base = new Vector(sp2.diff(sp1)); double r = dot(p.diff(sp1), base) / base.norm(); return sp1.sum(base.multiple(r)); } public Point2D reflect(Point2D sp1, Point2D sp2, Point2D p) { return p.sum(project(sp1, sp2, p).diff(p).multiple(2.0)); } } }
[ { "input": "0 0 2 0\n2\n-1 1\n-1 -1\n", "output": "COUNTER_CLOCKWISE\nCLOCKWISE\n" } ]
Java
codenet
s196451707
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class s196451707 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] g = new int[n + 1][n + 1]; for (int i = 0; i < n; i++) { int u = sc.nextInt(); int k = sc.nextInt(); for (int j = 0; j < k; j++) { int v = sc.nextInt(); g[u][v] = 1; } } int[] d = new int[n + 1]; for (int i = 0; i <= n; i++) { d[i] = -1; } Queue<Integer> que = new LinkedList<>(); que.add(1); d[1] = 0; while (!que.isEmpty()) { int top = que.poll(); for (int j = 1; j <= n; j++) { if (g[top][j] == 1 && d[j] == -1) { que.add(j); d[j] = d[top] + 1; } } } for (int i = 1; i <= n; i++) { System.out.println(i + " " + d[i]); } } }
[ { "input": "4\n1 2 2 4\n2 1 4\n3 0\n4 1 3\n", "output": "1 0\n2 1\n3 2\n4 1\n" } ]
Java
codenet
s897176066
import java.util.*; public class s897176066 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = sc.nextLong(); } Arrays.sort(A); for (int j = 1; j < N; j++) { if (A[j] == A[j - 1]) { System.out.println("NO"); System.exit(0); } } System.out.println("YES"); } }
[ { "input": "5\n2 6 1 4 5\n", "output": "YES\n" } ]
Java
codenet
s648025110
import java.util.Scanner; public class s648025110 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n; n = sc.nextInt(); int[] h = new int[n]; for (int i = 0; i < n; i++) { h[i] = sc.nextInt(); } int ans = 0; int out = 0; for (int i = 0; i < h.length; i++) { if (out < h[i]) { ans += h[i] - out; out = h[i]; } else { out = h[i]; } } System.out.println(ans); } }
[ { "input": "4\n1 2 2 1\n", "output": "2\n" } ]
Java
codenet
s682993858
import java.util.Scanner; public class s682993858 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int sum = 0; String s = sc.next(); if ("0".equals(s)) { break; } for (int i = 0; i < s.length(); i++) { char a = s.charAt(i); sum += a - '0'; } System.out.printf("%d\n", sum); } } }
[ { "input": "123\n55\n1000\n0\n", "output": "6\n10\n1\n" } ]
Java
codenet
s332475184
import java.io.*; import java.util.*; class s332475184 { static int[] counter; static List<List<Integer>> graph; public static void main(String[] args) { FastScanner fs = new FastScanner(); int n = fs.nextInt(); int q = fs.nextInt(); graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new LinkedList<>()); } counter = new int[n]; Integer a; Integer b; for (int i = 0; i < n - 1; i++) { a = fs.nextInt() - 1; b = fs.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } for (int i = 0; i < q; i++) { counter[fs.nextInt() - 1] += fs.nextInt(); } dfs(0, -1, 0); StringJoiner sj = new StringJoiner(" "); for (int i = 0; i < n; i++) { sj.add(String.valueOf(counter[i])); } System.out.println(sj.toString()); } static void dfs(int v, int par, long val) { for (Integer i : graph.get(v)) { if (i != par) { dfs(i, v, val + counter[v]); } } counter[v] += val; } static class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr; private int buflen; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) { ptr++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } } }
[ { "input": "4 3\n1 2\n2 3\n2 4\n2 10\n1 100\n3 1\n", "output": "100 110 111 110\n" } ]
Java
codenet
s280174843
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class s280174843 { private static BufferedReader buf; public static void main(String[] args) throws IOException { int[] abc = new int[3]; String str; String[] inp; buf = new BufferedReader(new InputStreamReader(System.in)); str = buf.readLine(); inp = str.split(" ", -1); for (int i = 0; i < inp.length; i++) { abc[i] = Integer.parseInt(inp[i]); } if (abc[0] < abc[1] && abc[1] < abc[2]) { System.out.println("Yes"); } else { System.out.println("No"); } } }
[ { "input": "1 3 8\n", "output": "Yes\n" } ]
Java
codenet
s584135649
import java.util.Scanner; public class s584135649 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = 0; for (i = 1; i <= 5; i++) { int n = sc.nextInt(); if (n == 0) { break; } } System.out.println(i); } }
[ { "input": "0 2 3 4 5\n", "output": "1\n" } ]
Java
codenet
s379215956
import java.util.*; class s379215956 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); String s1 = s.substring(0, 1); String s2 = s.substring(1, 2); String s3 = s.substring(2, 3); String s4 = s.substring(3, 4); int a = 0; if (s1.equals(s2)) { a = 1; } if (s2.equals(s3)) { a = 1; } if (s3.equals(s4)) { a = 1; } if (a == 1) { System.out.println("Bad"); } else { System.out.println("Good"); } } }
[ { "input": "3776\n", "output": "Bad\n" } ]
Java
codenet
s580342216
import java.io.*; import java.util.*; public class s580342216 { public static void main(String[] args) throws java.lang.Exception { new Solution(); } } class Solution { Scanner scanner; public Solution() { scanner = new Scanner(System.in); while (scanner.hasNext()) { run_case(); } } private void run_case() { String line = scanner.nextLine(); int N = Integer.parseInt(line.split("\\s+")[0]); int K = Integer.parseInt(line.split("\\s+")[1]); int len = 0; while (N > 0) { N /= K; len++; } System.out.println(len); } private int[] strToIntArray(String str) { String[] vals = str.split("\\s+"); int sz = vals.length; int[] res = new int[sz]; for (int i = 0; i < sz; i++) { res[i] = Integer.parseInt(vals[i]); } return res; } } class LCS { int[][] dp; public int lcs(String A, String B) { int szA = A.length(); int szB = B.length(); dp = new int[szA + 1][szB + 1]; for (int i = 0; i <= szA; i++) { dp[i][0] = 0; } for (int j = 0; j <= szB; j++) { dp[0][j] = 0; } for (int i = 1; i <= szA; i++) { for (int j = 1; j <= szB; j++) { if (A.charAt(i - 1) == B.charAt(j - 1)) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); } } } return dp[szA][szB]; } public String getLCS(String X, String Y) { int m = X.length(); int n = Y.length(); int index = dp[m][n]; int temp = index; char[] lcs = new char[index + 1]; lcs[index] = '\0'; int i = m; int j = n; while (i > 0 && j > 0) { if (X.charAt(i - 1) == Y.charAt(j - 1)) { lcs[index - 1] = X.charAt(i - 1); i--; j--; index--; } else if (dp[i - 1][j] > dp[i][j - 1]) { i--; } else { j--; } } return String.valueOf(lcs).substring(0, temp + 2); } }
[ { "input": "11 2\n", "output": "4\n" } ]
Java
codenet
s126744620
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class s126744620 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } Integer[] x = new Integer[200010]; Arrays.fill(x, 0); for (int i = 0; i < n; i++) { x[a[i] - 1]++; } Arrays.sort( x, new Comparator<Integer>() { public int compare(Integer p1, Integer p2) { return p1 - p2; } }); int ans = 0; for (int i = 0; i <= 200010 - k - 1; i++) { ans += x[i]; } System.out.println(ans); } }
[ { "input": "5 2\n1 1 2 2 5\n", "output": "1\n" } ]
Java
codenet
s450226252
import java.util.Scanner; class s450226252 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); short r = stdIn.nextShort(); if (r < 1200) { System.out.println("ABC"); return; } if (r < 2800) { System.out.println("ARC"); return; } System.out.println("AGC"); } }
[ { "input": "1199\n", "output": "ABC\n" } ]
Java
codenet
s824230885
import java.io.*; import java.math.*; import java.util.*; public class s824230885 { static class InputIterator { ArrayList<String> inputLine = new ArrayList<>(1024); int index; int max; String read; InputIterator() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { while ((read = br.readLine()) != null) { inputLine.add(read); } } catch (IOException e) { } max = inputLine.size(); } boolean hasNext() { return index < max; } String next() { if (hasNext()) { return inputLine.get(index++); } else { throw new IndexOutOfBoundsException("There is no more input"); } } } static HashMap<Integer, String> CONVSTR = new HashMap<>(); static InputIterator ii = new InputIterator(); static PrintWriter out = new PrintWriter(System.out); static void flush() { out.flush(); } static void myout(Object t) { out.println(t); } static void myerr(Object t) { System.err.print("debug:"); System.err.println(t); } static String next() { return ii.next(); } static boolean hasNext() { return ii.hasNext(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static ArrayList<String> nextStrArray() { return myconv(next(), 8); } static ArrayList<String> nextCharArray() { return myconv(next(), 0); } static ArrayList<Integer> nextIntArray() { ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<>(input.size()); for (int i = 0; i < input.size(); i++) { ret.add(Integer.parseInt(input.get(i))); } return ret; } static ArrayList<Long> nextLongArray() { ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<>(input.size()); for (int i = 0; i < input.size(); i++) { ret.add(Long.parseLong(input.get(i))); } return ret; } static String myconv(Object list, int no) { String joinString = CONVSTR.get(no); if (list instanceof String[]) { return String.join(joinString, (String[]) list); } else if (list instanceof ArrayList) { return String.join(joinString, (ArrayList) list); } else { throw new ClassCastException("Don't join"); } } static ArrayList<String> myconv(String str, int no) { String splitString = CONVSTR.get(no); return new ArrayList<>(Arrays.asList(str.split(splitString))); } public static void main(String[] args) { CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, ""); solve(); flush(); } static void solve() { int N = nextInt(); ArrayList<Integer> list = nextIntArray(); int max = 0; int output = 0; for (int i = 0; i < N; i++) { if (max <= list.get(i)) { max = list.get(i); output++; } } myout(output); } }
[ { "input": "4\n6 5 6 8\n", "output": "3\n" } ]
Java
codenet
s584572995
import java.io.*; import java.util.*; public class s584572995 { static int mod = (int) 1e9 + 7; static List<ArrayList<Integer>> to; static int[] dp; public static void main(String[] args) { FastScanner fs = new FastScanner(System.in); int N = fs.nextInt(); to = new ArrayList<>(); for (int i = 0; i < N; i++) { to.add(new ArrayList<Integer>()); } int[][] edges = new int[N - 1][2]; for (int i = 0; i < N - 1; i++) { int A = fs.nextInt() - 1; int B = fs.nextInt() - 1; to.get(A).add(B); to.get(B).add(A); edges[i][0] = B; edges[i][1] = A; } dp = new int[N]; rec(0, -1); long mulsum = 0; for (int[] e : edges) { int candidate1 = e[0]; int candidate2 = e[1]; int child = candidate1; if (dp[candidate1] > dp[candidate2]) { child = candidate2; } long a = dp[child]; long b = N - a; long mul = (modpow(2, a) - 1) * (modpow(2, b) - 1) % mod; mulsum += mul; mulsum %= mod; } long cases = modpow(2, N); long pn = (mulsum + (cases - 1 + mod) % mod) % mod; long bn = N * modpow(2, N - 1) % mod; long wn = (pn - bn + mod) % mod; long ans = wn * modpow(cases, mod - 2); ans %= mod; System.out.println(ans); } static int rec(int v, int parent) { int res = 1; for (int next : to.get(v)) { if (next == parent) { continue; } res += rec(next, v); } return dp[v] = res; } static long modpow(long x, long y) { if (y == 0) { return 1; } if (y % 2 != 0) { return x * modpow(x, y - 1) % mod; } long tmp = modpow(x, y / 2); return tmp * tmp % mod; } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public String next() { if (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 || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } }
[ { "input": "3\n1 2\n2 3\n", "output": "125000001\n" } ]
Java
codenet
s125881159
import static java.lang.System.*; import java.util.*; public class s125881159 { public static void main(String[] $) { Scanner sc = new Scanner(in); int n = sc.nextInt(); int d = 0; for (int i = 0; i < n; i++) { d += sc.nextInt() % 2; } out.println(d % 2 == 0 ? "YES" : "NO"); } }
[ { "input": "3\n1 2 3\n", "output": "YES\n" } ]
Java
codenet
s725559666
import java.util.Scanner; class s725559666 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); scan.close(); if (a < b && b < c && a < c) { System.out.println("Yes"); } else { System.out.println("No"); } } }
[ { "input": "1 3 8\n", "output": "Yes\n" } ]
Java
codenet
s733150445
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigDecimal; import java.util.StringTokenizer; public class s733150445 { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); BigDecimal a = new BigDecimal(st.nextToken()); BigDecimal b = new BigDecimal(st.nextToken()); BigDecimal mul = a.multiply(b); st = new StringTokenizer(mul.toString(), "."); System.out.println(st.nextElement()); } }
[ { "input": "198 1.10\n", "output": "217\n" } ]