messages
listlengths
2
2
[ { "role": "assistant", "content": "ABC = tuple(map(int, input().split()))\nif ABC.count(5) == 2:\n print('YES' if sum(ABC) == 17 else 'NO')\nelse:\n print('NO')\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class atcoder_ABC042_A {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String line = br.readLine();\n String[] list = line.split(\" \");\n int x = Integer.parseInt(list[0]);\n int a = Integer.parseInt(list[1]);\n int y = Integer.parseInt(list[2]);\n String h = \"NO\";\n if (x == 5 | x == 7 | a == 5 | a == 7 | y == 5 | y == 7) {\n if (x + y + a == 17) {\n h = \"YES\";\n }\n }\n System.out.println(h);\n }\n}\n" } ]
[ { "role": "assistant", "content": "s = str(input())\nmy_str = ''\nfor c in s:\n if c == '0' or c == '1':\n my_str += c\n elif c == 'B' and len(my_str) != 0:\n my_str = my_str[: len(my_str) - 1]\nprint(my_str)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.UncheckedIOException;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC043_B {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n LightScanner in = new LightScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BUnhappyHackingABCEdit solver = new BUnhappyHackingABCEdit();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BUnhappyHackingABCEdit {\n public void solve(int testNumber, LightScanner in, PrintWriter out) {\n String s = in.string();\n StringBuilder d = new StringBuilder();\n for (char c : s.toCharArray()) {\n switch (c) {\n case '0':\n d.append(\"0\");\n break;\n case '1':\n d.append(\"1\");\n break;\n case 'B':\n if (d.length() > 0) {\n d.setLength(d.length() - 1);\n d.trimToSize();\n }\n break;\n }\n }\n out.println(d);\n }\n }\n\n static class LightScanner {\n private BufferedReader reader = null;\n private StringTokenizer tokenizer = null;\n\n public LightScanner(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public String string() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n return tokenizer.nextToken();\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "print(input().replace(\",\", \" \"))\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.*;\nimport java.util.*;\n\npublic class atcoder_ABC051_A {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringBuilder sb = new StringBuilder();\n String a = br.readLine();\n sb.append(a.replace(\",\", \" \"));\n System.out.println(sb);\n }\n}\n" } ]
[ { "role": "assistant", "content": "A = list(map(int, input().split()))\nif A[1] <= A[2] or A[3] <= A[0]:\n print(0)\nelse:\n A.sort()\n print(A[2] - A[1])\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC070_B {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int d = in.nextInt();\n if (c > b) {\n System.out.println(0);\n } else if (a > d) {\n System.out.println(0);\n } else if (a < c) {\n System.out.println(Math.min(b, d) - c);\n } else {\n List<Integer> l = new ArrayList<>();\n l.add(a);\n l.add(b);\n l.add(c);\n l.add(d);\n Collections.sort(l);\n System.out.println(l.get(2) - l.get(1));\n }\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import numpy as np\nimport sys\nimport re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import deepcopy, copy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left, insort, insort_left\nfrom fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(* (MAP() for _ in range(n)))\n\n\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\nN = INT()\nS = [input() for _ in range(N)]\nmarch = [\"M\", \"A\", \"R\", \"C\", \"H\"]\nmarch_lis = [0] * 5\nfor s in S:\n if s[0].upper() in march:\n march_lis[march.index(s[0].upper())] += 1\nans = 0\nfor x, y, z in combinations(march_lis, 3):\n ans += x * y * z\nprint(ans)\n" }, { "role": "user", "content": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class atcoder_ABC089_C {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt();\n long[] cnt = new long[5];\n Arrays.fill(cnt, 0);\n for (int i = 0; i < n; ++i) {\n String str = in.next();\n if (str.charAt(0) == 'M') {\n cnt[0]++;\n } else if (str.charAt(0) == 'A') {\n cnt[1]++;\n } else if (str.charAt(0) == 'R') {\n cnt[2]++;\n } else if (str.charAt(0) == 'C') {\n cnt[3]++;\n } else if (str.charAt(0) == 'H') {\n cnt[4]++;\n }\n }\n long res =\n cnt[0] * cnt[1] * cnt[2]\n + cnt[0] * cnt[1] * cnt[3]\n + cnt[0] * cnt[1] * cnt[4]\n + cnt[0] * cnt[2] * cnt[3]\n + cnt[0] * cnt[2] * cnt[4]\n + cnt[0] * cnt[3] * cnt[4]\n + cnt[1] * cnt[2] * cnt[3]\n + cnt[1] * cnt[2] * cnt[4]\n + cnt[1] * cnt[3] * cnt[4]\n + cnt[2] * cnt[3] * cnt[4];\n out.println(res);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "D, G = map(int, input().split())\nPC = [tuple(map(int, input().split())) for _ in range(D)]\nans = 10 ** 9\nfor i in range(2 ** D):\n score = 0\n problem = 0\n for j in range(D):\n if (i >> j) & 1:\n score += 100 * (j + 1) * PC[j][0] + PC[j][1]\n problem += PC[j][0]\n if score > G:\n continue\n left = G - score\n for j in range(D):\n if (i >> j) & 1:\n continue\n if left > 100 * (j + 1) * PC[j][0] + PC[j][1]:\n pass\n else:\n tmp = (left + (100 * (j + 1)) - 1) // (100 * (j + 1))\n ans = min(ans, problem + min(tmp, PC[j][0]))\nprint(ans)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC104_C {\n static final int INF = 100000;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int D = sc.nextInt();\n long G = sc.nextLong();\n int[] p = new int[D];\n int[] c = new int[D];\n for (int i = 0; i < D; i++) {\n p[i] = sc.nextInt();\n c[i] = sc.nextInt();\n }\n int min = INF;\n for (int bit = 0; bit < (1 << D); bit++) {\n int score = 0;\n int solve_num = 0;\n for (int i = 0; i < D; i++) {\n if ((bit & (1 << i)) != 0) {\n score += 100 * (i + 1) * p[i] + c[i];\n solve_num += p[i];\n }\n }\n if (score < G) {\n loop:\n for (int i = D - 1; i >= 0; i--) {\n if ((bit & (1 << i)) == 0) {\n for (int j = 0; j < p[i] - 1; j++) {\n score += 100 * (i + 1);\n solve_num++;\n if (score >= G) {\n break loop;\n }\n }\n }\n }\n }\n if (score >= G) {\n min = Math.min(min, solve_num);\n }\n }\n System.out.println(min);\n sc.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "from sys import stdin\nfrom collections import Counter\nimport numpy as np\nN, M = [int(x) for x in stdin.readline().split()]\nA = np.array([int(a) for a in stdin.readline().split()], dtype=np.int64)\ncum_remainders = (np.hstack([0, A]) % M).cumsum() % M\nremainder_counts = Counter(cum_remainders)\ncombinations = 0\nfor count in remainder_counts.values():\n combinations += count * (count - 1) // 2\nprint(combinations)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC105_D {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n int[] a = in.nextIntArray(n);\n HashMap<Integer, Integer> dp = new HashMap<>();\n long ans = 0;\n int base = 0;\n for (int i = 0; i < n; i++) {\n base = (base - a[i] % m + m) % m;\n dp.merge((base + a[i]) % m, 1, Integer::sum);\n ans += dp.getOrDefault(base, 0);\n }\n out.println(ans);\n }\n }\n\n static class InputReader {\n private BufferedReader br;\n private StringTokenizer st;\n\n public InputReader(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n st = new StringTokenizer(\"\");\n }\n\n public String nextString() {\n while (!st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine(), \" \");\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n public int[] nextIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = nextInt();\n }\n return res;\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\nimport copy\nimport functools\nsys.setrecursionlimit(10 ** 7)\ninf = 10 ** 20\neps = 1.0 / 10 ** 10\nmod = 10 ** 9 + 7\ndd = [(- 1, 0), (0, 1), (1, 0), (0, - 1)]\nddn = [(- 1, 0), (- 1, 1), (0, 1), (1, 1),\n (1, 0), (1, - 1), (0, - 1), (- 1, - 1)]\n\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\ndef pf(s): return print(s, flush=True)\n\n\ndef main():\n s = S()\n k = I()\n l = 0\n for c in s:\n if c != '1':\n break\n l += 1\n if l >= k:\n return 1\n return s[l]\n\n\nprint(main())\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC106_C {\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n String str = sc.next();\n char[] c = str.toCharArray();\n long k = sc.nextLong();\n int n = str.length();\n for (int i = 0; i < k; i++) {\n if (c[i] == '1') {\n if (i == k - 1) {\n System.out.println(1);\n return;\n }\n } else {\n System.out.println(c[i]);\n return;\n }\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nN, K = map(int, input().split())\nlst = list(map(int, input().split()))\nlst_p = []\nlst_m = []\nfor i in range(N):\n if lst[i] == 0:\n K -= 1\n if lst[i] > 0:\n lst_p += [lst[i]]\n elif lst[i] < 0:\n lst_m += [lst[i]]\np = 0\nm = 0\nx, y = 0, len(lst_m) - 1\nlastx = len(lst_p)\nlasty = len(lst_m)\n\n\ndef check(k):\n ans = 10 ** 9\n for j in range(0, k + 1):\n if j > lastx or k - j > lasty:\n pass\n else:\n if j == 0:\n p = 0\n else:\n p = lst_p[j - 1]\n if k - j == 0:\n m = 0\n else:\n m = lst_m[lasty - (k - j)]\n ans = min(ans, 2 * p + abs(m), p + 2 * abs(m))\n return ans\n\n\nprint(check(K))\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC107_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int K = sc.nextInt();\n int S[] = new int[N];\n for (int i = 0; i < N; i++) S[i] = sc.nextInt();\n int temp = 0;\n int ans = 1000000000;\n if (K == 1) {\n for (int i = 0; i < N; i++) {\n temp = S[i];\n ans = Math.min(Math.abs(temp), ans);\n }\n System.out.println(ans);\n } else if (N - K != 0) {\n for (int i = 0; i <= N - K; i++) {\n int min = S[i];\n int max = S[i + K - 1];\n if (min < 0 && max > 0) temp = Math.min(2 * (-min) + max, (-min) + 2 * max);\n else temp = Math.max(Math.abs(min), Math.abs(max));\n ans = Math.min(ans, temp);\n }\n System.out.println(ans);\n } else {\n int min = S[0];\n int max = S[N - 1];\n if (min < 0 && max > 0)\n System.out.println(Math.min(2 * (-min) + max, (-min) + 2 * max));\n else System.out.println(Math.max(Math.abs(min), Math.abs(max)));\n }\n sc.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "class BIT:\n def __init__(self, N):\n self.size = N\n self.tree = [0] * (N + 1)\n self.depth = n.bit_length()\n\n def _bitsum(self, i):\n ret = 0\n while i:\n ret += self.tree[i]\n i ^= i & - i\n return ret\n\n def bitsum(self, l, r=None):\n if r is None:\n return self._bitsum(l)\n else:\n return self._bitsum(r) - self._bitsum(l)\n\n def bitadd(self, i, x):\n i += 1\n while i <= self.size:\n self.tree[i] += x\n i += i & - i\n return\n\n\nn = int(input())\nm = n * (n + 1) // 4\na = list(map(int, input().split()))\nd = dict()\n_a = sorted(set(a + [0]))\nfor i, x in enumerate(_a):\n d[x] = i\na = [d[x] for x in a]\n\n\ndef check(X):\n b = [0] + [(y >= X) * 2 - 1 for y in a]\n for i in range(n):\n b[i + 1] += b[i]\n c = min(b)\n b = [x - c for x in b]\n bit = BIT(max(b) + 2)\n ans = 0\n for x in b:\n ans += bit.bitsum(x + 1)\n bit.bitadd(x, 1)\n return ans >= m\n\n\nt = [len(_a), 0]\nwhile t[0] - t[1] > 1:\n mid = (t[0] + t[1]) // 2\n t[check(mid)] = mid\nprint(_a[t[1]])\n" }, { "role": "user", "content": "import java.io.BufferedInputStream;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class atcoder_ABC107_D {\n public static void main(String[] args) {\n Scanner scan = new Scanner(new BufferedInputStream(System.in));\n int N = scan.nextInt();\n int[] arr = new int[N];\n for (int i = 0; i < N; i++) arr[i] = scan.nextInt();\n Task tsk = new Task();\n System.out.println(tsk.solve(arr));\n }\n\n static class Task {\n public int solve(int[] arr) {\n int n = arr.length;\n int[] sorted = Arrays.copyOf(arr, n);\n Arrays.sort(sorted);\n long total = (long) n * (n + 1) / 2;\n int l = 0, r = n - 1;\n while (l < r) {\n int mid = l + (r - l) / 2;\n int target = sorted[mid];\n int cur = 0;\n long cnt = 0;\n long[] bit = new long[2 * n + 2];\n for (int x = n + 1; x < bit.length; x += x & -x) bit[x]++;\n for (int i = 0; i < n; i++) {\n cur += arr[i] <= target ? 1 : -1;\n for (int x = cur + n + 1; x < bit.length; x += x & -x) bit[x]++;\n for (int x = cur + n; x > 0; x -= x & -x) cnt += bit[x];\n }\n if (cnt >= total / 2 + 1) r = mid;\n else l = mid + 1;\n }\n return sorted[l];\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "p = input().split(\" \")\nx1 = int(p[0])\ny1 = int(p[1])\nx2 = int(p[2])\ny2 = int(p[3])\nDIF1 = x2 - x1\nDIF2 = y2 - y1\nx3 = x2 - DIF2\ny3 = y2 + DIF1\nx4 = x1 - DIF2\ny4 = y1 + DIF1\nprint(str(x3) + \" \" + str(y3) + \" \" + str(x4) + \" \" + str(y4))\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC108_B {\n public static int[] revpos(int[] p, int[] q) {\n int[] vec = {0, 0};\n for (int i = 0; i < vec.length; i++) {\n vec[i] = p[i] - q[i];\n }\n int tmp = 0;\n tmp = vec[0];\n vec[0] = vec[1];\n vec[1] = -tmp;\n int[] newpos = {0, 0};\n for (int i = 0; i < newpos.length; i++) {\n newpos[i] = q[i] + vec[i];\n }\n return newpos;\n }\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int[] input = {0, 0, 0, 0};\n for (int i = 0; i < input.length; i++) {\n input[i] = scan.nextInt();\n }\n scan.close();\n int[][] position = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};\n position[0][0] = input[0];\n position[0][1] = input[1];\n position[1][0] = input[2];\n position[1][1] = input[3];\n position[2] = revpos(position[0], position[1]);\n position[3] = revpos(position[1], position[2]);\n if (position[0] == revpos(position[2], position[3])) {\n System.out.println(\"OK\");\n }\n int[] output = {0, 0, 0, 0};\n output[0] = position[2][0];\n output[1] = position[2][1];\n output[2] = position[3][0];\n output[3] = position[3][1];\n for (int i : output) {\n System.out.println(i);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import defaultdict\nn = int(input())\ns = defaultdict(lambda: 0)\nl = list([input() for i in range(n)])\nf = 'Yes'\ni = - 1\nfor v in l:\n s[v] += 1\n if s[v] >= 2:\n f = 'No'\n if i != - 1 and l[i][- 1] != v[0]:\n f = 'No'\n i += 1\nprint(f)\n" }, { "role": "user", "content": "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class atcoder_ABC109_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n HashMap<Integer, String> map = new HashMap<>();\n for (int i = 0; i < N; i++) {\n map.put(i, sc.next());\n }\n boolean ans = true;\n HashMap<Integer, String> past = new HashMap<>();\n String next = \"\";\n for (int i = 0; i < N; i++) {\n if (past.containsValue(map.get(i))) {\n ans = false;\n break;\n }\n past.put(i, map.get(i));\n if (i != 0) {\n if (!next.equals(map.get(i).substring(0, 1))) {\n ans = false;\n break;\n }\n }\n next = map.get(i).substring(map.get(i).length() - 1, map.get(i).length());\n }\n if (ans) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import collections\n\n\ndef run(s, t):\n ss = sorted(list(collections.Counter(s).values()))\n tt = sorted(list(collections.Counter(t).values()))\n if ss == tt:\n return 'Yes'\n else:\n return 'No'\n\n\ndef main():\n s = input()\n t = input()\n print(run(s, t))\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC110_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String S = sc.nextLine();\n String T = sc.nextLine();\n sc.close();\n String[] A = {\n \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\",\n \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"\n };\n boolean res = true;\n for (String s : A) {\n int sIdx = S.indexOf(s);\n if (sIdx < 0) continue;\n String t = String.valueOf(T.charAt(sIdx));\n int idx = 0;\n while (idx < S.length()) {\n if (S.indexOf(s, idx) >= 0) {\n if (S.indexOf(s, idx) != T.indexOf(t, idx)) {\n res = false;\n break;\n } else {\n idx = S.indexOf(s, idx) + 1;\n }\n } else if (T.indexOf(t, idx) >= 0) {\n res = false;\n break;\n } else break;\n }\n if (!res) break;\n }\n if (res) System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n}\n" } ]
[ { "role": "assistant", "content": "n = int(input())\nx = list(int(i) for i in input().split())\na = []\nb = []\nfor i in range(0, n):\n if i % 2 == 0:\n a.append(x[i])\n else:\n b.append(x[i])\ncnta = [0] * (100002 + 1)\ncntb = [0] * (100002 + 1)\nvala = 0\nvala1 = 0\nmaxCnta = 0\nmaxCnta1 = 0\nfor i in a:\n cnta[i] += 1\nfor i in a:\n if maxCnta < cnta[i]:\n vala = i\n maxCnta = cnta[i]\nfor i in a:\n if maxCnta1 < cnta[i] and vala != i:\n maxCnta1 = cnta[i]\n vala1 = i\nvalb = 0\nvalb1 = 0\nmaxCntb = 0\nmaxCntb1 = 0\nfor i in b:\n cntb[i] += 1\nfor i in b:\n if maxCntb < cntb[i]:\n valb = i\n maxCntb = cntb[i]\nfor i in b:\n if maxCntb1 < cntb[i] and valb != i:\n maxCntb1 = cntb[i]\n valb1 = i\nif valb != vala:\n res = 0\n for i in a:\n if i != vala:\n res += 1\n for i in b:\n if i != valb:\n res += 1\n print(res)\nelse:\n resa = 0\n resb = 0\n resa1 = 0\n resb1 = 0\n for i in a:\n if i != vala:\n resa += 1\n if i != vala1:\n resa1 += 1\n for i in b:\n if i != valb:\n resb += 1\n if i != valb1:\n resb1 += 1\n print(min(resa + resb1, resa1 + resb))\n" }, { "role": "user", "content": "import java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class atcoder_ABC111_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.next());\n int[] v = new int[100010];\n for (int i = 0; i < n; i++) {\n v[i] = Integer.parseInt(sc.next());\n }\n Integer[] vo = new Integer[100010];\n Integer[] ve = new Integer[100010];\n Integer[] vt = new Integer[100010];\n Arrays.fill(vo, 0);\n Arrays.fill(ve, 0);\n Arrays.fill(vt, 0);\n for (int i = 0; i < n; i++) {\n vt[v[i]]++;\n if (i % 2 == 0) {\n ve[v[i]]++;\n } else {\n vo[v[i]]++;\n }\n }\n Arrays.sort(vo, Collections.reverseOrder());\n Arrays.sort(ve, Collections.reverseOrder());\n Arrays.sort(vt, Collections.reverseOrder());\n int ans = 0;\n if (vo[0] + ve[0] == vt[0]) {\n ans = Math.min(n - vo[0] - ve[1], n - vo[1] - ve[0]);\n } else {\n ans = n - vo[0] - ve[0];\n }\n System.out.println(ans);\n sc.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "age = int(input())\nif age == 1:\n print('Hello World')\nelse:\n a, b = [int(input()) for i in range(2)]\n print(a + b)\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class atcoder_ABC112_A {\n private static BufferedReader br = null;\n\n public static void main(String[] args) {\n int n = Integer.parseInt(read(1)[0]);\n if (n == 1) {\n System.out.println(\"Hello World\");\n } else {\n String[] strs = read(2);\n System.out.println(Integer.parseInt(strs[0]) + Integer.parseInt(strs[1]));\n }\n }\n\n private static String[] read(int len) {\n List<String> strList = new ArrayList<>();\n try {\n if (br == null) {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n for (int i = 0; i < len; i++) {\n strList.add(br.readLine());\n }\n } catch (IOException e) {\n }\n return strList.toArray(new String[0]);\n }\n\n private static void close() {\n try {\n if (br != null) {\n br.close();\n }\n } catch (IOException e) {\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\n\n\ndef solve(n, ls_xyh):\n x0 = None\n for i in range(n):\n if ls_xyh[i][2] > 0:\n [x0, y0, h0] = ls_xyh[i]\n break\n cands = [(cx, cy, h0 + abs(cx - x0) + abs(cy - y0))\n for cx in range(101) for cy in range(101)]\n for [x, y, h] in ls_xyh:\n cands = [(cx, cy, ch) for (cx, cy, ch) in cands if max(\n ch - abs(cx - x) - abs(cy - y), 0) == h]\n (xx, yy, hh) = cands[0]\n return ' '.join([str(xx), str(yy), str(hh)])\n\n\ndef readQuestion():\n ws = sys.stdin.readline().strip().split()\n n = int(ws[0])\n ls_xyh = [list(map(int, sys.stdin.readline().strip().split()))\n for j in range(n)]\n return (n, ls_xyh)\n\n\ndef main():\n print(solve(* readQuestion()))\n\n\nmain()\n" }, { "role": "user", "content": "import java.util.Scanner;\nimport java.util.stream.IntStream;\n\npublic class atcoder_ABC112_C {\n private static final int MAX = 100;\n\n public static void main(String[] args) {\n try (Scanner scanner = new Scanner(System.in)) {\n int n = scanner.nextInt();\n int[] x = new int[n], y = new int[n], h = new int[n];\n IntStream.range(0, n)\n .forEach(\n i -> {\n x[i] = scanner.nextInt();\n y[i] = scanner.nextInt();\n h[i] = scanner.nextInt();\n });\n for (int i = 0; i <= MAX; i++) {\n for (int j = 0; j <= MAX; j++) {\n int ch = check(n, x, y, h, i, j);\n if (ch > 0) {\n System.out.println(i + \" \" + j + \" \" + ch);\n }\n }\n }\n }\n }\n\n private static int check(int n, int[] x, int[] y, int[] h, int cx, int cy) {\n int ch = -1;\n for (int i = 0; i < n; i++) {\n if (h[i] > 0) {\n ch = Math.abs(x[i] - cx) + Math.abs(y[i] - cy) + h[i];\n break;\n }\n }\n for (int i = 0; i < n; i++) {\n if (h[i] != Math.max(ch - Math.abs(x[i] - cx) - Math.abs(y[i] - cy), 0)) {\n return -1;\n }\n }\n return ch;\n }\n}\n" } ]
[ { "role": "assistant", "content": "N = int(input())\n\n\ndef aaa(n):\n if int(n) > N:\n return 0\n ans = 1 if set(str(int(n))) == {'7', '5', '3'} else 0\n for i in '753':\n ans += aaa(n + i)\n return ans\n\n\nprint(aaa('0'))\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC114_C {\n static Scanner scanner;\n\n public static void main(String[] args) {\n scanner = new Scanner(System.in);\n int N = gi();\n long i = 357;\n int c = 0;\n while (i <= N) {\n String s = String.valueOf(i);\n if (s.contains(\"3\") && s.contains(\"5\") && s.contains(\"7\")) c++;\n StringBuilder sb = new StringBuilder();\n boolean f = false;\n for (int j = 0; j < s.length(); j++) {\n char a = s.charAt(s.length() - 1 - j);\n if (f) {\n sb.append(a);\n } else {\n if (a == '3') {\n sb.append('5');\n f = true;\n } else if (a == '5') {\n sb.append('7');\n f = true;\n } else {\n sb.append('3');\n }\n }\n }\n if (!f) sb.append(3);\n StringBuffer sb2 = new StringBuffer(sb);\n i = Long.parseLong(sb2.reverse().toString());\n }\n System.out.println(c);\n }\n\n public static String gs() {\n return scanner.next();\n }\n\n public static int gi() {\n return Integer.parseInt(scanner.next());\n }\n\n public static long gl() {\n return Long.parseLong(scanner.next());\n }\n\n public static double gd() {\n return Double.parseDouble(scanner.next());\n }\n}\n" } ]
[ { "role": "assistant", "content": "import fractions\nimport functools\nN = int(input())\nA = list(map(int, input().split()))\ngcd = functools.reduce(fractions.gcd, A)\nprint(gcd)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC118_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n ArrayList<Integer> a = new ArrayList<>();\n if (n == 1) {\n System.out.println(sc.nextInt());\n System.exit(0);\n }\n for (int i = 0; i < n; i++) {\n a.add(sc.nextInt());\n }\n Collections.sort(a);\n if (a.get(a.size() - 1) == 0) {\n System.out.println(0);\n System.exit(0);\n }\n int ans = 0;\n while (true) {\n if (a.size() == 1) {\n ans = a.get(0);\n break;\n }\n a = func(a);\n }\n System.out.println(ans);\n }\n\n private static ArrayList<Integer> func(ArrayList<Integer> A) {\n ArrayList<Integer> a = A;\n int min = 0;\n for (int i = 0; i < a.size(); i++) {\n if (a.get(i) == 0) {\n a.remove(i);\n i--;\n } else {\n if (min != 0) {\n a.set(i, a.get(i) % min);\n if (a.get(i) == 1) {\n System.out.println(1);\n System.exit(0);\n }\n } else {\n min = a.get(i);\n }\n }\n }\n Collections.sort(a);\n return a;\n }\n}\n" } ]
[ { "role": "assistant", "content": "N = int(input())\nx = [eval(input().replace('JPY', '* 1.0').replace('BTC', '* 380000.0'))\n for i in range(N)]\nprint(sum(x))\n" }, { "role": "user", "content": "import java.util.Scanner;\nimport java.util.stream.IntStream;\n\npublic class atcoder_ABC119_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n double[] x = new double[N];\n String[] u = new String[N];\n for (int i = 0; i < N; ++i) {\n x[i] = sc.nextDouble();\n u[i] = sc.next();\n }\n System.out.println(solve(x, u));\n sc.close();\n }\n\n static double solve(double[] x, String[] u) {\n return IntStream.range(0, x.length)\n .mapToDouble(i -> x[i] * (u[i].equals(\"JPY\") ? 1 : 380000))\n .sum();\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import deque\nfrom collections import Counter\nfrom itertools import product, permutations, combinations\nfrom operator import itemgetter\nfrom heapq import heappop, heappush\nfrom bisect import bisect_left, bisect_right, bisect\nfrom fractions import gcd\nfrom math import ceil, floor, sqrt, cos, sin, pi, factorial\nimport sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 8)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\n\ndef main():\n s = input()\n if len(set(s)) == 1:\n print(0)\n sys.exit()\n a = Counter(s)\n ans = min(a.values()) * 2\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC120_C {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String x = in.next();\n Stack<Character> s = new Stack<>();\n int c = 0;\n for (int i = 0; i < x.length(); i++) {\n s.push(x.charAt(i));\n while (s.size() > 1) {\n Character p = s.pop();\n Character q = s.pop();\n if ((p == '1' && q == '0') || (p == '0' && q == '1')) {\n c++;\n continue;\n } else {\n s.push(q);\n s.push(p);\n break;\n }\n }\n }\n out.println(c * 2);\n }\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "from itertools import accumulate\nn, q = map(int, input().split())\ns = input()\nproblems = [list(map(int, input().split())) for _ in range(q)]\n\n\ndef count(total, i):\n return total + 1 if s[i - 1: i + 1] == 'AC' else total\n\n\ncumsum = list(accumulate([0] + list(range(1, n)), count))\nfor l, r in problems:\n print(cumsum[r - 1] - cumsum[l - 1])\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC122_C {\n static final long mod = 1000000007;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int q = sc.nextInt();\n char[] c = sc.next().toCharArray();\n int[][] range = new int[q][2];\n for (int i = 0; i < q; i++) {\n range[i][0] = sc.nextInt();\n range[i][1] = sc.nextInt();\n }\n int[] frag = new int[n + 1];\n int[] rui = new int[n + 1];\n for (int i = 2; i <= n; i++) {\n if (c[i - 2] == 'A' && c[i - 1] == 'C') {\n frag[i]++;\n }\n rui[i] = rui[i - 1] + frag[i];\n }\n for (int i = 0; i < q; i++) {\n int left = range[i][0];\n int right = range[i][1];\n System.out.println(rui[right] - rui[left]);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "def ok(last4):\n for i in range(4):\n t = list(last4)\n if i >= 1:\n t[i], t[i - 1] = t[i - 1], t[i]\n if ''.join(t).count('AGC') >= 1:\n return False\n return True\n\n\ndef dfs(cur, last3):\n if last3 in memo[cur]:\n return memo[cur][last3]\n if cur == n:\n return 1\n ret = 0\n for c in \"ACGT\":\n if ok(last3 + c):\n ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod\n memo[cur][last3] = ret\n return ret\n\n\nn = int(input())\nmod = 10 ** 9 + 7\nmemo = [{} for i in range(n + 1)]\nprint(dfs(0, 'TTT'))\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC122_D {\n int N;\n long MOD = 1000000007L;\n String[] TOKENS = {\"A\", \"C\", \"G\", \"T\"};\n Map<String, Long>[] memo;\n\n atcoder_ABC122_D() {\n Scanner in = new Scanner(System.in);\n N = in.nextInt();\n in.close();\n this.memo = new Map[N + 1];\n for (int i = 0; i < this.memo.length; ++i) {\n this.memo[i] = new HashMap<String, Long>();\n }\n }\n\n long calc() {\n return dfs(0, \"TTT\");\n }\n\n boolean isOK(String last4) {\n if (last4.contains(\"AGC\")) {\n return false;\n }\n for (int i = 0; i < 3; ++i) {\n char[] vals = last4.toCharArray();\n vals[i] = last4.charAt(i + 1);\n vals[i + 1] = last4.charAt(i);\n String s = new String(vals);\n if (s.contains(\"AGC\")) {\n return false;\n }\n }\n return true;\n }\n\n long dfs(int current, String last3) {\n if (this.memo[current].containsKey(last3)) {\n return (Long) (this.memo[current].get(last3));\n }\n if (current == N) {\n return 1;\n }\n long result = 0;\n for (String c : TOKENS) {\n if (isOK(last3 + c)) {\n result = (result + dfs(current + 1, last3.substring(1, last3.length()) + c)) % MOD;\n }\n }\n memo[current].put(last3, result);\n return result;\n }\n\n public static void main(String[] args) {\n atcoder_ABC122_D ins = new atcoder_ABC122_D();\n System.out.println(ins.calc());\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nmenu = []\nfor _ in range(5):\n m = input()\n e = int(m[- 1])\n if e == 0:\n e = 10\n menu.append([int(m), e])\nmenu.sort(key=lambda x: x[1])\nans = 0\nfor m in menu[1:]:\n ans += math.ceil(m[0] / 10) * 10\nprint(ans + menu[0][0])\n" }, { "role": "user", "content": "import java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class atcoder_ABC123_B {\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n int a[] = new int[5];\n int r[] = new int[5];\n TreeMap<Integer, Integer> map = new TreeMap();\n for (int i = 0; i < a.length; i++) {\n a[i] = sc.nextInt();\n r[i] = a[i] % 10;\n int b = 10;\n if (r[i] != 0) {\n b = 10 - r[i];\n map.put(b, a[i]);\n }\n }\n int ans = 0;\n if (map.size() == 0) {\n for (int i = 0; i < a.length; i++) {\n ans += a[i];\n }\n System.out.println(ans);\n return;\n }\n int last = map.get(map.lastKey());\n int idx = 0;\n for (int i = 0; i < a.length; i++) {\n if (a[i] == last) {\n idx = i;\n }\n }\n for (int i = 0; i < a.length; i++) {\n if (i != idx) {\n if (a[i] % 10 == 0) {\n ans += a[i];\n } else {\n ans += a[i] + (10 - r[i]);\n }\n }\n }\n ans += last;\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nimport numpy as np\nfrom fractions import gcd\nimport fractions\nimport statistics\nimport collections\nfrom functools import reduce\nimport itertools\nN = int(input())\nA = [int(input()) for i in range(5)]\nprint(math.ceil(N / min(A)) + 4)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC123_C {\n private static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n long N = sc.nextLong();\n long min = 0;\n for (int i = 0; i < 5; i++) {\n if (i == 0) min = sc.nextLong();\n else min = Math.min(min, sc.nextLong());\n }\n p((long) Math.ceil((double) N / min) + 4);\n }\n\n static void p(String ans) {\n System.out.println(ans);\n }\n ;\n\n static void p(int ans) {\n System.out.println(ans);\n }\n ;\n\n static void p() {\n System.out.println();\n }\n ;\n\n static void p(long ans) {\n System.out.println(ans);\n }\n ;\n\n static void p(double ans) {\n System.out.println(ans);\n }\n ;\n}\n" } ]
[ { "role": "assistant", "content": "x, y, z, k = [int(_) for _ in input().split()]\na = [int(_) for _ in input().split()]\nb = [int(_) for _ in input().split()]\nc = [int(_) for _ in input().split()]\nab = []\nfor i in range(x):\n for j in range(y):\n ab.append(a[i] + b[j])\nab.sort(reverse=True)\nabc = []\nfor i in range(min(k, x * y)):\n for j in range(z):\n abc.append(ab[i] + c[j])\nabc.sort(reverse=True)\nfor i in range(k):\n print(abc[i])\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC123_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int x[] = new int[3];\n int max = 0;\n for (int i = 0; i < 3; ++i) {\n x[i] = sc.nextInt();\n max = Math.max(max, x[i]);\n }\n int k = sc.nextInt();\n List<Long> a[] = new List[3];\n for (int i = 0; i < 3; ++i) a[i] = new ArrayList<Long>();\n for (int i = 0; i < 3; ++i) {\n for (int j = 0; j < x[i]; ++j) a[i].add(sc.nextLong());\n Collections.sort(a[i]);\n }\n sc.close();\n List<Long> ans = new ArrayList<Long>();\n for (int i = 0; i < x[0]; ++i) {\n for (int j = 0; j < x[1]; ++j) {\n for (int m = 0; m < x[2]; ++m) {\n if ((i + 1) * (j + 1) * (m + 1) <= k) {\n long tmp =\n a[0].get(x[0] - i - 1)\n + a[1].get(x[1] - j - 1)\n + a[2].get(x[2] - m - 1);\n ans.add(tmp);\n }\n }\n }\n }\n Collections.sort(ans);\n int n = ans.size();\n for (int i = 0; i < k; ++i) System.out.println(ans.get(n - i - 1));\n }\n}\n" } ]
[ { "role": "assistant", "content": "a, b = map(int, input().split())\nc = 0\nfor i in range(2):\n c += max(a, b)\n if a >= b:\n a -= 1\n else:\n b -= 1\nprint(c)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC124_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = Integer.parseInt(sc.next());\n int b = Integer.parseInt(sc.next());\n ;\n int sum = 0;\n for (int i = 0; i < 2; i++) {\n if (a >= b) {\n sum += a;\n a = a - 1;\n } else {\n sum += b;\n b = b - 1;\n }\n }\n System.out.println(sum);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import collections\ns = list(input())\neven = collections.Counter(s[0:: 2])\nodd = collections.Counter(s[1:: 2])\nprint(min(len(s) - (even[\"0\"] + odd[\"1\"]), len(s) - (even[\"1\"] + odd[\"0\"])))\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC124_C {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CColoringColorfully solver = new CColoringColorfully();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CColoringColorfully {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String x = in.next();\n StringBuilder a = new StringBuilder(x);\n StringBuilder b = new StringBuilder(x);\n int a1 = 0;\n int a2 = 0;\n for (int i = 1; i < x.length(); i++) {\n if (a.charAt(i) == a.charAt(i - 1)) {\n if (a.charAt(i) == '1') a.setCharAt(i, '0');\n else a.setCharAt(i, '1');\n a1++;\n }\n }\n for (int i = x.length() - 1; i > 0; i--) {\n if (b.charAt(i) == b.charAt(i - 1)) {\n if (b.charAt(i - 1) == '1') b.setCharAt(i - 1, '0');\n else b.setCharAt(i - 1, '1');\n a2++;\n }\n }\n out.println(Math.min(a1, a2));\n }\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "a, b, t = map(int, input().split())\ncookie = 0\ntime = a\nwhile time <= t + 0.5:\n cookie += b\n time += a\nprint(cookie)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC125_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int sec = sc.nextInt();\n int per_num = sc.nextInt();\n double max_sec = (double) sc.nextInt() + 0.5;\n int ans_num = 0;\n for (int i = sec; i < max_sec; i += sec) {\n ans_num += per_num;\n }\n System.out.println(ans_num);\n }\n}\n" } ]
[ { "role": "assistant", "content": "N = int(input())\nV = input().split(\" \")\nV = [int(i) for i in V]\nC = input().split(\" \")\nC = [int(i) for i in C]\nlist = [0]\nans = 0\nX = 0\nY = 0\nfor i in range(N):\n if V[i] - C[i] > 0:\n X = V[i]\n Y = C[i]\n list.append(X - Y)\nprint(sum(list))\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC125_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n Integer n = Integer.valueOf(sc.nextLine());\n String vStr = sc.nextLine();\n Map<Integer, Integer> vList = str2List(vStr);\n String cStr = sc.nextLine();\n Map<Integer, Integer> cList = str2List(cStr);\n Integer max = 0;\n for (Integer i = 0; i < n; i++) {\n Integer profit = vList.get(i) - cList.get(i);\n if (profit > 0) {\n max += profit;\n }\n }\n System.out.println(max);\n }\n\n static Map<Integer, Integer> str2List(String str) {\n String[] vArrStr = str.split(\" \");\n Map<Integer, Integer> ret = new HashMap<>();\n Integer key = 0;\n for (String val : vArrStr) {\n ret.put(key, Integer.valueOf(val));\n key++;\n }\n return ret;\n }\n}\n" } ]
[ { "role": "assistant", "content": "def gcd(a: int, b: int) -> int:\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\ndef ruiseki_lr(array):\n def op(a, b): return gcd(a, b)\n e = 0\n n = len(array)\n left = [e] * (n + 1)\n right = [e] * (n + 1)\n for i in range(n):\n left[i + 1] = op(left[i], array[i])\n for i in reversed(range(n)):\n right[i] = op(right[i + 1], array[i])\n return left, right\n\n\nn = int(input())\na = list(map(int, input().split()))\nleft, right = ruiseki_lr(a)\nans = 0\nfor i in range(n):\n ans = max(gcd(left[i], right[i + 1]), ans)\nprint(ans)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC125_C {\n public static int[] A;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n A = new int[N];\n for (int i = 0; i < N; i++) {\n A[i] = sc.nextInt();\n }\n sc.close();\n int[] M = new int[N];\n int[] L = new int[N];\n int[] R = new int[N];\n L[0] = A[0];\n for (int i = 1; i < N; i++) {\n L[i] = gcd(L[i - 1], A[i]);\n }\n R[N - 1] = A[N - 1];\n for (int i = N - 2; i >= 0; i--) {\n R[i] = gcd(R[i + 1], A[i]);\n }\n int answer = Math.max(L[N - 2], R[1]);\n for (int i = 1; i < N - 1; i++) {\n ;\n answer = Math.max(answer, gcd(L[i - 1], R[i + 1]));\n }\n System.out.println(answer);\n }\n\n public static int gcd(int a, int b) {\n int tmp;\n if (b > a) {\n tmp = a;\n a = b;\n b = tmp;\n }\n if (b == 0) {\n return a;\n }\n int r = -1;\n do {\n r = a % b;\n a = b;\n b = r;\n } while (r != 0);\n return a;\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nsys.setrecursionlimit(10 ** 5)\n\n\nclass Node:\n def __init__(self):\n self.val = None\n self.color = None\n self.a = []\n\n\nn = int(input())\nnodes = []\nfor i in range(n):\n nodes.append(Node())\nfor i in range(n - 1):\n u, v, w = map(int, input().split())\n node1 = nodes[u - 1]\n node2 = nodes[v - 1]\n node1.val = u\n node2.val = v\n node1.a.append([node2, w])\n node2.a.append([node1, w])\nroot = nodes[0]\nroot.color = True\nnodeSet = set()\n\n\ndef traverse(node, distance):\n if node in nodeSet:\n return\n else:\n nodeSet.add(node)\n for pair in node.a:\n adjNode = pair[0]\n dis = pair[1]\n if (distance + dis) % 2 == 0:\n adjNode.color = root.color\n else:\n adjNode.color = not root.color\n traverse(adjNode, distance + dis)\n\n\ntraverse(root, 0)\nfor i in range(n):\n node = nodes[i]\n if node.color:\n print(1)\n else:\n print(0)\n" }, { "role": "user", "content": "import java.util.*;\nimport java.util.Map.*;\n\npublic class atcoder_ABC126_D {\n private static int[] colors;\n\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = n - 1;\n colors = new int[n];\n Arrays.fill(colors, -1);\n Point[] points = new Point[n];\n for (int i = 0; i < n; i++) {\n points[i] = new Point(i);\n }\n while (m-- > 0) {\n int me = sc.nextInt() - 1;\n int you = sc.nextInt() - 1;\n int length = sc.nextInt();\n points[me].becomeFriend(points[you], length);\n points[you].becomeFriend(points[me], length);\n }\n dfs(points[0], 0);\n for (int c : colors) {\n System.out.println(c);\n }\n }\n\n public static void dfs(Point p, int length) {\n boolean alreadyKnown = colors[p.name] != -1;\n if (alreadyKnown) return;\n if (length % 2 == 0) {\n colors[p.name] = 0;\n } else {\n colors[p.name] = 1;\n }\n for (Entry<Point, Integer> entry : p.friends.entrySet()) {\n Point friend = entry.getKey();\n int length2 = entry.getValue();\n dfs(friend, length + length2);\n }\n }\n\n public static class Point {\n int name;\n Map<Point, Integer> friends;\n\n Point(int name) {\n this.name = name;\n this.friends = new HashMap<Point, Integer>();\n }\n\n void becomeFriend(Point p, int length) {\n this.friends.put(p, length);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nfrom collections import deque\nsys.setrecursionlimit(10 ** 9)\nINF = 10 ** 18\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\ndef main():\n N, M = map(int, input().split())\n edge = [[] for _ in range(N)]\n for i in range(M):\n X, Y, Z = map(lambda x: int(x) - 1, input().split())\n edge[X].append(Y)\n edge[Y].append(X)\n used = [False] * N\n ans = 0\n for i in range(N):\n if not used[i]:\n ans += 1\n queue = deque()\n queue.append(i)\n while queue:\n node = queue.popleft()\n used[node] = True\n for nextnode in edge[node]:\n if not used[nextnode]:\n queue.append(nextnode)\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC126_E {\n Scanner sc = new Scanner(System.in);\n final int MOD = 1000000007;\n\n void doIt() {\n int n = sc.nextInt();\n UnionFindTree utf = new UnionFindTree(n);\n int m = sc.nextInt();\n for (int i = 0; i < m; i++) {\n int x = sc.nextInt() - 1;\n int y = sc.nextInt() - 1;\n int z = sc.nextInt();\n utf.unite(x, y);\n }\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (utf.par[i] == i) {\n cnt++;\n }\n }\n System.out.println(cnt);\n }\n\n class UnionFindTree {\n int n;\n int[] par;\n int[] rank;\n\n UnionFindTree(int n) {\n this.n = n;\n par = new int[n];\n rank = new int[n];\n for (int i = 0; i < n; i++) {\n par[i] = i;\n rank[i] = 0;\n }\n }\n\n int find(int x) {\n if (par[x] == x) {\n return x;\n } else {\n return par[x] = find(par[x]);\n }\n }\n\n void unite(int x, int y) {\n x = find(x);\n y = find(y);\n if (x == y) return;\n if (rank[x] < rank[y]) par[x] = y;\n else {\n par[y] = x;\n if (rank[x] == rank[y]) rank[x]++;\n }\n }\n\n boolean same(int x, int y) {\n return find(x) == find(y);\n }\n }\n\n public static void main(String[] args) {\n new atcoder_ABC126_E().doIt();\n }\n}\n" } ]
[ { "role": "assistant", "content": "r, D, x = map(int, input().split())\nfor i in range(2, 12):\n print(int((r ** (i - 1)) * (x + D / (1 - r)) - D / (1 - r)))\n" }, { "role": "user", "content": "import java.io.*;\nimport java.nio.CharBuffer;\nimport java.util.NoSuchElementException;\n\npublic class atcoder_ABC127_B {\n public static void main(String[] args) {\n SimpleScanner scanner = new SimpleScanner(System.in);\n PrintWriter writer = new PrintWriter(System.out);\n int r = scanner.nextInt();\n int d = scanner.nextInt();\n long x = scanner.nextLong();\n for (int i = 0; i < 10; ++i) {\n x = r * x - d;\n writer.println(x);\n }\n writer.close();\n }\n\n private static class SimpleScanner {\n private static final int BUFFER_SIZE = 10240;\n private Readable in;\n private CharBuffer buffer;\n private boolean eof;\n\n SimpleScanner(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n buffer = CharBuffer.allocate(BUFFER_SIZE);\n buffer.limit(0);\n eof = false;\n }\n\n private char read() {\n if (!buffer.hasRemaining()) {\n buffer.clear();\n int n;\n try {\n n = in.read(buffer);\n } catch (IOException e) {\n n = -1;\n }\n if (n <= 0) {\n eof = true;\n return '\u0000';\n }\n buffer.flip();\n }\n return buffer.get();\n }\n\n void checkEof() {\n if (eof) throw new NoSuchElementException();\n }\n\n char nextChar() {\n checkEof();\n char b = read();\n checkEof();\n return b;\n }\n\n String next() {\n char b;\n do {\n b = read();\n checkEof();\n } while (Character.isWhitespace(b));\n StringBuilder sb = new StringBuilder();\n do {\n sb.append(b);\n b = read();\n } while (!eof && !Character.isWhitespace(b));\n return sb.toString();\n }\n\n int nextInt() {\n return Integer.valueOf(next());\n }\n\n long nextLong() {\n return Long.valueOf(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import heapq\nq = int(input())\nans = [0, 0]\np1 = []\np2 = []\nheapq.heapify(p1)\nheapq.heapify(p2)\nsum_b = 0\nsum_p1 = 0\nsum_p2 = 0\nfor _ in range(q):\n ql = list(map(int, input().split()))\n if ql[0] == 2:\n if len(p1) == len(p2):\n print(- p2[0], sum_p1 - len(p1) * - p2[0] +\n len(p2) * - p2[0] - sum_p2 + sum_b)\n else:\n print(p1[0], sum_p1 - len(p1) * p1[0] +\n len(p2) * p1[0] - sum_p2 + sum_b)\n else:\n sum_b += ql[2]\n if len(p1) == 0:\n heapq.heappush(p1, ql[1])\n sum_p1 += ql[1]\n elif p1[0] <= ql[1]:\n heapq.heappush(p1, ql[1])\n sum_p1 += ql[1]\n else:\n heapq.heappush(p2, - ql[1])\n sum_p2 += ql[1]\n if len(p1) < len(p2):\n k = heapq.heappop(p2)\n heapq.heappush(p1, - k)\n sum_p2 += k\n sum_p1 -= k\n if len(p1) - 1 > len(p2):\n k = heapq.heappop(p1)\n heapq.heappush(p2, - k)\n sum_p1 -= k\n sum_p2 += k\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC127_F {\n static OutputStream outputStream = System.out;\n static PrintWriter out = new PrintWriter(outputStream);\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int t = Integer.parseInt(br.readLine());\n String[] s;\n PriorityQueue<Integer> pqmax = new PriorityQueue<Integer>();\n PriorityQueue<Integer> pqmin =\n new PriorityQueue<Integer>(\n new Comparator<Integer>() {\n public int compare(Integer x, Integer y) {\n return y - x;\n }\n });\n long sumMin = 0, sumMax = 0, sumb = 0;\n int min = 0;\n while (t-- > 0) {\n s = br.readLine().split(\" \");\n if (s[0].charAt(0) == '2') {\n long ans = min;\n ans *= pqmin.size();\n ans -= sumMin;\n long ans1 = min;\n ans1 *= pqmax.size();\n ans1 = sumMax - ans1;\n out.println(min + \" \" + (ans + ans1 + sumb));\n } else {\n int in = Integer.parseInt(s[1]);\n sumb += Long.parseLong(s[2]);\n if (in > min) {\n pqmax.add(in);\n sumMax += in;\n } else {\n pqmin.add(in);\n sumMin += in;\n }\n if (pqmin.size() > pqmax.size()) {\n sumMax += pqmin.peek();\n sumMin -= pqmin.peek();\n pqmax.add(pqmin.poll());\n }\n if (pqmin.size() < pqmax.size()) {\n sumMax -= pqmax.peek();\n sumMin += pqmax.peek();\n pqmin.add(pqmax.poll());\n }\n min = pqmin.peek();\n }\n }\n out.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "def main():\n import itertools\n n, m = map(int, input().split())\n li = [list(map(int, input().split()))[1:] for _ in range(m)]\n p = tuple(map(int, input().split()))\n q = set(sum(li, []))\n r = set(range(1, n + 1))\n v = r - q\n ans = 0\n for i in range(0, len(q) + 1):\n for s in itertools.combinations(q, i):\n for u, w in zip(li, p):\n s = set(s)\n if len(s & set(u)) % 2 != w:\n break\n else:\n ans += 2 ** (len(v))\n print(ans)\n\n\nif __name__ == \"__main__\":\n main()\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC128_C {\n public static void main(String[] args) {\n atcoder_ABC128_C main = new atcoder_ABC128_C();\n main.run();\n }\n\n public void run() {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int M = sc.nextInt();\n ArrayList<Integer> a = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n a.add(0);\n }\n for (int i = 0; i < M; i++) {\n int k = sc.nextInt();\n for (int j = 0; j < k; j++) {\n int s = sc.nextInt();\n s--;\n a.set(s, a.get(s) | (1 << i));\n }\n }\n int p = 0;\n for (int i = 0; i < M; i++) {\n int x = sc.nextInt();\n p |= (x << i);\n }\n int ans = 0;\n for (int s = 0; s < (1 << N); s++) {\n int t = 0;\n for (int i = 0; i < N; i++) {\n if (((s >> i) & 1) == 1) {\n t ^= a.get(i);\n }\n }\n if (p == t) {\n ans++;\n }\n }\n System.out.println(ans);\n sc.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "mod = 10 ** 9 + 7\nl = input()\nn = len(l)\ndp = [[0] * 2 for _ in range(n + 1)]\ndp[0][0] = 1\nfor i, c in enumerate(l):\n if c == '0':\n dp[i + 1][0] += dp[i][0]\n dp[i + 1][1] += dp[i][1] * 3\n else:\n dp[i + 1][0] += dp[i][0] * 2\n dp[i + 1][1] += dp[i][0]\n dp[i + 1][1] += dp[i][1] * 3\n dp[i + 1][0] %= mod\n dp[i + 1][1] %= mod\nprint((dp[n][0] + dp[n][1]) % mod)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC129_E {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int M = 1000000007;\n char[] s = sc.nextLine().toCharArray();\n int n = s.length;\n int[][] dp = new int[n + 1][2];\n dp[0][0] = 1;\n for (int i = 0; i < n; i++) {\n if (s[i] == '0') {\n dp[i + 1][0] = dp[i][0];\n dp[i + 1][1] = dp[i][1];\n } else {\n dp[i + 1][1] = (dp[i][0] + dp[i][1]) % M;\n }\n if (s[i] == '0') {\n dp[i + 1][1] += (dp[i][1] * 2) % M;\n dp[i + 1][1] %= M;\n } else {\n dp[i + 1][0] += (dp[i][0] * 2) % M;\n dp[i + 1][1] += (dp[i][1] * 2) % M;\n dp[i + 1][0] %= M;\n dp[i + 1][1] %= M;\n }\n }\n System.out.println((dp[n][0] + dp[n][1]) % M);\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import Counter\nS = input()\nc = Counter(S)\nSa = set(list(S))\nif len(Sa) != 2:\n print(\"No\")\n exit()\nfor i in Sa:\n if c[i] != 2:\n print(\"No\")\n exit()\nprint(\"Yes\")\n" }, { "role": "user", "content": "import java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.Scanner;\n\npublic class atcoder_ABC132_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n char[] targ = s.toCharArray();\n HashMap<Character, Integer> map = new HashMap<>();\n for (int i = 0; i < targ.length; i++) {\n if (!map.containsKey(targ[i])) {\n map.put(targ[i], 1);\n } else {\n map.put(targ[i], map.get(targ[i]) + 1);\n }\n }\n boolean ok = true;\n for (Entry<Character, Integer> c : map.entrySet()) {\n if (c.getValue() != 2) {\n ok = false;\n break;\n }\n }\n if (ok && map.size() == 2) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n in.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "mod = 10 ** 9 + 7\nn, k = map(int, input().split())\ncoef = []\nfor i in range(1, int(n ** 0.5) + 1):\n coef.append((n // i) - (n // (i + 1)))\ncoef += [1] * (n - sum(coef))\ncoef = coef[:: - 1]\nnn = len(coef)\ndp = [[0] * nn for _ in range(k + 1)]\ndp[0][0] = 1\nfor i in range(1, k + 1):\n tmp = 0\n for j in range(nn - 1, - 1, - 1):\n tmp += dp[i - 1][(nn - 1) - j]\n tmp %= mod\n dp[i][j] = coef[j] * tmp\n dp[i][j] %= mod\nprint(sum(dp[k]) % mod)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC132_F {\n public static void main(String[] args) {\n long mod = (long) 1e9 + 7;\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n sc.close();\n ArrayList<Integer> len = new ArrayList<>();\n int l = 1;\n while (l <= n) {\n int r = n / (n / l);\n len.add(r - l + 1);\n l = r + 1;\n }\n int q = len.size();\n long[] dp = new long[k * (q + 1)];\n for (int j = 1; j <= q; j++) {\n dp[j] = len.get(j - 1) + dp[j - 1];\n }\n for (int i = 1; i < k; i++) {\n for (int j = 1; j <= q; j++) {\n dp[i * (q + 1) + j] =\n dp[i * (q + 1) + j - 1]\n + dp[(i - 1) * (q + 1) + q - j + 1] * len.get(j - 1);\n dp[i * (q + 1) + j] %= mod;\n }\n }\n System.out.println(dp[k * (q + 1) - 1]);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nn, d = map(int, input().split())\npoints = [list(map(int, input().split())) for _ in range(n)]\n\n\ndef dist(x, y):\n tmp = 0.0\n for i in range(d):\n tmp += (x[i] - y[i]) ** 2\n return math.sqrt(tmp)\n\n\ncount = 0\nfor i, elm in enumerate(points):\n for j in range(i + 1, n):\n if dist(elm, points[j]).is_integer():\n count += 1\nprint(count)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC133_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int D = sc.nextInt();\n int[][] vectors = new int[N][D];\n for (int i = 0; i < N; i++) {\n for (int j = 0; j < D; j++) {\n vectors[i][j] = sc.nextInt();\n }\n }\n int answer = 0;\n for (int i = 0; i < N - 1; i++) {\n for (int j = i + 1; j < N; j++) {\n int dist = 0;\n for (int d = 0; d < D; d++) {\n int x = (vectors[i][d] - vectors[j][d]);\n dist += (x * x);\n }\n double sq = Math.sqrt(dist);\n answer += (Math.abs(sq - Math.floor(sq)) < 0.001 ? 1 : 0);\n }\n }\n System.out.println(answer);\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10 ** 7)\ngraph = defaultdict(list)\nN, K = map(int, input().split())\nfor i in range(N - 1):\n a, b = map(int, input().split())\n graph[a - 1].append(b - 1)\n graph[b - 1].append(a - 1)\nmod = 10 ** 9 + 7\n\n\ndef dfs(fro, to, f):\n caseNum = f\n colorNum = K - 1 if f == K else K - 2\n for u in graph[fro]:\n if u == to:\n continue\n pat = dfs(u, fro, colorNum)\n if pat == 0:\n caseNum = 0\n break\n caseNum = caseNum * pat % mod\n colorNum -= 1\n return caseNum\n\n\nans = dfs(0, - 1, K)\nprint(ans)\n" }, { "role": "user", "content": "import java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class atcoder_ABC133_E {\n private class Node {\n public long pattern = 0;\n public int index;\n public LinkedList<Integer> children = new LinkedList<Integer>();\n public int parent = -1;\n\n public Node(int i) {\n this.index = i;\n }\n\n public void setParent(int K, int parent, int use, Node[] nodes) {\n this.pattern = K - use;\n this.parent = parent;\n int count = 1;\n if (parent != -1) {\n count++;\n }\n for (int n : children) {\n if (n == this.parent) {\n continue;\n }\n nodes[n].setParent(K, index, count, nodes);\n count++;\n }\n }\n }\n\n public void solve() {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int K = in.nextInt();\n Node[] nodes = new Node[N];\n for (int i = 0; i < N; i++) {\n nodes[i] = new Node(i);\n }\n for (int i = 0; i < N - 1; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n nodes[a].children.add(b);\n nodes[b].children.add(a);\n }\n in.close();\n nodes[0].setParent(K, -1, 0, nodes);\n long patterns = 1;\n for (int i = 0; i < N; i++) {\n patterns = (patterns * nodes[i].pattern) % 1_000_000_007;\n }\n System.out.println(patterns);\n }\n\n public static void main(String[] args) {\n atcoder_ABC133_E main = new atcoder_ABC133_E();\n main.solve();\n }\n}\n" } ]
[ { "role": "assistant", "content": "def binary_search(key):\n bad, good = - 1, len(ans)\n while good - bad > 1:\n mid = (bad + good) // 2\n if ans[mid][- 1] < key:\n good = mid\n else:\n bad = mid\n return good\n\n\nN = int(input())\nans = []\nfor _ in range(N):\n A = int(input())\n idx = binary_search(A)\n if idx == len(ans):\n ans.append([A])\n else:\n ans[idx].append(A)\nprint(len(ans))\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC134_E {\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();\n while (n-- > 0) {\n int num = sc.nextInt();\n if (map.lowerKey(num) == null) {\n int val = map.getOrDefault(num, 0);\n map.put(num, ++val);\n } else {\n int key = map.lowerKey(num);\n int val = map.get(key);\n if (val == 1) {\n map.remove(key);\n } else {\n map.put(key, --val);\n }\n val = map.getOrDefault(num, 0);\n map.put(num, ++val);\n }\n }\n int ans = 0;\n for (Integer key : map.keySet()) {\n int val = map.get(key);\n ans += val;\n }\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nimport math\nfrom collections import defaultdict\nsys.setrecursionlimit(10 ** 7)\n\n\ndef input():\n return sys.stdin.readline()[: - 1]\n\n\nmod = 10 ** 9 + 7\ndef I(): return int(input())\ndef II(): return map(int, input().split())\ndef III(): return list(map(int, input().split()))\n\n\ndef Line(N):\n read_all = [tuple(map(int, input().split())) for _ in range(N)]\n return map(list, zip(* read_all))\n\n\nS = str(input())\nn = len(S)\nif n == 1:\n if S == '5' or S == '?':\n print(1)\n else:\n print(0)\n exit()\ndp = [[0] * 13 for i in range(n)]\nfor i in range(n):\n if i == 0:\n if S[i] != '?':\n dp[i][int(S[i])] += 1\n else:\n for j in range(10):\n dp[i][j] += 1\n else:\n if S[i] != '?':\n for k in range(13):\n dp[i][(k * 10 + int(S[i])) % 13] += dp[i - 1][k]\n else:\n for j in range(10):\n for k in range(13):\n dp[i][(k * 10 + j) % 13] += dp[i - 1][k]\n for k in range(13):\n dp[i][k] %= mod\nprint(dp[n - 1][5])\n" }, { "role": "user", "content": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class atcoder_ABC135_D {\n public static void main(String[] args) {\n new atcoder_ABC135_D().run();\n }\n\n final long MOD = (long) 1e9 + 7;\n\n void run() {\n Scanner sc = new Scanner(System.in);\n char[] cs = sc.next().toCharArray();\n long[][] dp = new long[cs.length][13];\n int base = 1;\n for (int i = 0; i < cs.length; ++i) {\n if (cs[cs.length - 1 - i] == '?') {\n for (int pre = 0; pre < 13; ++pre) {\n for (int next = 0; next < 10; ++next) {\n dp[i][(base * next + pre) % 13] +=\n (i > 0 ? dp[i - 1][pre] : (pre == 0 ? 1 : 0));\n dp[i][(base * next + pre) % 13] %= MOD;\n }\n }\n } else {\n int next = cs[cs.length - 1 - i] - '0';\n for (int pre = 0; pre < 13; ++pre) {\n dp[i][(base * next + pre) % 13] +=\n (i > 0 ? dp[i - 1][pre] : (pre == 0 ? 1 : 0));\n dp[i][(base * next + pre) % 13] %= MOD;\n }\n }\n base = base * 10 % 13;\n }\n System.out.println(dp[dp.length - 1][5]);\n }\n\n void tr(Object... objects) {\n System.out.println(Arrays.deepToString(objects));\n }\n}\n" } ]
[ { "role": "assistant", "content": "def main():\n N = int(input())\n i = 1\n ans = 0\n while 10 ** i <= N:\n ans += ((10 ** i) - (10 ** (i - 1)))\n i += 2\n ans += max(0, N - 10 ** (i - 1) + 1)\n print(ans)\n\n\nif __name__ == \"__main__\":\n main()\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC136_B {\n public static void main(String[] args) {\n Scanner stdIn = new Scanner(System.in);\n int N = stdIn.nextInt();\n int count = 0;\n int temp = N;\n int ans = 0;\n while (temp > 0) {\n temp /= 10;\n count++;\n }\n for (int i = 1; i <= count; i++) {\n if (i == count) {\n if (i % 2 == 1) {\n ans += (N - Math.pow(10, i - 1) + 1);\n }\n } else {\n if (i == 1) {\n ans += 9;\n } else if (i % 2 == 1) {\n ans += (Math.pow(10, i) - Math.pow(10, i - 1));\n }\n }\n }\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import heapq\nn, m = map(int, input().split())\nx = []\ny = []\nfor i in range(n):\n day, salary = map(int, input().split())\n heapq.heappush(x, (- day, - salary))\nwhile x:\n d, s = heapq.heappop(x)\n r = m - len(y)\n if r >= - d:\n heapq.heappush(y, - s)\n else:\n heapq.heappush(y, - s)\n heapq.heappop(y)\nprint(sum(y))\n" }, { "role": "user", "content": "import java.util.Collections;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\n\nclass Job implements Comparable<Job> {\n int a;\n int b;\n\n Job(int a, int b) {\n this.a = a;\n this.b = b;\n }\n\n @Override\n public int compareTo(Job otherJob) {\n if (otherJob.a == this.a) return this.b - otherJob.b;\n else return this.a - otherJob.a;\n }\n}\n\npublic class atcoder_ABC137_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String[] line = sc.nextLine().split(\" \\u2581 \");\n int N = Integer.parseInt(line[0]);\n int M = Integer.parseInt(line[1]);\n Queue<Job> q = new PriorityQueue<>();\n for (int i = 0; i < N; i++) {\n line = sc.nextLine().split(\" \\u2581 \");\n q.add(new Job(Integer.parseInt(line[0]), Integer.parseInt(line[1])));\n }\n int cnt = 0;\n Queue<Integer> jobQ = new PriorityQueue<>(Collections.reverseOrder());\n for (int i = 1; i <= M; i++) {\n while (!q.isEmpty()) {\n Job job = q.peek();\n if (job.a <= i) {\n jobQ.add(q.poll().b);\n } else break;\n }\n if (!jobQ.isEmpty()) cnt += jobQ.poll();\n }\n System.out.println(cnt);\n }\n}\n" } ]
[ { "role": "assistant", "content": "a, b = map(int, input().split())\nhole = 1\ni = 0\ncheck = True\nwhile check:\n if hole >= b:\n check = False\n else:\n hole = a * (i + 1) - i\n i += 1\nprint(i)\n" }, { "role": "user", "content": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class atcoder_ABC139_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int A = Integer.parseInt(sc.next());\n int B = Integer.parseInt(sc.next());\n int amari = 0;\n int result = 0;\n result = (B - 1) / (A - 1);\n amari = (B - 1) % (A - 1);\n if (amari != 0) {\n result += 1;\n }\n PrintWriter out = new PrintWriter(System.out);\n out.println(result);\n sc.close();\n out.flush();\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import deque\nimport scipy\nimport numpy\nfrom _collections import deque\n\n\ndef parser():\n while 1:\n data = list(input().split(' '))\n for number in data:\n if len(number) > 0:\n yield (number)\n\n\ninput_parser = parser()\n\n\ndef gw():\n global input_parser\n return next(input_parser)\n\n\ndef gi():\n data = gw()\n return int(data)\n\n\nMOD = int(1e9 + 7)\nN = gi()\nK = gi()\nS = gw()\nseg_cnt = 0\nfor i in range(0, N - 1):\n if S[i] != S[i + 1]:\n seg_cnt += 1\ncur_happy = N - 1 - seg_cnt\nif 2 * K >= seg_cnt:\n ans = N - 1\nelse:\n ans = cur_happy + 2 * K\nprint(ans)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC140_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = Integer.parseInt(sc.next());\n int K = Integer.parseInt(sc.next());\n String S = sc.next();\n char[] c1 = S.toCharArray();\n char[] c3 = S.toCharArray();\n boolean flag = false;\n int count = 0;\n for (int i = 0; i < N; i++) {\n if (flag && c1[i] == 'R') {\n flag = false;\n count++;\n }\n if (count == K) {\n break;\n }\n if (c1[i] == 'L') {\n flag = true;\n c1[i] = 'R';\n }\n }\n flag = false;\n count = 0;\n for (int i = 0; i < N; i++) {\n if (flag && c3[i] == 'L') {\n flag = false;\n count++;\n }\n if (count == K) {\n break;\n }\n if (c3[i] == 'R') {\n flag = true;\n c3[i] = 'L';\n }\n }\n String S1 = new String(c1);\n String S3 = new String(c3);\n count = 1;\n int sum1 = 0;\n char bef = S1.charAt(0);\n for (int i = 1; i < N; i++) {\n if (S1.charAt(i) == bef) {\n count++;\n if (i == N - 1) {\n sum1 += count - 1;\n }\n } else {\n bef = S1.charAt(i);\n sum1 += count - 1;\n count = 1;\n }\n }\n count = 1;\n int sum3 = 0;\n bef = S3.charAt(0);\n for (int i = 1; i < N; i++) {\n if (S3.charAt(i) == bef) {\n count++;\n if (i == N - 1) {\n sum3 += count - 1;\n }\n } else {\n bef = S3.charAt(i);\n sum3 += count - 1;\n count = 1;\n }\n }\n System.out.println(Math.max(sum1, sum3));\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\ndef I(): return (int(sys.stdin.readline()))\ndef LI(): return ([int(x) for x in sys.stdin.readline().split()])\n\n\ndef main():\n N = I()\n S = sorted(LI(), reverse=True)\n flag = [True] * len(S)\n cur = []\n cur.append(S[0])\n flag[0] = False\n for i in range(N):\n j = 0\n jM = len(cur)\n for k in range(len(S)):\n if flag[k] and S[k] < cur[j]:\n cur.append(S[k])\n j += 1\n flag[k] = False\n if j == jM:\n break\n else:\n return (\"No\")\n cur.sort(reverse=True)\n return (\"Yes\")\n\n\nif __name__ == \"__main__\":\n print(main())\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC140_F {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int size = (1 << N);\n int[] S = new int[size];\n boolean[] spawned = new boolean[size];\n spawned[size - 1] = true;\n for (int i = 0; i < size; i++) S[i] = sc.nextInt();\n Arrays.sort(S);\n List<Integer> active = new ArrayList<>();\n active.add(S[size - 1]);\n spawned[size - 1] = true;\n for (int i = 0; i < N; i++) {\n active.sort(Collections.reverseOrder());\n List<Integer> activated = new ArrayList<>();\n int next = size - 1;\n for (int slime : active) {\n while (next >= 0 && (S[next] >= slime || spawned[next])) {\n next--;\n }\n if (next < 0) {\n System.out.println(\"No\");\n return;\n }\n spawned[next] = true;\n activated.add(S[next]);\n }\n active.addAll(activated);\n }\n System.out.println(\"Yes\");\n }\n}\n" } ]
[ { "role": "assistant", "content": "from math import *\n\n\ndef next_int():\n return int(input())\n\n\ndef next_ints():\n return list(map(int, input().split()))\n\n\nn = next_int()\nt = 0\nfor i in range(n):\n if i + 1 & 1:\n t += 1\nprint(t / n)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\n\npublic class atcoder_ABC142_A {\n public static void main(String[] args) throws Exception {\n try {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n double input = Double.parseDouble(br.readLine());\n double countOdd = Math.round(input / 2);\n BigDecimal result = new BigDecimal(countOdd / input);\n result.setScale(10, RoundingMode.HALF_UP);\n System.out.println(result);\n } catch (IOException | NumberFormatException e) {\n e.printStackTrace();\n System.exit(0);\n } catch (final Exception e) {\n e.printStackTrace();\n System.exit(0);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "from operator import itemgetter\nN = int(input())\nA = [(i + 1, int(x)) for i, x in enumerate(input().split())]\nA_ = sorted(A, key=itemgetter(1))\nA__ = [a[0] for a in A_]\nfor i in A__[: - 1]:\n print(i, end=' ')\nprint(A__[- 1])\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC142_C {\n public static List<Integer> P;\n\n public static void main(String args[]) {\n Scanner scanner = new Scanner(System.in);\n int N = scanner.nextInt();\n Map<Integer, Integer> idorder = new HashMap<>();\n for (int i = 1; i <= N; i++) {\n int A = scanner.nextInt();\n idorder.put(A, i);\n }\n for (int i = 1; i <= N; i++) {\n System.out.print(idorder.get(i));\n System.out.print(\" \");\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "A, B = map(int, input().split())\nans = A - 2 * B\nif ans < 0:\n ans = 0\nprint(ans)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class atcoder_ABC143_A {\n public static void main(String[] args) {\n try {\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n String[] x = bf.readLine().trim().split(\" \");\n int a = Integer.parseInt(x[0]);\n int b = Integer.parseInt(x[1]);\n int c = a - b * 2;\n if (c < 0) c = 0;\n System.out.println(c);\n } catch (Exception e) {\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "from bisect import bisect_right, bisect_left\nn, * l = map(int, open(0).read().split())\nl.sort()\nans = 0\nfor i in range(n):\n for j in range(i + 1, n):\n a = l[i]\n b = l[j]\n right = bisect_left(l, a + b)\n left = bisect_right(l, max(a - b, b - a))\n tmp = max(0, right - left)\n if left <= i < right:\n tmp -= 1\n if left <= j < right:\n tmp -= 1\n ans += tmp\nprint(ans // 3)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC143_D {\n public static void main(String args[]) {\n Scanner scanner = new Scanner(System.in);\n int N = scanner.nextInt();\n List<Integer> L = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n L.add(scanner.nextInt());\n }\n Collections.sort(L);\n int count = 0;\n for (int i = 0; i < N; i++) {\n for (int j = i + 1; j < N; j++) {\n int a = L.get(i);\n int b = L.get(j);\n int res = find(L, j + 1, a + b);\n count = count + res;\n }\n }\n System.out.println(count);\n }\n\n public static int find(List<Integer> li, int from, int target) {\n int low = from;\n int upp = li.size() - 1;\n int mid = (upp - low + 1) % 2 == 0 ? (low + upp) / 2 + 1 : (low + upp) / 2;\n if (upp - low < 0) {\n return 0;\n } else if (li.get(from) >= target) {\n return 0;\n } else if (li.get(upp) < target) {\n return upp - low + 1;\n }\n while (upp - low > 1) {\n if (li.get(mid) >= target) {\n upp = mid;\n } else {\n low = mid;\n }\n mid = (upp - low + 1) % 2 == 0 ? (low + upp) / 2 + 1 : (low + upp) / 2;\n }\n return low - from + 1;\n }\n}\n" } ]
[ { "role": "assistant", "content": "n = int(input())\ns = input()\nif n % 2 != 0:\n print('No')\nelif s[: int(n / 2)] == s[int(n / 2):]:\n print('Yes')\nelse:\n print('No')\n" }, { "role": "user", "content": "import java.math.*;\nimport java.util.*;\n\npublic class atcoder_ABC145_B {\n public static void cout(String str) {\n System.out.println(str);\n }\n ;\n\n public static void main(String args[]) {\n Scanner cin = new Scanner(System.in);\n String a = \"\", b = \"\", str;\n int n;\n n = cin.nextInt();\n cin.nextLine();\n str = cin.nextLine();\n for (int i = 0; i < n / 2; i++) {\n a = a + str.charAt(i);\n }\n if (str.equals(a + a)) cout(\"Yes\");\n else cout(\"No\");\n }\n}\n;\n" } ]
[ { "role": "assistant", "content": "import sys\nimport itertools\n\n\ndef solve(N: int, x: \"List[int]\", y: \"List[int]\"):\n indices = [i for i in range(N)]\n permutations = itertools.permutations(indices)\n distances = []\n for permutation in permutations:\n total_distance = 0\n for i in range(0, N - 1):\n f, t = permutation[i: i + 2]\n distance = ((x[t] - x[f]) ** 2 + (y[t] - y[f]) ** 2) ** 0.5\n total_distance += distance\n distances.append(total_distance)\n result = sum(distances) / len(distances)\n print(result)\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens))\n x = [int()] * (N)\n y = [int()] * (N)\n for i in range(N):\n x[i] = int(next(tokens))\n y[i] = int(next(tokens))\n solve(N, x, y)\n\n\nif __name__ == \"__main__\":\n main()\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC145_C {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int N = scanner.nextInt();\n int[][] pos = new int[N][2];\n for (int i = 0; i < N; i++) {\n pos[i][0] = scanner.nextInt();\n pos[i][1] = scanner.nextInt();\n }\n double sum = 0;\n for (int i = 0; i < N; i++) {\n for (int j = 0; j < N; j++) {\n if (i == j) continue;\n sum += dist(pos[i][0], pos[i][1], pos[j][0], pos[j][1]);\n }\n }\n System.out.println(sum / N);\n }\n\n private static double dist(int x1, int y1, int x2, int y2) {\n return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nfrom operator import itemgetter\ninput = sys.stdin.readline\nTIME = 0\nVAL = 1\nN, T = [int(a) for a in input().split()]\ntime_value = [(- 1, - 1)] + [None] * (N)\nfor i in range(1, N + 1):\n time_value[i] = tuple(int(a) for a in input().split())\ntime_value.sort(key=itemgetter(VAL))\ndp = [[- 1] * T for _ in range(N + 1)]\nfor t in range(0, T):\n dp[0][t] = 0\nfor n in range(1, N + 1):\n dp[n][0] = 0\n for t in range(1, T):\n if time_value[n][TIME] > t:\n dp[n][t] = dp[n - 1][t]\n else:\n dp[n][t] = max(dp[n - 1][t], time_value[n][VAL] +\n dp[n - 1][t - time_value[n][TIME]])\nval_acum = time_value[N][VAL]\nt = T - 1\nmax_val = val_acum + dp[N - 1][t]\nfor n in range(N - 1, 0, - 1):\n val_acum += time_value[n][VAL]\n t -= time_value[n + 1][TIME]\n if t < 0:\n break\n else:\n max_val = max(max_val, val_acum + dp[n - 1][t])\nprint(max_val)\n" }, { "role": "user", "content": "import java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class atcoder_ABC145_E {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int T = sc.nextInt();\n int[][] AB = new int[N][2];\n for (int i = 0; i < N; i++) {\n AB[i][0] = sc.nextInt();\n AB[i][1] = sc.nextInt();\n }\n Arrays.sort(AB, Comparator.comparingInt(a -> a[0]));\n int[][] dp = new int[N + 1][6001];\n for (int i = 1; i <= N; i++) {\n for (int timeAfterEat = 0; timeAfterEat <= 6000; timeAfterEat++) {\n dp[i][timeAfterEat] = Math.max(dp[i][timeAfterEat], dp[i - 1][timeAfterEat]);\n int time = AB[i - 1][0];\n int value = AB[i - 1][1];\n if (0 <= timeAfterEat - time && timeAfterEat - time < T) {\n dp[i][timeAfterEat] =\n Math.max(dp[i][timeAfterEat], dp[i - 1][timeAfterEat - time] + value);\n }\n }\n }\n System.out.println(Arrays.stream(dp[N]).max().getAsInt());\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import deque\nimport sys\ninput = sys.stdin.readline\n\n\ndef bfs(v, N, G, E):\n visited = [0] * N\n queue = deque()\n K = - 1\n node2color = [- 1 for _ in range(N)]\n queue.append(v)\n visited[v] = 1\n while queue:\n q = queue.popleft()\n color = 0\n for nex in G[q]:\n if visited[nex]:\n continue\n visited[nex] = 1\n color += 1\n if color == node2color[q]:\n color += 1\n node2color[nex] = color\n E[(min(q, nex), max(q, nex))] = color\n queue.append(nex)\n K = max(K, color)\n return K\n\n\ndef main():\n N = int(input())\n G = [deque() for _ in range(N)]\n E = dict()\n for i in range(N - 1):\n a, b = map(lambda x: int(x) - 1, input().split())\n G[a].append(b)\n G[b].append(a)\n E[(a, b)] = 0\n K = bfs(0, N, G, E)\n print(K)\n for value in E.values():\n print(value)\n\n\nmain()\n" }, { "role": "user", "content": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class atcoder_ABC146_D {\n static int n;\n static List<ArrayList<Edge>> g;\n static int[] ans;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.next());\n g = new ArrayList();\n for (int i = 0; i < n; i++) {\n g.add(new ArrayList<Edge>());\n }\n for (int i = 0; i < n - 1; i++) {\n int a = Integer.parseInt(sc.next()) - 1;\n int b = Integer.parseInt(sc.next()) - 1;\n g.get(a).add(new Edge(i, b));\n g.get(b).add(new Edge(i, a));\n }\n ans = new int[n - 1];\n dfs(0, -1, -1);\n int max = 0;\n for (int temp : ans) {\n max = Math.max(max, temp);\n }\n System.out.println(max);\n for (int c : ans) {\n System.out.println(c);\n }\n }\n\n static void dfs(int to, int color, int parents) {\n int k = 1;\n for (Edge e : g.get(to)) {\n if (e.to == parents) continue;\n if (k == color) k++;\n ans[e.id] = k;\n dfs(e.to, k, to);\n k++;\n }\n }\n}\n\nclass Edge {\n Edge(int id, int to) {\n this.id = id;\n this.to = to;\n }\n\n int id;\n int to;\n}\n" } ]
[ { "role": "assistant", "content": "import numpy as np\nN = int(input())\nA = np.fromiter(map(int, input().split()), np.int64)\nresult = 0\nfor b in range(60):\n bs = int(((A >> b) & 1).sum())\n result = (result + bs * (N - bs) * (1 << b)) % 1000000007\nprint(result)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC147_D {\n public static void main(String[] args) {\n long startTime = System.currentTimeMillis();\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long div = (long) Math.pow(10, 9) + 7;\n long[] A = new long[n];\n long ans = 0;\n for (int i = 0; i < n; i++) {\n A[i] = sc.nextLong();\n }\n for (int i = 0; i < 60; i++) {\n long a = 0;\n long count1 = 0;\n for (int j = 0; j < n; j++) {\n if ((A[j] >> i & 1) == 1) count1++;\n }\n a = a + count1 * (n - count1);\n for (int j = 0; j < i; j++) {\n a = (a << 1) % div;\n }\n ans += a;\n ans %= div;\n }\n System.out.println(ans);\n long endTime = System.currentTimeMillis();\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import Counter, defaultdict, deque\nfrom heapq import heappop, heappush, heapify\nimport sys\nimport bisect\nimport math\nimport itertools\nimport pprint\nimport fractions\nsys.setrecursionlimit(10 ** 8)\nmod = 10 ** 9 + 7\nINF = float('inf')\ndef inp(): return int(sys.stdin.readline())\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\n\nn, ta, ao = inpl()\nta -= 1\nao -= 1\ng = [[] for i in range(n)]\nfor i in range(n - 1):\n a, b = inpl()\n g[a - 1].append(b - 1)\n g[b - 1].append(a - 1)\nta_dist = [None] * n\nta_dist[ta] = 0\nao_dist = [None] * n\nao_dist[ao] = 0\n\n\ndef ta_dfs(node):\n for v in g[node]:\n if ta_dist[v] != None:\n continue\n ta_dist[v] = ta_dist[node] + 1\n ta_dfs(v)\n\n\ndef ao_dfs(node):\n for v in g[node]:\n if ao_dist[v] != None:\n continue\n ao_dist[v] = ao_dist[node] + 1\n ao_dfs(v)\n\n\nao_dfs(ao)\nta_dfs(ta)\nres = 0\nfor i in range(n):\n if ta_dist[i] > ao_dist[i]:\n continue\n res = max(res, ao_dist[i])\nprint(res - 1)\n" }, { "role": "user", "content": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class atcoder_ABC148_F {\n public static void main(String[] args) throws Exception {\n try (Scanner sc = new Scanner(System.in)) {\n int N = sc.nextInt();\n int u = sc.nextInt() - 1;\n int v = sc.nextInt() - 1;\n List<Integer>[] edges = new List[N];\n for (int i = 0; i < N; i++) {\n edges[i] = new ArrayList<>();\n }\n for (int i = 0; i < N - 1; i++) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n edges[a].add(b);\n edges[b].add(a);\n }\n int[] d = new int[N];\n for (int i = 0; i < N; i++) {\n d[i] = Integer.MAX_VALUE;\n }\n d[u] = 0;\n dfs(u, d, edges);\n int[] e = new int[N];\n for (int i = 0; i < N; i++) {\n e[i] = Integer.MAX_VALUE;\n }\n e[v] = 0;\n dfs(v, e, edges);\n int q = -1;\n for (int i = 0; i < N; i++) {\n if (d[i] < e[i]) {\n if (e[i] > q) {\n q = e[i];\n }\n }\n }\n if (q <= 0) {\n System.out.println(0);\n } else {\n System.out.println(q - 1);\n }\n }\n }\n\n static void dfs(int u, int[] d, List<Integer>[] edges) {\n for (Integer nu : edges[u]) {\n if (d[nu] == Integer.MAX_VALUE) {\n d[nu] = d[u] + 1;\n dfs(nu, d, edges);\n }\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "cookies = [int(x) for x in input().split()]\nleftOver = cookies[0] - cookies[2]\ntakahashi = max(0, leftOver)\nprint(str(takahashi) + ' ' +\n (str(cookies[1]) if takahashi > 0 else str(max(0, cookies[1] - abs(leftOver)))))\n" }, { "role": "user", "content": "import java.io.*;\nimport java.nio.charset.StandardCharsets;\nimport java.util.*;\n\npublic class atcoder_ABC149_B {\n long A, B, K;\n long x, y;\n\n public static void main(String[] args) throws IOException {\n InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);\n BufferedReader in = new BufferedReader(reader);\n atcoder_ABC149_B ins = new atcoder_ABC149_B(in);\n ins.calc();\n ins.showResult();\n }\n\n atcoder_ABC149_B(BufferedReader in) throws IOException {\n String[] tokens = in.readLine().split(\" \");\n A = Long.parseLong(tokens[0]);\n B = Long.parseLong(tokens[1]);\n K = Long.parseLong(tokens[2]);\n }\n\n void calc() {\n x = A;\n y = B;\n x = A - K;\n if (x < 0) {\n y = B + x;\n x = 0;\n if (y < 0) {\n y = 0;\n }\n }\n }\n\n void showResult() {\n System.out.println(x + \" \" + y);\n }\n}\n" } ]
[ { "role": "assistant", "content": "X = int(input())\nprime = [True] * (100010)\nprime[0] = False\nprime[1] = False\nfor i in range(4, 100010, 2):\n prime[i] = False\ni = 3\nwhile (i * i <= 100008):\n if prime[i]:\n for j in range(i + i, 100008, i):\n prime[j] = False\n i += 2\nfor i in range(X, 100008):\n if prime[i]:\n print(i)\n break\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC149_C {\n public static void main(String[] args) {\n Scanner stdIn = new Scanner(System.in);\n int x = Integer.parseInt(stdIn.next());\n if (x != 2 && x % 2 == 0) x++;\n while (true) {\n int i;\n double sqrtNum = Math.sqrt(x);\n for (i = 3; i <= sqrtNum; i += 2) {\n if (x % i == 0) break;\n }\n if (i > sqrtNum) break;\n x += 2;\n }\n System.out.println(x);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import itertools\nn = int(input())\norig = list(itertools.permutations(list(range(1, n + 1))))\np = tuple(map(int, input().split()))\nq = tuple(map(int, input().split()))\npn = orig.index(p)\nqn = orig.index(q)\nprint(abs(pn - qn))\n" }, { "role": "user", "content": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class atcoder_ABC150_C {\n public static List<String> permutation(List<String> list, String target, String ans) {\n if (target.length() <= 1) {\n list.add(ans + target);\n } else {\n for (int i = 0; i < target.length(); i++) {\n permutation(\n list,\n target.substring(0, i) + target.substring(i + 1),\n ans + target.charAt(i));\n }\n }\n return list;\n }\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n Integer n = Integer.parseInt(scanner.next());\n String[][] line = new String[2][1];\n for (int i = 0; i < 2; i++) {\n Arrays.fill(line[i], \"\");\n for (int j = 0; j < n; j++) {\n line[i][0] += scanner.next();\n }\n }\n String number = \"\";\n for (int i = 1; i <= n; i++) {\n number += i;\n }\n List<String> listA = new ArrayList<>();\n permutation(listA, number, \"\");\n int sum = 0;\n for (int j = 0; j < line.length; j++) {\n for (int i = 0; i < listA.size(); i++) {\n if (listA.get(i).equals(line[j][0])) {\n if (sum == 0) {\n sum += i;\n } else {\n sum -= i;\n }\n }\n }\n }\n System.out.println(Math.abs(sum));\n }\n}\n" } ]
[ { "role": "assistant", "content": "import fractions\nimport math\nn, num = map(int, input().split())\nnum_set = set(map(lambda x: int(x), input().split()))\ntwo_times_set = set()\nfor i in num_set:\n for j in range(1, 30):\n i //= 2\n if i % 2 != 0:\n two_times_set.add(j)\n break\n if len(two_times_set) != 1:\n print(0)\n break\nelse:\n num_list = list(num_set)\n lcm = num_list[0]\n for i in range(1, len(num_list)):\n lcm = lcm * num_list[i] // fractions.gcd(lcm, num_list[i])\n print((num - lcm // 2) // (lcm) + 1)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC150_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.next());\n int m = Integer.parseInt(sc.next());\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = Integer.parseInt(sc.next()) / 2;\n }\n long gcd;\n long lcd = 1;\n for (int i = 0; i < n; i++) {\n gcd = getGCD(lcd, a[i]);\n lcd = lcd * a[i] / gcd;\n if (lcd > m) {\n System.out.println(0);\n return;\n }\n }\n for (int i = 0; i < n; i++) {\n if ((lcd / a[i]) % 2 == 0) {\n System.out.println(0);\n return;\n }\n }\n System.out.println((m / lcd + 1) / 2);\n }\n\n public static long getGCD(long a, long b) {\n if (b == 0) {\n return a;\n } else {\n return getGCD(b, a % b);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "mod = 10 ** 9 + 7\nn = int(input())\nc = list(map(int, input().split()))\nc.sort(reverse=True)\nb = pow(2, 2 * n - 2, mod)\na = 2 * b % mod\nans = 0\nfor i in range(n):\n ans += c[i] * (a + i * b)\n ans %= mod\nprint(ans)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class atcoder_ABC150_E {\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] sa = br.readLine().split(\" \");\n int n = Integer.parseInt(sa[0]);\n sa = br.readLine().split(\" \");\n int[] c = new int[n];\n for (int i = 0; i < n; i++) {\n c[i] = Integer.parseInt(sa[i]);\n }\n br.close();\n int mod = 1000000007;\n if (n == 1) {\n System.out.println(c[0] * 2 % mod);\n return;\n }\n Arrays.parallelSort(c);\n long b = power(2, n);\n long a = power(2, n - 2);\n long ans = 0;\n for (int i = 2; i <= n + 1; i++) {\n long val = a * i % mod;\n val *= c[n + 1 - i];\n val %= mod;\n ans += val;\n ans %= mod;\n }\n ans *= b;\n ans %= mod;\n System.out.println(ans);\n }\n\n static long power(long x, long n) {\n if (n == 0) {\n return 1;\n }\n int mod = 1000000007;\n long val = power(x, n / 2);\n val = val * val % mod;\n if (n % 2 == 1) {\n val = val * x % mod;\n }\n return val;\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nimport math\ndebug = False\n\n\ndef log(text):\n if debug:\n print(text)\n\n\ndef parse_input(lines_as_string=None):\n global debug\n lines = []\n if lines_as_string is None:\n debug = False\n lines.append(input())\n else:\n debug = True\n lines = [e for e in lines_as_string.split(\"\\n\")][1: - 1]\n c = [e for e in lines[0].split(\" \")][0]\n return (c, )\n\n\ndef solve(c):\n a = \"abcdefghijklmnopqrstuvwxyz\"\n i = a.index(c)\n return a[i + 1]\n\n\ndef main():\n result = solve(* parse_input())\n if isinstance(result, list):\n for r in result:\n print(\"%s\" % r, sep='')\n else:\n print(\"%s\" % result, sep='')\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class atcoder_ABC151_A {\n public static void main(String[] args) throws IOException {\n BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);\n String s;\n String sl[];\n s = r.readLine();\n System.out.printf(\"%c\", s.charAt(0) + 1);\n }\n}\n\nclass RemRing {\n long module;\n\n public RemRing(long module) {\n this.module = module;\n }\n\n public long sum(long a, long b) {\n return (a + b + module) % module;\n }\n\n public long sub(long a, long b) {\n return (a - b + module) % module;\n }\n\n public long prod(long a, long b) {\n return (a * b) % module;\n }\n\n public long div(long a, long b) {\n return (a * inv(b)) % module;\n }\n\n public long inv(long a) {\n long b = this.module;\n long u = 1;\n long v = 0;\n while (b > 0) {\n long t = a / b;\n a -= t * b;\n u -= t * v;\n long z = a;\n a = b;\n b = z;\n z = u;\n u = v;\n v = z;\n }\n u %= this.module;\n if (u < 0) u += this.module;\n return u;\n }\n}\n" } ]
[ { "role": "assistant", "content": "import numpy as np\nN = int(input())\nn = [int(x) for x in input().split()]\nn = np.array(n)\na = 1\npos = 0\nfor i in range(1, N):\n if n[pos] > n[i]:\n a += 1\n pos = i\nprint(a)\n" }, { "role": "user", "content": "import java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class atcoder_ABC152_C {\n public static void main(String[] args) {\n System.out.println(solve());\n }\n\n public static int solve() {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int[] arr = new int[N];\n for (int i = 0; i < N; i++) {\n arr[i] = sc.nextInt();\n }\n int sum = 0;\n Queue<Integer> q = new PriorityQueue<>();\n for (int i = 0; i < arr.length; i++) {\n q.add(arr[i]);\n if (arr[i] <= q.peek()) {\n sum++;\n }\n }\n return sum;\n }\n}\n" } ]
[ { "role": "assistant", "content": "from fractions import gcd\n\n\ndef lcm(a, b):\n return a * b / gcd(a, b)\n\n\nMOD = 10 ** 9 + 7\nN = int(input())\nA = list(map(int, input().split()))\n_lcm = 1\nfor a in A:\n _lcm = _lcm * a // gcd(_lcm, a)\nans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD\nprint(int(ans % MOD))\n" }, { "role": "user", "content": "import java.math.*;\nimport java.util.*;\nimport java.util.function.*;\n\npublic class atcoder_ABC152_E {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int[] A = new int[N];\n for (int i = 0; i < N; i++) {\n A[i] = sc.nextInt();\n }\n sc.close();\n BigInteger lcm = BigInteger.ONE;\n for (int ai : A) {\n BigInteger a = BigInteger.valueOf(ai);\n lcm = lcm.divide(lcm.gcd(a)).multiply(a);\n }\n long mod = 1000000007;\n long modLcm = lcm.remainder(BigInteger.valueOf(mod)).longValue();\n long ans = 0;\n for (int ai : A) ans = (ans + modDiv(modLcm, ai, mod)) % mod;\n System.out.println(ans);\n }\n\n private static long modDiv(long a, long b, long mod) {\n return (a % mod) * modInv(b, mod) % mod;\n }\n\n private static long modInv(long x, long mod) {\n return modPow(x, mod - 2, mod);\n }\n\n private static long modPow(long b, long e, long mod) {\n long ans = 1;\n long x = b % mod;\n for (long y = e; y != 0; y >>= 1) {\n if ((y & 1) == 1) ans = (ans * x) % mod;\n x = (x * x) % mod;\n }\n return ans;\n }\n}\n" } ]
[ { "role": "assistant", "content": "h, a = map(int, input().split(\" \"))\nsho = int(h / a)\nam = int(h % a)\nif am != 0:\n sho += 1\nelse:\n pass\nprint(sho)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class atcoder_ABC153_A {\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String[] str = in.readLine().split(\" \");\n int h = Integer.parseInt(str[0]);\n int a = Integer.parseInt(str[1]);\n int num = 0;\n for (int i = 1; h > 0; i++) {\n h = h - a;\n num++;\n }\n System.out.println(num);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\n\n\ndef solve(S: str, T: str, A: int, B: int, U: str):\n if S == U:\n A -= 1\n if T == U:\n B -= 1\n print(A, B)\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n S = next(tokens)\n T = next(tokens)\n A = int(next(tokens))\n B = int(next(tokens))\n U = next(tokens)\n solve(S, T, A, B, U)\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class atcoder_ABC154_A {\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String[] str = in.readLine().split(\" \");\n StringTokenizer st = new StringTokenizer(in.readLine());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n String u = in.readLine();\n System.out.println(u.equals(str[0]) ? (a - 1) + \" \" + b : a + \" \" + (b - 1));\n }\n}\n" } ]
[ { "role": "assistant", "content": "N, K = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort()\nll = - 10 ** 18 - 1\nrr = 10 ** 18 + 1\nwhile ll + 1 < rr:\n x = (ll + rr) // 2\n tot = 0\n for i in range(N):\n if A[i] < 0:\n l = - 1\n r = N\n while l + 1 < r:\n c = (l + r) // 2\n if A[i] * A[c] < x:\n r = c\n else:\n l = c\n tot += N - r\n else:\n l = - 1\n r = N\n while l + 1 < r:\n c = (l + r) // 2\n if A[i] * A[c] < x:\n l = c\n else:\n r = c\n tot += r\n if A[i] * A[i] < x:\n tot -= 1\n tot //= 2\n if tot < K:\n ll = x\n else:\n rr = x\nprint(ll)\n" }, { "role": "user", "content": "import java.math.*;\nimport java.util.*;\n\npublic class atcoder_ABC155_D {\n static int mod = (int) 1e9 + 7;\n static int DX[] = {-1, 0, 1, 0}, DY[] = {0, -1, 0, 1};\n static int n;\n static long k;\n static long a[];\n\n public static void main(String[] args) {\n Scanner fs = new Scanner(System.in);\n n = fs.nextInt();\n k = fs.nextLong();\n a = new long[n];\n for (int i = 0; i < n; ++i) {\n a[i] = fs.nextLong();\n }\n Arrays.sort(a);\n long INF = (long) (1e18) + 1;\n long l = -INF;\n long r = INF;\n while (l + 1 < r) {\n long c = (l + r) / 2;\n if (check(c)) l = c;\n else r = c;\n }\n System.out.println(l);\n }\n\n static boolean check(long x) {\n long tot = 0;\n for (int i = 0; i < n; i++) {\n long now = a[i];\n int l = 0, r = n;\n if (now >= 0) {\n while (l < r) {\n int c = (l + r) / 2;\n if (now * a[c] < x) l = c + 1;\n else r = c;\n }\n tot += l;\n } else {\n while (l < r) {\n int c = (l + r) / 2;\n if (now * a[c] >= x) l = c + 1;\n else r = c;\n }\n tot += (n - l);\n }\n if ((long) a[i] * a[i] < x) tot--;\n }\n if (tot / 2 < k) return true;\n else return false;\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\ninput_methods = ['clipboard', 'file', 'key']\nusing_method = 0\ninput_method = input_methods[using_method]\ndef IN(): return map(int, input().split())\n\n\nmod = 1000000007\n\n\ndef main_b():\n s = input()\n pp = 0\n na = 0\n for i, c in enumerate(s[:: - 1]):\n cc = na + int(c)\n na = 0\n if cc <= 4:\n pp += cc\n else:\n na = 1\n if i == len(s) - 1:\n pp += 1\n pp += 10 - cc\n print(pp)\n\n\ndef main():\n s = input()\n pmin = 1000\n mmin = 0\n s = '0' + s\n for c in s[:: - 1]:\n v = int(c)\n npmin = min(pmin + 10 - (v + 1), mmin + 10 - v)\n nmmin = min(pmin + v + 1, mmin + v)\n pmin = npmin\n mmin = nmmin\n return min(pmin, mmin)\n\n\nisTest = False\n\n\ndef pa(v):\n if isTest:\n print(v)\n\n\ndef input_clipboard():\n import clipboard\n input_text = clipboard.get()\n input_l = input_text.splitlines()\n for l in input_l:\n yield l\n\n\nif __name__ == \"__main__\":\n if sys.platform == 'ios':\n if input_method == input_methods[0]:\n ic = input_clipboard()\n def input(): return ic.__next__()\n elif input_method == input_methods[1]:\n sys.stdin = open('inputFile.txt')\n else:\n pass\n isTest = True\n else:\n pass\n ret = main()\n if ret is not None:\n print(ret)\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC155_E {\n public static void main(String[] args) {\n final long INF = (long) 1e15;\n Scanner sc = new Scanner(System.in);\n String number = sc.next();\n int[] digits = new int[number.length() + 1];\n for (int i = 0; i < number.length(); i++) {\n digits[i] = number.charAt(number.length() - 1 - i) - '0';\n }\n int bills = 0;\n for (int i = 0; i <= number.length(); i++) {\n if (digits[i] == 10) {\n digits[i + 1]++;\n digits[i] = 0;\n }\n if (digits[i] < 5) {\n bills += digits[i];\n } else if (digits[i] == 5) {\n if (digits[i + 1] >= 5) {\n digits[i + 1]++;\n }\n bills += 5;\n } else {\n digits[i + 1]++;\n bills += 10 - digits[i];\n }\n }\n System.out.println(bills);\n }\n}\n" } ]
[ { "role": "assistant", "content": "stdin = input()\ns = stdin\nresult = \"Yes\" if \"A\" in s and \"B\" in s else \"No\"\nprint(result)\n" }, { "role": "user", "content": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class atcoder_ABC158_A {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n AStationAndBus solver = new AStationAndBus();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AStationAndBus {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n String s = in.next();\n if (s.contains(\"A\") && s.contains(\"B\")) {\n out.println(\"Yes\");\n } else {\n out.println(\"No\");\n }\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\ninput = sys.stdin.readline\ndef I(): return int(input())\ndef MI(): return map(int, input().split())\ndef LI(): return list(map(int, input().split()))\n\n\ndef main():\n mod = 10 ** 9 + 7\n N, A, B = MI()\n ans = 0\n rep = N // (A + B)\n ans += rep * A\n res = N - rep * (A + B)\n ans += min(res, A)\n print(ans)\n\n\nmain()\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC158_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n long N = scan.nextLong();\n long A = scan.nextLong();\n long B = scan.nextLong();\n long k = 0;\n if (1 <= N\n && N <= Math.pow(10, 18)\n && 0 <= A\n && 0 <= B\n && 0 < A + B\n && A + B <= Math.pow(10, 18)) {\n if (A + B <= N) {\n k = N / (A + B);\n if (N - k * (A + B) > A) {\n System.out.println(A * k + (N - k * (A + B)) - (N - (k * (A + B) + A)));\n } else {\n System.out.println(A * k + (N - k * (A + B)));\n }\n } else if (A + B > N && A <= N) {\n System.out.println(A);\n } else {\n System.out.println(N);\n }\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nN = int(input())\nS = input()\n\n\ndef calculate(n, s):\n arr = list(s)\n rNum = arr.count(\"R\")\n gNum = arr.count(\"G\")\n bNum = arr.count(\"B\")\n sum = 0\n for step in range(1, math.ceil(n / 2) + 1):\n for i in range(n - 2 * step):\n s = \"\".join([arr[i], arr[i + step], arr[i + step * 2]])\n if s == \"RGB\" or s == \"RBG\" or s == \"BGR\" or s == \"BRG\" or s == \"GBR\" or s == \"GRB\":\n sum = sum + 1\n print(rNum * gNum * bNum - sum)\n\n\ncalculate(N, S)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC162_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n String s = sc.next();\n long rc = 0;\n long gc = 0;\n long bc = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == 'R') {\n rc++;\n } else if (s.charAt(i) == 'G') {\n gc++;\n } else {\n bc++;\n }\n }\n long result = rc * gc * bc;\n for (int i = 1; i <= n; i++) {\n for (int k = i + 1; k <= n; k++) {\n if ((i + k) % 2 == 0) {\n char is = s.charAt(i - 1);\n char ks = s.charAt(k - 1);\n char js = s.charAt(((i + k) / 2) - 1);\n if (is != ks && ks != js && js != is) {\n result--;\n }\n }\n }\n }\n System.out.println(result);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\n\n\ndef main():\n S, W = map(int, input().split())\n print(\"unsafe\") if (S <= W) else print(\"safe\")\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC164_A {\n public static void main(String[] args) throws Exception {\n Scanner scan = new Scanner(System.in);\n ArrayList<String> scList = new ArrayList<>();\n for (int i = 0; i >= 0; i++) {\n try {\n scList.add(scan.nextLine());\n } catch (Exception e) {\n break;\n }\n }\n String[] numlist = scList.get(0).split(\" \");\n int Sheep = Integer.parseInt(numlist[0]);\n int Wolve = Integer.parseInt(numlist[1]);\n if (Wolve >= Sheep) {\n System.out.println(\"unsafe\");\n } else {\n System.out.println(\"safe\");\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "s, l = (input(), 2019)\nm, a, r = ([1] + [0] * l, 0, 0)\nfor i, e in enumerate(s[:: - 1]):\n a += int(e) * pow(10, i, l)\n r += m[a % l]\n m[a % l] += 1\nprint(r)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC164_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String S = sc.next();\n int N = S.length();\n int[] mod_arr = new int[N];\n int[] mod_cnt = new int[2019];\n int radix = 1;\n for (int i = 0; i < N; i++) {\n int tmp = ((int) S.charAt(N - 1 - i) - (int) '0') * radix % 2019;\n if (i != 0) tmp = (tmp + mod_arr[i - 1]) % 2019;\n mod_arr[i] = tmp;\n mod_cnt[tmp]++;\n radix = radix * 10 % 2019;\n }\n long ans = 0L;\n mod_cnt[0]++;\n for (int i = 0; i < 2019; i++) {\n ans += mod_cnt[i] * (mod_cnt[i] - 1) / 2;\n }\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\n\n\ndef solve(N: int, M: int, Q: int, a: \"List[int]\", b: \"List[int]\", c: \"List[int]\", d: \"List[int]\"):\n res = 0\n\n def rec(A):\n nonlocal res\n if len(A) == N:\n ans = 0\n for i in range(Q):\n if A[b[i] - 1] - A[a[i] - 1] == c[i]:\n ans += d[i]\n res = max(res, ans)\n return\n last_max = 1 if len(A) == 0 else A[- 1]\n for i in range(last_max, M + 1):\n rec(A + [i])\n rec([])\n print(res)\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens))\n M = int(next(tokens))\n Q = int(next(tokens))\n a = [int()] * (Q)\n b = [int()] * (Q)\n c = [int()] * (Q)\n d = [int()] * (Q)\n for i in range(Q):\n a[i] = int(next(tokens))\n b[i] = int(next(tokens))\n c[i] = int(next(tokens))\n d[i] = int(next(tokens))\n solve(N, M, Q, a, b, c, d)\n\n\nif __name__ == '__main__':\n main()\n" }, { "role": "user", "content": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class atcoder_ABC165_C {\n static int[] a = null;\n static int[] b = null;\n static int[] c = null;\n static int[] d = null;\n static int n = 0;\n static int m = 0;\n static int q = 0;\n static long ans = -100L;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n m = sc.nextInt();\n q = sc.nextInt();\n a = new int[q];\n b = new int[q];\n c = new int[q];\n d = new int[q];\n for (int i = 0; i < q; ++i) {\n a[i] = sc.nextInt() - 1;\n b[i] = sc.nextInt() - 1;\n c[i] = sc.nextInt();\n d[i] = sc.nextInt();\n }\n dfs(new ArrayList<Integer>());\n System.out.println(ans);\n }\n\n public static void dfs(ArrayList<Integer> list) {\n if (list.size() == n) {\n long score = 0L;\n for (int i = 0; i < q; ++i) {\n score += (list.get(b[i]) - list.get(a[i]) == c[i]) ? d[i] : 0L;\n }\n ans = Math.max(ans, score);\n return;\n }\n if (!list.isEmpty()) {\n for (int num = list.get(list.size() - 1); num <= m; ++num) {\n list.add(num);\n dfs(list);\n list.remove(list.size() - 1);\n }\n } else {\n for (int num = 1; num <= m; ++num) {\n list.add(num);\n dfs(list);\n list.remove(list.size() - 1);\n }\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "(n, m) = [int(x) for x in input().split()]\np = [x for x in range(1, n + 1)]\nh = [int(x) for x in input().split()]\nhp = dict(zip(p, h))\npath = {i: [] for i in range(1, n + 1)}\nfor i in range(m):\n (a, b) = [int(x) for x in input().split()]\n path[a].append(b)\n path[b].append(a)\nc = 0\nfor i, v in path.items():\n f = 0\n for j in v:\n if hp[i] <= hp[j]:\n f = 1\n break\n if f == 0:\n c += 1\nprint(c)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC166_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n long M = sc.nextLong();\n long[] H = new long[N];\n boolean[] ans = new boolean[N];\n for (int i = 0; i < N; i++) {\n H[i] = sc.nextLong();\n ans[i] = true;\n }\n for (int i = 0; i < M; i++) {\n int temp1 = sc.nextInt();\n int temp2 = sc.nextInt();\n if (H[temp1 - 1] < H[temp2 - 1]) {\n ans[temp1 - 1] = false;\n } else if (H[temp1 - 1] > H[temp2 - 1]) {\n ans[temp2 - 1] = false;\n } else {\n ans[temp1 - 1] = false;\n ans[temp2 - 1] = false;\n }\n }\n int ans2 = 0;\n for (int i = 0; i < N; i++) {\n if (ans[i]) {\n ans2++;\n }\n }\n System.out.println(ans2);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import numpy as np\nimport itertools\nn, m, x = list(map(int, input().split()))\nc = np.array([list(map(int, input().split())) for _ in range(n)])\npre = np.arange(n)\nl = []\nrem = []\nans = 0\nfor i in pre + 1:\n for j in itertools.combinations(pre, i):\n l.append(list(j))\nfor i in range(1, m + 1):\n for j, k in enumerate(l):\n ca = 0\n for ii in k:\n ca += c[ii, i]\n if ca < x:\n rem.insert(0, j)\n else:\n pass\n if len(rem) > 0:\n for j in rem:\n l.pop(j)\n rem = []\n if len(l) == 0:\n print(- 1)\n break\nelse:\n for i in l:\n ca = 0\n for j in i:\n ca += c[j, 0]\n if ans == 0:\n ans = ca\n else:\n ans = min(ans, ca)\n print(ans)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC167_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(), m = sc.nextInt(), x = sc.nextInt(), min = Integer.MAX_VALUE;\n int[][] a = new int[n][m + 1];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j <= m; j++) a[i][j] = sc.nextInt();\n }\n for (int i = 0; i < Math.pow(2, n); i++) {\n int[] status = new int[n];\n for (int j = 0; j < n; j++) {\n if ((1 & i >> j) == 1) {\n status[j] = 1;\n }\n }\n int[] res = new int[m + 1];\n for (int j = 0; j < n; j++) {\n if (status[j] == 1) {\n for (int k = 0; k <= m; k++) {\n res[k] += a[j][k];\n }\n }\n }\n boolean flag = true;\n for (int j = 1; j <= m; j++) {\n if (res[j] < x) {\n flag = false;\n break;\n }\n }\n if (flag) min = Math.min(min, res[0]);\n }\n if (min == Integer.MAX_VALUE) System.out.println(-1);\n else System.out.println(min);\n }\n}\n" } ]
[ { "role": "assistant", "content": "from collections import defaultdict\nN, K = map(int, input().split())\nL = list(map(int, input().split()))\nL.insert(0, - 1)\npath = [1]\nind = 0\ncount = 0\nx = 1\nt = - 1\nflag = False\nHash = defaultdict(lambda: 0)\nfor i in range(N + 1):\n ne = L[x]\n if Hash[ne]:\n flag = True\n t = Hash[ne]\n break\n path.append(ne)\n ind += 1\n Hash[ne] = ind\n x = ne\nif flag == True:\n loop = path[t::]\n if K < (len(path)):\n print(path[K])\n else:\n K = K - len(path)\n K = K % len(loop)\n print(loop[K])\nelse:\n print(path[K - 1])\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_ABC167_D {\n Scanner sc = new Scanner(System.in);\n final int MOD = 1000000007;\n final int MAX = Integer.MAX_VALUE;\n final long LMAX = Long.MAX_VALUE;\n int len = (int) 1e6 + 1;\n\n void doIt() {\n int N = sc.nextInt();\n long K = sc.nextLong();\n int A[] = new int[N];\n for (int i = 0; i < N; i++) {\n A[i] = sc.nextInt() - 1;\n }\n Set<Integer> used = new HashSet<>();\n int idx[] = new int[N];\n int pos[] = new int[N];\n int next = 0, cur = 0;\n while (!used.contains(next)) {\n used.add(next);\n idx[next] = cur;\n pos[cur] = next;\n next = A[next];\n cur++;\n }\n long a = (long) cur - idx[next];\n long b = (long) idx[next];\n int ans = (int) ((10000 * a + K - b) % a + b);\n if (b > K) ans = (int) K;\n System.out.println(pos[ans] + 1);\n }\n\n public static void main(String[] args) {\n new atcoder_ABC167_D().doIt();\n }\n}\n" } ]
[ { "role": "assistant", "content": "def main():\n K = int(input())\n S = input()\n if len(S) <= K:\n return S\n return S[: K] + '...'\n\n\nif __name__ == '__main__':\n print(main())\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC168_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int K = in.nextInt();\n String S = in.next();\n if (S.length() <= K) {\n System.out.println(S);\n } else {\n System.out.println(S.substring(0, K) + \"...\");\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\na, b, h, m = map(int, input().split())\nC = abs(360 / 60 * m - 360 / 12 * h - 360 / 12 / 60 * m)\nif C > 180:\n C = 360 - C\ncosC = math.cos(math.radians(C))\nprint(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cosC))\n" }, { "role": "user", "content": "import java.math.BigDecimal;\nimport java.util.*;\n\npublic class atcoder_ABC168_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int A = sc.nextInt();\n int B = sc.nextInt();\n int H = sc.nextInt();\n int M = sc.nextInt();\n BigDecimal AA = new BigDecimal(A);\n BigDecimal BB = new BigDecimal(B);\n BigDecimal HH = new BigDecimal(H);\n BigDecimal MM = new BigDecimal(M);\n BigDecimal ans2;\n BigDecimal kaku;\n BigDecimal mkaku;\n BigDecimal hkaku;\n BigDecimal AA2;\n BigDecimal BB2;\n BigDecimal CC;\n BigDecimal DD;\n double dkaku;\n double dans2;\n mkaku = MM.multiply(BigDecimal.valueOf(6));\n hkaku = HH.multiply(BigDecimal.valueOf(30));\n hkaku = hkaku.add(BigDecimal.valueOf((double) M / 2));\n kaku = mkaku.subtract(hkaku);\n dkaku = Math.abs(Math.toRadians(kaku.doubleValue()));\n AA2 = AA.multiply(AA);\n BB2 = BB.multiply(BB);\n CC = AA2.add(BB2);\n DD = BigDecimal.valueOf(Math.cos(dkaku));\n DD = DD.multiply(BigDecimal.valueOf(2));\n DD = DD.multiply(AA);\n DD = DD.multiply(BB);\n ans2 = CC.subtract(DD);\n dans2 = ans2.doubleValue();\n double ans = Math.sqrt(dans2);\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "def main():\n from sys import setrecursionlimit, stdin\n from os import environ\n from collections import defaultdict, deque, Counter\n from math import ceil, floor, gcd\n from itertools import accumulate, combinations, combinations_with_replacement\n setrecursionlimit(10 ** 6)\n dbg = (lambda * something: print(* something)\n ) if 'TERM_PROGRAM' in environ else lambda * x: 0\n\n def input(): return stdin.readline().rstrip()\n def LMIIS(): return list(map(int, input().split()))\n def II(): return int(input())\n P = 10 ** 9 + 7\n INF = 10 ** 9 + 10\n sa, sb = input().split()\n a = int(sa)\n b = int(float(sb) * 100 + 0.1)\n print(a * b // 100)\n\n\nmain()\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC169_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long a = sc.nextLong();\n String b = sc.next();\n char[] bChar = b.toCharArray();\n int length = bChar.length;\n String bStr = \"\";\n for (int i = 0; i < length; i++) {\n if (bChar[i] != '.') {\n bStr += bChar[i];\n }\n }\n int bInt = Integer.parseInt(bStr);\n long result = (a * bInt) / 100;\n System.out.println(result);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nfrom functools import reduce\nfrom collections import deque, Counter\nimport sys\nsys.setrecursionlimit(10 ** 7)\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef get_nums_l():\n return [int(s) for s in input().split(\" \")]\n\n\ndef get_nums_n(n):\n return [int(input()) for _ in range(n)]\n\n\ndef get_all_int():\n return map(int, open(0).read().split())\n\n\ndef rangeI(it, l, r):\n for i, e in enumerate(it):\n if l <= i < r:\n yield e\n elif l >= r:\n break\n\n\ndef log(* args):\n print(\"DEBUG:\", * args, file=sys.stderr)\n\n\nINF = 999999999999999999999999\nMOD = 10 ** 9 + 7\nn = int(input())\nif n == 1:\n print(0)\n exit()\n\n\ndef prime_factorize(n):\n a = []\n while n % 2 == 0:\n a.append(2)\n n //= 2\n f = 3\n while f * f <= n:\n if n % f == 0:\n a.append(f)\n n //= f\n else:\n f += 2\n if n != 1:\n a.append(n)\n return a\n if len(arr) == 0:\n arr.append((n, 1))\n return arr\n\n\nfac_ = prime_factorize(n)\nfac = Counter(fac_)\nans = 0\nfor p, e in fac.items():\n x = e\n for i in range(1, 99999999):\n if x >= i:\n x -= i\n ans += 1\n else:\n break\nprint(ans)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC169_D {\n public static void main(String[] args) {\n try (Scanner scanner = new Scanner(System.in)) {\n long n = scanner.nextLong();\n int sqrt = (int) Math.sqrt(n);\n int answer = 0;\n for (int i = 2; i <= sqrt; i++) {\n int count = 0;\n while (0 == (n % i)) {\n n /= i;\n count++;\n }\n for (int j = 1; count - j >= 0; j++) {\n count -= j;\n answer++;\n }\n }\n if (n > 1) {\n answer++;\n }\n System.out.println(answer);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "def resolve():\n n = int(input())\n low = []\n high = []\n for i in range(n):\n a, b = map(int, input().split())\n low.append(a)\n high.append(b)\n low.sort()\n high.sort()\n if n % 2:\n print(high[(n + 1) // 2 - 1] - low[(n + 1) // 2 - 1] + 1)\n else:\n hh = (high[(n) // 2 - 1] + high[(n) // 2]) / 2\n ll = (low[(n) // 2 - 1] + low[(n) // 2]) / 2\n print(int((hh - ll) * 2) + 1)\n\n\nif __name__ == \"__main__\":\n resolve()\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC169_E {\n public static void main(String[] args) throws Exception {\n int num = 998244353;\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n int n = Integer.parseInt(bf.readLine());\n ArrayList<Integer> ai = new ArrayList<Integer>();\n ArrayList<Integer> bi = new ArrayList<Integer>();\n for (int i = 0; i < n; i++) {\n StringTokenizer st = new StringTokenizer(bf.readLine());\n ai.add(Integer.parseInt(st.nextToken()));\n bi.add(Integer.parseInt(st.nextToken()));\n }\n Collections.sort(ai);\n Collections.sort(bi);\n if (n % 2 == 1) {\n out.println(bi.get(bi.size() / 2) - ai.get(ai.size() / 2) + 1);\n out.close();\n } else {\n double b = (ai.get(ai.size() / 2) + ai.get(ai.size() / 2 - 1) + 0.0) / 2;\n double c = (bi.get(bi.size() / 2) + bi.get(bi.size() / 2 - 1) + 0.0) / 2;\n out.println((int) (2 * (c - b) + 1));\n out.close();\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "a = list(map(int, input().split()))\nfor e, i in enumerate(a):\n if i == 0:\n print(e + 1)\n break\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\n\npublic class atcoder_ABC170_A {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n String[] input_array = br.readLine().split(\" \");\n int result = 0;\n for (String str : input_array) {\n result += 1;\n if (\"0\".equals(str)) break;\n }\n pw.println(result);\n br.close();\n pw.close();\n }\n}\n" } ]
[ { "role": "assistant", "content": "n, k = map(int, input().split())\nprint(sum(sorted(list(map(int, input().split())))[: k]))\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC171_B {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Solution sol = new Solution();\n sol.solve(in, out);\n out.close();\n }\n\n private static class Solution {\n private void solve(InputReader in, PrintWriter out) {\n int n = in.ni(), k = in.ni();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) a[i] = in.ni();\n Arrays.parallelSort(a);\n int ans = 0;\n for (int i = 0; i < k; ++i) ans += a[i];\n out.println(ans);\n }\n }\n\n private static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n private InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n private String n() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n private int ni() {\n return Integer.parseInt(n());\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "from functools import *\nfrom operator import *\nN = int(input())\na = list(map(int, input().split()))\ntotal = reduce(xor, a, 0)\nprint(\" \".join(list(map(lambda ai: str(ai ^ total), a))))\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC171_E {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] a = new int[n];\n int r = 0;\n for (int i = 0; i < n; i++) {\n a[i] = sc.nextInt();\n r ^= a[i];\n }\n for (int i = 0; i < n; i++) {\n if (i != 0) System.out.print(\" \");\n System.out.print(r ^ a[i]);\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\ndef rs(): return sys.stdin.readline().rstrip()\ndef ri(): return int(rs())\ndef rs_(): return [_ for _ in rs().split()]\ndef ri_(): return [int(_) for _ in rs().split()]\n\n\nN = ri()\nans = 0\nfor i in range(1, N + 1):\n ans += i * (N // i) * (N // i + 1) // 2\nprint(ans)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_ABC172_D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long ans = 0;\n for (int i = 1; i < n + 1; i++) {\n ans += (long) i * ((long) n / (long) i) * (((long) n / (long) i) + 1) / 2;\n }\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "from sys import stdin, stdout, setrecursionlimit\nfrom math import gcd, ceil, sqrt\nfrom collections import Counter\nfrom bisect import bisect_left, bisect_right\ndef ii1(): return int(stdin.readline().strip())\ndef is1(): return stdin.readline().strip()\n\n\ndef iia(): return list(map(int, stdin.readline().strip().split()))\ndef isa(): return stdin.readline().strip().split()\n\n\nsetrecursionlimit(100000)\nmod = 1000000007\nk = ii1()\nt = 0\nfor i in range(1, k + 1):\n t = (t % k) * 10 + 7\n if t % k == 0:\n print(i)\n break\nelse:\n print(- 1)\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC174_C {\n private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n private static final PrintWriter pw =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n private static StringTokenizer st;\n\n private static int readInt() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return Integer.parseInt(st.nextToken());\n }\n\n public static void main(String[] args) throws IOException {\n pw.println(solve());\n pw.close();\n }\n\n private static int solve() throws IOException {\n int K = readInt();\n if (K % 2 == 0 || K % 5 == 0) return -1;\n if (K % 7 == 0) K /= 7;\n K *= 9;\n int ans = 1;\n int remainder = 10 % K;\n while (remainder != 1) {\n ans++;\n remainder = remainder * 10 % K;\n }\n return ans;\n }\n}\n" } ]
[ { "role": "assistant", "content": "def check(lis, k, mid):\n for i in lis:\n if (i % mid == 0):\n k += 1\n k -= (i // mid)\n return k >= 0\n\n\nn, k = map(int, input().split())\nlis = list(map(int, input().split()))\na, b = 1, max(lis)\nans = b\nwhile (a <= b):\n mid = (a + b) // 2\n if (check(lis, k, mid)):\n ans = mid\n b = mid - 1\n else:\n a = mid + 1\nprint(ans)\n" }, { "role": "user", "content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class atcoder_ABC174_E {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Solution sol = new Solution();\n sol.solve(in, out);\n out.close();\n }\n\n private static class Solution {\n private void solve(InputReader in, PrintWriter out) {\n int n = in.nextInt(), k = in.nextInt();\n int[] logsLength = in.readArray(n);\n int min = 1, max = (int) 1e9 + 1000;\n while (min < max) {\n int mid = (min + max) / 2;\n if (nei(mid, logsLength, k)) max = mid;\n else min = mid + 1;\n }\n out.println(min);\n }\n\n private boolean nei(int mid, int[] logsLength, int k) {\n for (int log : logsLength) k -= (log + mid - 1) / mid - 1;\n return k >= 0;\n }\n }\n\n private static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n private InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n private String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n private int nextInt() {\n return Integer.parseInt(next());\n }\n\n private int[] readArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) a[i] = nextInt();\n return a;\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import os\nfrom sys import stdin, stdout\n\n\ndef solve(tc):\n a = int(stdin.readline().strip())\n print(1 if a == 0 else 0)\n\n\ntcs = 1\ntc = 1\nwhile tc <= tcs:\n solve(tc)\n tc += 1\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC178_A {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int x = Integer.parseInt(scan.next());\n boolean bool = x == 1 ? true : false;\n int result = !bool ? 1 : 0;\n PrintWriter out = new PrintWriter(System.out);\n out.println(result);\n out.flush();\n }\n}\n" } ]
[ { "role": "assistant", "content": "import math\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport bisect\nimport sys\nimport queue\nimport copy\nsys.setrecursionlimit(10 ** 7)\ninf = 10 ** 20\nmod = 10 ** 9 + 7\ndd = [(- 1, 0), (0, 1), (1, 0), (0, - 1)]\nddn = [(- 1, 0), (- 1, 1), (0, 1), (1, 1),\n (1, 0), (1, - 1), (0, - 1), (- 1, - 1)]\n\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\n\ndef main():\n a, b, c, d = LI()\n return max(a * c, b * d, a * d, b * c)\n\n\nprint(main())\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_ABC178_B {\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n static int modPower(int x, int y, int mod) {\n int res = 1;\n x %= mod;\n if (x == 0) return 0;\n while (y > 0) {\n if (y % 2 == 1) {\n res = (res * x) % mod;\n }\n y = y >> 1;\n x = (x * x) % mod;\n }\n return res;\n }\n\n static class pair<T1, T2> {\n T1 first;\n T2 second;\n\n pair(T1 first, T2 second) {\n this.first = first;\n this.second = second;\n }\n }\n\n public static void main(String[] args) throws java.lang.Exception {\n FastReader in = new FastReader();\n long[] a = new long[4];\n for (int i = 0; i < 4; i++) a[i] = in.nextLong();\n System.out.println(\n Math.max(a[0] * a[2], Math.max(a[1] * a[3], Math.max(a[0] * a[3], a[1] * a[2]))));\n }\n}\n" } ]
[ { "role": "assistant", "content": "import bisect\nimport collections\nimport copy\nimport heapq\nimport itertools\nimport math\nimport numpy\nimport string\nimport sys\ndef S(): return sys.stdin.readline().rstrip()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\n\na, b = LI()\nif a > 0:\n print('Positive')\nelif a <= 0 and b >= 0:\n print('Zero')\nelse:\n if (a + b) % 2 == 0:\n print('Negative')\n else:\n print('Positive')\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_AGC002_A {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int a = scanner.nextInt();\n int b = scanner.nextInt();\n if (a > 0) {\n System.out.println(\"Positive\");\n } else if (b >= 0) {\n System.out.println(\"Zero\");\n } else if ((b - a + 1) % 2 == 0) {\n System.out.println(\"Positive\");\n } else {\n System.out.println(\"Negative\");\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nimport re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import accumulate, permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left\nfrom fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(* (MAP() for _ in range(n)))\n\n\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\nN, M = MAP()\nballs = [[1, 0] for _ in range(N)]\nballs[0] = [0, 1]\nfor _ in range(M):\n x, y = MAP()\n w_x, r_x = balls[x - 1]\n w_y, r_y = balls[y - 1]\n if w_x >= 1 and r_x >= 1:\n balls[x - 1][0] -= 1\n balls[y - 1][1] += 1\n elif w_x == 0:\n balls[x - 1][1] -= 1\n balls[y - 1][1] += 1\n else:\n balls[x - 1][0] -= 1\n balls[y - 1][0] += 1\nans = 0\nfor i in range(N):\n if balls[i][1]:\n ans += 1\nprint(ans)\n" }, { "role": "user", "content": "import java.util.Scanner;\n\npublic class atcoder_AGC002_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int M = sc.nextInt();\n Box[] B = new Box[N];\n B[0] = new Box(1, true);\n for (int i = 1; i < N; i++) {\n B[i] = new Box(1, false);\n }\n for (int i = 0; i < M; i++) {\n int x = sc.nextInt() - 1;\n int y = sc.nextInt() - 1;\n B[x].moveTo(B[y]);\n }\n int counter = 0;\n for (Box b : B) {\n if (b.red) {\n counter++;\n }\n }\n System.out.println(counter);\n }\n}\n\nclass Box {\n public int num;\n public boolean red;\n\n public Box(int n, boolean r) {\n num = n;\n red = r;\n }\n\n public void moveTo(Box other) {\n if (num == 0) {\n return;\n } else if (num == 1) {\n num = 0;\n other.num++;\n if (red) {\n other.red = true;\n }\n red = false;\n } else {\n num--;\n other.num++;\n if (red) {\n other.red = true;\n }\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "N = int(input())\nA = [int(input()) * N + i for i in range(N)]\nA.sort()\ncnt = 0\nfor i in range(N):\n d = (A[i] % N) % 2\n if d % 2 != i % 2:\n cnt += 1\nprint(cnt // 2)\n" }, { "role": "user", "content": "import java.util.*;\n\npublic class atcoder_AGC003_C {\n static final int NUM = (int) (1e5 + 2);\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n HashMap<Integer, Integer> map = new HashMap<>();\n PriorityQueue<Integer> nums = new PriorityQueue<>();\n for (int i = 0; i < N; i++) {\n int tmp = sc.nextInt();\n nums.add(tmp);\n map.put(tmp, i);\n }\n int bin = 0;\n int diff = 0;\n while (!nums.isEmpty()) {\n int num = nums.poll();\n int idx = map.get(num);\n if ((bin % 2) != (idx % 2)) {\n diff++;\n }\n bin++;\n bin %= 2;\n }\n int ans = (diff / 2);\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "def main():\n n, x = map(int, input().split())\n a = list(map(int, input().split()))\n b = [[None for _ in [0] * n] for _ in [0] * n]\n for i in range(n):\n m = a[i]\n for j in range(n):\n k = i - j\n if k < 0:\n k += n\n m = min(m, a[k])\n b[j][i] = m\n m = 10 ** 15\n for i, j in enumerate(b):\n m = min(m, sum(j) + x * i)\n print(m)\n\n\nmain()\n" }, { "role": "user", "content": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class atcoder_AGC004_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt();\n long x = scan.nextLong();\n List<Long> srimeList = new ArrayList<>(N);\n for (long i = 0; i < N; i++) {\n srimeList.add(scan.nextLong());\n }\n List<Long[]> costList = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n costList.add(new Long[N]);\n }\n for (int i = 0; i < N; i++) {\n costList.get(i)[0] = srimeList.get(i);\n for (int castNum = 1; castNum < N; castNum++) {\n costList.get(i)[castNum] =\n Math.min(\n costList.get(i)[castNum - 1], srimeList.get((i - castNum + N) % N));\n }\n }\n List<Long> result = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n final int j = i;\n result.add(i * x + costList.stream().mapToLong(costArray -> costArray[j]).sum());\n }\n System.out.println(result.stream().mapToLong(i -> i).min().getAsLong());\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nsys.setrecursionlimit(10 ** 6)\n\n\ndef dfs(links, n, k, v, p):\n height_from_leaf = 0\n cut_count = 0\n for u in links[v]:\n if u == 0:\n continue\n hgt, cut = dfs(links, n, k, u, v)\n height_from_leaf = max(height_from_leaf, hgt)\n cut_count += cut\n height_from_leaf += 1\n if p != 0 and height_from_leaf == k:\n height_from_leaf = 0\n cut_count += 1\n return height_from_leaf, cut_count\n\n\nn, k, * aaa = map(int, sys.stdin.buffer.read().split())\nlinks = [set() for _ in range(n)]\nfor i, a in enumerate(aaa):\n a -= 1\n links[a].add(i)\n_, ans = dfs(links, n, k, 0, 0)\nif aaa[0] != 1:\n ans += 1\nprint(ans)\n" }, { "role": "user", "content": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class atcoder_AGC004_D {\n public static void main(String args[]) {\n new Thread(null, new MyRunnable(), \"\", 1 << 26).start();\n }\n}\n\nclass MyRunnable implements Runnable {\n @Override\n public void run() {\n int n;\n int k;\n List<Integer> as = new ArrayList<>();\n try (Scanner sc = new Scanner(System.in)) {\n n = sc.nextInt();\n k = sc.nextInt();\n for (int i = 0; i < n; i++) {\n as.add(sc.nextInt() - 1);\n }\n }\n System.out.println(new Calculator(n, k, as).calculate());\n }\n}\n\nclass Calculator {\n private int k;\n private int answer = 0;\n private boolean isCalculate = false;\n private List<List<Integer>> lists = new ArrayList<>();\n\n Calculator(int n, int k, List<Integer> as) {\n this.k = k;\n for (int i = 0; i < n; i++) {\n this.lists.add(new ArrayList<>());\n }\n for (int i = 0; i < n; i++) {\n int j = as.get(i);\n if (0 < i) {\n this.lists.get(j).add(i);\n } else if (0 < j) {\n this.answer++;\n }\n }\n }\n\n int calculate() {\n if (!this.isCalculate) {\n this.dfs(0, 0);\n this.isCalculate = true;\n }\n return this.answer;\n }\n\n private int dfs(int a, int pre) {\n int h = 0;\n for (int i : this.lists.get(a)) {\n h = Math.max(h, this.dfs(i, a));\n }\n if (0 < pre && h == this.k - 1) {\n h = 0;\n this.answer++;\n } else {\n h++;\n }\n return h;\n }\n}\n" } ]
[ { "role": "assistant", "content": "def root(x): return x if par[x] == x else root(par[x])\ndef same(x, y): return root(x) == root(y)\n\n\ndef unite(* z):\n x, y = map(root, z)\n if x != y:\n if rank[x] < rank[y]:\n par[x] = y\n size[y] += size[x]\n else:\n par[y] = x\n size[x] += size[y]\n if rank[x] == rank[y]:\n rank[x] += 1\n\n\nn, * a = map(int, open(0).read().split())\n* par, = range(n)\nrank = [1] * n\nsize = [1] * n\nb = [0] * n\nfor i, t in enumerate(a):\n b[t - 1] = i\nc = 0\nfor k in b[:: - 1]:\n l = r = 1\n if k > 0 and a[k - 1] > a[k]:\n l += size[root(k - 1)]\n unite(k - 1, k)\n if k + 1 < n and a[k + 1] > a[k]:\n r += size[root(k + 1)]\n unite(k + 1, k)\n c += l * r * a[k]\nprint(c)\n" }, { "role": "user", "content": "import java.util.ArrayDeque;\nimport java.util.Scanner;\n\npublic class atcoder_AGC005_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt();\n int[] a = new int[N];\n for (int i = 0; i < N; ++i) {\n a[i] = scan.nextInt();\n }\n int[] leftl = new int[N];\n int[] rightl = new int[N];\n ArrayDeque<Integer> que = new ArrayDeque<>();\n int index = 0;\n while (index < N) {\n while (!que.isEmpty() && a[que.peek()] > a[index]) {\n int ind = que.poll();\n rightl[ind] = index - ind - 1;\n }\n que.push(index++);\n }\n while (!que.isEmpty()) {\n int ind = que.poll();\n rightl[ind] = N - ind - 1;\n }\n index = N - 1;\n while (index >= 0) {\n while (!que.isEmpty() && a[que.peek()] > a[index]) {\n int ind = que.poll();\n leftl[ind] = ind - index - 1;\n }\n que.push(index--);\n }\n while (!que.isEmpty()) {\n int ind = que.poll();\n leftl[ind] = ind - index - 1;\n }\n long ans = 0;\n for (int i = 0; i < N; ++i) {\n ans += (long) a[i] * (leftl[i] + 1) * (rightl[i] + 1);\n }\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "n = int(input())\ns = list(input())\nt = list(input())\nif s == t:\n print(n)\nelse:\n cnt = 0\n for i in range(n):\n for j in range(n - i):\n if s[i + j] != t[j]:\n break\n if j == n - i - 1:\n cnt = n - i\n print(2 * n - cnt)\n" }, { "role": "user", "content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_AGC006_A {\n static int N = 200 + 10;\n static int f[] = new int[N];\n static char b[] = new char[N];\n\n static void getFail(char b[], int m) {\n int j = 0;\n f[0] = f[1] = 0;\n for (int i = 2; i <= m; i++) {\n while (j > 0 && b[j + 1] != b[i]) j = f[j];\n if (b[j + 1] == b[i]) j++;\n f[i] = j;\n }\n }\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = in.nextInt();\n String s1 = in.next(), str = in.next();\n int cnt = 0;\n for (int i = 0; i < n; i++) b[++cnt] = str.charAt(i);\n for (int i = 0; i < n; i++) b[++cnt] = s1.charAt(i);\n getFail(b, cnt);\n int len = Math.min(f[cnt], Math.min(n, n));\n out.println(2 * n - len);\n out.flush();\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n" } ]
[ { "role": "assistant", "content": "from itertools import permutations\nN, X = [int(_) for _ in input().split()]\n\n\ndef calc(x):\n def sub(y, debug=0):\n if debug:\n print(\"D\", y)\n while len(y) > 1:\n y = [sorted(y[i: i + 3])[1] for i in range(len(y) - 2)]\n if debug:\n print(\"D\", y)\n return y\n y = sub(x)\n if y[0] == 2:\n pass\n sub(x, 1)\n print(\"=\", x)\n return y[0]\n\n\nif X == 1 or X == N * 2 - 1:\n print(\"No\")\nelse:\n print(\"Yes\")\n if X == N * 2 - 2:\n xs = list(range(N - 1, X + 2)) + list(range(1, N - 1))\n else:\n ys = list(range(1, X - 1)) + list(range(X + 3, N * 2))\n xs = ys[: N - 3] + [X + 2, X - 1, X, X + 1] + ys[N - 3:]\n for x in xs:\n print(x)\n" }, { "role": "user", "content": "import java.util.Scanner;\nimport java.util.stream.IntStream;\n\npublic class atcoder_AGC006_B {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int x = scanner.nextInt();\n print(x, n);\n }\n\n public static void print(int x, int n) {\n int max = n * 2 - 1;\n if (x == 1 || x == max) {\n System.out.println(\"No\");\n return;\n }\n System.out.println(\"Yes\");\n String sep = System.lineSeparator();\n String ans =\n IntStream.range(x + n - 1, x + n + max - 1)\n .mapToObj(e -> (e % max + 1) + sep)\n .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)\n .toString();\n System.out.println(ans);\n }\n}\n" } ]
[ { "role": "assistant", "content": "import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nN, d, x = map(int, read().split())\n\n\ndef main(N, d, x):\n ret = 0\n while N:\n ret += d + (N - 0.5) * x\n d = d + (d / N) + (5 * x) / (2 * N)\n x += 2 * x / N\n N -= 1\n return ret\n\n\nprint(main(N, d, x))\n" }, { "role": "user", "content": "import java.math.BigDecimal;\nimport java.text.DecimalFormat;\nimport java.util.Scanner;\n\npublic class atcoder_AGC007_C {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n double N = scan.nextDouble();\n double d = scan.nextDouble();\n double x = scan.nextDouble();\n BigDecimal ans = new BigDecimal(\"0.0\");\n while (N > 0.5) {\n BigDecimal adnum = BigDecimal.valueOf(d + x * (N - 0.5));\n ans = ans.add(adnum);\n d = (N + 1.0) * d / N + (5.0 * x) / (2.0 * N);\n x = (1.0 + (2.0 / N)) * x;\n --N;\n }\n DecimalFormat format = new DecimalFormat(\"#.#\");\n format.setMinimumFractionDigits(20);\n System.out.println(format.format(ans));\n }\n}\n" } ]
README.md exists but content is empty.
Downloads last month
29