public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner sc = new Scanner(System.in); String[][] numArray = new String[6][]; int largestSum = 0; for (int i = 0; i < 6; i++) { numArray[i] = sc.nextLine().split(" "); } for (int i = 0; i <= 3; i++) { for (int j = 0; j <= 3; j++) { int sum = Integer.parseInt(numArray[i][j]) + Integer.parseInt(numArray[i][j + 1]) + Integer.parseInt(numArray[i][j + 2]) + Integer.parseInt(numArray[i + 1][j + 1]) + Integer.parseInt(numArray[i + 2][j]) + Integer.parseInt(numArray[i + 2][j + 1]) + Integer.parseInt(numArray[i + 2][j + 2]); // System.out.println(sum); if (i == 0 && j == 0) { largestSum = sum; } else { if (sum > largestSum) { largestSum = sum; } } } } System.out.println(largestSum); }
public void solve() { Scanner s = new Scanner(System.in); while (s.hasNext()) { int n = s.nextInt(); System.out.println(ci(n + 1)); } }
public void solve() throws Exception { int n = in.nextInt(); int[] a = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); sum += a[i]; } sum /= 2; boolean[] dp = new boolean[sum + 1]; dp[0] = true; for (int tmp : a) { for (int i = sum; i >= tmp; i--) { if (dp[i - tmp]) { dp[i] = true; } } } String ans = dp[sum] ? "YES" : "NO"; out.println(ans); }
public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int m = s.nextInt(); int[][] b = new int[n][m]; for (int i = 0; i < n; i++) { String line = s.next(); for (int j = 0; j < m; j++) { b[i][j] = line.charAt(j) - '0'; } } int[][] a = new int[n][m]; for (int i = 0; i < n - 2; i++) { for (int j = 1; j < m - 1; j++) { if (b[i][j] > 0) { a[i + 1][j] = b[i][j]; b[i][j] -= a[i + 1][j]; b[i + 1][j - 1] -= a[i + 1][j]; b[i + 1][j + 1] -= a[i + 1][j]; b[i + 2][j] -= a[i + 1][j]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { System.out.print(a[i][j]); } System.out.println(); } }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); long d3 = 3, d5 = 5, d15 = 15; long n3 = 0, n5 = 0, n15 = 0; if ((1 <= T) && (T <= 100000)) { for (int j = 0; j < T; j++) { long sum3 = 0, sum5 = 0, sum15 = 0, sum = 0; long l3, l5, l15 = 0; int N = sc.nextInt(); if ((1 <= N) && (N <= 1000000000)) { N = N - 1; l3 = N % 3; l3 = N - l3; n3 = (l3 - 3) / 3 + 1; sum3 = (3 * ((n3) + 1) * (n3)) / 2; l5 = N % 5; l5 = N - l5; n5 = (l5 - 5) / 5 + 1; sum5 = (5 * ((n5) + 1) * (n5)) / 2; l15 = N % 15; l15 = N - l15; n15 = (l15 - 15) / 15 + 1; sum15 = (15 * ((n15) + 1) * (n15)) / 2; sum = sum3 + sum5 - sum15; System.out.println(sum); } } } }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int N = in.nextInt(); Node[] nodes = new Node[N]; for (int i = 0; i < N; i++) { nodes[i] = new Node(i + 1); } for (int i = 0; i < N; i++) { int a = in.nextInt(); int b = in.nextInt(); Node n = nodes[i]; if (a != -1) n.left = nodes[a - 1]; if (b != -1) n.right = nodes[b - 1]; } int T = in.nextInt(); for (int i = 0; i < T; i++) { int K = in.nextInt(); swap(nodes[0], K, 1); Inorder(nodes[0]); System.out.println(""); } }
public static void main(String args[]) { Scanner input = new Scanner(System.in); int T = input.nextInt(); CPoint[] array = new CPoint[SIZE]; for (int t = 0; t < T; t++) { int n = input.nextInt(); for (int i = 0; i < n; i++) { int a = input.nextInt(); int b = input.nextInt(); array[i] = new CPoint(); array[i].setPoint(a, b); } int ans = 0; for (int i = 0; i < n; i++) { int sum = 0; for (int j = 0; j < n; j++) if (i != j) { if (array[j].x > array[i].x && array[j].y > array[i].y) sum++; if (array[j].x < array[i].x && array[j].y < array[i].y) sum++; } if (sum > ans) ans = sum; } System.out.println(ans); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int arr[][] = new int[6][6]; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { arr[i][j] = in.nextInt(); } } List sum = new ArrayList(); for (int i = 1; i < 5; i++) { for (int j = 1; j < 5; j++) { int temp = arr[i][j] + arr[i - 1][j - 1] + arr[i - 1][j] + arr[i - 1][j + 1] + arr[i + 1][j - 1] + arr[i + 1][j] + arr[i + 1][j + 1]; sum.add(temp); } } System.out.println(Collections.max(sum)); }
public static void main(String[] args) throws Exception { long[] ans = new long[30]; ans[1] = 1; ans[2] = 9; ans[3] = 89; ans[4] = 89; long step = 500; for (int i = 5; i <= 20; ++i) { long now = ans[i - 1]; while (!check(now, i)) now += step; ans[i] = now; // System.out.println(ans[i]); step *= 5; } for (int i = 1; i <= 20; ++i) { System.out.printf("a[%d]=%dll;\n", i, ans[i]); } Scanner cin = new Scanner(new BufferedInputStream(System.in)); int tests = cin.nextInt(); int ca = 0; while (tests-- > 0) { int n = cin.nextInt(); System.out.printf("%d %d ", ++ca, n); System.out.println(ans[n]); } }
public void init() { Scanner scan = new Scanner(System.in); count = scan.nextInt(); x0 = scan.nextLong(); y0 = scan.nextLong(); int result = 0; boolean special = false; for (int i = 0; i < count; i++) { long tempx = scan.nextLong(); long tempy = scan.nextLong(); if (tempx == x0 && tempy == y0) { special = true; continue; } boolean isDuplicate = false; for (int j = 0; j < result; j++) { long x1 = xList.get(j); long y1 = yList.get(j); if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) { isDuplicate = true; break; } } if (!isDuplicate) { xList.add(tempx); yList.add(tempy); result++; } } if (special && result == 0) result = 1; System.out.println(result); scan.close(); }
public static void main(String[] args) throws Exception { Scanner s = new Scanner(new FileReader("pb.in")); while (s.hasNext()) { String line = s.nextLine(); String[] rep = line.split("\\("); String[] nonrep = (rep[0] + "0").split("\\."); long num1 = Integer.parseInt(rep[1].substring(0, rep[1].length() - 1)); String nine = ""; while (nine.length() != rep[1].length() - 1) nine += "9"; for (int i = 0; i < nonrep[1].length() - 1; i++) nine += "0"; String ten = ""; while (nonrep[1].length() != ten.length()) ten += "0"; ten = "1" + ten; String nr = nonrep[0] + nonrep[1]; long den1 = Long.parseLong(nine); long den2 = Long.parseLong(ten); long num2 = Long.parseLong(nr); long num = num1 * den2 + num2 * den1; long den = den1 * den2; long gcd = new BigInteger("" + num).gcd(new BigInteger("" + den)).longValue(); num /= gcd; den /= gcd; System.out.println(line + " = " + num + " / " + den); } }
public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(3 ^ 5 ^ 4 ^ 5 ^ 5 ^ 6 ^ 6 ^ 7); System.out.println(3 ^ 7); int[] a = new int[10]; for (int i = 0; i < 10; i++) a[i] = input.nextInt(); for (int aa : a) { System.out.print(aa); } sss(1, 3, 4, 5, 6, 7, 8, 9); BigInteger aa = new BigInteger( "12809348038290834905895869048359034859083495894038590438590348590834905890345"); BigInteger bb = new BigInteger("111111111111111111111"); System.out.println(aa.subtract(bb)); BigDecimal rrrr = new BigDecimal(input.next()); int aaa; double b; float c; StringBuilder sssss = new StringBuilder("1234234"); System.out.println(); Integer ttt = 4; Double t1 = 14.2; }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int arr[][] = new int[6][6]; int max = -10000; // lowest possible value is -9*6=-54 int sum; for (int arr_i = 0; arr_i < 6; arr_i++) { for (int arr_j = 0; arr_j < 6; arr_j++) { arr[arr_i][arr_j] = in.nextInt(); } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { sum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2]; max = Math.max(sum, max); } } System.out.println(max); }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ try { Scanner sc = new Scanner(new File("/home/santosh/Desktop/testData")); int testCases = sc.nextInt(); int i = 0; ArrayList<ArrayList<Integer>> inputArraysList = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> list; while (i++ < testCases) { int n = sc.nextInt(); int k = 0; list = new ArrayList<Integer>(); while (k < n) { list.add(sc.nextInt()); k++; } inputArraysList.add(list); } // System.out.println(inputArraysList.size()); for (ArrayList<Integer> arr : inputArraysList) { countPairs(arr.toArray(new Integer[arr.size()])); } } catch (Exception e) { } }
public static void main(String[] args) { Scanner inp = new Scanner(System.in); int n = inp.nextInt(); String[] store = new String[n]; for (int i = 0; i < n; i++) store[i] = inp.next(); int[] cnt = new int[n]; Arrays.fill(cnt, 0); String str = inp.next(); for (int j = 0; j < n; j++) { int l1 = store[j].length(); for (int k = 0; k <= (str.length() - l1); k++) { if (str.substring(k, k + l1).equals(store[j])) { cnt[j] = cnt[j] + 1; } } } int y = 0; for (int m = 0; m < n; m++) { y = Math.max(y, cnt[m]); } System.out.println(y); for (int h = 0; h < n; h++) { if (cnt[h] == y) System.out.println(store[h]); } }
public void init() { Scanner scan = new Scanner(System.in); n = scan.nextInt(); m = scan.nextInt(); for (int i = 0; i < n; i++) { String input = scan.next(); record.add(input); } for (int i = 0; i < m; i++) { String input = scan.next(); char[] charArray = input.toCharArray(); boolean isValid = false; for (int j = 0; j < charArray.length; j++) { char c = charArray[j]; for (char d = 'a'; d <= 'c'; d = (char) (d + 1)) { if (d == c) continue; charArray[j] = d; if (record.contains(new String(charArray))) { isValid = true; break; } } charArray[j] = c; if (isValid) break; } if (isValid) System.out.println("YES"); else System.out.println("NO"); } scan.close(); }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); System.out.println("You entered integer " + n); List<BigDecimal> BD = new ArrayList<BigDecimal>(); // System.out.println("Enter a string"); // n = scanner.nextInt(); /* while(scanner.hasNext()){ BD.add(new BigDecimal(scanner.next())); break; } for(BigDecimal bd :BD){ System.out.println(bd); } */ for (int i = 0; i < n; i++) { BD.add(new BigDecimal(scanner.next())); } // Collections.reverse(BD); Collections.sort(BD, Collections.reverseOrder()); for (BigDecimal bd : BD) { System.out.println(bd); } }
public static void main(String args[]) throws Exception { Scanner cin = new Scanner(System.in); BigInteger s, M; int p, i; while (cin.hasNext()) { p = cin.nextInt(); s = BigInteger.valueOf(4); M = BigInteger.ONE; M = M.shiftLeft(p).subtract(BigInteger.ONE); for (i = 0; i < p - 2; ++i) { s = s.multiply(s).subtract(BigInteger.valueOf(2)); while (s.bitLength() > p) { s = s.shiftRight(p).add(s.and(M)); } } if (s.compareTo(BigInteger.ZERO) == 0 || s.compareTo(M) == 0) { System.out.println(0); continue; } String ans = ""; while (s.compareTo(BigInteger.ZERO) > 0) { long buf = s.mod(BigInteger.valueOf(16)).longValue(); ans += Integer.toHexString((int) buf); s = s.divide(BigInteger.valueOf(16)); } for (i = ans.length() - 1; i >= 0; --i) System.out.print(ans.charAt(i)); System.out.println(); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] data = new int[n]; for (int i = 0; i < n; i++) data[i] = -1; for (int i = 0; i < n; i++) { in.next(); if (in.nextInt() == 1) { data[i] = in.nextInt(); } } int max = 10000; int max_sum = 0; int min_sum = 0; int cnt = 0; for (int i = 0; i < n; i++) { if (data[i] == -1) { max_sum += max; cnt++; } else { max = data[i]; max_sum += data[i]; min_sum += (cnt + 1) * data[i]; cnt = 0; } } min_sum += cnt; // System.out.println(min_sum+" "+max_sum); if (min_sum <= 100 * 100 && max_sum >= 100 * 100) System.out.println("YES"); else System.out.println("NO"); }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int cases = in.nextInt(); for (int i = 0; i < cases; i++) { System.out.println(digits(in.nextInt())); } }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int numberOfTestCases = in.nextInt(); for (int i = 0; i < numberOfTestCases; i++) { int n = in.nextInt(); System.out.println((n * (n - 1)) / 2); } }
public static void main(String[] args) { Scanner s = new Scanner(System.in); BigInteger a = new BigInteger(s.next()); BigInteger b = new BigInteger(s.next()); BigInteger ad = a.add(b); BigInteger mu = a.multiply(b); System.out.println(ad); System.out.println(mu); }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in); BigInteger bigInteger1 = scan.nextBigInteger(); BigInteger bigInteger2 = scan.nextBigInteger(); System.out.println(bigInteger1.add(bigInteger2)); System.out.println(bigInteger1.multiply(bigInteger2)); }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); int num[][] = { {0, 2, 3, 5, 6, 7, 8, 9}, {2, 3, 4, 5, 6, 8, 9}, {0, 2, 3, 5, 6, 8, 9}, {0, 4, 5, 6, 8, 9}, {0, 1, 2, 3, 4, 7, 8, 9}, {0, 2, 6, 8}, {0, 1, 3, 4, 5, 6, 7, 8, 9} }; while (scanner.hasNextInt()) { int a = scanner.nextInt(); String b = scanner.next(); if (a == 0) break; String data[][] = new String[5 + (a - 1) * 2][(3 + (a - 1)) * b.length()]; for (int i = 0; i < 5 + (a - 1) * 2; i++) for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) data[i][j] = " "; for (int i = 0; i < b.length(); i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < num[j].length; k++) { if ((int) b.charAt(i) - 48 == num[j][k]) { for (int h = 0; h < a; h++) data[(a + 1) * j][1 + i * (a + 2) + h] = "-"; } } } for (int j = 3; j < 5; j++) { for (int k = 0; k < num[j].length; k++) { if ((int) b.charAt(i) - 48 == num[j][k]) { for (int h = 0; h < a; h++) data[1 + h][(j - 3) * (a + 1) + (i * (a + 2))] = "|"; } } } for (int j = 5; j < 7; j++) { for (int k = 0; k < num[j].length; k++) { if ((int) b.charAt(i) - 48 == num[j][k]) { for (int h = 0; h < a; h++) data[a + 2 + h][(j - 5) * (a + 1) + (i * (a + 2))] = "|"; } } } } StringBuffer sb = new StringBuffer(""); for (int i = 0; i < 5 + (a - 1) * 2; i++) { for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) { if ((j - (a + 1)) % (a + 2) == 0 && (j + 1) != (3 + (a - 1)) * b.length()) sb.append(data[i][j] + " "); else sb.append(data[i][j]); } sb.append("\n"); } System.out.println(sb); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int a0 = 0; a0 < t; a0++) { int n = in.nextInt(); int treeHeight = getHeightOfTree(n); System.out.println(treeHeight); } }
public void loadWords(Scanner S) { for (int i = 0; i < words.length; i++) { S.nextLine(); // makes the words upper case so that guesses // are case insensitive words[i] = S.next().toUpperCase(); played[i] = new String(""); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } System.out.println("Ans: " + findK(arr, 0, n - 1, k)); }
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); while (scanner.hasNext()) { String str = scanner.next(); if (str.equals("*")) break; if ((int) str.charAt(0) < 97) num(str); else abcd(str); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int m; m = in.nextInt(); String grid[] = new String[m]; for (int i = 0; i < m; i++) { grid[i] = in.next(); } displayPathtoPrincess(m, grid); }
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in); long T = scan.nextLong(); for (long i = 0; i < T; i++) { long N = scan.nextLong(); long diff = 0; diff = wholeSum(N) - indiSum(N); System.out.println(diff); } }