messages
listlengths 2
2
|
---|
[
{
"role": "assistant",
"content": "n, a = int(input()), list(map(int, input().split()))\nif sum(a) % (n * (n + 1) / 2):\n print(\"NO\")\nelse:\n k = sum(a) / (n * (n + 1) / 2)\n a += [a[0]]\n if sum([(k - i + j) % n for i, j in zip(a[1:], a)]) or sum([(k - i + j) / n >= 0 for i, j in zip(a[1:], a)]) != n:\n print(\"NO\")\n else:\n print(\"YES\")\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class atcoder_AGC010_B {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int N = scanner.nextInt();\n int[] A = new int[N];\n for (int i = 0; i < N; i++) A[i] = scanner.nextInt();\n if (possible(N, A)) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n private static boolean possible(int N, int[] A) {\n long sum = 0;\n for (int i = 0; i < N; i++) sum += A[i];\n long NS = (long) N * (N + 1) / 2;\n if (sum % NS != 0) return false;\n long K = sum / NS;\n for (int i = 0; i < N; i++) {\n int j = i == 0 ? N - 1 : i - 1;\n long d = K - (A[i] - A[j]);\n if (d < 0 || d % N != 0) return false;\n }\n return true;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import queue\nn, m = map(int, input().split())\nvis, ci, cb, cc = [0] * (n + 1), 0, 0, 0\ng = [[] for i in range(n + 1)]\n\n\ndef dfs(x):\n stk, flag = queue.LifoQueue(), True\n stk.put((x, 1))\n while not stk.empty():\n u, col = stk.get()\n if vis[u]:\n flag &= (vis[u] == col)\n continue\n vis[u] = col\n for i in g[u]:\n stk.put((i, 3 - col))\n return flag\n\n\nfor i in range(m):\n u, v = map(int, input().split())\n g[u] += [v]\n g[v] += [u]\nfor i in range(1, n + 1):\n if vis[i] == 0:\n if len(g[i]) == 0:\n ci += 1\n else:\n if dfs(i):\n cb += 1\n else:\n cc += 1\nprint(ci * ci + 2 * ci * (n - ci) + cc * cc + 2 * cb * cc + 2 * cb * cb)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\nclass atcoder_AGC011_C implements Runnable {\n ArrayList<Integer>[] graph;\n boolean[] visited;\n int[] color;\n long one;\n long bipartite;\n long count;\n boolean mujun;\n\n int dfs(int a, int c) {\n if (visited[a]) {\n if (color[a] >= 0 && color[a] != c) mujun = true;\n return 0;\n }\n visited[a] = true;\n color[a] = c;\n int total = 1;\n for (int b : graph[a]) {\n total += dfs(b, 1 - c);\n }\n return total;\n }\n\n public void run() {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int m = scan.nextInt();\n this.graph = new ArrayList[n];\n for (int i = 0; i < n; ++i) this.graph[i] = new ArrayList<Integer>();\n for (int i = 0; i < m; ++i) {\n int u = scan.nextInt() - 1;\n int v = scan.nextInt() - 1;\n this.graph[u].add(v);\n this.graph[v].add(u);\n }\n visited = new boolean[n];\n color = new int[n];\n Arrays.fill(color, -1);\n one = 0;\n bipartite = 0;\n count = 0;\n for (int i = 0; i < n; ++i) {\n if (visited[i]) continue;\n count++;\n mujun = false;\n int kind = dfs(i, 0);\n if (kind == 1) one++;\n else if (!mujun) bipartite++;\n }\n long total = one * (2 * n - one);\n total += (count - one) * (count - one);\n total += bipartite * bipartite;\n System.out.println(total);\n }\n\n public static void main(String[] args) {\n new Thread(null, new atcoder_AGC011_C(), \"\", 128 * 1024 * 1024).start();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from statistics import median\nfrom fractions import gcd\nfrom itertools import combinations\nfrom collections import deque\nfrom collections import defaultdict\nimport bisect\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10 ** 9 + 7\n\n\ndef readInts():\n return list(map(int, input().split()))\n\n\ndef main():\n n = int(input())\n A = readInts()\n A = sorted(A)\n ans = 0\n for i in range(len(A) - 2, len(A) - 2 * n - 1, - 2):\n ans += A[i]\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"
},
{
"role": "user",
"content": "import static java.lang.Math.*;\n\nimport java.util.*;\n\npublic class atcoder_AGC012_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] array = new int[3 * n];\n for (int i = 0; i < array.length; i++) array[i] = sc.nextInt();\n Arrays.sort(array);\n int head = array.length - 2;\n long res = 0;\n for (int i = 0; i < n; i++) {\n res += array[head];\n head -= 2;\n }\n System.out.println(res);\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 groupby, 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 = INT()\nA = LIST()\nA = [k for k, g in groupby(A)]\nN = len(A)\ni = 1\nans = 0\nwhile i < N - 1:\n if A[i - 1] < A[i] > A[i + 1] or A[i - 1] > A[i] < A[i + 1]:\n ans += 1\n i += 1\n i += 1\nprint(ans + 1)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_AGC013_A {\n public static void main(String[] args) {\n Scanner stdIn = new Scanner(System.in);\n int N = stdIn.nextInt();\n int[] A = new int[N];\n for (int i = 0; i < N; i++) {\n A[i] = stdIn.nextInt();\n }\n int count = 0;\n for (int i = 0; i < N; i++) {\n if (i == N - 1) count++;\n else if (A[i] == A[i + 1])\n ;\n else if (A[i] < A[i + 1]) {\n while (A[i] <= A[i + 1]) {\n i++;\n if (i == N - 1) break;\n }\n count++;\n } else {\n while (A[i] >= A[i + 1]) {\n i++;\n if (i == N - 1) break;\n }\n count++;\n }\n }\n System.out.println(count);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\nfrom collections import deque\ninput = sys.stdin.buffer.readline\nN = int(input())\nadj = [[] for _ in range(N + 1)]\nfor _ in range(N - 1):\n a, b = map(int, input().split())\n adj[a].append(b)\n adj[b].append(a)\nque = deque()\nque.append(1)\nseen = [0] * (N + 1)\nseen[1] = 1\npar = [0] * (N + 1)\nchild_num = [0] * (N + 1)\nwhile que:\n v = que.popleft()\n for u in adj[v]:\n if seen[u] == 0:\n seen[u] = 1\n par[u] = v\n child_num[v] += 1\n que.append(u)\nseq = deque()\nfor i in range(1, N + 1):\n if child_num[i] == 0:\n seq.append(i)\nwhile seq:\n c = seq.pop()\n seen[c] = 0\n if seen[par[c]] == 0:\n print('First')\n exit()\n seen[par[c]] = 0\n child_num[par[par[c]]] -= 1\n if child_num[par[par[c]]] == 0:\n seq.append(par[par[c]])\nprint('Second')\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_AGC014_D {\n static ArrayList<Integer>[] g;\n\n static int maxMatching(int v, int p) {\n int a = 0;\n int o = 0;\n for (int w : g[v]) {\n if (w == p) continue;\n int r = maxMatching(w, v);\n a += r / 2;\n o += r % 2;\n }\n return 2 * a + Math.min(1, o) + 1;\n }\n\n @SuppressWarnings(\"unchecked\")\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n int n = sc.nextInt();\n g = new ArrayList[n];\n Arrays.setAll(g, x -> new ArrayList<Integer>());\n for (int i = 0; i < n - 1; ++i) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n g[a].add(b);\n g[b].add(a);\n }\n int m = maxMatching(0, -1) / 2;\n out.println(2 * m == n ? \"Second\" : \"First\");\n out.close();\n }\n\n public static PrintWriter out;\n\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\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 (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "N, P = map(int, input().split())\n\n\ndef combi(N, K):\n a = 1\n for i in range(K):\n a *= N - i\n for j in range(K):\n a /= j + 1\n return a\n\n\nans = 0\nlis = list(map(int, input().split()))\nls = []\nfor a in lis:\n ls.append(a % 2)\none = ls.count(1)\nzero = ls.count(0)\npattern_a = 0\npattern_b = 0\nfor j in range(zero + 1):\n pattern_b += combi(zero, j)\ntime = 0\nwhile time <= one:\n if time % 2 == P:\n pattern_a += combi(one, time)\n time += 1\nprint(int(pattern_a * pattern_b))\n"
},
{
"role": "user",
"content": "import java.math.*;\nimport java.util.*;\n\npublic class atcoder_AGC017_A {\n static BigInteger C(int n, int m) {\n BigInteger res = new BigInteger(\"1\");\n for (int i = m - n + 1; i <= m; i++) res = res.multiply(BigInteger.valueOf(i));\n for (int i = 1; i <= n; i++) res = res.divide(BigInteger.valueOf(i));\n return res;\n }\n\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int n, p;\n int k0 = 0;\n int k1 = 0;\n n = sc.nextInt();\n p = sc.nextInt();\n for (int i = 0; i < n; i++) {\n int x;\n x = sc.nextInt();\n if (x % 2 == 1) k1++;\n else k0++;\n }\n BigInteger ans = new BigInteger(\"1\");\n for (int i = 0; i < k0; i++) ans = ans.multiply(BigInteger.valueOf(2));\n if (p == 0) {\n BigInteger add = new BigInteger(\"0\");\n for (int i = 0; i <= k1; i += 2) add = add.add(C(i, k1));\n ans = ans.multiply(add);\n System.out.println(ans);\n } else {\n BigInteger add = new BigInteger(\"0\");\n for (int i = 1; i <= k1; i += 2) add = add.add(C(i, k1));\n ans = ans.multiply(add);\n System.out.println(ans);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\nimport re\nfrom collections import deque, defaultdict, Counter\nfrom math import sqrt, hypot, factorial, pi, sin, cos, radians\nif sys.version_info.minor >= 5:\n from math import gcd\nelse:\n from fractions import gcd\nfrom heapq import heappop, heappush, heapify, heappushpop\nfrom bisect import bisect_left, bisect_right\nfrom itertools import permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom functools import reduce, partial\nfrom fractions import Fraction\nfrom string import ascii_lowercase, ascii_uppercase, digits\ndef input(): return sys.stdin.readline().strip()\ndef ceil(a, b=1): return int(- (- a // b))\ndef round(x): return int((x * 2 + 1) // 2)\ndef fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD\ndef lcm(x, y): return (x * y) // gcd(x, y)\ndef lcm_list(nums): return reduce(lcm, nums, initial=1)\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\n\n\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\nq, h, s, d = MAP()\nn = INT()\nbest1L = min(q * 4, h * 2, s)\nbest2L = min(d, best1L * 2)\nif n % 2 == 0:\n print(best2L * (n // 2))\nelse:\n print(best2L * (n // 2) + best1L)\n"
},
{
"role": "user",
"content": "import static java.lang.System.*;\n\nimport java.util.*;\n\npublic class atcoder_AGC019_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long Q = sc.nextLong();\n long H = sc.nextLong();\n long S = sc.nextLong();\n long D = sc.nextLong();\n long N = sc.nextLong();\n long onePrice = Math.min(Math.min(Q * 4, H * 2), S);\n if ((double) onePrice <= (double) D / 2) {\n out.println(N * onePrice);\n } else {\n out.println((N / 2) * D + (N % 2) * onePrice);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from math import atan2, pi\nN, * XY = map(int, open(0).read().split())\nXY = list(zip(* [iter(XY)] * 2))\nfor i, (x, y) in enumerate(XY):\n D = sorted(atan2(X - x, Y - y) for j, (X, Y) in enumerate(XY) if j != i)\n D.append(D[0] + 2 * pi)\n ans = 0\n for a, b in zip(D, D[1:]):\n if b - a >= pi:\n ans = (b - a) - pi\n print(ans / (2 * pi))\n"
},
{
"role": "user",
"content": "import java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class atcoder_AGC021_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt();\n int[] x = new int[N];\n int[] y = new int[N];\n for (int i = 0; i < N; ++i) {\n x[i] = scan.nextInt();\n y[i] = scan.nextInt();\n }\n for (int i = 0; i < N; ++i) {\n List<Double> thetas = new ArrayList<>();\n for (int j = 0; j < N; ++j) {\n if (i == j) continue;\n thetas.add(Math.atan2(y[j] - y[i], x[j] - x[i]));\n }\n thetas.sort(Comparator.naturalOrder());\n thetas.add(thetas.get(0) + 2 * Math.PI);\n double ans = 0;\n for (int k = 0; k < N - 1; ++k)\n ans = Math.max(ans, thetas.get(k + 1) - thetas.get(k) - Math.PI);\n System.out.println(ans / (Math.PI * 2));\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def main():\n N = int(input())\n P = [int(input()) for _ in range(N)]\n editorial(N, P)\n\n\ndef editorial(N, P):\n if N == 1:\n print(0)\n return\n a = [0] * (N + 1)\n for i, p in enumerate(P):\n a[p] = i\n tmp = 1\n max_len = 1\n for i in range(1, N):\n if a[i] < a[i + 1]:\n tmp += 1\n max_len = max(max_len, tmp)\n else:\n tmp = 1\n ans = N - max_len\n print(ans)\n\n\ndef WA(N, P):\n tmp = 0\n ans = 0\n for i, p in enumerate(P):\n if i == 0 or P[i - 1] + 1 == p:\n tmp += 1\n else:\n ans = max(ans, tmp)\n tmp = 1\n print(N - ans)\n\n\nif __name__ == '__main__':\n main()\n"
},
{
"role": "user",
"content": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class atcoder_AGC024_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt();\n int[] P = new int[N];\n for (int i = 0; i < N; ++i) P[i] = scan.nextInt() - 1;\n Map<Integer, Integer> map = new HashMap<>();\n for (int i = 0; i < N; ++i) map.put(P[i], i);\n List<Integer> nglist = new ArrayList<>();\n for (int i = 0; i < N - 1; ++i) if (map.get(i) > map.get(i + 1)) nglist.add(i);\n if (nglist.isEmpty()) {\n System.out.println(0);\n return;\n }\n int ans = Math.min(N - nglist.get(0) - 1, nglist.get(nglist.size() - 1) + 1);\n for (int i = 0; i < nglist.size() - 1; ++i) {\n ans = Math.min(nglist.get(i) + 1 + N - nglist.get(i + 1) - 1, ans);\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = input()\na = [\"10\", \"100\", \"1000\", \"10000\", \"100000\"]\nnew = sum(list(map(int, n)))\nif n in a:\n print(10)\nelse:\n print(new)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class atcoder_AGC025_A {\n public static int sum(int a) {\n int ans = 0;\n while (a >= 10) {\n ans += a % 10;\n a /= 10;\n }\n ans += a;\n return ans;\n }\n\n public static void main(String[] args) {\n Scanner stdIn = new Scanner(System.in);\n int N = stdIn.nextInt();\n int n = 0;\n if (N % 2 == 0) {\n n = N / 2;\n } else {\n n = (N + 1) / 2;\n }\n int ans = sum(1) + sum(N - 1);\n for (int A = 1; A <= n; A++) {\n if (sum(A) + sum(N - A) < ans) {\n ans = sum(A) + sum(N - A);\n }\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def na(): return list(map(int, input().split()))\n\n\nn, x = na()\na = sorted(na())\nans = 0\nif a[0] > x:\n print(0)\n exit()\nfor i in a:\n if i > x:\n x = 0\n break\n x -= i\n ans += 1\nif x != 0:\n ans -= 1\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_AGC027_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n long x = sc.nextInt();\n List<Long> sweet = new ArrayList<Long>();\n for (int i = 0; i < N; i++) {\n long a = sc.nextInt();\n sweet.add(a);\n }\n Collections.sort(sweet);\n int num = 0;\n for (int i = 0; i < N; i++) {\n if (x - sweet.get(num) >= 0) {\n x = x - sweet.get(num);\n num++;\n } else {\n break;\n }\n }\n if ((num == N) && (x > 0)) {\n num -= 1;\n }\n System.out.println(num);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from itertools import accumulate\nN, X, * A = map(int, open(0).read().split())\nS = list(accumulate(A))\nans = float(\"inf\")\nfor k, s in enumerate(S, 1):\n E = k * X + 2 * sum(S[j] for j in range(N - 2 * k - 1, - 1, - k))\n ans = min(ans, E)\nprint(ans + N * X + 5 * S[- 1])\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_AGC027_B {\n int INF = Integer.MAX_VALUE;\n\n public static void main(String[] args) {\n new atcoder_AGC027_B().solve();\n }\n\n void solve() {\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n long X = sc.nextLong();\n long[] x = new long[N];\n long[] xsum = new long[N + 1];\n for (int i = 0; i < N; i++) {\n x[i] = sc.nextInt();\n xsum[i + 1] = xsum[i] + x[i];\n }\n long ans = X * N + 5 * xsum[N];\n for (int i = 1; i < N; i++) {\n long cost = X * i + 5 * (xsum[N] - xsum[N - i]);\n for (int j = 5, k = N - i; k >= 0; j += 2, k -= i) {\n if (cost > ans) {\n break;\n }\n cost += j * (xsum[k] - xsum[Math.max(k - i, 0)]);\n }\n ans = Math.min(ans, cost);\n }\n System.out.println(ans + N * X);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "N, M = map(int, input().split())\nS = input()\nT = input()\nlist_S = list(S)\nlist_T = list(T)\nNumber_i = [i for i in range(N)]\nNumber_iMN = []\nfor i in Number_i:\n Number_iMN.append(i * M / N)\nNumber_j = [j for j in range(M)]\nKaburi_j = list(set(Number_iMN) & set(Number_j))\nKaburi_i = []\nfor j in Kaburi_j:\n Kaburi_i.append(int(j * N / M))\ncounter = 0\nFlag = 0\nKaburi_Size = len(Kaburi_i)\nwhile counter <= Kaburi_Size - 1:\n if list_S[int(Kaburi_i[counter])] == list_T[int(Kaburi_j[counter])]:\n pass\n else:\n Flag = 1\n break\n counter += 1\n\n\ndef gcd(a, b):\n while b > 0:\n a, b = b, a % b\n return a\n\n\nif Flag == 1:\n print(- 1)\nelse:\n print(int(N * M / gcd(N, M)))\n"
},
{
"role": "user",
"content": "import java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class atcoder_AGC028_A {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] $) {\n int n = scanner.nextInt(),\n m = scanner.nextInt(),\n gcd = BigInteger.valueOf(n).gcd(BigInteger.valueOf(m)).intValue();\n String s = scanner.next(), t = scanner.next();\n System.out.println(\n IntStream.range(0, gcd)\n .filter(k -> s.charAt(k * n / gcd) != t.charAt(k * m / gcd))\n .mapToLong(k -> -1)\n .findAny()\n .orElse(\n BigInteger.valueOf(n)\n .multiply(BigInteger.valueOf(m))\n .divide(BigInteger.valueOf(gcd))\n .longValue()));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import numpy as np\nimport sys\ninput = sys.stdin.readline\nMOD = 10 ** 9 + 7\nN = int(input())\nM = 10 ** 6\nA = np.array(input().split(), dtype=np.int64)\nNsq = 10 ** 3\nfact = np.arange(M, dtype=np.int64).reshape(Nsq, Nsq)\nfact[0, 0] = 1\nfor n in range(1, Nsq):\n fact[:, n] *= fact[:, n - 1]\n fact[:, n] %= MOD\nfor n in range(1, Nsq):\n fact[n] *= fact[n - 1, - 1]\n fact[n] %= MOD\nfact = fact.ravel()\nj = np.arange(N)\ninv = np.array([pow(i + 1, MOD - 2, MOD) for i in range(N)])\ninv = np.cumsum(inv) % MOD\ntemp = inv[j] + inv[N - 1 - j] - 1\nans = (A * temp % MOD).sum()\nans %= MOD\nans *= fact[N]\nans %= MOD\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class atcoder_AGC028_B {\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n String[] sa = br.readLine().split(\" \");\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = Integer.parseInt(sa[i]);\n }\n br.close();\n int mod = 1000000007;\n long p = 1;\n for (int i = 2; i <= n; i++) {\n p = p * i % mod;\n }\n long[] q = new long[n];\n q[0] = 1;\n for (int i = 1; i < n; i++) {\n q[i] = (q[i - 1] + modinv(i + 1, mod)) % mod;\n }\n long ans = 0;\n for (int i = 0; i < n; i++) {\n long val = q[i] + q[n - i - 1] - 1;\n val *= a[i];\n val %= mod;\n val *= p;\n val %= mod;\n ans += val;\n ans %= mod;\n }\n System.out.println(ans);\n }\n\n static long modinv(long a, int m) {\n long b = m;\n long u = 1;\n long v = 0;\n long tmp = 0;\n while (b > 0) {\n long t = a / b;\n a -= t * b;\n tmp = a;\n a = b;\n b = tmp;\n u -= t * v;\n tmp = u;\n u = v;\n v = tmp;\n }\n u %= m;\n if (u < 0) u += m;\n return u;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import random\ninput()\nA = [int(_) for _ in input().split()]\nA = [A[0]] + [j for i, j in zip(A, A[1:]) if i >= j]\nN = len(A)\n\n\ndef cut(array, index):\n if index < 1:\n return []\n if index <= array[0][0]:\n return [(index, array[0][1])]\n for _ in range(len(array) - 1, 0, - 1):\n if array[_ - 1][0] < index:\n return array[: _] + [(index, array[_][1])]\n\n\ndef is_possible(K):\n dp = [(A[0], 0)]\n for a in A[1:]:\n if a <= dp[- 1][0]:\n dp = cut(dp, a)\n else:\n dp += [(a, 0)]\n is_added = False\n for j in range(len(dp) - 1, - 1, - 1):\n if dp[j][1] < K - 1:\n dp = cut(dp, dp[j][0] - 1) + [(dp[j][0], dp[j][1] + 1)]\n if dp[- 1][0] < a:\n dp += [(a, 0)]\n is_added = True\n break\n if not is_added:\n return False\n return True\n\n\ndef bis(x, y):\n if y == x + 1:\n return y\n elif is_possible((x + y) // 2):\n return bis(x, (x + y) // 2)\n else:\n return bis((x + y) // 2, y)\n\n\nprint(bis(0, N))\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.TreeMap;\n\npublic class atcoder_AGC029_C {\n private int n;\n private int[] a;\n private TreeMap<Integer, Integer> s;\n\n public static void main(String[] args) {\n atcoder_AGC029_C m = new atcoder_AGC029_C();\n m.solve();\n }\n\n private void set() {\n try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\n n = Integer.parseInt(br.readLine());\n a = Arrays.stream(br.readLine().split(\" \")).mapToInt(Integer::parseInt).toArray();\n s = new TreeMap<>();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private void solve() {\n set();\n int ng = 0;\n int ok = n;\n while (ok - ng > 1) {\n int k = (ng + ok) / 2;\n if (isPossible(k)) {\n ok = k;\n } else {\n ng = k;\n }\n }\n System.out.println(ok);\n }\n\n private boolean isPossible(int k) {\n s.clear();\n int current = 0;\n for (int ai : a) {\n if (ai <= current) {\n if (k == 1) return false;\n while (!s.isEmpty() && s.lastKey() >= ai) s.pollLastEntry();\n int p = ai - 1;\n while (true) {\n if (p < 0) return false;\n int sp = s.getOrDefault(p, 0) + 1;\n s.put(p, sp);\n if (sp == k) {\n s.remove(p);\n p--;\n } else {\n break;\n }\n }\n }\n current = ai;\n }\n return true;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import numpy as np\nh, w = map(int, input().split())\ngraph = [[0 if i == '#' else float('inf')\n for i in list(input())] for _ in range(h)]\ngraph = np.array(graph)\nfor x in range(w - 1):\n graph[:, x + 1] = np.minimum(graph[:, x] + 1, graph[:, x + 1])\nfor x in range(w - 1, 0, - 1):\n graph[:, x - 1] = np.minimum(graph[:, x] + 1, graph[:, x - 1])\nfor y in range(h - 1):\n graph[y + 1, :] = np.minimum(graph[y, :] + 1, graph[y + 1, :])\nfor y in range(h - 1, 0, - 1):\n graph[y - 1, :] = np.minimum(graph[y, :] + 1, graph[y - 1, :])\nprint(int(np.max(graph)))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_AGC033_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int H = sc.nextInt();\n int W = sc.nextInt();\n char[][] A = new char[H][W];\n Queue<int[]> queue = new ArrayDeque<int[]>();\n for (int i = 0; i < H; i++) {\n String row = sc.next();\n for (int j = 0; j < W; j++) {\n A[i][j] = row.charAt(j);\n if (A[i][j] == '#') {\n int[] start = {i, j, 0};\n queue.add(start);\n }\n }\n }\n int[][] flag = new int[H][W];\n int ans = 0;\n int[] dx = {1, -1, 0, 0};\n int[] dy = {0, 0, 1, -1};\n loop:\n while (!queue.isEmpty()) {\n int[] temp = queue.remove();\n int y = temp[0];\n int x = temp[1];\n int depth = temp[2];\n for (int i = 0; i < 4; i++) {\n if (0 <= y + dy[i] && y + dy[i] <= H - 1 && 0 <= x + dx[i] && x + dx[i] <= W - 1) {\n if (flag[y + dy[i]][x + dx[i]] == 0 && A[y + dy[i]][x + dx[i]] == '.') {\n flag[y + dy[i]][x + dx[i]] = 1;\n int[] queue_add = {y + dy[i], x + dx[i], depth + 1};\n queue.add(queue_add);\n ans = depth + 1;\n }\n }\n }\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "H, W, N = map(int, input().split())\ns_r, s_c = map(int, input().split())\nS = input()\nT = input()\nJudge = False\nS_L, S_R, S_U, S_D = 0, 0, 0, 0\nT_L, T_R, T_U, T_D = 0, 0, 0, 0\nfor x in range(N):\n if S[x] == 'L':\n S_L += 1\n if S_L - T_R - s_c == 0:\n Judge = True\n elif S[x] == 'R':\n S_R += 1\n if s_c + (S_R - T_L) == W + 1:\n Judge = True\n elif S[x] == 'U':\n S_U += 1\n if S_U - T_D - s_r == 0:\n Judge = True\n elif S[x] == 'D':\n S_D += 1\n if s_r + (S_D - T_U) == H + 1:\n Judge = True\n if T[x] == 'L':\n if S_R - T_L + s_c != 1:\n T_L += 1\n if T[x] == 'R':\n if s_c + (T_R - S_L) != W:\n T_R += 1\n if T[x] == 'U':\n if S_D - T_U + s_r != 1:\n T_U += 1\n if T[x] == 'D':\n if s_r + (T_D - S_U) != H:\n T_D += 1\nif Judge:\n print('NO')\nelse:\n print('YES')\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_AGC033_B {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int h = scanner.nextInt();\n int w = scanner.nextInt();\n int n = scanner.nextInt();\n int sr = scanner.nextInt();\n int sc = scanner.nextInt();\n String s = scanner.next();\n String t = scanner.next();\n boolean end = false;\n int usafe = 1;\n int dsafe = h;\n for (int i = n - 1; i >= 0; i--) {\n if (s.charAt(i) == 'U') {\n usafe++;\n } else if (s.charAt(i) == 'D') {\n dsafe--;\n }\n if (usafe > dsafe) {\n end = true;\n break;\n }\n if (i > 0) {\n if (t.charAt(i - 1) == 'U') {\n dsafe = Math.min(dsafe + 1, h);\n } else if (t.charAt(i - 1) == 'D') {\n usafe = Math.max(usafe - 1, 1);\n }\n }\n }\n int lsafe = 1;\n int rsafe = w;\n for (int i = n - 1; i >= 0; i--) {\n if (s.charAt(i) == 'L') {\n lsafe++;\n } else if (s.charAt(i) == 'R') {\n rsafe--;\n }\n if (lsafe > rsafe) {\n end = true;\n break;\n }\n if (i > 0) {\n if (t.charAt(i - 1) == 'L') {\n rsafe = Math.min(rsafe + 1, w);\n } else if (t.charAt(i - 1) == 'R') {\n lsafe = Math.max(lsafe - 1, 1);\n }\n }\n }\n if (sr >= usafe && sr <= dsafe && sc >= lsafe && sc <= rsafe && !end) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\nimport math\nimport collections\nimport heapq\nimport itertools\n\n\ndef gcd(a, b):\n a, b = max(a, b), min(a, b)\n while a % b > 0:\n a, b = b, a % b\n return b\n\n\ndef solve():\n s = input()\n t = \"\"\n i = 0\n while i < len(s):\n if s[i] == \"A\":\n t += \"A\"\n i += 1\n elif s[i] == \"B\":\n if i < len(s) - 1:\n if s[i + 1] == \"C\":\n t += \"D\"\n i += 2\n else:\n t += \"X\"\n i += 1\n else:\n t += \"X\"\n i += 1\n else:\n t += \"X\"\n i += 1\n total = 0\n numA = 0\n for i in range(len(t)):\n if t[i] == \"X\":\n numA = 0\n else:\n if t[i] == \"A\":\n numA += 1\n else:\n total += numA\n print(total)\n INF = 10 ** 25\n mod = 7 + 10 ** 9\n return 0\n\n\nif __name__ == \"__main__\":\n solve()\n"
},
{
"role": "user",
"content": "import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class atcoder_AGC034_B {\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 BABC solver = new BABC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BABC {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n String s = in.next().replaceAll(\"BC\", \"D\");\n long cnt = 0;\n long tmp = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == 'A') {\n tmp++;\n } else if (s.charAt(i) == 'D') {\n cnt += tmp;\n } else {\n tmp = 0;\n }\n }\n out.println(cnt);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import numpy as np\nfrom collections import deque\nimport heapq\nN, M = map(int, input().split())\nedges = [set() for _ in range(N)]\ndegs = [0 for i in range(N)]\nparity = [0 for _ in range(N)]\nflag = [False for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n edges[a - 1].add(b - 1)\n edges[b - 1].add(a - 1)\n degs[a - 1] += 1\n degs[b - 1] += 1\nif M % 2 != 0:\n print(- 1)\n exit()\nQ = []\nfor i, d in enumerate(degs):\n Q.append((d, i))\nheapq.heapify(Q)\nwhile len(Q) > 0:\n _, u = Q[0]\n heapq.heappop(Q)\n if flag[u]:\n continue\n flag[u] = True\n for i, v in enumerate(edges[u]):\n edges[v].remove(u)\n if parity[u] != 0 and i == 0:\n print(u + 1, v + 1)\n parity[u] = 1 - parity[u]\n else:\n print(v + 1, u + 1)\n parity[v] = 1 - parity[v]\n degs[v] -= 1\n heapq.heappush(Q, (degs[v], v))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_AGC035_B {\n @SuppressWarnings(\"unchecked\")\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numNode = sc.nextInt();\n int numEdge = sc.nextInt();\n connect = new ArrayList[numNode];\n for (int i = 0; i < numNode; i++) {\n connect[i] = new ArrayList<>();\n }\n for (int i = 0; i < numEdge; i++) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n connect[a].add(b);\n connect[b].add(a);\n }\n if (numEdge % 2 != 0) {\n System.out.println(-1);\n return;\n }\n visited = new int[numNode];\n odd = new boolean[numNode];\n print = new StringBuilder();\n dfs(0, -1);\n System.out.println(print);\n }\n\n static ArrayList<Integer> connect[];\n static int visited[];\n static boolean odd[];\n static StringBuilder print;\n\n static void dfs(int crt, int parent) {\n visited[crt] = 1;\n ArrayList<Integer> crtConnect = connect[crt];\n for (int child : crtConnect) {\n if (child == parent || visited[child] == 1) {\n continue;\n } else if (visited[child] == 2) {\n print.append((crt + 1) + \" \" + (child + 1) + \"\\n\");\n odd[crt] = !odd[crt];\n } else {\n dfs(child, crt);\n if (odd[child]) {\n print.append((child + 1) + \" \" + (crt + 1) + \"\\n\");\n odd[child] = !odd[child];\n } else {\n print.append((crt + 1) + \" \" + (child + 1) + \"\\n\");\n odd[crt] = !odd[crt];\n }\n }\n }\n visited[crt] = 2;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "N, K = map(int, input().split())\nS = input()\naaaa = False\nif K >= 15:\n aaaa = True\nelif 2 ** K >= N:\n aaaa = True\nif aaaa:\n print(min(S) * N)\n exit()\n\n\ndef get_last_dict(s_str):\n U = s_str + s_str[:: - 1]\n c = min(s_str)\n p = U.index(c)\n minindex = p\n p += 1\n while p <= N:\n if U[p] == c:\n if check_normal_dict(U, minindex, p):\n minindex = p\n p += 1\n return U[minindex: minindex + N]\n\n\ndef check_normal_dict(u, pointer1, pointer2):\n for i in range(N):\n if u[pointer1 + i] > u[pointer2 + i]:\n return True\n elif u[pointer1 + i] < u[pointer2 + i]:\n return False\n return False\n\n\nS = get_last_dict(S)\nif K == 1:\n print(S)\nelse:\n count = 0\n for c in S:\n if c == S[0]:\n count += 1\n else:\n break\n if count * (2 ** (K - 1)) >= N:\n print(S[0] * N)\n else:\n S = S[0] * (count * ((2 ** (K - 1)) - 1)) + S\n print(S[0: N])\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class atcoder_AGC037_E {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n try {\n final int N = sc.nextInt();\n int K = sc.nextInt();\n StringBuilder S = new StringBuilder(sc.next());\n boolean firstTime = true;\n int step = 1;\n while (K > 0) {\n StringBuilder T = new StringBuilder(S.toString());\n T.reverse();\n StringBuilder revU = new StringBuilder(S.toString() + T.toString());\n revU.reverse();\n String sDash = S.toString();\n for (int i = N; i >= 0; i -= step) {\n String tmp = revU.substring(i, i + N);\n if (sDash.compareTo(tmp) > 0) {\n sDash = tmp;\n } else {\n if (!firstTime) {\n break;\n }\n }\n }\n if (firstTime) {\n firstTime = false;\n if (Math.pow(2, K) > N) {\n char c = sDash.charAt(0);\n for (int i = 0; i < N; i++) {\n System.out.print(c);\n }\n System.out.println();\n System.exit(0);\n }\n } else {\n step += step;\n }\n K--;\n S = new StringBuilder(sDash);\n S.reverse();\n }\n System.out.println(S.reverse());\n } finally {\n sc.close();\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\n\n\ndef solve(H: int, W: int, A: int, B: int):\n answer = [[\"0\"] * W for _ in range(H)]\n for i in range(H):\n for j in range(W):\n if i < B:\n if j < A:\n answer[i][j] = \"0\"\n else:\n answer[i][j] = \"1\"\n else:\n if j < A:\n answer[i][j] = \"1\"\n else:\n answer[i][j] = \"0\"\n for i in range(H):\n print(''.join(answer[i]))\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 H = int(next(tokens))\n W = int(next(tokens))\n A = int(next(tokens))\n B = int(next(tokens))\n solve(H, W, A, B)\n\n\nif __name__ == '__main__':\n main()\n"
},
{
"role": "user",
"content": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Scanner;\n\npublic class atcoder_AGC038_A {\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n int H = sc.nextInt();\n int W = sc.nextInt();\n int A = sc.nextInt();\n int B = sc.nextInt();\n if (W < 2 * A || H < 2 * B) {\n System.out.println(-1);\n return;\n }\n for (int i = 0; i < H; i++) {\n for (int j = 0; j < W; j++) {\n if ((i < B && j < A) || (i >= B) && (j >= A)) bw.write(\"0\");\n else bw.write(\"1\");\n }\n bw.newLine();\n }\n bw.flush();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def twos_in_factorial(n):\n return n - bin(n).count('1')\n\n\ndef parity_of_nCr(n, i):\n f = twos_in_factorial\n return f(n) - f(n - i) - f(i) > 0\n\n\nif __name__ == \"__main__\":\n n = int(input())\n nums = list(map(lambda x: int(x) - 1, input().strip()))\n no_one = False\n if 1 not in nums:\n nums = [num // 2 for num in nums]\n no_one = True\n is_odd = False\n for i, num in enumerate(nums):\n if not parity_of_nCr(n - 1, i) and num & 1:\n is_odd ^= 1\n if not is_odd:\n print(0)\n else:\n print(1 << no_one)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class atcoder_AGC043_B {\n private int cal(String s, char c) {\n int n = s.length();\n int m = n - 1;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n if (s.charAt(i) == c && (m & i) == i) {\n ans ^= 1;\n }\n }\n return ans;\n }\n\n private void solve() {\n int n = sc.nextInt();\n String s = sc.next();\n StringBuilder sb = new StringBuilder();\n for (int i = 1; i < n; i++) {\n sb.append(Math.abs(s.charAt(i) - s.charAt(i - 1)));\n }\n if (n == 2) {\n out.println(sb.charAt(0));\n return;\n }\n s = sb.toString();\n if (s.contains(\"1\")) {\n out.println(cal(s, '1'));\n } else {\n out.println(cal(s, '2') * 2);\n }\n }\n\n private static PrintWriter out;\n private static MyScanner sc;\n\n private static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n private MyScanner() {\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\n public static void main(String[] args) {\n out = new PrintWriter(new BufferedOutputStream(System.out));\n sc = new MyScanner();\n new atcoder_AGC043_B().solve();\n out.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from math import gcd\nx = int(input())\nprint(360 // gcd(360, x))\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class atcoder_AGC046_A {\n public static void main(String[] args) throws IOException {\n FastReader sc = new FastReader();\n PrintWriter pw = new PrintWriter(System.out);\n int x = sc.nextInt();\n int count = 0;\n int tmp = x;\n x = 0;\n while (x != 360) {\n x = x + tmp;\n if (x > 360) {\n x = x - 360;\n }\n count++;\n }\n System.out.println(count);\n }\n}\n\nclass 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 (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "A, B, C, D = map(int, input().split())\nm = 998244353\nd = [[0] * (D + 1) for _ in range(C + 1)]\nd[A][B] = 1\nfor i in range(A, C + 1):\n for j in range(B, D + 1):\n d[i][j] += (d[i][j - 1] * i + d[i - 1][j] * j -\n d[i - 1][j - 1] * (i - 1) * (j - 1)) % m\nprint(d[C][D])\n"
},
{
"role": "user",
"content": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class atcoder_AGC046_B {\n long MOD = 998244353L;\n long[][] dp = new long[3001][3001];\n\n void solve(Scanner sc, PrintWriter pw) {\n int A = sc.nextInt();\n int B = sc.nextInt();\n int C = sc.nextInt();\n int D = sc.nextInt();\n dp[A][B] = 1;\n for (int c = A; c <= C; c++) {\n for (int d = B; d <= D; d++) {\n if (c == A && d == B) {\n continue;\n }\n long ans = 0;\n if (c > A) {\n long part = dp[c - 1][d];\n ans = (part * d);\n }\n if (d > B) {\n long part = dp[c][d - 1];\n ans = (ans + (part * c));\n }\n if (c > A && d > B) {\n ans = (ans - (dp[c - 1][d - 1] * (c - 1) * (d - 1)));\n }\n dp[c][d] = ((ans % MOD) + MOD) % MOD;\n }\n }\n pw.println(dp[C][D]);\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n new atcoder_AGC046_B().solve(sc, pw);\n pw.flush();\n pw.close();\n sc.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "s = list(input())\nnum_g, num_p = 0, 0\nscore = 0\nfor x in s:\n if x == 'g':\n if num_g - num_p > 0:\n score += 1\n num_p += 1\n else:\n score = score\n num_g += 1\n elif x == 'p':\n if num_g - num_p > 0:\n score = score\n num_p += 1\n else:\n score -= 1\n num_g += 1\nprint(score)\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_ARC062_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 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 String S = in.next();\n int score = 0;\n for (int i = 0; i < S.length(); i++) {\n char my = i % 2 == 0 ? 'g' : 'p';\n char his = S.charAt(i);\n if (my != his) {\n score += my == 'p' ? 1 : -1;\n }\n }\n out.println(score);\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": "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, num):\n if N <= 0:\n return [[]] * num\n elif num == 1:\n return [I() for _ in range(N)]\n else:\n read_all = [tuple(II()) for _ in range(N)]\n return map(list, zip(* read_all))\n\n\ndef my_sign(x):\n return (x > 0) - (x < 0)\n\n\nN = I()\na = III()\nmax_val = 0\nmax_sign = 0\nmax_index = - 1\nfor i, a0 in enumerate(a):\n if abs(a0) > max_val:\n max_val = abs(a0)\n max_sign = my_sign(a0)\n max_index = i\nif max_sign == 0:\n print(0)\nelif max_sign == 1:\n print(2 * N - 1)\n for i in range(N):\n print(max_index + 1, i + 1)\n for i in range(N - 1):\n print(i + 1, i + 2)\nelse:\n print(2 * N - 1)\n for i in range(N):\n print(max_index + 1, i + 1)\n for i in range(1, N)[:: - 1]:\n print(i + 1, i)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class atcoder_ARC086_B {\n public static void main(String[] $) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int[] a = new int[n];\n Arrays.setAll(a, i -> s.nextInt());\n ArrayList<String> r = new ArrayList<>();\n int m = 0;\n for (int i = 1; i < n; ++i) if (Math.abs(a[m]) < Math.abs(a[i])) m = i;\n for (int i = 0; i < n; ++i) if (a[m] >= 0 ^ a[i] >= 0) r.add(m + 1 + \" \" + (i + 1));\n if (a[m] >= 0) {\n for (int i = 1; i < n; ++i) r.add(i + \" \" + (i + 1));\n } else {\n for (int i = n; i > 1; --i) r.add(i + \" \" + (i - 1));\n }\n System.out.println(r.size());\n r.forEach(System.out::println);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "K, N = list(map(int, input().split()))\ndprint = lambda * x: x\n\n\ndef cmb(n, r, mod):\n if (r < 0 or r > n):\n return 0\n r = min(r, n - r)\n return g1[n] * g2[r] * g2[n - r] % mod\n\n\nmod = 998244353\n__N = 8000\ng1 = [1, 1]\ng2 = [1, 1]\ninverse = [0, 1]\nfor i in range(2, __N + 1):\n g1.append((g1[- 1] * i) % mod)\n inverse.append((- inverse[mod % i] * (mod // i)) % mod)\n g2.append((g2[- 1] * inverse[- 1]) % mod)\n\n\ndef kumiawase(p, q):\n return cmb(p + q - 1, q - 1, mod)\n\n\ndef solve(n):\n assert n <= K + 1\n ans = 0\n kumi = (n - 1) // 2\n for p in range(kumi + 1):\n if p > N:\n break\n ans += 2 ** p * cmb(kumi, p, mod) * kumiawase(N - p,\n p + (K - kumi * 2 - int(n % 2 == 0)))\n if n % 2 == 0 and N - p - 1 >= 0:\n ans += 2 ** p * cmb(kumi, p, mod) * kumiawase(N -\n p - 1, p + (K - kumi * 2 - int(n % 2 == 0)))\n return ans\n\n\nans = []\nfor i in range(2, 2 * K + 1):\n if i <= K + 1:\n tmp = solve(i) % 998244353\n ans.append(tmp)\n print(tmp)\n else:\n print(ans[- i + K])\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class atcoder_ARC102_C {\n static int mod = 998244353;\n static long[][] nchoosek;\n\n public static void main(String[] args) {\n nchoosek = new long[4001][4001];\n for (int i = 0; i < nchoosek.length; i++) {\n nchoosek[i][0] = nchoosek[i][i] = 1;\n }\n for (int i = 2; i < nchoosek.length; i++) {\n for (int j = 1; j < i; j++) {\n nchoosek[i][j] = (nchoosek[i - 1][j] + nchoosek[i - 1][j - 1]) % mod;\n }\n }\n Scanner sc = new Scanner(System.in);\n int k = sc.nextInt();\n int n = sc.nextInt();\n for (int i = 2; i <= 2 * k; i++) {\n int pairs;\n if (i > k) {\n pairs = k - i / 2;\n } else {\n pairs = (i - 1) / 2;\n }\n int active = k - 2 * pairs;\n if (i % 2 == 0) active -= 1;\n long times2 = 1;\n long total = 0;\n for (int j = 0; j <= pairs; j++) {\n long choice = times2 * nchoosek[pairs][j] % mod;\n times2 = times2 * 2 % mod;\n if (active + j - 1 < 0) continue;\n total += choice * nchoosek[n + active - 1][active + j - 1];\n if (i % 2 == 0) {\n total += choice * nchoosek[n + active - 2][active + j - 1];\n }\n total %= mod;\n }\n System.out.println(total);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\ninput_array = []\nfor i in range(n):\n S, R, H, C = map(int, input().split())\n input_array.append((S, R, H, C))\noutdated = []\nfor i in range(n):\n for j in range(n):\n if (input_array[i][0] < input_array[j][0] and input_array[i][1] < input_array[j][1] and input_array[i][2] < input_array[j][2]):\n outdated.append(input_array[i])\noutdated = set(outdated)\nminimum_cost = 100000\ninput_number = 0\nfor i in range(n):\n current_item = input_array[i]\n cost = current_item[3]\n if (current_item not in outdated and cost < minimum_cost):\n minimum_cost = current_item[3]\n input_number = i + 1\nprint(input_number)\n"
},
{
"role": "user",
"content": "import java.io.PrintWriter;\nimport java.util.*;\nimport java.util.Scanner;\n\npublic class codeforces_106_B {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = input.nextInt();\n int[][] vec = new int[n][4];\n for (int i = 0; i < n; i++) {\n vec[i][0] = input.nextInt();\n vec[i][1] = input.nextInt();\n vec[i][2] = input.nextInt();\n vec[i][3] = input.nextInt();\n }\n int ans = 500;\n int ansprice = 20000;\n for (int i = 0; i < n; i++) {\n int fl = 1;\n for (int j = 0; j < n; j++) {\n if (vec[i][0] < vec[j][0] && vec[i][1] < vec[j][1] && vec[i][2] < vec[j][2]) {\n fl = 0;\n }\n }\n if (fl == 1) {\n if (vec[i][3] < ansprice) {\n ansprice = vec[i][3];\n ans = i + 1;\n }\n }\n }\n System.out.println(ans);\n out.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def s():\n input()\n a = list(map(int, input().split()))\n a.sort()\n for i in range(1, len(a)):\n if a[i] != a[i - 1] and a[i] < a[i - 1] * 2:\n return 'YES'\n return 'NO'\n\n\nprint(s())\n"
},
{
"role": "user",
"content": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class codeforces_108_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n Arrays.sort(a);\n for (int i = 0; i < a.length - 1; i++) {\n if (a[i + 1] < a[i] * 2 && a[i] != a[i + 1]) {\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "LUCKY = \"abcd\"\nn = int(input())\ns = \"\"\nfor i in range(n):\n s += LUCKY[i % 4]\nprint(s)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_110_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n, i, j, p = 97;\n n = sc.nextInt();\n char c[] = new char[n];\n for (i = 0; i < 4; i++) {\n for (j = i; j < n; j += 4) c[j] = (char) p;\n p++;\n }\n for (i = 0; i < n; i++) System.out.print(c[i]);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, d = map(int, input().split())\nx = []\nm = 0\nq = 0\nx = input().split()\nfor i in range(len(x)):\n x[i] = int(x[i])\nfor a in range(len(x) - 1):\n if x[a] >= x[a + 1]:\n q = int((x[a] - x[a + 1]) / d + 1)\n m = m + q\n x[a + 1] = x[a + 1] + q * d\nprint(m)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_11_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int d = in.nextInt();\n int[] nums = new int[n];\n for (int i = 0; i < n; i++) {\n nums[i] = in.nextInt();\n }\n int result = 0;\n int a = 0;\n for (int i = 1; i < n; i++) {\n a = (nums[i - 1] - nums[i]);\n if (a >= 0) {\n result += a / d + 1;\n nums[i] += (a / d + 1) * d;\n }\n }\n System.out.println(result);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from collections import Counter\nimport sys\ninput = sys.stdin.readline\nn = int(input())\nw = Counter(map(int, input().split()))\nc = 0\nfor i in w:\n if i == 0:\n c += w[i] * (w[i] - 1)\n else:\n if - i in w:\n c += w[i] * w[- i]\nprint(c // 2)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_131_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int N = (int) 1e5 + 5;\n long[] cnt = new long[21];\n for (int i = 0; i < n; i++) {\n cnt[scan.nextInt() + 10]++;\n }\n long res = 0;\n for (int i = 0; i < 10; i++) {\n res += cnt[i] * cnt[20 - i];\n }\n res += (cnt[10] * (cnt[10] - 1)) / 2;\n System.out.println(res);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\ninput = sys.stdin.readline\nn = int(input())\nw = list(map(int, input().split()))\nx = sum(w)\nd = []\nfor i in range(n):\n if (x - w[i]) / (n - 1) == w[i]:\n d.append(i + 1)\nprint(len(d))\nprint(' '.join(map(str, d)))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_134_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] arr = new int[n];\n int sum = 0;\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n sum += arr[i];\n }\n int c = 0;\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < n; i++) {\n if ((sum - arr[i]) % (n - 1) == 0 && (sum - arr[i]) / (n - 1) == arr[i]) {\n c++;\n sb.append((i + 1) + \" \");\n }\n }\n System.out.println(c);\n System.out.println(sb.toString());\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nnumber = list(map(int, list(input())))\nh1 = 0\nh2 = 0\nx = 0\nfor i in range(n):\n if number[i] != 4 and number[i] != 7:\n print(\"NO\")\n x += 1\n break\n if i < n // 2:\n h1 += number[i]\n else:\n h2 += number[i]\nif not x:\n if h1 == h2:\n print(\"YES\")\n else:\n print(\"NO\")\n"
},
{
"role": "user",
"content": "import static java.lang.Math.*;\n\nimport java.util.*;\n\npublic class codeforces_146_A {\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n int x = 0, y = 0;\n int t = 0;\n int n = in.nextInt();\n String str = in.next();\n char l[] = new char[str.length()];\n l = str.toCharArray();\n for (int i = 0; i < n; i++) {\n if (l[i] != '4' && l[i] != '7') {\n t = 1;\n }\n }\n if (t == 1) {\n System.out.println(\"NO\");\n } else {\n for (int i = 0; i < n / 2; i++) {\n x = x + Character.getNumericValue(l[i]);\n }\n for (int i = n - 1; i > (n / 2) - 1; i--) {\n y = y + Character.getNumericValue(l[i]);\n }\n if (x == y) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "s = input()\nres = []\npunctuation = [',', '.', '!', '?']\nfor i in range(len(s)):\n if i >= 1:\n if s[i] == '':\n if res[- 1] != '':\n res.append(s[i])\n else:\n continue\n else:\n if s[i] in punctuation:\n if res[- 1] == '':\n res.pop()\n res.append(s[i])\n res.append('')\n else:\n res.append(s[i])\n else:\n if s[i] == '':\n continue\n if s[i] in punctuation:\n continue\n else:\n res.append(s[i])\nprint(''.join(res))\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class codeforces_147_A {\n public static boolean isLatinLetter(char c) {\n return c >= 'a' && c <= 'z';\n }\n\n public static boolean isPunctuation(char c) {\n if (c == '.') return true;\n if (c == ',') return true;\n if (c == '!') return true;\n if (c == '?') return true;\n return false;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n String s = br.readLine();\n StringBuilder sb = new StringBuilder();\n int n = s.length();\n sb.append(s.charAt(0));\n for (int i = 1; i < n; i++) {\n char c = s.charAt(i);\n if (isLatinLetter(c)) {\n if (!isLatinLetter(s.charAt(i - 1))) {\n sb.append(' ');\n }\n sb.append(c);\n } else if (isPunctuation(c)) {\n sb.append(c);\n }\n }\n pw.println(sb);\n pw.flush();\n pw.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "princess = int(input())\ndragon = int(input())\nt = int(input())\nf = int(input())\nc = int(input())\nif dragon <= princess:\n print(0)\n exit(0)\nresult = 0\nposition = t * princess\nposition += princess * position / (dragon - princess)\nwhile position < c:\n result += 1\n position += princess * position / dragon\n position += princess * f\n position += princess * position / (dragon - princess)\nprint(result)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_148_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n double VP = in.nextInt();\n double VD = in.nextInt();\n double T = in.nextInt();\n double F = in.nextInt();\n double C = in.nextInt();\n if (VD <= VP) {\n System.out.println(\"0\");\n return;\n }\n int answer = 0;\n double start = T;\n while (true) {\n double x = start * VP / (VD - VP);\n if ((start + x) * VP >= C) {\n break;\n }\n start += 2 * x + F;\n answer++;\n }\n System.out.println(answer);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "s = input()\nn = int(input())\nans = 0\nfor i in range(n):\n x = input()\n a, b = 0, 0\n for j in s:\n if j == x[0]:\n a += 1\n elif j == x[1]:\n b += 1\n else:\n ans = ans + min(a, b)\n a, b = 0, 0\n ans = ans + min(a, b)\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class codeforces_154_A {\n public static void main(String hi[]) throws Exception {\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\n char[] arr = infile.readLine().toCharArray();\n int N = arr.length;\n HashSet<String> set = new HashSet<String>();\n int K = Integer.parseInt(infile.readLine());\n int res = 0;\n for (int k = 0; k < K; k++) {\n String input = infile.readLine();\n int a = 0;\n int b = 0;\n for (int i = 0; i < N; i++) {\n if (arr[i] == input.charAt(0)) a++;\n else if (arr[i] == input.charAt(1)) b++;\n else {\n res += Math.min(a, b);\n a = b = 0;\n }\n }\n res += Math.min(a, b);\n }\n System.out.println(res);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\ninput = sys.stdin.readline\na, b = input()[: - 1].split()\nx = max(len(a), len(b))\na = a.rjust(x, '0')\nb = b.ljust(x, '0')\ns = ''\nc = 0\nfor i in range(x):\n d = int(b[i]) + int(a[x - i - 1]) + c\n if d > 9:\n s += str(d)[1]\n c = 1\n else:\n s += str(d)\n c = 0\nif c == 1:\n s += '1'\nprint(int(s[:: - 1]))\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_171_A {\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 (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n public static void main(String[] args) {\n FastReader sc = new FastReader();\n int n = sc.nextInt();\n int m = sc.nextInt();\n int t = reverse(m);\n System.out.println(t + n);\n }\n\n public static int reverse(int n) {\n if (n < 10) return n * 10;\n int t = n, r = 0;\n while (t > 0) {\n r = (r * 10) + t % 10;\n t = t / 10;\n }\n return r;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def cutRibbon():\n arr = [int(i) for i in input().split()]\n length = arr[0]\n arr = sorted(arr[1: 4], reverse=False)\n if (length % arr[0] == 0):\n print(int(length / arr[0]))\n return\n ans = 0\n if (arr[0] == arr[1]):\n k = 0\n for i in range(int(length / arr[2]) + 1):\n check = length - i * arr[2]\n if (check >= 0 and check % arr[0] == 0):\n k = int(check / arr[0])\n ans = max(ans, k + i)\n else:\n k = 0\n for i in range(int(length / arr[2]) + 1):\n for j in range(int(length / arr[1]) + 1):\n check = length - i * arr[2] - j * arr[1]\n if (check >= 0 and check % arr[0] == 0):\n k = int(check / arr[0])\n ans = max(ans, k + i + j)\n print(ans)\n return\n\n\ncutRibbon()\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_189_A {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int maxn = 4010;\n int a = scanner.nextInt();\n int b = scanner.nextInt();\n int c = scanner.nextInt();\n int[] arr = {a, b, c};\n int[] dp = new int[maxn];\n for (int i = 0; i < n; i++) {\n dp[i] = Integer.MIN_VALUE;\n }\n dp[0] = 0;\n for (int i = 0; i < 3; i++) {\n for (int j = arr[i]; j < dp.length; j++) {\n dp[j] = Math.max(dp[j], dp[j - arr[i]] + 1);\n }\n }\n System.out.println(dp[n]);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\nif n < 1:\n if m < 1:\n print(n, m)\n quit()\n print(\"Impossible\")\n quit()\nif m > n:\n min = m\n max = n + m - 1\n print(min, max)\nif m <= n:\n min = n\n max = n + m - 1\n if m == 0:\n max = n\n print(min, max)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_190_A {\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 if (n == 0) {\n if (m != 0) System.out.println(\"Impossible\");\n else System.out.println(0 + \" \" + 0);\n return;\n }\n if (m <= n) {\n if (m == 0) {\n m = 1;\n }\n System.out.print(n + \" \" + (m + n - 1));\n return;\n }\n System.out.print(m + \" \" + (m + n - 1));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "xxs = input().split(\" \")\nx, t, a, b, da, db = int(xxs[0]), int(xxs[1]), int(\n xxs[2]), int(xxs[3]), int(xxs[4]), int(xxs[5])\n\n\ndef main():\n if x == 0:\n print(\"YES\")\n return \"Result Found\"\n a_time = min([a // da, t - 1])\n b_time = min([b // db, t - 1])\n for i in range(a_time + 1):\n for j in range(b_time + 1):\n if a - da * i == x or b - db * j == x:\n print(\"YES\")\n return \"Result Found\"\n if (a - da * i) + (b - db * j) == x:\n print(\"YES\")\n return \"Result Found\"\n return \"Result Not Found\"\n\n\nff = main()\nif ff == \"Result Not Found\":\n print(\"NO\")\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_203_A {\n private void solve() {\n int x = nextInt();\n int t = nextInt();\n int a = nextInt();\n int b = nextInt();\n int da = nextInt();\n int db = nextInt();\n int first;\n int second;\n boolean ok = false;\n for (int i = 0; i < t; i++) {\n first = a - (da * i);\n for (int j = 0; j < t; j++) {\n second = b - (db * j);\n if (second + first == x || second == x || first == x || x == 0) {\n ok = true;\n break;\n }\n }\n }\n if (ok) out.print(\"YES\");\n else out.print(\"NO\");\n }\n\n public static void main(String[] args) {\n new codeforces_203_A().run();\n }\n\n BufferedReader br;\n StringTokenizer st;\n PrintWriter out;\n\n private void run() {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private int nextInt() {\n return Integer.parseInt(next());\n }\n\n private String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n return \"END_OF_FILE\";\n }\n }\n return st.nextToken();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def solve_case():\n n, m = map(int, input().split())\n count = [None] * n\n for i in range(n):\n count[i] = [0] * n\n ans = - 1\n for k in range(m):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n found = False\n for i in range(x - 2, x + 1):\n for j in range(y - 2, y + 1):\n if i >= 0 and i < n and j >= 0 and j < n:\n count[i][j] += 1\n if count[i][j] == 9:\n found = True\n if found:\n ans = k + 1\n break\n print(ans)\n\n\nsolve_case()\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_203_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int M = in.nextInt();\n int[][] black = new int[N + 2][N + 2];\n for (int m = 1; m <= M; m++) {\n int x = in.nextInt();\n int y = in.nextInt();\n for (int xx = x - 1; xx <= x + 1; xx++) {\n for (int yy = y - 1; yy <= y + 1; yy++) {\n if (++black[xx][yy] == 9) {\n System.out.println(m);\n return;\n }\n }\n }\n }\n System.out.println(\"-1\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def readInts(): return map(int, input().split())\n\n\ndef dfs(g, seen, i):\n if i in seen:\n return 0, 0\n seen.add(i)\n nodes = 1\n edges = len(g[i])\n for j in g[i]:\n x, y = dfs(g, seen, j)\n nodes += x\n edges += y\n return nodes, edges\n\n\ndef solve():\n line0 = []\n try:\n line0 = readInts()\n except EOFError:\n return False\n n, m = line0\n g = {}\n seen = set()\n for i in range(1, n + 1):\n g[i] = set()\n for _ in range(m):\n a, b = readInts()\n g[a].add(b)\n g[b].add(a)\n ans = 0\n for i in range(1, n + 1):\n if i not in seen:\n nodes, edges = dfs(g, seen, i)\n if nodes > 1 and nodes % 2 == 1 and 2 * nodes == edges:\n ans += 1\n if (n - ans) % 2 == 1:\n ans += 1\n print(ans)\n return True\n\n\nwhile solve():\n pass\n"
},
{
"role": "user",
"content": "import java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class codeforces_216_B {\n int count;\n boolean[] seen;\n int path = 0, cycle = 1;\n LinkedList<LinkedList<Integer>> graph;\n\n public int dfs(int child, int par) {\n if (seen[child] == true) return cycle;\n seen[child] = true;\n for (Integer i : graph.get(child)) {\n if (i != par) {\n this.count++;\n if (dfs(i, child) == cycle) return cycle;\n }\n }\n return path;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int m = sc.nextInt();\n int n = sc.nextInt();\n codeforces_216_B ft = new codeforces_216_B();\n ft.graph = new LinkedList<>();\n for (int i = 0; i <= m; i++) {\n ft.graph.add(new LinkedList<Integer>());\n }\n ft.seen = new boolean[m + 1];\n for (int i = 0; i < n; i++) {\n int x = sc.nextInt();\n int y = sc.nextInt();\n ft.graph.get(x).add(y);\n ft.graph.get(y).add(x);\n }\n int toremove = 0;\n for (int i = 1; i <= m; i++) {\n if (!ft.seen[i]) {\n ft.count = 0;\n if (ft.dfs(i, 0) == ft.cycle) {\n if (ft.count % 2 == 1) toremove++;\n }\n }\n }\n if ((m - toremove) % 2 == 1) toremove++;\n System.out.println(toremove);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def main():\n n, k = list(map(int, input().split(' ')))\n elems = list(map(int, input().split(' ')))\n def all_same(arr): return all([x == arr[0] for x in arr])\n if all_same(elems):\n print(0)\n return\n if k == 1:\n print(- 1)\n return\n if not all_same(elems[k - 1:]):\n print(- 1)\n return\n target = elems[- 1]\n to_delete = elems[0: k - 1]\n while to_delete and to_delete[- 1] == target:\n to_delete.pop()\n print(len(to_delete))\n\n\nif __name__ == \"__main__\":\n main()\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_222_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(), k = in.nextInt(), l = 0, c = 1;\n for (int i = 0; i < n; i++) {\n int a = in.nextInt();\n if (a == l) c += 1;\n else c = 1;\n l = a;\n }\n if (c + k > n) System.out.println(n - c);\n else System.out.println(-1);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nc = 0\nfor i in range(n):\n l1 = list(map(int, input().split()))\n if sum(l1) > 1:\n c = c + 1\nprint(c)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_231_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int t = sc.nextInt();\n int count = 0;\n while (t-- > 0) {\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n if ((a == 1 && b == 1)\n || (a == 1 && c == 1)\n || (b == 1 && c == 1)\n || (a == 1 && b == 1 && c == 1)) {\n count++;\n }\n }\n System.out.println(count);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nfor i in range(n):\n a = int(input())\n if a < 2:\n print(0)\n if a >= 2:\n print(a - 2)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_23_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int t = scan.nextInt();\n for (int i = 0; i < t; i++) {\n int n = scan.nextInt();\n System.out.println(maxLeft(n));\n }\n }\n\n public static int maxLeft(int n) {\n return n > 2 ? n - 2 : 0;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "x, y, a, b = map(int, input().split())\ngames = []\nfor i in range(a, x + 1):\n if (i <= b):\n continue\n else:\n for j in range(b, y + 1):\n if i > j:\n games.append((i, j))\nprint(len(games))\nfor i in games:\n print(f\"{i[0]} {i[1]}\")\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_242_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int x, y, a, b;\n x = in.nextInt();\n y = in.nextInt();\n a = in.nextInt();\n b = in.nextInt();\n int count = 0;\n for (int i = a; i <= x; i++) {\n for (int j = b; j <= y; ++j) {\n if (i <= j) continue;\n count++;\n }\n }\n System.out.println(count);\n for (int i = a; i <= x; i++) {\n for (int j = b; j <= y; ++j) {\n if (i <= j) continue;\n System.out.println(i + \" \" + j);\n }\n }\n in.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import os\nimport sys\nimport io\nimport math\nfrom tokenize import Triple\nfrom math import *\ndef I(): return [* map(int, sys.stdin.readline().split())]\ndef IS(): return input()\n\n\ndef IN(): return int(input())\ndef IF(): return float(input())\n\n\nn = IN()\nid = 0\nl, r = map(int, input().split())\nfor i in range(1, n):\n li, ri = map(int, input().split())\n if li <= l and r <= ri:\n id = i\n elif li < l or r < ri:\n id = n\n l = min(l, li)\n r = max(r, ri)\nprint(- 1 if id == n else id + 1)\n"
},
{
"role": "user",
"content": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class codeforces_242_B {\n static final int INF = (int) 1e9 + 5;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n;\n n = sc.nextInt();\n ArrayList<Integer> a = new ArrayList<>();\n ArrayList<Integer> b = new ArrayList<>();\n int left = INF, right = 0;\n for (int i = 0; i < n; i++) {\n a.add(sc.nextInt());\n b.add(sc.nextInt());\n left = Math.min(left, a.get(i));\n right = Math.max(right, b.get(i));\n }\n for (int i = 0; i < n; i++) {\n if (left == a.get(i) && right == b.get(i)) {\n System.out.println(++i);\n return;\n }\n }\n System.out.println(-1);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nlist = [int(x) % 2 for x in input().split()]\nif sum(list) == 1:\n print(list.index(1) + 1)\nelse:\n print(list.index(0) + 1)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_25_A {\n public static void main(String[] args) {\n Scanner ob = new Scanner(System.in);\n int n = ob.nextInt();\n int array[] = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n array[i] = ob.nextInt();\n }\n int odd = 0, even = 0, odd_ind = 0, even_ind = 0;\n for (int i = 1; i <= n; i++) {\n if (array[i] % 2 == 0) {\n even++;\n even_ind = i;\n } else {\n odd++;\n odd_ind = i;\n }\n }\n if (odd > even) System.out.println(even_ind);\n else System.out.println(odd_ind);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nl = []\nfor i in range(n):\n l.append(int(input()))\nans = n - 1\nlast = 0\nfor i in l:\n ans += abs(last - i) + 1\n last = i\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_265_B {\n public static void main(String[] args) {\n Scanner scn = new Scanner(System.in);\n int n = scn.nextInt();\n int[] arr = new int[n];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = scn.nextInt();\n }\n int ans = arr[0] + 1;\n for (int i = 1; i < arr.length; i++) {\n ans += Math.abs(arr[i] - arr[i - 1]) + 2;\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def substract(a, b):\n if a > b:\n total = 0\n while a > 0 and b > 0:\n total += int(a / b)\n a = a % b\n if a > 0:\n total += int(b / a)\n b = b % a\n return total\n if a < b:\n total = 0\n while a > 0 and b > 0:\n total += int(b / a)\n b = b % a\n if b > 0:\n total += int(a / b)\n a = a % b\n return total\n if a == b:\n return 1\n\n\nn = int(input())\nlst = []\nfor i in range(0, n):\n a, b = map(int, input().split())\n lst.append(substract(a, b))\nfor i in lst:\n print(i)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_267_A {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n for (int i = 0; i < n; i++) {\n int a = scan.nextInt();\n int b = scan.nextInt();\n System.out.println(sub(a, b));\n }\n }\n\n public static int sub(int a, int b) {\n int min = Math.min(a, b);\n int max = Math.max(a, b);\n int result = 0;\n while (min > 0) {\n result += max / min;\n max = max % min;\n int curr_min = Math.min(min, max);\n int curr_max = Math.max(min, max);\n min = curr_min;\n max = curr_max;\n }\n return result;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nq = []\ncount = 0\nfor i in range(n):\n a = input().split()\n q.append(a)\nfor j in q:\n for k in q:\n if k == j:\n continue\n elif j[0] == k[len(k) - 1]:\n count += 1\n else:\n continue\nprint(count)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_268_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.nextLine());\n int result = 0;\n int[] h = new int[n];\n int[] g = new int[n];\n for (int i = 0; i < n; i++) {\n h[i] = sc.nextInt();\n g[i] = sc.nextInt();\n }\n for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (h[i] == g[j]) result++;\n System.out.println(result);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def main():\n input()\n return nPairsWithCommonFX(map(int, input().split()))\n\n\ndef nPairsWithCommonFX(sequence):\n storage = {}\n FXs = []\n for value in sequence:\n y = f(value)\n if y not in storage:\n storage[y] = [value]\n FXs.append(y)\n else:\n storage[y].append(value)\n return (sum(len(storage[y]) * len(storage[y]) for y in FXs) - sum(len(storage[y]) for y in FXs)) // 2\n\n\ndef f(n):\n y = 1\n while n != 1:\n if n % 2:\n y += 1\n n //= 2\n return y\n\n\nif __name__ == '__main__':\n print(main())\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class codeforces_272_B {\n public static void main(String[] args) {\n FastReader sc = new FastReader();\n PrintWriter out = new PrintWriter(System.out);\n int n = sc.nextInt();\n int a[] = new int[33];\n for (int i = 0; i < n; i++) {\n a[rec(sc.nextInt())]++;\n }\n double answer = 0;\n for (int i = 0; i < a.length; i++) {\n double summ = (1 + a[i] - 1) / 2.0 * (a[i] - 1);\n answer += summ;\n }\n out.println((long) answer);\n out.close();\n }\n\n static int rec(long x) {\n int answer = 0;\n for (int k = 31; k >= 0; k--) {\n if ((x & (1 << k)) != 0) answer++;\n }\n return answer;\n }\n\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 (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "num, k = [int(x) for x in input().split()]\narr = [int(x) for x in input().split()]\ndifferent = set()\ntemp = 0\narr.sort()\nfor x in arr:\n if (x % k != 0 or not x // k in different):\n different.add(x)\n temp = max(len(different), temp)\nprint(temp)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_274_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long k = sc.nextLong();\n long[] arr = new long[n];\n HashSet<Long> set = new HashSet<>();\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextLong();\n }\n Arrays.sort(arr);\n int count = 0;\n for (int i = 0; i < n; i++) {\n if (arr[i] % k != 0) {\n count++;\n set.add(arr[i]);\n } else if (!set.contains(arr[i] / k)) {\n count++;\n set.add(arr[i]);\n }\n }\n System.out.println(count);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "s = list(input())\nx = True\ndt = {}\nfor i in s:\n if i in dt:\n dt[i] += 1\n else:\n dt[i] = 1\ncnt = 0\nx = True\nfor key, value in dt.items():\n if value % 2 != 0 and cnt < 1:\n cnt += 1\n elif value % 2 != 0 and cnt >= 1:\n x = False\n break\nif x:\n print(\"First\")\nelif not x and len(s) % 2 == 0:\n print(\"Second\")\nelif not x and len(s) % 2 != 0:\n print(\"First\")\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class codeforces_276_B {\n public static void main(String[] args) throws NumberFormatException, IOException {\n InputStreamReader inputStreamReader = new InputStreamReader(System.in);\n BufferedReader bufferedReader = new BufferedReader(inputStreamReader);\n PrintWriter writer = new PrintWriter(System.out);\n String str = bufferedReader.readLine();\n Map<Character, Integer> map = new HashMap<>();\n int oddCount = 0;\n for (int i = 0; i < str.length(); i++) {\n char ch = str.charAt(i);\n if (map.containsKey(ch)) {\n map.put(ch, map.get(ch) + 1);\n } else {\n map.put(ch, 1);\n }\n }\n for (Map.Entry<Character, Integer> entry : map.entrySet()) {\n if (entry.getValue() % 2 != 0) {\n oddCount++;\n }\n }\n if (oddCount <= 1 || oddCount % 2 != 0) {\n writer.println(\"First\");\n } else {\n writer.println(\"Second\");\n }\n writer.flush();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "firstline = int(input())\ntotal = 0\nmemory = []\nfor x in range(firstline):\n A, G = list(map(int, input().split()))\n if total + A <= 500:\n total += A\n memory.append(\"A\")\n else:\n total -= G\n memory.append(\"G\")\nprint(\"\".join(memory))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_282_B {\n public static void main(String arg[]) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n char ch[] = new char[n];\n int s1 = 0, s2 = 0;\n int i, j = 0, flag = 0, dif = 0;\n for (i = 0; i < n; i++) {\n int x = sc.nextInt();\n int y = sc.nextInt();\n int temp1 = s1 + x;\n int temp2 = s2 + y;\n if (Math.abs(temp1 - s2) <= 500) {\n s1 += x;\n ch[j++] = 'A';\n continue;\n }\n if (Math.abs(temp2 - s1) <= 500) {\n s2 += y;\n ch[j++] = 'G';\n continue;\n }\n flag = 1;\n break;\n }\n if (flag == 1) System.out.println(-1);\n else {\n String ans = \"\";\n ans = ans.valueOf(ch);\n System.out.println(ans);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "t = []\nfor i in range(4):\n l = list(map(str, input()))\n t.append(l)\nblack = 0\nwhite = 0\ncorrect = 0\nfor i in range(3):\n for j in range(3):\n if t[i][j] == '#':\n black += 1\n else:\n white += 1\n if t[i][j + 1] == '#':\n black += 1\n else:\n white += 1\n if t[i + 1][j] == '#':\n black += 1\n else:\n white += 1\n if t[i + 1][j + 1] == '#':\n black += 1\n else:\n white += 1\n if (black == 0 or black == 3 or white == 0 or white == 3 or white == 4 or black == 4):\n correct = 1\n break\n black = 0\n white = 0\nif correct == 1:\n print('YES')\nelse:\n print('NO')\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_287_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String[] str = new String[4];\n int i = -1;\n while (i != 3) {\n i = i + 1;\n str[i] = sc.next();\n }\n int u = -1;\n i = -1;\n int yes = 0;\n while (u != 2) {\n u = u + 1;\n i = -1;\n while (i != 2) {\n i = i + 1;\n if ((str[u].charAt(i) == str[u].charAt(i + 1)\n && (str[u + 1].charAt(i) == str[u].charAt(i)\n || str[u + 1].charAt(i + 1) == str[u].charAt(i)))\n || (str[u + 1].charAt(i) == str[u + 1].charAt(i + 1)\n && (str[u].charAt(i) == str[u + 1].charAt(i)\n || str[u].charAt(i + 1) == str[u + 1].charAt(i)))) {\n yes = 1;\n System.out.println(\"YES\");\n break;\n }\n }\n if (yes == 1) {\n break;\n }\n }\n if (yes == 0) {\n System.out.println(\"NO\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nm = input().split()\npossible = True\nfor i in set(m):\n if m.count(i) >= n / 2 + 1:\n possible = False\n break\nprint('YES' if possible else 'NO')\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class codeforces_296_A {\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 Task solver = new Task();\n solver.solve(in, out);\n out.close();\n }\n\n static class Task {\n public void solve(InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] array = new int[1001];\n for (int i = 0; i < n; i++) {\n int index = in.nextInt();\n array[index]++;\n }\n int countMax = -1;\n for (int i = 1; i < array.length; i++) {\n if (countMax < array[i]) countMax = array[i];\n }\n if (n % 2 == 0) {\n if (countMax <= n / 2) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n } else {\n if (countMax <= n / 2 + 1) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n }\n }\n }\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n }\n\n String next() {\n while (tokenizer == null || !tokenizer.hasMoreElements()) {\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 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 = reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def num_inp(): return int(input())\n\n\ndef arr_inp(): return list(map(int, input().split()))\ndef sp_inp(): return map(int, input().split())\n\n\na = sorted(map(int, [* open(0)][1].split()))\nprint([a[0], - 1][any(x % a[0] for x in a)])\n"
},
{
"role": "user",
"content": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class codeforces_299_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n Arrays.sort(a);\n int min = a[0];\n for (int value : a) {\n if (value % min != 0) {\n System.out.println(-1);\n return;\n }\n }\n System.out.println(min);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\nsa = input().count(\"-\")\nsa = min([n - sa, sa])\nss = []\nfor _ in range(m):\n a, b = map(int, input().split())\n b -= a\n ss.append((b % 2 and b <= sa << 1) and \"1\\n\" or \"0\\n\")\nprint(\"\".join(ss))\n"
},
{
"role": "user",
"content": "import java.io.IOException;\nimport java.util.Scanner;\n\npublic class codeforces_302_A {\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int arr[] = new int[n];\n for (int i = 0; i < n; i++) arr[i] = sc.nextInt();\n StringBuffer res = new StringBuffer();\n int o = 0, e = 0;\n for (int i = 0; i < n; i++)\n if (arr[i] == 1) ++o;\n else ++e;\n for (int i = 0; i < k; i++) {\n int l = sc.nextInt();\n int r = sc.nextInt();\n if ((r - l + 1) % 2 == 1) res.append(\"0\\n\");\n else {\n if ((r - l + 1) / 2 <= o && (r - l + 1) / 2 <= e) res.append(\"1\\n\");\n else res.append(\"0\\n\");\n }\n }\n System.out.print(res);\n sc.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\nq = n // m\nr = n % m\na = [q] * m\nfor i in range(r):\n a[i] += 1\nfor i in range(m):\n print(a[i], end=' ')\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_306_A {\n public static Scanner input = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = input.nextInt();\n int m = input.nextInt();\n int a[] = new int[m];\n if (n % m == 0) {\n for (int i = 0; i < a.length; i++) {\n a[i] = n / m;\n }\n } else {\n int sub = n / m;\n for (int i = 0; i < a.length; i++) {\n a[i] = sub;\n }\n int test = n - (sub * m);\n int count = 0;\n for (int i = 0; i < test; i++) {\n a[count] = a[count] + 1;\n count++;\n if (count > +a.length) count = 0;\n }\n }\n for (int i = (a.length - 1); i >= 0; i--) {\n System.out.print(a[i] + \" \");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def task4(A, B, n):\n for X in range(- 1000, 1001):\n if A * (X ** n) == B:\n return X\n return \"No solution\"\n\n\n[A, B, n] = input().split()\nprint(task4(int(A), int(B), int(n)))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_30_A {\n public static void main(String[] args) {\n new codeforces_30_A().solve(new Scanner(System.in));\n }\n\n private void solve(Scanner sc) {\n int A = sc.nextInt(), B = sc.nextInt(), n = sc.nextInt();\n if (A == 0) {\n if (B == 0) System.out.println(1);\n else System.out.println(\"No solution\");\n return;\n }\n if (B % A != 0) {\n System.out.println(\"No solution\");\n return;\n }\n B /= A;\n boolean neg = B < 0;\n if (neg && n % 2 == 0) {\n System.out.println(\"No solution\");\n return;\n }\n if (neg) B = -B;\n for (int x = 0; x <= B; x++) {\n if (Math.pow(x, n) == B) {\n System.out.println(neg ? -x : x);\n return;\n }\n }\n System.out.println(\"No solution\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "soz = input()\na = [0] * (len(soz) + 1)\nfor i in range(1, len(soz)):\n a[i] = a[i - 1]\n if soz[i - 1] == soz[i]:\n a[i] += 1\nn = int(input())\narr = []\nfor i in range(n):\n m, l = input().split()\n arr.append(a[int(l) - 1] - a[int(m) - 1])\nfor i in arr:\n print(i)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class codeforces_313_B {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n Fast f = new Fast();\n f.sol(br, pw);\n pw.close();\n }\n}\n\nclass Fast {\n public void sol(BufferedReader br, PrintWriter pw) throws IOException {\n StringTokenizer st = new StringTokenizer(br.readLine());\n String s = st.nextToken();\n Integer cum[] = new Integer[s.length() + 1];\n cum[0] = cum[s.length()] = 0;\n for (int i = 1; i < s.length(); i++) {\n if (s.charAt(i) == s.charAt(i - 1)) cum[i] = cum[i - 1] + 1;\n else cum[i] = cum[i - 1];\n }\n st = new StringTokenizer(br.readLine());\n Integer q = Integer.parseInt(st.nextToken());\n while (q-- != 0) {\n st = new StringTokenizer(br.readLine());\n Integer l = Integer.parseInt(st.nextToken()), r = Integer.parseInt(st.nextToken()) - 1;\n pw.println(cum[r] - cum[l - 1]);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "y = int(input())\narr = [int(i) for i in input().split()]\nfor i in range(len(arr)):\n for j in range(len(arr)):\n if i == j:\n continue\n for k in range(len(arr)):\n if arr[k] != arr[j] and arr[k] != arr[i] and arr[k] == arr[i] + arr[j]:\n print(k + 1, j + 1, i + 1)\n exit()\nprint(- 1)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_31_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int f = 0;\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = sc.nextInt();\n }\n int k = 0, j = 0, i = 0;\n for (k = 0; k < n; k++) {\n int t = a[k];\n for (i = 0; i < n; i++) {\n for (j = 0; j < n - 1; j++) {\n if (i != j && t == (a[i] + a[j])) {\n f = 1;\n break;\n }\n }\n if (f == 1) break;\n }\n if (f == 1) break;\n }\n if (f == 1) System.out.println(k + 1 + \" \" + (j + 1) + \" \" + (i + 1));\n else System.out.println(\"-1\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import itertools\n\n\ndef find(s, ch):\n return [i for i, ltr in enumerate(s) if ltr == ch]\n\n\nif __name__ == '__main__':\n n = int(input())\n s = input().replace(\"\", \"\")\n if '0' not in s:\n print(n - 1)\n else:\n indices = find(s, '0')\n if len(indices) == 1:\n print(n)\n else:\n maximum = 0\n combs = itertools.combinations(indices, 2)\n for x in combs:\n maximum = max(\n maximum, 2 + 2 * (abs(indices.index(x[0]) - indices.index(x[1])) - 1) - (abs(x[0] - x[1]) - 1))\n print(s.count('1') + maximum)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_327_A {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n if (scanner.hasNext()) {\n int n = scanner.nextInt();\n int arr[] = new int[n];\n for (int i = 0; i < n; i++) arr[i] = scanner.nextInt();\n int max = Integer.MIN_VALUE;\n for (int i = 0; i < n; i++) {\n for (int j = i; j < n; j++) {\n int x = 0;\n int brr[] = new int[n];\n for (int k : arr) brr[x++] = k;\n for (int k = i; k <= j; k++) {\n if (brr[k] == 0) brr[k] = 1;\n else brr[k] = 0;\n }\n int count = checKNo(brr);\n if (count > max) max = count;\n }\n }\n if (n == 1) {\n if (arr[0] == 1) System.out.println(0);\n else System.out.println(1);\n } else {\n System.out.println(max);\n }\n }\n }\n\n private static int checKNo(int[] brr) {\n int val = 0;\n for (int i : brr) if (i == 1) ++val;\n return val;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "s = input()\nresult = \"\"\ni = 0\nwhile i < len(s):\n if s[i] == \".\":\n result += '0'\n else:\n i += 1\n if s[i] == \".\":\n result += '1'\n else:\n result += '2'\n i += 1\nprint(result)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_32_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n char[] n = in.next().toCharArray();\n boolean s = false;\n for (int i = 0; i < n.length; i++) {\n if (n[i] == '.') {\n if (s) {\n System.out.print(1);\n s = false;\n } else {\n System.out.print(0);\n }\n } else {\n if (s) {\n System.out.print(2);\n s = false;\n } else {\n s = true;\n }\n }\n }\n in.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "I = input\nn, m = map(int, I().split())\nb = [1] * n * 2\nb[0] = b[n - 1] = b[n] = b[2 * n - 1] = 0\nfor i in range(m):\n r, c = map(int, I().split())\n b[r - 1] = b[n + c - 1] = 0\nif n % 2 and b[n // 2] and b[n + n // 2]:\n b[n // 2] = 0\nprint(sum(b))\n"
},
{
"role": "user",
"content": "import static java.lang.Math.*;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class codeforces_333_B {\n public static FastReader in = new FastReader();\n public static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) {\n int n = in.nextInt(), m = in.nextInt();\n Set<Integer> bannedRows, bannedCols;\n bannedRows = new HashSet<>();\n bannedCols = new HashSet<>();\n for (int i = 0; i < m; i++) {\n int r = in.nextInt();\n if (r > 1 && r < n) bannedRows.add(r);\n int c = in.nextInt();\n if (c > 1 && c < n) bannedCols.add(c);\n }\n int answer = (n - 2) * 2;\n answer -= bannedRows.size();\n answer -= bannedCols.size();\n if (n % 2 != 0) {\n int mid = (n + 1) / 2;\n if (!bannedRows.contains(mid) && !bannedCols.contains(mid)) {\n answer--;\n }\n }\n out.println(answer);\n out.close();\n }\n\n public 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 (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\ni, j = 1, n * n\nwhile i < j:\n print(i, j)\n i += 1\n j -= 1\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_334_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = in.nextInt();\n int square = n * n;\n ArrayList<Integer> odd = new ArrayList<>();\n ArrayList<Integer> even = new ArrayList<>();\n for (int i = 1; i <= square; i++) {\n if (i % 2 == 0) {\n even.add(i);\n } else {\n odd.add(i);\n }\n }\n int loop = square / n;\n int div = loop / 2;\n debug(div);\n for (int i = 1; i <= loop; i++) {\n for (int j = 0; j < div; j++) {\n if (i % 2 == 1) {\n pw.print(odd.remove(0) + \" \" + (even.remove(even.size() - 1)) + \" \");\n } else {\n pw.print(even.remove(0) + \" \" + (odd.remove(odd.size() - 1)) + \" \");\n }\n }\n pw.println();\n }\n pw.close();\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def G(a, b):\n while a % b != 0:\n a, b = b, a % b\n return b\n\n\ndef L(a, b):\n return a * b // G(a, b)\n\n\nl = input().split(' ')\nx, y, a, b = int(l[0]), int(l[1]), int(l[2]), int(l[3])\nlcm = L(x, y)\nprint(b // lcm - (a - 1) // lcm)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_340_A {\n public static void main(String[] sh) {\n Scanner s = new Scanner(System.in);\n long x = s.nextInt();\n long y = s.nextInt();\n long a = s.nextInt();\n long b = s.nextInt();\n long j = 2, i, x1 = 0, y1 = 0, c = 0;\n boolean ans = true;\n c = Math.max(x, y);\n if (c > b) {\n System.out.println(\"0\");\n ans = false;\n }\n while (c % Math.min(x, y) != 0 && ans) {\n if (x > y) {\n c = x * j;\n j++;\n } else {\n c = y * j;\n j++;\n }\n if (c > b) {\n System.out.println(\"0\");\n ans = false;\n break;\n }\n }\n if (ans) {\n long count = 0;\n i = a;\n for (i = a; i <= b; i++) {\n if (i % c == 0) break;\n }\n if (i != b + 1) System.out.println(((b - i) / c) + 1);\n else System.out.println(\"0\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def R(): return map(int, input().split())\n\n\nn, m, s, f = R()\nif s < f:\n d = 1\n c = 'R'\nelse:\n d = - 1\n c = 'L'\nres = \"\"\ni = 1\nj = s\nt, l, r = R()\nk = 1\nwhile j != f:\n if i > t and k < m:\n t, l, r = R()\n k += 1\n if i == t and (l <= j <= r or l <= j + d <= r):\n res += 'X'\n else:\n res += c\n j += d\n i += 1\nprint(res)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\n\npublic class codeforces_342_B {\n public static void main(String[] args) throws IOException {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n String input[] = reader.readLine().split(\" \");\n int m = Integer.parseInt(input[1]);\n int s = Integer.parseInt(input[2]);\n int f = Integer.parseInt(input[3]);\n int maxT = -1;\n HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();\n while (m > 0) {\n String mth[] = reader.readLine().split(\" \");\n int k = Integer.parseInt(mth[0]);\n map.put(k, new ArrayList<>());\n map.get(k).add(Integer.parseInt(mth[1]));\n map.get(k).add(Integer.parseInt(mth[2]));\n maxT = Math.max(maxT, k);\n m--;\n }\n StringBuilder actions = new StringBuilder();\n final char M = (s < f) ? 'R' : 'L';\n int d = (s < f) ? +1 : -1;\n int cur = s;\n int a = -1;\n int b = -1;\n for (int t = 1; t <= maxT; t++) {\n if (map.containsKey(t)) {\n a = map.get(t).get(0).intValue();\n b = map.get(t).get(1).intValue();\n }\n if (map.containsKey(t) && ((cur >= a && cur <= b) || (cur + d >= a && cur + d <= b))) {\n actions.append('X');\n } else {\n actions.append(M);\n cur += d;\n }\n if (cur == f) break;\n }\n while (cur != f) {\n actions.append(M);\n cur += d;\n }\n System.out.println(actions);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nt = [0] + list(map(int, input().split()))\na = [0] + list(map(int, input().split()))\nans, cnt = [], [0 for i in range(n + 1)]\nfor i in a:\n cnt[i] += 1\nfor i in range(1, n + 1):\n if t[i] == 1:\n crt = [i]\n x = a[i]\n while cnt[x] == 1:\n crt.append(x)\n x = a[x]\n if len(crt) > len(ans):\n ans = crt[:]\nans.reverse()\nprint(len(ans))\nprint(' '.join(map(str, ans)))\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_350_B {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = scanner.nextInt();\n int a[] = new int[n + 1];\n int b[] = new int[n + 1];\n int num[] = new int[n + 1];\n for (int i = 1; i <= n; i++) a[i] = scanner.nextInt();\n for (int i = 1; i <= n; i++) b[i] = scanner.nextInt();\n for (int i = 1; i <= n; i++) num[b[i]]++;\n String ss = \"\";\n int ans = 0;\n boolean st[] = new boolean[n + 1];\n for (int i = 1; i <= n; i++) {\n if (a[i] == 1) {\n st[i] = true;\n StringBuilder sb = new StringBuilder();\n int x = b[i];\n StringBuilder sss = new StringBuilder();\n sss.append(i);\n sb.append(\" \" + sss.reverse());\n int s = 1;\n while (!st[x] && num[x] == 1 && x != 0 && a[x] != 1) {\n sss = new StringBuilder();\n sss.append(x);\n sb.append(\" \" + sss.reverse());\n st[x] = true;\n x = b[x];\n s++;\n }\n if (s > ans) {\n ans = s;\n ss = sb.reverse().toString();\n }\n }\n }\n System.out.println(ans);\n System.out.println(ss);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\narr = list(map(float, input().split()))\narr = sorted([x - int(x) for x in arr if x - int(x) != 0])\no = 2 * n - len(arr)\narr_sum = sum(arr)\nres = int(2e9)\nfor i in range(n + 1):\n if i + o >= n:\n res = min(res, abs(i - arr_sum))\nprint(\"%.3f\" % res)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic final class codeforces_351_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 int n = Integer.parseInt(br.readLine());\n StringTokenizer st = new StringTokenizer(br.readLine());\n Double[] arr = new Double[2 * n];\n int non_int = 0;\n double sum_before = 0, sum = 0;\n for (int i = 0; i < 2 * n; i++) {\n double num = Double.parseDouble(st.nextToken());\n sum_before += num;\n if (num != Math.floor(num)) non_int++;\n sum += Math.floor(num);\n arr[i] = num;\n }\n double max_sum = Math.min(n, non_int) + sum;\n double min_sum = Math.max(0, non_int - n) + sum;\n double ans;\n if (min_sum > sum_before) ans = (min_sum - sum_before);\n else if (max_sum < sum_before) ans = (sum_before - max_sum);\n else {\n double x = sum_before - Math.floor(sum_before);\n ans = Math.min(1 - x, x);\n }\n System.out.printf(\"%.3f\", ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, L, R, QL, QR = map(int, input().split())\nW = list(map(int, input().split()))\nsum_el = [0]\nfor i in range(1, n + 1):\n sum_el.append(W[i - 1] + sum_el[i - 1])\nanswer = QR * (n - 1) + sum_el[n] * R\nfor i in range(1, n + 1):\n energy = L * sum_el[i] + R * (sum_el[n] - sum_el[i])\n if i > (n - i):\n energy = energy + (i - (n - i) - 1) * QL\n elif (n - i) > i:\n energy = energy + ((n - i) - i - 1) * QR\n if energy < answer:\n answer = energy\nprint(answer)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_354_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int L = in.nextInt();\n int R = in.nextInt();\n int QL = in.nextInt();\n int QR = in.nextInt();\n int[] W = new int[N];\n int[] sum = new int[N + 1];\n for (int n = 0; n < N; n++) {\n W[n] = in.nextInt();\n sum[n + 1] = sum[n] + W[n];\n }\n long min = Long.MAX_VALUE;\n for (int firstR = 0; firstR <= N; firstR++) {\n int lCount = firstR;\n int rCount = N - lCount;\n long cand = sum[lCount] * L + (sum[N] - sum[lCount]) * R;\n int llCount = Math.max(0, lCount - rCount - 1);\n int rrCount = Math.max(0, rCount - lCount - 1);\n cand += llCount * QL;\n cand += rrCount * QR;\n min = Math.min(cand, min);\n }\n System.out.println(min);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().strip().split())\nout = [0 for _ in range(n)]\ncomp = [i + 2 for i in range(n)]\nfor _ in range(m):\n l, r, x = map(int, input().strip().split())\n t = l\n while t <= r:\n next_val = comp[t - 1]\n if out[t - 1] == 0 and t != x:\n out[t - 1] = x\n comp[t - 1] = r + 1 if t >= x else x\n t = next_val\nprint(* out)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_356_A {\n public static void main(String[] args) throws Exception {\n FastReader in = new FastReader();\n int n = in.nextInt();\n TreeSet<Integer> left = new TreeSet<>();\n int[] answer = new int[n];\n for (int i = 0; i < n; i++) {\n left.add(i);\n }\n int q = in.nextInt();\n while (q-- > 0) {\n int l = in.nextInt() - 1;\n int r = in.nextInt() - 1;\n int win = in.nextInt();\n while (left.ceiling(l) != null && left.ceiling(l) <= r) {\n int curr = left.ceiling(l);\n answer[curr] = win;\n left.remove(curr);\n }\n answer[win - 1] = 0;\n left.add(win - 1);\n }\n StringBuilder ans = new StringBuilder();\n for (int i = 0; i < n; i++) {\n ans.append(answer[i] + \"\");\n }\n System.out.println(ans);\n }\n\n static class FastReader {\n StringTokenizer st;\n BufferedReader br;\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 s = \"\";\n while (st == null || st.hasMoreElements()) {\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return s;\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def get_nums(num, t):\n return [t // num + 1 if i in range(t % num) else t // num for i in range(num)]\n\n\nn, k, l, r, sa, sk = map(int, input().split())\nans = get_nums(k, sk) + get_nums(n - k, sa - sk)\nprint(' '.join(map(str, ans)))\n"
},
{
"role": "user",
"content": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class codeforces_369_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int k = scan.nextInt();\n int l = scan.nextInt();\n int r = scan.nextInt();\n int sAll = scan.nextInt();\n int sk = scan.nextInt();\n int[] ans = getPoints(n, k, l, r, sAll, sk);\n for (int num : ans) {\n System.out.print(num + \" \");\n }\n }\n\n public static int[] getPoints(int n, int k, int l, int r, int sAll, int sk) {\n int[] ans = new int[n];\n Arrays.fill(ans, l);\n sAll -= sk + (n - k) * l;\n sk -= k * l;\n while (sk > 0) {\n int idx = n - 1;\n while (sk > 0 && idx >= n - k) {\n ans[idx--]++;\n sk--;\n }\n }\n while (sAll > 0) {\n int idx = 0;\n while (sAll > 0 && idx < n - k) {\n ans[idx++]++;\n sAll--;\n }\n }\n return ans;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def sum(k):\n ret = 0\n pw = 10\n len = 1\n while 1 == 1:\n cur = min(pw - 1, k)\n prev = pw // 10\n ret += (cur - prev + 1) * len\n if (pw - 1 >= k):\n break\n len += 1\n pw *= 10\n return ret\n\n\nw, m, k = map(int, input().split())\nlo = 0\nhi = int(1e18)\nwhile hi - lo > 1:\n md = (lo + hi) // 2\n c = sum(m + md - 1) - sum(m - 1)\n if c * k <= w:\n lo = md\n else:\n hi = md\nprint(lo)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_373_B {\n public static long ans = 0;\n\n public static long get(long a) {\n long ret = 0;\n long now = 1;\n long t = 1;\n for (; ; ) {\n if (now * 10 > a) {\n ret += (a - now + 1) * t;\n break;\n }\n ret += now * 9 * t;\n now *= 10;\n t++;\n }\n return ret;\n }\n\n public static long binarySearch(long k, long l, long r, long x) {\n if (r >= l) {\n long mid = l + (r - l) / 2;\n if (mid > ans && mid * k <= x) ans = mid;\n\n if (k * mid == x) return mid;\n\n if (k * mid > x) return binarySearch(k, l, mid - 1, x);\n\n return binarySearch(k, mid + 1, r, x);\n }\n\n return -1;\n }\n\n public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n public static PrintWriter pw = new PrintWriter(System.out);\n\n public static void main(String[] args) throws IOException {\n Scanner S = new Scanner(System.in);\n long gen, st, tim;\n gen = S.nextLong();\n st = S.nextLong();\n tim = S.nextLong();\n gen /= tim;\n long beg = st - 1, end = (long) Math.pow(10, 18);\n while (true) {\n long med = (beg + end) / 2 + 1;\n if (get(med) - get(st - 1) > gen) {\n end = med - 1;\n } else {\n beg = med;\n }\n if (beg == end) {\n System.out.println(beg - st + 1);\n break;\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import re\ncandeleIntere, b = map(int, input().split())\ns = 0\nrestoSciolte = 0\nwhile candeleIntere > 0 or restoSciolte >= b:\n candeleIntere += restoSciolte // b\n restoSciolte %= b\n s += candeleIntere\n restoSciolte += candeleIntere % b\n candeleIntere //= b\nprint(s)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_379_A {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int a = scan.nextInt();\n int b = scan.nextInt();\n int res = a;\n while (a >= b) {\n res += (a / b);\n a = (a / b) + (a % b);\n }\n System.out.println(res);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nl = list(map(int, input().split()))\nhigh = 1\ntower = n\nmaximum = 1\nl.sort()\nfor i in range(1, n):\n if l[i] == l[i - 1]:\n tower -= 1\n high += 1\n else:\n if high > maximum:\n maximum = high\n high = 1\nif high > maximum:\n maximum = high\nprint(maximum, tower)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class codeforces_37_A {\n public static void main(String[] args) {\n FastScanner input = new FastScanner();\n int n = input.nextInt();\n HashMap<Integer, Integer> map = new HashMap<>();\n for (int i = 0; i < n; i++) {\n int val = input.nextInt();\n map.put(val, map.getOrDefault(val, 0) + 1);\n }\n int max = Integer.MIN_VALUE;\n for (Map.Entry<Integer, Integer> entry : map.entrySet()) {\n Integer value = entry.getValue();\n max = Math.max(max, value);\n }\n System.out.println(max + \"\" + map.size());\n }\n\n static class FastScanner {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(\"\");\n\n String next() {\n while (!st.hasMoreTokens()) {\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() throws IOException {\n return br.readLine();\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "h1, m1 = (map(int, input().split(':')))\nm1 += h1 * 60\nh2, m2 = (map(int, input().split(':')))\nm2 += h2 * 60\nm2 = m1 - m2\nm2 %= 1440\nprint(\"%02d:%02d\" % (m2 // 60, m2 % 60))\n"
},
{
"role": "user",
"content": "import java.io.IOException;\nimport java.time.LocalTime;\nimport java.util.*;\n\npublic class codeforces_387_A {\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n String[] s = sc.next().split(\":\");\n String[] t = sc.next().split(\":\");\n LocalTime x = LocalTime.of(Integer.parseInt(s[0]), Integer.parseInt(s[1]));\n LocalTime y = LocalTime.of(Integer.parseInt(t[0]), Integer.parseInt(t[1]));\n System.out.println(x.minusHours(y.getHour()).minusMinutes(y.getMinute()));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def main():\n n, m = [int(i) for i in input().split()]\n round_complexity = [int(i) for i in input().split()]\n george_complexity = [int(i) for i in input().split()]\n i = j = 0\n while (i < n and j < m):\n i += 1 * (round_complexity[i] <= george_complexity[j])\n j += 1\n print(n - i)\n\n\nif __name__ == '__main__':\n main()\n"
},
{
"role": "user",
"content": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class codeforces_387_B {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int m = input.nextInt();\n ArrayList<Integer> req = new ArrayList();\n ArrayList<Integer> pre = new ArrayList();\n for (int i = 0; i < n; i++) {\n req.add(input.nextInt());\n }\n for (int i = 0; i < m; i++) {\n pre.add(input.nextInt());\n }\n int i = n - 1, j = m - 1;\n int ans = 0;\n while (i >= 0 && j >= 0) {\n if (req.get(i) > pre.get(j)) {\n ans++;\n } else {\n j--;\n }\n i--;\n }\n System.out.print(ans + i + 1);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "class CodeforcesTask397BSolution:\n def __init__(self):\n self.result = ''\n self.t = 0\n self.queries = []\n\n def read_input(self):\n self.t = int(input())\n for _ in range(self.t):\n self.queries.append([int(x) for x in input().split(\" \")])\n\n def process_task(self):\n res = []\n for query in self.queries:\n k = query[0] // query[1]\n res.append(\"Yes\" if k * query[2] >= query[0] else \"No\")\n self.result = \"\\n\".join(res)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask397BSolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n"
},
{
"role": "user",
"content": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class codeforces_397_B {\n static int N;\n static int MOD = (int) (1e9 + 7);\n\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int t = in.nextInt();\n while (t-- > 0) {\n long n = in.nextInt();\n long a = in.nextInt();\n long b = in.nextInt();\n if (n < a) {\n out.println(\"No\");\n continue;\n }\n if (a == b) {\n if (n % a == 0) {\n out.println(\"Yes\");\n } else {\n out.println(\"No\");\n }\n continue;\n }\n long x = b / (b - a);\n if (n > x * a) {\n out.println(\"Yes\");\n continue;\n }\n long low = 1;\n long high = x + 1;\n long ans = 1;\n while (low <= high) {\n long mid = (low + high) / 2;\n if (mid * a < n) {\n low = mid + 1;\n } else {\n ans = mid;\n high = mid - 1;\n }\n }\n if (n > (ans - 1) * b && n < ans * a) {\n out.println(\"No\");\n } else {\n out.println(\"Yes\");\n }\n }\n out.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import collections\nimport heapq\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom io import BytesIO, IOBase\nimport os\ndef value(): return tuple(map(int, input().split()))\ndef values(): return tuple(map(int, sys.stdin.readline().split()))\ndef inlst(): return [int(i) for i in input().split()]\ndef inlsts(): return [int(i) for i in sys.stdin.readline().split()]\ndef inp(): return int(input())\ndef inps(): return int(sys.stdin.readline())\ndef instr(): return input()\ndef stlst(): return [i for i in input().split()]\n\n\ndef help(a, b, l):\n tot = []\n for i in range(b):\n tot.append(l[i * a: i * a + a])\n for i in zip(* tot):\n if sum((i)) == b:\n return True\n return False\n\n\ndef solve():\n tot = []\n x = instr()\n s = []\n for i in x:\n if i == 'O':\n s.append(0)\n else:\n s.append(1)\n for i in range(1, 13):\n if 12 % i == 0:\n if help(i, 12 // i, s):\n tot.append((12 // i, i))\n print(len(tot), end=' ')\n for a, b in sorted(tot):\n print(f'{a}x{b}', end=' ')\n print()\n\n\nif __name__ == \"__main__\":\n for i in range(inp()):\n solve()\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class codeforces_400_A {\n public static boolean isSolution(int columnsCount, String x) {\n boolean allXs[] = new boolean[columnsCount];\n Arrays.fill(allXs, true);\n for (int i = 0; i < 12; i++) {\n if (x.charAt(i) != 'X') allXs[i % columnsCount] = false;\n }\n for (int i = 0; i < columnsCount; i++) if (allXs[i]) return true;\n return false;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n int t = Integer.parseInt(br.readLine());\n for (int i = 0; i < t; i++) {\n int possibleSolutions = 0;\n StringBuilder solutions = new StringBuilder();\n String s = br.readLine();\n if (isSolution(12, s)) {\n solutions.append(\" 1x12\");\n possibleSolutions++;\n }\n if (isSolution(6, s)) {\n solutions.append(\" 2x6\");\n possibleSolutions++;\n }\n if (isSolution(4, s)) {\n solutions.append(\" 3x4\");\n possibleSolutions++;\n }\n if (isSolution(3, s)) {\n solutions.append(\" 4x3\");\n possibleSolutions++;\n }\n if (isSolution(2, s)) {\n solutions.append(\" 6x2\");\n possibleSolutions++;\n }\n if (isSolution(1, s)) {\n solutions.append(\" 12x1\");\n possibleSolutions++;\n }\n pw.print(possibleSolutions++);\n pw.println(solutions);\n }\n pw.flush();\n pw.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\nc = set(s.find(\"S\") - s.find(\"G\") for s in (input() for _ in range(n)))\nprint(- 1 if any(a < 0 for a in c) else len(c))\n"
},
{
"role": "user",
"content": "import java.util.HashSet;\nimport java.util.Scanner;\n\npublic class codeforces_400_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 String arrs[] = new String[n];\n for (int i = 0; i < n; i++) {\n arrs[i] = sc.next();\n }\n int[] length = new int[n];\n int index = 0;\n int returnDex = 0;\n for (String tmp : arrs) {\n int dexG = tmp.indexOf(\"G\");\n int dexS = tmp.indexOf(\"S\");\n if (dexG > dexS) {\n returnDex = -1;\n }\n length[index++] = dexS - dexG;\n }\n HashSet set = new HashSet<Integer>();\n for (int len : length) {\n set.add(len);\n }\n if (returnDex == -1) {\n System.out.println(returnDex);\n } else {\n System.out.println(set.size());\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\ns = []\nfor i in range(n):\n k = input()\n s.append(k)\nflag = 0\nd1 = []\nd2 = []\nrem = set()\nfor i in range(n):\n for j in range(n):\n if (i == j):\n d1.append(s[i][j])\n if (i == n - j - 1):\n d2.append(s[i][j])\n if (i != j and i != n - j - 1):\n rem.add(s[i][j])\nif (len(rem) != 1):\n print('NO')\nelif (d1 != d2):\n print('NO')\nelif (len(set(d1)) != 1):\n print('NO')\nelif (set(d1) == rem):\n print('NO')\nelse:\n print('YES')\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_404_A {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n char arr[][] = new char[n][n];\n String str[] = new String[n];\n for (int i = 0; i < n; i++) {\n str[i] = sc.next();\n }\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n arr[i][j] = str[i].charAt(j);\n }\n }\n char a = arr[0][0];\n char b = arr[0][1];\n if (a == b) System.out.println(\"NO\");\n else {\n boolean res = true;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i == j || i + j == n - 1) {\n if (arr[i][j] != a) {\n res = false;\n break;\n }\n } else {\n if (arr[i][j] != b) {\n res = false;\n break;\n }\n }\n }\n }\n if (res) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from collections import defaultdict, deque\nfrom functools import lru_cache\nfrom heapq import heappush, heappop\nfrom typing import Counter\nfrom bisect import bisect_right, bisect_left\nimport math\nhpop = heappop\nhpush = heappush\n\n\ndef solution():\n line = input()\n bought_count = Counter(line)\n line = input()\n made_cout = Counter(line)\n res = 0\n for color in made_cout:\n if color not in bought_count:\n return print(- 1)\n res += min(bought_count[color], made_cout[color])\n print(res)\n\n\ndef main():\n t = 1\n for _ in range(t):\n solution()\n\n\nmain()\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_408_B {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n String s1 = s.next();\n String s2 = s.next();\n if (isValid(s1, s2) == false) {\n System.out.println(-1);\n } else {\n HashMap<Character, Integer> m1 = new HashMap<>();\n HashMap<Character, Integer> m2 = new HashMap<>();\n for (char c : s1.toCharArray()) {\n if (m1.containsKey(c)) {\n m1.put(c, m1.get(c) + 1);\n } else {\n m1.put(c, 1);\n }\n }\n for (char c : s2.toCharArray()) {\n if (m2.containsKey(c)) {\n m2.put(c, m2.get(c) + 1);\n } else {\n m2.put(c, 1);\n }\n }\n int ans = 0;\n HashSet<Character> hs = new HashSet<>();\n for (char c : s2.toCharArray()) {\n if (!hs.contains(c)) {\n hs.add(c);\n int x1 = m1.get(c);\n int x2 = m2.get(c);\n x1 = Math.min(x1, x2);\n ans += x1;\n }\n }\n System.out.println(ans);\n }\n }\n\n public static boolean isValid(String s1, String s2) {\n int n1 = s1.length();\n int n2 = s2.length();\n HashMap<Character, Boolean> map = new HashMap<>();\n for (char c : s1.toCharArray()) {\n map.put(c, true);\n }\n for (char c : s2.toCharArray()) {\n if (!map.containsKey(c)) return false;\n }\n return true;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, k = map(int, input().split())\nv = input()\nd = [\"LEFT\", \"RIGHT\"]\nf = k - 1 < n - k\nm = min(k - 1, n - k)\na = []\nfor i in range(0, m):\n a.append(d[not f])\nfor i in v[:: - 1 + 2 * f]:\n a.append(\"PRINT \" + i)\n a.append(d[f])\nprint(* a[: - 1], sep=\"\\n\")\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_412_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(), k = sc.nextInt();\n String a = sc.next();\n if (k > n / 2) {\n while (k < n) {\n System.out.println(\"RIGHT\");\n k++;\n }\n } else {\n while (k > 1) {\n System.out.println(\"LEFT\");\n k--;\n }\n }\n if (k == 1) {\n for (int i = 0; i < a.length(); i++) {\n System.out.println(\"PRINT \" + a.charAt(i));\n if ((i + 1) < a.length()) {\n System.out.println(\"RIGHT\");\n }\n }\n } else {\n for (int i = a.length() - 1; i >= 0; i--) {\n System.out.println(\"PRINT \" + a.charAt(i));\n if ((i - 1) >= 0) {\n System.out.println(\"LEFT\");\n }\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, a, b = [int(x) for x in input().split(\" \")]\nlista = [int(x) for x in input().split(\" \")]\nlistb = [int(x) for x in input().split(\" \")]\nfor k in range(n):\n if k + 1 in lista:\n print(1, end=\" \")\n else:\n print(2, end=\" \")\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_421_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n, a, b;\n n = sc.nextInt();\n a = sc.nextInt();\n b = sc.nextInt();\n ArrayList<Integer> list1 = new ArrayList<>();\n ArrayList<Integer> list2 = new ArrayList<>();\n for (int i = 0; i < a; i++) {\n list1.add(sc.nextInt());\n }\n for (int i = 0; i < b; i++) {\n list2.add(sc.nextInt());\n }\n for (int i = 0; i < n; i++) {\n if (list1.contains(i + 1)) {\n System.out.print(1 + \" \");\n } else {\n System.out.print(2 + \" \");\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\nl = []\nfor i in range(n):\n s = input()\n s = list(s)\n for j in range(m):\n if s[j] == '.':\n if (i + j) & 1:\n s[j] = 'W'\n else:\n s[j] = 'B'\n l.append(s)\nfor c in l:\n print(\"\".join(c))\n"
},
{
"role": "user",
"content": "import java.io.*;\n\npublic class codeforces_445_A {\n public static void main(String[] args) throws IOException {\n BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));\n String[] inp = buf.readLine().split(\"\");\n int n = Integer.parseInt(inp[0]);\n int m = Integer.parseInt(inp[1]);\n String[] ans = new String[n];\n for (int i = 0; i < n; i++) {\n String str = buf.readLine();\n StringBuilder temp = new StringBuilder(\"\");\n for (int j = 0; j < m; j++)\n if (str.charAt(j) == '-') temp.append(\"-\");\n else {\n if ((i + j) % 2 == 1) temp.append(\"W\");\n else temp.append(\"B\");\n }\n ans[i] = temp.toString();\n }\n for (int i = 0; i < n; i++) {\n System.out.println(ans[i]);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\nl = list(map(int, input().split()))\nl2 = []\nfor i in l:\n if i % m == 0:\n l2.append(i // m)\n else:\n l2.append(i // m + 1)\nmx = max(l2)\nfor i in range(n):\n if l2[i] == mx:\n ind = i\nprint(ind + 1)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_450_A {\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 Queue<Integer> q1 = new LinkedList<>();\n Queue<Integer> q2 = new LinkedList<>();\n for (int i = 1; i <= n; i++) {\n q1.add(sc.nextInt());\n q2.add(i);\n }\n int ans = 0;\n while (!q1.isEmpty()) {\n if (q1.peek() <= m) {\n q1.poll();\n ans = q2.poll();\n } else if (q1.peek() > m) {\n int x = q1.poll();\n int val = x - m;\n q1.add(val);\n int val2 = q2.poll();\n q2.add(val2);\n }\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nm = [[int(x) for x in input().split()] for i in range(n)]\nm.sort(reverse=True)\na = m[0]\nfor i in m[1:]:\n if i[1] > a[1]:\n print('Happy Alex')\n break\n a = i\nelse:\n print('Poor Alex')\n"
},
{
"role": "user",
"content": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class codeforces_456_A {\n static ArrayList md = new ArrayList();\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] a = new int[n];\n int[] b = new int[n];\n int temp = 0;\n int q = 0;\n int w = 0, e = 0;\n boolean f = false;\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n b[i] = in.nextInt();\n if (temp < a[i]) {\n if (q > b[i]) {\n f = true;\n }\n q = b[i];\n temp = a[i];\n }\n if (temp > a[i]) {\n if (q < b[i]) {\n f = true;\n }\n q = b[i];\n temp = a[i];\n }\n if (a[i] > w) {\n w = a[i];\n if (b[i] < e) {\n f = true;\n }\n e = b[i];\n }\n if (a[i] < w) {\n if (b[i] > e) {\n f = true;\n }\n }\n }\n if (f == true) {\n System.out.println(\"Happy Alex\");\n } else System.out.println(\"Poor Alex\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import math\ngiven = input(\"\")\nl1 = given.split()\nl1 = [int(x) for x in l1]\nx1 = l1[0]\ny1 = l1[1]\nx2 = l1[2]\ny2 = l1[3]\ndenominator = x2 - x1\nnumerator = y2 - y1\nif denominator != 0:\n quotient = numerator / denominator\nif numerator == 0:\n d = int(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))\n x4 = x1\n x3 = x2\n y3 = y2 + d\n y4 = y1 + d\n print(f\"{x3} {y3} {x4} {y4}\")\nelif denominator == 0:\n y4 = y2\n y3 = y1\n d = int(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))\n x4 = x1 + d\n x3 = x2 + d\n print(f\"{x3} {y3} {x4} {y4}\")\nelif quotient == 1:\n x4 = x2\n x3 = x1\n y4 = y1\n y3 = y2\n print(f\"{x3} {y3} {x4} {y4}\")\nelif quotient == - 1:\n x4 = x1\n x3 = x2\n y4 = y2\n y3 = y1\n print(f\"{x3} {y3} {x4} {y4}\")\nelse:\n print('-1')\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_459_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();\n if (x1 == x2) {\n int dif = Math.abs(y1 - y2);\n pw.println((x1 + dif) + \" \" + y1 + \" \" + (x1 + dif) + \" \" + y2);\n } else if (y1 == y2) {\n int dif = Math.abs(x1 - x2);\n pw.println((x1) + \" \" + (y1 + dif) + \" \" + (x2) + \" \" + (y2 + dif));\n } else if (Math.abs(x1 - x2) == Math.abs(y1 - y2)) {\n pw.println(x1 + \" \" + y2 + \" \" + x2 + \" \" + y1);\n } else {\n pw.println(-1);\n }\n pw.close();\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nl1 = list(map(int, input().split()))\nl1.sort()\na = l1[- 1]\nb = l1[0]\nif a == b:\n print(a - b, (n) * (n - 1) // 2)\nelse:\n ac = l1.count(a)\n bc = l1.count(b)\n print(a - b, ac * bc)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_459_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int N = in.nextInt();\n int[] A = new int[N];\n for (int n = 0; n < N; n++) {\n A[n] = in.nextInt();\n }\n Arrays.sort(A);\n int min = A[0];\n int max = A[N - 1];\n long mins = 0;\n long maxs = 0;\n for (int value : A) {\n if (value == min) mins++;\n if (value == max) maxs++;\n }\n if (min == max) {\n pw.println((max - min) + \" \" + mins * (mins - 1) / 2);\n } else {\n pw.println((max - min) + \" \" + mins * maxs);\n }\n pw.close();\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, k = map(int, input().split())\ns = input()\ncount = [0] * 26\nfor c in s:\n count[ord(c) - ord(\"A\")] += 1\ncount.sort(reverse=True)\nres = 0\nfor i in range(26):\n if count[i] >= k:\n res += k * k\n print(res)\n exit()\n k -= count[i]\n res += count[i] ** 2\nprint(res)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_462_B {\n public static void main(String[] args) throws Exception {\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n StringTokenizer st = new StringTokenizer(f.readLine());\n int n = Integer.parseInt(st.nextToken());\n int k = Integer.parseInt(st.nextToken());\n c462b[] cards = new c462b[26];\n for (int i = 0; i < 26; i++) {\n cards[i] = new c462b();\n }\n String s = f.readLine();\n for (int t = 0; t < n; t++) {\n cards[s.charAt(t) - 'A'].left++;\n }\n long ans = 0;\n for (int i = 0; i < k; i++) {\n Arrays.sort(cards);\n long change = Math.min(cards[25].left, k - i);\n ans += change * change;\n cards[25].left -= change;\n i += change - 1;\n }\n out.println(ans);\n out.close();\n }\n}\n\nclass c462b implements Comparable {\n int left = 0;\n\n @Override\n public int compareTo(Object o) {\n return left - ((c462b) o).left;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "max_level = int(input())\nx = list(map(int, input().split()))\ny = list(map(int, input().split()))\nx.pop(0)\ny.pop(0)\nx = set(x)\ny = set(y)\nif 0 in x:\n x.discard(0)\nelif 0 in y:\n y.discard(0)\nz = x.union(y)\nif len(z) != max_level:\n print(\"Oh, my keyboard!\")\nelse:\n print(\"I become the guy.\")\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_469_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int levels = sc.nextInt();\n int sum = 0;\n int sum2 = 0;\n int sum3 = 0;\n int[] arr = new int[levels];\n int count = 0;\n for (int i = 0; i < levels; i++) {\n arr[i] = sc.nextInt();\n }\n int level2 = sc.nextInt();\n int level3 = levels + level2;\n int[] arr2 = new int[level3];\n for (int i = 0; i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n for (int i = arr.length; i < level3; i++) {\n arr2[i] = sc.nextInt();\n }\n for (int i = 0; i < arr2.length; i++) {}\n int[] arr3 = new int[n];\n int j = 0;\n for (int i = 0; i < n; i++) {\n arr3[i] = ++j;\n }\n for (int i = 0; i < n; i++) {\n for (int x = 0; x < arr2.length; x++) {\n if (arr3[i] == arr2[x]) {\n count++;\n break;\n }\n }\n }\n if (count == n) {\n System.out.println(\"I become the guy.\");\n } else {\n System.out.println(\"Oh, my keyboard!\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "L = []\ninput()\nr = 1\nfor k in input().split():\n L += [r] * int(k)\n r += 1\ninput()\nfor j in input().split():\n print(L[int(j) - 1])\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_474_B {\n public static void main(String args[]) throws IOException {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int arr[] = new int[n];\n arr[0] = sc.nextInt();\n for (int i = 1; i < n; i++) {\n int x = sc.nextInt();\n arr[i] = x + arr[i - 1];\n }\n int m = sc.nextInt();\n int q[] = new int[m];\n for (int i = 0; i < m; i++) q[i] = sc.nextInt();\n for (int k = 0; k < m; k++) System.out.println(fun(arr, q[k], n, m) + 1);\n }\n\n static int fun(int arr[], int q, int n, int m) {\n int res = 0;\n int i = 0, j = n;\n while (i <= j) {\n int md = i + (j - i) / 2;\n if (arr[md] == q) return md;\n else if (arr[md] > q) {\n res = md;\n j = md - 1;\n } else i = md + 1;\n }\n return res;\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "a = input()\nvo = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']\nfor i in range(len(a) - 1, - 1, - 1):\n if (a[i] == ' ' or a[i] == '?'):\n continue\n else:\n if (a[i] in vo):\n print(\"YES\")\n else:\n print(\"NO\")\n break\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_49_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n int length = s.length();\n char ch = 0;\n for (int i = length - 1; i >= 0; i--) {\n if (s.charAt(i) != ' ' && s.charAt(i) != '?') {\n ch = s.charAt(i);\n break;\n }\n }\n ch = Character.toLowerCase(ch);\n if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y') {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\nn, t = map(int, input().split())\ns = list([int(x) for x in input().split()])\ncurrent_cell = 0\nwhile current_cell <= t:\n current_cell += s[current_cell - 1]\n if current_cell == t:\n print(\"YES\")\n sys.exit()\n else:\n continue\nprint(\"NO\")\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_500_A {\n public static boolean dfs(int currpos, int[] arr, int target) {\n if (currpos == target) return true;\n if (currpos == arr.length + 1) return false;\n boolean teleport = dfs(currpos + arr[currpos - 1], arr, target);\n if (teleport) return true;\n return false;\n }\n\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int goal = sc.nextInt();\n int[] arr = new int[n - 1];\n for (int i = 0; i < n - 1; i++) arr[i] = sc.nextInt();\n boolean isFound = dfs(1, arr, goal);\n if (isFound) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n sc.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "ip = input()\nst = \"\"\nif len(ip) != 1:\n if ip[0] == \"9\":\n st = \"9\"\n ip = ip[1:]\n for i in ip:\n if int(i) > 4:\n n = 9 - int(i)\n st += str(n)\n else:\n st += i\nelse:\n st = ip\nprint(int(st))\n"
},
{
"role": "user",
"content": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class codeforces_514_A {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n List<Long> list = new ArrayList<>();\n long x = sc.nextLong();\n while (x > 0) {\n long r = x % 10;\n if (9 - r < r) {\n if (x / 10 == 0 && 9 - r == 0) list.add(r);\n else list.add(9 - r);\n } else list.add(r);\n x = x / 10;\n }\n int pow = 0;\n long newNumber = 0;\n for (int i = 0; i < list.size(); i++) {\n newNumber = newNumber + list.get(i) * (long) Math.pow(10, pow);\n pow++;\n }\n System.out.println(newNumber);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "s, t = input(), input()\nfreqs = dict()\nfreqt = dict()\nyay, whoops = 0, 0\nfor letra in s:\n if letra in freqs:\n freqs[letra] += 1\n else:\n freqs[letra] = 1\nfor letra in t:\n if letra in freqt:\n freqt[letra] += 1\n else:\n freqt[letra] = 1\nfor letra in freqs.keys():\n while (freqs[letra] > 0 and letra in freqt and freqt[letra] > 0):\n yay += 1\n freqs[letra] -= 1\n freqt[letra] -= 1\nfor letra in freqs.keys():\n while (freqs[letra] > 0):\n if letra.islower() and letra.upper() in freqt.keys() and freqt[letra.upper()] > 0:\n whoops += 1\n freqs[letra] -= 1\n freqt[letra.upper()] -= 1\n elif letra.isupper() and letra.lower() in freqt.keys() and freqt[letra.lower()] > 0:\n whoops += 1\n freqs[letra] -= 1\n freqt[letra.lower()] -= 1\n else:\n break\nprint(yay, whoops)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_518_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n StringBuilder s = new StringBuilder(scan.next());\n String t = scan.next();\n int ura = 0;\n int opa = 0;\n Map<Character, Integer> tmap = new HashMap<>();\n for (int i = 0; i < t.length(); i++) {\n Character ch = t.charAt(i);\n if (!tmap.containsKey(ch)) tmap.put(ch, 1);\n else tmap.put(ch, tmap.get(ch) + 1);\n }\n int length = s.length();\n for (int i = 0; i < length; i++) {\n Character ch = s.charAt(i);\n Integer num = tmap.get(ch);\n if (num == null) continue;\n int inum = num;\n if (inum == 1) tmap.remove(ch);\n else tmap.put(ch, inum - 1);\n s.setCharAt(i, 'Я');\n ura++;\n }\n for (int i = 0; i < length; i++) {\n Character ch = s.charAt(i);\n Character rch = reverse(ch);\n Integer num = tmap.get(rch);\n if (num == null) continue;\n int inum = num;\n if (inum == 1) tmap.remove(rch);\n else tmap.put(rch, inum - 1);\n opa++;\n }\n System.out.println(ura + \" \" + opa);\n }\n\n public static Character reverse(Character ch) {\n if (Character.isLowerCase(ch)) {\n return Character.toUpperCase(ch);\n } else return Character.toLowerCase(ch);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\nx = 0\ny = 0\nz = 0\nfor i in a:\n x += i\nfor i in b:\n y += i\nfor i in c:\n z += i\nprint(abs(x - y))\nprint(abs(y - z))\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_519_B {\n public static void main(String args[]) throws IOException {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a = 0, b = 0, c = 0;\n for (int i = 0; i < n; i++) a += sc.nextInt();\n for (int i = 0; i < n - 1; i++) b += sc.nextInt();\n for (int i = 0; i < n - 2; i++) c += sc.nextInt();\n int x = a - b, y = b - c;\n System.out.println(x);\n System.out.println(y);\n }\n}\n"
}
] |