problem_id stringlengths 32 32 | name stringclasses 1
value | problem stringlengths 200 14k | solutions stringlengths 12 1.12M | test_cases stringlengths 37 74M | difficulty stringclasses 3
values | language stringclasses 1
value | source stringclasses 7
values | num_solutions int64 12 1.12M | starter_code stringlengths 0 956 |
|---|---|---|---|---|---|---|---|---|---|
811ef53ea5e010947709828a6800a48e | UNKNOWN | Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p_1, p_2, ..., p_{n} for his birthday.
Jeff hates inversions in sequences. An inversion in sequence a_1, a_2, ..., a_{n} is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality a_{i} > a_{j... | ["n = int(input())\ninp = input()\nseq = inp.split(' ')\nseq = [ abs(int(x)) for x in seq ]\nMax = max(seq)\nnxt = [0] * n\ncnt = [0] * n\npos = [n] * (Max+1)\nfor i in range(n-1, -1, -1):\n nxt[i] = pos[seq[i]]\n pos[seq[i]] = i\nfor i in range(0, Max+1):\n j = pos[i]\n while(j<n):\n front = sum(cnt... | {
"inputs": [
"2\n2 1\n",
"9\n-2 0 -1 0 -1 2 1 0 -1\n",
"9\n0 0 1 1 0 0 1 0 1\n",
"8\n0 1 2 -1 -2 1 -2 2\n",
"24\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\n",
"1\n0\n",
"31\n-2 2 -2 -1 0 0 1 2 1 1 -1 -2 1 -1 -2 2 0 1 -1 -2 -1 -2 -1 2 2 2 2 1 1 0 1\n",
"9\n1 -1 -1 0 -1 ... | COMPETITION | PYTHON3 | CODEFORCES | 1,456 | |
af5d051a925e947678b3ad89113c6929 | UNKNOWN | Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible.
Evlampiy alread... | ["def f(m):\n nonlocal dp, sdp\n l = 0\n for i in range(n):\n while l < n and v[l] < v[i] - m:\n l += 1\n if l - 1 > i - k:\n dp[i] = False\n else:\n dp[i] = (sdp[i - k + 1] != sdp[l - 1])\n sdp[i + 1] = sdp[i] + (1 if dp[i] else 0)\n return dp[n ... | {
"inputs": [
"5 2\n50 110 130 40 120\n",
"4 1\n2 3 4 1\n",
"1 1\n4\n",
"2 2\n7 5\n",
"3 2\n34 3 75\n",
"5 2\n932 328 886 96 589\n",
"10 4\n810 8527 9736 3143 2341 6029 7474 707 2513 2023\n",
"20 11\n924129 939902 178964 918687 720767 695035 577430 407131 213304 810868 596349 266075 12... | COMPETITION | PYTHON3 | CODEFORCES | 1,292 | |
50420fb6c2c47a2fb1bbb95491937762 | UNKNOWN | We have three stones at points (0, 0), (1,0), and (0,1) on a two-dimensional plane.
These three stones are said to form an L when they satisfy the following conditions:
- Each of the stones is at integer coordinates.
- Each of the stones is adjacent to another stone. (That is, for each stone, there is another stone w... | ["import sys\ninput = sys.stdin.readline\n\ndef solve(ax,ay,bx,by,cx,cy):\n x = ax+bx+cx\n y = ay+by+cy\n x -= x//3+1\n y -= y//3+1\n if x==y:\n return x if 0 <= x <= 1 else abs(x)+1\n else:\n return max(abs(x), abs(y))\n\nT = int(input())\nfor _ in range(T):\n ax,ay,bx,by,cx,cy = map... | {"inputs": ["1\n3 2 2 2 2 1\n", "10\n0 0 1 0 0 1\n1 0 0 1 1 1\n2 -1 1 -1 1 0\n1 -2 2 -1 1 -1\n-1 2 0 2 -1 3\n-1 -2 -2 -2 -2 -3\n-2 4 -3 3 -2 3\n3 1 4 2 4 1\n-4 2 -4 3 -3 3\n5 4 5 3 4 4\n", "1000\n999999981 999999988 999999982 999999987 999999981 999999987\n-5 2 -5 1 -4 1\n999999987 -999999992 999999987 -999999993 99999... | COMPETITION | PYTHON3 | ATCODER.JP | 78,451 | |
ce5f868251bb2cecb7de207a67be6054 | UNKNOWN | There are N people, conveniently numbered 1 through N.
We want to divide them into some number of groups, under the following two conditions:
- Every group contains between A and B people, inclusive.
- Let F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds.
Fin... | ["def main():\n mod = 10**9+7\n inv_n = [0]*1001\n nCr = [[1]*(i+1) for i in range(1001)]\n for i in range(1001):\n inv_n[i] = pow(i, mod-2, mod)\n for i in range(2, 1001):\n for j in range(1, i):\n nCr[i][j] = (nCr[i-1][j-1]+nCr[i-1][j]) % mod\n n, a, b, c, d = list(map(int, ... | {"inputs": ["3 1 3 1 2\n", "7 2 3 1 3\n", "1000 1 1000 1 1000\n", "10 3 4 2 5\n", "1000 1 68 1 986\n", "1000 1 934 8 993\n", "1000 1 80 2 980\n", "1000 1 467 4 942\n", "1000 739 920 1 679\n", "1000 340 423 2 935\n", "1 1 1 1 1\n", "522 155 404 151 358\n", "81 7 60 34 67\n", "775 211 497 3 226\n", "156 42 153 1 129\n"],... | COMPETITION | PYTHON3 | ATCODER.JP | 14,844 | |
a3f7e2ca7869ba637a26ec3a8caa0852 | UNKNOWN | The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official language... | ["rd = lambda: list(map(int, input().split()))\n\ndef root(x):\n if f[x]!=x: f[x] = root(f[x])\n return f[x]\n\nn, m = rd()\nN = list(range(n))\nf = list(N)\nlang = [0]*n\nfor i in N: lang[i] = set(rd()[1:])\nfor i in N:\n for j in N[:i]:\n rj = root(j)\n if lang[rj].intersection(lang[i]):\n f[rj] = i\n ... | {
"inputs": [
"5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"2 2\n1 2\n0\n",
"2 2\n0\n0\n",
"5 5\n1 3\n0\n0\n2 4 1\n0\n",
"6 2\n0\n0\n2 1 2\n1 1\n1 1\n0\n",
"7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1\n",
"8 4\n0\n0\n4 ... | COMPETITION | PYTHON3 | CODEFORCES | 15,912 | |
925236b3808f6c272a3a140b580ad328 | UNKNOWN | 3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl from cell $(1, 1)$ to the gate at $(2, n)$ and escape the maze. The girl can o... | ["import sys\nreadline = sys.stdin.readline\n\nN, Q = list(map(int, readline().split()))\nstate = [[False]*(N+2) for _ in range(2)]\n\ncnt = 0\n\nAns = [None]*Q\nfor qu in range(Q):\n r, c = list(map(int, readline().split()))\n r -= 1\n c -= 1\n state[r][c] = not state[r][c]\n res = state[r-1][c-1] + sta... | {
"inputs": [
"5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"2 2\n2 1\n1 2\n",
"2 4\n2 1\n1 2\n1 2\n1 2\n",
"4 1\n1 4\n",
"10 42\n1 4\n1 2\n2 2\n2 8\n1 10\n1 7\n2 8\n2 3\n1 9\n1 2\n2 4\n2 8\n2 4\n1 7\n2 3\n1 9\n1 6\n2 7\n2 7\n1 10\n1 2\n1 10\n2 7\n1 5\n2 2\n1 4\n1 10\n1 2\n2 6\n2 9\n1 7\n1 2\n1 7\n2 3\n1 10\n... | COMPETITION | PYTHON3 | CODEFORCES | 488 | |
22f4df3d272c52e0c388eed4f78395db | UNKNOWN | Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ... | ["n, k = [int(c) for c in input().split()]\na = []\nfor i in range(k):\n ak = [int(c) for c in input().split()]\n a.append(ak[1:])\n\ntotal = k - 1\n\nfor ak in a:\n if ak[0] == 1:\n j = 1\n while j <= len(ak) - 1:\n if ak[j] != ak[j-1] + 1:\n break\n j += 1\n... | {
"inputs": [
"3 2\n2 1 2\n1 3\n",
"7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"1 1\n1 1\n",
"3 2\n1 2\n2 1 3\n",
"5 3\n1 4\n3 1 2 3\n1 5\n",
"8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8\n",
"10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2\n",
"20 6\n3 8 9 13\n3 4 14 20\n2 15 17\n3 2 5 11\n5 7 10 ... | COMPETITION | PYTHON3 | CODEFORCES | 12,000 | |
3cb9c2a60b27cbb1dd20b67d3b7e3a74 | UNKNOWN | In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.
V... | ["import os\nimport random\nimport sys\nfrom typing import List, Dict\n\n\nclass Int:\n def __init__(self, val):\n self.val = val\n\n def get(self):\n return self.val + 111\n\nclass Unique:\n def __init__(self):\n self.s = set()\n\n def add(self, val : int):\n self.s.add(val)\n\n... | {
"inputs": [
"6\n0 1 3 7 15 31\n",
"2\n73 37\n",
"2\n0 1000000000\n",
"8\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782\n",
"2\n0 1\n",
"8\n552283832 997699491 89302459 301640204 288141798 31112026 710831619 862166501\n",
"4\n0 500000000 500000001 10000000... | COMPETITION | PYTHON3 | CODEFORCES | 6,198 | |
16abd0992df68f644ff6eea5936e6196 | UNKNOWN | One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will call person a a subordinates of another person b, if either b is an immediate... | ["n = int(input())\nt = [list(map(int, input().split())) for q in range(n)]\nt[0][0] = 0\nn += 1\nu = [-1e7] * n\nv = [0] * n\nfor i, (j, a) in list(enumerate(t, 1))[::-1]:\n u[i] = max(u[i], v[i] + a)\n v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])\nprint(u[1])", "n = int(input())\nt ... | {
"inputs": [
"7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n",
"1\n-1 42\n",
"2\n-1 3\n1 2\n",
"3\n-1 3\n1 1\n1 2\n",
"3\n-1 1\n1 2\n1 3\n",
"3\n-1 3\n1 2\n2 1\n",
"20\n-1 100\n1 10\n2 26\n2 33\n3 31\n2 28\n1 47\n6 18\n6 25\n9 2\n4 17\n6 18\n6 2\n6 30\n13 7\n5 25\n7 11\n11 7\n17 40\n12 43\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 583 | |
9b4d5d01dbf63dd9b64ab3ebcd311406 | UNKNOWN | You are given an array $a$ of $n$ integers.
You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where $len$ is the length of this segment (added integers can be different).
It... | ["n=int(input())\nL=list(map(int,input().split()))\nif n==1:\n print(1,1)\n print(0)\n print(1,1)\n print(0)\n print(1,1)\n print(-L[0])\nelse:\n print(1,n-1)\n for i in range(n-1):print(L[i]*(n-1),end=' ')\n print()\n print(n,n)\n print(-L[n-1])\n print(1,n)\n for i in range(n-1)... | {"inputs": ["4\n1 3 2 4\n", "1\n34688642\n", "2\n-492673762 -496405053\n", "4\n-432300451 509430974 -600857890 -140418957\n", "16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n", "8\n-311553829 469... | COMPETITION | PYTHON3 | CODEFORCES | 745 | |
12a2533c42952eec1cee831ad21812e7 | UNKNOWN | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (x_{i}, y_{i}).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan co... | ["from collections import Counter\nn = int(input())\npoints = Counter([tuple(map(int, input().split(' '))) for i in range(n)])\n\nx, y = Counter([k for k, v in points.elements()]), Counter([v for k, v in points.elements()])\n\nans = sum([v*(v-1)//2 for k, v in list(x.items())])+sum([v*(v-1)//2 for k, v in list(y.items(... | {
"inputs": [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n",
"10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55\n",
"1\n-5 -90\n",
"2\n315 845\n-669 -762\n",
"3\n8911 7861\n-6888 7861\n8911 7861\n",
"2\n-1 1000000000\n0 -1\n",
"2\n1000000000 0\n-... | COMPETITION | PYTHON3 | CODEFORCES | 11,102 | |
6a6444f50a74780fde926f16d02419cb | UNKNOWN | Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit... | ["from sys import*\n#\ndef check(u, d, l, r):\n used = [pointsx[i][1] for i in range(l)]\n used += [pointsx[-1 - i][1] for i in range(r)]\n used += [pointsy[i][1] for i in range(u)]\n used += [pointsy[-1 - i][1] for i in range(d)]\n if len(set(used)) > k:\n return DOHERA\n dx = pointsx[-1 - r][... | {
"inputs": [
"3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n",
"4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n",
"3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n",
"11 8\n9 1 11 5\n2 2 8 12\n3 8 23 10\n2 1 10 5\n7 1 19 5\n1 8 3 10\n1 5 3 9\n1 2 3 4\n1 2 3 4\n4 2 12 16\n8 5 12 9\n",
"20 5\n1 12 21 22\n9 10 1... | COMPETITION | PYTHON3 | CODEFORCES | 1,064 | |
48073d3f551b220b2f734bfb804acec5 | UNKNOWN | Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x_1, x_2, ..., x_{k} (k > 1) is such maximum element x_{j}, that the following inequality holds: $x_{j} \neq \operatorname{max}_{i = 1}^{k} x_{i}$.
The lucky number of the sequence of disti... | ["def maximum_xor_secondary(sequence):\n stack, answer = [], 0\n for x in sequence:\n while stack:\n answer = max(answer, stack[-1] ^ x)\n if stack[-1] > x:\n break\n else:\n stack.pop()\n stack.append(x)\n\n return answer\n\n\nsize, ... | {
"inputs": [
"5\n5 2 1 4 3\n",
"5\n9 8 3 5 7\n",
"10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\n",
"10\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331\n",
"10\n30301275 19973434 63004643 54007648 93722492 9167... | COMPETITION | PYTHON3 | CODEFORCES | 7,099 | |
a8a570ed3936a746c43081aad497beeb | UNKNOWN | You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n.
You need to permute the array elements so that value $\sum_{i = 1}^{n - k}|A [ i ] - A [ i + k ]|$ became minimal possible. In particular, it is allowed not to change order of elements at all.
-----Inpu... | ["INF = 10 ** 18 + 179\n[n, k], a = [list(map(int, input().split())) for x in range(2)]\na.sort()\ndp, l = [[0] * (k - n % k + 1) for x in range(n % k + 1)], n // k\nfor i in range(n % k + 1):\n for j in range(k - n % k + 1):\n pos = i * (l + 1) + j * l\n dp[i][j] = min((dp[i - 1][j] + a[pos - 1] - a[p... | {
"inputs": [
"3 2\n1 2 4\n",
"5 2\n3 -5 3 -5 3\n",
"6 3\n4 3 4 3 2 5\n",
"2 1\n1 100\n",
"4 3\n1 2 4 8\n",
"5 2\n1 2 8 8 16\n",
"10 3\n-999999914 -999999976 -999999966 -999999952 29 54 -999999963 -999999959 -999999974 48\n",
"30 2\n-999999924 -499999902 500000091 -999999998 500000030 ... | COMPETITION | PYTHON3 | CODEFORCES | 6,410 | |
2601c86b88805ed00dc40540a7827058 | UNKNOWN | It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be w_{i}, then 0 < w_1 ≤ w_2 ≤ ... ≤ w_{k} holds.
Polar bears Alice and Bob each have caught some fish, and th... | ["rd = lambda: list(map(int, input().split()))\n\nrd()\na = sorted(rd(), reverse=True)\nb = sorted(rd(), reverse=True)\nif len(a) > len(b): print(\"YES\"); return\nfor i in range(len(a)):\n if a[i] > b[i]: print(\"YES\"); return\nprint(\"NO\")", "n,m,k=list(map(int,input().split()))\na=list(map(int,input().split()))\n... | {
"inputs": [
"3 3 3\n2 2 2\n1 1 3\n",
"4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n",
"5 5 10\n8 2 8 5 9\n9 1 7 5 1\n",
"7 7 10\n8 2 8 10 6 9 10\n2 4 9 5 6 2 5\n",
"15 15 10\n4 5 9 1 4 6 4 1 4 3 7 9 9 2 6\n6 6 7 7 2 9 1 6 10 9 7 10 7 10 9\n",
"25 25 10\n10 6 2 1 9 7 2 5 6 9 2 3 2 8 5 8 2 9 10 8 9 7 7 4 8\... | COMPETITION | PYTHON3 | CODEFORCES | 4,730 | |
52563859339ab535d1e18b4482260a4b | UNKNOWN | Little X has n distinct integers: p_1, p_2, ..., p_{n}. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number a - x must also belong to set A. If number x belongs to set B, then number b - x must also belong to set B.
Help Lit... | ["from collections import defaultdict\n\ndef solve(n, a, b, xs):\n group = [None] * n\n id_ = {x: i for i, x in enumerate(xs)}\n if a == b:\n for x in xs:\n if a - x not in id_:\n return False\n group = [0] * n\n else:\n for i, x in enumerate(xs):\n ... | {
"inputs": [
"4 5 9\n2 3 4 5\n",
"3 3 4\n1 2 4\n",
"100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 2900 239 3551 1977 24... | COMPETITION | PYTHON3 | CODEFORCES | 9,849 | |
b3d6be894f42dd42376f8f7a72ae4f25 | UNKNOWN | One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.
A positive integer $a$ is initially on the screen. The player can put a coin into the machine and then add $1$ to or subtract $1$ from any two adjacent digits. All digits must remain from $0$ to $9$ af... | ["def main():\n n = int(input())\n a = list(map(int, (x for x in input())))\n b = list(map(int, (x for x in input())))\n x = [0] * (n - 1)\n x[0] = b[0] - a[0]\n for i in range(1, n - 1):\n x[i] = b[i] - a[i] - x[i - 1]\n if a[n - 1] + x[n - 2] != b[n - 1]:\n print(-1)\n return... | {"inputs": ["3\n223\n322\n", "2\n20\n42\n", "2\n35\n44\n", "2\n99\n11\n", "2\n85\n96\n", "2\n37\n97\n", "28\n1467667189658578897086606309\n4558932538274887201553067079\n", "4\n7972\n7092\n", "100\n8089764625697650091223132375349870611728630464931601901362210777083214671357960568717257055725808124\n951235865341844926445... | COMPETITION | PYTHON3 | CODEFORCES | 1,909 | |
58a7be2bc48376de83c1a1340a8736e9 | UNKNOWN | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly q_{i} items he buys. Under the t... | ["import sys\n\nn_discounts = int(sys.stdin.readline())\ndiscount_values = [int(x) for x in sys.stdin.readline().split()]\nn_items = int(sys.stdin.readline())\nitem_values = [int(x) for x in sys.stdin.readline().split()]\n\nmin_discount_req = 10000000\nfor discount_value in discount_values:\n min_discount_req = min(... | {
"inputs": [
"1\n2\n4\n50 50 100 100\n",
"2\n2 3\n5\n50 50 50 50 50\n",
"1\n1\n7\n1 1 1 1 1 1 1\n",
"60\n7 4 20 15 17 6 2 2 3 18 13 14 16 11 13 12 6 10 14 1 16 6 4 9 10 8 10 15 16 13 13 9 16 11 5 4 11 1 20 5 11 20 19 9 14 13 10 6 6 9 2 13 11 4 1 6 8 18 10 3\n26\n2481 6519 9153 741 9008 6601 6117 1689... | COMPETITION | PYTHON3 | CODEFORCES | 7,696 | |
d6bac5ecb5038329a529609c3c471914 | UNKNOWN | Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th number in increasing order on this segment. In other words, you should find th... | ["from math import pi\nfrom cmath import exp\ndef fft(a, lgN, rot=1): # rot=-1 for ifft\n N = 1<<lgN\n assert len(a)==N\n rev = [0]*N\n for i in range(N):\n rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1)\n A = [a[rev[i]] for i in range(N)]\n h = 1\n while h<N:\n w_m = exp((0+1j) * rot * (pi / h))\n for k in range... | {
"inputs": [
"5 3\n1 2 3 4 5\n",
"2 6\n-5 9\n",
"6 99\n-1 -1 -1 -1 -1 -1\n",
"5 -2\n-1 -1 -4 -5 1\n",
"5 -6\n-4 2 -7 -1 -5\n",
"10 29\n88 57 -3 -9 16 48 -84 80 -73 -46\n",
"1 1000000000\n1\n",
"2 -1000000000\n465132 210\n",
"10 -8\n7 -1 0 -8 8 -1 -10 -7 4 0\n",
"10 9\n-2 6 0 -... | COMPETITION | PYTHON3 | CODEFORCES | 1,198 | |
4fb4947c790b43af15e37048e1ee918c | UNKNOWN | Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2 + \ldots + a_n$ biscuits, and the owner of this biscuit will give it to a ... | ["MOD = 998244353\n\nn = int(input())\n\na = list(map(int, input().split()))\ntot = sum(a)\n\ndef inv(x):\n return pow(x, MOD - 2, MOD)\n\nl = [0, pow(n, tot, MOD) - 1]\n\nfor i in range(1, tot):\n aC = i\n cC = (n - 1) * (tot - i)\n curr = (aC + cC) * l[-1]\n curr -= tot * (n - 1)\n curr -= aC * l[-2... | {
"inputs": [
"2\n1 1\n",
"2\n1 2\n",
"5\n0 0 0 0 35\n",
"5\n8 4 2 0 1\n",
"5\n24348 15401 19543 206086 34622\n",
"10\n7758 19921 15137 1138 90104 17467 82544 55151 3999 6781\n",
"2\n0 1\n",
"2\n184931 115069\n",
"100\n9 0 2 8 3 6 55 1 11 12 3 8 32 18 38 16 0 27 6 3 3 4 25 2 0 0 7 ... | COMPETITION | PYTHON3 | CODEFORCES | 2,021 | |
ecbdca6b8d668e1e6601425bc108cc38 | UNKNOWN | Levko loves array a_1, a_2, ... , a_{n}, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
Increase all elements from l_{i} to r_{i} by d_{i}. In other words, perform assignments a_{j} = a_{j... | ["n, m = map(int, input().split())\na = [10**9 for _ in range(n)]\nextra = [0 for _ in range(n)]\nquery = list()\nfor _ in range(m):\n t, l, r, x = map(int, input().split())\n l -= 1\n r -= 1\n query.append((t, l, r, x))\n if t == 1:\n for j in range(l, r + 1):\n extra[j] += x... | {"inputs": ["4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n", "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n", "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 8\n", "1 2\n2 1 1 8\n2 1 1 7\n", "1 2\n2 1 1 10\n2 1 1 5\n", "2 2\n2 1 1 10\n2 1 2 5\n", "1 2\n2 1 1 5\n2 1 1 1\n",... | COMPETITION | PYTHON3 | CODEFORCES | 800 | |
f9da9036251d0f161a5e3a911875c55a | UNKNOWN | Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le... | ["import heapq\n\ndef coor_neighbor(coor, dxs, dys):\n x, y = coor\n for dx in dxs:\n for dy in dys:\n yield x + dx, y + dy\n\n\ndef coor_bottoms(coor):\n return coor_neighbor(coor, (-1, 0, 1), (-1, ))\n\n\ndef coor_tops(coor):\n return coor_neighbor(coor, (-1, 0, 1), (1, ))\n\n\ndef coor_... | {
"inputs": [
"3\n2 1\n1 0\n0 1\n",
"5\n0 0\n0 1\n0 2\n0 3\n0 4\n",
"10\n-1 2\n-3 0\n5 5\n4 4\n-2 1\n1 1\n3 3\n2 2\n0 0\n-1000000000 0\n",
"10\n-678318184 2\n-678318182 3\n580731357 2\n-678318182 1\n-678318184 1\n-678318183 0\n-678318181 2\n580731357 1\n580731358 0\n-678318183 2\n",
"15\n-49118981... | COMPETITION | PYTHON3 | CODEFORCES | 3,689 | |
6a9cda78b7b64caab00adcb99fd0600a | UNKNOWN | You are given n strings s_1, s_2, ..., s_{n} consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation s_{a}_{i}s_{b}_{i} is saved into a new string s_{n} + i (the operations are numbered starting from 1). A... | ["from sys import stdin, stdout\n\nK = 20\n\ndef findAllStrings(s):\n n = len(s)\n sDict = {}\n for i in range(1,K+1):\n sDict[i]=set()\n for x in range(n-i+1):\n sDict[i].add(s[x:x+i])\n return sDict\n\nn = int(stdin.readline().rstrip())\nstringDicts = []\nstringEnd = []\nstringBeg... | {
"inputs": [
"5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n",
"5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7\n",
"5\n111101000111100011100110000100\n000111001\n01101000\n0000110100100010011001000000010100100111110110\n0110001\n10\n5 5\n2 2\n5 6\n1 1\n1 7\n10 6\n6 2\n11 1\n3 6\n8 2\n",
"1\n1\n... | COMPETITION | PYTHON3 | CODEFORCES | 8,232 | |
140282c02911c107007348b0b21fd099 | UNKNOWN | Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $n$ elements. The $i$-th element is $a_i$ ($i$ = $1, 2, \ldots, n$). He gradually takes the first two leftmost elements from the deque (let's call them $A$ and $B$, respectively), and then does th... | ["import sys\ninput = sys.stdin.readline\n\n\nfrom collections import deque\nN, Q = list(map(int, input().split()))\nque = deque([int(a) for a in input().split()])\nma = max(que)\n\nX = []\nk = -1\nc = 0\nwhile c <= k+N+5:\n a = deque.popleft(que)\n b = deque.popleft(que)\n \n X.append((a, b))\n c += 1\n... | {
"inputs": [
"5 3\n1 2 3 4 5\n1\n2\n10\n",
"2 0\n0 0\n",
"2 1\n1 2\n1\n",
"3 2\n1000000 999999 999998\n98\n999999999999\n",
"5 10\n5728 41414 457879 94 1\n1\n100\n10000\n1000000\n100000000\n10000000000\n1000000000000\n100000000000000\n10000000000000000\n1000000000000000000\n",
"71 57\n9 26 80... | COMPETITION | PYTHON3 | CODEFORCES | 11,839 | |
486f9a971ca6edeb28ea55ffd137b809 | UNKNOWN | Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights w_{i} kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He... | ["3\n\nimport sys\n\nn, l, r, ql, qr = list(map(int, sys.stdin.readline().strip().split()))\nw = [int(x) for x in sys.stdin.readline().strip().split()]\n\ns = [0]\nfor i in range(0, n):\n s.append(s[-1] + w[i])\n\ndef cost(left):\n right = n - left\n diff = left - right\n bonus = 0\n if diff > 0: # left ... | {
"inputs": [
"3 4 4 19 1\n42 3 99\n",
"4 7 2 3 9\n1 2 3 4\n",
"2 100 100 10000 10000\n100 100\n",
"2 3 4 5 6\n1 2\n",
"1 78 94 369 10000\n93\n",
"1 94 78 369 10000\n93\n",
"5 1 100 1 10000\n1 2 3 4 5\n",
"5 100 1 10000 1\n1 2 3 4 5\n",
"5 1 100 10000 1\n1 2 3 4 5\n",
"5 100 1 ... | COMPETITION | PYTHON3 | CODEFORCES | 12,733 | |
ae77ea489c8dc6af18b48105cefaa48c | UNKNOWN | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color c_{i}. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones that ... | ["n = int(input())\nC = list(map(int, input().split()))\n\ndp = [[0]*n for _ in range(n)]\nfor i in range(n) :\n dp[i][i] = 1\n\nfor i in range(n-2, -1, -1) :\n for j in range(i+1, n) :\n dp[i][j] = 1 + dp[i+1][j]\n if C[i] == C[i+1] : dp[i][j] = min( dp[i][j], 1 + (dp[i+2][j] if i+2 < n else 0) )\n... | {
"inputs": [
"3\n1 2 1\n",
"3\n1 2 3\n",
"7\n1 4 4 2 3 2 1\n",
"1\n1\n",
"2\n1 1\n",
"2\n1 2\n",
"8\n1 2 1 3 4 1 2 1\n",
"50\n5 7 5 10 7 9 1 9 10 2 8 3 5 7 3 10 2 3 7 6 2 7 1 2 2 2 4 7 3 5 8 3 4 4 1 6 7 10 5 4 8 1 9 5 5 3 4 4 8 3\n",
"50\n13 17 20 5 14 19 4 17 9 13 10 19 16 13 17 ... | COMPETITION | PYTHON3 | CODEFORCES | 11,639 | |
24436c96908743d6bb854b9587b0c46c | UNKNOWN | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an... | ["from operator import __or__, __and__, __xor__\nfrom sys import stdin, stdout\nn, b, c = int(stdin.readline()), 0, 1023\nm = {'|': __or__, '&': __and__, '^': __xor__}\nfor i in range(n):\n t, v = [i for i in stdin.readline().split()]\n b = m[t](b, int(v))\n c = m[t](c, int(v))\nx, o, a = 0, 0, 1023\nfor i in ... | {
"inputs": [
"3\n| 3\n^ 2\n| 1\n",
"3\n& 1\n& 3\n& 5\n",
"3\n^ 1\n^ 2\n^ 3\n",
"2\n| 999\n^ 689\n",
"3\n& 242\n^ 506\n^ 522\n",
"2\n| 56\n^ 875\n",
"3\n^ 125\n^ 377\n& 1019\n",
"1\n& 123\n",
"1\n| 123\n",
"1\n^ 123\n",
"10\n^ 218\n& 150\n| 935\n& 61\n| 588\n& 897\n| 411\n|... | COMPETITION | PYTHON3 | CODEFORCES | 20,887 | |
6dd1a9681b0f2bbd78b53bcd26956ee3 | UNKNOWN | In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ... | ["from itertools import combinations_with_replacement \nfrom collections import deque\n\n#sys.stdin = open(\"input_py.txt\",\"r\")\n\nn, m = map(int, input().split())\nG = [ [] for i in range(n)]\n\nfor i in range(m):\n x, y = map(int, input().split())\n x-=1; y-=1\n G[x].append(y)\n G[y].append(x)\n\ndef B... | {
"inputs": [
"5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n",
"5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n",
"5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1\n",
"9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 3\n",
"9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 4\n",
"10 11\n1 3\n2 ... | COMPETITION | PYTHON3 | CODEFORCES | 4,009 | |
a90e525ec6d6dcee6c38b63055fc0e87 | UNKNOWN | Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The answer to the i-th query is the length of the maximum correct brack... | ["import sys\ninput = sys.stdin.readline\n\ns = input()\n\nM = int(input())\n\n\ndef next_pow_2(n):\n p = 1\n while p < n:\n p <<= 1\n return p\n\n\ndef represented_range(node, size):\n l = node\n r = node\n while l < size:\n l = 2*l\n r = 2*r + 1\n return l-size, r-size\n\n\nc... | {
"inputs": [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n",
"(((((()((((((((((()((()(((((\n1\n8 15\n",
"((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 46\n57 63\n29 48\n51 75\n14 72\n5 70\n51 73\n10 64\n31 56\n50 54\n15 78\n78 82\n1 11\n... | COMPETITION | PYTHON3 | CODEFORCES | 6,238 | |
05eed071477a83a23cf5a14cff6b9870 | UNKNOWN | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team ... | ["n = int(input())\nif n % 2:\n print(\"contest\")\nelse:\n print(\"home\")", "n = int(input())\nif n % 2 == 0:\n print('home')\nelse:\n print('contest')", "n = int(input())\nif n % 2 == 0:\n\tprint(\"home\")\nelse:\n\tprint(\"contest\")", "n = int(input())\nif n % 2 == 0:\n print('home')\nelse:\n pri... | {
"inputs": [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n",
"1\nESJ\nESJ->TSJ\n",
"2\nXMR\nFAJ->XMR\nXMR->FAJ\n",
"3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ\n",
"10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\n... | COMPETITION | PYTHON3 | CODEFORCES | 5,414 | |
a118aa31b1fec5867b4a2f82a0666201 | UNKNOWN | Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.
Ivan represent his array with increasing sequences with h... | ["n = int(input())\nfrom bisect import bisect_left\n\n\na = list(map(int, input().split()))\nss = []\nms = []\nfor i in range(n):\n k = a[i]\n ind = bisect_left(ms, -k)\n if ind == len(ms):\n ss.append([])\n ms.append(0)\n ss[ind].append(k)\n ms[ind] = -k\n\nfor s in ss:\n print(' '.join... | {
"inputs": [
"5\n1 3 2 5 4\n",
"4\n4 3 2 1\n",
"4\n10 30 50 101\n",
"1\n1\n",
"1\n200000\n",
"2\n1 2\n",
"2\n2 1\n",
"2\n1 200000\n",
"2\n200000 1\n",
"10\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967\n",
"3\n1 100 10000... | COMPETITION | PYTHON3 | CODEFORCES | 8,305 | |
b058c29a0202f4c8093f731af8bc4656 | UNKNOWN | When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t... | ["def main():\n import sys\n input = sys.stdin.readline\n \n n = int(input())\n arr = input()\n \n one = arr.count('n')\n zero = arr.count('z')\n \n ans = [1] * one + [0] * zero\n \n print(*ans)\n \n return 0\n\nmain()\n", "n = int(input())\ns = input()\nones = 0\nfor i in s:\n... | {
"inputs": [
"4\nezor\n",
"10\nnznooeeoer\n",
"4\neorz\n",
"3\nnoe\n",
"40\noeerzzozozzrezeezzzoroozrrreorrreereooeo\n",
"32\noeonznzneeononnerooooooeeeneenre\n",
"35\nozrorrooeoeeeozonoenzoeoreenzrzenen\n",
"30\nooeoeneenneooeennnoeeonnooneno\n",
"400\nzzzerrzrzzrozrezooreroeoeez... | COMPETITION | PYTHON3 | CODEFORCES | 6,040 | |
1dfbe103348517257f30cb135e233143 | UNKNOWN | You are given a sequence a_1, a_2, ..., a_{n} consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a subsequen... | ["\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn=int(input())\nb=list(map(int,input().split()))\nbb=sorted(b)\nc={bb[i]:i for i in range(n)}\na=[c[b[i]] for i in range(n)]\nvis=[0]*n\n\nout=[]\nfor i in range(n):\n if vis[i]: continue\n vis[i]=1\n newlist=[i]\n while a[newlist[-1... | {
"inputs": [
"6\n3 2 1 6 5 4\n",
"6\n83 -75 -49 11 37 62\n",
"1\n1\n",
"2\n1 2\n",
"2\n2 1\n",
"3\n1 2 3\n",
"3\n3 2 1\n",
"3\n3 1 2\n",
"10\n3 7 10 1 9 5 4 8 6 2\n",
"20\n363756450 -204491568 95834122 -840249197 -49687658 470958158 -445130206 189801569 802780784 -790013317 -1... | COMPETITION | PYTHON3 | CODEFORCES | 14,174 | |
af909cbcfcc2cf3d11f0a63487222087 | UNKNOWN | DZY loves planting, and he enjoys solving tree problems.
DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every... | ["n = int(input())\nedges = [[int(x) for x in input().split()] for i in range(n-1)]\nedges = sorted(edges)\nuse_count = [0]+[int(input()) for i in range(n)]\nlo,hi = 0,10000\ndef getpar(par,u):\n if par[par[u]] == par[u]:\n return par[u]\n par[u] = getpar(par,par[u])\n return par[u]\ndef unite(par,sz,us... | {
"inputs": [
"4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n",
"4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n",
"10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 3 4465\n9 7 8886\n10 3 9362\n2\n5\n5\n4\n4\n5\n4\n5\n1\n2\n",
"10\n2 1 5297\n3 2 7674\n4 1 1935\n5 2 1941\n6 3 1470\n7 1 3823\n8 2 4959\n9 4 ... | COMPETITION | PYTHON3 | CODEFORCES | 981 | |
ce8ce8c58102d55d0d4129c9d70ec411 | UNKNOWN | As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the number of voters and the number of parties — $n$ and $m$ respectively. For each ... | ["\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,m=list(map(int,input().split()))\n\nparty=[[] for _ in range(m+5)]\npc=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1])\nchoose=[0]*n\n\nfor i in range(n):\n party[pc[i][0]].append(i)\n\n\n\nwant=10**18\nfor i in... | {
"inputs": [
"1 2\n1 100\n",
"5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n",
"5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n",
"5 5\n1 3\n1 6\n5 4\n3 7\n2 10\n",
"5 5\n1 7\n3 3\n2 7\n2 4\n1 2\n",
"5 5\n2 5\n2 4\n2 1\n3 6\n3 7\n",
"1 3000\n918 548706881\n",
"10 10\n7 29\n10 31\n9 40\n5 17\n5 30\... | COMPETITION | PYTHON3 | CODEFORCES | 10,912 | |
47d4c13de7351d238741be1d2f22a680 | UNKNOWN | Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}.
Your task is to find such permutation p of length n, that the group of numbers |p_1 - p_2|, |p_2 - p_3|, ..., |p_... | ["3\n\nimport sys\n\ndef __starting_point():\n \n n, k = list(map(int, sys.stdin.readline().split()))\n l = []\n i = 1\n j = k + 1\n while i <= j:\n l.append(str(i))\n i += 1\n if j > i:\n l.append(str(j))\n j -= 1\n for i in range(k+2, n+1):\n l.ap... | {"inputs": ["3 2\n", "3 1\n", "5 2\n", "5 4\n", "10 4\n", "10 3\n", "10 9\n", "2 1\n", "4 1\n", "4 2\n", "9 8\n", "7 5\n"], "outputs": ["1 3 2\n", "1 2 3\n", "1 3 2 4 5\n", "1 5 2 4 3\n", "1 10 2 9 8 7 6 5 4 3\n", "1 10 2 3 4 5 6 7 8 9\n", "1 10 2 9 3 8 4 7 5 6\n", "1 2\n", "1 2 3 4\n", "1 4 3 2\n", "1 9 2 8 3 7 4 6 5\... | COMPETITION | PYTHON3 | CODEFORCES | 11,876 | |
c732013cef95ef8937614cd251b536f2 | UNKNOWN | There are $n$ water tanks in a row, $i$-th of them contains $a_i$ liters of water. The tanks are numbered from $1$ to $n$ from left to right.
You can perform the following operation: choose some subsegment $[l, r]$ ($1\le l \le r \le n$), and redistribute water in tanks $l, l+1, \dots, r$ evenly. In other words, repla... | ["n = int(input())\nl = list(map(int, input().split()))\n\nstack = []\nfor v in l:\n currVal = v\n currSize = 1\n div = v\n \n while stack:\n nex, nexS, nDiv = stack[-1]\n\n if div < nDiv:\n currSize += nexS\n currVal += nex\n stack.pop()\n\n div ... | {
"inputs": [
"4\n7 5 5 7\n",
"5\n7 8 8 10 12\n",
"10\n3 9 5 5 1 7 5 3 8 7\n",
"12\n8 10 4 6 6 4 1 2 2 6 9 5\n",
"7\n765898 894083 551320 290139 300748 299067 592728\n",
"13\n987069 989619 960831 976342 972924 961800 954209 956033 998067 984513 977987 963504 985482\n",
"1\n12345\n",
"2... | COMPETITION | PYTHON3 | CODEFORCES | 995 | |
3cc02886f66ff3d9cd49a84c948e3f9c | UNKNOWN | John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge.
John has been pa... | ["k = int(input())\np = [['0'] * 100 for j in range(100)]\ng = lambda n: n * (n * n - 1) // 6\ni = n = 0\nwhile g(n + 1) <= k: n += 1\nwhile i < n + 1:\n for j in range(i): p[i][j] = p[j][i] = '1'\n i += 1\nk -= g(n)\ng = lambda n: n * n - n >> 1\nwhile k:\n n = 0\n while g(n + 1) <= k: n += 1\n for j in... | {"inputs": ["1\n", "10\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "12\n", "19\n"], "outputs": ["3\n011\n101\n110\n", "5\n01111\n10111\n11011\n11101\n11110\n", "4\n0111\n1011\n1100\n1100\n", "5\n01001\n10111\n01001\n01001\n11110\n", "4\n0111\n1011\n1101\n1110\n", "5\n01001\n10111\n01011\n01101\n11110\n"... | COMPETITION | PYTHON3 | CODEFORCES | 4,831 | |
449e7063e9051ef9eacacd86a7eb3b20 | UNKNOWN | Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.
The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: ... | ["#!/usr/bin/env python\n# 556D_fug.py - Codeforces.com 556D Fug quiz\n#\n# Copyright (C) 2015 Sergey\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n# http://www.apache.org/license... | {
"inputs": [
"4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n",
"2 2\n11 14\n17 18\n2 9\n",
"2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999\n",
"5 10\n1 2\n3 3\n5 7\n11 13\n14 20\n9 10 2 9 10 4 9 9 9 10\n",
"5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5\n",
"6 9\n1 4\n10 1... | COMPETITION | PYTHON3 | CODEFORCES | 46,919 | |
ae650a65efd2b3d565f1b9c70ebfb8e2 | UNKNOWN | Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates $(x, y)$, such that $x_1 \leq x \leq x_2$ and $y_1 \leq y \leq y_2$, where... | ["# \nimport collections, atexit, math, sys\nfrom functools import cmp_to_key\n#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )\n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\nimport bisect \ntry :\n #raise ModuleNotFoundError\n import numpy\n d... | {
"inputs": [
"4\n4 1 3 2 3 2 1 3\n",
"3\n5 8 5 5 7 5\n",
"1\n553296794 23577639\n",
"2\n100000001 95312501 97600001 1\n",
"2\n1 499999999 705032704 1000000000\n",
"2\n81475384 79354071 83089784 94987161\n",
"2\n229872385 40870434 490042790 160550871\n",
"2\n186213023 151398020 5267074... | COMPETITION | PYTHON3 | CODEFORCES | 8,443 | |
6bd13d83a6c64a9fca0abf3be71c9e56 | UNKNOWN | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that t... | ["3\nn = int(input())\na = [True] * (n + 2)\nfor i in range(2, n + 2):\n if not a[i]:\n continue\n j = i * i\n while j < n + 2:\n a[j] = False\n j += i\nif n <= 2:\n print(1)\nelse:\n print(2)\nprint(' '.join('1' if x else '2' for x in a[2:]))\n", "def isprime(n):\n if n==2:\n ... | {"inputs": ["3\n", "4\n", "17\n", "25\n", "85\n", "105\n", "123\n", "1\n", "10\n", "2\n", "1\n", "2\n"], "outputs": ["2\n1 1 2 \n", "2\n1 1 2 1 \n", "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 \n", "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 \n", "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2... | COMPETITION | PYTHON3 | CODEFORCES | 10,250 | |
173ca64cb52a435ed97ba75535e09b2b | UNKNOWN | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | ["p, n = [], int(input())\na = b = 0\nfor i in range(n):\n t = list(map(int, input().split()))\n k = t[0] // 2 + 1\n a += sum(t[1: k])\n if t[0] & 1:\n p.append(t[k])\n b += sum(t[k + 1: ])\n else: b += sum(t[k: ])\np.sort(reverse = True)\nprint(a + sum(p[0 :: 2]), b + sum(p[1 :: 2]))", "n=... | {
"inputs": [
"2\n1 100\n2 1 10\n",
"1\n9 2 8 6 5 9 4 7 1 3\n",
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"1\n1 1\n",
"5\n1 3\n1 2\n1 8\n1 1\n1 4\n",
"3\n5 1 2 3 4 5\n4 1 2 3 4\n8 1 2 3 4 5 6 7 8\n",
"5\n5 1 1 ... | COMPETITION | PYTHON3 | CODEFORCES | 9,662 | |
133460c2545d497967e60b88ecf45dc9 | UNKNOWN | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | ["import sys\n\ns1, s2 = input().split()\nn = int(input())\n\nfor _ in range(n):\n print(s1, s2)\n killed, new = input().split()\n if s1 == killed:\n s1 = new\n else:\n s2 = new\n\nprint(s1, s2)\n", "def main():\n\ta, b = map(str, input().split())\n\tn = int(input())\n\tprint(a, b)\n\tfor i in... | {
"inputs": [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n",
"a b\n3\na c\nb d\nd e\n",
"ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg\n",
"q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\... | COMPETITION | PYTHON3 | CODEFORCES | 5,639 | |
25dc3b300c9ce78656de8ec6355342ed | UNKNOWN | 10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
- In the i-th query, you are gi... | ["def i1():\n return int(input())\ndef i2():\n return [int(i) for i in input().split()]\nq=i1()\nimport math\ny=[]\nfor i in range(q):\n y.append(i2())\n\nfor a,b in y:\n x=a*b\n c=int(math.sqrt(x))\n if c**2==x:\n c-=1\n z=2*c\n if c>0 and (x//c)==c:\n z-=1\n if c>0 and x%c==0 and (x//c-1)==c:\n z-=1\n if a<=c:... | {"inputs": ["8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n", "99\n207579013 207579013\n376140463 376140463\n186969586 186969586\n326402540 326402540\n158176573 158176573\n127860890 127860890\n570870045 570870045\n178509023 178509023\n61263305 61263305\n558212775 558212775\n26389630 26389630\n49614800... | COMPETITION | PYTHON3 | ATCODER.JP | 29,078 | |
c7a4a1df946f3e79d90f0fb7fcad98e7 | UNKNOWN | Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i} — the current skill level. All skills have the same maximum level A.
Along w... | ["import itertools\nimport bisect\n\nn, A, cf, cm, m = [int(x) for x in input().split()]\nskills = [int(x) for x in input().split()]\nsorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))\nbottom_lift = [0 for i in range(n)]\nfor i in range(1, n):\n bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills... | {
"inputs": [
"3 5 10 1 5\n1 3 1\n",
"3 5 10 1 339\n1 3 1\n",
"2 6 0 1 4\n5 1\n",
"1 1000000000 1000 1000 1000000000000000\n0\n",
"1 100 1 2 30\n1\n",
"1 100 1 2 30\n71\n",
"1 1000000000 1000 1000 1000000000000000\n1000000000\n",
"5 5 10 20 50\n0 0 0 0 0\n",
"5 5 10 20 50\n3 3 3 3 ... | COMPETITION | PYTHON3 | CODEFORCES | 11,301 | |
7dac8ba568fd54d4b749e53a81cea238 | UNKNOWN | You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ denotes the operation bitwise XOR).
An inversion in the $b$ array is a pair... | ["n = int(input())\nl = list(map(int, input().split()))\n\ninv = 0\nout = 0\nmult = 1\nfor i in range(32):\n curr = dict()\n opp = 0\n same = 0\n\n for v in l:\n if v ^ 1 in curr:\n if v & 1:\n opp += curr[v ^ 1]\n else:\n same += curr[v ^ 1]\n ... | {
"inputs": [
"4\n0 1 3 2\n",
"9\n10 7 9 10 7 5 5 3 5\n",
"3\n8 10 3\n",
"5\n1000000000 1000000000 1000000000 0 0\n",
"1\n0\n",
"3\n2 24 18\n",
"7\n23 18 5 10 29 33 36\n",
"19\n1 32 25 40 18 32 5 23 38 1 35 24 39 26 0 9 26 37 0\n",
"96\n79 50 37 49 30 58 90 41 77 73 31 10 8 57 73 9... | COMPETITION | PYTHON3 | CODEFORCES | 1,255 | |
86b266431408a43a792b983033595cce | UNKNOWN | Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p_1, p_2, ..., p_{n}. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two a... | ["3\n\nimport sys\n\nclass CumTree:\n \n def __init__(self, a, b):\n self.a = a\n self.b = b\n self.count = 0\n if a == b:\n return\n mid = (a + b) // 2\n self.levo = CumTree(a, mid)\n self.desno = CumTree(mid+1, b)\n \n def manjsi(self, t):\n ... | {
"inputs": [
"2\n1 2\n",
"5\n3 5 2 4 1\n",
"16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\n",
"9\n1 7 8 5 3 4 6 9 2\n",
"5\n2 3 4 5 1\n",
"9\n4 1 8 6 7 5 2 9 3\n",
"10\n3 4 1 5 7 9 8 10 6 2\n",
"13\n3 1 11 12 4 5 8 10 13 7 9 2 6\n",
"10\n8 4 1 7 6 10 9 5 3 2\n",
"2\n2 1\n",
"... | COMPETITION | PYTHON3 | CODEFORCES | 4,580 | |
b32eaae379baeecf52a4932f9c0a5393 | UNKNOWN | Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note that the order of the points inside the group of three chosen point... | ["def Search(L,aa,x):\n a=aa\n b=len(L)\n while(b-a>1):\n i=(b+a)//2\n if(L[i]>x):\n b=i\n elif(L[i]<x):\n a=i\n else:\n return (i+1)-aa-1\n return b-aa-1\n\nimport math\n\nn,d=list(map(int,input().split()))\n\nP=list(map(int,input().split()))\nan... | {
"inputs": [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n",
"10 5\n31 36 43 47 48 50 56 69 71 86\n",
"10 50\n1 4 20 27 65 79 82 83 99 100\n",
"10 90\n24 27 40 41 61 69 73 87 95 97\n",
"100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -6... | COMPETITION | PYTHON3 | CODEFORCES | 10,009 | |
8c46d88f32c24d6c72e7b6335c6d02fa | UNKNOWN | You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the chosen... | ["m = int(input())\ns = input().strip()\n\nsa = [0] * len(s)\nfor i in range(len(s)):\n\tsa[i] = ord(s[i]) - ord('a')\n\nsa = [-1] + sa + [-1]\n\ndef check_value(sa, m, threshold):\n\tprev_ind = 0\n\tfor i in range(len(sa)):\n\t\tif sa[i] <= threshold:\n\t\t\tif i - prev_ind <= m:\n\t\t\t\tprev_ind = i\n\t\t\telse:\n\t... | {
"inputs": [
"3\ncbabc\n",
"2\nabcab\n",
"3\nbcabcbaccba\n",
"5\nimmaydobun\n",
"5\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzknetdibv\n",
"10\nefispvmzuutsrpxzfrykhabznxiyquwvhwhrksrgzodtuepfvamilfdynapzhzyhncorhzuewrrkcduvuhwsrprjrmgctnvrdtp... | COMPETITION | PYTHON3 | CODEFORCES | 7,419 | |
c027e54ac7f0e9f488791a884c412e02 | UNKNOWN | Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i} stones. The players make their moves alternatively. A move is con... | ["n = int(input())\narr = [int(input()) for i in range(n)]\nb = [0 for i in range(n)]\ns = 0\nfor i in range(n):\n j = int((arr[i] << 1) ** 0.5)\n if j * (j + 1) > (arr[i] << 1):\n j -= 1\n s ^= j\nif s != 0:\n print('NO')\nelse:\n print('YES')\n", "from math import sqrt\nk = 0\nfor t in range(int... | {
"inputs": [
"1\n5\n",
"2\n1\n2\n",
"3\n34\n44\n21\n",
"6\n34\n44\n21\n55\n1\n36\n",
"14\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n",
"10\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n",
"12\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n",
"118\n34\n44\n21\n55\n1\n36\n53\n31... | COMPETITION | PYTHON3 | CODEFORCES | 1,026 | |
54971de4afdd2da15b5e41426c65a11c | UNKNOWN | You are given an array consisting of n non-negative integers a_1, a_2, ..., a_{n}.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array are destroyed.
After each element is destroyed you have to find out the seg... | ["__author__ = 'Think'\nn=int(input())\naints=[int(i) for i in input().split()]\npermutes=[int(i)-1 for i in input().split()]\nresults=[0]\n\nrebuilt={}\nm=0\nfor numby in range(n-1, 0, -1):\n\tp=permutes[numby]\n\tbelow=False\n\tabove=False\n\tif p-1 in rebuilt:\n\t\tbelow=True\n\tif p+1 in rebuilt:\n\t\tabove=True\n\... | {
"inputs": [
"4\n1 3 2 5\n3 4 1 2\n",
"5\n1 2 3 4 5\n4 2 3 5 1\n",
"8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n",
"10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8\n",
"17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4\n",
"17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 ... | COMPETITION | PYTHON3 | CODEFORCES | 19,372 | |
dd5ab2a65b68acfafcfff0d32615ee5e | UNKNOWN | Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: Add the integer x_{i} to the first a_{i} elements of the sequence. Append an integer k_{i} to the end of the sequence... | ["n = int(input())\na, b = [0] * (n + 2), [0] * (n + 2)\ns, l = 0, 1\np = [0] * n\nfor i in range(n):\n t = list(map(int, input().split()))\n if t[0] == 1:\n b[t[1] - 1] += t[2]\n s += t[1] * t[2]\n elif t[0] == 2:\n a[l] = t[1]\n l += 1\n s += t[1]\n else:\n l -= 1... | {
"inputs": [
"5\n2 1\n3\n2 3\n2 1\n3\n",
"6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3\n",
"1\n1 1 1\n",
"1\n2 1\n",
"2\n2 1\n1 2 1\n",
"5\n2 1\n1 2 1\n2 1\n2 1\n1 2 1\n",
"5\n1 1 7\n1 1 7\n1 1 7\n2 5\n1 2 2\n",
"5\n1 1 -48\n1 1 19\n1 1 -35\n2 -67\n1 2 -13\n",
"1\n1 1 0\n",
"1\n2 0\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 13,548 | |
f57832556f583283ce7a5655fa658ec3 | UNKNOWN | There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is ... | ["# -*- coding: utf-8 -*-\nfrom time import perf_counter\nfrom sys import stdin\n\ndef run(n, s):\n m = 0\n small = n // 2\n for big in range(n-1, (n+1)//2-1, -1):\n while small >= 0 and s[small] > s[big] / 2:\n small -= 1\n if small == -1:\n break\n #print(small, big... | {
"inputs": [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n",
"12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52\n",
"12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9\n",
"100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n9... | COMPETITION | PYTHON3 | CODEFORCES | 7,119 | |
61e0d1559f3fbcf311b137889fa06f29 | UNKNOWN | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | ["from bisect import bisect_left, insort_left\na = []\nn = int(input())\nfor _ in range(n):\n #print(a)\n s, d = list(map(int, input().split()))\n if len(a) == 0:\n print(s, s+d - 1)\n a.append((s, s + d - 1))\n continue\n p = bisect_left(a, (s, s + d - 1))\n #print('p', p)\n ok =... | {"inputs": ["3\n9 2\n7 3\n2 4\n", "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n", "1\n1 1\n", "1\n1000000000 1\n", "1\n1000000000 5000000\n", "5\n6 2\n10 1\n10 2\n9 2\n5 1\n", "10\n1 3\n77 8\n46 5\n83 4\n61 7\n8 4\n54 7\n80 7\n33 7\n13 4\n", "10\n588 12\n560 10\n593 14\n438 15\n761... | COMPETITION | PYTHON3 | CODEFORCES | 8,336 | |
c822e6eb9585779f2f7da79532321b02 | UNKNOWN | Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want to pick the best carrot as their present.
There are n carrots arranged in a... | ["def evens(A):\n n = len(A)\n l = n//2-1; r = n//2\n if len(A)%2 == 1: l+= 1\n ans = [max(A[l], A[r])]\n while r < n-1:\n l-= 1; r+= 1\n ans.append(max(ans[-1], A[l], A[r]))\n return ans\n\ndef interleave(A, B):\n q = []\n for i in range(len(B)): q+= [A[i], B[i]]\n if len(A) !=... | {
"inputs": [
"4\n1 2 3 5\n",
"5\n1000000000 1000000000 1000000000 1000000000 1\n",
"4\n1 12 3 5\n",
"5\n1 3 2 2 4\n",
"5\n1 2 3 2 1\n",
"1\n1941283\n",
"3\n2 8 2\n",
"3\n6 4 6\n",
"3\n5 8 7\n",
"40\n2 2 88 88 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 2 2 2 2 2 2 2 2 2 ... | COMPETITION | PYTHON3 | CODEFORCES | 616 | |
1f90082b0565ac2e95f599f5f1ad755b | UNKNOWN | Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.
In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge ... | ["from collections import defaultdict, deque\n \nadj = defaultdict(lambda: defaultdict(lambda: 0))\ndef bfs(graph, inicio, destino, parent):\n parent.clear()\n queue = deque()\n queue.append([inicio, float(\"Inf\")])\n parent[inicio] = -2\n while (len(queue)):\n current, flow = queue.popleft()\n ... | {
"inputs": [
"4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2\n",
"5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30\n",
"10 16 63\n1 2 1\n2 10 1\n1 3 1\n3 10 1\n1 4 1\n4 10 1\n1 5 1\n5 10 1\n1 6 1\n6 10 1\n1 7 1\n7 10 1\n1 8 1\n8 10 1\n1 9 1\n9 10 1\n",
"2 1 3\n1 2 301\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 13,748 | |
f103135eae58e6b3cc5f78f0b5a839e8 | UNKNOWN | For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisible on $x$. $\textrm{lcm}(s)$ is the minimum positive integer $x$, that divis... | ["\ndef Sieve(n): \n ret = []\n divlis = [-1] * (n+1) \n \n flag = [True] * (n+1)\n flag[0] = False\n flag[1] = False\n\n ind = 2\n while ind <= n:\n\n if flag[ind]:\n ret.append(ind)\n\n ind2 = ind ** 2\n\n while ind2 <= n:\n flag[ind2] = F... | {
"inputs": [
"2\n1 1\n",
"4\n10 24 40 80\n",
"10\n540 648 810 648 720 540 594 864 972 648\n",
"2\n199999 200000\n",
"2\n198761 199999\n",
"10\n972 972 324 972 324 648 1944 243 324 474\n",
"3\n166299 110866 86856\n",
"2\n10007 20014\n",
"2\n4 6\n",
"5\n25 25 5 5 5\n",
"2\n3... | COMPETITION | PYTHON3 | CODEFORCES | 1,251 | |
0ef3958d797f83be4e22eb19910091c6 | UNKNOWN | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (the... | ["class DisjointSet(object):\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n self.num = n # number of disjoint sets\n\n def union(self, x, y):\n self._link(self.find_set(x), self.find_set(y))\n\n def _link(self, x, y):\n if x == y:\n ... | {
"inputs": [
"3 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n",
"4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n",
"100000 0\n",
"100 3\n1 2 0\n2 3 0\n3 1 0\n",
"9 2\n1 2 0\n2 3 0\n",
"28567 13\n28079 24675 1\n18409 26720 1\n980 10815 1\n20794 16571 1\n7376 19861 1\n11146 706 1\n4255 16391 1\n27376 18263 1\... | COMPETITION | PYTHON3 | CODEFORCES | 2,503 | |
78a4ce827f98eb470f9d81a495789fab | UNKNOWN | Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of mi... | ["__author__ = 'Pavel Mavrin'\n\nn = int(input())\na = [int(x) for x in input().split()]\n\ns = 0\nres = 0\nfor i in a:\n if i == 0:\n res += s\n else:\n s += 1\n\nprint(res)\n", "import sys\nn=int(input())\nL=list(map(int,sys.stdin.readline().split()))\n\nz=L.count(0)\n\nif(z==n or z==0):\n prin... | {
"inputs": [
"4\n0 0 1 0\n",
"5\n1 0 1 0 1\n",
"50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0\n",
"100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0... | COMPETITION | PYTHON3 | CODEFORCES | 5,902 | |
e3312bedc5bd1f916332289b5d91d743 | UNKNOWN | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | ["3\n\nimport sys\nfrom functools import lru_cache\n\nMOD = 1000000007\n\ncnk = [[1 for i in range(1001)] for j in range(1001)]\nfor i in range(1, 1001):\n for j in range(1, i):\n cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j]\n\n\nk = int(input())\ncs = [int(input()) for i in range(k)]\n\nans = 1\nsm = 0\nfor... | {
"inputs": [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n",
"10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n",
"5\n10\n10\n10\n10\n10\n",
"11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2\n",
"1\n1\n",
"13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76\n",
"25\n35\n43\n38\n33\n47\n44\n4... | COMPETITION | PYTHON3 | CODEFORCES | 11,466 | |
0cd0a76432e39e8b203ac888fa8cf5c8 | UNKNOWN | There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the mi... | ["strings = int(input())\n\ncount = [0 for x in range(7)]\n\nfor k in range(strings):\n s = input()\n for index in range(7):\n if s[index] == '1':\n count[index] += 1\n\nprint(max(count))\n", "n = int(input())\ns = [0] * 7\nfor _ in range(n):\n\tmes = input()\n\tfor i in range(7):\n\t\ts[i] += (... | {
"inputs": [
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n",
"1\n0111000\n",
"1\n0000000\n",
"1\n1111111\n",
"2\n1000000\n0101000\n",
"3\n0101111\n1101011\n1010011\n",
"5\n0100101\n0000001\n0110000\n0010000\n0011110\n",
"6\n1101110\n1111011\n1101110\n0100011\n1110110\n1... | COMPETITION | PYTHON3 | CODEFORCES | 5,351 | |
6d2ea9324fde18cf8e5ea4f27ae67654 | UNKNOWN | Mitya has a rooted tree with $n$ vertices indexed from $1$ to $n$, where the root has index $1$. Each vertex $v$ initially had an integer number $a_v \ge 0$ written on it. For every vertex $v$ Mitya has computed $s_v$: the sum of all values written on the vertices on the path from vertex $v$ to the root, as well as $h_... | ["from collections import defaultdict, deque\n\nn = int(input())\nadj = [[] for _ in range(n)]\nv = [0] * n\nl = list(map(int, input().split()))\nfor i, f in enumerate(l):\n adj[f - 1].append(i + 1)\n\ns = list(map(int, input().split()))\n\nQ = deque([(0, s[0], s[0])])\nans = 0\nflag = False\npossible = True\nwhile ... | {
"inputs": [
"5\n1 1 1 1\n1 -1 -1 -1 -1\n",
"5\n1 2 3 1\n1 -1 2 -1 -1\n",
"3\n1 2\n2 -1 1\n",
"2\n1\n0 -1\n",
"2\n1\n1 -1\n",
"5\n1 2 2 3\n1 -1 2 3 -1\n",
"5\n1 2 3 4\n5 -1 5 -1 7\n",
"10\n1 1 1 1 2 3 4 5 1\n3 -1 -1 -1 -1 3 3 3 3 -1\n",
"10\n1 1 2 4 4 5 6 3 3\n0 -1 -1 0 -1 -1 1 2 ... | COMPETITION | PYTHON3 | CODEFORCES | 23,562 | |
3e9250666bf74943ec1d2ff43319ece3 | UNKNOWN | In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.
One example of a grid path is (0, 0) → (0, 1) → (0, 2) → (1, 2... | ["from time import time\n\n\nopposite = {\n 'N': 'S',\n 'S': 'N',\n 'E': 'W',\n 'W': 'E'\n}\notr = str.maketrans(opposite)\n\nbits = {\n 'N': 0,\n 'S': 1,\n 'E': 2,\n 'W': 3,\n}\n\nQ = 4294967291\n\n\ndef combine(h, v, q):\n return (h<<2 | v) % q\n\n\ndef combinel(h, v, q, s):\n return (v*... | {
"inputs": [
"7\nNNESWW\nSWSWSW\n",
"3\nNN\nSS\n",
"3\nES\nNW\n",
"5\nWSSE\nWNNE\n",
"2\nE\nE\n",
"2\nW\nS\n",
"2\nS\nN\n",
"100\nWNWWSWWSESWWWSSSSWSSEENWNWWWWNNENESWSESSENEENNWWWWWSSWSWSENESWNEENESWWNNEESESWSEEENWWNWNNWWNNWWWWSW\nEESEESSENWNWWWNWWNWWNWWSWNNWNWNWSWNNEENWSWNNESWSWNWSES... | COMPETITION | PYTHON3 | CODEFORCES | 1,856 | |
5d130679f49612f0cc20789e2b1ad21b | UNKNOWN | Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, th... | ["n, k = map(int, input().split())\nt = set(map(int, input().split()))\ny = x = min(t)\nt = list(t)\nwhile True:\n for i in t:\n if i % x > k: x = i // (i // x + 1)\n if y == x: break\n y = x\nprint(y)", "n,k=list(map(int,input().split()))\nt=set(map(int,input().split()))\ny=x=min(t)\nt=list(t)\nwhile T... | {
"inputs": [
"6 1\n3 6 10 12 13 16\n",
"5 3\n8 21 52 15 77\n",
"13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58\n",
"18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68\n",
"25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64\n",
"7 1\n12 84 21 60 33 21 45\n... | COMPETITION | PYTHON3 | CODEFORCES | 4,951 | |
d9c74692ea1b3951c27e586040031a3c | UNKNOWN | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations: Write parity(a) to... | ["print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO')", "a, b = input(), input()\nx, y = a.count('1'), b.count('1')\nprint('YNEOS'[x + (x & 1) < y :: 2])", "a = input()\nb = input()\n\nif ((a.count('1') + 1) // 2 * 2) >= b.count('1'):\n print(\"YES\")\nelse:\n print(\"NO\")", "a = input().r... | {
"inputs": [
"01011\n0110\n",
"0011\n1110\n",
"11111\n111111\n",
"0110011\n01100110\n",
"10000100\n011110\n",
"1\n0\n",
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111... | COMPETITION | PYTHON3 | CODEFORCES | 4,459 | |
d36000eb70394c39fecc91f0a729e6e4 | UNKNOWN | You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$).
Let's sort $p$ in non-decreasing order, and $q$ in non-increasing order, we can denote the sorted ... | ["\nimport sys\nfrom sys import stdin\n\ndef modfac(n, MOD):\n \n f = 1\n factorials = [1]\n for m in range(1, n + 1):\n f *= m\n f %= MOD\n factorials.append(f)\n inv = pow(f, MOD - 2, MOD)\n invs = [1] * (n + 1)\n invs[n] = inv\n for m in range(n, 1, -1):\n inv *= m\n ... | {
"inputs": [
"1\n1 4\n",
"2\n2 1 2 1\n",
"3\n2 2 2 2 2 2\n",
"5\n13 8 35 94 9284 34 54 69 123 846\n",
"1\n2 5\n",
"7\n2 5 6 25 22 21 7 9 7 22 25 25 22 24\n",
"5\n2 7 14 11 14 15 3 11 7 16\n",
"4\n4 9 5 13 5 6 5 13\n",
"10\n1 1 1 1 1 1 1 1 1 1 1000000000 1000000000 1000000000 10000... | COMPETITION | PYTHON3 | CODEFORCES | 1,887 | |
f9a4d0367f921c6d8c25b8130e636486 | UNKNOWN | While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers $a_1, a_2, \ldots, a_n$. Since the talk was long and not promising, Kostya created a new cyclic array $b_1, b_2, \ldots, b_{n}$ so that $b_i = (a_i \mod a_{i + 1})$, where we take $a_{n+1} = a_1$. Here $mod$ i... | ["n = int(input())\n\nb = list(map(int, input().split()))\n\nm, M = min(b), max(b)\nif m == M:\n if M == 0:\n print('YES')\n print(' '.join(['1' for i in range(n)]))\n else:\n print('NO')\nelse:\n print('YES')\n\n pos = list([i for i in range(n) if b[i] == M and b[i - 1] < M])[0]\n\n ... | {
"inputs": [
"4\n1 3 1 0\n",
"2\n4 4\n",
"5\n5 4 3 2 1\n",
"10\n3 3 3 5 6 9 3 1 7 3\n",
"100\n57 5 28 44 99 10 66 93 76 32 67 92 67 81 33 3 6 6 67 10 41 72 5 71 27 22 21 54 21 59 36 62 43 39 28 49 55 65 21 73 87 40 0 62 67 59 40 18 56 71 15 97 73 73 2 61 54 44 6 52 25 34 13 20 18 13 25 51 19 66 6... | COMPETITION | PYTHON3 | CODEFORCES | 504 | |
0997ac1ffec276b2d179c85cf6e06a9f | UNKNOWN | Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allow... | ["from bisect import *\n\nn, tc, td = [int(i) for i in input().split()]\nfc = []\nfd = []\nmbc = 0\nmbd = 0\nfor _ in range(n):\n b, p, ft = input().split()\n b, p = int(b), int(p)\n f = (p, b)\n if ft == 'C':\n if p <= tc:\n fc.append(f)\n mbc = max(mbc, b)\n else:\n ... | {
"inputs": [
"3 7 6\n10 8 C\n4 3 C\n5 6 D\n",
"2 4 5\n2 5 C\n2 1 D\n",
"3 10 10\n5 5 C\n5 5 C\n10 11 D\n",
"6 68 40\n1 18 D\n6 16 D\n11 16 D\n7 23 D\n16 30 D\n2 20 D\n",
"6 4 9\n6 6 D\n1 4 D\n6 7 C\n7 6 D\n5 7 D\n2 5 D\n",
"52 38 22\n9 25 D\n28 29 C\n29 25 D\n4 28 D\n23 29 D\n24 25 D\n17 12 C... | COMPETITION | PYTHON3 | CODEFORCES | 27,079 | |
909fc1b3c6a9e97a41995943e38092cf | UNKNOWN | Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct.
Ujan is lazy, so he will do the following reordering o... | ["\ndef main():\n k = int(input())\n n = []\n a = []\n for i in range(k):\n line = [int(x) for x in input().split()]\n ni = line[0]\n ai = []\n n.append(ni)\n a.append(ai)\n for j in range(ni):\n ai.append(line[1 + j])\n answer, c, p = solve(k, n, a)\n... | {
"inputs": [
"4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n",
"2\n2 3 -2\n2 -1 5\n",
"2\n2 -10 10\n2 0 -20\n",
"1\n1 0\n",
"3\n1 20\n2 30 40\n3 50 60 80\n",
"3\n3 1 3 100\n2 4 104\n2 2 102\n",
"4\n3 80 1 10\n3 52 19 24\n3 27 46 29\n3 74 13 25\n",
"2\n5 -1000000000 999999999 -999999998 999999997 0\... | COMPETITION | PYTHON3 | CODEFORCES | 11,726 | |
0717f59dcb5a0c1a11f8c1dafdd46cab | UNKNOWN | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | ["s = input()\nt = input()\n\nn = len(s)\nm = len(t)\n\nt = t + '$' + s\n\np = [0] * (n + m + 1)\nk = 0\nfor i in range(1, n + m + 1):\n while k > 0 and t[k] != t[i]:\n k = p[k - 1]\n if t[k] == t[i]:\n k += 1\n p[i] = k\n\nans = [0] * n\nsums = [0] * (n + 1)\ncurs = 0\nwas = False\nj = 0\nMOD = ... | {
"inputs": [
"ababa\naba\n",
"welcometoroundtwohundredandeightytwo\nd\n",
"ddd\nd\n",
"vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n",
"kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa\n",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n",
"a\na... | COMPETITION | PYTHON3 | CODEFORCES | 5,350 | |
e439de97f12fed8a631156dc4fc7a946 | UNKNOWN | Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.
In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.
Du will chat in the group for $n$ days. On the $i$-th day: If Du can speak, he'll make fun of Boboniu ... | ["import sys\nreadline = sys.stdin.readline\n\nN, D, M = map(int, readline().split())\nA = list(map(int, readline().split()))\nAm = [a for a in A if a > M]\nAo = [a for a in A if a <= M]\nAm.sort(reverse = True)\nAo.sort(reverse = True)\nCam = Am[:]\nCao = Ao[:]\n\nfor i in range(1, len(Cam)):\n Cam[i] += Cam[i-1]\n... | {
"inputs": [
"5 2 11\n8 10 15 23 5\n",
"20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n",
"1 1 0\n0\n",
"100 61 71\n11 18 0 47 33 75 91 13 8 21 73 64 50 97 62 50 2 36 68 32 64 74 32 77 81 41 23 44 40 36 45 33 21 68 57 79 75 23 67 37 99 27 30 56 75 62 75 63 46 19 79 42 11 66 21 25 2 12 89... | COMPETITION | PYTHON3 | CODEFORCES | 4,456 | |
f232db22b28c60bff83d98d2f5433e12 | UNKNOWN | Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and three different types of guns.
Namely, the two types of monsters are: a n... | ["n,r1,r2,r3,D = map(int,input().split())\n\nstate = [0,0] # after odd number of 2 (1st), or not (2nd)\n\na = list(map(int,input().split()))\n\n# First element\n\n# Choosing P~P + A\n\nstate[0] = r1 * a[0] + r3\n\n# Choosing L + P later or all P\n\nstate[1] = min(r2 + r1 + D, r1 * (a[0] + 2) + D)\n\n# Second to Second ... | {
"inputs": [
"4 1 3 4 3\n3 2 5 1\n",
"4 2 4 4 1\n4 5 1 2\n",
"2 2 5 7 3\n4 5\n",
"100 4 8 9 1\n1 8 1 8 7 8 1 8 10 4 7 7 3 2 6 7 3 7 3 7 1 8 5 7 4 10 9 7 3 4 7 7 4 9 6 10 4 5 5 2 5 3 9 2 8 3 7 8 8 8 10 4 7 2 3 6 2 8 9 9 7 4 8 6 5 8 5 2 5 10 3 6 2 8 1 3 3 7 6 1 5 8 9 9 2 2 9 3 7 3 3 3 10 10 3 5 10 1 3 ... | COMPETITION | PYTHON3 | CODEFORCES | 3,771 | |
410070b210150c0d511fb87ef264daef | UNKNOWN | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | ["import sys\n\ndef binpow(a, n, p):\n res = 1\n while n > 0:\n if n % 2 == 1:\n res = (res * a) % p\n a = (a * a) % p\n n >>= 1\n return res\n\ndef main():\n result = []\n \n t = int(sys.stdin.readline())\n for line in sys.stdin.readlines():\n p, q, b = list(... | {
"inputs": [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n",
"10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2\n",
"10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10\n",
"10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 ... | COMPETITION | PYTHON3 | CODEFORCES | 4,917 | |
b9e4879b67bf9b2d63c53f8fadc9be0e | UNKNOWN | In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with the $r$-th character as ... | ["import sys\ninput = sys.stdin.readline\n\nMOD = 987654103\n\nn = int(input())\nt = input()\n\nplace = []\nf1 = []\ne1 = []\n\ns = []\ncurr = 0\ncount1 = 0\nfor i in range(n):\n c = t[i]\n if c == '0':\n if count1:\n e1.append(i - 1)\n if count1 & 1:\n s.append(1)\n ... | {
"inputs": [
"5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n",
"1\n0\n1\n1 1 1\n",
"3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n",
"10\n0100001001\n10\n2 5 4\n10 2 1\n5 3 5\n2 9 2\n5 3 1\n3 3 3\n9 8 1\n5 3 1\n9 5 2\n2 3 6\n",
"5\n00010\n5\n5 3 1\n2 1 2\n4 1 1\n3 1 3\n2 1 3\n",
"50\n0111001110010110100100110111010101... | COMPETITION | PYTHON3 | CODEFORCES | 2,542 | |
0cf1ce8bfd666247f786725b7f292d54 | UNKNOWN | You are given an array $a$ of $n$ integers and an integer $s$. It is guaranteed that $n$ is odd.
In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to $s$.
The median of the array with odd leng... | ["\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,s=list(map(int,input().split()))\n\na=list(map(int,input().split()))\na.sort()\nmed=a[n//2]\n\nans=0\nif med>s:\n for i in range(n//2+1):\n if a[i]>s:\n ans+=a[i]-s\nelif med<s:\n for i in range(n//2,n):\n if s>a... | {
"inputs": [
"3 8\n6 5 8\n",
"7 20\n21 15 12 11 20 19 12\n",
"3 1\n1 2 5\n",
"1 100\n105\n",
"5 1\n2 2 4 6 1\n",
"1 100\n88\n",
"1 1\n100000\n",
"3 4\n1 2 5\n",
"1 1\n1\n",
"3 10\n5 5 10\n"
],
"outputs": [
"2",
"6",
"1",
"5",
"2",
"12",
"99999",... | COMPETITION | PYTHON3 | CODEFORCES | 13,429 | |
d519bdd2050f6968949f34951a6b0e9e | UNKNOWN | This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$. You can hack this problem only if you solve and lock both problems.
Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepa... | ["# \u7d20\u56e0\u6570\u5206\u89e3\ndef prime_decomposition(n):\n i = 2\n table = []\n while i * i <= n:\n while n % i == 0:\n n //= i\n table.append(i)\n i += 1\n if n > 1:\n table.append(n)\n return table\nimport sys\ninput = sys.stdin.readline\nN = int(input(... | {
"inputs": [
"3\n1 0 1\n",
"1\n1\n",
"3\n0 0 1\n",
"20\n0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 1 0\n",
"100\n1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 1 1... | COMPETITION | PYTHON3 | CODEFORCES | 14,954 | |
176af03ef1e1fba6b7aecedc107de9a8 | UNKNOWN | In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
We are sure that Mister B will solve the problem soon and will fly to the Mo... | ["#!/usr/bin/env python3\n\nfrom collections import defaultdict\n\nDEBUG = False\n\n\ndef main():\n if DEBUG:\n test()\n\n n = int(input())\n\n paths = cycles(n)\n\n print(len(paths))\n for p in paths:\n print('%d %s' % (len(p), ' '.join([str(v) for v in p])))\n\n\ndef cycles(n):\n \"\"\... | {"inputs": ["3\n", "5\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n"], "outputs": ["2\n3 1 2 3\n3 1 2 3\n", "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n", "4\n3 4 1 2\n3 2 3 4\n3 1 2 3\n3 3 4 1\n", "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n", "9\n3 6 1 2\n4 6 2 5 3\n3... | COMPETITION | PYTHON3 | CODEFORCES | 3,120 | |
31a379110bf062c717d171cfdade92f2 | UNKNOWN | Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he... | ["k, q = list(map(int, input().split()))\nt = [0] * (k + 1)\nt[1] = 1\nd = [0]\nn = i = 1\nwhile i < 1001:\n if 2000 * t[k] > i - 1e-7:\n d.append(n)\n i += 1\n else:\n t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)]\n n += 1\nfor i in range(q): print(d[int... | {
"inputs": [
"1 1\n1\n",
"2 2\n1\n2\n",
"3 5\n1\n4\n20\n50\n300\n",
"4 5\n2\n4\n30\n100\n1000\n",
"5 6\n1\n2\n3\n4\n5\n6\n",
"6 6\n10\n20\n30\n40\n50\n60\n",
"990 1\n990\n",
"7 10\n100\n200\n300\n400\n500\n600\n700\n800\n900\n1000\n",
"8 10\n50\n150\n250\n350\n450\n550\n650\n750\n... | COMPETITION | PYTHON3 | CODEFORCES | 674 | |
43ac5df1627a58d66940b3f367529a8f | UNKNOWN | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with ... | ["def main():\n n, m = list(map(int, input().split()))\n aa = []\n for _ in range(n):\n row = list(map(int, input().split()))\n row.append(0)\n aa.append(row)\n aa.append([0] * (m + 1))\n d1, d2, d3, d4 = ([[0] * (m + 1) for _ in range(n + 1)] for _ in (1, 2, 3, 4))\n for i in ran... | {
"inputs": [
"3 3\n100 100 100\n100 1 100\n100 100 100\n",
"4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n",
"3 3\n3 1 2\n3 2 0\n2 3 2\n",
"3 3\n1 10 1\n1 10 1\n1 10 1\n",
"3 3\n0 0 0\n0 10000 0\n0 0 0\n",
"3 3\n1 ... | COMPETITION | PYTHON3 | CODEFORCES | 19,665 | |
8ab8fc33d7bd8ee1cdee2a7ebdbb7191 | UNKNOWN | You are given a set Y of n distinct positive integers y_1, y_2, ..., y_{n}.
Set X of n distinct positive integers x_1, x_2, ..., x_{n} is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X: Take any integer x_{i} and multiply it by two, i.e. repl... | ["def main():\n from heapq import heapify, heapreplace\n input()\n s = set(map(int, input().split()))\n xx = [-x for x in s]\n heapify(xx)\n while True:\n x = -xx[0]\n while x != 1:\n x //= 2\n if x not in s:\n s.add(x)\n heapreplace(xx... | {
"inputs": [
"5\n1 2 3 4 5\n",
"6\n15 14 3 13 1 12\n",
"6\n9 7 13 17 5 11\n",
"10\n18 14 19 17 11 7 20 10 4 12\n",
"100\n713 716 230 416 3 2 597 216 779 839 13 156 723 793 168 368 232 316 98 257 170 27 746 9 616 147 792 890 796 362 852 117 993 556 885 73 131 475 121 753 508 158 473 931 527 282 54... | COMPETITION | PYTHON3 | CODEFORCES | 487 | |
58651f142c0e00f119a97c0da243a167 | UNKNOWN | Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$.
Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1... | ["def comp(x):\n for i in range(2, x):\n if x % i == 0:\n return True\n return False\n\nN = int(input())\n\nif N == 4:\n print('YES', '1', '3', '2', '4', sep = '\\n')\nelif comp(N):\n print('NO')\nelse:\n print('YES', '1', sep = '\\n')\n if N > 1:\n for i in range(2, N):\n ... | {"inputs": ["7\n", "6\n", "7137\n", "1941\n", "55004\n", "1\n", "2\n", "3\n", "4\n", "5\n"], "outputs": ["YES\n1\n2\n5\n6\n3\n4\n7\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n1\n", "YES\n1\n2\n", "YES\n1\n2\n3\n", "YES\n1\n3\n2\n4", "YES\n1\n2\n4\n3\n5\n"]} | COMPETITION | PYTHON3 | CODEFORCES | 1,168 | |
863c0ecaf195d4ad1a00b03ca7325590 | UNKNOWN | Polycarp took $n$ videos, the duration of the $i$-th video is $a_i$ seconds. The videos are listed in the chronological order, i.e. the $1$-st video is the earliest, the $2$-nd video is the next, ..., the $n$-th video is the last.
Now Polycarp wants to publish exactly $k$ ($1 \le k \le n$) posts in Instabram. Each vid... | ["import sys\nn,k = map(int, sys.stdin.readline().split())\narr = list(map(int, sys.stdin.readline().split()))\ntot = sum(arr)\nif tot % k != 0:\n\tprint('No')\n\treturn\ntot //= k\nidx,cur = 0,0\nans = []\nfor i in range(n):\n\tcur += arr[i]\n\tidx += 1\n\tif cur == tot:\n\t\tans.append(idx)\n\t\tidx = 0\n\t\tcur = 0\... | {
"inputs": [
"6 3\n3 3 1 4 1 6\n",
"3 3\n1 1 1\n",
"3 3\n1 1 2\n",
"3 1\n1 10 100\n",
"1 1\n3\n",
"2 1\n1 3\n",
"2 1\n3 3\n",
"2 2\n3 1\n",
"2 2\n1 3\n",
"4 2\n2 1 3 1\n"
],
"outputs": [
"Yes\n2 3 1 ",
"Yes\n1 1 1 ",
"No",
"Yes\n3 ",
"Yes\n1 ",
"Yes... | COMPETITION | PYTHON3 | CODEFORCES | 13,430 | |
c7f202dbe3abb655373105e6f03745e3 | UNKNOWN | Consider a tree $T$ (that is, a connected graph without cycles) with $n$ vertices labelled $1$ through $n$. We start the following process with $T$: while $T$ has more than one vertex, do the following:
choose a random edge of $T$ equiprobably;
shrink the chosen edge: if the edge was connecting vertices $v$ and $... | ["maxn=50+10\ng=[None]*maxn\ndp=[None]*maxn\nc=[None]*maxn\nsize=[0]*maxn\n\nfor i in range(0,maxn):\n c[i]=[0]*maxn\n c[i][0]=1\n for j in range(1,i+1):\n c[i][j]=c[i-1][j-1]+c[i-1][j]\n\nn=int(input())\nfor i in range(1,n+1):\n g[i]=[]\nfor i in range(1,n):\n u,v=input().split()\n u=int(u)\n ... | {"inputs": ["4\n1 2\n1 3\n1 4\n", "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "1\n", "10\n9 8\n7 4\n10 7\n6 7\n1 9\n4 9\n9 3\n2 3\n1 5\n", "20\n13 11\n4 12\n17 16\n15 19\n16 6\n7 6\n6 8\n12 2\n19 20\n1 8\n4 17\n18 12\n9 5\n14 13\n11 15\n1 19\n3 13\n4 9\n15 10\n", "30\n15 21\n21 3\n22 4\n5 18\n26 25\n12 24\n11 2\n27 13\n11 14\... | COMPETITION | PYTHON3 | CODEFORCES | 1,233 | |
77c6947f48c9d561a1bef5f45be17606 | UNKNOWN | Koa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form:
In one operation Koa selects positions $i$ and $i+1$ for some $i$ with $1 \le i < |s|$ and sets $s_i$ to $max(s_i, s_{i+1})$. Then Koa deletes position $i+1$ from $s$ (after the rem... | ["import sys\nreadline = sys.stdin.readline\n\nMOD = 10**9+7\nS = readline().strip().split('1')\nif len(S) == 1:\n print(len(S[0]))\nelse:\n S = [len(s)+1 for s in S]\n ans = S[0]*S[-1]\n S = S[1:-1]\n \n dp = [0]*(max(S)+2)\n dp[0] = 1\n for ai in S:\n res = 0\n rz = 0\n fo... | {
"inputs": [
"000\n",
"0101\n",
"0001111\n",
"00101100011100\n",
"0\n",
"11\n",
"01011111111101101100000100000000100000111001011011110110110010010001011110100011000011100100010001\n",
"0100111100100101001101111001011101011001111100110111101110001001010111100010011100011011101111010111... | COMPETITION | PYTHON3 | CODEFORCES | 7,567 | |
e12adc652830d112b6227fcce59dbb16 | UNKNOWN | Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is $\{0,1,…,M-1\}$, for some positive integer $M$. Ajs draws a number from the first bag and a... | ["import sys\ninput = sys.stdin.readline\n\ndef main():\n n, m = map(int, input().split())\n a = list(map(int, input().split())) + [0]*500000\n ans_S = 0\n a[n] = a[0] + m\n s = [0]*600600\n for i in range(n):\n s[i] = a[i + 1] - a[i]\n s[n] = -1\n for i in range(n):\n s[2*n - i] =... | {
"inputs": [
"2 5\n3 4\n",
"4 1000000000\n5 25 125 625\n",
"2 4\n1 3\n",
"1 2\n1\n",
"14 34\n1 2 4 7 10 12 13 18 19 21 24 27 29 30\n",
"36 81\n4 5 7 8 13 14 16 17 22 23 25 26 31 32 34 35 40 41 43 44 49 50 52 53 58 59 61 62 67 68 70 71 76 77 79 80\n",
"9 10\n1 2 3 4 5 6 7 8 9\n",
"3 10... | COMPETITION | PYTHON3 | CODEFORCES | 950 | |
db272f8abf1e5ba93ee3fe71cab0a692 | UNKNOWN | Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of gia... | ["def init_factorials(N, mod):\n f = 1\n fac = [1] * N\n for i in range(1, N):\n f *= i\n f %= mod\n fac[i] = f\n return fac\n\ndef init_inv(N, mod, fac):\n b = bin(mod-2)[2:][-1::-1]\n ret = 1\n tmp = fac[N]\n if b[0] == '1':\n ret = fac[N]\n for bi in b[1:]:\n ... | {
"inputs": [
"3 4 2\n2 2\n2 3\n",
"100 100 3\n15 16\n16 15\n99 88\n",
"1000 1000 4\n50 50\n51 50\n50 51\n51 51\n",
"100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000\n",
"2 2 2\n2 1\n1 2\n",
"100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\... | COMPETITION | PYTHON3 | CODEFORCES | 17,379 | |
dc908ea3c5235ea55af3c87d7867a38e | UNKNOWN | Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n steps. On the i-th step Greg removes vertex number x_{i} from the graph. As... | ["import sys\nfrom array import array # noqa: F401\n\nn = int(input())\nmatrix = [array('i', list(map(int, input().split()))) for _ in range(n)]\naa = tuple([int(x) - 1 for x in input().split()])\nans = [''] * n\n\nfor i in range(n-1, -1, -1):\n x = aa[i]\n\n for a in range(n):\n for b in range(n):\n ... | {
"inputs": [
"1\n0\n1\n",
"2\n0 5\n4 0\n1 2\n",
"4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n",
"4\n0 57148 51001 13357\n71125 0 98369 67226\n49388 90852 0 66291\n39573 38165 97007 0\n2 3 1 4\n",
"5\n0 27799 15529 16434 44291\n47134 0 90227 26873 52252\n41605 21269 0 9135 55784\n70744 17563... | COMPETITION | PYTHON3 | CODEFORCES | 692 | |
5ae8581533bfb5cb570a3e8dd06b7083 | UNKNOWN | You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$.
Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$.
-----Input-----
The first line contains integers $n, p, k$ ($2 \le n \le 3 \cdot 10^5$, $2 \le p \l... | ["def check(num1, num2, p, k):\n v = num1 + num2\n v *= num1 * num1 + num2 * num2\n v %= p\n v += p\n v %= p\n return v == k % p\n\ndef __starting_point():\n\n n, p, k = (int(x) for x in input().split())\n idx___number = [int(x) for x in input().split()]\n\n idx___precount = [((pow(x, 4, p) -... | {
"inputs": [
"3 3 0\n0 1 2\n",
"6 7 2\n1 2 3 4 5 6\n",
"5 5 3\n3 0 4 1 2\n",
"7 7 3\n4 0 5 3 1 2 6\n",
"2 2 1\n1 0\n",
"3 3 0\n0 2 1\n",
"2 2 0\n1 0\n",
"3 3 1\n0 2 1\n",
"3 3 2\n0 1 2\n"
],
"outputs": [
"1",
"3",
"1",
"0",
"1",
"1",
"0",
"1",
... | COMPETITION | PYTHON3 | CODEFORCES | 6,992 | |
0c1989ced4acd68841a335fe51f7da0e | UNKNOWN | There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut ... | ["import heapq\n\ndef sum_sqaure(a, k):\n q, r = divmod(a, k)\n return q**2 * (k-r) + (q+1)**2 * r\n\ndef diff(a, k):\n return sum_sqaure(a, k+1) - sum_sqaure(a, k)\n\nn, k = map(int, input().split())\nnums = list(map(int, input().split()))\n\ncurr = sum(sum_sqaure(a, 1) for a in nums)\nQ = [(diff(a, 1), a, 1)... | {
"inputs": [
"3 6\n5 3 1\n",
"1 4\n19\n",
"1 3\n1000000\n",
"1 1\n1\n",
"10 23\n343 984 238 758983 231 74 231 548 893 543\n",
"20 40\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
"29 99047\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931... | COMPETITION | PYTHON3 | CODEFORCES | 1,651 | |
b81ae2c0d16424b435b3d79330ad0682 | UNKNOWN | Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value init_{i}, whi... | ["import sys\n\ndef dfs(tree, root, priv_root, cur_lvl, priv_lvl, diff, pick_list):\n if not tree:\n return\n stack = [(root, priv_root, cur_lvl, priv_lvl)]\n while stack:\n (root, priv_root, cur_lvl, priv_lvl) = stack.pop()\n if cur_lvl ^ diff[root]:\n cur_lvl ^= 1\n ... | {
"inputs": [
"10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n",
"15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0\n",
"20\n2 1\n3 2\n4 3\n5 4\n6 4\n7 1\n8 2\n9 4\n... | COMPETITION | PYTHON3 | CODEFORCES | 28,471 | |
e9f63fe4347150e5f79b858c5330b4df | UNKNOWN | Let's assume that v(n) is the largest prime number, that does not exceed n;
u(n) is the smallest prime number strictly greater than n.
Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$.
-----Input-----
The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.
Each of the following t lines of the ... | ["def prime(n):\n m = int(n ** 0.5) + 1\n t = [1] * (n + 1)\n for i in range(3, m):\n if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)\n return [2] + [i for i in range(3, n + 1, 2) if t[i]]\n\ndef gcd(a, b):\n c = a % b\n return gcd(b, c) if c else b\n\np = prime(31650)\ndef g(n)... | {
"inputs": [
"2\n2\n3\n",
"1\n1000000000\n",
"5\n3\n6\n9\n10\n5\n",
"5\n5\n8\n18\n17\n17\n",
"5\n7\n40\n37\n25\n4\n",
"5\n72\n72\n30\n75\n11\n",
"5\n79\n149\n136\n194\n124\n",
"6\n885\n419\n821\n635\n63\n480\n",
"1\n649580447\n"
],
"outputs": [
"1/6\n7/30\n",
"99999994... | COMPETITION | PYTHON3 | CODEFORCES | 4,059 | |
dfc52efa7a8e2b63bc36146ffeabe5ff | UNKNOWN | Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}.
Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a_{l} | a_{l} + 1 | ... | a_{r}.
Polycarpus ... | ["n, p, q = input(), set(), set()\nfor i in map(int, input().split()):\n q = set(i | j for j in q)\n q.add(i)\n p.update(q)\nprint(len(p))", "n, p, q = input(), set(), set()\nfor i in map(int, input().split()):\n q = set(i | j for j in q)\n q.add(i)\n p.update(q)\nprint(len(p))", "n, a, b = input(), s... | {
"inputs": [
"3\n1 2 0\n",
"10\n1 2 3 4 5 6 1 2 9 10\n",
"1\n123\n",
"10\n6 8 4 5 1 9 10 2 3 7\n",
"7\n1 2 4 8 16 32 64\n",
"10\n375813 659427 484038 348181 432640 368050 271089 721588 345312 630771\n",
"5\n0 1 2 0 4\n",
"1\n0\n",
"1\n1000000\n"
],
"outputs": [
"4",
"1... | COMPETITION | PYTHON3 | CODEFORCES | 3,452 | |
e15cd290080fd75be82e8756c665c3c8 | UNKNOWN | After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest... | ["buck = [[0, 0] for i in range(2201)]\nm = int(input())\nfor i in range(m):\n a = int(input())\n ok = True\n br = 0\n for j in range(2200, -1, -1):\n if a & (1 << j):\n if(buck[j][0]):\n a ^= buck[j][0]\n br ^= buck[j][1]\n else:\n ... | {
"inputs": [
"7\n7\n6\n5\n4\n3\n2\n1\n",
"2\n5\n5\n",
"10\n81\n97\n12\n2\n16\n96\n80\n99\n6\n83\n",
"10\n15106\n13599\n69319\n33224\n26930\n94490\n85089\n60931\n23137\n62868\n",
"10\n5059464500\n8210395556\n3004213265\n248593357\n5644084048\n9359824793\n8120649160\n4288978422\n183848555\n81358459... | COMPETITION | PYTHON3 | CODEFORCES | 1,850 | |
630ef7421a84ad63726a89293fc02371 | UNKNOWN | Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on... | ["n = int(input())\ns = list(map(int,input().split(' ')))\na = []\nfor i in range(max(s)):\n a.append([]) \nfor i in range(len(s)):\n a[s[i]-1].append(i)\na = list([x for x in a if x != []])\nif len(a) > 1:\n for i in range(1,len(a)):\n if len(a[i]) > 1:\n s = a[i-1][-1]\n if s ... | {
"inputs": [
"4\n6 3 1 2\n",
"1\n1000\n",
"7\n3 3 3 3 3 3 3\n",
"64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256 404 852 496 373 322 716 202 689 857 936 806 556 153 137 863 1047 678 564 474 282 135 610 176 855 360... | COMPETITION | PYTHON3 | CODEFORCES | 3,427 | |
56905c6b66146772a2dae95b23d3b115 | UNKNOWN | The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n.
This time the Little Elephant has permutation p_1, p_2, ..., p_{n}. Its... | ["inp = input().split(' ')\nval=[];\n\ntotNums = int(inp[0]); totOpt = int(inp[1]);\ninp = input().split(' '); #assert(len(inp) == totNums);\nfor it in inp: val.append(int(it))\n\ndp = [[0.0 for _ in range(0,totNums)] for __ in range(0,totNums)]\nfor i in range(0,totNums):\n for j in range(0,totNums):\n if va... | {
"inputs": [
"2 1\n1 2\n1 2\n",
"4 3\n1 3 2 4\n1 2\n2 3\n1 4\n",
"7 4\n7 6 4 2 1 5 3\n1 3\n2 1\n7 2\n3 5\n",
"10 1\n1 2 3 4 5 6 7 8 9 10\n1 10\n",
"9 20\n9 8 7 6 5 4 3 2 1\n4 6\n9 4\n5 9\n6 8\n1 9\n5 8\n6 9\n7 3\n1 9\n8 3\n4 5\n9 6\n3 8\n4 1\n1 2\n3 2\n4 9\n6 7\n7 5\n9 6\n",
"20 7\n3 17 7 14 ... | COMPETITION | PYTHON3 | CODEFORCES | 845 | |
b376141aea5d14e8d91764a2ab8b3cff | UNKNOWN | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the i-th safe fro... | ["q, b, c = list(map(int, input().split()))\nn = int(input())\na = list(map(int, input().split()))\nans = 0\nfor i in a:\n\tif b < i < c:\n\t\tans += 1\nprint(ans)\n", "a, b, c = list(map(int, input().split(' ')))\nn = int(input())\nl = list(map(int, input().split(' ')))\n\nres = 0\nfor x in l:\n if x > b and x < c:... | {
"inputs": [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n",
"3 2 4\n1\n3\n",
"5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6\n",
"7 3 10\n5\n3 3 3 3 3\n",
"3 2 5\n4\n1 3 4 5\n",
"3 2 4\n1\n1\n",
"6 4 8\n1\n4\n",
"2 1 3\n1\n3\n"
],
"outputs": [
"4\n",
"0\n",
"1\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 4,783 | |
d2867e70a885e6873514c1c626ad6cc9 | UNKNOWN | There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or several people come to the door and it is open, all people immediatel... | ["def solve():\n n1, m, a, d = list(map(int, input().split()))\n t = list(map(int, input().split()))\n from bisect import insort\n from math import floor\n insort(t, a * n1)\n pred = 0\n k = 0\n kpred = 0\n n = 0\n step = d // a + 1\n sol = 0\n fl = 0\n for i in t:\n if (i ... | {
"inputs": [
"1 1 3 4\n7\n",
"4 3 4 2\n7 9 11\n",
"10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n",
"70 10 26 17\n361 371 579 585 629 872 944 1017 1048 1541\n",
"100 20 49 52\n224 380 690 1585 1830 1973 2490 2592 3240 3341 3406 3429 3549 3560 3895 3944 4344 4390 4649 4800\n",
"100 30 ... | COMPETITION | PYTHON3 | CODEFORCES | 3,503 | |
9a8d4f8cd2017979fcbfdc5c606969c0 | UNKNOWN | Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send a_{i} requests.
Polycarp plans to test Fakebook under a special kind... | ["n = int(input())\n\na = list(map(int, input().split()))\n\nlp,rp = [0 for i in range(n)],[0 for i in range(n)]\nlnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)]\nmx = a[0]\nfor i in range(1,n):\n if a[i] > mx:\n mx = a[i]\n lp[i] = lp[i-1]\n else:\n mx += 1\n lp[i] = lp[i... | {
"inputs": [
"5\n1 4 3 2 5\n",
"5\n1 2 2 2 1\n",
"7\n10 20 40 50 70 90 30\n",
"1\n1\n",
"2\n1 15\n",
"4\n36 54 55 9\n",
"5\n984181411 215198610 969039668 60631313 85746445\n",
"10\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916\n",
"1... | COMPETITION | PYTHON3 | CODEFORCES | 6,441 | |
b73a007e10e09b5ad2074201dd1447fe | UNKNOWN | Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea... | ["oleg = input()\nigor = input()\noleg = sorted(list(oleg))\nigor = sorted(list(igor))\nn = len(oleg)\noleg_turns = (n + 1) // 2\nigor_turns = n // 2\nmin_oleg_id = 0\nmin_igor_id = n - igor_turns\nans = ['?'] * n\nmax_oleg_id = oleg_turns - 1 \nmax_igor_id = n - 1\ncurr_turn = 'o'\nnext_turn = {'o' : 'i', 'i' : 'o'}\n... | {
"inputs": [
"tinkoff\nzscoder\n",
"xxxxxx\nxxxxxx\n",
"ioi\nimo\n",
"abc\naaa\n",
"reddit\nabcdef\n",
"cbxz\naaaa\n",
"bcdef\nabbbc\n",
"z\ny\n",
"y\nz\n"
],
"outputs": [
"fzfsirk\n",
"xxxxxx\n",
"ioi\n",
"aab\n",
"dfdeed\n",
"abac\n",
"bccdb\n",
... | COMPETITION | PYTHON3 | CODEFORCES | 18,387 | |
2b9368e660968f444988ccc8c71d84e1 | UNKNOWN | We start with a string $s$ consisting only of the digits $1$, $2$, or $3$. The length of $s$ is denoted by $|s|$. For each $i$ from $1$ to $|s|$, the $i$-th character of $s$ is denoted by $s_i$.
There is one cursor. The cursor's location $\ell$ is denoted by an integer in $\{0, \ldots, |s|\}$, with the following mean... | ["import sys\nmod = 10**9 + 7\n\nfor _ in range(int(input())):\n x = int(input())\n s = list(map(int, input()))\n ans = len(s)\n for i in range(1, x+1):\n ans = (i + (ans-i) * s[i-1]) % mod\n r = len(s)\n for _ in range(s[i-1]-1):\n if len(s) < x:\n s += s[i:r]... | {
"inputs": [
"4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n",
"9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n",
"1\n1000000\n22\n",
"1\n1000000\n221\n",
"1\n1000000\n1221\n",
"1\n10000... | COMPETITION | PYTHON3 | CODEFORCES | 3,695 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.