public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int t = in.readInt(); int[] a = new int[400000000]; for (int j = 1; j <= 400000000; j++) { int ans2 = 0; int j1 = j; while (j1 > 0) { int x = j1 % 10; if (x % 2 == 0) { ans2 += (2 * x); } else { ans2 += x; } j1 = j1 / 10; } a[j - 1] = ans2 % 10; } for (int i = 0; i < t; i++) { int a1 = in.readInt(); int b1 = in.readInt(); int ans = 0; for (int j = a1; j <= b1; j++) { ans += a[j - 1]; } out.printLine(ans); } { out.close(); } }
public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.readInt(); long m = in.readLong(); long[] b = new long[n]; long mf = 0; for (int i = 0; i < n; i++) { b[i] = in.readLong(); } long ans = 0; long cntm = 0; for (int j = 0; j < n; j++) { ans += ((b[j] * (b[j] * (b[j] + 1) / 2)) % m); if (b[j] <= m) { ans += FACT(b[j], m); // ans=ans.mod(m); } else { if (cntm == 0) { mf = FACT(m, m); cntm++; } ans += mf; // ans=ans.mod(m); } // System.out.println(ans); // ans=ans.mod(new BigInteger(Integer.toString(m))); } out.printLine(ans); { out.close(); } }
public static void main(String[] args) throws Exception { // System.setIn(new // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt")); InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int t = in.readInt(); NXT: while (t-- > 0) { int n = in.readInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = (long) in.readDouble(); } long ans = 1; for (int j = 0; j < n; j++) { ans -= a[j]; ans *= 2; if (ans < 0) { out.printLine("No"); continue NXT; } } if (ans != 0) { out.printLine("No"); } else { out.printLine("Yes"); } } }
public static void main(String[] args) throws Exception { // System.setIn(new // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt")); InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.readInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.readInt(); } HashSet<Integer> hs = new HashSet<Integer>(); for (int i = 0; i < n; i++) { while (a[i] % 2 == 0) { a[i] /= 2; } while (a[i] % 3 == 0) { a[i] /= 3; } hs.add(a[i]); if (hs.size() > 1) { out.printLine("No"); return; } } out.printLine("Yes"); }
public static void main(String[] args) { BufferedReader in; try { in = new BufferedReader( new FileReader( "/Users/rahulkhairwar/Documents/IntelliJ IDEA Workspace/Competitive " + "Programming/src/com/google/codejam16/qualificationround/inputB.txt")); OutputWriter out = new OutputWriter(System.out); Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 28); thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } out.flush(); in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int tc = in.nextInt(); while (tc-- > 0) { String a = in.nextString(); String b = in.nextString(); int[][] dp = new int[2][b.length() + 1]; dp[1][0] = 1; for (int i = 0; i <= b.length(); i++) { dp[0][i] = i; } for (int i = 1, r = a.length(); i <= r; i++) { dp[i % 2][0] = i; for (int j = 1, c = b.length(); j <= c; j++) { if (a.charAt(i - 1) == b.charAt(j - 1)) { dp[i % 2][j] = dp[(i - 1) % 2][j - 1]; } else { dp[i % 2][j] = 1 + min(dp[(i - 1) % 2][j], dp[(i - 1) % 2][j - 1], dp[i % 2][j - 1]); } } } out.println(dp[a.length() % 2][b.length()]); } out.flush(); out.close(); }
public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); { out.close(); } }
public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); Task10107 solver = new Task10107(); solver.solve(1, in, out); out.close(); }
public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); Solver solver = new Solver(in, out); solver.solve(); in.close(); out.flush(); out.close(); }
public static void main(String[] args) { in = new InputReader(System.in); out = new OutputWriter(System.out); solve(); out.flush(); in.close(); out.close(); }
public static void main(String[] args) { InputReader ir = new InputReader(System.in); OutputWriter ow = new OutputWriter(System.out); int tests = ir.readInt(); for (int i = 0; i < tests; i++) { int num = ir.readInt(); if ((num & 1) == 0) ow.printLine("ALICE"); else ow.printLine("BOB"); } ow.close(); }
public static void main(String[] argv) throws IOException { Task t; boolean home = argv.length > 0 && argv[0].equals("test"); InputStream inputStream; OutputStream outputStream; if (home) { inputStream = new FileInputStream(Task.filename + ".in"); outputStream = new FileOutputStream(Task.filename + ".out"); } else { switch (Task.read) { case 0: inputStream = new FileInputStream(Task.filename + ".in"); outputStream = new FileOutputStream(Task.filename + ".out"); break; case 1: inputStream = new FileInputStream("input.txt"); outputStream = new FileOutputStream("output.txt"); break; default: inputStream = System.in; outputStream = System.out; break; } } InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream, home); if (home) do { long time = System.currentTimeMillis(); t = new Task(); t.in = in; t.out = out; t.run(); out.writeln(); out.writeln("=====Time:" + (System.currentTimeMillis() - time)); out.flush(); } while (in.toNextTest()); else { t = new Task(); t.in = in; t.out = out; t.run(); } out.close(); }
public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int tc = in.nextInt(); while (tc-- > 0) { int n = in.nextInt(); out.println(countTri(n)); } out.flush(); out.close(); }
@Test public void testParseConfiguration() throws Exception { JmxTransExporterConfiguration config = new JmxTransConfigurationXmlLoader("classpath:jmxtrans-agent.xml").loadConfiguration(); assertThat(config.collectInterval, is(11)); assertThat(config.collectIntervalTimeUnit, is(TimeUnit.SECONDS)); assertThat(config.getConfigReloadInterval(), equalTo(-1)); OutputWriter decoratedOutputWriter = config.outputWriter; // CircuitBreaker assertTrue(decoratedOutputWriter.getClass().equals(OutputWriterCircuitBreakerDecorator.class)); OutputWriterCircuitBreakerDecorator circuitBreakerDecorator = (OutputWriterCircuitBreakerDecorator) decoratedOutputWriter; assertThat(circuitBreakerDecorator.isDisabled(), is(false)); // Graphite Writer assertTrue( circuitBreakerDecorator.delegate.getClass().equals(GraphitePlainTextTcpOutputWriter.class)); GraphitePlainTextTcpOutputWriter graphiteWriter = (GraphitePlainTextTcpOutputWriter) circuitBreakerDecorator.delegate; assertThat(graphiteWriter.graphiteServerHostAndPort.getPort(), is(2203)); assertThat(graphiteWriter.graphiteServerHostAndPort.getHost(), is("localhost")); assertThat(graphiteWriter.getMetricPathPrefix(), is("app_123456.server.i876543.")); assertThat(config.queries.size(), is(13)); Map<String, Query> queriesByResultAlias = indexQueriesByResultAlias(config.queries); { Query query = queriesByResultAlias.get("os.systemLoadAverage"); assertThat(query.objectName, is(new ObjectName("java.lang:type=OperatingSystem"))); assertThat(query.getAttributes(), contains("SystemLoadAverage")); assertThat(query.resultAlias, is("os.systemLoadAverage")); assertThat(query.key, is((String) null)); } { Query query = queriesByResultAlias.get("jvm.heapMemoryUsage.used"); assertThat(query.objectName, is(new ObjectName("java.lang:type=Memory"))); assertThat(query.getAttributes(), contains("HeapMemoryUsage")); assertThat(query.resultAlias, is("jvm.heapMemoryUsage.used")); assertThat(query.key, is("used")); } Map<String, Invocation> invocationsByResultAlias = indexInvocationsByResultAlias(config.invocations); { Invocation invocation = invocationsByResultAlias.get("jvm.gc"); assertThat(invocation.objectName, is(new ObjectName("java.lang:type=Memory"))); assertThat(invocation.operationName, is("gc")); assertThat(invocation.resultAlias, is("jvm.gc")); } }
public static void main(String[] args) { AdditionAndMultiplication aAM = new AdditionAndMultiplication(); reader = aAM.new InputReader(System.in); writer = aAM.new OutputWriter(System.out); getAttributes(); writer.flush(); reader.close(); writer.close(); }
public static void main(String[] args) throws IOException { // InputStream inputStream = new FileInputStream("replaceme.in"); // OutputStream outputStream = new FileOutputStream("replaceme.out"); ///////////////////////////////////////////////////////////////////// InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); System.exit(0); }
public static void main(String[] args) { First first = new First(); reader = first.new InputReader(System.in); writer = first.new OutputWriter(System.out); getAttributes(); writer.flush(); reader.close(); writer.close(); }
public void solve(int testNumber, InputReader in, OutputWriter out) { String X; PriorityQueue<Integer> pq = new PriorityQueue<>(); Stack<Integer> stack = new Stack<>(); while ((X = in.next()) != null) { int x = Integer.valueOf(X); pq.add(x); int sz = pq.size(); int median = 0; if (sz == 1) { median = pq.peek(); } else { for (int i = 0; i <= sz / 2; i++) { stack.add(pq.poll()); if ((i == (sz / 2) - 1 && sz % 2 == 0) || i == (sz / 2)) { median += stack.peek(); } } if (sz % 2 == 0) median /= 2; } while (!stack.isEmpty()) pq.add(stack.pop()); out.printLine(median); } }
public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int t = in.readInt(); for (int i = 0; i < t; i++) { int a = in.readInt(); if (a % 2 == 0) { out.printLine(a); } else { out.printLine(a - 1); } } { out.close(); } }
public static void main(String[] args) throws Exception { // System.setIn(new // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt")); InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.readInt(); // entering number of vertices int[][] a = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = in.readInt(); } } { out.close(); } }
public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); while (true) { int n = in.nextInt(); if (n == 0) break; int c = 0; while (n > 1) { n /= 2; c++; } out.println(c); } out.flush(); out.close(); }
public void solve(int testNumber, InputReader in, OutputWriter out) { long money = in.readLong(); long fee = in.readLong(); int count = in.readInt(); long[] price = new long[count]; long[] stale = new long[count]; IOUtils.readLongArrays(in, price, stale); long currentDeliveryCost = fee; long lastStale = -1; long[] antiStale = stale.clone(); for (int i = 0; i < count; i++) antiStale[i] = -antiStale[i]; Integer[] order = ListUtils.order(Array.wrap(price), Array.wrap(antiStale)); long answer = 0; for (int i : order) { if (lastStale >= stale[i]) continue; long p1 = currentDeliveryCost; long p2 = price[i]; long q = stale[i] - lastStale; long c = lastStale + 1; if (p1 / p2 >= c) { if (money / q >= price[i]) { long alpha1 = money / (currentDeliveryCost + q * price[i]); long beta1 = q * alpha1; if (alpha1 * p1 + beta1 * p2 > money) throw new RuntimeException(); if (beta1 > q * alpha1) throw new RuntimeException(); answer = Math.max(answer, c * alpha1 + beta1); long alpha2 = alpha1 + 1; if (alpha2 * currentDeliveryCost <= money) { long remainingMoney = money - alpha2 * p1; long beta2 = remainingMoney / p2; if (alpha2 * p1 + beta2 * p2 > money) throw new RuntimeException(); if (beta2 > q * alpha2) throw new RuntimeException(); answer = Math.max(answer, c * alpha2 + beta2); } } else { long alpha = 1; long beta = (money - currentDeliveryCost) / p2; if (alpha * p1 + beta * p2 > money) throw new RuntimeException(); if (beta > q * alpha) throw new RuntimeException(); answer = Math.max(answer, c * alpha + beta); } } else { long alpha = money / p1; long remainingMoney = money - alpha * p1; long beta = remainingMoney / p2; if (remainingMoney / q >= alpha) beta = Math.min(beta, alpha * q); if (alpha * p1 + beta * p2 > money) throw new RuntimeException(); if (beta > q * alpha) throw new RuntimeException(); answer = Math.max(answer, c * alpha + beta); } if (money / price[i] >= stale[i] - lastStale) { currentDeliveryCost += (stale[i] - lastStale) * price[i]; lastStale = stale[i]; } else break; if (currentDeliveryCost > money) break; } out.printLine("Case #" + testNumber + ":", answer); }
public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(), m = in.nextInt(); boolean[] tab = new boolean[255 * 255 * 2]; for (int p = 0; p <= m; ++p) { for (int q = 0; q <= p; ++q) { tab[p * p + q * q] = true; } } List<Integer> lst = new ArrayList<Integer>(); for (int i = 0; i < tab.length; ++i) { if (tab[i]) { lst.add(i); } } boolean found = false; int b = 1; while (true) { if ((n - 1) * b > m * m * 2) { break; } for (int idx = 0; idx + n <= lst.size(); ++idx) { int a = lst.get(idx); if (a + (n - 1) * b > m * m * 2) { break; } // out.println(a, b); boolean flag = true; for (int i = n - 1; i >= 0; --i) { int x = a + i * b; if (!tab[x]) { flag = false; break; } } if (flag) { out.println(a, b); found = true; } } b++; } if (!found) { out.println("NONE"); } }
/** * @return A {@link PrintWriter} wrapping the {@link #getOutputStream output stream}. The writer * is created if it does not already exist. */ public PrintWriter getPrintWriter(String encoding) { getOutputStream(); if (_writer == null) { _writer = new OutputWriter(); _printWriter = new UncheckedPrintWriter(_writer); } _writer.setCharacterEncoding(encoding); return _printWriter; }
static void getAttributes() { t = reader.nextInt(); for (int i = 0; i < t; i++) { x = reader.next(); y = reader.next(); int len = x.length(); int j = 0; for (j = 0; j < len; j++) { if (x.charAt(j) == '?' || y.charAt(j) == '?' || x.charAt(j) == y.charAt(j)) continue; else break; } if (j == len) writer.println("Yes"); else writer.println("No"); } }
public static void main(String[] args) throws Exception { // System.setIn(new // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt")); InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.readInt(), k = in.readInt(), d = in.readInt(); long[] dp1 = new long[n + 1], dp2 = new long[n + 1]; dp1[0] = dp2[0] = 1; for (int i = 1; i <= n; i++) { for (int j = i - 1; j >= i - k && j >= 0; j--) { dp1[i] = (dp1[i] % MOD + dp1[j] % MOD) % MOD; } for (int j = i - 1; j >= i - d + 1 && j >= 0; j--) { dp2[i] = (dp2[i] % MOD + dp2[j] % MOD) % MOD; } } long ans = ((dp1[n] % MOD - dp2[n] % MOD) + MOD) % MOD; out.printLine(ans); }
public static void main(String[] args) { InputStream inputStream; try { inputStream = new FileInputStream(args[0]); } catch (IOException e) { throw new RuntimeException(e); } OutputStream outputStream; try { outputStream = new FileOutputStream("output.txt"); } catch (IOException e) { throw new RuntimeException(e); } InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); }
public static void main(String[] args) throws Exception { // System.setIn(new // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt")); InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.readInt(), k = in.readInt(), seg = n / k; int[] a = new int[seg], b = new int[seg], cases = new int[seg]; for (int i = 0; i < seg; i++) { a[i] = in.readInt(); } for (int i = 0; i < seg; i++) { b[i] = in.readInt(); } int[] ten = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}, nine = {0, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999}; for (int i = 0; i < (n / k); i++) { cases[i] = 0; cases[i] = ten[k] / a[i]; if (ten[k] % a[i] == 0) { cases[i]--; } cases[i] = cases[i] % MOD; if (b[i] == 0) { cases[i] = cases[i] - ((ten[k - 1] - 1) / a[i]); continue; } int lw = (b[i] - 1) * ten[k - 1] + nine[k - 1]; int up = b[i] * ten[k - 1] + nine[k - 1]; int lw_cases = lw / a[i]; int up_cases = up / a[i]; cases[i] = cases[i] - (up_cases - lw_cases); cases[i] = (cases[i] + 1) % MOD; } long prod = 1; for (int i = 0; i < (n / k); i++) { prod = (prod * cases[i]) % MOD; } out.printLine(prod); }
void solve() { n = in.nextInt(); m = in.nextInt(); days = new int[n + 1]; req = new int[m + 1]; for (int i = 1; i <= n; i++) days[i] = in.nextInt(); for (int i = 1; i <= m; i++) req[i] = in.nextInt(); if (!isPossible(n)) { out.println(-1); return; } int low, high, mid; low = 1; high = n; mid = 1; while (low <= high) { mid = low + high >> 1; boolean poss = isPossible(mid); if (poss) { boolean prev = isPossible(mid - 1); if (prev) high = mid - 1; else break; } else low = mid + 1; } out.println(mid); }
void solve(int testNumber) { n = in.nextInt(); q = in.nextInt(); tree = new Node[4 * n]; buildTree(1, 0, n - 1); for (int i = 0; i < q; i++) { int type, from, to; type = in.nextInt(); from = in.nextInt(); to = in.nextInt(); if (type == 0) update(1, 0, n - 1, from, to); else out.println(query(1, 0, n - 1, from, to)); } }