problem_id stringlengths 32 32 | name stringlengths 2 54 | problem stringlengths 204 5.28k | solutions listlengths 1 5.17k | test_cases stringlengths 38 86.7k | difficulty stringclasses 1
value | language stringclasses 1
value | source stringclasses 1
value | num_solutions int64 1 5.17k | starter_code stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|
c59ca7de6700cc5a4c83078af6170202 | The Monster and the Squirrel | Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other v... | [
"#!/usr/bin/env python3\n\nfrom sys import stdin\n\nn = int(stdin.readline().strip())\n\nout = (n - 2) ** 2\n\nprint(out)\n",
"import sys\n\n\n#sys.stdin = open(\"input.txt\")\n#sys.stdout = open(\"output.txt\", \"w\")\n\nn = int(input())\nans = (n - 4) * (n - 3) + 2 * (n - 3) + (n - 2)\nprint(ans) ",
"# print... | {"inputs": ["5", "3", "54321", "4", "6", "7", "8", "9", "10", "54320", "54319", "54318", "54317", "54316", "54315", "54314", "8153", "51689", "16659", "47389", "314", "23481", "20380", "1994"], "outputs": ["9", "1", "2950553761", "4", "16", "25", "36", "49", "64", "2950445124", "2950336489", "2950227856", "2950119225",... | UNKNOWN | PYTHON3 | CODEFORCES | 113 | |
c5ae15dcd5da50929da25698093ceacc | Second Order Statistics | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | [
"n = int(input())\r\na = list(map(int,input().split()))\r\na = set(a)\r\na = list(a)\r\na.sort()\r\nif not len(a) ==1:\r\n print(a[1])\r\nelse:\r\n print('NO')",
"n=int(input())\na=[int(x) for x in input().split()]\na=list(set(a))\na.sort()\nif(len(a)==1):\n print(\"NO\")\nelse:\n print(a[1])\n\t \t\... | {"inputs": ["4\n1 2 2 -4", "5\n1 2 3 1 1", "1\n28", "2\n-28 12", "3\n-83 40 -80", "8\n93 77 -92 26 21 -48 53 91", "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49", "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 ... | UNKNOWN | PYTHON3 | CODEFORCES | 442 | |
c5c5681c6f810bdbc9e8ce105d24d625 | Round Subset | Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\nm = 30 * n\r\na = list(map(int, input().split()))\r\ninf = 114514\r\ndp = [[-inf] * (m + 1) for _ in range(n + 1)]\r\ndp[0][0] = 0\r\ndp0 = [0] * (n + 1)\r\nfor i in range(n):\r\n ai = a[i]\r\n x, y = 0, 0\r\n while not ai... | {"inputs": ["3 2\n50 4 20", "5 3\n15 16 3 25 9", "3 3\n9 77 13", "1 1\n200000000", "1 1\n3", "3 1\n1000000000000000000 800000000000000000 625", "20 13\n93050001 1 750000001 950000001 160250001 482000001 145875001 900000001 500000001 513300001 313620001 724750001 205800001 400000001 800000001 175000001 875000001 8526860... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
c5ca3ab2eac89426a9d116a1fd9ce067 | Little Girl and Maximum Sum | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)... | [
"\r\n\r\nfrom sys import stdin\r\n\r\ndef get_input():\r\n # Faster IO\r\n input_str = stdin.read().strip().split('\\n')\r\n n, q = map(int, input_str[0].split())\r\n arr = list(map(int, input_str[1].split()))\r\n queries = [map(int, input_str[i].split()) for i in range(2, len(input_str))]\r\n\r\n ... | {"inputs": ["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "16 ... | UNKNOWN | PYTHON3 | CODEFORCES | 92 | |
c5ea6b1be53adf0faf640c2b06b4178e | Seating On Bus | Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<=≤<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to... | [
"def main():\n n, m = map(int, input().split())\n bus = [[None for _ in range(4)] for _ in range(n)]\n half = 2 * n\n for i in range(0, 2 * n, 2):\n row = i // 2\n bus[row][0] = i + 1\n bus[row][3] = i + 2\n bus[row][1] = half + i + 1\n bus[row][2] = half + i + 2\n\n ... | {"inputs": ["2 7", "9 36", "1 1", "1 4", "10 1", "10 10", "10 40", "10 39", "77 1", "77 13", "77 53", "77 280", "100 1", "100 13", "100 77", "100 103", "100 200", "100 199", "100 201", "100 300", "100 399", "100 400", "3 9"], "outputs": ["5 1 6 2 7 3 4", "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 3... | UNKNOWN | PYTHON3 | CODEFORCES | 88 | |
c5f46d86f67634da80c5333c585ae150 | Phone Numbers | And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed... | [
"a,b = map(int,input().split(' '))\ns = input()\ns1 = sorted(set(s))\n\nif b>a:\n\tprint(s+s1[0]*(b-a))\nelse:\n\ti = b-1\n\twhile s[i]>=s1[-1] and i>-1:\n\t\ti -= 1\n\td = s1.index(s[i])\n\tprint(s[:i]+s1[d+1]+s1[0]*(b-i-1))",
"import sys\r\n\r\ninput = lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\n\r\nn, k ... | {"inputs": ["3 3\nabc", "3 2\nabc", "3 3\nayy", "2 3\nba", "1 3\nf", "3 1\nazz", "3 3\nzbf", "2 3\ngi", "3 2\nyzy", "5 10\nkekff", "10 5\nhqqqqcdddb", "10 10\nmrfkcsxcuj", "10 3\nggjnohlepu", "8 9\npppppppp", "10 7\nffffffffyf", "10 2\nkmiejhcimj", "10 1\ngiwekrmngf", "8 8\nlolololo", "10 9\nbcegikmyyy", "7 5000\nqqqqq... | UNKNOWN | PYTHON3 | CODEFORCES | 57 | |
c60017dd2b08478f814800ebfa6f9f27 | Guess Your Way Out! II | Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the nodes of the tree such t... | [
"import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(h, Q):\r\n L1, R1 = 2**(h-1), 2**h-1\r\n Q1 = []\r\n n = 0\r\n for i, L, R, ans in Q:\r\n L2, R2 = 2**(h-i)*L, 2**(h-i)*R+2**(h-i)-1\r\n if ans==0:\r\n Q1.append([L2, 0, n])\r\n Q1.append([R2, 1, n])... | {"inputs": ["3 1\n3 4 6 0", "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "4 2\n3 4 6 1\n4 12 15 1", "4 2\n3 4 5 1\n2 3 3 1", "1 0", "1 1\n1 1 1 0"], "outputs": ["7", "14", "Data not sufficient!", "Game cheated!", "1", "Game cheated!"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
c64702b7496904c374deec17f72e5c05 | Odd sum | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequen... | [
"n =int(input())\r\nns = map(int,input().split())\r\nint_max = 1000000\r\n\r\nsumm = 0\r\nm = int_max\r\n\r\nfor e in ns:\r\n if e > 0:\r\n summ += e\r\n if e % 2 != 0:\r\n m = min(m, abs(e))\r\n\r\nif summ % 2 == 0:\r\n summ -= m \r\n\r\nprint(summ)",
"n = int(input())\na = list(map(int, i... | {"inputs": ["4\n-2 2 -3 1", "3\n2 -5 -3", "1\n1", "1\n-1", "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046", "2\n-5439 -6705", "2\n2850 6843", "2\n144 9001", "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757", "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197", "10\n... | UNKNOWN | PYTHON3 | CODEFORCES | 102 | |
c6729c66bbbfd7bb2760347f9870b5b0 | Sum of Remainders | Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7).
The modulo operator *a* mod *b* stands for the remainder after dividing *a* by *b*. For example 10 mod 3 = 1.
Th... | [
"#n,m=list(map(int,input().split()))\r\n#Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. \r\n# As the result can be very large, \r\n# you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).\r\n\r\n# for i in range(1,151):\r\n# print(f\"100 %{i}={100%i}\")\... | {"inputs": ["3 4", "4 4", "1 1", "20000000 10000000", "10000000000000 10000000000000", "1 10000000000000", "10000000000000 1", "100 100", "1000 1000", "500 1000", "1010 435", "997167959139 7344481199252", "7244641009859 6300054748096", "3483524125987 5259923264237", "9726702209411 4215496813081", "5965585325539 3175365... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
c6cb6358e37594008f8beb2f16fd86b0 | Kindergarten | In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maxim... | [
"import sys\r\n\r\ninf = float('inf')\r\n\r\ndef read_int():\r\n res = b''\r\n \r\n while True:\r\n d = sys.stdin.buffer.read(1)\r\n if d == b'-' or d.isdigit():\r\n res += d\r\n elif res:\r\n break\r\n \r\n return int(res)\r\n\r\nn = read_int()\r\n\r\ndp, neg, po... | {"inputs": ["5\n1 2 3 1 2", "3\n3 3 3", "1\n0", "2\n-1000000000 1000000000", "4\n1 4 2 3", "4\n23 5 7 1", "4\n23 7 5 1", "8\n23 2 7 5 15 8 4 10", "8\n4 5 3 6 2 7 1 8"], "outputs": ["3", "0", "0", "2000000000", "4", "24", "22", "37", "16"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
c6e9fbfb051ff01b6a80e52bde08d396 | LCM Challenge | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | [
"import math\r\n\r\ndef main():\r\n n = int(input())\r\n if n <= 3:\r\n ans = 1\r\n for i in range(1,n+1):\r\n ans *= i\r\n print(ans)\r\n return\r\n if n%2 == 0:\r\n #print(n,n-1,n-3)\r\n if n%3 == 0:\r\n print((n-3)*(n-1)*(n-2))\r\n e... | {"inputs": ["9", "7", "1", "5", "6", "33", "21", "2", "41", "29", "117", "149", "733", "925", "509", "829", "117", "605", "245", "925", "213", "53", "341", "21", "605", "149", "733", "117", "53", "245", "829", "924", "508", "700", "636", "20", "604", "796", "732", "412", "700", "244", "828", "508", "796", "636", "924",... | UNKNOWN | PYTHON3 | CODEFORCES | 122 | |
c6fc6efb4116f26068ba51942a03faac | Mahmoud and Ehab and the xor | Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to... | [
"n, x = map(int, input().split())\nif n == 1:\n print(\"YES\")\n print(x)\n exit()\nelif n == 2:\n if x == 0:\n print(\"NO\")\n else:\n print(\"YES\")\n print(0, x)\n exit()\nl = [i for i in range(1, n-2)]\nv = 0\nfor i in range(1,n-2):\n v = v^i\nr1 = x^v\nr1 ^= 2**17 + 2*... | {"inputs": ["5 5", "3 6", "3 0", "1 0", "3 3", "100000 41243", "100000 100000", "32 32", "32 31", "1 1", "2 0", "3 1", "3 2", "3 5", "3 4", "3 10203", "3 10100", "5 0", "5 1", "5 2", "5 3", "5 4", "5 6", "5 7", "5 8", "5 9", "100000 1", "100000 0", "100000 21323", "100000 65536", "100000 65537", "100000 65535", "4 2", ... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
c71255b01a479ab3650e790fad56511a | Fire Again | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing... | [
"import sys\r\nsys.stdin = open(\"input.txt\", \"r\")\r\nsys.stdout = open(\"output.txt\", \"w\")\r\ninput = sys.stdin.buffer.readline\r\n\r\nn, m = map(int, input().split())\r\nk = int(input())\r\nxy = list(map(int, input().split()))\r\nma, u, v = 0, 1, 1\r\nfor i in range(1, n + 1):\r\n for j in range(1, m + 1... | {"inputs": ["3 3\n1\n2 2", "3 3\n1\n1 1", "3 3\n2\n1 1 3 3", "1 1\n1\n1 1", "2 2\n1\n2 2", "2 2\n2\n1 1 2 1", "2 2\n3\n1 2 2 1 1 1", "2 2\n4\n2 1 2 2 1 1 1 2", "10 10\n1\n5 5", "10 10\n2\n7 8 1 9", "10 10\n3\n3 9 6 3 3 5", "10 10\n4\n5 3 4 7 7 5 8 5", "10 10\n5\n2 7 10 6 5 3 9 5 2 9", "10 10\n6\n5 1 4 6 3 9 9 9 5 7 7 2... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
c73011b7f575e990667e991cae603566 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | [
"x = int(input())\r\ns = list(map(int,input().split())) \r\nc = 0\r\nmax = max(s)\r\nmin = min(s)\r\nfor i in range(0,x):\r\n if s[i] != max and s[i]!=min:\r\n c = c + 1\r\nprint(c)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ndef count(nums):\r\n if len(nums) <= 2:\r\n prin... | {"inputs": ["2\n1 5", "3\n1 2 5", "4\n1 2 3 4", "8\n7 8 9 4 5 6 1 2", "1\n1", "1\n100", "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3... | UNKNOWN | PYTHON3 | CODEFORCES | 198 | |
c7341b7a840763c95143df19e11cfce1 | Oranges and Apples | In 2*N*<=-<=1 boxes there are apples and oranges. Your task is to choose *N* boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
The first input line contains one number *T* — amount of tests. The description of each test starts with a natural number *N* — am... | [
"\nt=int(input())\nfor _ in range(t):\n n=int(input())\n nums=[]\n for i in range(2*n-1):\n a,b=map(int,input().split())\n nums.append([b,a,i+1])\n nums=sorted(nums)[::-1]\n vals=[nums[0][2]]\n i=1\n while(i+1<len(nums)):\n c=i\n if(nums[i][1]<nums[i+1][1]):\n ... | {"inputs": ["2\n2\n10 15\n5 7\n20 18\n1\n0 0"], "outputs": ["YES\n3 1\nYES\n1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
c74fe8f7ab7e5d953a678609275967cc | Inna and New Matrix of Candies | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | [
"temp=list(map(int,input().split()))\r\nn=temp[0]\r\nm=temp[1]\r\narr=[]\r\n\r\ndef combo(arr,n,c):\r\n arr1=[x for x in arr if x!=0]\r\n if len(arr1)==0:\r\n return c\r\n else:\r\n t=min(arr1)\r\n if max(arr)==0:\r\n return c\r\n else:\r\n for i in range(n):\r\n ... | {"inputs": ["3 4\n*G*S\nG**S\n*G*S", "1 3\nS*G", "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S", "5 10\nG***S*****\nG****S****\n***GS*****\nG*S*******\nG***S*****", "4 8\nG*S*****\n****G*S*\nG*****S*\n**G***S*", "4 10\n***G****S*\n*****GS*... | UNKNOWN | PYTHON3 | CODEFORCES | 101 | |
c7a543879506cdc6eb620e614597cc1f | Compartments | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of *n* compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ... | [
"#! /usr/bin/env python\n\nn = int(input())\ncounts = [0] * 5\nnums = [int(x) for x in input().split()]\nfor x in nums:\n counts[x] += 1\n\ns = sum(nums)\nif s > 2 and s != 5:\n ans = 0\n if counts[1] >= counts[2]:\n ans += counts[2]\n counts[3] += counts[2]\n counts[1] -= counts[2]\n ... | {"inputs": ["5\n1 2 2 4 3", "3\n4 1 1", "4\n0 3 0 4", "5\n4 4 3 3 1", "5\n4 3 4 2 4", "10\n2 1 2 3 4 1 3 4 4 4", "10\n2 3 3 1 3 1 3 2 2 4", "120\n1 1 1 1 1 1 1 4 4 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 4 1 1 4 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
c7bebd7fa695c6aa741ee0b47480fe3f | Number Busters | Arthur and Alexander are number busters. Today they've got a competition.
Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=≤<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*) and Alexander took integer *с*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each s... | [
"a,b,w,x,c = map(int,input().split())\npoc = 0\ns = set()\ns.add(b)\npa,pb,pc = a,b,c\nwhile (c > a) :\n\tc -= 1\n\tif b >= x:\n\t\tb = b-x\n\telse:\n\t\ta -= 1\n\t\tb = w - (x-b)\n\tif b in s:\n\t\tkolko = len(s)\n\t\tbreak\n\ts.add(b)\ndl = len(s)\nkolko = max(pa-a,1)\nif dl == kolko:\n\tprint(0)\nelse:\n\troz = ... | {"inputs": ["4 2 3 1 6", "4 2 3 1 7", "1 2 3 2 6", "1 1 2 1 1", "1 0 1000 999 2000000000", "10 1 6 4 20", "10 3 6 5 30", "10 3 5 1 30", "10 32 312 72 1000", "1 102 123 27 2321", "2000000000 159 1000 870 2000000000", "200000000 794 1000 117 2000000000", "20000000 280 1000 25 2000000000", "1999999999 47 1000 527 20000000... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
c7e27805e59dc67395e03bd861fc9692 | Playing with Permutations | Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*.
A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), all integers there are distinct.
There is only one thing Petya likes more than p... | [
"n,k=map(int,input().strip().split())\r\na=list(map(int,input().strip().split()))\r\nb=list(map(int,input().strip().split()))\r\nups = [[i+1 for i in range(n)]]\r\ndowns = [[i+1 for i in range(n)]]\r\n\r\ndef apply(arr):\r\n out = [0]*n\r\n for i in range(n):\r\n out[i] = arr[a[i]-1]\r\n return out\... | {"inputs": ["4 1\n2 3 4 1\n1 2 3 4", "4 1\n4 3 1 2\n3 4 2 1", "4 3\n4 3 1 2\n3 4 2 1", "4 2\n4 3 1 2\n2 1 4 3", "4 1\n4 3 1 2\n2 1 4 3", "4 3\n4 3 1 2\n2 1 4 3", "4 3\n2 1 4 3\n4 3 1 2", "4 1\n2 1 4 3\n2 1 4 3", "4 2\n2 1 4 3\n2 1 4 3", "4 2\n2 3 4 1\n1 2 3 4", "5 3\n2 1 4 3 5\n2 1 4 3 5", "9 10\n2 3 1 5 6 7 8 9 4\n2 3... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
c7e518f6e36784b468c9c07c49fe35b5 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | [
"n = int(input())\r\ns = input()\r\nse = set({})\r\nfor x in s:\r\n se.add(x)\r\nif n <= 26:\r\n print(n - len(se))\r\nelse:\r\n print(-1)\r\n",
"n=int(input())\r\ns=input()\r\nif n>26:\r\n print(-1)\r\nelse:\r\n list1=[]\r\n list1[:0]=s\r\n c=list(set(list1))\r\n a=n-len(c)\r\n print(a... | {"inputs": ["2\naa", "4\nkoko", "5\nmurat", "6\nacbead", "7\ncdaadad", "25\npeoaicnbisdocqofsqdpgobpn", "25\ntcqpchnqskqjacruoaqilgebu", "13\naebaecedabbee", "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "10\nbababbdaee", "11\ndbadcdbdbca", "12\nacceaabddaaa", "13\nabddfbfaeecfa", "14\neeceecacdbcbbb", "15\ndcbceaaggabaheb", "16\... | UNKNOWN | PYTHON3 | CODEFORCES | 244 | |
c7e74819c84278ce098eec5e10bf0950 | Harry Potter and the History of Magic | The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has ... | [
"n = int(input())\n\nvalues = [ 1000, 100, 10, 1 ]\nranges = [ [1, 2], range(10), range(10), range(10) ]\n\ndef attempt(previous, digits, x):\n least = None\n for i in range(4):\n for d in ranges[i]:\n y = x + (d - digits[i]) * values[i]\n if y <= 2011 and y >= previous and (least... | {"inputs": ["3\n1875\n1936\n1721", "4\n9999\n2000\n3000\n3011", "3\n1999\n5055\n2000", "2\n2037\n2025", "1\n1234", "1\n9876", "2\n9988\n8899", "3\n1095\n1094\n1095", "5\n5555\n4444\n3333\n2222\n1111", "3\n2010\n2011\n2012", "5\n1901\n1166\n1308\n1037\n1808", "5\n1612\n7835\n8183\n3368\n1685", "10\n1501\n1617\n1368\n173... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
c81d5e4a49895d98aa46236e26ffe463 | Ladder | You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original array, that is, the sequence of numbers *a**l**i*,<=*a**l**i*<=+<=1,<=*a**l**i*<=+<=2,<=...... | [
"n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb,c=[0]*n,[0]*n\r\nfor i in range(1,n):\r\n if a[i]<=a[i-1]: b[i]=b[i-1]+1\r\nfor i in range(n-2,-1,-1):\r\n if a[i]<=a[i+1]: c[i]=c[i+1]+1\r\nfor i in range(m):\r\n L,R=map(int,input().split())\r\n if abs(R-L)<=c[L-1]+b[R-1]:\r\n ... | {"inputs": ["8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "1 1\n6\n1 1", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2", "10 10\n4 7 2 6 4 8 1 2 1 9\n6 10\n1 9\n9 9\n2 8\n9 9\n1 1\n8 8\n4 8\n8 8\n7 7", "7 5\n13 13 16 12 16 3 19\n2 7\n3 4\n7 7\n1 2\n4 7", "13 6\n2 6 1 3 5 2 2 1 6 4 2 5 2\n10 13\n4 10\n4 11\n3 5\n9 13\n3 13... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
c8591ab3dbd3135c5318ccccc83231f2 | Yaroslav and Algorithm | Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as *a*. 1. The algorithm consists of some number of command. Сommand number *i* looks either as *s**i* >> *w**i*, or as *s**i* <> *w**i*, where *s**i* and... | [
"print('9??>>??0')\r\nfor i in range(9):\r\n print('{}??<>{}'.format(i, i + 1))\r\nprint('??<>1')\r\nfor i in range(10):\r\n print('?{0}>>{0}?'.format(i))\r\nprint('?>>??')\r\nprint('>>?')",
"print(\"0??<>1\");\r\nprint(\"1??<>2\");\r\nprint(\"2??<>3\");\r\nprint(\"3??<>4\");\r\nprint(\"4??<>5\");\r\nprint(\"5?... | {"inputs": ["2\n10\n79", "5\n9\n99\n999\n9999\n99999", "5\n99999\n9999\n999\n99\n9", "10\n392\n605\n903\n154\n293\n383\n422\n717\n719\n896", "10\n448\n727\n772\n539\n870\n913\n668\n300\n36\n895", "10\n704\n812\n323\n334\n674\n665\n142\n712\n254\n869", "10\n548\n645\n663\n758\n38\n860\n724\n742\n530\n779", "10\n317\n36\... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
c88414bf76eef58c9a7872fa666c98b0 | Little Pigs and Wolves | Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size *n*<=×<=*m*. Each cell in this grid was either empty, containing one little pig, or containing one wolf.
A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afra... | [
"from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\ndef check(i,j):\r\n\tif (i-1)>=0:\r\n\t\tif l[i-1][j]==\"P\":\r\n\t\t\tl[i][j]=\".\"\r\n\t\t\tl[i-1][j]=\".\"\r\n\t\t\treturn True\r\n\tif (i+1)<n:\r\n\t\tif l[i+1][j]==\"P\":\r\n\t\t\tl[i][j]=\".\"\r\n\t\t\tl[i+1][j]=\".\"\r\n\t\t\treturn True\... | {"inputs": ["2 3\nPPW\nW.P", "3 3\nP.W\n.P.\nW.P", "1 1\nP", "2 6\nWW..WW\n.PPPP.", "6 2\n.W\n.W\n.P\nWP\n.P\nPW", "2 10\nW..WWP.P.P\nW..PP.WWP.", "10 2\nP.\n.W\nPW\n..\nW.\nW.\n..\nP.\nWP\nPP", "3 4\nWPPW\n.P..\nPWW.", "4 3\n.WW\n..P\nP.P\nPWW", "3 10\nWPPP...PP.\n.P...WW..W\n.WWP.PP.PW", "10 3\n...\nPWW\n..P\n..P\nP.... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
c8a6479bca3e0c6689745a18c57e353e | Tic-tac-toe | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the... | [
"\"\"\"\nCodeforces\n3C - Tic-tac-toe\nhttp://codeforces.com/problemset/problem/3/C\n\nHéctor González Belver\n../07/2018\n\"\"\"\nimport sys\n\nSIZE = 3\n\ndef main():\n rows = [sys.stdin.readline().strip() for _ in range(SIZE)]\n\n num_x = ''.join(rows).count('X')\n num_0 = ''.join(rows).count('0')\n\n column... | {"inputs": ["X0X\n.0.\n.X.", "0.X\nXX.\n000", "XXX\n.0.\n000", "XXX\n...\n000", "X.X\nX..\n00.", "X.X\nX.0\n0.0", "XXX\nX00\nX00", "000\nX.X\nX.X", "XXX\n0.0\n0..", "X0X\n0X0\nX0X", "XX.\nX0X\nX..", "X0X\n0X0\nX..", "XX0\n0..\n000", "XXX\n0..\n.0.", "XXX\nX..\n.00", "X00\n0.0\nXX0", "0.0\n0XX\n..0", ".00\nX.X\n0..", ".... | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
c8b59efdcaa0c4ce3da4b4d5ef8753c8 | Death Stars (medium) | The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so... | [
"n, m = [int(x) for x in input().split()]\nlist1 = []\nlist2 = []\nfor i in range(n):\n list1.append(input())\n\nfor j in range(m):\n list2.append(input())\n\nlist3 = []\nfor i in range(n - m + 1):\n y = \"\"\n for j in range(m):\n y += list1[j + i]\n list3.append(y)\n\nlist4 = []\nfor i in ra... | {"inputs": ["10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "1 1\ng\ng"], "outputs": ["4 6", "1 1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
c8c6dafa16661bd281ebc6cc95d78b44 | Calendar | BerOilGasDiamondBank has branches in *n* cities, at that *n* is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly *n*<=/<=2 lines of strictly equal length, each of which contains exactly two names and exactly... | [
"import heapq\r\nn = int(input())\r\ntotLength = 0\r\nallNames = []\r\nused = {}\r\nnamesOfLength = [[] for i in range(11)]\r\nfor o in range(n):\r\n s = input()\r\n totLength += len(s)\r\n allNames.append(s)\r\n namesOfLength[len(s)].append(s)\r\nd = input()\r\nfor i in range(n):\r\n allNames[i] +=... | {"inputs": ["4\nb\naa\nhg\nc\n.", "2\naa\na\n!", "2\naa\na\n|", "4\nqhcivbxotj\nirgxzzxvw\npxdmcyszvk\nyyaevcdal\n~", "8\nbad\nrnnpg\njvcjsxfob\nad\nairnnpg\nqury\njvcjsxfo\nquryai\n6", "6\neh\nehkhdp\ngque\nkhdptvgque\ntvgque\nehkhdptv\n}", "10\ndoecgzo\ntjptpqp\noitegxzwlp\nmwsrwmeyeg\nsmapaqanak\nsmapaqa\nqghrydm\nn... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
c8c6e9cfbda391ccbc4fdded3cf790eb | Laurenty and Shop | A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each... | [
"N = int(input())\r\n\r\nfr, sr = [ int(i) for i in input().split() ], [ int(i) for i in input().split() ]\r\ncross = [ int(i) for i in input().split() ]\r\n\r\nspend_time = [sum(sr) + cross[0]]\r\nfor i in range(1, N):\r\n summ = spend_time[-1] - sr[i - 1] - cross[i - 1]\r\n summ = summ + fr[i - 1] + cross[i... | {"inputs": ["4\n1 2 3\n3 2 1\n3 2 2 3", "3\n1 2\n3 3\n2 1 3", "2\n1\n1\n1 1", "2\n1\n1\n2 1", "3\n1 100\n1 1\n100 100 100", "4\n5 6 7\n8 9 10\n1 8 8 1", "4\n1 2 3\n2 2 3\n2 3 4 3", "48\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | UNKNOWN | PYTHON3 | CODEFORCES | 78 | |
c8ce6e123182a0581d1c615039667841 | Reachability from the Capital | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
The first line of input consists of three integers $n$,... | [
"# https://codeforces.com/contest/999\n\nimport sys\nfrom typing import List, Optional\n\ninput = lambda: sys.stdin.readline().rstrip() # faster!\n\nn, m, s = map(int, input().split())\ns -= 1\nadj = [[] for _ in range(n)] # type: List[List[Optional[int]]]\nfor _ in range(m):\n u, v = map(lambda x: int(x) - 1,... | {"inputs": ["9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "5 4 5\n1 2\n2 3\n3 4\n4 1", "5000 0 2956", "2 0 2", "2 1 1\n1 2", "2 1 2\n1 2", "2 2 2\n1 2\n2 1", "5000 2 238\n3212 238\n238 3212", "5000 2 3810\n3225 1137\n1137 3225", "100 1 30\n69 81", "500 1 209\n183 107", "1000 1 712\n542 916", "39 40 38\n4 8\n24 ... | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
c8d0de1d9d6b8ab910755fb08a28ec2a | Bargaining Table | Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=×<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, t... | [
"# Codeforces Beta Round #22 (Div. 2 Only)\n# B. Bargaining Table\n\nn, m = map(int, input().split())\noffice = []\nfor _ in range(n):\n office += [list(input())]\n\n# dp is a set of 4-tuples (x, y, l, w) which describes the coordinates of a\n# table. (x, y, l, w) is in dp iff the rectangle from (x, y) to (x + l... | {"inputs": ["3 3\n000\n010\n000", "5 4\n1100\n0000\n0000\n0000\n0000", "3 3\n000\n110\n000", "4 2\n00\n10\n11\n00", "3 5\n00001\n00000\n10100", "1 1\n0", "10 11\n11111111101\n01111111111\n11101111111\n01111110111\n11111111111\n11111111111\n11111111111\n11110111111\n11111111111\n11111111111", "7 7\n1110111\n1111111\n111... | UNKNOWN | PYTHON3 | CODEFORCES | 30 | |
c8d20c0015d8c8ad5f2d84cc1c0da6db | Comments | A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment ex... | [
"t = input().split(',')\r\nw = t[::2]\r\nc = list(map(lambda x : int(x), t[1::2]))\r\n\r\nmax_d = 0\r\ncur_d = 0\r\ncnt = [10**6]\r\n\r\nans = [[] for i in range(10**6)]\r\n\r\n\r\ni = 0\r\nwhile i < len(w):\r\n\tans[cur_d].append(w[i])\r\n\tcnt[cur_d] -= 1\r\n\tif c[i] > 0:\r\n\t\tcnt.append(c[i])\r\n\t\tcur_d += ... | {"inputs": ["hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0", "a,5,A,0,a,0,A,0,a,0,A,0", "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0", "BA,0", "Tu,1,dU,1,zncD,0", "nwEwA,2,C,1,aG,0,xgv,0", "aa,0", "ab,0,ba,0", "aa,0,ab,1,a,0", "a,0,bb,1,a,1,bb,0", "a,2,b,0,bb,1,a,1,a,0", "bb,0,b,1,a,1,b,1,a,0,b,0", ... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
c9003a393c88d23eebbb3bcb8db3ab73 | BerOS file system | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | [
"print(\"/\"+\"/\".join(filter(None, input().split(\"/\"))))",
"#***************20A - BerOS file system***************#\r\n#author - @Divyesh Chhabra\r\n\r\nfrom math import *\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nfrom itertools import *\r\n\r\npath = input()\r\nnew = re.split(\"/\",path)\r\... | {"inputs": ["//usr///local//nginx/sbin", "////a//b/////g", "/a/b/c", "/", "////", "/a//aa/a//", "/aa//b/aa", "////////////////////////////////////////////////////////////////////////////////////////////////////", "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "/root/pokerband/trunk/server/game/c... | UNKNOWN | PYTHON3 | CODEFORCES | 107 | |
c95ec8bbce763fd036c37dea65abd276 | Paths and Trees | Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows.
Let's assume that we are given a c... | [
"import heapq\r\n\r\nn, m = map(int, input().split())\r\ng = [[] for _ in range(n + 1)]\r\nfor i in range(1, m + 1):\r\n u, v, w = map(int, input().split())\r\n g[u].append((i, v, w))\r\n g[v].append((i, u, w))\r\nsrc = int(input())\r\n\r\npq = [(0, 0, src, -1)]\r\nmk = [0] * (n + 1)\r\nt = []\r\ns = 0\r\n... | {"inputs": ["3 3\n1 2 1\n2 3 1\n1 3 2\n3", "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4", "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 40\n3 5 10\n3 6 50\n5 6 60\n4", "1 0\n1", "2 1\n1 2 1000000000\n2"], "outputs": ["2\n1 2 ", "4\n2 3 4 ", "3\n1 2 3 ", "230\n1 4 5 6 7 ", "0", "1000000... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
c9bd2ecc84eee31c97d701505f902d35 | Bad Luck Island | The Bad Luck Island is inhabited by three kinds of species: *r* rocks, *s* scissors and *p* papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill... | [
"def var():\r\n return (map(int,input().split()))\r\ndef a():\r\n return list((map(int,input().split())))\r\n\r\n\r\nimport copy\r\nfrom collections import defaultdict,deque\r\n\r\ndp1=[[[-1]*(102) for _ in range(102)] for _ in range(102)]\r\ndp2=[[[-1]*(102) for _ in range(102)] for _ in range(102)]\r\ndp3=[... | {"inputs": ["2 2 2", "2 1 2", "1 1 3", "3 2 1", "100 100 100", "1 100 100", "100 1 100", "100 100 1", "1 100 99", "99 1 100", "100 99 1", "100 1 99", "1 99 100", "99 100 1", "1 1 1", "100 100 2", "100 2 100", "2 100 100", "3 3 3", "44 54 32", "100 90 5", "90 5 100", "5 100 90", "100 5 90", "5 90 100", "90 100 5", "4 4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 14 | |
c9c7b9f7d69ec1a2adb6957425033f52 | Maximum in Table | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | [
"n = int(input())\r\ns = []\r\nx = [[0] * n for _ in range(n)]\r\n\r\nfor i in range(n):\r\n x[i][0] = 1\r\n x[0][i] = 1\r\nfor i in range(1, n):\r\n for j in range(1, n):\r\n x[i][j] = x[i - 1][j] + x[i][j - 1]\r\nfor row in x:\r\n s.append(max(row))\r\nm = max(s)\r\nprint(m)",
"n = int(input(... | {"inputs": ["1", "5", "2", "3", "4", "6", "7", "9", "10", "8"], "outputs": ["1", "70", "2", "6", "20", "252", "924", "12870", "48620", "3432"]} | UNKNOWN | PYTHON3 | CODEFORCES | 869 | |
c9db3ceceb2ff1f67aefc2459bf97dc9 | Wallpaper | Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has *n* rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).
Boris c... | [
"n,a=int(input()),[]\r\nfor i in range(n):a.append(list(map(int,input().split())))\r\nm,b=int(input()),[]\r\nfor i in range(m):b.append(list(map(int,input().split())))\r\nans = 0\r\nfor room in a:\r\n p,c_room=2*(room[0]+room[1]),10**10\r\n for ob in b:\r\n z=ob[0]//room[2]*ob[1]\r\n if z==0:con... | {"inputs": ["1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500", "1\n9 10 7\n1\n7 1 3", "1\n6 9 5\n3\n8 5 10\n8 5 2\n6 3 7", "1\n3 3 10\n3\n5 5 1\n9 9 2\n10 1 500", "3\n29 30 29\n30 15 28\n27 30 23\n3\n30 27 21\n11 24 30\n25 20 12", "5\n4 4 1\n3 1 4\n4 1 3\n5 1 1\n1 1 1\n5\n5 3 3\n4 3 4\n5 2 3\n2 1 5\n3 1 3", "10\n57 66 71\n14... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
ca115b811848bef818685ad440e1ead2 | Tufurama | One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ... | [
"from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\ndef make_tree(n):\r\n tree = [0] * (n + 1)\r\n return tree\r\n\r\ndef get_sum(i):\r\n s = 0\r\n while i > 0:\r\n s += tree[i]\r\n i -= i & -i\r\n return s\r\n\r\ndef get_sum_segment(s, t):\r\n if ... | {"inputs": ["5\n1 2 3 4 5", "3\n8 12 7", "3\n3 2 1", "5\n2 3 4 5 6", "8\n7 2 6 6 5 1 4 9", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "1\n1"], "outputs": ["0", "3", "2", "4", "9", "45", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
ca1dfc506b7bb53a74ad35faa89dd5c1 | Taymyr is calling you | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | [
"n, m, z = (int(i) for i in input().split())\r\n\r\ncalls = set(i for i in range(0, z + 1, n))\r\nart = set(i for i in range(0, z + 1, m))\r\n\r\nprint(len(calls & art) - 1)",
"n, m, z = [int(i) for i in input().split()]\r\n \r\ncopy_n = n\r\ncopy_m = m\r\n \r\nx = 1\r\ncnt = 0\r\nwhile x <= z:\r\n if n == x:\r\... | {"inputs": ["1 1 10", "1 2 5", "2 3 9", "4 8 9", "7 9 2", "10000 10000 10000", "24 22 9235", "74 8 417", "972 1 203", "550 1 754", "860 1 884", "358 2 809", "33 27 216", "2940 1 9311", "4624 1 1953", "2696 2 7345", "3443 2 6701", "3 613 2275", "1 10000 10000", "10000 1 10000", "1 1 1", "1 1 10000", "34 27 10000", "2 2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 473 | |
ca2e11a194b5b6dd6e1572ac699a94bb | Maximal GCD | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi... | [
"def divisors(x):\r\n\tdivisor=[]\r\n\tfor i in range(1,int(x**(1/2)+1)):\r\n\t\tif x%i==0:\r\n\t\t\tdivisor.append(i)\r\n\t\t\tif i!=x//i:\r\n\t\t\t\tdivisor.append(x//i)\r\n\treturn divisor\r\n\r\n\r\nn,k=[int(x) for x in input().split()]\r\nfactors=sorted(divisors(n))\r\nmaxfactor=0\r\n\r\nfor i in factors:\r\n\... | {"inputs": ["6 3", "8 2", "5 3", "1 1", "1 2", "2 1", "2 10000000000", "5 1", "6 2", "24 2", "24 3", "24 4", "24 5", "479001600 2", "479001600 3", "479001600 4", "479001600 5", "479001600 6", "3000000021 1", "3000000021 2", "3000000021 3", "3000000021 4", "3000000021 50000", "3000000021 100000", "10000000000 100", "100... | UNKNOWN | PYTHON3 | CODEFORCES | 70 | |
ca337d70fd33ab768399ea1ce6e1e0cd | T-primes | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The fir... | [
"import math\r\n\r\n# 预处理数组\r\nN = int(1e6+1)\r\nis_prime = [True] * N\r\nis_prime[0], is_prime[1] = False, False\r\nfor i in range(2, int(math.sqrt(N))+1):\r\n if is_prime[i]:\r\n for j in range(i*i, N, i):\r\n is_prime[j] = False\r\n\r\ndef is_t_prime(num):\r\n # 判断一个数是否为T-prime\r\n # T... | {"inputs": ["3\n4 5 6", "2\n48 49", "10\n10 9 8 7 6 5 4 3 2 1", "1\n36", "1\n999966000289", "1\n999993399999", "9\n111 121 131 111 121 131 111 121 131", "1\n1", "1\n10", "1\n976197352729", "1\n1000000000000", "1\n9", "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "3\n223092870 64696... | UNKNOWN | PYTHON3 | CODEFORCES | 61 | |
ca3947b67c3a6a10a16078700522a212 | Statistics of Recompressing Videos | A social network for dogs called DH (DogHouse) has *k* special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network.
We know that each server takes one second to recompress a on... | [
"import heapq\r\nf=lambda:map(int,input().split())\r\nn,k=f()\r\np=[0]*k\r\nq=[0]*n\r\nfor i in range(n):\r\n s,m=f()\r\n q[i]=max(p[0],s)+m\r\n heapq.heapreplace(p,q[i])\r\nprint(' '.join(map(str,q)))",
"import heapq\nn, k = map(int, input().split())\npq = [0] * k\nres = [None] * n\nfor i in range(n):\n s, m ... | {"inputs": ["3 2\n1 5\n2 5\n3 5", "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3", "1 1\n1 1", "1 1\n1000000000 10000", "10 6\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1", "10 4\n1 1\n2 2\n3 1\n4 1\n5 1\n6 1\n7 1\n8 2\n9 1\n10 1", "10 2\n1 5650\n2 4753\n3 7632\n4 688\n5 8853\n6 2... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
ca3d6467bdb990da04d4d92e4273bb4d | Room Leader | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly *n* participants. During the contest the participants are suggested to solve five prob... | [
"total_contestants = int(input())\r\n\r\nfinal_scores = {}\r\n\r\nfor _ in range(total_contestants):\r\n handle, successful_hacks, unsuccessful_hacks, *problem_values = input().split() \r\n\r\n successful_hacks = int(successful_hacks)\r\n unsuccessful_hacks = int(unsuccessful_hacks)\r\n\r\n final_scores[handle]... | {"inputs": ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0", "1\nA 0 0 200 0 0 0 0", "2\n12345678901234567890 1 0 200 0 0 0 0\n_ 1 0 201 0 0 0 0", "5\nAb 0 0 481 900 1200 1600 2000\nCd 0 0 480 899 1200 1600... | UNKNOWN | PYTHON3 | CODEFORCES | 86 | |
ca4164560911dd7263a284d68b508ad5 | Writing Code | Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that he writes.
Let's call a sequence of non-negative integers *v*1,<=*v*2,<=...,<=*v**n* a plan, if *... | [
"def main():\n n, m, b, mod = map(int, input().split())\n b += 1\n nxt = [[0] * b for _ in range(m)]\n row_zero = [0] * b\n row_zero[0] = 1\n for a in list(map(int, input().split())):\n cur, nxt = nxt, []\n src0 = row_zero\n for src1 in cur:\n src0 = [(x + src0[i]) ... | {"inputs": ["3 3 3 100\n1 1 1", "3 6 5 1000000007\n1 2 3", "3 5 6 11\n1 2 1", "2 3 3 1000\n1 2", "3 10 10 150691913\n8 7 10", "100 500 500 895583345\n20 39 5 5 41 47 36 33 34 22 21 33 7 4 15 35 16 37 39 46 27 4 12 35 43 26 23 40 16 50 27 7 49 28 17 28 16 22 18 12 25 34 28 24 10 21 38 10 40 50 35 18 23 38 10 42 22 19 24... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
ca67f81524362b2d19d014c461c2397c | As Fast As Possible | On vacations *n* pupils decided to go on excursion and gather all together. They need to overcome the path with the length *l* meters. Each of the pupils will go with the speed equal to *v*1. To get to the excursion quickly, it was decided to rent a bus, which has seats for *k* people (it means that it can't fit more t... | [
"n, L, v1, v2, k = map(int, input().split())\r\nn = (n + k - 1) // k * 2\r\ndif = v2 - v1\r\np1 = (n * v2 - dif) * L\r\np2 = (n * v1 + dif) * v2\r\nans = p1 / p2\r\nprint(ans)\r\n",
"n,l,v,V,k=map(int,input().split())\r\nn=(n+k-1)//k\r\na=(n-1)*(V-v)/(v+V)\r\nprint(l/V/(n-a)*(n+a))",
"n,l,v1,v2,k=map(int,input(... | {"inputs": ["5 10 1 2 5", "3 6 1 2 1", "39 252 51 98 26", "59 96 75 98 9", "87 237 3 21 40", "11 81 31 90 1", "39 221 55 94 1", "59 770 86 94 2", "10000 1000000000 1 2 1", "10000 1 999999999 1000000000 1", "9102 808807765 95894 96529 2021", "87 422 7 90 3", "15 563 38 51 5", "39 407 62 63 2", "18 518 99 100 4", "8367 5... | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
ca82c102c0674d5c724b69c7a9077362 | Dima and Salad | Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have *n* fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit sa... | [
"from heapq import heappush, heappop, heapify\r\nfrom collections import defaultdict, Counter, deque\r\nfrom functools import lru_cache\r\nimport threading\r\nimport sys\r\nimport bisect\r\ninput = sys.stdin.readline\r\ndef ri(): return int(input())\r\ndef rs(): return input()\r\ndef rl(): return list(map(int, inpu... | {"inputs": ["3 2\n10 8 1\n2 7 1", "5 3\n4 4 4 4 4\n2 2 2 2 2", "1 1\n1\n1", "1 1\n1\n2", "2 1\n75 65\n16 60", "21 8\n50 39 28 27 58 46 95 46 50 8 28 94 61 58 57 7 1 38 9 34 12\n94 1 77 1 17 40 99 31 26 1 1 1 15 7 6 1 85 3 32 65 78", "16 2\n60 5 39 38 43 10 99 2 88 24 2 73 21 57 60 69\n59 92 96 9 1 15 4 42 23 7 100 10 9... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
ca8f6ab2803cb58d95f89fdce4108ac1 | Anniversary | There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations.
Dima is sure that it'll be great to learn to solve the following problem by the Big Day: You're given a set *A*, consisting of numb... | [
"m, l, r, k = map(int, input().split())\r\nl -= 1\r\na = 0\r\nwhile a * a < r:\r\n a += 1\r\nGCD = 0\r\nfor i in range(1, a + 1):\r\n t = r // i\r\n if (r // t - l // t >= k) and (GCD < t):\r\n GCD = t\r\nfor i in range(1, a + 1):\r\n t = i\r\n if (r // t - l // t >= k) and (GCD < t):\r\n ... | {"inputs": ["10 1 8 2", "10 1 8 3", "10 1 20 2", "4 1 10 2", "1000000000 999000000000 1000000000000 1000000001", "643354696 8 9 2", "829051283 4 9 2", "549070627 2 6 2", "275299363 7 8 2", "232100782 7 9 2", "466253512 1 10 2", "828885826 8 10 2", "572252279 9 10 2", "888775378 3 6 2", "524357331 2 4 3", "467730377 5 8... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
caa61827937e47f0ebc44c0a38d8d796 | More Cowbell | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a sin... | [
"import math\r\nimport time\r\nfrom collections import defaultdict,deque\r\nfrom sys import stdin,stdout\r\nfrom bisect import bisect_left,bisect_right\r\nn,k=map(int,stdin.readline().split())\r\na=list(map(int,stdin.readline().split()))\r\ndouble=n-k\r\nans=0\r\nfor i in range(double):\r\n ans=max(ans,a[i]+a[2*... | {"inputs": ["2 1\n2 5", "4 3\n2 3 5 9", "3 2\n3 5 7", "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10 10\n3 15 31 61 63 63 68 94 98 100", "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 35... | UNKNOWN | PYTHON3 | CODEFORCES | 117 | |
caabb5fbf0ee08c9833cf9b20aa2cdd4 | Journey | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | [
"def dfs(start):\r\n visited = [0, True] + [False]*(n-1)\r\n stack = [(x, 1, 1/len(tree[start])) for x in tree[start]]\r\n while stack:\r\n v, l, p = stack.pop()\r\n if leafs[v]:\r\n L.append(l*p)\r\n if not visited[v]:\r\n visited[v] = True\r\n for u i... | {"inputs": ["4\n1 2\n1 3\n2 4", "5\n1 2\n1 3\n3 4\n2 5", "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n... | UNKNOWN | PYTHON3 | CODEFORCES | 68 | |
caadddf957eac691420c3d53c94444e8 | none | In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different fl... | [
"\r\n\r\nimport bisect as bs\r\nimport sys\r\ninp = sys.stdin.readlines()\r\nn, m, ladders, elevators, v = [int(x) for x in inp[0].strip().split()]\r\nladders = [int(x) for x in inp[1].strip().split()]\r\nelevators = [int(x) for x in inp[2].strip().split()]\r\nq = int(inp[3].strip())\r\nqs = []\r\nfor i in range(q)... | {"inputs": ["5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "2 2 0 1 1\n\n1\n1\n1 2 2 2", "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3", "10 10 1 8 4\n10\n2 3 4 5 6 7 8 9\n10\n1 1 3 1\n2 1 7 1\n1 1 9 1\n7 1 4 1\n10 1 7 1\n2 1 7 1\n3 1 2 1\n5 1 2 1\n10 1 5 1\n6 1 9 1", "2 5 1 0 1\n2\n\n1\n1 4 1 5", "... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
cab62735c2bdf05556c35b9dc9b289cd | Robot's Task | Robot Doc is located in the hall, with *n* computers stand in a line, numbered from left to right from 1 to *n*. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the *i*-th of them, the robot needs to colle... | [
"n=int(input())\r\narr=list(map(int,input().split()))\r\nfound=0\r\nans=-1\r\ncur=0\r\nwhile found<n:\r\n if ans%2==1:\r\n for i in range(0,len(arr)):\r\n if arr[i]!=-1 and arr[i]<=found:\r\n found+=1\r\n arr[i]=-1\r\n #print(i+1)\r\n ans+=1\r... | {"inputs": ["3\n0 2 0", "5\n4 2 3 0 1", "7\n0 3 1 0 5 2 6", "1\n0", "2\n0 1", "10\n0 0 0 0 0 0 0 0 0 0", "3\n0 2 1", "10\n7 1 9 3 5 8 6 0 2 4", "10\n1 3 5 7 9 8 6 4 2 0", "10\n5 0 0 1 3 2 2 2 5 7", "10\n8 6 5 3 9 7 1 4 2 0", "10\n1 2 4 5 0 1 3 7 1 4", "10\n3 4 8 9 5 1 2 0 6 7", "10\n2 2 0 0 6 2 9 0 2 0", "10\n1 7 5 3 2... | UNKNOWN | PYTHON3 | CODEFORCES | 128 | |
cab72222040910bb0a4ac88e83a6f633 | Let's Go Rolling! | On a number axis directed from the left rightwards, *n* marbles with coordinates *x*1,<=*x*2,<=...,<=*x**n* are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in t... | [
"import sys\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom math import *\r\nfrom array import *\r\nfrom functools import lru_cache\r\nimport heapq\r\nimport bisect\r\nimport random\r\nimport io, os\r\nfrom bisect import *\r\n\r\nif sys.hexversion == 50924784:\r\n sys.stdin = open('cfinput.txt')\... | {"inputs": ["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1", "1\n-948943148 10", "5\n864449017 54\n864449026 504\n864449027 308\n864449028 284\n864449030 249", "10\n439333887 2\n439333930 1\n439333947 2\n439333949 3\n439333950 1\n439333952 3\n439333953 1\n439333954 2\n439333955 2\n439333956 1", "15\n-793387817 -4\n-793387... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
cae5a1f13eb5f93ac2ee925307fd5622 | Cheaterius's Problem | Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu... | [
"def contains(cont: list, temp: str) -> bool:\r\n for i in range(4):\r\n if temp in cont:\r\n return True\r\n temp = f'{temp[2]}{temp[0]}{temp[3]}{temp[1]}'\r\n return False\r\n\r\n\r\nn = int(input())\r\ncont = []\r\nfor i in range(n):\r\n temp = input() + input()\r\n if not co... | {"inputs": ["4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13", "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53", "4\n56\n61\n**\n31\n31\n**\n33\n11\n**\n11\n33", "4\n36\n44\n**\n32\n46\n**\n66\n41\n**\n64\n34", "3\n63\n63\n**\n66\n33\n**\n36\n36", "3\n11\n54\n**\n42\n63\n**\n42\n63", "3\n14\n54\n**\n45\n41\n**\n12\n22", "... | UNKNOWN | PYTHON3 | CODEFORCES | 38 | |
cb03cf99183747b6f7f40626d1e6f888 | Binary String Constructing | You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. It is guaranteed that the answer always exists.
For example, fo... | [
"\r\ndef mp():return map(int,input().split())\r\ndef it():return int(input())\r\n\r\n\r\na,b,x=mp()\r\ns=''\r\nif x&1==0:\r\n\r\n\tif a>b:\r\n\t\ts+='01'*(x//2)\r\n\t\ts+='1'*(b-(x//2))\r\n\t\ts+='0'*(a-(x//2))\r\n\telse:\r\n\t\ts+='10'*(x//2)\r\n\t\ts+='0'*(a-(x//2))\r\n\t\ts+='1'*(b-(x//2))\r\nelse:\r\n\tif a>b:\... | {"inputs": ["2 2 1", "3 3 3", "5 3 6", "100 1 2", "100 1 1", "1 100 1", "1 100 2", "7 8 7", "100 100 199", "50 47 18", "2 3 3", "100 100 100", "2 2 2", "3 4 6", "1 1 1", "5 6 2", "5 4 2", "2 3 4", "3 3 2", "100 99 100", "3 2 1", "12 74 22", "6 84 12", "3 2 4", "66 11 22", "83 83 83", "9 89 18", "2 1 2", "52 12 17", "55... | UNKNOWN | PYTHON3 | CODEFORCES | 68 | |
cb102d5bedfb81d7278cc148c8fbc106 | none | You are given an infinite checkered field. You should get from a square (*x*1; *y*1) to a square (*x*2; *y*2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
A square (*x*; ... | [
"from math import floor\na,b,x1,y1,x2,y2=map(int,input().split())\na*=2\nb*=2\nfl=floor\nx11=fl((y1-x1)/b)\ny11=fl((y1+x1)/a)\nx22=fl((y2-x2)/b)\ny22=fl((y2+x2)/a)\n# print(x11,y11)\n# print(x22,y22)\nl1=abs(x11-x22)\nl2=abs(y11-y22)\n# l1,l2=min(l1,l2),max(l1,l2)\nif (abs(x1+y1)%a==0 or abs(x1-y1)%b==0) and (abs(x... | {"inputs": ["2 2 1 0 0 1", "2 2 10 11 0 1", "2 4 3 -1 3 7", "2 2 9 10 -10 -11", "3 2 -11 -10 10 11", "3 2 11 -12 -12 11", "3 3 12 11 -12 -11", "2 3 -12 13 13 -12", "3 4 -8 5 6 -3", "2 3 2 -1 -10 -1", "4 4 3 2 10 -1", "3 2 -8 -9 -14 -1", "4 4 0 -3 11 -4", "5 3 6 3 3 12", "3 5 -4 -7 5 0", "3 5 -20 19 21 16", "5 6 23 -10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
cb10bc64a38e5cbbb28229c038a03616 | Robin Hood | We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give i... | [
"import sys\n\n\n\ninp = sys.stdin.read().splitlines()\n\nn,k = list(map(int,inp[0].split()))\n\nlst = list(map(int,inp[1].split()))\n\nlst.sort()\n\ntotal = sum(lst)\n\nlower = int(total/n)\n\nnupper = total%n\n\n\n\nif nupper == 0:\n\n\tupper = lower;\n\nelse:\n\n\tupper = lower+1;\n\nnlower = n - nupper;\n\n\n\n... | {"inputs": ["4 1\n1 1 4 2", "3 1\n2 2 2", "10 20\n6 4 7 10 4 5 5 3 7 10", "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2", "2 0\n182 2", "123 54564\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94 57 65 85 64 47 24 20 34 86 26 91 98 12 36 96 80 4 70 40 95 38 70 22 58 50 34 84 80 45 14 60 61 43 11 56 19 ... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
cb10e3687854c6f485432e7332948d67 | New Year and Hurry | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | [
"inp = input().split()\r\nlis = [eval(i) for i in inp]\r\n\r\nk = lis[1]\r\n\r\nn = 5\r\na,b=0,lis[0]\r\nfor i in range(lis[0]):\r\n if(k<240 and k+((i+1)*5)<=240):\r\n k+=n\r\n n+=5\r\n else:break\r\n a=i+1\r\n\r\nprint(int(a))",
"def solve(n, k):\r\n l = 240 - k\r\n for i in range(1... | {"inputs": ["3 222", "4 190", "7 1", "10 135", "10 136", "1 1", "1 240", "10 1", "10 240", "9 240", "9 1", "9 235", "9 236", "5 225", "5 226", "4 210", "4 211", "4 191", "10 165", "10 166", "8 100", "8 101", "8 60", "8 61", "10 15", "10 16", "4 100", "4 101", "7 167", "10 164", "9 170", "8 160", "1 100", "8 123", "2 99... | UNKNOWN | PYTHON3 | CODEFORCES | 765 | |
cb263938720825c045f25d273e28aa47 | Pythagorean Triples | Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, tripl... | [
"n = int(input())\na = n * n\nb = a // 2\nc = a - b\nif b == c:\n b //= 2\n c = b + 1\n b -= 1\nif (b > 0) and (c > 0):\n print(int(b), int(c))\nelse:\n print(-1)\n\n\t \t \t \t\t\t \t\t\t \t\t\t\t \t\t",
"import math\r\n\r\ndef find_pythagorean_triple1(n):\r\n if n <= 2:\r\n ret... | {"inputs": ["3", "6", "1", "17", "67", "10", "14", "22", "23", "246", "902", "1000000000", "1998", "2222222", "2222226", "1111110", "9999998", "1024", "8388608", "4", "8", "16", "492", "493824", "493804", "493800", "2048", "8388612", "44", "444", "4444", "44444", "444444", "4444444", "100000000", "2", "3", "5", "7", "9... | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
cb29bcdc75039540bb7686e4763a4ad0 | A Twisty Movement | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | [
"\r\n\r\nn=int(input())\r\n\r\nl=list(map(int, input().split()))\r\n\r\ndpl=[[0,0,0] for _ in range(n)]\r\ndpr=[[0,0,0] for _ in range(n)]\r\n\r\ndpl[0][l[0]]=1 \r\ndpl[0][0]=1 \r\n\r\nfor i in range(1,n):\r\n if l[i]==1:\r\n dpl[i][1]=dpl[i-1][1]+1 \r\n dpl[i][2]=dpl[i-1][2]\r\n dpl[i][0]=m... | {"inputs": ["4\n1 2 1 2", "10\n1 1 2 2 2 1 1 2 2 1", "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 33 | |
cb38fa4528d2503a145a641662196af3 | Dancing Lessons | There are *n* people taking dancing lessons. Every person is characterized by his/her dancing skill *a**i*. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other... | [
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat May 7 11:48:38 2016\r\n\r\n@author: Alex\r\n\"\"\"\r\n\r\nimport heapq, sys\r\nq = []\r\ncnt = 0\r\nn = int(input())\r\nsex = input()\r\na = list(map(int, input().split()))\r\nl = [i-1 for i in range(n)] #生成左指针列表\r\nr = [i+1 for i in range(n)] #生成右指针列表\r\nfor i ... | {"inputs": ["4\nBGBG\n4 2 4 3", "4\nBBGG\n4 6 1 5", "4\nBGBB\n1 1 2 3", "1\nB\n490297", "2\nBB\n2518190 6313112", "3\nBBB\n3146681 8599398 1571560", "10\nGBBBBGBBGG\n9448959 6234076 8008159 4440374 4736443 255932 6568554 4544108 54187 1105310", "10\nBGGBBGBGBG\n9892816 3514007 5425956 5241945 9171176 3351177 2772494 28... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
cb8618f8fcb1feb01437682b6e177e54 | Delivery Bears | 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 e... | [
"from collections import deque\r\n \r\nclass Dinic():\r\n def __init__(self, listEdge, s, t):\r\n self.s = s\r\n self.t = t\r\n self.graph = {}\r\n self.maxCap = 1000000\r\n # dict các node lân cận\r\n \r\n # e[0]: from, e[1]: to, e[2]: dung luong \r\n ... | {"inputs": ["4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2", "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", "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", "2 1 3\n1 2 301", "2 2 1\n1 2 48\n2 1 39", "5 9 5\... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
cb9186b9a4e23f221c547dc20fa1cbd3 | Heap Operations | Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the heap; - extract the minimum element from the heap;
Thus, at any moment of time the heap contains se... | [
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nfrom heapq import *\r\n \r\nans = []\r\nv = []\r\nfor _ in range(int(input())):\r\n A = input().split()\r\n a = A[0]\r\n \r\n\r\n if a=='insert':\r\n b = int(A[1])\r\n ans.append(a+' ' +str(b))\r\n heappush(v,b)\r\... | {"inputs": ["2\ninsert 3\ngetMin 4", "4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2", "1\ninsert 1", "1\ngetMin 31", "1\nremoveMin", "2\ninsert 2\ngetMin 2", "2\ninsert 31\nremoveMin", "2\ngetMin 31\nremoveMin", "2\nremoveMin\ngetMin 31", "8\ninsert 219147240\nremoveMin\ngetMin 923854124\nremoveMin\ngetMin -876779400\nrem... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
cbb676850d743a009c1cd41772a6d438 | Masha and Bears | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | [
"v1, v2, v3, vm = map(int, input().split())\r\n\r\nif vm > 2*v3 or v3> 2*vm or vm >= v2 or vm >= v1:\r\n print(-1)\r\nelse:\r\n print(2*v1)\r\n print(2*v2)\r\n print(max(v3, vm))\r\n \r\n ",
"vi = list(map(int,input().split()))\r\nv1,v2,v3,vm = vi[0],vi[1],vi[2],vi[3]\r\nm1,m2,m3 = 0,0,0\r\nflag... | {"inputs": ["50 30 10 10", "100 50 10 21", "100 50 19 10", "99 50 25 49", "3 2 1 1", "100 99 98 100", "100 40 30 40", "100 50 19 25", "100 50 19 30", "49 48 25 49", "48 47 23 46", "37 23 16 20", "98 2 1 1", "99 22 13 14", "97 95 3 2", "27 3 2 3", "13 7 6 2", "19 17 11 6", "15 6 4 5", "21 3 1 3", "100 99 98 97", "99 32 ... | UNKNOWN | PYTHON3 | CODEFORCES | 92 | |
cbc0daf7ec2b8a32eed497f9d63ecf29 | Stepan's Series | Well, the series which Stepan watched for a very long time, ended. In total, the series had *n* episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not.
Stepan's dissatisfaction is the maximum n... | [
"import sys\n\nn, k = map(int, input().split(' '))\n\ns = input()\n\ndef max_streak(s):\n result = 0\n\n for i in range(len(s)):\n j = i\n while j < len(s) and s[j] == 'N':\n j += 1\n\n result = max(result, j - i)\n\n return result\n\nfor i in range(n - k + 1):\n cur = li... | {"inputs": ["5 2\nNYNNY", "6 1\n????NN", "100 8\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN", "10 1\nNY???NY?Y?", "20 7\nN?N??NNN?NNN?Y???Y??", "30 1\nNYYYNYYY?Y?YY?YYYYYYYYYYYYYNYY", "40 14\nNNNNNNNNNNNNNNNNNYNNNNYNNYNNNNNNYNNNNNNN", "51 1\nYYYNYNYNNYYNNY?YNYYY... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
cbc8bc5adddd9ff53f82afb50a6c38e8 | Heidi and Library (easy) | Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are *n* different books, numbered 1 through *n*.
We will ... | [
"n, k = map(int, input().split())\na = list(map(int, input().split()))\ninventory = set()\nbought = 0\nfor i in range(n):\n if a[i] not in inventory:\n if len(inventory) == k:\n farthest_time = 0\n farthest = 0\n for v in inventory:\n try:\n ... | {"inputs": ["4 80\n1 2 2 1", "4 1\n1 2 2 1", "4 2\n1 2 3 1", "11 1\n1 2 3 5 1 10 10 1 1 3 5", "5 2\n1 2 3 1 2", "4 2\n1 2 3 2", "1 1\n1", "80 4\n9 9 2 6 3 10 2 5 4 9 6 7 5 5 3 8 5 3 2 10 7 8 5 3 4 9 4 3 9 5 2 10 8 4 7 3 8 3 5 2 3 7 8 4 2 4 4 7 2 2 5 7 5 8 10 10 5 1 1 3 5 2 10 8 7 9 7 4 8 3 2 8 7 9 10 9 7 1 5 5", "80 4\... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
cbd3bd36a78afd98ce39b978953fe69c | Posterized | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref... | [
"n, k = [int(x) for x in input().split()]\r\n\r\nps = [int(x) for x in input().split()]\r\n\r\nmapping = [-1 for _ in range(256)]\r\n\r\nres = []\r\nfor p in ps:\r\n if mapping[p] == -1:\r\n j = p - k + 1\r\n while j < 0 or (mapping[j] != -1 and mapping[j] + k <= p):\r\n j += 1\r\n ... | {"inputs": ["4 3\n2 14 3 4", "5 2\n0 2 1 255 254", "10 3\n112 184 161 156 118 231 191 128 91 229", "9 3\n174 149 118 124 166 146 219 233 107", "8 4\n180 195 13 195 61 24 132 160", "1 4\n51", "2 4\n218 213", "3 3\n212 167 3", "100 7\n39 242 238 155 95 30 129 132 72 59 22 61 133 113 99 81 253 204 160 109 92 187 11 227 14... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
cbd781d42f2b14ec31bd058e858ae936 | Help Shrek and Donkey 2 | Having learned (not without some help from the Codeforces participants) to play the card game from the previous round optimally, Shrek and Donkey (as you may remember, they too live now in the Kingdom of Far Far Away) have decided to quit the boring card games and play with toy soldiers.
The rules of the game are as f... | [
"def get(a):\r\n global m\r\n R = -1\r\n G = -1\r\n mi = -1\r\n for i in range(m):\r\n if a[i] == '-':\r\n mi = i\r\n elif a[i] == \"R\":\r\n R = i\r\n else:\r\n G = i\r\n return G, R, mi\r\n\r\n\r\nn, m, k = map(int, input().split())\r\ndraw =... | {"inputs": ["2 3 1\nR-G\nRG-", "3 3 2\nG-R\nR-G\nG-R", "2 3 1\n-R-\n-G-", "2 5 2\n-G-R-\n-R-G-", "3 3 1\nG-R\nR-G\nG-R", "2 5 1\n-G-R-\n-R-G-", "2 2 1\nGG\n-R", "2 2 2\nR-\nGG", "3 2 1\nRR\n--\nG-", "3 2 2\n--\n-G\nRR", "2 2 2\nRR\nGG", "2 1 1\nG\nR", "1 1 1\n-", "3 5 2\n-R--G\nG---R\n-R-G-", "3 5 1\n-R--G\nG---R\n-R-G... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
cbe46e8904a05d3d4188f09dd4ace78c | Fox and Card Game | 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... | [
"n = int(input())\r\nc = [list(map(int, input().split())) for _ in range(n)]\r\na, b = 0, 0\r\nd = []\r\nfor i in range(n):\r\n if len(c[i]) % 2:\r\n a += sum(c[i][1:c[i][0]//2+1])\r\n b += sum(c[i][c[i][0]//2+1:])\r\n else:\r\n a += sum(c[i][1:c[i][0]//2+1])\r\n b += sum(c[i][c[i]... | {"inputs": ["2\n1 100\n2 1 10", "1\n9 2 8 6 5 9 4 7 1 3", "3\n3 1 3 2\n3 5 4 6\n2 8 7", "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "1\n1 1", "5\n1 3\n1 2\n1 8\n1 1\n1 4", "3\n5 1 2 3 4 5\n4 1 2 3 4\n8 1 2 3 4 5 6 7 8", "5\n5 1 1 1 1 1\n4 1 1 1 1\n3 1 1 1\n2 1 1\n1 1", "6\n2 1 1\... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
cbee248948dd04736c1c417697f70d86 | Young Table | You've got table *a*, consisting of *n* rows, numbered from 1 to *n*. The *i*-th line of table *a* contains *c**i* cells, at that for all *i* (1<=<<=*i*<=≤<=*n*) holds *c**i*<=≤<=*c**i*<=-<=1.
Let's denote *s* as the total number of cells of table *a*, that is, . We know that each cell of the table contains a sing... | [
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nN = int(input())\r\nC = list(map(int, input().split()))\r\nA = []\r\nfor _ in range(N):\r\n A.append(list(map(int, input().split())))\r\n \r\ndef find(num):\r\n for i in range(N):\r\n for j in range(len(A[i])):\r\n if A[i... | {"inputs": ["3\n3 2 1\n4 3 5\n6 1\n2", "1\n4\n4 3 2 1", "5\n4 4 3 3 1\n14 13 4 15\n11 1 2 5\n7 6 10\n8 9 3\n12", "2\n8 6\n1 2 3 13 10 4 11 7\n9 12 8 5 14 6", "6\n10 9 7 6 4 3\n18 20 29 19 5 28 31 30 32 15\n38 33 11 8 39 2 6 9 3\n13 37 27 24 26 1 17\n36 10 35 21 7 16\n22 23 4 12\n34 25 14", "8\n2 2 2 2 1 1 1 1\n10 9\n11... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
cbefa8ce4237f3212920f6d2b168800e | Shortest path of the king | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | [
"s, t = input(), input()\r\n\r\ns = [ord(s[0]) - ord('a') + 1, int(s[1])]\r\nt = [ord(t[0]) - ord('a') + 1, int(t[1])]\r\ncount = 0\r\np = []\r\nwhile (s != t):\r\n if (s[0] != t[0] and s[1] != t[1]):\r\n if (s[0] < t[0]):\r\n if (s[1] < t[1]):\r\n s[0] += 1\r\n s[... | {"inputs": ["a8\nh1", "b2\nb4", "a5\na5", "h1\nb2", "c5\nh2", "e1\nf2", "g4\nd2", "a8\nb2", "d4\nh2", "c5\na2", "h5\nf8", "e6\nb6", "a6\ng4", "f7\nc2", "b7\nh8", "g7\nd6", "c8\na3", "h8\nf1", "d1\nb7", "a7\ne5", "d6\nb1", "f5\ng5", "h4\nd1", "b3\na5", "d2\nf1", "f1\nc5", "a8\nh1", "c7\ne5", "e7\nb1", "g8\na8", "g6\nf2"... | UNKNOWN | PYTHON3 | CODEFORCES | 273 | |
cbf2401bef0f45c21901b34f0c5649fa | Kalila and Dimna in the Logging Industry | Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money.
The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain sa... | [
"f = lambda: list(map(int, input().split()))\r\ng = lambda j: a[i] * b[j] + t[j]\r\nh = lambda j, k: (t[i] - t[j]) * (b[j] - b[k]) < (t[j] - t[k]) * (b[i] - b[j])\r\n\r\nn = int(input())\r\na, b = f(), f()\r\nt = [0] * n\r\np = [0]\r\nfor i in range(1, n):\r\n while len(p) > 1 and g(p[1]) < g(p[0]): p.pop(0)\r\n... | {"inputs": ["5\n1 2 3 4 5\n5 4 3 2 0", "6\n1 2 3 10 20 30\n6 5 4 3 2 0"], "outputs": ["25", "138"]} | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
cbf4ad8bd05b36fab2101dcda7d9b6c9 | Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | [
"MOD = 10**9+7\r\n\r\n\r\ndef solve(values):\r\n notUsed = set(range(1, len(values)+1))\r\n chairs = set()\r\n for i, a in enumerate(values, 1):\r\n if a == -1:\r\n chairs.add(i)\r\n else:\r\n notUsed -= {a}\r\n fixed = len(chairs & notUsed)\r\n m = len(notUsed)\r\... | {"inputs": ["5\n-1 -1 4 3 -1", "8\n2 4 5 3 -1 8 -1 6", "7\n-1 -1 4 -1 7 1 6", "6\n-1 -1 -1 -1 -1 -1", "2\n-1 -1", "10\n4 10 -1 1 6 8 9 2 -1 -1", "20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"], "outputs": ["2", "1", "4", "265", "1", "4", "927799753"]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
cc22c937dd57137fe8ae380fccc12c66 | Dynasty Puzzles | The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the... | [
"from sys import stdin\nn = int(stdin.readline().strip())\nl = [stdin.readline().strip() for i in range(n)]\ndp = []\nfor i in range(26):\n dp.append([-999999999] * 26)\nans = 0\nfor i in range(26):\n dp[i][i] = 0\n for j in range(n):\n first = ord(l[j][0]) - 97\n ln = len(l[j])\n last... | {"inputs": ["3\nabc\nca\ncba", "4\nvvp\nvvp\ndam\nvvp", "3\nab\nc\ndef", "5\nab\nbc\ncd\nde\nffffffffff", "5\ncab\nbbc\ncaa\nccc\naca", "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd", "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhjgcia... | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
cc2ed94d2164907de60a5c20c496a2e5 | Car Repair Shop | 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 o... | [
"n = int(input())\r\nl, r = [0] * n, [0] * n\r\nf = lambda x, y: all(x > r[j] or y < l[j] for j in range(i))\r\n \r\nfor i in range(n):\r\n x, d = map(int, input().split())\r\n y = x + d - 1\r\n \r\n if not f(x, y):\r\n k = min(r[j] for j in range(i + 1) if f(r[j] + 1, r[j] + d))\r\n x, y = k... | {"inputs": ["3\n9 2\n7 3\n2 4", "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "1\n1 1", "1\n1000000000 1", "1\n1000000000 5000000", "5\n6 2\n10 1\n10 2\n9 2\n5 1", "10\n1 3\n77 8\n46 5\n83 4\n61 7\n8 4\n54 7\n80 7\n33 7\n13 4", "10\n588 12\n560 10\n593 14\n438 15\n761 11\n984 6\n50... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
cc32fd5210a68b5474019c046d82478b | PolandBall and Forest | PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a valid tree.
There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to ... | [
"def main():\n n = int(input())\n relav = list(map(int,input().split()))\n\n trees = dict.fromkeys(range(1,n+1),-1)\n\n for i in range(n):\n if trees[relav[i]] == -1:\n trees[i+1]=relav[i]\n else:\n trees[i+1]=trees[relav[i]]\n #print(trees)\n count = 0\n for... | {"inputs": ["5 3\n1 2\n3 4\n4 5", "1 0", "5 1\n4 5", "10 3\n2 8\n5 9\n6 10", "18 2\n9 17\n1 18", "1 0", "2 1\n1 2", "2 0", "3 1\n2 3", "3 2\n1 2\n2 3", "3 0", "10000 1\n1725 10000", "5 4\n1 3\n1 4\n4 2\n5 2", "4 3\n3 1\n1 2\n2 4", "5 4\n3 2\n2 5\n5 1\n1 4", "5 4\n1 2\n1 3\n1 4\n3 5", "6 5\n1 4\n2 3\n3 4\n4 5\n5 6"], "o... | UNKNOWN | PYTHON3 | CODEFORCES | 77 | |
cc3d4bf0993f096240a30911a45cbe0e | Swaps in Permutation | You are given a permutation of the numbers 1,<=2,<=...,<=*n* and *m* pairs of positions (*a**j*,<=*b**j*).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let *p* and *q* be two permutations of the numbe... | [
"from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\nN, M = map(int, input().split())\r\n\r\n\r\nparent = [i for i in range(N)]\r\nrank = [0] * N\r\n\r\n\r\ndef find(i):\r\n if parent[i] == i:\r\n return i\r\n else:\r\n parent[i] = find(parent[i])\r\n return... | {"inputs": ["9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9", "1 1\n1\n1 1", "2 10\n2 1\n2 1\n1 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 1\n2 1\n2 1", "3 10\n1 2 3\n2 2\n1 1\n2 2\n3 3\n1 1\n3 3\n3 3\n3 3\n2 2\n1 1", "4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3\n3 3\n1 4\n3 3\n2 2\n3 3\n4 1\n2 2\n1 4\n3 3\n4 1\n1 1\n3 3\n2 2\n2 2... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
cc5c1d4e139eb29e530d93e1760c9634 | The Race | Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.
So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li... | [
"n = int(input())\r\n\r\nzap = list(map(int, input().split()))\r\n\r\nupperbound = float('inf')\r\nlowerbound = -float('inf')\r\n\r\ncounter = 1\r\nfor item in zap:\r\n upperbound = min(upperbound, 10/counter + 10 * item / counter)\r\n counter += 1\r\n\r\nk = 1\r\nfor item in zap:\r\n lowerbound = max(lowe... | {"inputs": ["3\n1 2 4", "2\n1 2", "1\n5", "3\n1 3 4", "5\n1 2 3 5 6", "6\n1 2 3 5 6 7", "10\n1 2 4 5 7 8 9 11 12 14", "10\n1 3 5 6 8 10 12 13 15 17", "9\n2 5 7 10 12 15 17 20 22", "10\n7 14 21 28 35 42 49 56 63 70", "15\n5 11 16 22 28 33 39 45 50 56 62 67 73 79 84", "17\n5 11 16 22 28 33 39 45 50 56 62 67 73 79 84 90 9... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
cc5c29e25f4a62e672d02de221aa504b | Divisiblity of Differences | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | [
"n,k,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\n\r\nmods=[0]*m\r\nmod=0\r\nfor i in range(n):\r\n\tmod=a[i]%m\r\n\tmods[mod]+=1\r\n\tif mods[mod]==k:\r\n\t\tbreak\r\nelse:\r\n\tprint('No')\r\n\texit()\r\nprint('Yes')\r\nresults=[None]*k\r\ncount=0\r\nfor i in range(n):\r\n\tcur=a[i]\r\n\tif c... | {"inputs": ["3 2 3\n1 8 4", "3 3 3\n1 8 4", "4 3 5\n2 7 7 7", "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455",... | UNKNOWN | PYTHON3 | CODEFORCES | 129 | |
cc71101bf1a32ac7a83f342726de0a60 | Lucky Year | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | [
"n=int(input())\r\ns=str(n)\r\nr=int(s[0])+1\r\nss=str(r)+'0'*(len(s)-1)\r\nss=int(ss)\r\nprint(ss-n)\r\n",
"n = int(input())\n\nprint(((1 + int(str(n)[0])) * 10**(len(str(n)) - 1)) - n)\n# Sat Oct 07 2023 19:59:11 GMT+0300 (Moscow Standard Time)\n",
"x = int(input())\r\ndef First(year):\r\n year = str(year)... | {"inputs": ["4", "201", "4000", "9", "10", "1", "100000000", "900000000", "999999999", "1000000000", "9999999", "100000001", "3660", "21", "900000001", "62911", "11", "940302010", "91", "101", "1090", "987654321", "703450474", "1091", "89", "109", "190", "19", "8", "482", "1", "2", "3", "4", "5", "6", "7", "8", "9", "1... | UNKNOWN | PYTHON3 | CODEFORCES | 282 | |
cc711c4080333b9f14e986ed9ffc24fa | Heroes | The year of 2012 is coming...
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us... | [
"import math\nimport itertools\n\nif __name__ == '__main__':\n N = int(input())\n likes = [input() for i in range(N)]\n likes = [line.split() for line in likes]\n likes = [(words[0], words[2]) for words in likes]\n a, b, c = (float(val) for val in input().split())\n\n min_diff = max(a, b, c)\n ... | {"inputs": ["3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180", "2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50", "11\nSnowy likes Dracul\nAnka likes Dracul\nChapay likes Snowy\nHexadecimal likes Troll\nAnka likes Cleo\nChapay likes Dracul\nAnka likes Chapay\nSnowy likes Troll\nAnka ... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
cc9a6194b46b75af2a7ecae3f3b268ef | Tournament | The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participa... | [
"\r\nn=int(input())\r\nd={}\r\nl=[]\r\nfor i in range((n*(n-1))//2-1):\r\n x,y=map(int,input().split())\r\n l.append([x,y])\r\n d[x]=d.get(x,0)+1\r\n d[y]=d.get(y,0)+1\r\nans=[]\r\nfor i in d.keys():\r\n if d[i]==n-2:\r\n ans.append(i)\r\nf1=0\r\nf2=0\r\nfor i in l:\r\n if i[0]==ans[0]:\r\n... | {"inputs": ["3\n3 2\n1 2", "4\n2 4\n3 4\n1 2\n1 4\n1 3", "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2", "6\n3 4\n3 5\n5 4\n1 2\n5 6\n2 6\n5 2\n3 6\n3 2\n4 6\n2 4\n1 3\n1 5\n1 4", "7\n2 4\n6 1\n6 5\n3 4\n6 3\n2 6\n6 4\n3 7\n7 1\n1 4\n7 4\n7 5\n2 7\n2 3\n5 4\n3 5\n3 1\n5 1\n6 7\n2 1", "8\n4 3\n6 8\n1 5\n8 3\n1 4\n1 7\... | UNKNOWN | PYTHON3 | CODEFORCES | 63 | |
cc9dd4e6b5f4255387e96f4f9d873077 | Alphabetic Removals | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | [
"n,k=map(int,input().split())\r\ns=input()\r\nfor j in range(ord('a'), ord('z') + 1):\r\n i=len(s)\r\n s=s.replace(chr(j), \"\",k)\r\n j=len(s)\r\n k-=(i-j)\r\n if k==0:\r\n break\r\n\r\nprint(s)",
"n, k = map(int, input().split())\r\ns=[*input()]\r\na = sorted([(x, y) for y, x in enumerate(... | {"inputs": ["15 3\ncccaabababaccbc", "15 9\ncccaabababaccbc", "5 2\nzyzyx", "4 3\nhack", "4 3\nzzzz", "6 5\naaccdd", "2 1\nzz", "14 5\nhxehmvkybeklnj"], "outputs": ["cccbbabaccbc", "cccccc", "zzy", "k", "z", "d", "z", "xmvkyklnj"]} | UNKNOWN | PYTHON3 | CODEFORCES | 98 | |
cca086aaaaa8acaf7ee3d71ae7350ac6 | none | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this... | [
"n = int(input())\na = [int(i) for i in input().split()]\nl = [i for i in range(len(a))]\nr = [i for i in range(len(a))]\nfor i in range(len(a)):\n\twhile l[i]>=1 and a[i]|a[l[i]-1]<=a[i]:\n\t\tl[i] = l[l[i]-1]\n \nfor j in range(len(a)):\n\ti = len(a)-j-1\n\twhile r[i]<len(a)-1 and a[i]|a[r[i]+1]<=a[i] and a[i]... | {"inputs": ["5\n3 2 1 6 5", "4\n3 3 3 3", "1\n0", "1\n1", "1\n1000000000", "1\n6", "228\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
ccab9113e4676fc4e63aefdba473c54e | Non-Secret Cypher | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the informati... | [
"from collections import defaultdict\nn, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\nwindow = defaultdict(lambda : 0)\nwindow[a[0]] += 1\ni, j, ans = 0, 0, 0\nwhile i < n and j < n:\n if window[a[j]] >= k:\n ans += n-j\n window[a[i]] -= 1\n i += 1\n elif ... | {"inputs": ["4 2\n1 2 1 2", "5 3\n1 2 1 1 3", "3 1\n1 1 1", "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10", "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3 1 1 3 1 1 1 1 2 1 1 6 3 2 1 1 1 1 2 2 3 2 1 1 1 2 1 4 2 1 2 3 2 1 1 1 1 2 4 3 4 2 5 1 1 2 1", "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 7... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
ccb33a039bf5e61811f4bf46ba0c1b6c | Powers of Two | You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Find the number of pairs of indexes *i*,<=*j* (*i*<=<<=*j*) that *a**i*<=+<=*a**j* is a power of 2 (i. e. some integer *x* exists so that *a**i*<=+<=*a**j*<==<=2*x*).
The first line contains the single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of int... | [
"import sys\r\ninput = sys.stdin.readline\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\nw = Counter(map(int, input().split()))\r\nd = []\r\nc = 0\r\nfor i in range(31):\r\n d.append(2**i)\r\nfor i in w:\r\n for j in d:\r\n if j > i:\r\n x = j-i\r\n if x == i:\r\n ... | {"inputs": ["4\n7 3 2 1", "3\n1 1 1", "1\n1000000000", "10\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607", "10\n6 6 7 3 9 14 15 7 2 2", "100\n3 6 12 1 16 4 9 5 4 4 5 8 12 4 6 14 5 1 2 2 2 1 7 1 9 10 6 13 7 8 3 11 8 11 7 5 15 6 14 10 4 2 10 9 1 8 14 9 5 11 3 4 1 12 6 8 13 4 8 ... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
cceb3418316a02ad44067bef5d4dfbc8 | Olympiad | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | [
"n=int(input())\na=list(map(int,input().split()))\nsa=set(a)\narr=list(sa)\ncount=0\nfor i in sa:\n if i!=0:\n count+=1\nprint(count) \n\t\t\t \t \t \t \t\t \t \t \t\t",
"jagratha=int(input())\r\nmanushulu=list(map(int,input().split()))\r\nwhile(0 in manushulu):\r\n manushulu.remove(0)\... | {"inputs": ["4\n1 3 3 2", "3\n1 1 1", "4\n42 0 0 42", "10\n1 0 1 0 1 0 0 0 0 1", "10\n572 471 540 163 50 30 561 510 43 200", "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322... | UNKNOWN | PYTHON3 | CODEFORCES | 763 | |
ccf90e94056e7f71bca90c97428d0854 | DZY Loves Chessboard | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | [
"n, m = map(int, input().split())\r\ninp = [input() for _ in range(n)]\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if inp[i][j] == '-':\r\n print('-', end='')\r\n else:\r\n print('B' if (i+j)%2==0 else 'W', end='')\r\n print('')",
"n, m = map(int, input().split()... | {"inputs": ["1 1\n.", "2 2\n..\n..", "3 3\n.-.\n---\n--.", "3 1\n-\n.\n.", "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------", "1 1\n-", "4 2\n..\n..\n..\n..", "5 1\n.\n.\n.\n.\n."], "outputs": ["B", "BW\nWB", "B-B\n---\... | UNKNOWN | PYTHON3 | CODEFORCES | 323 | |
ccfde368ce481926b7fe8da6a5a19d86 | Maxim and Matrix | Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (*m*<=+<=1)<=×<=(*m*<=+<=1):
Maxim asks you to count, how many numbers *m* (1<=≤<=*m*<=≤<=*n*) are there, such that the sum of values in the cells in the row number *m*<=+<=1 of the resulting matrix equals *t*.
... | [
"# i'm from jasnah, do not ban me\r\nn, t = map(int, input().split())\r\nn += 1\r\nif t & (t - 1):\r\n print(0)\r\nelse:\r\n dp = [0] * 65\r\n c = 0\r\n for j in range(60, -1, -1):\r\n for i in range(60, 0, -1):\r\n dp[i] += dp[i - 1]\r\n if n >> j & 1:\r\n dp[c] += 1... | {"inputs": ["1 1", "3 2", "3 3", "1000000000000 1048576", "35 4", "70 32", "79 32", "63 16", "6 4", "82 16", "4890852 16", "473038165 2", "326051437 4", "170427799 16", "168544291 8", "82426873 1", "175456797 16384", "257655784 16384", "9581849 1024", "8670529 16384", "621597009 268435456", "163985731 33554432", "75864... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
cd1341a74edf0fecdcc915ce6739938a | Well-known Numbers | Numbers *k*-bonacci (*k* is integer, *k*<=><=1) are a generalization of Fibonacci numbers and are determined as follows:
- *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=<<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), fo... | [
"s,k=map(int,input().split())\r\nf=[0]\r\nf.append(1)\r\nwhile(True):\r\n cur=sum(f[-k:])\r\n if cur>s:\r\n break\r\n f.append(cur)\r\nf=list(set(f))\r\nf.sort()\r\nans=[]\r\ni=len(f)-1\r\nwhile(s and i>0):\r\n if f[i]<=s:\r\n s-=f[i]\r\n ans.append(f[i])\r\n i-=1\r\nprint(len(an... | {"inputs": ["5 2", "21 5", "1 1000", "1000000000 1000000000", "122 7", "4 3", "321123 3211232", "1 2", "2 2", "3 2", "8 2", "17 2", "137 2", "7298 2", "76754 2", "12345678 2", "987654321 2", "1000000000 2", "701408733 2", "1 3", "2 3", "3 3", "100 3", "87783 3", "615693473 3", "615693474 3", "1000000000 3", "1 4", "2 4... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
cd3089bf322bec62b4b20e5acd4e4a51 | Little Robber Girl's Zoo | Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl was angry at first, but then she decided to arrange the animals herself. She ... | [
"n= int(input())\r\na = list(map(int,input().split()))\r\nQQQ = 0\r\nwhile True:\r\n B = list(a)\r\n for i in range(n-1):\r\n if a[i] > a[i+1]:\r\n print(i+1,i+2)\r\n a[i],a[i+1] = a[i+1],a[i]\r\n #print(a)\r\n if a == B:\r\n break",
"if __name__ == '__main__':\n n = int(input())\n a... | {"inputs": ["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1", "78\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38 40 39 42 42 48 46 49 49 58 50 60 58 65 61 68 66 69 69 69 69 70 69 71 71 77 73 78 77 80 79 85 83 86 86 86 86 88 87 91 90 96 91 98 97 99 98", "99\n5 5 5 5 5 5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
cd3bf5d29eadbcf458616c8f199d7895 | Borya and Hanabi | Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding *n* cards. The game is somewhat complicated by the fact that everybody sees Borya's cards exc... | [
"input()\r\np={ (1<< 'RGBYW'.index(c)) + (1<<int(k)+4) for c, k in input().split()}\r\nmn=20\r\nres=90\r\nfor i in range(1024):\r\n if len(p)==len(set(i&j for j in p)):\r\n mn=min(mn,bin(i).count('1'))\r\nprint(mn)",
"n = int(input())\r\nlist1 = list(set(input().split()))\r\nbins = []\r\nif len(list1)==... | {"inputs": ["2\nG3 G3", "4\nG4 R4 R3 B3", "5\nB1 Y1 W1 G1 R1", "10\nY4 B1 R3 G5 R5 W3 W5 W2 R1 Y1", "3\nG4 G3 B4", "2\nW3 Y5", "2\nW5 Y5", "100\nW4 Y1 W5 R4 W3 Y1 R4 W2 G3 G1 B5 Y5 Y2 Y3 G4 B5 W1 G5 Y5 Y3 G2 Y5 Y5 G5 R2 B3 B1 W5 Y1 W5 B4 W4 R4 B1 R1 W3 R5 R4 G2 W3 W3 R2 W5 Y2 B2 R3 R3 Y1 G5 G2 Y1 R4 Y5 W5 G5 B3 W2 R1 B... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
cd70c7ee2dfbd1f686f64c9d0ed3c074 | Quarrel | Friends Alex and Bob live in Bertown. In this town there are *n* crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads number *n*.
One day Alex and Bob had a big quarrel, and they refused to see each other. It... | [
"import sys\nfrom collections import deque\nreadline = sys.stdin.readline\n\nN, M = [int(w) for w in readline().split()]\ncity = [[] for _ in range(N + 1)]\nedges = []\nfor _ in range(M):\n u, v = [int(w) for w in readline().split()]\n city[u].append(v)\n city[v].append(u)\n edges.append((u, v))\n\ndef ... | {"inputs": ["2 1\n1 2", "7 5\n1 2\n2 7\n7 6\n2 3\n3 4", "7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5", "6 10\n3 6\n3 5\n1 3\n2 6\n5 4\n6 4\n6 5\n5 1\n2 3\n1 2", "5 7\n5 2\n1 3\n4 2\n3 4\n5 3\n2 3\n4 1", "10 7\n3 4\n8 6\n4 8\n3 1\n9 10\n10 6\n9 4", "10 16\n9 8\n1 2\n9 5\n5 4\n9 2\n3 2\n1 6\n5 10\n7 2\n8 2\n3 7\n4 9\n5 7\n10 3\n10... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
cd8569e989f67f116902d5f72934bb5a | Remainders Game | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has... | [
"import math\r\nfrom typing import List\r\n\r\n#calcula la descomposicion en primos de un numero\r\ndef PrimesDiv(n):\r\n primes_list=[]\r\n cant=0\r\n while n%2==0:\r\n cant+=1\r\n n=n/2\r\n if cant:primes_list.append([2,cant])\r\n\r\n for i in range(3,int(math.sqrt(n))+1,2):\r\n ... | {"inputs": ["4 5\n2 3 5 12", "2 7\n2 3", "1 6\n8", "2 3\n9 4", "4 16\n19 16 13 9", "5 10\n5 16 19 9 17", "11 95\n31 49 8 139 169 121 71 17 43 29 125", "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17", "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71", "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 3... | UNKNOWN | PYTHON3 | CODEFORCES | 26 | |
cdab43ee10fbd94cbd611a337801b847 | Mahmoud and Ehab and the MEX | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, x = map(int, input().split())\r\na = list(map(int, input().split()))\r\nl = 105\r\ncnt = [0] * l\r\nfor i in a:\r\n cnt[i] += 1\r\nans = 0\r\nfor i in range(x):\r\n if not cnt[i]:\r\n ans += 1\r\nans += cnt[x]... | {"inputs": ["5 3\n0 4 5 6 7", "1 0\n0", "5 0\n1 2 3 4 5", "10 5\n57 1 47 9 93 37 76 70 78 15", "10 5\n99 98 93 97 95 100 92 94 91 96", "10 5\n1 2 3 4 59 45 0 58 51 91", "100 100\n79 13 21 11 3 87 28 40 29 4 96 34 8 78 61 46 33 45 99 30 92 67 22 97 39 86 73 31 74 44 62 55 57 2 54 63 80 69 25 48 77 98 17 93 15 16 89 12 4... | UNKNOWN | PYTHON3 | CODEFORCES | 160 | |
cdd53a40de34107ec869a299815ab410 | Embassy Queue | In an embassy of a well-known kingdom an electronic queue is organised. Every person who comes to the embassy, needs to make the following three actions: show the ID, pay money to the cashier and be fingerprinted. Besides, the actions should be performed in the given order.
For each action several separate windows are... | [
"from collections import deque\nfrom typing import List\n\ndef maximum_time_spend(k1: int, k2: int, k3: int, t1: int, t2: int, t3: int,\n n: int, oq: List[int]) -> int:\n\n k = [k1, k2, k3]\n t = [t1, t2, t3]\n c = [[0] * n for i in range(3)]\n s = 0\n for i in range(n):\n ... | {"inputs": ["1 1 1\n1 1 1\n5\n1 1 1 1 1", "2 1 1\n5 1 1\n5\n1 2 3 3 5", "1 1 1\n1 1 1\n5\n1 2 3 4 5", "1 1 1\n1 1 1\n5\n1 2 3 3 4", "9 5 6\n8 2 2\n1\n5", "2 7 3\n8 10 5\n5\n5 6 7 8 9", "3 9 10\n3 10 4\n5\n2 2 2 2 2", "2 7 1\n10 3 10\n100\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 3... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
ce078bca9cb34927fa29762b3a352266 | Fraction | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | [
"from math import gcd\r\nn=int(input())\r\n#print(gcd(1,0))\r\na=0\r\nu=[]\r\nfor i in range(1,n+1):\r\n if gcd(a+i,n-i)==1:\r\n u.append([a+i,n-i])\r\nprint(*u[(len(u)//2)-1])\r\n \r\n",
"n = int(input())\r\ni = 1\r\nj = n - 1\r\nmxi = -1\r\nmxj = 1001\r\nwhile i < j:\r\n for d in range(2, i+1):\... | {"inputs": ["3", "4", "12", "34", "13", "11", "24", "17", "10", "69", "100", "57", "1000", "999", "998", "997", "996", "995", "994", "5", "6", "8", "9", "423", "876", "29"], "outputs": ["1 2", "1 3", "5 7", "15 19", "6 7", "5 6", "11 13", "8 9", "3 7", "34 35", "49 51", "28 29", "499 501", "499 500", "497 501", "498 49... | UNKNOWN | PYTHON3 | CODEFORCES | 325 | |
ce18d7053c8a3377aad3bca251aa0bc6 | Event Dates | On a history lesson the teacher asked Vasya to name the dates when *n* famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [*l**i*,<=*r**i*] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help... | [
"n = int(input())\r\nseg = []\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n seg.append((l, r, i))\r\n\r\nseg.sort(key=lambda tup: (tup[1], tup[0], tup[2]))\r\nassigned = set()\r\nans = [0] * n\r\n\r\nfor i in range(n):\r\n \r\n # this loop won't run more than 100 times as n <= 100\r... | {"inputs": ["3\n1 2\n2 3\n3 4", "2\n1 3\n1 3", "10\n1 10\n3 4\n8 10\n3 4\n5 9\n1 4\n7 10\n1 9\n1 8\n4 10", "10\n1 1\n8 10\n1 7\n6 8\n5 7\n1 9\n8 8\n6 10\n1 4\n3 4", "10\n1 2\n1 3\n1 9\n10 10\n4 4\n5 9\n2 5\n7 8\n2 10\n7 10", "10\n4 12\n2 8\n1 12\n6 8\n4 6\n12 12\n3 10\n1 10\n3 3\n1 10", "10\n6 7\n5 11\n5 10\n9 10\n11 1... | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
ce33750da56e1793b724225fd29caf3f | Diversity | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input conta... | [
"s = input()\r\nx = int(input())\r\nif x > len(s):\r\n print('impossible')\r\nelif x < len(set(s)):\r\n print(0)\r\nelse:\r\n print(x - len(set(s)))",
"ch=input()\r\nk=int(input())\r\nd={}\r\nfor e in ch:\r\n if e in d:\r\n d[e]+=1\r\n else:\r\n d[e]=1\r\nn=len(d)\r\nif n>=k:\r\n p... | {"inputs": ["yandex\n6", "yahoo\n5", "google\n7", "a\n1", "z\n2", "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26", "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26", "a\n3", "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1", "cuguccgcugc... | UNKNOWN | PYTHON3 | CODEFORCES | 236 | |
ce3c021d36b6ba21396a789329d9a43d | Prime Matrix | You've got an *n*<=×<=*m* matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times.
You are really curious about prime numbers. Let us remind you ... | [
"import sys\r\n\r\ndistancia_prima = [0] * (10**5 + 4)\r\n\r\ndef precompute_prime_distance():\r\n is_prime = [True] * (10**5 + 10)\r\n is_prime[0] = is_prime[1] = False\r\n for i in range(2, 10**5 + 4):\r\n if is_prime[i]:\r\n for multiplo in range(2 * i, 10**5 + 4, i):\r\n ... | {"inputs": ["3 3\n1 2 3\n5 6 1\n4 4 1", "2 3\n4 8 8\n9 2 9", "2 2\n1 3\n4 2", "1 1\n14", "5 3\n2 14 8\n8 8 2\n8 10 10\n1 2 1\n100 100 8", "6 5\n8 8 8 8 20\n13 8 16 13 9\n11 5 3 14 18\n13 8 6 18 6\n6 8 9 14 7\n2 14 14 9 3", "5 7\n9 5 3 9 2 8 2\n15 7 9 8 18 4 6\n2 9 14 3 6 13 18\n4 13 3 14 11 13 8\n14 10 1 14 18 5 6", "3... | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
ce51e9e2bf9e9d028f33636c885eb53c | Black Square | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | [
"k = list(map(int,input().split()))\r\ns = str(input())\r\n\r\nsum = 0\r\n\r\nfor i in s:\r\n if i == \"1\":\r\n sum += k[0]\r\n elif i == \"2\":\r\n sum += k[1]\r\n elif i == \"3\":\r\n sum += k[2]\r\n elif i == \"4\":\r\n sum += k[3]\r\n\r\nprint(sum)\r\n",
"sList = [int... | {"inputs": ["1 2 3 4\n123214", "1 5 3 2\n11221", "5 5 5 1\n3422", "4 3 2 1\n2", "5651 6882 6954 4733\n2442313421", "0 0 0 0\n4132", "3163 5778 83 7640\n11141442444", "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442", "0 0 0 0\n1", "1 2 3 4\n4", "... | UNKNOWN | PYTHON3 | CODEFORCES | 1,034 | |
ceae7eedfe1a4cc59e25f381a4377cac | Famil Door and Roads | Famil Door’s City map looks like a tree (undirected connected acyclic graph) so other people call it Treeland. There are *n* intersections in the city connected by *n*<=-<=1 bidirectional roads.
There are *m* friends of Famil Door living in the city. The *i*-th friend lives at the intersection *u**i* and works at the ... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef bfs(s):\r\n q = [s]\r\n dist = [-1] * (n + 1)\r\n dist[s] = 0\r\n parent = [-1] * (n + 1)\r\n for k in range(n):\r\n i = q[k]\r\n di = dist[i]\r\n for j in G[i]:\r\n if dist[... | {"inputs": ["4 3\n2 4\n4 1\n3 2\n3 1\n2 3\n4 1", "3 3\n1 2\n1 3\n1 2\n1 3\n2 3", "10 5\n8 10\n3 6\n7 3\n7 4\n8 9\n9 4\n5 1\n10 5\n6 2\n9 1\n7 6\n5 1\n6 9\n10 2"], "outputs": ["4.00000000\n3.00000000\n3.00000000", "2.50000000\n2.50000000\n3.00000000", "7.50000000\n6.50000000\n6.00000000\n7.50000000\n9.00000000"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.