language
stringclasses
1 value
dataset
stringclasses
1 value
id
stringlengths
10
10
code
stringlengths
220
26.6k
test_IO
list
Java
codenet
s387083574
import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.stream.Collectors; public class s387083574 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); Map<Integer, Integer> map = new HashMap<>(); for (int i = 1; i < N + 1; i++) { map.put(i, sc.nextInt()); } System.out.println( String.join( " ", map.entrySet().stream() .sorted(Entry.<Integer, Integer>comparingByValue()) .map(Map.Entry::getKey) .map(String::valueOf) .collect(Collectors.toList()))); } }
[ { "input": "3\n2 3 1\n", "output": "3 1 2\n" } ]
Java
codenet
s601569023
import java.util.Scanner; class s601569023 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); if (num < 1200) { System.out.println("ABC"); } else { System.out.println("ARC"); } } }
[ { "input": "1000\n", "output": "ABC\n" } ]
Java
codenet
s449886393
import static java.lang.System.*; import java.math.*; import java.util.*; public class s449886393 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] youbi = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; String s = sc.next(); int ans = 0; for (int i = 0; i < youbi.length; i++) { if (youbi[i].equals(s)) { ans = 7 - i; } } out.println(ans); } }
[ { "input": "SAT\n", "output": "1\n" } ]
Java
codenet
s513933260
import java.util.Scanner; public class s513933260 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); long n = stdIn.nextLong(); System.out.println(n * (n + 1) / 2 - n); } }
[ { "input": "2\n", "output": "1\n" } ]
Java
codenet
s325080396
import java.util.Scanner; class s325080396 { static final int MAX = 200000; public static void main(String[] args) { int[] R = new int[MAX]; Scanner in = new Scanner(System.in); int n = in.nextInt(); for (int i = 0; i < n; i++) { R[i] = in.nextInt(); } int maxv = R[1] - R[0]; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = Math.max(maxv, R[i] - minv); minv = Math.min(minv, R[i]); } System.out.println(maxv); } }
[ { "input": "6\n5\n3\n1\n3\n4\n3\n", "output": "3\n" } ]
Java
codenet
s041542819
import java.io.*; import java.nio.charset.Charset; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.StringTokenizer; public class s041542819 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; LightScanner in = new LightScanner(inputStream); LightWriter out = new LightWriter(outputStream); DLazyFaith solver = new DLazyFaith(); solver.solve(1, in, out); out.close(); } static class DLazyFaith { public void solve(int testNumber, LightScanner in, LightWriter out) { int a = in.ints(); int b = in.ints(); int q = in.ints(); long[] s = new long[a + 2]; long[] t = new long[b + 2]; s[0] = t[0] = -10_000_000_000L; for (int i = 0; i < a; i++) { s[i + 1] = in.longs(); } for (int i = 0; i < b; i++) { t[i + 1] = in.longs(); } s[a + 1] = t[b + 1] = 20_000_000_000L; for (int i = 0; i < q; i++) { long x = in.longs(); long sl = x - s[Math.max(0, ArrayUtil.lowerBound(s, x + 1) - 1)]; long tl = x - t[Math.max(0, ArrayUtil.lowerBound(t, x + 1) - 1)]; long sr = s[ArrayUtil.lowerBound(s, x)] - x; long tr = t[ArrayUtil.lowerBound(t, x)] - x; out.ansln( IntMath.min( Math.max(sl, tl), Math.max(sr, tr), 2 * sl + tr, 2 * tl + sr, sl + 2 * tr, tl + 2 * sr)); } } } static class LightScanner { private BufferedReader reader; private StringTokenizer tokenizer; public LightScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public String string() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new UncheckedIOException(e); } } return tokenizer.nextToken(); } public int ints() { return Integer.parseInt(string()); } public long longs() { return Long.parseLong(string()); } } static class LightWriter implements AutoCloseable { private final Writer out; private boolean autoflush; private boolean breaked = true; public LightWriter(Writer out) { this.out = out; } public LightWriter(OutputStream out) { this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset()))); } public LightWriter print(char c) { try { out.write(c); breaked = false; } catch (IOException ex) { throw new UncheckedIOException(ex); } return this; } public LightWriter print(String s) { try { out.write(s, 0, s.length()); breaked = false; } catch (IOException ex) { throw new UncheckedIOException(ex); } return this; } public LightWriter ans(String s) { if (!breaked) { print(' '); } return print(s); } public LightWriter ans(long l) { return ans(Long.toString(l)); } public LightWriter ansln(long... n) { for (long n1 : n) { ans(n1).ln(); } return this; } public LightWriter ln() { print(System.lineSeparator()); breaked = true; if (autoflush) { try { out.flush(); } catch (IOException ex) { throw new UncheckedIOException(ex); } } return this; } public void close() { try { out.close(); } catch (IOException ex) { throw new UncheckedIOException(ex); } } } static final class IntMath { private IntMath() {} public static long min(long... v) { return Arrays.stream(v).min().orElseThrow(NoSuchElementException::new); } } static final class ArrayUtil { private ArrayUtil() {} public static int lowerBound(long[] a, long t) { return lowerBound(a, t, 0); } public static int lowerBound(long[] a, long t, int min) { int max = a.length; while (min < max) { int mid = (min + max) / 2; if (t <= a[mid]) { max = mid; } else { min = mid + 1; } } return min; } } }
[ { "input": "2 3 4\n100\n600\n400\n900\n1000\n150\n2000\n899\n799\n", "output": "350\n1400\n301\n399\n" } ]
Java
codenet
s902370101
import java.util.Scanner; public class s902370101 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] array = new int[n]; int max = 0; int min = 10000; for (int i = 0; i < array.length; i++) { array[i] = sc.nextInt(); if (max < array[i]) { max = array[i]; } if (min > array[i]) { min = array[i]; } } System.out.println(max - min); sc.close(); } }
[ { "input": "4\n2 3 7 9\n", "output": "7\n" } ]
Java
codenet
s573993837
import java.io.*; import java.util.*; public class s573993837 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); solve(in, out); out.close(); } static int L; static int R; static int top; static int bottom; public static void solve(InputReader sc, PrintWriter pw) { int t = 1; u: while (t-- > 0) { long n = sc.nextLong(); long m = sc.nextLong(); if (n == 0) { pw.println(0); continue u; } if (n == m) { pw.println(0); continue u; } if (n > m) { n = m + n % m; n -= m; pw.println(Math.min(m - n, n)); continue u; } pw.println(Math.min(m - n, n)); } } public static void swap(char[] chrr, int i, int j) { char temp = chrr[i]; chrr[i] = chrr[j]; chrr[j] = temp; } public static int num(int n) { int a = 0; while (n > 0) { a += n & 1; n >>= 1; } return a; } static class Pair { int u; int v; int i; int val; Pair(int a, int b, int i) { this.u = a; this.v = b; this.i = i; } } static boolean isPrime(int n) { if (n <= 1) { return false; } if (n <= 3) { return true; } if (n % 2 == 0 || n % 3 == 0) { return false; } for (int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } static long gcd(long a, long b) { if (b == 0) { return a; } return a > b ? gcd(b, a % b) : gcd(a, b % a); } static long fast_pow(long base, long n, long M) { if (n == 0) { return 1; } if (n == 1) { return base; } long halfn = fast_pow(base, n / 2, M); if (n % 2 == 0) { return (halfn * halfn) % M; } else { return (((halfn * halfn) % M) * base) % M; } } static long modInverse(long n, long M) { return fast_pow(n, M - 2, M); } public static void feedArr(long[] arr, InputReader sc) { for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextLong(); } } public static void feedArr(double[] arr, InputReader sc) { for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextDouble(); } } public static void feedArr(int[] arr, InputReader sc) { for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); } } public static void feedArr(String[] arr, InputReader sc) { for (int i = 0; i < arr.length; i++) { arr[i] = sc.next(); } } public static String printArr(int[] arr) { StringBuilder sbr = new StringBuilder(); for (int i : arr) sbr.append(i).append(" "); return sbr.toString(); } public static String printArr(long[] arr) { StringBuilder sbr = new StringBuilder(); for (long i : arr) sbr.append(i).append(" "); return sbr.toString(); } public static String printArr(String[] arr) { StringBuilder sbr = new StringBuilder(); for (String i : arr) sbr.append(i + " "); return sbr.toString(); } public static String printArr(double[] arr) { StringBuilder sbr = new StringBuilder(); for (double i : arr) sbr.append(i).append(" "); return sbr.toString(); } 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": "7 4\n", "output": "1\n" } ]
Java
codenet
s511234019
import java.io.*; import java.util.*; public class s511234019 { public static void main(String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int a; int b; a = in.nextInt(); b = in.nextInt(); if (a % 2 == 0 || b % 2 == 0) { System.out.println("No"); } else { System.out.println("Yes"); } } }
[ { "input": "3 1\n", "output": "Yes\n" } ]
Java
codenet
s494783955
import java.util.*; public class s494783955 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String C = sc.next(); System.out.println((char) (C.charAt(0) + 1)); } }
[ { "input": "a\n", "output": "b\n" } ]
Java
codenet
s059916837
import java.util.Scanner; public class s059916837 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String S = scanner.nextLine(); String T = scanner.nextLine(); int min = Integer.MAX_VALUE; for (int i = 0; i <= S.length() - T.length(); i++) { min = Math.min(min, find(S.substring(i, i + T.length()), T)); } if (min != Integer.MAX_VALUE) { System.out.println(min); } else { System.out.println(T.length()); } } public static int find(String a, String b) { int calc = 0; for (int x = 0; x < a.length(); x++) { if (a.charAt(x) != b.charAt(x)) { calc++; } } return calc; } }
[ { "input": "cabacc\nabc\n", "output": "1\n" } ]
Java
codenet
s458826999
import java.util.Scanner; public class s458826999 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String S = sc.next(); long mod = 1000000007; long[][] dp = new long[S.length() + 1][13]; dp[0][0] = 1; for (int i = 0; i < S.length(); i++) { if ("?".equals(S.substring(i, i + 1))) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; dp[i + 1][(k * 10 + j) % 13] %= mod; } } } else { for (int k = 0; k < 13; k++) { int x = Integer.parseInt(S.substring(i, i + 1)); dp[i + 1][(k * 10 + x) % 13] += dp[i][k]; dp[i + 1][(k * 10 + x) % 13] %= mod; } } } System.out.println(dp[S.length()][5]); } }
[ { "input": "??2??5\n", "output": "768\n" } ]
Java
codenet
s780604068
import java.util.*; public class s780604068 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] map = new int[N * 2]; for (int i = 0; i < N * 2; i++) { map[i] = sc.nextInt(); } Arrays.sort(map); int max = 0; for (int i = 0; i < N * 2; i += 2) { max += Math.min(map[i], map[i + 1]); } System.out.println(max); } }
[ { "input": "2\n1 3 1 2\n", "output": "3\n" } ]
Java
codenet
s685537842
import java.util.Scanner; public class s685537842 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int t = sc.nextInt(); double time = 0; int count = 0; while (time < t + 0.5) { count += b; time += a; if (time > t + 0.5) { count -= b; break; } } System.out.println(count); } }
[ { "input": "3 5 7\n", "output": "10\n" } ]
Java
codenet
s319823779
import java.util.*; class s319823779 { 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 x = sc.nextInt(); int res = 0; for (int i = 0; i <= a; i++) { for (int j = 0; j <= b; j++) { for (int k = 0; k <= c; k++) { int total = 500 * i + 100 * j + 50 * k; if (total == x) { res++; } } } } System.out.println(res); } }
[ { "input": "2\n2\n2\n100\n", "output": "2\n" } ]
Java
codenet
s320655609
import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; public class s320655609 { List<Long> constraints = new ArrayList<>(); long N; long result; s320655609() throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(reader); this.N = Long.parseLong(in.readLine()); for (int i = 0; i < 5; ++i) { this.constraints.add(Long.parseLong(in.readLine())); } in.close(); this.calc(); } void calc() { long min = Long.MAX_VALUE; for (Long c : this.constraints) { min = Math.min(min, c); } long time = this.N / min; if (this.N % min != 0) { ++time; } time += 4; this.result = time; } public static void main(String[] args) throws IOException { s320655609 ins = new s320655609(); System.out.println(ins.result); } }
[ { "input": "5\n3\n2\n4\n3\n5\n", "output": "7\n" } ]
Java
codenet
s047401835
import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class s047401835 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); List<Integer> numbers = new ArrayList(); for (int i = 0; i < N; i++) { numbers.add(Integer.parseInt(scanner.next())); } int count = 0; do { numbers = numbers.stream() .filter(i -> (i % 2) == 0) .map(i -> i / 2) .collect(Collectors.toList()); if (numbers.size() == N) { count++; } } while (numbers.size() == N); System.out.println(count); } }
[ { "input": "3\n8 12 40\n", "output": "2\n" } ]
Java
codenet
s831281137
import java.io.PrintStream; import java.util.Scanner; public class s831281137 { static final Scanner sc = new Scanner(System.in); static final PrintStream so = System.out; public static void main(String[] args) { int N = nint(); int W = nint(); int[] v = new int[N + 1]; int[] w = new int[N + 1]; for (int i = 1; i <= N; i++) { v[i] = nint(); w[i] = nint(); } int[][] sumV = new int[N + 1][W + 1]; for (int i = 1; i <= N; i++) { for (int i_sum = 0; i_sum < w[i]; i_sum++) { sumV[i][i_sum] = sumV[i - 1][i_sum]; } for (int i_sum = w[i]; i_sum <= W; i_sum++) { sumV[i][i_sum] = Math.max(sumV[i - 1][i_sum], sumV[i - 1][i_sum - w[i]] + v[i]); } } so.println(sumV[N][W]); } private static long nlong() { return sc.nextLong(); } private static int nint() { return sc.nextInt(); } private static String nstr() { return sc.next(); } private static char[] nsToChars() { return sc.next().toCharArray(); } private static long[] nlongs(int n) { return nlongs(n, 0, 0); } private static int[] nints(int n) { return nints(n, 0, 0); } private static int[] nints(int n, int padL, int padR) { int[] a = new int[padL + n + padR]; for (int i = 0; i < n; i++) { a[padL + i] = nint(); } return a; } private static long[] nlongs(int n, int padL, int padR) { long[] a = new long[padL + n + padR]; for (int i = 0; i < n; i++) { a[padL + i] = nlong(); } return a; } private static String[] nstrs(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) { a[i] = nstr(); } return a; } private static char[][] nsToChars2D(int h, int w) { return nsToChars2D(h, w, 0); } private static char[][] nsToChars2D(int h, int w, int pad) { char[][] a2 = new char[h + pad * 2][w + pad * 2]; for (int i = 0; i < h; i++) { System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w); } return a2; } }
[ { "input": "4 5\n4 2\n5 2\n2 1\n8 3\n", "output": "13\n" } ]
Java
codenet
s745776078
import java.io.*; import java.util.*; public class s745776078 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int[][] A = new int[n][m]; int[] b = new int[m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { A[i][j] = in.nextInt(); } } for (int i = 0; i < m; i++) { b[i] = in.nextInt(); } for (int i = 0; i < n; i++) { int c = 0; for (int j = 0; j < m; j++) { c += A[i][j] * b[j]; } out.println(c); } out.flush(); } }
[ { "input": "3 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0\n", "output": "5\n6\n9\n" } ]
Java
codenet
s826491904
import java.util.*; public class s826491904 { public static void main(String[] args) { new s826491904().solve(); } private final Scanner sc = new Scanner(System.in); void solve() { int N = sc.nextInt(); int max; int min; max = min = sc.nextInt(); for (int i = 1; i < N; i++) { int in = sc.nextInt(); max = Math.max(max, in); min = Math.min(min, in); } System.out.println(max - min); } }
[ { "input": "4\n2 3 7 9\n", "output": "7\n" } ]
Java
codenet
s893190600
import static java.util.Comparator.*; import java.io.*; import java.util.*; public class s893190600 { 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(in, out); solver.solve(); out.close(); } static class Solver { MyInput in; PrintWriter out; public Solver(MyInput in, PrintWriter out) { this.in = in; this.out = out; } public void solve() { int H = ni(); int W = ni(); char[][] C = new char[H + 2][W + 2]; char[] c; for (int i = 0; i < H; i++) { c = ns().toCharArray(); for (int j = 0; j < W; j++) { C[i + 1][j + 1] = c[j]; } } if (H == 1 && W == 1) { prn("No"); return; } for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) { if (C[i][j] == '#' && C[i - 1][j] != '#' && C[i + 1][j] != '#' && C[i][j - 1] != '#' && C[i][j + 1] != '#') { prn("No"); return; } } } prn("Yes"); } static class MapCounter { private TreeMap<Integer, Integer> map; public MapCounter() { map = new TreeMap<>(); } public MapCounter(boolean reverse) { if (reverse) { map = new TreeMap<Integer, Integer>(Collections.reverseOrder()); } else { map = new TreeMap<>(); } } public void add(Integer key) { add(key, 1); } public void add(Integer key, int cnt) { Integer val = map.get(key); if (val == null) { map.put(key, cnt); } else { map.put(key, val + cnt); } } public void remove(Integer key) { sub(key, 1, false); } public void sub(Integer key) { sub(key, 1); } public void sub(Integer key, int cnt) { sub(key, cnt, true); } public void sub(Integer key, int cnt, boolean minus) { Integer val = map.get(key); if (val == null) { if (minus) { map.put(key, -cnt); } } else if (val > cnt || minus) { map.put(key, val - cnt); } else { map.remove(key); } } public void set(Integer key, int cnt) { map.put(key, cnt); } public Integer getCountwithNull(Integer key) { return map.get(key); } public Integer getCount(Integer key) { Integer val = map.get(key); if (val == null) { return 0; } else { return val; } } public Set<Integer> getKey() { return map.keySet(); } public int getKeyCount() { return map.keySet().size(); } public Integer getFirstKey() { return map.firstKey(); } public Integer getLastKey() { return map.lastKey(); } public void clear() { map.clear(); } } boolean isRightMin(int[] a, boolean f, int index, int key) { if (f && a[index] >= key) { return true; } else if (!f && a[index] > key) { return true; } else { return false; } } int binarySearchRightMin(int[] a, boolean f, int key) { int ng = -1; int ok = (int) a.length; while (Math.abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isRightMin(a, f, mid, key)) { ok = mid; } else { ng = mid; } } return ok; } boolean isLeftMax(int[] a, boolean f, int index, int key) { if (f && a[index] <= key) { return true; } else if (!f && a[index] < key) { return true; } else { return false; } } int binarySearchLeftMax(int[] a, boolean f, int key) { int ng = -1; int ok = (int) a.length; while (Math.abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isLeftMax(a, f, mid, key)) { ng = mid; } else { ok = mid; } } return ng; } static class EulerTour { Graph g; List<Integer> euler_tour = new ArrayList<>(); int[] begin; int[] end; int k; int root; void dfs(int v, int p, PrintWriter out) { out.println("v = " + v + " p = " + p); begin[v] = k; euler_tour.add(v); k++; if (!g.contains(v)) { return; } for (int i : g.get(v)) { if (i != p) { dfs(i, v, out); euler_tour.add(v); k++; } } end[v] = k; } public void init(int p_cnt, int root, Graph g, PrintWriter out) { begin = new int[p_cnt + 1]; end = new int[p_cnt + 1]; this.root = root; this.g = g; dfs(root, -1, out); } public List getPartTour(int v) { return euler_tour.subList(begin[v], end[v]); } public List<Integer> getPartList(int v) { Set<Integer> set = new TreeSet<>(); set.addAll(getPartTour(v)); List<Integer> ans = new ArrayList<>(); for (Integer p : set) { ans.add(p); } return ans; } } class Graph { private Map<Integer, List<Integer>> data = new HashMap<Integer, List<Integer>>(); void add(int from, int to) { List<Integer> list = data.get(from); if (list == null) { list = new ArrayList<Integer>(); data.put(from, list); } list.add(to); } void del(int from, int to) { List<Integer> list = data.get(from); if (list == null) { return; } if (list.contains(to)) { list.remove((Object) to); } } List<Integer> get(int key) { return data.get(key); } boolean contains(int key) { return data.containsKey(key); } Set<Integer> keySet() { return data.keySet(); } boolean isConnect(int key_1, int key_2) { List<Integer> list = data.get(key_1); if (list == null) { return false; } else { return list.contains(key_2); } } List<PP> distList(int key) { List<PP> dist = new ArrayList<>(); Set<Integer> mark = new HashSet<>(); Stack<PP> stack = new Stack<>(); stack.push(new PP(key, 0)); while (!stack.isEmpty()) { PP wk = stack.pop(); int pp = wk.getKey(); int dd = wk.getVal(); mark.add(pp); dist.add(new PP(pp, dd)); List<Integer> list = get(pp); for (int next : list) { if (mark.contains(next)) { continue; } stack.push(new PP(next, dd + 1)); } } return dist; } int[] distV(int key) { int[] dist = new int[data.keySet().size() + 1]; Arrays.fill(dist, -1); Set<Integer> mark = new HashSet<>(); Stack<PP> stack = new Stack<>(); stack.push(new PP(key, 0)); while (!stack.isEmpty()) { PP wk = stack.pop(); int pp = wk.getKey(); int dd = wk.getVal(); mark.add(pp); dist[pp] = dd; List<Integer> list = get(pp); for (int next : list) { if (mark.contains(next)) { continue; } stack.push(new PP(next, dd + 1)); } } return dist; } Map<Integer, Integer> mapCnt = new HashMap<>(); Map<Integer, Integer> mapLow = new HashMap<>(); Set<Integer> mark = new HashSet<>(); int number; int bridgeDfs(int now, int pre) { mark.add(now); mapCnt.put(now, number); mapLow.put(now, number); int low; for (int next : get(now)) { if (next == pre) { continue; } if (mark.contains(next)) { if (mapLow.get(now) > mapLow.get(next)) { mapLow.put(now, mapLow.get(next)); } continue; } number++; low = bridgeDfs(next, now); if (mapLow.get(now) > low) { mapLow.put(now, low); } } return mapLow.get(now); } int bridgeCnt(int start) { mapCnt.clear(); mapLow.clear(); mark.clear(); number = 0; bridgeDfs(start, start); int ans = 0; for (int key : mapCnt.keySet()) { if (mapCnt.get(key) == mapLow.get(key)) { ans++; } } return ans - 1; } void dump(PrintWriter out) { for (int key : data.keySet()) { out.print(key + " : "); for (int val : data.get(key)) { out.print(val + " "); } out.println(""); } } } static class GraphWith { private Map<Integer, List<PP>> data = new HashMap<Integer, List<PP>>(); void add(int key, PP p) { List<PP> list = data.get(key); if (list == null) { list = new ArrayList<PP>(); data.put(key, list); } list.add(p); } List<PP> get(int key) { return data.get(key); } boolean contains(int key) { return data.containsKey(key); } Set<Integer> keySet() { return data.keySet(); } boolean isConnect(int key_1, int key_2) { List<PP> list = data.get(key_1); if (list == null) { return false; } boolean ans = false; for (PP p : list) { if (p.getKey() == key_2) { ans = true; break; } } return ans; } int distance(int key_1, int key_2) { Set<Integer> mark = new HashSet<>(); Stack<PP> stack = new Stack<>(); stack.push(new PP(key_1, 0)); PP wk; int key; int val; List<PP> list; while (!stack.isEmpty()) { wk = stack.pop(); key = wk.getKey(); val = wk.getVal(); mark.add(key); if (key == key_2) { return val; } list = get(key); if (list == null) { continue; } for (PP pp : list) { if (mark.contains(pp.getKey())) { continue; } stack.push(new PP(pp.getKey(), val + pp.getVal())); } } return Integer.MAX_VALUE; } } static class GraphLong { private Map<Long, List<Long>> G = new HashMap<Long, List<Long>>(); void add(long key, long value) { List<Long> list = G.get(key); if (list == null) { list = new ArrayList<Long>(); G.put(key, list); } list.add(value); } List<Long> get(long key) { return G.get(key); } } static class GraphLongWith { private Map<Long, List<PPL>> G = new HashMap<Long, List<PPL>>(); void add(long key, PPL p) { List<PPL> list = G.get(key); if (list == null) { list = new ArrayList<PPL>(); G.put(key, list); } list.add(p); } List<PPL> get(long key) { return G.get(key); } } void prn(String s) { out.println(s); } void prn(int i) { out.println(i); } void prn(long i) { out.println(i); } void prr(String s) { out.print(s); } int ni() { return in.nextInt(); } long nl() { return in.nextLong(); } double nd() { return in.nextDouble(); } String ns() { return in.nextString(); } int[] ndi(int n) { int[] ans = new int[n]; for (int i = 0; i < n; i++) { ans[i] = ni(); } return ans; } long[] ndl(int n) { long[] ans = new long[n]; for (int i = 0; i < n; i++) { ans[i] = nl(); } return ans; } double[] ndd(int n) { double[] ans = new double[n]; for (int i = 0; i < n; i++) { ans[i] = nd(); } return ans; } String[] nds(int n) { String[] ans = new String[n]; for (int i = 0; i < n; i++) { ans[i] = ns(); } return ans; } int[][] nddi(int n, int m) { int[][] ans = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans[i][j] = ni(); } } return ans; } long[][] nddl(int n, int m) { long[][] ans = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans[i][j] = nl(); } } return ans; } } static class PP { public int key; public int val; public PP(int key, int val) { this.key = key; this.val = val; } public int getKey() { return key; } public void setKey(int key) { this.key = key; } public int getVal() { return val; } public void setVal(int val) { this.val = val; } } static class PPP { public int key; public int val1; public int val2; public PPP(int key, int val1, int val2) { this.key = key; this.val1 = val1; this.val2 = val2; } public int getKey() { return key; } public void setKey(int key) { this.key = key; } public int getVal1() { return val1; } public void setVal1(int val1) { this.val1 = val1; } public int getVal2() { return val2; } public void setVal2(int val2) { this.val2 = val2; } } static class PPL { public long key; public long val; public PPL(long key, long val) { this.key = key; this.val = val; } public long getKey() { return key; } public void setKey(long key) { this.key = key; } public long getVal() { return val; } public void setVal(long val) { this.val = val; } } static class PPDL { public long key; public long[] val; public PPDL(long key, long[] val) { this.key = key; this.val = val; } public long getKey() { return key; } public void setKey(long key) { this.key = key; } public long[] getVal() { return val; } public void setVal(long[] val) { this.val = val; } public void dump(PrintWriter out) { out.print("key = " + key + " val "); for (int i = 0; i < val.length; i++) { out.print("[" + val[i] + "] "); } out.println(""); } } static final class PPKEY { private final int key; private final int val; public PPKEY(int key, int val) { this.key = key; this.val = val; } public int getKey() { return key; } public int getVal() { return val; } @Override public boolean equals(Object obj) { if (obj instanceof PPKEY) { PPKEY dest = (PPKEY) obj; return this.key == dest.key && this.val == dest.val; } else { return false; } } @Override public int hashCode() { return Objects.hash(key, val); } } static final class PPLKEY { private final long key; private final long val; public PPLKEY(long key, long val) { this.key = key; this.val = val; } public long getKey() { return key; } public long getVal() { return val; } @Override public boolean equals(Object obj) { if (obj instanceof PPKEY) { PPKEY dest = (PPKEY) obj; return this.key == dest.key && this.val == dest.val; } else { return false; } } @Override public int hashCode() { return Objects.hash(key, val); } } 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); } } 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 double nextDouble() { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; double ret = 0; if (str[0] == '-') { i = 1; } int cnt = 0; for (; i < len; i++) { if (str[i] == '.') { cnt = 10; continue; } if (cnt == 0) { ret = ret * 10 + str[i] - '0'; } else { ret = ret + ((double) (str[i] - '0') / cnt); cnt *= 10; } } 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": "3 3\n.#.\n###\n.#.\n", "output": "Yes\n" } ]
Java
codenet
s739337307
import java.math.*; import java.util.*; class s739337307 { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { int n = Integer.parseInt(sc.next()); int m = Integer.parseInt(sc.next()); HashMap<Integer, Integer> map = new HashMap<>(); int countAc = 0; int countWaAll = 0; for (int i = 0; i < m; i++) { int question = Integer.parseInt(sc.next()); String waOrAc = sc.next(); if (!map.containsKey(question)) { if ("WA".equals(waOrAc)) { map.put(question, 1); } else { map.put(question, -1); countAc++; } } else { int countWa = map.get(question); if (countWa >= 0) { if ("WA".equals(waOrAc)) { map.replace(question, countWa, countWa + 1); } else { map.replace(question, countWa, -countWa); countAc++; countWaAll += countWa; } } } } System.out.println(countAc + " " + countWaAll); } catch (Exception e) { e.printStackTrace(); } } }
[ { "input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n", "output": "2 2\n" } ]
Java
codenet
s596918302
import java.util.*; public class s596918302 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] arr = new int[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { arr[i][j] = sc.nextInt(); } } int ans = 0; ans = dpx(arr, n); System.out.println(ans); } static int min(int[] arr, int n) { if (n == 1) { return 0; } if (n == 2) { return Math.abs(arr[n - 1] - arr[n - 2]); } int op1 = Math.abs(arr[n - 1] - arr[n - 2]) + min(arr, n - 1); int op2 = Math.abs(arr[n - 1] - arr[n - 3]) + min(arr, n - 2); return Math.min(op1, op2); } static int dpc(int[][] arr, int i, int n, int row) { if (row == n) { return 0; } int j = 0; int k = 0; if (i == 1) { j = 0; k = 2; } else if (i == 0) { j = 1; k = 2; } else { j = 0; k = 1; } return arr[row][i] + Math.max(dpc(arr, j, n, row + 1), dpc(arr, k, n, row + 1)); } static int dpx(int[][] arr, int n) { 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 in = 0; in < 3; in++) { int j = 0; int k = 0; if (in == 1) { j = 0; k = 2; } else if (in == 0) { j = 1; k = 2; } else { j = 0; k = 1; } dp[i][in] = Math.max(dp[i - 1][k], dp[i - 1][j]) + arr[i][in]; } } return Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])); } }
[ { "input": "3\n10 40 70\n20 50 80\n30 60 90\n", "output": "210\n" } ]
Java
codenet
s701317277
import java.util.*; public class s701317277 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] A = new int[N]; int min = Integer.MAX_VALUE; int count = 0; long sum = 0; for (int i = 0; i < N; i++) { A[i] = sc.nextInt(); if (A[i] < 0) { count++; } min = Math.min(min, Math.abs(A[i])); sum += Math.abs(A[i]); } sc.close(); if (count % 2 == 0) { System.out.println(sum); } else { System.out.println(sum - min * 2); } } }
[ { "input": "3\n-10 5 -4\n", "output": "19\n" } ]
Java
codenet
s125278297
import java.util.*; public class s125278297 { static Scanner scanner = new Scanner(System.in); public static void main(String[] $) { int h = scanner.nextInt(); int w = scanner.nextInt(); String[] ans = new String[h]; for (int i = 0; i < h; i++) { ans[i] = "#" + scanner.next() + "#"; } System.out.println(String.valueOf(new char[w + 2]).replace('\0', '#')); for (String s : ans) { System.out.println(s); } System.out.println(String.valueOf(new char[w + 2]).replace('\0', '#')); } }
[ { "input": "2 3\nabc\narc\n", "output": "#####\n#abc#\n#arc#\n#####\n" } ]
Java
codenet
s670290220
import java.util.*; class s670290220 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); char[] c = sc.next().toCharArray(); for (int i = 0; i < c.length; i++) { c[i] = (char) ((c[i] - 'A' + N) % 26 + 'A'); } System.out.println(c); } }
[ { "input": "2\nABCXYZ\n", "output": "CDEZAB\n" } ]
Java
codenet
s552480860
import java.util.*; public class s552480860 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int h1 = sc.nextInt(); int m1 = sc.nextInt(); int h2 = sc.nextInt(); int m2 = sc.nextInt(); int k = sc.nextInt(); int t1 = h1 * 60 + m1; int t2 = h2 * 60 + m2; System.out.println(t2 - t1 - k); } }
[ { "input": "10 0 15 0 30\n", "output": "270\n" } ]
Java
codenet
s504715611
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Random; import java.util.Scanner; class UnionFind { int[] Parent; UnionFind(int n) { Parent = new int[n]; Arrays.fill(Parent, -1); } int root(int A) { if (Parent[A] < 0) { return A; } return Parent[A] = root(Parent[A]); } int size(int A) { return -Parent[root(A)]; } boolean connect(int A, int B) { A = root(A); B = root(B); if (A == B) { return false; } if (size(A) < size(B)) { int C = 0; C = B; B = A; A = C; } Parent[A] += Parent[B]; Parent[B] = A; return true; } } public class s504715611 { static FastScanner scan = new FastScanner(); static Scanner scanner = new Scanner(System.in); static Random rand = new Random(); static long mod = 1000000007; static double eps = 1.0E-14; static int big = Integer.MAX_VALUE; static double PI = 3.14159265358979323846262338327950288; static long modlcm(long a, long b) { return a * b * modint(gcd(a, b), mod); } static long gcd(long a, long b) { return b > 0 ? gcd(b, a % b) : a; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static int max(int a, int b) { return a > b ? a : b; } static int min(int a, int b) { return a < b ? a : b; } static long lmax(long a, long b) { return Math.max(a, b); } static long lmin(long a, long b) { return Math.min(a, b); } static long factorial(int i) { return i == 1 ? 1 : i * factorial(i - 1); } public static void main(String[] args) throws IOException { String str = scan.next(); System.out.println( str.charAt(2) == str.charAt(3) && str.charAt(4) == str.charAt(5) ? "Yes" : "No"); } static int lower_bound(int[] a, int key) { int right = a.length; int left = 0; while (right - left > 1) { int mid = (right + left) / 2; if (a[mid] < key) { left = mid; } else { right = mid; } } return left; } static int upper_bound(int[] a, int key) { int right = a.length; int left = 0; while (right - left > 1) { int mid = (right + left) / 2; if (a[mid] <= key) { left = mid; } else { right = mid; } } return left; } static boolean isPrime(long n) { if (n == 2) { return true; } if (n < 2 || n % 2 == 0) { return false; } double d = Math.sqrt(n); for (int i = 3; i <= d; i += 2) { if (n % i == 0) { return false; } } return true; } static int upper_division(int a, int b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } static long lupper_division(long a, long b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } static int[] setArray(int a) { int[] b = new int[a]; for (int i = 0; i < a; i++) { b[i] = scan.nextInt(); } return b; } static long[] lsetArray(int a) { long[] b = new long[a]; for (int i = 0; i < a; i++) { b[i] = scan.nextLong(); } return b; } static String reverse(String str) { char[] ch = new char[str.length()]; char[] chch = str.toCharArray(); int a = str.length(); for (int i = 0; i < upper_division(a, 2); i++) { ch[i] = chch[ch.length - i - 1]; ch[ch.length - 1 - i] = chch[i]; } return String.valueOf(ch); } public static void printArray(int[] que) { for (int i = 0; i < que.length - 1; i++) { System.out.print(que[i] + " "); } System.out.println(que[que.length - 1]); } public static int[][] doublesort(int[][] a) { Arrays.sort(a, (x, y) -> Integer.compare(x[0], y[0])); return a; } public static long[][] ldoublesort(long[][] a) { Arrays.sort(a, (x, y) -> Long.compare(x[0], y[0])); return a; } static long modpow(long x, long n, long mo) { long sum = 1; while (n > 0) { if ((n & 1) == 1) { sum = sum * x % mo; } x = x * x % mo; n >>= 1; } return sum; } public static char[] revch(char[] ch) { char[] ret = new char[ch.length]; for (int i = ch.length - 1, j = 0; i >= 0; i--, j++) { ret[j] = ch[i]; } return ret; } public static int[] revint(int[] ch) { int[] ret = new int[ch.length]; for (int i = ch.length - 1, j = 0; i >= 0; i--, j++) { ret[j] = ch[i]; } return ret; } public static void warshall_floyd(int[][] v, int n) { for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { v[i][j] = min(v[i][j], v[i][k] + v[k][j]); } } } } public static long modint(long a, long m) { long b = m; long u = 1; long v = 0; while (b != 0) { long t = a / b; a -= t * b; long x = a; a = b; b = x; u -= t * v; x = u; u = v; v = x; } u %= m; if (u < 0) { u += m; } return u; } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; 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()); } public char nextchar() { try { return (char) System.in.read(); } catch (Exception e) { throw new RuntimeException(e); } } }
[ { "input": "sippuu\n", "output": "Yes\n" } ]
Java
codenet
s987117545
import java.util.*; class s987117545 { final Scanner sc = new Scanner(System.in); final long DEVISOR = 1000000000 + 7; public static void main(String[] args) { new s987117545().run(); } private void run() { long n = sc.nextLong(); long k = sc.nextLong(); long ans = 0; for (long i = k; i <= n + 1; i++) { long max = i * (2 * n - i + 1) / 2; long min = i * (i - 1) / 2; ans += (max - min + 1) % DEVISOR; } System.out.println(ans % DEVISOR); } }
[ { "input": "3 2\n", "output": "10\n" } ]
Java
codenet
s709681166
import java.util.Scanner; public class s709681166 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isUpperCase(c)) { c += 32; System.out.print(c); } else if (Character.isLowerCase(c)) { c -= 32; System.out.print(c); } else { System.out.print(c); } } System.out.println(); sc.close(); } }
[ { "input": "fAIR, LATER, OCCASIONALLY CLOUDY.\n", "output": "Fair, later, occasionally cloudy.\n" } ]
Java
codenet
s905556405
import java.util.*; public class s905556405 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] numlist = new int[5]; int k; for (int i = 0; i < 5; i++) { numlist[i] = sc.nextInt(); } k = sc.nextInt(); if ((numlist[4] - numlist[0]) > k) { System.out.println(":("); } else { System.out.println("Yay!"); } } }
[ { "input": "1\n2\n4\n8\n9\n15\n", "output": "Yay!\n" } ]
Java
codenet
s943650310
import java.util.Scanner; public class s943650310 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int X = sc.nextInt(); int t = sc.nextInt(); if (X - t >= 0) { System.out.println(X - t); } else { System.out.println(0); } } }
[ { "input": "100 17\n", "output": "83\n" } ]
Java
codenet
s036404962
import java.util.Scanner; public class s036404962 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); int X = scan.nextInt(); int t = scan.nextInt(); if (X >= t) { System.out.println(X - t); } else if (X < t) { System.out.print(0); } } }
[ { "input": "100 17\n", "output": "83\n" } ]
Java
codenet
s951567432
import java.util.*; public class s951567432 { public static void main(String[] args) { int count = new Scanner(System.in).nextInt(); int total = 0; for (int ix = 1; ix <= count; ix++) { total += ix; } System.out.println(total); } }
[ { "input": "3\n", "output": "6\n" } ]
Java
codenet
s696692583
import static java.util.Arrays.deepToString; import java.util.Scanner; public class s696692583 { public static void main(String[] args) { new s696692583().run(); } void tr(Object... os) { System.err.println(deepToString(os)); } Scanner sc = new Scanner(System.in); public void run() { while (sc.hasNext()) { int my1 = sc.nextInt(); int my2 = sc.nextInt(); int enemy1 = sc.nextInt(); boolean[] used = new boolean[11]; used[my1] = true; used[my2] = true; used[enemy1] = true; int all = 0; int safe = 0; for (int i = 1; i <= 10; i++) { if (!used[i]) { all++; if (my1 + my2 + i <= 20) { safe++; } } } if (safe * 2 >= all) { System.out.println("YES"); } else { System.out.println("NO"); } } } char solve(int[][] a) { char[] s = {'d', 'o', 'x'}; for (int side = 1; side <= 2; side++) { for (int i = 0; i < 3; i++) { if (a[i][0] == side && a[i][1] == side && a[i][2] == side) { return s[side]; } if (a[0][i] == side && a[1][i] == side && a[2][i] == side) { return s[side]; } } if (a[0][0] == side && a[1][1] == side && a[2][2] == side) { return s[side]; } if (a[0][2] == side && a[1][1] == side && a[2][0] == side) { return s[side]; } } return 'd'; } }
[ { "input": "1 2 3\n5 6 9\n8 9 10\n", "output": "YES\nYES\nNO\n" } ]
Java
codenet
s378126458
import java.util.*; public class s378126458 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int Q = sc.nextInt(); String s = sc.next(); int[] pre = new int[N + 1]; for (int i = 1; i < N; i++) { if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') { pre[i] = 1; } } for (int i = 1; i < N; i++) { pre[i] += pre[i - 1]; } while (Q-- > 0) { int l = sc.nextInt(); int r = sc.nextInt(); r--; System.out.println(pre[r] - pre[l - 1]); } } }
[ { "input": "8 3\nACACTACG\n3 7\n2 3\n1 8\n", "output": "2\n0\n3\n" } ]
Java
codenet
s456888268
import java.io.*; import java.util.*; public class s456888268 { static void solve() { String tmp = ns(); char[] s = tmp.toCharArray(); int n = s.length; int ans = 0; int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == 'S') { cnt++; } else { if (cnt == 0) { continue; } ans++; cnt--; } } out.println(n - 2 * ans); } 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": "TSTTSS\n", "output": "4\n" } ]
Java
codenet
s383412435
import java.util.Arrays; import java.util.Scanner; public class s383412435 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long[] a = new long[N]; int tmp; int ans = 0; for (int z = 0; N > z; z++) { a[z] = sc.nextInt(); } Arrays.sort(a); if (N == 1 && a[0] > 1) { ans = 1; } else { for (int j = 0; N > j; j++) { if (j == 0 || a[j] != a[j - 1]) { tmp = 1; for (int i = j + 1; N > i; i++) { if (a[j] == a[i]) { tmp++; } else { break; } } if (tmp > a[j]) { ans += tmp - a[j]; } else if (tmp < a[j]) { ans += tmp; } } } } System.out.println(ans); } }
[ { "input": "4\n3 3 3 3\n", "output": "1\n" } ]
Java
codenet
s523386612
import java.util.*; class s523386612 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int[] count = new int[t + 1]; for (int i = 2; i < t + 1; i++) { count[sc.nextInt()]++; } for (int i = 1; i < t + 1; i++) { System.out.println(count[i]); } } }
[ { "input": "5\n1 1 2 2\n", "output": "2\n2\n0\n0\n0\n" } ]
Java
codenet
s291405468
import java.util.*; public class s291405468 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(sc.nextInt() % 500 <= sc.nextInt() ? "Yes" : "No"); } }
[ { "input": "2018\n218\n", "output": "Yes\n" } ]
Java
codenet
s799795787
import java.util.*; public class s799795787 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] array = new String[n]; int cnt = 0; int cnt2 = 0; for (int i = 0; i < n; i++) { array[i] = sc.next(); } Arrays.sort(array); String a = array[0]; cnt++; for (int i = 0; i < n; i++) { if (a.equals(array[i])) { } else { cnt++; } a = array[i]; } System.out.println(cnt); } }
[ { "input": "3\napple\norange\napple\n", "output": "2\n" } ]
Java
codenet
s857785109
import java.util.*; public class s857785109 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if ((n / 10) % 111 == 0) { System.out.println("Yes"); } else if ((n % 1000) % 111 == 0) { System.out.println("Yes"); } else { System.out.println("No"); } } }
[ { "input": "1118\n", "output": "Yes\n" } ]
Java
codenet
s461257670
import java.util.*; class s461257670 { public static void main(String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); for (int i = 0; count > i; i++) { int y = sc.nextInt(); int m = sc.nextInt(); int d = sc.nextInt(); System.out.println(Answer(y, m, d)); } } public static int Answer(int y, int m, int d) { int result = 1; if (y % 3 == 0) { result += 20 - d; } else if (m % 2 == 0) { result += 19 - d; } else { result += 20 - d; } for (m += 1; m <= 10; m++) { if (y % 3 == 0) { result += 20; } else { if (m % 2 == 0) { result += 19; } else { result += 20; } } } for (y += 1; y < 1000; y++) { if (y % 3 == 0) { result += 200; } else { result += 195; } } return result; } }
[ { "input": "8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 8 7\n344 2 19\n696 4 19\n999 10 20\n", "output": "196470\n128976\n59710\n160715\n252\n128977\n59712\n1\n" } ]
Java
codenet
s575985145
import java.util.Scanner; public class s575985145 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int size = scan.nextInt(); int[][] graph = new int[size][size]; int id = 0; int cols = 0; int[] row = new int[0]; for (int i = 0; i < size; i++) { id = scan.nextInt(); cols = scan.nextInt(); row = new int[size]; for (int j = 0; j < cols; j++) { row[scan.nextInt() - 1] = 1; } graph[id - 1] = row; } for (int i = 0; i < graph.length; i++) { for (int j = 0; j < graph[i].length; j++) { System.out.print(graph[i][j]); if (j < graph[i].length - 1) { System.out.print(" "); } } System.out.println(); } } }
[ { "input": "4\n1 2 2 4\n2 1 4\n3 0\n4 1 3\n", "output": "0 1 0 1\n0 0 0 1\n0 0 0 0\n0 0 1 0\n" } ]
Java
codenet
s835214694
import java.util.*; public class s835214694 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); if (b % a == 0) { System.out.println(a + b); } else { System.out.println(b - a); } } }
[ { "input": "4 12\n", "output": "16\n" } ]
Java
codenet
s596709252
import java.util.*; public class s596709252 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int z = sc.nextInt(); sc.close(); System.out.println(z + " " + x + " " + y); } }
[ { "input": "1 2 3\n", "output": "3 1 2\n" } ]
Java
codenet
s657273562
import java.io.*; import java.util.*; public class s657273562 { static PrintWriter pw; static Scanner sc; static ArrayList<Integer>[] adj; static boolean[] visit; static HashMap<Pair, Integer> dp; static long ceildiv(long x, long y) { return (x + y - 1) / y; } static int mod(long x, int m) { return (int) ((x % m + m) % m); } static HashMap<Integer, Integer> map; static long gcd(long x, long y) { return y == 0 ? x : gcd(y, x % y); } static int Int(boolean x) { return x ? 1 : 0; } static void put(TreeMap<Pair, Integer> map, Pair p) { if (map.containsKey(p)) { map.replace(p, map.get(p) + 1); } else { map.put(p, 1); } } static void rem(TreeMap<Pair, Integer> map, Pair p) { if (map.get(p) == 1) { map.remove(p); } else { map.replace(p, map.get(p) - 1); } } public static void main(String[] args) throws Exception { sc = new Scanner(System.in); pw = new PrintWriter(System.out); int n = sc.nextInt(); Integer[] arr = sc.nextsort(n); Arrays.sort(arr, Collections.reverseOrder()); if (n >= 3) { TreeMap<Pair, Integer> map = new TreeMap<>(Collections.reverseOrder()); long ans = arr[0] + arr[1]; map.put(new Pair(arr[0], arr[1]), 1); Pair p1 = new Pair(arr[2], arr[1]); Pair p2 = new Pair(arr[2], arr[0]); put(map, p1); put(map, p2); for (int i = 3; i < n; i++) { Pair p = map.firstKey(); rem(map, p); ans += Math.min(p.x, p.y); put(map, new Pair(p.x, arr[i])); put(map, new Pair(p.y, arr[i])); } pw.println(ans); } else { pw.println(arr[0]); } pw.close(); } static void fill(int[] arr, int x) { for (int i = 0; i < 30; i++) { arr[i] += Int(((1 << i) & x) != 0); } } static long pow(long a, long pow) { long ans = 1; while (pow > 0) { if ((pow & 1) == 1) { ans *= a; } a *= a; pow >>= 1; } return ans; } static int getpow(int x) throws Exception { int pow = x; pw.println("B " + pow); pw.flush(); sc.next(); pw.println("B " + pow); pw.flush(); if (sc.nextInt() == 1) { pow *= x; while (true) { pw.println("B " + pow); pw.flush(); if (sc.nextInt() == 0) { return pow / x; } pow *= x; } } else { return 1; } } static int[] least; static TreeSet<Integer> prime; static void linearsieve(int x) { least = new int[x + 1]; prime = new TreeSet<>(); for (int i = 2; i <= x; i++) { if (least[i] == 0) { least[i] = i; prime.add(i); } for (int y : prime) { if (i * y <= x) { least[i * y] = y; } else { break; } } } } static void printArr(int[] arr) { for (int i = 0; i < arr.length - 1; i++) { pw.print(arr[i] + " "); } pw.println(arr[arr.length - 1]); } static void printArr(long[] arr) { for (int i = 0; i < arr.length - 1; i++) { pw.print(arr[i] + " "); } pw.println(arr[arr.length - 1]); } static void printArr(Integer[] arr) { for (int i = 0; i < arr.length; i++) { pw.print(arr[i] + " "); } pw.println(); } static void printArr(char[] arr) { for (int i = 0; i < arr.length; i++) { pw.print(arr[i] == 0 ? '1' : arr[i]); } pw.println(); } static void printArr(ArrayList<Integer> list) { for (int i = 0; i < list.size(); i++) { pw.print(list.get(i) + " "); } pw.println(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } 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 { return Double.parseDouble(next()); } public int[] nextArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < arr.length; i++) { arr[i] = nextInt(); } return arr; } public Integer[] nextsort(int n) throws IOException { Integer[] arr = new Integer[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public Pair nextPair() throws IOException { return new Pair(nextInt(), nextInt()); } public Pair[] nextPairArr(int n) throws IOException { Pair[] arr = new Pair[n]; for (int i = 0; i < n; i++) { arr[i] = nextPair(); } return arr; } public boolean ready() throws IOException { return br.ready(); } } static class Pair implements Comparable<Pair> { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } public int hashCode() { return this.x * 1000 + this.y; } public int compareTo(Pair p) { int min1 = Math.min(x, y); int min2 = Math.min(p.x, p.y); if (min1 != min2) { return min1 - min2; } if (x == p.x) { return y - p.y; } return x - p.x; } public boolean equals(Object obj) { if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } Pair p = (Pair) obj; return this.x == p.x && this.y == p.y; } public Pair clone() { return new Pair(x, y); } public String toString() { return this.x + " " + this.y; } public void add(Pair p) { x += p.x; y += p.y; } } }
[ { "input": "4\n2 2 1 3\n", "output": "7\n" } ]
Java
codenet
s453440639
import java.util.Scanner; public class s453440639 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); sc.nextLine(); char[][] S = new char[H][W]; for (int i = 0; i < H; i++) { String text = sc.nextLine(); for (int j = 0; j < W; j++) { S[i][j] = text.charAt(j); } } sc.close(); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '.') { int count = 0; for (int a = -1; a <= 1; a++) { if (i + a < 0 || H <= i + a) { continue; } for (int b = -1; b <= 1; b++) { if (j + b < 0 || W <= j + b) { continue; } if (S[i + a][j + b] == '#') { count++; } } } S[i][j] = (char) (count + 48); } System.out.printf("%c", S[i][j]); } System.out.printf("\n"); } } }
[ { "input": "3 5\n.....\n.#.#.\n.....\n", "output": "11211\n1#2#1\n11211\n" } ]
Java
codenet
s127819686
import java.util.Scanner; public class s127819686 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int hb = b / 2; System.out.println(a + hb); } }
[ { "input": "81 58\n", "output": "110\n" } ]
Java
codenet
s302365683
import java.io.*; import java.util.*; public class s302365683 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); StringTokenizer s = new StringTokenizer(br.readLine()); int n = Integer.parseInt(s.nextToken()); HashMap<Integer, Integer> hm = new HashMap<>(); s = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { int val = Integer.parseInt(s.nextToken()); hm.put(val, hm.getOrDefault(val, 0) + 1); } int ans = 0; for (int val : hm.keySet()) { int num = hm.get(val); if (num > val) { ans += num - val; } else if (num < val) { ans += num; } } pw.println(ans); pw.close(); } }
[ { "input": "4\n3 3 3 3\n", "output": "1\n" } ]
Java
codenet
s789781857
import java.util.Scanner; public class s789781857 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] c = new int[n - 1]; int[] s = new int[n - 1]; int[] f = new int[n - 1]; for (int i = 0; i < n - 1; i++) { c[i] = in.nextInt(); s[i] = in.nextInt(); f[i] = in.nextInt(); } for (int i = 0; i < n - 1; i++) { int time = s[i] + c[i]; for (int j = i + 1; j < n - 1; j++) { if (time % f[j] != 0) { time += f[j] - (time % f[j]); } if (time < s[j]) { time = s[j]; } time += c[j]; } System.out.println(time); } System.out.println(0); } }
[ { "input": "3\n6 5 1\n1 10 1\n", "output": "12\n11\n0\n" } ]
Java
codenet
s316260310
import java.awt.*; import java.io.*; import java.math.*; import java.util.*; public class s316260310 implements Runnable { @Override public void run() { try { new Solver().solve(); System.exit(0); } catch (Exception | Error e) { e.printStackTrace(); System.exit(1); } } public static void main(String[] args) { new s316260310().run(); } } class Solver { final Helper hp; final int MAXN = 1000_006; final long MOD = (long) 1e9 + 7; final Timer timer; final TimerTask task; Solver() { hp = new Helper(MOD, MAXN); hp.initIO(System.in, System.out); timer = new Timer(); task = new TimerTask() { @Override public void run() { try { hp.flush(); System.exit(0); } catch (Exception e) { } } }; } void solve() throws Exception { int tc = TESTCASES ? hp.nextInt() : 1; for (int tce = 1; tce <= tc; ++tce) { solve(tce); } timer.cancel(); hp.flush(); } boolean TESTCASES; void solve(int tc) throws Exception { int i; int j; int k; int N = hp.nextInt(); long K = hp.nextLong(); int[] A = hp.getIntArray(N); ArrayList<Integer> straight = new ArrayList<>(); ArrayList<Integer> cycle = new ArrayList<>(); boolean[] vis = new boolean[N]; int curr = 0; while (!vis[curr]) { vis[curr] = true; curr = A[curr] - 1; } int st = 0; while (st != curr) { straight.add(st); st = A[st] - 1; } cycle.add(curr); curr = A[curr] - 1; while (curr != cycle.get(0)) { cycle.add(curr); curr = A[curr] - 1; } if (K < straight.size()) { hp.println(straight.get((int) K) + 1); } else { K -= straight.size(); hp.println(cycle.get((int) (K % cycle.size())) + 1); } } } class Helper { final long MOD; final int MAXN; final Random rnd; public Helper(long mod, int maxn) { MOD = mod; MAXN = maxn; rnd = new Random(); } public static int[] sieve; public static ArrayList<Integer> primes; public void setSieve() { primes = new ArrayList<>(); sieve = new int[MAXN]; int i; int j; for (i = 2; i < MAXN; ++i) { if (sieve[i] == 0) { primes.add(i); for (j = i; j < MAXN; j += i) { sieve[j] = i; } } } } public static long[] factorial; public void setFactorial() { factorial = new long[MAXN]; factorial[0] = 1; for (int i = 1; i < MAXN; ++i) { factorial[i] = factorial[i - 1] * i % MOD; } } public long getFactorial(int n) { if (factorial == null) { setFactorial(); } return factorial[n]; } public long ncr(int n, int r) { if (r > n) { return 0; } if (factorial == null) { setFactorial(); } long numerator = factorial[n]; long denominator = factorial[r] * factorial[n - r] % MOD; return numerator * pow(denominator, MOD - 2, MOD) % MOD; } public long[] getLongArray(int size) throws Exception { long[] ar = new long[size]; for (int i = 0; i < size; ++i) { ar[i] = nextLong(); } return ar; } public int[] getIntArray(int size) throws Exception { int[] ar = new int[size]; for (int i = 0; i < size; ++i) { ar[i] = nextInt(); } return ar; } public String[] getStringArray(int size) throws Exception { String[] ar = new String[size]; for (int i = 0; i < size; ++i) { ar[i] = next(); } return ar; } public String joinElements(long... ar) { StringBuilder sb = new StringBuilder(); for (long itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(int... ar) { StringBuilder sb = new StringBuilder(); for (int itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(String... ar) { StringBuilder sb = new StringBuilder(); for (String itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(Object... ar) { StringBuilder sb = new StringBuilder(); for (Object itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public long max(long... ar) { long ret = ar[0]; for (long itr : ar) ret = Math.max(ret, itr); return ret; } public int max(int... ar) { int ret = ar[0]; for (int itr : ar) ret = Math.max(ret, itr); return ret; } public long min(long... ar) { long ret = ar[0]; for (long itr : ar) ret = Math.min(ret, itr); return ret; } public int min(int... ar) { int ret = ar[0]; for (int itr : ar) ret = Math.min(ret, itr); return ret; } public long sum(long... ar) { long sum = 0; for (long itr : ar) sum += itr; return sum; } public long sum(int... ar) { long sum = 0; for (int itr : ar) sum += itr; return sum; } public void shuffle(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void shuffle(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void reverse(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = ar.length - 1 - i; if (r > i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void reverse(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = ar.length - 1 - i; if (r > i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public long pow(long base, long exp, long MOD) { base %= MOD; long ret = 1; while (exp > 0) { if ((exp & 1) == 1) { ret = ret * base % MOD; } base = base * base % MOD; exp >>= 1; } return ret; } static final int BUFSIZE = 1 << 20; static byte[] buf; static int index; static int total; static InputStream in; static BufferedWriter bw; public void initIO(InputStream is, OutputStream os) { try { in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); buf = new byte[BUFSIZE]; } catch (Exception e) { } } public void initIO(String inputFile, String outputFile) { try { in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile))); buf = new byte[BUFSIZE]; } catch (Exception e) { } } private int scan() throws Exception { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } public String next() throws Exception { int c; for (c = scan(); c <= 32; c = scan()) { } StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } public int nextInt() throws Exception { int c; int val = 0; for (c = scan(); c <= 32; c = scan()) { } boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } public long nextLong() throws Exception { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) { } boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } public void print(Object a) throws Exception { bw.write(a.toString()); } public void printsp(Object a) throws Exception { print(a); print(" "); } public void println() throws Exception { bw.write("\n"); } public void println(Object a) throws Exception { print(a); println(); } public void flush() throws Exception { bw.flush(); } }
[ { "input": "4 5\n3 2 4 1\n", "output": "4\n" } ]
Java
codenet
s918596375
import java.io.*; import java.util.AbstractMap; import java.util.StringTokenizer; public class s918596375 { public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); solve(sc, out); out.flush(); } public static void solve(FastScanner sc, PrintWriter out) { String s = sc.next(); String[] a = {"a", "e", "i", "o", "u"}; for (String str : a) { if (str.equalsIgnoreCase(s)) { out.println("vowel"); return; } } out.println("consonant"); } public static int gcd(int a, int b) { if (a < b) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } public static long gcd(long a, long b) { if (a < b) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } } class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> { public Pair(final K key, final V value) { super(key, value); } public Pair<V, K> swap() { return new Pair<>(getValue(), getKey()); } } class FastScanner { private final BufferedReader reader; private StringTokenizer tokenizer; 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": "a\n", "output": "vowel\n" } ]
Java
codenet
s551454565
import java.util.Scanner; public class s551454565 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); if ("Sunny".equals(s)) { System.out.println("Cloudy"); } else if ("Cloudy".equals(s)) { System.out.println("Rainy"); } else { System.out.println("Sunny"); } sc.close(); } }
[ { "input": "Sunny\n", "output": "Cloudy\n" } ]
Java
codenet
s428436430
import java.util.*; class calArea { int Area(int w, int h) { return w * h; } } public class s428436430 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); List<Integer> arr = new ArrayList<>(); for (int i = 0; i < 4; i++) { arr.add(Integer.parseInt(sc.next())); } calArea ab = new calArea(); int area1 = ab.Area(arr.get(0), arr.get(1)); int area2 = ab.Area(arr.get(2), arr.get(3)); if (area1 > area2) { System.out.println(area1); } else if (area1 < area2) { System.out.println(area2); } else if (area1 == area2) { System.out.println(area1); } } }
[ { "input": "3 5 2 7\n", "output": "15\n" } ]
Java
codenet
s607507157
import java.util.Scanner; public class s607507157 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n % 10 == 9 || n / 10 == 9) { System.out.println("Yes"); } else { System.out.println("No"); } } }
[ { "input": "29\n", "output": "Yes\n" } ]
Java
codenet
s010698290
import java.awt.geom.*; import java.io.*; import java.util.*; public class s010698290 { public static void main(String[] args) { try { FastReader s = new FastReader(); BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out)); int i; int j; int m; int n; int t; int max; int k; int x; int y; int min; int correctAns; int num; int numPenal; long a; long b; long sum; String str; n = s.nextInt(); m = s.nextInt(); int[] penal = new int[n + 1]; boolean[] solved = new boolean[n + 1]; Arrays.fill(solved, false); for (i = 0; i < m; i++) { num = s.nextInt(); str = s.next(); if (str.charAt(0) == 'A') { solved[num] = true; } else if (solved[num] == false) { penal[num]++; } } correctAns = 0; numPenal = 0; for (i = 1; i <= n; i++) { if (solved[i]) { correctAns++; numPenal += penal[i]; } } w.write(correctAns + " " + numPenal + "\n"); w.close(); } catch (Exception e) { e.printStackTrace(); } } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } Double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
[ { "input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n", "output": "2 2\n" } ]
Java
codenet
s525447134
import java.util.Scanner; public class s525447134 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); if ("Sunny".equals(s)) { System.out.println("Cloudy"); } else if ("Cloudy".equals(s)) { System.out.println("Rainy"); } else { System.out.println("Sunny"); } } }
[ { "input": "Sunny\n", "output": "Cloudy\n" } ]
Java
codenet
s867221485
import java.util.*; public class s867221485 { static int N; static int K; static long Q; static int A; static int B; static long C; static double min = 9999999; static long ans; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); scanner.nextLine(); String s = scanner.nextLine(); boolean flag = false; int ans = 0; int hen = 0; int sha = 0; int dot = 0; int temp = 0; boolean first = true; for (int i = 0; i < N; i++) { if (s.charAt(i) == '#') { first = false; if (sha <= dot) { ans += sha; sha = 0; dot = 0; first = true; } sha++; } else { dot++; } } if (sha <= dot) { ans += sha; dot = 0; } System.out.println(ans + dot); } }
[ { "input": "3\n#.#\n", "output": "1\n" } ]
Java
codenet
s973587235
import java.util.*; public class s973587235 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int minN = sc.nextInt() - 1; for (int i = 0; i < n - 1; i++) { int h = sc.nextInt(); if (minN == h) { minN = h; } else if (minN == h - 1) { minN = h - 1; } else if (minN < h - 1) { minN = h - 1; } else if (minN > h) { System.out.println("No"); return; } } System.out.println("Yes"); } }
[ { "input": "5\n1 2 1 1 3\n", "output": "Yes\n" } ]
Java
codenet
s391272180
import java.util.Scanner; public class s391272180 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder s; StringBuilder t; s = new StringBuilder(sc.next()); t = new StringBuilder(sc.next()); boolean flag = false; for (int i = 0; i < s.length(); i++) { s = new StringBuilder(Rotate(s)); if (t.toString().equals(s.toString())) { flag = true; break; } } if (flag) { System.out.println("Yes"); } else { System.out.println("No"); } } public static StringBuilder Rotate(StringBuilder str) { int len = str.length(); char t = str.charAt(0); for (int i = 0; i < len - 1; i++) { str.setCharAt(i, str.charAt(i + 1)); } str.setCharAt(len - 1, t); return str; } }
[ { "input": "kyoto\ntokyo\n", "output": "Yes\n" } ]
Java
codenet
s888333881
import java.io.*; import java.math.*; import java.util.*; public class s888333881 { static class Graph0n { private ArrayList<Node0n> dt = new ArrayList<>(); Graph0n(int sz) { for (int i = 0; i < sz; i++) { Node0n node1 = new Node0n(); dt.add(node1); } } public void add(int vn, int val) { dt.get(vn).add(val); } public void add2(int vn, int val) { dt.get(vn).add(val); dt.get(val).add(vn); } public int get(int vn, int index) { return dt.get(vn).get(index); } public ArrayList<Integer> get(int vn) { return dt.get(vn).getAll(); } public int sizeOf(int vn) { return dt.get(vn).size(); } public void clear() { for (int i = 0; i < dt.size(); i++) { dt.get(i).clear(); } } } static class Node0n { private ArrayList<Integer> next_vs = new ArrayList<>(); public void add(int val) { next_vs.add(val); } public int get(int ad) { return next_vs.get(ad); } public ArrayList<Integer> getAll() { return next_vs; } public int size() { return next_vs.size(); } public void clear() { next_vs.clear(); } } static class Edge { int from = -1; int v2 = -1; long weight; public Edge(int vn, long w) { this.v2 = vn; this.weight = w; } public Edge(int cm, int vn, long w) { this.from = cm; this.v2 = vn; this.weight = w; } } static class Edge2 { int v2; long cost1; long cost2; public Edge2(int vn, long w1, long w2) { this.v2 = vn; this.cost1 = w1; this.cost2 = w2; } } static class Comparator_Edge implements Comparator<Edge> { public int compare(Edge a, Edge b) { if (a.weight > b.weight) { return -1; } else if (a.weight < b.weight) { return 1; } else { return b.v2 - a.v2; } } } static class V2Comp implements Comparator<Edge> { public int compare(Edge a, Edge b) { if (a.v2 > b.v2) { return -1; } else if (a.v2 < b.v2) { return 1; } else if (a.weight > b.weight) { return -1; } else if (a.weight < b.weight) { return 1; } else { return 0; } } } static class antiV2 implements Comparator<Edge> { public int compare(Edge a, Edge b) { if (a.v2 > b.v2) { return 1; } else if (a.v2 < b.v2) { return -1; } else if (a.weight > b.weight) { return -1; } else if (a.weight < b.weight) { return 1; } else { return 0; } } } static class Vector { int x; int y; public Vector(int sx, int sy) { this.x = sx; this.y = sy; } } public static void main(String[] args) throws Exception { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n = sc.nexI(); String s = sc.next(); boolean[] flaged = new boolean[n]; fill(flaged, false); long pop1st = 0L; for (int i = 0; i < n; i++) { if (s.charAt(i) == '1') { flaged[i] = true; pop1st++; } } long surp1 = 0; for (int i = 0; i < n; i++) { surp1 *= 2L; if (flaged[i]) { surp1++; } surp1 %= pop1st + 1L; } long surp9 = 0L; if (pop1st > 1) { for (int i = 0; i < n; i++) { surp9 *= 2L; if (flaged[i]) { surp9++; } surp9 %= pop1st - 1L; } } for (int p = 0; p < n; p++) { if (flaged[p]) { if (pop1st == 1) { out.println(0); continue; } long dw = surp9; long dif = pow10E97(2, n - p - 1, pop1st - 1); dw -= dif; dw += pop1st - 1L; dw %= pop1st - 1L; int ans = 1; while (dw != 0) { if (dw < 0) { out.println(1 / 0); } int count = countFlaged(dw); dw %= count; ans++; } out.println(ans); } else { long dw = surp1; long dif = pow10E97(2, n - p - 1, pop1st + 1); dw += dif; dw %= pop1st + 1L; int ans = 1; while (dw != 0) { if (dw < 0) { out.println(1 / 0); } int count = countFlaged(dw); dw %= count; ans++; } out.println(ans); } } out.flush(); } private static final int INF = (int) 1e8; private static final long INFL = (long) 1e17; private static final long e97 = (long) 1e9 + 7; void assertion(boolean b) { if (!b) { throw new AssertionError(); } } private static int abs(int a) { return a >= 0 ? a : -a; } private static long abs(long a) { return a >= 0 ? a : -a; } private static double abs(double a) { return a >= 0 ? a : -a; } private static int min(int a, int b) { return a > b ? b : a; } private static long min(long a, long b) { return a > b ? b : a; } private static double min(double a, double b) { return a > b ? b : a; } private static int max(int a, int b) { return a > b ? a : b; } private static long max(long a, long b) { return a > b ? a : b; } private static double max(double a, double b) { return a > b ? a : b; } private static int minN(int... ins) { int min = ins[0]; for (int i = 1; i < ins.length; i++) { if (ins[i] < min) { min = ins[i]; } } return min; } private static int maxN(int... ins) { int max = ins[0]; for (int i = 1; i < ins.length; i++) { if (ins[i] > max) { max = ins[i]; } } return max; } private static long minN(long... ins) { long min = ins[0]; for (int i = 1; i < ins.length; i++) { if (ins[i] < min) { min = ins[i]; } } return min; } private static long maxN(long... ins) { long max = ins[0]; for (int i = 1; i < ins.length; i++) { if (ins[i] > max) { max = ins[i]; } } return max; } private static int minExAd(int[] dt, int ad) { int min = INF; for (int i = 0; i < dt.length; i++) { if ((i != ad) && (dt[i] < min)) { min = dt[i]; } } return min; } private static long minExAd(long[] dt, int ad) { long min = INFL; for (int i = 0; i < dt.length; i++) { if ((i != ad) && (dt[i] < min)) { min = dt[i]; } } return min; } private static int minExVal(int[] dt, int ex_val) { int min = INF; for (int i = 0; i < dt.length; i++) { if ((dt[i] != ex_val) && (dt[i] < min)) { min = dt[i]; } } return min; } private static long minExVal(long[] dt, long ex_val) { long min = INFL; for (int i = 0; i < dt.length; i++) { if ((dt[i] != ex_val) && (dt[i] < min)) { min = dt[i]; } } return min; } private static int maxExAd(int[] dt, int ad) { int max = -INF; for (int i = 0; i < dt.length; i++) { if ((i != ad) && (dt[i] > max)) { max = dt[i]; } } return max; } private static long maxExAd(long[] dt, int ad) { long max = -INFL; for (int i = 0; i < dt.length; i++) { if ((i != ad) && (dt[i] > max)) { max = dt[i]; } } return max; } private static int maxExVal(int[] dt, int ex_val) { int max = -INF; for (int i = 0; i < dt.length; i++) { if ((dt[i] != ex_val) && (dt[i] > max)) { max = dt[i]; } } return max; } private static long maxExVal(long[] dt, long ex_val) { long max = -INFL; for (int i = 0; i < dt.length; i++) { if ((dt[i] != ex_val) && (dt[i] > max)) { max = dt[i]; } } return max; } private static int sumA(int[] dt) { int sum = 0; for (int e : dt) { sum += e; } return sum; } private static long sumA(long[] dt) { long sum = 0; for (long e : dt) { sum += e; } return sum; } private static int sumA(List<Integer> dt) { int sum = 0; for (long e : dt) { sum += e; } return sum; } private static boolean same3(long a, long b, long c) { if (a != b) { return false; } if (b != c) { return false; } return c == a; } private static boolean dif3(long a, long b, long c) { if (a == b) { return false; } if (b == c) { return false; } return c != a; } private static boolean triangle_inequality(int a, int b, int c) { if ((a + b) < c) { return false; } if ((b + c) < a) { return false; } return (c + a) >= b; } private static double hypod(double a, double b) { return Math.sqrt(a * a + b * b); } private static long factorial(int n) { long ans = 1; for (long i = n; i > 0; i--) { ans *= i; } return ans; } private static long facP(int n, long p) { long ans = 1; for (long i = n; i > 0; i--) { ans *= i; ans %= p; } return ans; } private static long lcm(long m, long n) { long ans = m / gcd(m, n); ans *= n; return ans; } private static long gcd(long m, long n) { if (m < n) { return gcd(n, m); } if (n == 0) { return m; } return gcd(n, m % n); } private static boolean is_prime(long a) { if (a == 1) { return false; } for (long i = 2L; i <= Math.sqrt(a); i++) { if (a % i == 0) { return false; } } return true; } private static long modinv(long a, long p) { long b = p; long u = 1L; long v = 0L; while (b > 0) { long t = a / b; long pe = a % b; a = b; b = pe; pe = u - t * v; u = v; v = pe; } u %= p; if (u < 0) { u += p; } return u; } private static int pow(int n, int k) { int ans = 1; for (int i = 0; i < k; i++) { ans *= n; } return ans; } private static long pow(long n, int k) { long ans = 1; for (int i = 0; i < k; i++) { ans *= n; } return ans; } private static int pow2(int in) { return in * in; } private static long pow2(long in) { return in * in; } private static double pow2(double in) { return in * in; } private static int getDigit2(long num) { long cf = 1; int d = 0; while (num >= cf) { d++; cf = 1L << d; } return d; } private static int getDigit10(long num) { long cf = 1; int d = 0; while (num >= cf) { d++; cf *= 10; } return d; } private static boolean isINF(int in) { return ((long) in * 20) > INF; } private static boolean isINFL(long in) { return (in * 10000) > INFL; } private static long pow10E97(long ob, long soeji, long p) { if (ob == 0) { return 0; } if (soeji == 0) { return 1; } if (soeji == 2) { return (ob * ob) % p; } int d = getDigit2(soeji); long[] obPow2pow = new long[d]; obPow2pow[0] = ob; for (int i = 1; i < d; i++) { obPow2pow[i] = (obPow2pow[i - 1] * obPow2pow[i - 1]) % p; } long ans = 1; for (int i = d - 1; i >= 0; i--) { if (soeji >= (long) (1 << i)) { soeji -= (long) (1 << i); ans = (ans * obPow2pow[i]) % p; } } return ans % p; } private static long flag(long pos) { return 1L << pos; } private static boolean isFlaged(int bit, int pos) { return (bit & (1 << pos)) > 0; } private static boolean isFlaged(long bit, int pos) { return (bit & (1L << pos)) > 0; } private static int deflag(int bit, int pos) { return bit & ~(1 << pos); } private static int countFlaged(int bit) { int ans = 0; for (int i = 0; i < getDigit2(bit); i++) { if ((bit & (1 << i)) > 0) { ans++; } } return ans; } private static int countFlaged(long bit) { int ans = 0; for (long i = 0; i < getDigit2(bit); i++) { if ((bit & (1L << i)) > 0) { ans++; } } return ans; } private static void showflag(int bit) { for (int i = 0; i < getDigit2(bit); i++) { if (isFlaged(bit, i)) { System.out.print("O"); } else { System.out.print("."); } } System.out.println(); } public static int biSearch(int[] dt, int target) { int left = 0; int right = dt.length - 1; int mid = -1; while (left <= right) { mid = (right + left) / 2; if (dt[mid] == target) { return mid; } if (dt[mid] < target) { left = mid + 1; } else { right = mid - 1; } } return -1; } public static int biSearchMax(long[] dt, long target) { int left = -1; int right = dt.length; int mid = -1; while ((right - left) > 1) { mid = left + (right - left) / 2; if (dt[mid] <= target) { left = mid; } else { right = mid; } } return left; } public static int biSearchMaxAL(ArrayList<Integer> dt, long target) { int left = -1; int right = dt.size(); int mid = -1; while ((right - left) > 1) { mid = left + (right - left) / 2; if (dt.get(mid) <= target) { left = mid; } else { right = mid; } } return left; } private static void fill_parent(int[] ob) { for (int i = 0; i < ob.length; i++) { ob[i] = i; } } private static int get_root_uf(int[] parent, int index) { if (parent[index] == index) { return index; } int root = get_root_uf(parent, parent[index]); parent[index] = root; return root; } private static boolean is_same_uf(int[] parent, int x, int y) { return get_root_uf(parent, x) == get_root_uf(parent, y); } private static void unite_uf(int[] parent, int receiver, int attacker) { parent[get_root_uf(parent, attacker)] = get_root_uf(parent, receiver); } private static final int[] Xdir4 = {1, 0, 0, -1}; private static final int[] Ydir4 = {0, 1, -1, 0}; private static final int[] Xdir8 = {1, 1, 1, 0, 0, -1, -1, -1}; private static final int[] Ydir8 = {1, 0, -1, 1, -1, 1, 0, -1}; private static boolean is_in_area(int y, int x, int h, int w) { if (y < 0) { return false; } if (x < 0) { return false; } if (y >= h) { return false; } return x < w; } static void show2(boolean[][] dt, int lit_x, int lit_y) { PrintWriter out = new PrintWriter(System.out); for (int j = 0; j < dt.length; j++) { for (int i = 0; i < dt[j].length; i++) { if ((i == lit_y) && (j == lit_x)) { out.print("X"); } else if (dt[j][i]) { out.print("O"); } else { out.print("."); } } out.println(); } out.flush(); } static void show2(int[][] dt, String cmnt) { PrintWriter out = new PrintWriter(System.out); for (int i = 0; i < dt.length; i++) { for (int j = 0; j < dt[i].length; j++) { out.print(dt[i][j] + ","); } out.println("<-" + cmnt + ":" + i); } out.flush(); } static void show2(long[][] dt, String cmnt) { PrintWriter out = new PrintWriter(System.out); for (int i = 0; i < dt.length; i++) { for (int j = 0; j < dt[i].length; j++) { out.print(dt[i][j] + ","); } out.println("<-" + cmnt + ":" + i); } out.flush(); } static void disp_que(ArrayDeque<Long> dt) { long a = 0; while (!dt.isEmpty()) { a = dt.removeFirst(); System.out.print(a); } System.out.println("\n"); } static void disp_list(List dt) { for (int i = 0; i < dt.size(); i++) { System.out.print(dt.get(i) + ","); } System.out.println("\n"); } private static void prtlnas(int[] as) { PrintWriter out = new PrintWriter(System.out); for (int i = 0; i < as.length; i++) { out.println(as[i]); } out.flush(); } private static void prtlnas(long[] as) { PrintWriter out = new PrintWriter(System.out); for (int i = 0; i < as.length; i++) { out.println(as[i]); } out.flush(); } private static void prtspas(int[] as) { PrintWriter out = new PrintWriter(System.out); out.print(as[0]); for (int i = 1; i < as.length; i++) { out.print(" " + as[i]); } out.println(); out.flush(); } private static void prtspas(long[] as) { PrintWriter out = new PrintWriter(System.out); out.print(as[0]); for (int i = 1; i < as.length; i++) { out.print(" " + as[i]); } out.println(); out.flush(); } private static void prtspas(List as) { PrintWriter out = new PrintWriter(System.out); out.print(as.get(0)); for (int i = 1; i < as.size(); i++) { out.print(" " + as.get(i)); } out.println(); out.flush(); } private static void fill(boolean[] ob, boolean res) { for (int i = 0; i < ob.length; i++) { ob[i] = res; } } private static void fill(int[] ob, int res) { for (int i = 0; i < ob.length; i++) { ob[i] = res; } } private static void fill(long[] ob, long res) { for (int i = 0; i < ob.length; i++) { ob[i] = res; } } private static void fill(char[] ob, char res) { for (int i = 0; i < ob.length; i++) { ob[i] = res; } } private static void fill(double[] ob, double res) { for (int i = 0; i < ob.length; i++) { ob[i] = res; } } private static void fill(boolean[][] ob, boolean res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { ob[i][j] = res; } } } private static void fill(int[][] ob, int res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { ob[i][j] = res; } } } private static void fill(long[][] ob, long res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { ob[i][j] = res; } } } private static void fill(char[][] ob, char res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { ob[i][j] = res; } } } private static void fill(double[][] ob, double res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { ob[i][j] = res; } } } private static void fill(int[][][] ob, int res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { for (int k = 0; k < ob[0][0].length; k++) { ob[i][j][k] = res; } } } } private static void fill(long[][][] ob, long res) { for (int i = 0; i < ob.length; i++) { for (int j = 0; j < ob[0].length; j++) { for (int k = 0; k < ob[0][0].length; k++) { ob[i][j][k] = res; } } } } 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 nexL() { 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) || b == ':') { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nexI() { long nl = nexL(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nexD() { return Double.parseDouble(next()); } public void ni(long[] array2) { for (int i = 0; i < array2.length; i++) { array2[i] = nexL(); } } public void ni(int[] array2) { for (int i = 0; i < array2.length; i++) { array2[i] = nexI(); } } public void ni(int[] as, int[] bs) { for (int i = 0; i < as.length; i++) { as[i] = nexI(); bs[i] = nexI(); } } public void ni(long[] as, long[] bs) { for (int i = 0; i < as.length; i++) { as[i] = nexL(); bs[i] = nexL(); } } public void ni(int[] as, int[] bs, int[] cs) { for (int i = 0; i < as.length; i++) { as[i] = nexI(); bs[i] = nexI(); cs[i] = nexI(); } } public void nisan(int[][] as) { for (int i = 0; i < as.length; i++) { for (int j = 0; j < as[0].length; j++) { as[i][j] = nexI(); } } } } }
[ { "input": "3\n011\n", "output": "2\n1\n1\n" } ]
Java
codenet
s910447421
import java.io.*; import java.math.*; import java.util.*; public class s910447421 { static int ans = 100; static int[][] balls; static int N; static boolean[] taken; public static void main(String[] args) { FastScanner I = new FastScanner(); OutPut O = new OutPut(); N = I.nextInt(); ans = N; balls = new int[N][2]; for (int i = 0; i < N; i++) { balls[i][0] = I.nextInt(); balls[i][1] = I.nextInt(); } Arrays.sort(balls, (a, b) -> Integer.compare(a[0], b[0])); solve(); for (int i = 0; i < N; i++) { int x = balls[i][0]; int y = balls[i][1]; balls[i][0] = y; balls[i][1] = x; } Arrays.sort(balls, (a, b) -> Integer.compare(a[0], b[0])); solve(); O.pln(ans); } public static void solve() { for (int add = 1; add < N; add++) { taken = new boolean[N]; int p = balls[add][0] - balls[0][0]; int q = balls[add][1] - balls[0][1]; ans = min(ans, check(p, q)); } } public static int check(int p, int q) { int ret = 0; while (true) { boolean added = false; int start = 0; int x = -1; int y = -1; for (int i = 0; i < N; i++) { if (!taken[i]) { added = true; ret++; start = i; taken[i] = true; x = balls[i][0] + p; y = balls[i][1] + q; break; } } if (!added) { break; } for (int i = start + 1; i < N; i++) { if (balls[i][0] == x && balls[i][1] == y) { taken[i] = true; x += p; y += q; } } } return ret; } public static double max(double a, double b) { return Math.max(a, b); } public static double min(double a, double b) { return Math.min(a, b); } public static long min(long a, long b) { return Math.min(a, b); } public static long max(long a, long b) { return Math.max(a, b); } public static int min(int a, int b) { return Math.min(a, b); } public static int max(int a, int b) { return Math.max(a, b); } public static long abs(long x) { return Math.abs(x); } public static long ceil(long num, long den) { long ans = num / den; if (num % den != 0) { ans++; } return ans; } public static long GCD(long a, long b) { if (a == 0 || b == 0) { return max(a, b); } return GCD(min(a, b), max(a, b) % min(a, b)); } public static long FastExp(long base, long exp, long mod) { long ans = 1; while (exp > 0) { if (exp % 2 == 1) { ans *= base; } exp /= 2; base *= base; base %= mod; ans %= mod; } return ans; } public static long ModInv(long num, long mod) { return FastExp(num, mod - 2, mod); } public static int pop(long x) { int cnt = 0; while (x > 0) { if (x % 2 == 1) { cnt++; } x /= 2; } return cnt; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } ; double nextDouble() { return Double.parseDouble(next()); } } static class OutPut { PrintWriter w = new PrintWriter(System.out); void pln(double x) { w.println(x); w.flush(); } void pln(boolean x) { w.println(x); w.flush(); } void pln(int x) { w.println(x); w.flush(); } void pln(long x) { w.println(x); w.flush(); } void pln(String x) { w.println(x); w.flush(); } void pln(char x) { w.println(x); w.flush(); } void pln(StringBuilder x) { w.println(x); w.flush(); } void pln(BigInteger x) { w.println(x); w.flush(); } void p(int x) { w.print(x); w.flush(); } void p(long x) { w.print(x); w.flush(); } void p(String x) { w.print(x); w.flush(); } void p(char x) { w.print(x); w.flush(); } void p(StringBuilder x) { w.print(x); w.flush(); } void p(BigInteger x) { w.print(x); w.flush(); } void p(double x) { w.print(x); w.flush(); } void p(boolean x) { w.print(x); w.flush(); } } }
[ { "input": "2\n1 1\n2 2\n", "output": "1\n" } ]
Java
codenet
s836223717
import java.util.Scanner; public class s836223717 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] ryuka = new long[n + 1]; ryuka[0] = 2; ryuka[1] = 1; for (int i = 2; i < n + 1; i++) { ryuka[i] = ryuka[i - 1] + ryuka[i - 2]; } System.out.println(ryuka[n]); } }
[ { "input": "5\n", "output": "11\n" } ]
Java
codenet
s163827828
import java.util.*; public class s163827828 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); String[] s = new String[N]; int aNum = 0; int bNum = 0; boolean flag = true; int ans = 0; for (int i = 0; i < N; i++) { s[i] = sc.next(); if ("B".equals(s[i].substring(0, 1))) { bNum++; } if ("A".equals(s[i].substring(s[i].length() - 1, s[i].length()))) { aNum++; } if ("B".equals(s[i].substring(0, 1)) || "A".equals(s[i].substring(s[i].length() - 1, s[i].length()))) { if (!("B".equals(s[i].substring(0, 1)) && "A".equals(s[i].substring(s[i].length() - 1, s[i].length())))) { flag = false; } } for (int j = 0; j < s[i].length() - 1; j++) { if ("AB".equals(s[i].substring(j, j + 2))) { ans++; } } } ans += Math.min(aNum, bNum); if (Math.min(aNum, bNum) != 0 && flag) { ans--; } System.out.println(ans); } }
[ { "input": "3\nABCA\nXBAZ\nBAD\n", "output": "2\n" } ]
Java
codenet
s798589501
import java.util.*; public class s798589501 { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); int E = s.nextInt(); int Y = s.nextInt(); if (E == 0) { if (Y <= 1911) { System.out.print("M"); System.out.println(Y - 1867); } else if (Y <= 1925) { System.out.print("T"); System.out.println(Y - 1911); } else if (Y <= 1988) { System.out.print("S"); System.out.println(Y - 1925); } else { System.out.print("H"); System.out.println(Y - 1988); } } else if (E == 1) { System.out.println(1867 + Y); } else if (E == 2) { System.out.println(1911 + Y); } else if (E == 3) { System.out.println(1925 + Y); } else { System.out.println(1988 + Y); } } }
[ { "input": "0 2015\n", "output": "H27\n" } ]
Java
codenet
s858314534
import java.util.Scanner; public class s858314534 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner scanner = new Scanner(System.in); int A = scanner.nextInt(); int B = scanner.nextInt(); int T = scanner.nextInt(); log((T / A) * B); } private static void log(String str) { System.out.println(str); } private static void log(int str) { System.out.println(str); } }
[ { "input": "3 5 7\n", "output": "10\n" } ]
Java
codenet
s233008404
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class s233008404 { String[][] colorMtr; int h; int w; int k; public static void main(String[] args) throws IOException { s233008404 mainObj = new s233008404(); mainObj.solve(); } public void solve() throws IOException { FastScanner fs = new FastScanner(); h = fs.nextInt(); w = fs.nextInt(); k = fs.nextInt(); colorMtr = new String[h][]; for (int i = 0; i < h; i++) { colorMtr[i] = fs.next().split(""); } int hPattern = pow(2, h); int wPattern = pow(2, w); int ans = 0; for (int i = 0; i < hPattern; i++) { for (int j = 0; j < wPattern; j++) { if (judge(i, j)) { ans++; } } } System.out.println(ans); } boolean judge(int hPattern, int wPattern) { int[] hBitArr = new int[h]; int[] wBitArr = new int[w]; for (int i = 0; i < h; i++) { if (((hPattern >> i) & 1) == 1) { hBitArr[i] = 1; } } for (int i = 0; i < w; i++) { if (((wPattern >> i) & 1) == 1) { wBitArr[i] = 1; } } int black = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (hBitArr[i] == 1 || wBitArr[j] == 1) { continue; } if ("#".equals(colorMtr[i][j])) { black++; } } } return black == k; } public int pow(int base, int n) { int retVal = 1; while (n > 0) { if ((n & 1) == 1) { retVal *= base; } n >>= 1; base *= base; } return retVal; } public class FastScanner { BufferedReader reader; private StringTokenizer st; public FastScanner() { st = null; reader = new BufferedReader(new InputStreamReader(System.in)); } public String next() throws IOException { if (st == null || !st.hasMoreElements()) { st = new StringTokenizer(reader.readLine()); } return st.nextToken(); } public String nextLine() throws IOException { st = null; String readLine = null; readLine = reader.readLine(); return readLine; } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } public int[] nextIntArr(int n) throws NumberFormatException, IOException { int[] retArr = new int[n]; for (int i = 0; i < n; i++) { retArr[i] = nextInt(); } return retArr; } public long[] nextLongArr(int n) throws NumberFormatException, IOException { long[] retArr = new long[n]; for (int i = 0; i < n; i++) { retArr[i] = nextLong(); } return retArr; } public void close() throws IOException { reader.close(); } } }
[ { "input": "2 3 2\n..#\n###\n", "output": "5\n" } ]
Java
codenet
s880132387
import static java.lang.System.*; import java.math.BigInteger; import java.util.*; class s880132387 { public static Scanner sc = new Scanner(in); public static Random rand = new Random(); public void run() { TCase: while (true) { int W = sc.nextInt(); int H = sc.nextInt(); if (W == 0 && H == 0) { return; } char[][] map = new char[H][W]; for (int h = 0; h < H; h++) { map[h] = sc.next().toCharArray(); } BigInteger[][] dp = new BigInteger[H][W]; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { BigInteger hprev = BigInteger.ZERO; if (h >= 1) { hprev = dp[h - 1][w]; } BigInteger wprev = BigInteger.ZERO; if (w >= 1) { wprev = dp[h][w - 1]; } if (Character.isDigit(map[h][w])) { BigInteger max; if (hprev.compareTo(wprev) > 0) { max = hprev; } else { max = wprev; } dp[h][w] = max.multiply(BigInteger.TEN).add(new BigInteger(map[h][w] + "")); } else { dp[h][w] = BigInteger.ZERO; } } } BigInteger max = BigInteger.ZERO; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { if (dp[h][w].compareTo(max) > 0) { max = dp[h][w]; } } } ln(max); } } public static void main(String[] args) { new s880132387().run(); } public int[] nextIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = sc.nextInt(); } return res; } public static void pr(Object o) { out.print(o); } public static void ln(Object o) { out.println(o); } public static void ln() { out.println(); } }
[ { "input": "7 4\n9R2A993\n0E314A0\n8A900DE\n820R037\n6 7\nJH03HE\nID7722\n0DA1AH\n30C9G5\n99971A\nCA7EAI\nAHLBEM\n20 2\nA1234567891234CBDEGH\nBDEDF908034265091499\n0 0\n", "output": "23900037\n771971\n12345908034265091499\n" } ]
Java
codenet
s066389476
import java.util.Scanner; public class s066389476 { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in) ) { solve(sc); } } public static void solve(Scanner sc) { char[] a = sc.next().toCharArray(); if (a[0] == a[1] || a[1] == a[2] || a[2] == a[0]) { System.out.println("No"); } else { System.out.println("Yes"); } } }
[ { "input": "bac\n", "output": "Yes\n" } ]
Java
codenet
s927992720
import java.util.Scanner; class s927992720 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int a = sc.nextInt(); String op = sc.next(); int b = sc.nextInt(); if ("?".equals(op)) { break; } if ("+".equals(op)) { System.out.println(a + b); } if ("-".equals(op)) { System.out.println(a - b); } if ("*".equals(op)) { System.out.println(a * b); } if ("/".equals(op)) { System.out.println(a / b); } } } }
[ { "input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n0 ? 0\n", "output": "3\n38\n26\n10\n108\n" } ]
Java
codenet
s369598583
import java.util.*; public class s369598583 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int count = 0; int next = 10; for (int i = 1; i <= N; i++) { count++; if (i == next - 1) { i = next * 10 - 1; next *= 100; } } System.out.println(count); } }
[ { "input": "11\n", "output": "9\n" } ]
Java
codenet
s967693306
import java.io.*; import java.util.*; class s967693306 { static final long INF = Long.MAX_VALUE / 2; static final int MOD = 1_000_000_007; static final int SIZE = 1_000_000; long[] fac = new long[SIZE]; long[] inv = new long[SIZE]; long[] finv = new long[SIZE]; FastScanner sc = new FastScanner(); public static void main(String[] args) { new s967693306().solve(); } void solve() { int n = sc.nextInt(); int m = sc.nextInt(); Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < m; i++) { int s = sc.nextInt(); int c = sc.nextInt(); if (map.get(s) != null && map.get(s) != c) { System.out.println(-1); System.exit(0); } map.put(s, c); } for (int i = 0; i < 1000; i++) { String s = "" + i; boolean flag = true; if (s.length() < n) { continue; } for (int j = 0; j < n; j++) { if ((map.get(j + 1) != null && map.get(j + 1) != Character.getNumericValue(s.charAt(j))) || (map.get(j + 1) == null && Character.getNumericValue(s.charAt(j)) != 0)) { if (map.get(j + 1) == null && j == 0 && Character.getNumericValue(s.charAt(j)) == 1) { continue; } flag = false; break; } } if (flag && s.length() == n) { System.out.println(s); System.exit(0); } } System.out.println(-1); } long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } long lcm(long a, long b) { return a * b / gcd(a, b); } long inv(long a) { return pow(a, MOD - 2); } long pow(long a, long r) { long sum = 1; while (r > 0) { if ((r & 1) == 1) { sum *= a; sum %= MOD; } a *= a; a %= MOD; r >>= 1; } return sum; } long modFact(long n) { if (n == 0) { return 1; } return n * modFact(n - 1) % MOD; } long fact(long n) { if (n == 0) { return 1; } return n * fact(n - 1); } void initCOMB() { fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1; for (int i = 2; i < SIZE; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long modComb(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } long comb(long n, long r) { long num = 1; for (long i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } boolean isPrime(long a) { if (a <= 1) { return false; } for (int i = 2; i * i <= a; i++) { if (a % i == 0) { return false; } } return true; } String nextPermutation(String s) { ArrayList<Character> list = new ArrayList<>(); for (int i = 0; i < s.length(); i++) { list.add(s.charAt(i)); } int pivotPos = -1; char pivot = 0; for (int i = list.size() - 2; i >= 0; i--) { if (list.get(i) < list.get(i + 1)) { pivotPos = i; pivot = list.get(i); break; } } if (pivotPos == -1 && pivot == 0) { return null; } int L = pivotPos + 1; int R = list.size() - 1; int minPos = -1; char min = Character.MAX_VALUE; for (int i = R; i >= L; i--) { if (pivot < list.get(i)) { if (list.get(i) < min) { min = list.get(i); minPos = i; } } } Collections.swap(list, pivotPos, minPos); Collections.sort(list.subList(L, R + 1)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { sb.append(list.get(i)); } return sb.toString(); } boolean nextPermutation(long[] a) { for (int i = a.length - 1; i > 0; i--) { if (a[i - 1] < a[i]) { int swapIndex = find(a[i - 1], a, i, a.length - 1); long temp = a[swapIndex]; a[swapIndex] = a[i - 1]; a[i - 1] = temp; Arrays.sort(a, i, a.length); return true; } } return false; } int find(long dest, long[] a, int s, int e) { if (s == e) { return s; } int m = (s + e + 1) / 2; return a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e); } void elimination(int[][] a, int[] b) { int n = a.length; double f; for (int k = 0; k < n - 1; k++) { for (int i = k + 1; i < n; i++) { f = -a[i][k] / a[k][k]; for (int j = k + 1; j < n; j++) { a[i][j] += f * a[k][j]; } b[i] += f * b[k]; } for (int i = n - 1; i >= 0; i--) { for (int j = i + 1; j < n; j++) { b[i] -= a[i][j] * b[j]; } b[i] = b[i] / a[i][i]; } } } } class Pair implements Comparable<Pair> { long a; long b; public Pair(long i, long j) { a = i; b = j; } @Override public int compareTo(Pair p) { if (this.b < p.b) { return -1; } else if (this.b > p.b) { return 1; } else { return 0; } } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; 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 3\n1 7\n3 2\n1 7\n", "output": "702\n" } ]
Java
codenet
s910008321
import java.util.Scanner; public class s910008321 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int h = scanner.nextInt(); int a = scanner.nextInt(); if (h % a == 0) { System.out.println(h / a); } else { System.out.println(h / a + 1); } } }
[ { "input": "10 4\n", "output": "3\n" } ]
Java
codenet
s659026534
import java.util.Scanner; public class s659026534 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int count = 0; for (int i = 1; i <= n; i++) { count += i; } System.out.println(count); } }
[ { "input": "3\n", "output": "6\n" } ]
Java
codenet
s912747097
import java.util.Scanner; public class s912747097 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int r = sc.nextInt(); System.out.println(3 * r * r); } }
[ { "input": "4\n", "output": "48\n" } ]
Java
codenet
s012761786
import java.util.*; public class s012761786 { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { long n = nextLong(); long a = nextLong(); long b = nextLong(); long sa = Math.abs(a - b); long ans = 0; if (sa % 2 == 0) { ans = sa / 2; } else { long aaa = Math.min((n - a), (a - 1)); long bbb = Math.min((n - b), (b - 1)); ans = Math.min(aaa, bbb); sa -= 1; ans += 1; ans += sa / 2; } System.out.println(ans); } static String next() { return sc.next(); } static int nextInt() { return Integer.parseInt(sc.next()); } static long nextLong() { return Long.parseLong(sc.next()); } static double nextDouble() { return Double.parseDouble(sc.next()); } static String[] splitString(String s) { return s.split(""); } static char[] splitChar(String s) { return s.toCharArray(); } static int charToInt(char aaa) { return aaa - 48; } public static int maxInt(int[] a, int lng) { int max = a[0]; for (int i = 1; i < lng; i++) { max = Math.max(max, a[i]); } return max; } public static int minInt(int[] a, int lng) { int min = a[0]; for (int i = 1; i < lng; i++) { min = Math.min(min, a[i]); } return min; } public static long maxLong(long[] a, int lng) { long max = a[0]; for (int i = 1; i < lng; i++) { max = Math.max(max, a[i]); } return max; } public static long minLong(long[] a, int lng) { long min = a[0]; for (int i = 1; i < lng; i++) { min = Math.min(min, a[i]); } return min; } }
[ { "input": "5 2 4\n", "output": "1\n" } ]
Java
codenet
s799557290
import java.util.*; public class s799557290 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); boolean[] ju = new boolean[100001]; int[] pe = new int[100001]; int wa = 0; int ac = 0; for (int i = 0; i < b; i++) { int n = sc.nextInt(); String res = sc.next(); if ("WA".equals(res) && ju[n - 1] != true) { pe[n - 1]++; } if ("AC".equals(res)) { ju[n - 1] = true; } } for (int i = 0; i < a; i++) { if (ju[i]) { ac++; wa += pe[i]; } } System.out.println("" + ac + " " + wa); } }
[ { "input": "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n", "output": "2 2\n" } ]
Java
codenet
s537034016
import java.util.Arrays; import java.util.Scanner; public class s537034016 { static long[] dp; static int mod = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int s = sc.nextInt(); sc.close(); dp = new long[s + 1]; Arrays.fill(dp, -1); dp[0] = 1; System.out.println(dfs(s)); } static long dfs(int s) { if (dp[s] != -1) { return dp[s]; } long ret = 0; for (int i = s - 3; i >= 0; i--) { ret += dfs(i); ret %= mod; } return dp[s] = ret; } }
[ { "input": "7\n", "output": "3\n" } ]
Java
codenet
s818271374
import java.util.*; public class s818271374 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int count1 = 0; int count2 = 0; for (int i = 0; i < N; i++) { int a = sc.nextInt(); if (a % 4 == 0) { count1++; } else if (a % 2 == 0 && (a / 2) % 2 == 1) { count2++; } } if (count1 >= N / 2) { System.out.println("Yes"); } else if (((N / 2 - count1) * 2 + N % 2) == count2) { System.out.println("Yes"); } else { System.out.println("No"); } } }
[ { "input": "3\n1 10 100\n", "output": "Yes\n" } ]
Java
codenet
s518927375
import java.util.Scanner; public class s518927375 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long k = sc.nextLong(); long a = sc.nextLong(); long b = sc.nextLong(); if (b <= a + 2) { System.out.println(1 + k); return; } long x = k - (a - 1); long ans = a + (x / 2) * (b - a) + (x % 2); System.out.println(ans); } }
[ { "input": "4 2 6\n", "output": "7\n" } ]
Java
codenet
s518990279
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class s518990279 { public static final int BIG_NUM = 2000000000; public static final int MOD = 1000000007; public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int ans; while (true) { try { String inputed = br.readLine(); if (inputed.length() == 1 && "0".equals(inputed)) { break; } ans = 0; for (int i = 0; i < inputed.length(); i++) { ans += inputed.charAt(i) - '0'; } System.out.printf("%d\n", ans); } catch (IOException e) { e.printStackTrace(); } } } }
[ { "input": "123\n55\n1000\n0\n", "output": "6\n10\n1\n" } ]
Java
codenet
s287007304
import java.io.BufferedReader; import java.io.InputStreamReader; public class s287007304 { public static void main(String[] args) { String[] s = readLine().split(" "); int a = Integer.parseInt(s[0]); int b = Integer.parseInt(s[1]); if (b % a == 0) { System.out.println(a + b); } else { System.out.println(b - a); } } private static String readLine() { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { return reader.readLine(); } catch (Exception e) { return e.getMessage(); } } }
[ { "input": "4 12\n", "output": "16\n" } ]
Java
codenet
s302760734
import java.util.Scanner; public class s302760734 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char[] s = scanner.next().toCharArray(); char[] t = scanner.next().toCharArray(); boolean check = false; for (int i = s.length - t.length; i >= 0; i--) { boolean check2 = true; for (int j = 0; j < t.length; j++) { if (s[i + j] != '?' && s[i + j] != t[j]) { check2 = false; } } if (check2) { check = true; for (int j = 0; j < t.length; j++) { s[i + j] = t[j]; } } if (check) { break; } } if (check) { for (int i = 0; i < s.length; i++) { if (s[i] == '?') { System.out.print("a"); } else { System.out.print(s[i]); } } System.out.println(); } else { System.out.println("UNRESTORABLE"); } } }
[ { "input": "?tc????\ncoder\n", "output": "atcoder\n" } ]
Java
codenet
s022525398
import java.util.Scanner; class s022525398 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String a = in.next(); String b = in.next(); System.out.println(b + a); } }
[ { "input": "oder atc\n", "output": "atcoder\n" } ]
Java
codenet
s193347311
import java.util.Scanner; public class s193347311 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int intLoop = scan.nextInt(); String strTaro = ""; String strHana = ""; int intTaro = 0; int intHana = 0; for (int i = 0; i < intLoop; i++) { strTaro = scan.next(); strHana = scan.next(); int intJudge = strTaro.compareTo(strHana); if (intJudge < 0) { intHana += 3; } else if (intJudge == 0) { intTaro++; intHana++; } else if (0 < intJudge) { intTaro += 3; } } System.out.println(intTaro + " " + intHana); scan.close(); } }
[ { "input": "3\ncat dog\nfish fish\nlion tiger\n", "output": "1 7\n" } ]
Java
codenet
s498914558
import java.util.*; public class s498914558 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] po = new int[n]; for (int i = 0; i < n; i++) { po[i] = sc.nextInt(); m -= po[i]; } Arrays.sort(po); System.out.println(n + m / po[0]); } }
[ { "input": "3 1000\n120\n100\n140\n", "output": "9\n" } ]
Java
codenet
s566905615
import java.util.*; class s566905615 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); String answer = "No"; if (a + b >= c) { answer = "Yes"; } System.out.println(answer); } }
[ { "input": "50 100 120\n", "output": "Yes\n" } ]
Java
codenet
s967858671
import java.util.Scanner; public class s967858671 { public static void main(String[] args) { int[] num; num = new int[11]; Scanner n = new Scanner(System.in); for (int i = 0; i < 10; i++) { num[i] = n.nextInt(); } for (int a = 9; a >= 0; a--) { for (int b = 0; b < a; b++) { if (num[b] < num[b + 1]) { num[10] = num[b]; num[b] = num[b + 1]; num[b + 1] = num[10]; } } } System.out.println(num[0]); System.out.println(num[1]); System.out.println(num[2]); } }
[ { "input": "1819\n2003\n876\n2840\n1723\n1673\n3776\n2848\n1592\n922\n", "output": "3776\n2848\n2840\n" } ]
Java
codenet
s201062219
import java.io.IOException; import java.util.Scanner; public class s201062219 { public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); String mark; int c = 0; int b = 0; int[] a = new int[100000]; int x = 0; do { c = scan.nextInt(); mark = scan.next(); b = scan.nextInt(); if ("?".equals(mark)) { a[x] = 2000001; break; } else if ("+".equals(mark)) { a[x] = c + b; } else if ("-".equals(mark)) { a[x] = c - b; } else if ("*".equals(mark)) { a[x] = c * b; } else if ("/".equals(mark)) { a[x] = c / b; } x++; } while (true); x = 0; do { if (a[x] == 2000001) { break; } System.out.println(a[x]); x++; } while (true); scan.close(); } }
[ { "input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n0 ? 0\n", "output": "3\n38\n26\n10\n108\n" } ]
Java
codenet
s004995062
import java.math.*; import java.util.*; public class s004995062 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String sa = sc.next(); String sb = sc.next(); BigDecimal A = new BigDecimal(sa); BigDecimal B = new BigDecimal(sb); System.out.println(A.multiply(B).setScale(0, RoundingMode.DOWN)); } }
[ { "input": "198 1.10\n", "output": "217\n" } ]
Java
codenet
s185737640
import java.util.Scanner; public class s185737640 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String S = sc.nextLine(); sc.close(); if (S.length() % 2 == 1) { S = S.substring(0, S.length() - 1); } else { S = S.substring(0, S.length() - 2); } for (; S.length() > 0; S = S.substring(0, S.length() - 2)) { if (isEvenString(S)) { break; } } System.out.println(S.length()); } static boolean isEvenString(String s) { String a = s.substring(0, s.length() / 2); String b = s.substring(s.length() / 2); return a.equals(b); } }
[ { "input": "abaababaab\n", "output": "6\n" } ]
Java
codenet
s612878490
import static java.lang.Integer.parseInt; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class s612878490 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; String[] words; line = br.readLine(); int N; int M; N = parseInt(line.substring(0, line.indexOf(' '))); M = parseInt(line.substring(line.indexOf(' ') + 1)); int[] shortage = new int[M]; for (int i = 0; i < M; i++) { line = br.readLine(); int A = parseInt(line.substring(0, line.indexOf(' '))); shortage[i] = N > A ? N - A : 0; } Arrays.sort(shortage); int ans = 0; for (int i = 0; i < M - 1; i++) { ans += shortage[i]; } System.out.println(ans); } }
[ { "input": "4 5\n1 7\n6 2\n3 5\n4 4\n0 8\n", "output": "4\n" } ]
Java
codenet
s312529015
import java.util.Scanner; public class s312529015 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int B = sc.nextInt(); if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) { System.out.println("Possible"); } else { System.out.println("Impossible"); } } }
[ { "input": "4 5\n", "output": "Possible\n" } ]
Java
codenet
s699933302
import java.util.Scanner; public class s699933302 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = Integer.parseInt(sc.next()); int b = Integer.parseInt(sc.next()); int c = Integer.parseInt(sc.next()); int count = 0; for (int i = a; i <= b; i++) { if (c % i == 0) { count++; } } System.out.println(count); } }
[ { "input": "5 14 80\n", "output": "3\n" } ]
Java
codenet
s493101281
import java.io.*; import java.util.*; public class s493101281 { public static final long MOD = 1000000007; public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); Integer i; Integer j; Integer k; Integer n = 0; Integer m = 0; Integer h = 0; Integer w = 0; Integer ans = 0; long a = 0; long b = 0; long c = 0; long d = 0; long x = 0; long y = 0; long z = 0; List<Integer> l = new ArrayList<>(); List<String> s = new ArrayList<>(); List<Pair> p = new ArrayList<>(); n = sc.nextInt(); for (i = 0; i < n; i++) { l.add(sc.nextInt()); } Collections.sort(l); print(l.get(n / 2) - l.get(n / 2 - 1)); out.flush(); } private static void print(Object o) { System.out.println(o.toString()); } private static long lcm(long m, long n) { return m * n / gcd(m, n); } private static long gcd(long m, long n) { if (m < n) { return gcd(n, m); } if (n == 0) { return m; } return gcd(n, m % n); } private static class Pair { private int key; private int value; public Pair(int key, int value) { this.key = key; this.value = value; } public int getValue() { return this.value; } public int getKey() { return this.key; } } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; 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": "6\n9 1 4 4 6 7\n", "output": "2\n" } ]
Java
codenet
s890213274
import java.util.Scanner; public class s890213274 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a1 = sc.nextInt(); int a2 = sc.nextInt(); int a3 = sc.nextInt(); if ((a1 + a2 + a3) >= 22) { System.out.println("bust"); } else { System.out.println("win"); } } }
[ { "input": "5 7 9\n", "output": "win\n" } ]
Java
codenet
s264878779
import java.util.Scanner; public class s264878779 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int n = s.length(); long ans = 0; for (int mask = 0; mask < 1 << (n - 1); mask++) { long sum = 0; String x = "" + s.charAt(0); for (int i = 0; i < n - 1; i++) { if ((mask & (1 << i)) >= 1) { x += "+" + s.charAt(i + 1); } else { x += s.charAt(i + 1); } } String[] split = x.split("\\+"); for (int i = 0; i < split.length; i++) { sum += Long.valueOf(split[i]); } ans += sum; } System.out.println(ans); } }
[ { "input": "125\n", "output": "176\n" } ]
Java
codenet
s968213233
import java.io.*; import java.util.*; public class s968213233 { public s968213233(FastScanner in, PrintWriter out, int test) { int N = in.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } Arrays.sort(A); long res = 0; PriorityQueue<int[]> q = new PriorityQueue<>( Comparator.comparingInt((int[] e) -> Math.min(e[0], e[1])).reversed()); q.add(new int[] {A[N - 1], A[N - 1]}); for (int i = N - 2; i >= 0; i--) { int a = A[i]; int[] place = q.remove(); res += Math.min(place[0], place[1]); q.add(new int[] {place[0], a}); q.add(new int[] {a, place[1]}); } out.println(res); } public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); FastScanner in = new FastScanner(System.in); for (int t = 1; t <= 1; t++) { s968213233 sol = new s968213233(in, out, t); } out.close(); } } class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; } int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } String nextLine() { int c = read(); while (isEndline(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } }
[ { "input": "4\n2 2 1 3\n", "output": "7\n" } ]
Java
codenet
s445598069
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class s445598069 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); int[] s = new int[100010]; for (int i = 0; i < n; i++) { s[Integer.parseInt(str[i])]++; } int dec = 0; for (int i = 0; i < s.length; i++) { if (s[i] != 0) { if (s[i] % 2 == 0) { s[i] = 2; } else { s[i] = 1; } } } int one = 0; int two = 0; for (int i = 0; i < s.length; i++) { if (s[i] == 2) { two++; } else if (s[i] == 1) { one++; } } if (two % 2 != 0) { one--; } System.out.println(two + one); } }
[ { "input": "5\n1 2 1 3 7\n", "output": "3\n" } ]