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
ee290edbd5a1f89e87bcf4c569f8b0ac
Marks
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook. Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject. Let's consider a student the best at ...
[ "import sys,math\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\nn,m = get_ints()\r\nar = [0]*n\r\nL = []\r\nfor i in range(n):\r\n s = get_string()\...
{"inputs": ["3 3\n223\n232\n112", "3 5\n91728\n11828\n11111", "2 2\n48\n27", "2 1\n4\n6", "1 2\n57", "1 1\n5", "3 4\n2553\n6856\n5133", "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285", "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994", "10 20\n...
UNKNOWN
PYTHON3
CODEFORCES
355
ee5b860445484c793c2090948a1390f4
Cheap Travel
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu...
[ "import math\r\nnumbers = input('')\r\n\r\nnumbers = numbers.split(' ')\r\nnumbers = [int(i) for i in numbers]\r\n\r\nn = numbers[0]\r\nm = numbers[1]\r\na = numbers[2]\r\nb = numbers[3]\r\n\r\nwithout_special = n * a\r\nwith_special = ((math.ceil(n / m) * m) / m) * b\r\nhybrid = (math.floor(n / m) * b) + ((n % m) ...
{"inputs": ["6 2 1 2", "5 2 2 3", "10 3 5 1", "1000 1 1000 1000", "1000 3 1000 1000", "1 1 1 1", "10 2 1 1", "1 1000 1 2", "1 1000 3 2", "10 3 1 2", "995 1 2 1", "556 2 16 15", "477 2 16 14", "101 110 1 100", "9 3 3 10", "100 8 10 1", "6 4 1 3", "8 5 2 8", "1000 2 1 1000"], "outputs": ["6", "8", "4", "1000000", "334000...
UNKNOWN
PYTHON3
CODEFORCES
211
ee651746d24d782078b0ebdf67678f88
none
There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names. Political parties find their number in the ballot highly important. Overall there are *m* possible numbers: 1,<=2,<=...,<=*m*. Each of ...
[ "MOD = 1000000007\r\ndp = [[[0] * 2 for _ in range(11)] for _ in range(11)]\r\nN = 0\r\ndig = [0] * 11\r\ndigits = 0\r\ndef rec(n, lucky, pre):\r\n global dp\r\n if n == 0:\r\n if lucky == 0:\r\n return 1\r\n else:\r\n return 0\r\n r = dp[n][lucky][pre]\r\n if r != -1...
{"inputs": ["7", "8", "47", "10", "9", "11", "25", "74", "128", "1000000000", "458754", "987549745", "15478459", "674810014", "245", "1000", "10000", "100000", "1000000", "100000000", "10000000", "54785", "68745844", "545794012", "301542785", "794512405", "30", "40", "44", "42"], "outputs": ["0", "1440", "907362803", "...
UNKNOWN
PYTHON3
CODEFORCES
1
ee669d4259b4c354077301faf4447276
Lucky Substring
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya was delivered a string *s*, containing only digits. He needs to find a string that - ...
[ "s = input()\r\nd4 = 0\r\nd7 = 0\r\nfor c in s:\r\n if c == '4':\r\n d4 += 1\r\n if c == '7':\r\n d7 += 1\r\nif not d4 and not d7:\r\n print('-1')\r\nelif d4 == d7:\r\n print('4')\r\nelif d4 > d7:\r\n print('4')\r\nelse:\r\n print('7')", "n = input()\r\nprint((7, 4, -1)[-1 if n.cou...
{"inputs": ["047", "16", "472747", "1925", "5486846414848445484", "516160414", "9458569865994896", "94894948577777777884888", "00000", "9589", "7665711", "538772857", "8679647744", "23607019991994", "86145305734278927901987281894864719533015270066521", "22438808523154336905543301642540261833729318191", "290732082244359...
UNKNOWN
PYTHON3
CODEFORCES
19
ee790672cff083b346103762a1110517
Fibonacci Number
John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when div...
[ "ak=int(10**13)\r\nf=int(input())\r\nn,m,List=10000,15000,[]\r\n\r\ndef Fun1(input):\r\n\tif input==0:\r\n\t\treturn (0,1)\r\n\ta,b=Fun1(input>>1)\r\n\ta,b=((2*a*b-a*a)%n,(b*b+a*a)%n)\r\n\tif input&1:\r\n\t\ta,b=(b%n,(a+b)%n)\r\n\treturn (a,b)\r\n\r\nfor j in range(m):\r\n\tif Fun1(j)[0]==f%n:\r\n\t\tList.append(j)...
{"inputs": ["13", "377", "2406684390626", "1", "3705587146357", "2644848607501", "3153355924376", "2029910151951", "9673339843751", "9673339843751", "9137820308201", "5673339843751", "1800000000001", "5794082000001", "6138242440179", "7402222686319", "2524707127593", "2372721962933", "6052638322329", "2145870521291", "...
UNKNOWN
PYTHON3
CODEFORCES
9
ee9f800ad09193009ed6954de62a602e
Batch Sort
You are given a table consisting of *n* rows and *m* columns. Numbers in each row form a permutation of integers from 1 to *m*. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are al...
[ "from sys import stdin\nfrom sys import stdout\nfrom sys import exit\nnm = [int(x) for x in stdin.readline()[:-1].split(' ')]\nn = nm[0]\nm = nm[1]\nmatrice = [[] for z in range(n)]\nfor i in range(n):\n matrice[i] = [int(x) for x in stdin.readline()[:-1].split(' ')]\ncancomplete = False\na = [[0 for i in range(...
{"inputs": ["2 4\n1 3 2 4\n1 3 4 2", "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5", "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "5 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 8 5 6 7 10 9 4 11 12\n1 5 3 4 2 6 7 10 9 8 11 12\n1...
UNKNOWN
PYTHON3
CODEFORCES
32
eecb6998b9428babfb66e5c53e2102c3
Game with String
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string *s*, consisting of small English letters, and uniformly at random chooses an integer *k* from a segment [0,<=*len*(*s*)<=-<=1]. He tells Vasya this string *s*, and then shifts it *k* letters to the left, i. e. create...
[ "s = input()\nn = len(s)\nsett = {}\n\nfor i in range(n):\n if s[i] not in sett:\n sett[s[i]] = []\n sett[s[i]].append(s[i + 1:] + s[:i])\nans = 0\n\n# ao fazer sett.items(), é realizado unpack da chave,valor para k,l, respectivamente\nfor k, l in sett.items():\n tmp = 0\n for j in range(n - 1):\...
{"inputs": ["technocup", "tictictactac", "bbaabaabbb", "cbbbbcaaca", "cadbcdddda", "bababbdaee", "fabbbhgedd", "gaejllebhn", "bbababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbb", "eaaebccaeacdecaedcaabbbdeebccdcdaabeeaeeaddbaabdccebecebbbbedbdcbbbbbbecbaddcddcccdcbbadbe...
UNKNOWN
PYTHON3
CODEFORCES
11
eeea6d294ad71f72291c70c42d7bc5dd
Modulo Sum
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*. Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*. The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size ...
[ "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nrem = set()\r\nfor i in a:\r\n new = {(i + j) % m for j in rem | {0}}\r\n rem |= new\r\n if 0 in rem:\r\n print('YES')\r\n exit()\r\nprint('NO')", "l=lambda:map(int,input().split())\r\nn,k=l();a=set()\r\nfor i in l(...
{"inputs": ["3 5\n1 2 3", "1 6\n5", "4 6\n3 1 1 3", "6 6\n5 5 5 5 5 5", "4 5\n1 1 1 1", "5 5\n1 1 1 1 1", "4 7\n1 2 3 3", "1 47\n0", "2 47\n1 0", "9 11\n8 8 8 8 8 8 8 8 5", "10 11\n8 8 8 8 8 8 8 8 7 8", "3 5\n2 1 3", "100 968\n966 966 967 966 967 967 967 967 966 966 966 967 966 966 966 967 967 966 966 967 967 967 967 9...
UNKNOWN
PYTHON3
CODEFORCES
15
eeec33d280b9716e115cd0080f123cb9
Primal Sport
Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, an...
[ "from math import floor, sqrt\r\nimport bisect\r\n\r\nimport math\r\n\r\n\r\ndef rwh_primes2(n):\r\n # https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188\r\n \"\"\" Input n>=6, Returns a list of primes, 2 <= p < n \"\"\"\r\n correction = (n%6>1)\r\n...
{"inputs": ["14", "20", "8192", "1000000", "959806", "1452", "4", "6", "8", "9", "10", "12", "15", "16", "110880", "166320", "221760", "277200", "332640", "498960", "554400", "665280", "720720", "510510", "570570", "690690", "959818", "959878", "959902", "974847", "974859", "974931", "885481", "896809", "908209", "9350...
UNKNOWN
PYTHON3
CODEFORCES
31
eeee9d9b5074f669b25f5aa86308738f
Repaintings
A chessboard *n*<=×<=*m* in size is given. During the zero minute we repaint all the black squares to the 0 color. During the *i*-th minute we repaint to the *i* color the initially black squares that have exactly four corner-adjacent squares painted *i*<=-<=1 (all such squares are repainted simultaneously). This proce...
[ "def calcEdges(n, m):\r\n if n == 1:\r\n return m // 2 if m % 2 == 0 else m // 2 + 1\r\n if m == 1:\r\n return n // 2 if n % 2 == 0 else n // 2 + 1\r\n top, bottom, left, right = 0, 0, 0, 0\r\n left = n // 2 if n % 2 == 0 else n // 2 + 1\r\n right = n // 2 if m % 2 == 0 else left\r\n ...
{"inputs": ["3 3\n1", "3 3\n2", "1 1\n1", "8 8\n8", "9 10\n1", "9 9\n3", "10 9\n4", "1 5000\n3", "5000 1\n3", "4999 1\n7", "1 4999\n2309", "1 4999\n1000000", "1 1\n200", "5000 5000\n1000000000", "7 7\n777", "126 4125\n52", "1755 2051\n1", "3385 4978\n192", "3663 2904\n1149", "293 2183\n60", "1922 109\n41", "3552 3036\n...
UNKNOWN
PYTHON3
CODEFORCES
11
ef24c77593c5f2b7e036ea0dbeb8f091
Ice Skating
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves...
[ "n=int(input())\r\nq={}\r\nl=[]\r\nr=[]\r\ndef f(a):\r\n while q[a]!=a:\r\n a=q[a]\r\n return a\r\nfor i in range(n):\r\n a,b=map(str,input().split())\r\n o,p=\"x\"+a,\"y\"+b\r\n l+=[[o,p]]\r\n r+=[o,p]\r\n q[o]=o\r\n q[p]=p\r\nfor i in range(n):\r\n l[i][0]=f(l[i][0])\r\n l[i][...
{"inputs": ["2\n2 1\n1 2", "2\n2 1\n4 1", "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459", "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312...
UNKNOWN
PYTHON3
CODEFORCES
344
ef3243360f9822d7c0381c2f12cfbc4f
Guest From the Past
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas...
[ "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\nl = 0\nwhile n >= a or n >= b:\n if n >= b and b - c < a:\n nl1 = (n - b) // (b - c)\n nl2 = n // b\n nl = max(nl1, nl2)\n l += nl\n n -= (b - c) * nl\n else:\n nl = n // a\n l += nl\n ...
{"inputs": ["10\n11\n9\n8", "10\n5\n6\n1", "2\n2\n2\n1", "10\n3\n3\n1", "10\n1\n2\n1", "10\n2\n3\n1", "9\n2\n4\n1", "9\n2\n2\n1", "9\n10\n10\n1", "10\n2\n2\n1", "1000000000000000000\n2\n10\n9", "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000", "10\n1\n9\n8", "10\n8\n8\n7", "10\n5\n5\n1",...
UNKNOWN
PYTHON3
CODEFORCES
37
ef44ef5c48e114113fdb4216e7802b81
Polo the Penguin and Segments
Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*). He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 uni...
[ "myMap = map(int , input().split())\r\nmyMap = list(myMap)\r\nn , k , sum = myMap[0] , myMap[1] , 0\r\n\r\nfor i in range(n) :\r\n temp = map(int , input().split())\r\n temp = list(temp)\r\n sum+= (temp[1] - temp[0]) + 1\r\nsum = sum%k\r\nif sum !=0 :\r\n sum = k - sum\r\nprint(sum)", "n, k = input()....
{"inputs": ["2 3\n1 2\n3 4", "3 7\n1 2\n3 3\n4 7", "3 7\n1 10\n11 47\n74 128", "5 4\n1 1\n2 2\n3 3\n4 4\n5 5", "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 6", "10 2\n92 92\n55 59\n70 73\n78 81\n62 65\n95 99\n74 75\n85 87\n51 51\n60 60", "10 474\n56 60\n82 82\n73 73\n105 109\n77 80\n51 51\n85 88\n97 100\n91 92\n64 68", "4...
UNKNOWN
PYTHON3
CODEFORCES
179
ef5a143b363c4530ff1b59426aee6913
inc ARG
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored...
[ "n = int(input())\r\ncells = input()\r\nif cells.find('0') == -1:\r\n print(n)\r\nelse:\r\n before = int(cells[::-1], 2)\r\n after = before + 1\r\n print(str(bin(before ^ after)).count('1'))\r\n", "n = int(input())\r\ns = (input())\r\n\r\nnum = (s[::-1])\r\nans = 0\r\nrem = 1\r\nwhile num:\r\n x = ...
{"inputs": ["4\n1100", "4\n1111", "1\n0", "1\n1", "2\n00", "2\n01", "2\n10", "2\n11", "10\n0000000000", "20\n11111111110110001100", "50\n01011110100010000001010000100001001101001101101011", "60\n111111111101111111111111111111111111111111111111111111111111", "60\n111111111111111111111111111111111111111111111111111111111...
UNKNOWN
PYTHON3
CODEFORCES
244
ef76c1c7f1e048329cf3055336d0d01f
E-reader Display
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return u * n + v\r\n\r\nn = int(input())\r\ns = []\r\nfor _ in range(n):\r\n s0 = list(input().rstrip())\r\n for i in s0:\r\n s.append(i)\r\nans = 0\r\nx1, y1 = [0] * n, [0] * n\r\nfor i in ra...
{"inputs": ["5\n01110\n10010\n10001\n10011\n11110", "4\n0000\n0111\n0001\n0001", "6\n100000\n010000\n001000\n000100\n000000\n000001", "10\n0000000000\n0000110000\n1001000000\n1000011110\n1011111101\n1011110011\n1011000111\n1011000001\n1111000010\n0000111110", "1\n0", "1\n1", "2\n00\n00", "2\n10\n00", "2\n11\n00", "2\n1...
UNKNOWN
PYTHON3
CODEFORCES
2
ef87b2649896428f789cfd90fdffac08
New Year and Rainbow Roads
Roy and Biv have a set of *n* points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it...
[ "#Problem Set F: Collaborated with no one\n\nn = int(input())\n\nresult = 0\ntemp = 0\n\nb_red = 0\nb_blue = 0\n\nfinal_red = -1\nfinal_blue = -1\nfinal_green = -(1<<60)\n\n\nfor i in range(n):\n cost_colorList = input().split()\n cost = int(cost_colorList[0])\n color = cost_colorList[1]\n \n\n if col...
{"inputs": ["4\n1 G\n5 R\n10 B\n15 G", "4\n1 G\n2 R\n3 B\n10 G", "4\n1 G\n123123 R\n987987987 B\n1000000000 G", "1\n3 R"], "outputs": ["23", "12", "1012135134", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
10
ef910e6c990a4190029b939a4dbe2fc4
Vasiliy's Multiset
Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given *q* queries and a multiset *A*, initially containing only integer 0. There are three types of queries: 1. "+ x" — add integer *x* to multiset *A*.1. "- x" — erase one occurrence of integer *x* from multiset *A...
[ "import dataclasses\r\n\r\nclass node:\r\n count : int = 0\r\n l : \"node\" = None\r\n r : \"node\" = None\r\n\r\nclass bit_bor:\r\n def __init__(self, k):\r\n self.k = k\r\n self.l = None\r\n self.r = None\r\n def add(self, x):\r\n bitmask = 1 << self.k\r\n current...
{"inputs": ["10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11", "12\n+ 4\n+ 4\n+ 5\n? 3\n- 4\n? 3\n- 4\n? 3\n? 3\n- 5\n+ 10\n? 1", "10\n? 1\n+ 1\n+ 8\n- 1\n+ 2\n+ 7\n+ 4\n+ 7\n+ 3\n? 7", "7\n? 1\n+ 941492387\n+ 72235422\n+ 449924898\n+ 783332532\n- 941492387\n- 72235422", "3\n? 5\n? 4\n? 3", "1\n? 4", "14\n+ 4\n+...
UNKNOWN
PYTHON3
CODEFORCES
3
efdafdcc47849895660ecbe9f9495933
Another Problem on Strings
A string is binary, if it consists only of characters "0" and "1". String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if th...
[ "number_of_ones = int(input())\r\nstring = input()\r\nlist_of_index = []\r\nfor i in range(len(string)):\r\n if string[i] == '1':\r\n list_of_index.append(i)\r\nlist_of_index.append(len(string))\r\ncount = 0\r\nlast_value = 0\r\nadd = 1\r\nif number_of_ones != 0:\r\n for i in range(len(list_of_index) -...
{"inputs": ["1\n1010", "2\n01010", "100\n01010", "0\n01010", "0\n0010100011", "0\n10000", "988205\n000110001001000", "10\n1011110011111001100", "0\n000", "16\n1111011111110110111111111", "0\n0", "0\n1", "1\n0", "1\n1", "2\n0", "2\n1", "1000000\n0", "1000000\n1", "0\n00", "0\n01", "0\n10", "0\n11", "1\n00", "1\n01", "1\...
UNKNOWN
PYTHON3
CODEFORCES
54
eff454f64b8b6423e14d9b17630633b9
Combination
Ilya plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number *a**i*, and the botto...
[ "N = int(input())\r\nlist = []\r\nrec = 1\r\npoints = 0\r\nfor i in range(N):\r\n a,b = map(int, input().split())\r\n c = [a,b]\r\n list.append(c)\r\nlist.sort(key = lambda x: x[1], reverse = True)\r\nwhile rec > 0 and len(list) > 0:\r\n if list[0][1] >= 1:\r\n points+=list[0][0]\r\n rec+=...
{"inputs": ["2\n1 0\n2 0", "3\n1 0\n2 0\n0 2", "5\n0 0\n2 0\n2 0\n3 0\n5 1", "7\n9 1\n8 1\n9 0\n9 1\n5 1\n1 1\n0 1", "7\n5 0\n4 0\n3 0\n5 2\n3 0\n4 2\n0 0", "1\n7 0", "1\n10 1", "10\n18 0\n4 0\n10 0\n5 0\n1 0\n18 0\n19 0\n11 1\n11 1\n0 1", "20\n33 0\n53 0\n91 0\n15 0\n35 0\n55 0\n23 0\n70 0\n98 0\n98 0\n56 0\n65 0\n20 ...
UNKNOWN
PYTHON3
CODEFORCES
9
f00c2eef3bf338fe1407001f71720af1
Huge Strings
You are given *n* strings *s*1,<=*s*2,<=...,<=*s**n* consisting of characters 0 and 1. *m* operations are performed, on each of them you concatenate two existing strings into a new one. On the *i*-th operation the concatenation *s**a**i**s**b**i* is saved into a new string *s**n*<=+<=*i* (the operations are numbered st...
[ "# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport collections\r\nimport bisect\r\nimport heapq\r\nimport time\r\nimport random\r\n\r\n\"\"\"\r\ncreated by shhuan at 2017/10/5 15:00\r\n\r\n\"\"\"\r\n\r\nN = int(input())\r\nS = ['']\r\nfor i in range(N):\r\n S.append(input())\r\nM = int(input())\r\n\r\n# t0 = ...
{"inputs": ["5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4", "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7", "5\n111101000111100011100110000100\n000111001\n01101000\n0000110100100010011001000000010100100111110110\n0110001\n10\n5 5\n2 2\n5 6\n1 1\n1 7\n10 6\n6 2\n11 1\n3 6\n8 2", "1\n1\n1\n1 1", "5\n1101010101010...
UNKNOWN
PYTHON3
CODEFORCES
4
f03cd8a1aca18e581bedbee64b3aa5b1
Beard Graph
Let's define a non-oriented connected graph of *n* vertices and *n*<=-<=1 edges as a beard, if all of its vertices except, perhaps, one, have the degree of 2 or 1 (that is, there exists no more than one vertex, whose degree is more than two). Let us remind you that the degree of a vertex is the number of edges that con...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef binary_trie(n):\r\n G0 = [[-1] for _ in range(n)]\r\n G1 = [[-1] for _ in range(n)]\r\n cnt = [[0] for _ in range(n)]\r\n return G0, G1, cnt\r\n\r\ndef insert(G0, G1, cnt, x, l):\r\n j = 0\r\n for i in r...
{"inputs": ["3\n1 2\n2 3\n7\n3 1 2\n3 1 3\n3 2 3\n2 2\n3 1 2\n3 1 3\n3 2 3", "6\n1 5\n6 4\n2 3\n3 5\n5 6\n6\n3 3 4\n2 5\n3 2 6\n3 1 2\n2 3\n3 3 1", "3\n2 3\n1 3\n4\n3 3 1\n3 2 2\n3 1 3\n2 2", "5\n3 4\n1 2\n2 4\n5 3\n10\n3 4 1\n3 5 5\n3 3 3\n2 3\n3 1 1\n3 4 4\n3 3 1\n3 2 3\n3 4 3\n2 1", "10\n8 9\n4 1\n3 4\n2 6\n7 6\n1 5...
UNKNOWN
PYTHON3
CODEFORCES
1
f03f163d9dcf59356562a10964351ea7
Colorful Points
You are given a set of points on a straight line. Each point has a color assigned to it. For point *a*, its neighbors are the points which don't have any other points between them and *a*. Each point has at most two neighbors - one from the left and one from the right. You perform a sequence of operations on this set ...
[ "# https://codeforces.com/problemset/problem/909/D\r\ndef process(a):\r\n assert len(a) >= 2\r\n \r\n n = len(a)\r\n min_ = float('inf')\r\n\r\n for i, [cnt, c] in enumerate(a):\r\n if i == 0 or i == n-1:\r\n min_ = min(min_, cnt)\r\n else:\r\n min_ = min(min_, ...
{"inputs": ["aabb", "aabcaa", "abbcccbba", "aaaaaaaaaaa", "aaaaaaaaabbbbbaaaabaaaaaaaaaaaaaaaaabaaaaaabbbbbbbaaabbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaa", "abc", "a", "ab", "ba", "aaabbb", "abababababab", "aaabbbbbbaaa", "bbbbbbbbbbbbbbbbbbbbbbddddddddddddddddaaaaaaaaaaaaaccccccccbbbbbbbaaaaaaaaaabbbbbbbbaaaaaaa...
UNKNOWN
PYTHON3
CODEFORCES
3
f03f9da834f54eb8e8b876b0b59ffb7f
Sand Fortress
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right. Obviously, there is not enough sand o...
[ "n, H = map(int, input().split())\r\n\r\ndef is_ok(maxh):\r\n k = min(H, maxh)\r\n cnt = maxh*maxh-k*(k-1)//2\r\n return cnt <= n\r\n\r\ndef get(maxh):\r\n global n\r\n k = min(H, maxh)\r\n cnt = maxh*maxh-k*(k-1)//2\r\n x = (2*maxh-1)-(k-1)\r\n n = n-cnt\r\n return x+(n+maxh-1)//maxh\r\n...
{"inputs": ["5 2", "6 8", "20 4", "1000000000000000000 1000000000000000000", "1 1", "1 1000000000000000000", "1000000000000000000 1", "1036191544337895 45523434", "1036191544337896 45523434", "1036191544337895 45523433", "1036191544337895 1", "1036191544337895 1000000000000000000", "30 3", "30 4", "6 100", "7 100", "10...
UNKNOWN
PYTHON3
CODEFORCES
51
f072fa63e87a25ed800de65e1ffc8d7c
Letters
There are $n$ dormitories in Berland State University, they are numbered with integers from $1$ to $n$. Each dormitory consists of rooms, there are $a_i$ rooms in $i$-th dormitory. The rooms in $i$-th dormitory are numbered from $1$ to $a_i$. A postman delivers letters. Sometimes there is no specific dormitory and roo...
[ "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n a[i]+=a[i-1]\r\ndef rbinsearch(a, n,x):\r\n l = -1\r\n r = n - 1\r\n while r - l > 1:\r\n d = (l + r) // 2\r\n if x <= a[d]:\r\n r = d\r\n els...
{"inputs": ["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999", "1 1\n1\n1", "5 15\n10 20 30 20 10\n1 6 10 11 15 30 31 54 60 61 76 80 81 84 90", "1 10\n10\n1 2 3 4 5 6 7 8 9 10", "5 8\n10 1 1 1 10\n9 10 11 12 13 14 15 23", "1 3\n10000\n1 4325 10000", "4 18\n5 6 3 4\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
UNKNOWN
PYTHON3
CODEFORCES
156
f076dc74abe1afb96365abfa76bcf681
Partitions
You are given a set of *n* elements indexed from 1 to *n*. The weight of *i*-th element is *w**i*. The weight of some subset of a given set is denoted as . The weight of some partition *R* of a given set into *k* subsets is (recall that a partition of a given set is a set of its subsets such that every element of the ...
[ "def read_data():\r\n n, m = map(int, list(input().strip().split()))\r\n a = list(map(int, list(input().strip().split())))\r\n return n, m, a\r\n \r\ndef get_modinv(m):\r\n modinv = [-1 for _ in range(m+1)]\r\n modinv[1] = 1\r\n for i in range(2,m+1):\r\n modinv[i] = (-(div//i) * modinv[div...
{"inputs": ["4 2\n2 3 2 3", "5 2\n1 2 3 4 5", "1 1\n1", "1 1\n1000000000", "2 1\n6042 8885", "2 2\n8224 8138", "3 1\n2403 4573 3678", "3 2\n1880 3827 5158", "3 3\n4062 8888 5423", "4 1\n1867 5670 374 4815", "4 2\n4049 2220 6447 3695", "4 3\n3526 1473 9416 2974", "4 4\n9900 6535 5489 1853", "5 1\n6740 1359 1663 8074 568...
UNKNOWN
PYTHON3
CODEFORCES
1
f09b50026b0c62af013f97d2d56c23a9
Little Girl and Game
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the p...
[ "import sys \r\ninput = sys.stdin.readline \r\nfrom collections import Counter , defaultdict\r\ndef instr():\r\n return input()[:-1]\r\nimport math \r\n############################\r\nw = instr()\r\nc = Counter(w)\r\nf = sum(x%2 != 0 for x in c.values())\r\nif f == 0 :\r\n print(\"First\")\r\nelse :\r\n pr...
{"inputs": ["aba", "abca", "aabb", "ctjxzuimsxnarlciuynqeoqmmbqtagszuo", "gevqgtaorjixsxnbcoybr", "xvhtcbtouuddhylxhplgjxwlo", "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbom...
UNKNOWN
PYTHON3
CODEFORCES
155
f0ad95136bd7be42237709c4ab074470
Bear and Displayed Friends
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*. Spring is starting and the Wint...
[ "n, k, q = map(int, input().split())\r\nni = [int(x) for x in input().split()]\r\nqi = []\r\nd = []\r\na = []\r\n\r\nfor i in range(q):\r\n qi.append([int(x) for x in input().split()])\r\n\r\nfor i in qi:\r\n if i[0] == 1:\r\n if len(d) == k:\r\n if min(d) > ni[i[1]-1]:\r\n co...
{"inputs": ["4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3", "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3", "6 3 10\n62417580 78150524 410053501 582708235 630200761 760672946\n2 2\n1 5\n1 2\n1 4\n2 4\n2 1\n2 1\n1 6\n2 5\n2 6", "20 2 15\n12698951 55128070 116962690 156763505 18...
UNKNOWN
PYTHON3
CODEFORCES
74
f0c98e53e5f00dc6fccb04a61d09a569
Ray Tracing
There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,<=0) and (*n*,<=*m*). Walls of the room are paralle...
[ "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import defaultdict\r\n\r\n\r\ndef inside(n, m, x, y):\r\n return 0 <= x <= n and 0 <= y <= m\r\n\r\ndef corner(n, m, x, y):\r\n return x in [0, n] and y in [0, m]\r\n\r\ndef next(n, m, x, y, t, a, b):\r\n for cx in [0, n]:\r\n cy = a * cx...
{"inputs": ["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3", "10 10 10\n3 8\n1 7\n2 3\n4 2\n4 8\n3 3\n2 8\n5 5\n6 3\n3 1"], "outputs": ["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1", "-1\n-1\n-1\n-1\n-1\n3\n-1\n5\n-1\n-1"]}
UNKNOWN
PYTHON3
CODEFORCES
7
f0cd2e3f5e07139f08498f5621356785
Barnicle
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance ...
[ "import re\r\ns = input()\r\n\r\nd = re.findall(\".\\d+e\", s)[0][1:-1] + \"0\" * 100\r\na = re.findall(\"\\d+.\", s)[0][:-1]\r\nb = int(re.findall(\"e\\d+\", s)[0][1:])\r\nr = a + d[:b] + \".\" + d[b:]\r\nr = r.replace(\"0\", ' ').strip().replace(' ', '0')\r\nif r[0] == '.':\r\n r = \"0\" + r\r\nif r[-1] == '.'...
{"inputs": ["8.549e2", "8.549e3", "0.33e0", "1.31e1", "1.038e0", "8.25983e5", "8.77056e6", "4.28522890224373996236468418851564462623381500262405e30", "4.09336275522154223604344399571355118601483591618747e85", "2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85", "0...
UNKNOWN
PYTHON3
CODEFORCES
67
f0e43d5e6116cabcd5a5afab0d7d9360
Div. 64
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi...
[ "a=int(input())\r\ns=str(a)\r\ncount=0\r\nfor i in s:\r\n if i==\"0\":\r\n count+=1\r\nif (count>=6):\r\n print(\"yes\")\r\nelse:\r\n print(\"no\")\r\n", "\r\na = input()\r\nsz = len(a)\r\n\r\nflg = 0\r\ncnt = 0\r\nfor i in range (0,sz):\r\n k = a[i]\r\n if(int(k)==1) :\r\n fl...
{"inputs": ["100010001", "100", "0000001000000", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111", "01111111011111111111111111111111111111111111111111111111111111...
UNKNOWN
PYTHON3
CODEFORCES
266
f0ea84336296576d23e955b31c95fd20
Magic Numbers
Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-mag...
[ "from sys import stdin\r\ndef main():\r\n mod = 10**9 + 7\r\n\r\n _all = map(str, stdin.read().split())\r\n m, d, a, b = int(next(_all)), int(next(_all)), next(_all), next(_all)\r\n n = len(a)\r\n n_2, re, list_not_d, dp = n & 1, [0]*n, [i for i in range(10) if i ^ d], [[0]*m for i in range(n)]\r\n ...
{"inputs": ["2 6\n10\n99", "2 0\n1\n9", "19 7\n1000\n9999", "9 4\n33\n52", "10 8\n18\n59", "43 3\n587\n850", "65 3\n3436\n3632", "850 8\n55735\n94089", "590 6\n428671\n715453", "1053 8\n1539368\n3362621", "477 9\n3062053\n6465858", "1901 9\n1941695\n3314270", "29 0\n1649127\n6241670", "566 3\n63724516599577003628541628...
UNKNOWN
PYTHON3
CODEFORCES
4
f0f8b71ffb52b06d4de452eb67b0aa25
Counting Kangaroos is Fun
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who i...
[ "import sys, math\nn=int(input())\na=sorted(int(x) for x in sys.stdin)\ni=(n//2)-1\nj=n-1\nk=0\nwhile j>((n//2)-1) and i>=0:\n if 2*a[i]<=a[j]:\n j-=1\n k+=1\n i-=1\n#print(a)\nprint(n-k)\n \t\t \t \t \t \t\t\t \t\t \t \t\t\t\t \t\t", "n = int(input())\nsizes = sorted([int(input()) for i ...
{"inputs": ["8\n2\n5\n7\n6\n9\n8\n4\n2", "8\n9\n1\n6\n2\n6\n5\n8\n3", "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52", "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9", "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267...
UNKNOWN
PYTHON3
CODEFORCES
61
f12339773992c002ec45b994955d599d
PolandBall and Gifts
It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are *n* Balls overall. Each Ball has someone for whom he should bring a present according to some permutation *p*, *p**i*<=≠<=*i* for all *i*. Unfortunately, Balls are quite clumsy. We know earlier that exactly *k* of them will forg...
[ "import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nimport time\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpo...
{"inputs": ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1", "5 4\n3 1 4 5 2", "3 0\n2 3 1", "4 3\n2 3 4 1", "2 0\n2 1", "2 1\n2 1", "2 2\n2 1", "3 0\n2 3 1", "3 1\n2 3 1", "3 2\n2 3 1", "3 3\n2 3 1", "5 1\n2 3 4 5 1", "6 3\n2 3 1 5 6 4", "9 5\n3 4 5 2 7 8 1 9 6", "6 2\n4 5 6 2 1 3", "2 2\n2 1", "9 2\n8 6 7 5 2 3 1 9 4"...
UNKNOWN
PYTHON3
CODEFORCES
1
f1358e5820183e8ec8f2e3b61ee5ef36
The number on the board
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbe...
[ "k = int(input())\r\nn = input()\r\na = dict()\r\nans = 0\r\nfor i in range(10):\r\n a[i] = 0\r\nfor i in n:\r\n a[int(i)] += 1\r\n ans += int(i)\r\nx = 0\r\nfor i in range(10):\r\n while a[i] > 0 and ans < k:\r\n x += 1\r\n a[i] -= 1\r\n ans += 9 - i\r\nprint(x)\r\n", "k=int(inpu...
{"inputs": ["3\n11", "3\n99", "10\n5205602270", "70\n3326631213", "200\n1000000010000000000000000000010000000000000001000001000000000000000000000000000000000000000000000000", "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035", "700\n930721675640459016214334490155...
UNKNOWN
PYTHON3
CODEFORCES
86
f15218a1d52d8afdb6e5afd7f1b1934b
Spy Syndrome 2
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique. For a given sentence, the ciphe...
[ "# [https://codeforces.com/contest/633/submission/33363209]\r\n\r\nn = int(input())\r\nt = input()[::-1]\r\nm = int(input())\r\nd = {q.lower(): q for q in [input() for i in range(m)]}\r\nk = 0\r\ns = []\r\nl = sorted(set(map(len, d)))\r\nwhile n:\r\n k -= 1\r\n if len(l) + k < 0: k, n = s.pop()\r\n elif n ...
{"inputs": ["30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote", "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello", "71\nbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n8\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
UNKNOWN
PYTHON3
CODEFORCES
2
f16748607c785c0b98dd1acfb1db8b04
Two Seals
One very important person has a piece of paper in the form of a rectangle *a*<=×<=*b*. Also, he has *n* seals. Each seal leaves an impression on the paper in the form of a rectangle of the size *x**i*<=×<=*y**i*. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nN,a,b = map(int, input().split())\r\n\r\ndef deal(x1,y1,x2,y2):\r\n ans = []\r\n x = x1+x2\r\n y = max(y1,y2)\r\n ans.append((x,y))\r\n \r\n x = max(x1,x2)\r\n y = y1+y2\r\n ans.append((x,y))\r\n \r\n return ans\r\n\r\...
{"inputs": ["2 2 2\n1 2\n2 1", "4 10 9\n2 3\n1 1\n5 10\n9 11", "3 10 10\n6 6\n7 7\n20 5", "2 1 1\n1 1\n1 1", "2 1 2\n1 1\n1 1", "2 100 100\n100 100\n1 1", "2 100 100\n50 100\n100 50", "2 100 100\n100 100\n87 72", "5 100 100\n100 100\n100 100\n100 100\n100 100\n100 100", "15 50 50\n9 36\n28 14\n77 74\n35 2\n20 32\n83 85...
UNKNOWN
PYTHON3
CODEFORCES
34
f1713e8c1a645361ed6d91822ead2758
Depression
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels! There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful ...
[ "h,m = list(map(int,input().split(':')))\r\nprint((h*30+m/2)%360,m*6)\r\n", "s=input()\r\n\r\nh=int(s[:2])\r\nm=int(s[3:])\r\nif h>=12:\r\n h=h%12\r\nm1=6*m\r\nh1=30*h+(1/12)*m1\r\nprint(h1,m1)\r\n", "time = input()\r\n\r\nhh = int(time[:2])\r\nmm = int(time[3:])\r\n\r\nif hh >= 12:\r\n\tr = int(hh)-12\r\nel...
{"inputs": ["12:00", "04:30", "08:17", "07:20", "09:55", "11:59", "01:23", "11:00", "00:00", "12:30", "23:59", "20:00", "23:45", "07:14", "15:15", "16:05", "19:55", "23:58", "14:33", "18:00", "00:24", "19:45", "20:05", "21:13", "08:04", "07:40", "19:12", "06:36", "06:16", "11:49", "18:45", "06:44", "20:45", "17:48", "0...
UNKNOWN
PYTHON3
CODEFORCES
36
f19ce5e43cad559a41626683b26478cf
Indian Summer
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked....
[ "n = int(input())\r\nmySet = set(())\r\nfor i in range(n):\r\n s = input()\r\n mySet.add(s)\r\n\r\nprint(len(mySet))", "n=int(input())\r\nset=set()\r\nfor i in range(0,n):\r\n set.add(input())\r\nprint(len(set))", "t=int(input())\nd={}\nfor i in range(t):\n s=input().strip()\n d.setdefault(s,0)\n...
{"inputs": ["5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "3\noak yellow\noak yellow\noak yellow", "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae", "1\nqvwli hz", "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab", "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syde...
UNKNOWN
PYTHON3
CODEFORCES
623
f1a35742b0a9a1e287eebb34373efa86
Longest k-Good Segment
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output...
[ "n,k = [int(i) for i in input().split()]\r\nd = [int(i) for i in input().split()]\r\nl,r=0,0\r\ns= dict()\r\nans = 0\r\nll,rr=0,0\r\nwhile r<n:\r\n while len(s)>=k:\r\n s[d[l]]-=1\r\n if s[d[l]]==0:\r\n s.pop(d[l])\r\n l+=1\r\n while r<n:\r\n if d[r] not in s:\r\n ...
{"inputs": ["5 5\n1 2 3 4 5", "9 3\n6 5 1 2 3 2 1 4 5", "3 1\n1 2 3", "1 1\n747391", "5 2\n171230 171230 171230 171230 171230", "10 3\n512008 512008 452221 512008 314256 123232 314256 512008 314256 123232", "6 1\n1 1 2 1 1 1", "5 4\n1 2 3 4 0", "5 4\n2 3 4 5 0", "2 2\n0 1", "2 2\n0 0", "5 4\n1 2 3 45 0"], "outputs": ["...
UNKNOWN
PYTHON3
CODEFORCES
54
f1cdb30715841ea0612c3bcf79aecec7
Wilbur and Swimming Pool
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned...
[ "import math\r\n\r\ndef rl():\r\n return map(int,input().split())\r\n\r\ndef ri():\r\n return int(input())\r\n\r\nn=ri()\r\n\r\nx=[]\r\ny=[]\r\n\r\nwhile n:\r\n a,b=rl()\r\n x.append(a)\r\n y.append(b)\r\n n-=1\r\n\r\ns=(max(x)-min(x))*(max(y)-min(y))\r\n\r\nif s==0:\r\n print(-1)\r\nelse:\r\n ...
{"inputs": ["2\n0 0\n1 1", "1\n1 1", "1\n-188 17", "1\n71 -740", "4\n-56 -858\n-56 -174\n778 -858\n778 -174", "2\n14 153\n566 -13", "2\n-559 894\n314 127", "1\n-227 -825", "2\n-187 583\n25 13", "2\n-337 451\n32 -395", "4\n-64 -509\n-64 960\n634 -509\n634 960", "2\n-922 -505\n712 -683", "2\n-1000 -1000\n-1000 0", "2\n-1...
UNKNOWN
PYTHON3
CODEFORCES
130
f1e893d735a5a95becb2ba80e08851fe
Matchmaker
Polycarpus has *n* markers and *m* marker caps. Each marker is described by two numbers: *x**i* is the color and *y**i* is the diameter. Correspondingly, each cap is described by two numbers: *a**j* is the color and *b**j* is the diameter. Cap (*a**j*,<=*b**j*) can close marker (*x**i*,<=*y**i*) only if their diameters...
[ "import sys\r\nimport math \r\n\r\nn, m = list(map(int, input().split()))\r\n\r\nc = []\r\nz = [0] * 1000\r\nk = [0] * 1000\r\nfor i in range(1000):\r\n c.append([0] * 1000)\r\n\r\nfor i in range(n):\r\n x, y = list(map(int, input().split()))\r\n c[x - 1][y - 1] += 1\r\n z[y - 1] += 1\r\n\r\n...
{"inputs": ["3 4\n1 2\n3 4\n2 4\n5 4\n2 4\n1 1\n1 2", "2 2\n1 2\n2 1\n3 4\n5 1", "6 7\n2 1\n2 2\n2 1\n1 1\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n1 1\n1 2", "6 7\n2 1\n1 1\n2 2\n1 2\n1 1\n1 2\n2 1\n1 1\n1 1\n1 1\n1 2\n2 2\n1 1", "6 7\n2 1\n2 2\n1 1\n1 2\n2 2\n1 2\n1 2\n1 1\n1 2\n2 2\n2 2\n2 2\n1 1", "6 7\n1 1\n1 1\n1 2\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
21
f1f9f715455d8c3f24e570cb59b1a3cb
Rats
Rats have bred to hundreds and hundreds in the basement of the store, owned by Vasily Petrovich. Vasily Petrovich may have not noticed their presence, but they got into the habit of sneaking into the warehouse and stealing food from there. Vasily Petrovich cannot put up with it anymore, he has to destroy the rats in th...
[ " \r\nfrom functools import reduce\r\n\r\n#Este BFS se utiliza identificar que celdas se alcanzan desde first y por tanto alcanzarán a first si se coloca una granada en ellas.\r\ndef bfs(first, d,mat,n,m):\r\n queue = []\r\n mv = [(0, -1), (0, 1), (-1, 0), (1, 0)]\r\n levels = {first:0}\r\n queue.append...
{"inputs": ["4 4 1\nXXXX\nXR.X\nX.RX\nXXXX", "9 14 5\nXXXXXXXXXXXXXX\nX....R...R...X\nX..R.........X\nX....RXR..R..X\nX..R...X.....X\nXR.R...X.....X\nX....XXR.....X\nX....R..R.R..X\nXXXXXXXXXXXXXX", "7 7 1\nXXXXXXX\nX.R.R.X\nX.....X\nX..X..X\nX..R..X\nX....RX\nXXXXXXX", "7 7 2\nXXXXXXX\nX.....X\nXRXR..X\nX.....X\nXR......
UNKNOWN
PYTHON3
CODEFORCES
1
f1facf569ffcf5bc4df80b22352296b4
Xor-Paths
There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints: - You can move to the right or to ...
[ "n,m,k = map(int,input().split())\r\nmat = []\r\nfor _ in range(n):\r\n arr = list(map(int,input().split()))\r\n mat.append(arr)\r\nfrom collections import defaultdict\r\nmemo = defaultdict(lambda:0)\r\ndef forw(i,j,cnt,val):\r\n val = val^mat[i][j]\r\n if cnt == half:\r\n memo[i,j,val]+=1\r\n ...
{"inputs": ["3 3 11\n2 1 5\n7 10 0\n12 6 4", "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1", "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1", "1 1 1000000000000000000\n1000000000000000000", "1 1 1000000000000000000\n999999999999999999", "1 1 1\n1", "1 2 3\n1 2", "1 10 1023\n1 2 4 8 16 32 64 128 256 512", "1 20 1048575\n1 2 4 ...
UNKNOWN
PYTHON3
CODEFORCES
9
f206f390408b8469f5ead1d5a0d4ef6f
Ilya And The Tree
Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex *i* is equal to *a**i*. Ilya believes that the beauty of the vertex *x* is the greatest co...
[ "# for I/O for local system\nimport sys\nfrom os import path\nif(path.exists('Input.txt')):\n sys.stdin = open('Input.txt','r')\n sys.stdout = open('Output.txt','w')\n \n# For fast I/O\ninput = sys.stdin.buffer.readline\n# input = sys.stdin.readline\nprint = sys.stdout.write\n \n# Import libraries here whenev...
{"inputs": ["2\n6 2\n1 2", "3\n6 2 3\n1 2\n1 3", "1\n10", "10\n2 3 4 5 6 7 8 9 10 11\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n4 8\n8 9\n9 10", "4\n6 2 3 2\n1 2\n2 3\n3 4"], "outputs": ["6 6 ", "6 6 6 ", "10 ", "2 3 2 1 1 1 1 1 1 1 ", "6 6 3 2 "]}
UNKNOWN
PYTHON3
CODEFORCES
1
f20f51e123ce54994ea16251d4a30538
Hexadecimal's theorem
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F...
[ "n = int(input())\nif n == 0:\n print(0, 0, 0)\nelif n == 1:\n print(0, 0, 1)\nelif n == 2:\n print(0, 1, 1)\nelse:\n arr = [0, 1]\n i = 1\n while True:\n m = arr[i]+arr[i-1]\n if m <= n:\n arr.append(m)\n i += 1\n else:\n break\n\n\n print(...
{"inputs": ["3", "13", "0", "1", "2", "1597", "0", "1", "1", "2", "3", "5", "8", "13", "21", "34", "55", "89", "144", "233", "377", "610", "987", "1597", "2584", "4181", "6765", "10946", "17711", "28657", "46368", "75025", "121393", "196418", "317811", "514229", "832040", "1346269", "2178309", "3524578", "5702887", "92...
UNKNOWN
PYTHON3
CODEFORCES
437
f23516b21bb43236372be770896daf03
Martian Clock
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored...
[ "a,b = input().split(':')\r\na = a.lstrip('0')\r\nb = b.lstrip('0')\r\nif len(a) == 0:\r\n a = '0'\r\nif len(b) == 0:\r\n b = '0'\r\nif len(a) == 1 and len(b) == 1:\r\n ok = True\r\n if ord(a[0])-ord('A') > 13:\r\n ok = False\r\n if ord(b[0])-ord('A') > 49:\r\n ok = False\r\n if ok:\...
{"inputs": ["11:20", "2A:13", "000B:00001", "00000:00000", "70:00", "00:21", "02:130", "123:A", "N8HYJ:042JW", "N:7", "00000:00021", "00002:00130", "00394:00321", "0000P:0000E", "0000F:0002G", "0000N:00007", "000G6:000GD", "000B3:00098", "100:0101", "00101:0101", "00001:00001", "00A:00A", "10101:000", "0010:00000", "00...
UNKNOWN
PYTHON3
CODEFORCES
4
f2643261d115329182a78ea3b0e7a79f
none
Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок,...
[ "n=int(input())\r\nk=0\r\ns=0\r\nb=input().split()\r\nfor i in range(n):\r\n\tif b[i]=='4' or b[i] == '5':\r\n\t\tk+=1\r\n\telse:\r\n\t\ts+=k//3\r\n\t\tk=0\r\ns+=k//3\r\nprint(s)\r\n", "n = int(input())\r\ns = input().split()\r\na = [0]*n\r\nx = 0\r\nz = 0\r\nfor i in range(n):\r\n a[i] = s[i]\r\nfor i in rang...
{"inputs": ["6\n4 5 4 5 4 4", "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5", "3\n4 5 4", "3\n4 5 1", "4\n5 4 3 5", "10\n4 4 5 4 4 5 5 5 4 4", "20\n5 5 5 4 5 4 5 5 5 5 5 4 4 5 3 4 4 4 5 4", "30\n4 4 5 5 5 4 5 5 4 5 4 4 5 4 4 4 5 4 4 4 5 5 5 5 4 5 5 5 4 4", "40\n5 4 4 5 5 5 1 5 4 4 4 4 4 2 4 4 4 4 4 4 5 4 4 4 5 5 3 4 4 5 5 5 4 4 4 4...
UNKNOWN
PYTHON3
CODEFORCES
22
f26fc951cce2e4c8216142310433c9ea
Coder
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). ...
[ "k=0\r\nc=0\r\ns=''\r\nss=''\r\nn=int(input())\r\nfor i in range(n):\r\n if k%2==0:\r\n s+='C'\r\n ss+='.'\r\n else:\r\n s+='.'\r\n ss+='C'\r\n k+=1\r\nk=0\r\nfor i in range(n):\r\n if k%2==0:\r\n c+=s.count('C')\r\n else:\r\n c+=ss.count('C')\r\n k+=1\r\n...
{"inputs": ["2", "3", "4", "10", "15", "100", "101", "500", "501", "755", "888", "998", "999", "1000", "1"], "outputs": ["2\nC.\n.C", "5\nC.C\n.C.\nC.C", "8\nC.C.\n.C.C\nC.C.\n.C.C", "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C", "113\nC.C.C...
UNKNOWN
PYTHON3
CODEFORCES
297
f28494b1bb4a51fe0632070103000036
Restoring Numbers
Vasya had two arrays consisting of non-negative integers: *a* of size *n* and *b* of size *m*. Vasya chose a positive integer *k* and created an *n*<=×<=*m* matrix *v* using the following formula: Vasya wrote down matrix *v* on a piece of paper and put it in the table. A year later Vasya was cleaning his table when h...
[ "def main():\r\n n, m = map(int, input().split())\r\n l = list(tuple(map(int, input().split())) for _ in range(n))\r\n ma = max(x for _ in l for x in _)\r\n bb = l[0]\r\n x = bb[0]\r\n aa = [_[0] - x for _ in l]\r\n err = set(map(abs, filter(None, (a + b - x for a, row in zip(aa, l) for b, x in...
{"inputs": ["2 3\n1 2 3\n2 3 4", "2 2\n1 2\n2 0", "2 2\n1 2\n2 1", "2 2\n2 3\n1 2", "2 2\n2 0\n1 2", "2 2\n2 1\n0 2", "2 2\n0 2\n2 1", "2 3\n1 3 3\n3 0 1", "3 2\n1 3\n3 0\n3 1", "2 3\n3 0 1\n1 3 3", "3 2\n3 0\n3 1\n1 3", "3 2\n3 1\n3 0\n1 3", "3 2\n3 0\n1 3\n3 1", "2 2\n0 1000000000\n1000000000 0", "2 2\n0 1000000000\n...
UNKNOWN
PYTHON3
CODEFORCES
2
f2b5de567aac6e94f6ed4a324fabb0a8
Cup Trick
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble. The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of *n* plastic cups. Then the magician places a small marb...
[ "import io\nimport os\n\n# List with O(n^1/3) (for n=10**6) get/set/insert/delete based on: https://github.com/cheran-senthil/PyRival/blob/master/pyrival/data_structures/SortedList.py\n\n\nclass UnsortedList:\n def __init__(self, iterable=[], _load=200):\n \"\"\"Initialize sorted list instance.\"\"\"\n ...
{"inputs": ["2 1\n2 1", "3 2\n1 2\n1 1", "3 3\n1 3\n2 3\n1 3", "3 2\n1 1\n3 2", "5 2\n3 3\n3 1", "5 3\n3 1\n4 3\n5 4", "7 3\n4 4\n5 4\n2 4", "10 3\n7 10\n8 7\n5 5", "100 50\n11 28\n11 1\n98 58\n38 27\n24 27\n67 37\n90 48\n91 14\n43 29\n3 64\n24 6\n53 19\n97 65\n13 27\n75 53\n37 82\n69 75\n94 99\n1 26\n95 60\n45 27\n100...
UNKNOWN
PYTHON3
CODEFORCES
1
f2bde5c509c9733a406a6e0eff989a26
Mr. Kitayuta's Colorful Graph
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he giv...
[ "from sys import stdin\r\ninput=stdin.readline\r\nR=lambda:map(int,input().split())\r\nI=lambda:int(input())\r\ndef dfs(x,y,z):\r\n\tif x==y:return True\r\n\tg[x]=1\r\n\tfor p in cl[x]:\r\n\t\tif p[1]==z and g[p[0]]==0 and dfs(p[0],y,z):return True\r\n\treturn False\r\nn,m=R()\r\ncl=[[] for i in range(n)]\r\nfor i ...
{"inputs": ["4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "2 1\n1 2 1\n1\n1 2", "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2", "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2"], "outputs": ["2\n1\n0", "1\n1\n1\n1\n2", "1", "3", "5"]}
UNKNOWN
PYTHON3
CODEFORCES
125
f2d46ff61caf83aa5c9d524ad3d861b9
Terse princess
«Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous on...
[ "n,a,b=list(map(int,input().split()))\r\nif n==1:\r\n print(n)\r\nelif b==0 and a==n-1:\r\n print(-1)\r\nelse:\r\n ans,p,sm=[1],0,1\r\n if b==0:\r\n sm=0 \r\n ans.append(1)\r\n p=1 \r\n for i in range(p,n-1):\r\n if b>0:\r\n ans.append(sm+1)\r\n sm+=a...
{"inputs": ["10 2 3", "5 0 0", "5 2 2", "6 2 2", "10 9 0", "1 0 0", "10 0 9", "42 10 13", "7 3 3", "12 0 0", "19 1 0", "17 2 3", "7 3 1", "19 3 1", "10 4 4", "11 5 4", "8 0 2", "19 5 1", "100 9 0", "2 0 1", "2 1 0", "3 0 2", "3 1 1", "3 2 0", "4 0 0", "4 0 1", "4 0 2", "4 0 3", "4 1 0", "4 2 0", "4 3 0", "4 1 1", "4 1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
f2de2e39564f4a23db850d2627d473bd
Friends and Subsequences
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an integer sequences *a* and *b* of length *n*. Being given a query of the form of pair of integers...
[ "\r\n\r\ndx=[[0]*(1<<20) for _ in range(20)]\r\ndy=[[0]*(1<<20) for _ in range(20)]\r\nlg=[0]*(1<<20)\r\n\r\ndef mx(l,r):\r\n p=lg[r-l+1]\r\n return max(dx[p][l],dx[p][r-(1<<p)+1])\r\n\r\ndef mn(l,r):\r\n p=lg[r-l+1]\r\n return min(dy[p][l],dy[p][r-(1<<p)+1])\r\n\r\n\r\nif __name__ == '__main__':\r\n ...
{"inputs": ["6\n1 2 3 2 1 4\n6 7 1 2 3 2", "3\n3 3 3\n1 1 1", "17\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388097 -959271262\n-417715348 -959271262 -959271262 714413739 -189641729 571055593 5710555...
UNKNOWN
PYTHON3
CODEFORCES
2
f2f920d63727a5da8738e73b9c49da84
Psychos in a Line
There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. You're given the initial arran...
[ "n = int(input())\r\nA = list(map(int,input().strip().split()))[::-1]\r\np = 0\r\np_max = 0\r\nX = []\r\nfor i in A:\r\n # print(X)\r\n while(len(X)>0 and X[-1][0]<i):\r\n p = max((p+1,X[-1][1]))\r\n X.pop()\r\n X.append((i,p))\r\n if p>p_max:\r\n p_max = p\r\n p=0\r\nprint(p_max...
{"inputs": ["10\n10 9 7 8 6 5 3 4 2 1", "6\n1 2 3 4 5 6", "6\n6 5 4 3 2 1", "10\n10 7 4 2 5 8 9 6 3 1", "15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4", "100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 73 94 78 60 20 42 84 97 83 16 81 67 64 74 46 82 5 88 80 14 48...
UNKNOWN
PYTHON3
CODEFORCES
10
f30a23a3a1dd6e38a255a088067f20fc
Chess Placing
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to . In one step you can move...
[ "i1=int(input())\r\nar=list(map(int,input().split()))\r\nsm1=0\r\nsm2=0\r\nar.sort()\r\nfor i in range(1,i1,2):\r\n sm2+=abs(i-ar[int(i/2)])\r\nar.sort(reverse=True)\r\nfor i in range(0,i1,2):\r\n sm1+=abs(i1-i-ar[int(i/2)])\r\nprint(min(sm1,sm2))", "n = int(input())\r\n\r\nA = [int(x) for x in input().spli...
{"inputs": ["6\n1 2 6", "10\n1 2 3 4 5", "2\n2", "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100", "100\n93 54 57 61 68 66 70 96 64 82 80 75 69 77 76 94 67 86 90 73 74 58 100 83 92 89 56 99 88 59 95 72 81 51 85 71 9...
UNKNOWN
PYTHON3
CODEFORCES
94
f33131958c663e5a2ee1b0463cbe2016
Bus
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ...
[ "a, b, f, k = map(int, input().split())\r\n\r\ndef main():\r\n if(b < f):\r\n return -1;\r\n if(b < a - f):\r\n return -1;\r\n if(k == 1):\r\n if(b >= a):\r\n return 0\r\n else:\r\n return 1\r\n count = 0\r\n x = b\r\n to = True\r\n for i in ran...
{"inputs": ["6 9 2 4", "6 10 2 4", "6 5 4 3", "2 2 1 1", "10 4 6 10", "3 1 1 1", "2 1 1 1", "1000000 51923215 2302 10000", "10 11 3 2", "20 50 10 25", "10 10 5 20", "15 65 5 50", "10 19 1 5", "10 19 9 5", "23 46 12 2", "23 46 12 3", "20 20 19 1", "20 23 17 2", "100 70 50 1", "100 70 70 2", "140 480 139 40", "1000000 10...
UNKNOWN
PYTHON3
CODEFORCES
31
f353ac7a2ae46c10fac90cbe25b2a7fb
Second price auction
Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receive...
[ "class Cie:\n def __init__(self, id, start, end):\n self.id = id\n self.start = start\n self.end = end\n self.range = end - start + 1\n\n def lte(self, k):\n return min(self.range, max(0, k - self.start + 1))\n\n def gte(self, k):\n return min(self.range, max(0, 1 ...
{"inputs": ["3\n4 7\n8 10\n5 5", "3\n2 5\n3 4\n1 6", "5\n1 10000\n1 10000\n1 10000\n1 10000\n1 10000", "2\n1 2\n1 2", "2\n1 3\n1 3", "5\n1 7\n2 5\n3 9\n4 8\n5 6", "5\n17 9999\n19 9992\n1 10000\n6 9\n34 99", "5\n3778 9170\n2657 6649\n4038 9722\n3392 7255\n4890 8961", "5\n2194 6947\n2062 8247\n4481 8430\n3864 9409\n3784 ...
UNKNOWN
PYTHON3
CODEFORCES
7
f35e9fe9adbb9f6f5fa5aa441e337afe
Ants on a Circle
*n* ants are on a circle of length *m*. An ant travels one unit of distance per one unit of time. Initially, the ant number *i* is located at the position *s**i* and is facing in the direction *d**i* (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the al...
[ "import sys\nn,m,t=[int(i)for i in sys.stdin.readline().split()]\na,b,k,c=[0]*n,[0]*n,[0]*n,0\nfor i in range(n):x,y=sys.stdin.readline().split();a[i]=int(x)-1;b[i]=(a[i],i);d=1 if y==\"R\"else -1;w,u=divmod(a[i]+t*d,m);a[i],c=u,c+w\na,b=sorted(a),sorted(b)\nfor i in range(n):k[b[i][1]]=a[(i+c)%n]+1\nprint(\" \".jo...
{"inputs": ["2 4 8\n1 R\n3 L", "4 8 6\n6 R\n5 L\n1 R\n8 L", "4 8 2\n1 R\n5 L\n6 L\n8 R", "10 10 90\n2 R\n1 R\n3 L\n4 R\n7 L\n8 L\n6 R\n9 R\n5 R\n10 L", "10 20 85\n6 L\n12 R\n2 L\n20 R\n18 L\n8 R\n16 R\n14 L\n10 L\n4 R", "10 20 59\n1 R\n15 L\n7 L\n13 R\n5 R\n17 R\n3 L\n9 R\n11 L\n19 L", "2 2 0\n2 L\n1 R", "2 2 0\n2 L\n1...
UNKNOWN
PYTHON3
CODEFORCES
3
f364ca2a099e8d455d001a8fa0bf3be0
Martian Food
Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of *R*, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of *r* and is located as close to the edge of the plate as poss...
[ "for _ in range(int(input())):\r\n a, b, k = map(float, input().split())\r\n print(\"{:.9f}\".format(1 / (1 / (a - b) + k * k * (a - b) / a / b)))\r\n", "#!/usr/bin/env python3\r\n\r\ndef solve(R,r,k):\r\n # Thanks to Numberphile's \"Epic circles\" video\r\n # Use the formula for radii of circles in Pappu...
{"inputs": ["2\n4 3 1\n4 2 2", "1\n4 2 2", "1\n7 2 1", "1\n8 7 2", "1\n2 1 1", "1\n1000 999 2", "1\n1000 1 2", "1\n1000 998 1000", "1\n1000 1 1000", "1\n1000 500 123", "1\n1000 999 1", "1\n1000 1 1"], "outputs": ["0.9230769231\n0.6666666667", "0.6666666667", "1.7948717949", "0.9333333333", "0.6666666667", "0.9999959960...
UNKNOWN
PYTHON3
CODEFORCES
4
f391d73d45dd1d927cf8e993cb4dccc5
Balls and Boxes
Little Vasya had *n* boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to *n* from left to right. Once Vasya chose one of the boxes, let's assume that its number is *i*, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began pu...
[ "from math import inf\n\nn, x = map(int, input().split())\na = list(map(int, input().split()))\nx -= 1\n\nmx = inf\nmi = None\nfor i in range(x, x - n, -1):\n if a[i] < mx:\n mx = a[i]\n mi = i\n\nmi %= n\n\nfor i in range(n):\n a[i] -= mx\n\na[mi] = mx * n + (x - mi) % n\n\nfor i in range(mi + ...
{"inputs": ["4 4\n4 3 1 6", "5 2\n3 2 0 2 7", "3 3\n2 3 1", "10 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "5 4\n0 554459682 978416312 784688178 954779973", "5 2\n1 554459683 978416312 784688178 954779974", "10 8\n994538714 617271264 168716105 9159...
UNKNOWN
PYTHON3
CODEFORCES
17
f3a1a7fd9526cd12c40b83d70cf25ffd
On Sum of Fractions
Let's assume that - *v*(*n*) is the largest prime number, that does not exceed *n*;- *u*(*n*) is the smallest prime number strictly greater than *n*. Find . The first line contains integer *t* (1<=≤<=*t*<=≤<=500) — the number of testscases. Each of the following *t* lines of the input contains integer *n* (2<=≤<...
[ "T = int( input() )\r\n\r\nMAX = 33000\r\n\r\nbePrime = [0] * MAX;\r\nprimNum = []\r\n\r\nfor j in range(2, MAX):\r\n if bePrime[j] == 0: \r\n primNum.append( j )\r\n i = j\r\n while i < MAX:\r\n bePrime[i] = 1\r\n i = i + j\r\n\r\ndef isPrime( a ):\r\n for j in prim...
{"inputs": ["2\n2\n3", "1\n1000000000", "5\n3\n6\n9\n10\n5", "5\n5\n8\n18\n17\n17", "5\n7\n40\n37\n25\n4", "5\n72\n72\n30\n75\n11", "5\n79\n149\n136\n194\n124", "6\n885\n419\n821\n635\n63\n480", "1\n649580447"], "outputs": ["1/6\n7/30", "999999941999999673/1999999887999999118", "7/30\n5/14\n61/154\n9/22\n23/70", "23/70...
UNKNOWN
PYTHON3
CODEFORCES
3
f3be2edd00eefa041c20c29eb293b913
Panoramix's Prediction
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
[ "def is_prime(n):\r\n return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1))\r\n\r\n\r\nn, m = map(int, input().split())\r\nnext_prime = n + 1\r\nwhile not is_prime(next_prime):\r\n next_prime += 1\r\nprint(\"YES\" if next_prime == m else \"NO\")", "s, k = list(map(int, input().split()))\r\ncount...
{"inputs": ["3 5", "7 11", "7 9", "2 3", "2 4", "3 4", "3 5", "5 7", "7 11", "11 13", "13 17", "17 19", "19 23", "23 29", "29 31", "31 37", "37 41", "41 43", "43 47", "2 5", "2 7", "2 6", "2 11", "3 6", "3 7", "3 9", "5 6", "5 9", "5 11", "5 13", "5 15", "7 8", "7 13", "13 15", "13 17", "19 21", "13 20", "41 49", "43 4...
UNKNOWN
PYTHON3
CODEFORCES
706
f3befb56bb448c975b4759d7d190e4cb
Counting-out Rhyme
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T...
[ "import sys\r\ninput = sys.stdin.readline\r\nn, k = map(int, input().split())\r\nl = sorted(list(range(1, n+1)))\r\nc = 0\r\nt = []\r\nfor i in [int(j) for j in input().split()]:\r\n c = (c+i)%len(l)\r\n t.append(l[c])\r\n l = l[:c]+l[c+1:]\r\nprint(*t)\r\n", "n, k = [int(i) for i in input().split()]\r\n...
{"inputs": ["7 5\n10 4 11 4 1", "3 2\n2 5", "2 1\n1", "2 1\n2", "2 1\n3", "10 7\n5 10 4 3 8 10 6", "10 8\n12 6 12 15 20 8 17 12", "12 10\n76 58 82 54 97 46 17 40 36 15", "12 6\n76 61 94 15 66 26", "90 10\n1045 8705 6077 3282 1459 9809 383 6206 2674 7274", "100 30\n601771 913885 829106 91674 465657 367068 142461 873149 ...
UNKNOWN
PYTHON3
CODEFORCES
129
f3d62dd60c00cd2fd042a33e2c83f89b
Asphalting Roads
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was ma...
[ "n = int(input())\r\nr = [False]*n\r\nl = [False]*n\r\n\r\n\r\nc = ''\r\nfor i in range(n*n):\r\n k, m= [int(i) for i in input().split()]\r\n if not r[k - 1] and not l[m - 1]:\r\n r[k - 1] = True\r\n l[m - 1] = True\r\n c += str(i + 1) + ' '\r\nprint(c)", "n = int(input())\r\n\r\nh = [F...
{"inputs": ["2\n1 1\n1 2\n2 1\n2 2", "1\n1 1", "2\n1 1\n2 2\n1 2\n2 1", "2\n1 2\n2 2\n2 1\n1 1", "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 1", "3\n1 3\n3 1\n2 1\n1 1\n1 2\n2 2\n3 2\n3 3\n2 3", "4\n1 3\n2 3\n2 4\n4 4\n3 1\n1 1\n3 4\n2 1\n1 4\n4 3\n4 1\n3 2\n1 2\n4 2\n2 2\n3 3", "4\n3 3\n4 2\n2 3\n3 4\n4 4\n1 2\n3 2\...
UNKNOWN
PYTHON3
CODEFORCES
262
f3d7158f8e0792de72e5f73a3a3af603
Trip For Meal
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ...
[ "n, ro, re, oe = int(input()), int(input()), int(input()), int(input())\r\nd, a, c, b = {0: ro, 1: re, 2: oe}, [ro, re, oe], 0, [0, 1]\r\nfor i in range(n - 1):\r\n if d[b[0]] >= d[b[1]]:\r\n c += d[b[1]]\r\n b.append(3 - sum(b))\r\n b.remove(b[0])\r\n else:\r\n c += d[b[0]]\r\n ...
{"inputs": ["3\n2\n3\n1", "1\n2\n3\n5", "10\n1\n8\n3", "7\n10\n5\n6", "9\n9\n7\n5", "9\n37\n85\n76", "76\n46\n77\n11", "80\n42\n1\n37", "8\n80\n55\n1", "10\n13\n72\n17", "9\n24\n1\n63", "65\n5\n8\n7", "56\n8\n9\n3", "59\n8\n1\n2", "75\n50\n50\n5", "75\n54\n76\n66", "73\n71\n69\n66", "83\n58\n88\n16", "74\n31\n11\n79", ...
UNKNOWN
PYTHON3
CODEFORCES
234
f3dbac550b76e20c952e310e24ea589c
Spyke Chatting
The R2 company has *n* employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke. R2 has *m* Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges...
[ "n,m,k=map(int,input().split())\r\nL=[]\r\nfor i in range(n):\r\n L.append(list((map(int,input().split()))))\r\n\r\nK={}\r\nfor i in range(m):\r\n K[i+1]=[]\r\n for j in range(n):\r\n if(L[j][i]==1):\r\n K[i+1].append(j+1)\r\nAns=[0]*n\r\nAnss=[0]*m\r\nfor i in range(k):\r\n x,y=map(in...
{"inputs": ["3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2", "4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3", "2 1 1\n1\n1\n1 1", "3 3 1\n1 1 1\n1 1 1\n1 1 1\n3 1", "3 2 1\n0 1\n1 0\n1 1\n1 2", "5 5 5\n0 1 1 1 0\n1 1 0 1 1\n1 1 1 1 1\n0 1 1 1 1\n1 0 0 1 1\n4 5\n4 5\n1 3\n5 4\n1 2", "4 5 6\n1 1 1 1 1...
UNKNOWN
PYTHON3
CODEFORCES
20
f42402e6c70bf58ecf9462382be78531
Martian Luck
You know that the Martians use a number system with base *k*. Digit *b* (0<=≤<=*b*<=&lt;<=*k*) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year *b* (by Martian chronology). A digital root *d*(*x*) of number *x* is a number that consists of a single digit, resulting aft...
[ "from sys import stdin\r\ninp = stdin.readline\r\n\r\nk, b, n = map(int, inp().split())\r\ns = [int(i) for i in inp().split()]\r\na = b % (k-1)\r\n\r\nsums = {0: 1}\r\n\r\n\r\ndef zero():\r\n i, count2 = 0, 0\r\n s.append(1)\r\n while i < n:\r\n if s[i] == 0:\r\n x = 0\r\n whil...
{"inputs": ["10 5 6\n3 2 0 5 6 1", "7 6 4\n3 5 0 4", "257 0 3\n0 0 256", "2 1 1\n0", "2 0 20\n1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1", "100 29 33\n28 89 23 14 97 97 66 56 55 60 47 29 9 79 26 80 63 78 83 60 41 29 52 10 82 26 47 88 99 75 52 1 31", "3 2 100\n2 0 0 0 0 2 1 1 1 2 0 1 1 1 1 2 0 0 1 0 1 1 2 0 2 0 1 0 1 0 0 2...
UNKNOWN
PYTHON3
CODEFORCES
4
f431895a1a729fdbd0c3ad3f22be56ce
Professor GukiZ and Two Arrays
Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a *s**a* as close as possible to the sum of the elements in the array b *s**b*. So he wants to minimize the value *v*<==<=|*s**a*<=-<=*s**b*|. In one operation professor can swap some element from the arra...
[ "from bisect import bisect_left\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nm = int(input())\r\nb = list(map(int, input().split()))\r\n\r\nsum_a, sum_b = sum(a), sum(b)\r\ndelta = sum_b - sum_a\r\nans = abs(delta)\r\nans_swap = []\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if a...
{"inputs": ["5\n5 4 3 2 1\n4\n1 1 1 1", "5\n1 2 3 4 5\n1\n15", "5\n1 2 3 4 5\n4\n1 2 3 4", "1\n-42\n1\n-86", "1\n-21\n10\n-43 6 -46 79 -21 93 -36 -38 -67 1", "10\n87 -92 -67 -100 -88 80 -82 -59 81 -72\n10\n-50 30 30 77 65 92 -60 -76 -29 -15", "6\n1 2 3 4 5 11\n1\n3", "2\n-2 -17\n2\n11 -9"], "outputs": ["1\n2\n1 1\n4 2"...
UNKNOWN
PYTHON3
CODEFORCES
1
f43a0ddbf858622f14a65dfa900d98f3
Holidays
School holidays come in Berland. The holidays are going to continue for *n* days. The students of school №*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people a...
[ "n, m = map(int, input().split())\r\na = [0]*105\r\n\r\nwhile m:\r\n l, r = map(int, input().split())\r\n a[l] += 1\r\n a[r+1] -= 1\r\n m -= 1\r\n\r\nfor i in range(1, n+1):\r\n a[i] += a[i-1]\r\n\r\nflag = 1\r\nfor i in range(1, n+1):\r\n if a[i] == 0 or a[i] > 1:\r\n flag = 0\r\n p...
{"inputs": ["10 5\n1 2\n3 3\n4 6\n7 7\n8 10", "10 5\n1 2\n2 3\n4 5\n7 8\n9 10", "10 5\n1 2\n3 3\n5 7\n7 7\n7 10", "5 4\n1 1\n2 2\n3 3\n4 5", "100 50\n1 2\n3 3\n4 5\n6 8\n9 10\n11 11\n12 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 21\n22 23\n24 24\n25 26\n27 30\n31 34\n35 37\n38 38\n39 40\n41 43\n44 46\n47 53\n54 54\n55 5...
UNKNOWN
PYTHON3
CODEFORCES
32
f43a2e0a33c8f44633805b0dd90f0796
Cupboard and Balloons
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure be...
[ "r, h = map(int, input().split())\r\na = 1 + 2 * h // r\r\nif h % r >=3 ** 0.5 * r / 2:\r\n a += 1\r\nprint(a)\r\n", "r, h = map(int, input().split())\r\nres = h // r * 2\r\nif 2 * (h % r) >= (3 ** .5) * r:\r\n res += 3\r\nelif 2 * (h % r) >= r:\r\n res += 2\r\nelse:\r\n res += 1\r\nprint(res)", "fr...
{"inputs": ["1 1", "1 2", "2 1", "2 2", "2 3", "4 1", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 9", "5 10", "5 11", "674098 1358794", "3983458 7761504", "4841874 9131511", "667586 5534221", "1526002 6904227", "4835362 5823289", "5693778 7001807", "6552194 8371814", "2377906 4774524", "4365659 4738707", "98 1358794",...
UNKNOWN
PYTHON3
CODEFORCES
14
f453f02226d9971eb7bbf5becec6b38f
Find Marble
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position *s*. Then he performs som...
[ "enter = input().split()\r\nn = int(enter[0]) - 1\r\ns = int(enter[1]) - 1 \r\nt = int(enter[2]) - 1\r\nfix = s\r\narr_b = [int(i) - 1 for i in input().split()]\r\narr_a = [i for i in range(1,n+2)]\r\ntarget = arr_a[s]\r\nflag = 0\r\n#print(arr_a)\r\n#print(arr_b)\r\n\r\n\r\ni = 0\r\nwhile (arr_a[t] != target):\r\n...
{"inputs": ["4 2 1\n2 3 4 1", "4 3 3\n4 1 3 2", "4 3 4\n1 2 3 4", "3 1 3\n2 1 3", "1 1 1\n1", "10 6 7\n10 7 8 1 5 6 2 9 4 3", "10 3 6\n5 6 7 3 8 4 2 1 10 9", "10 10 4\n4 2 6 9 5 3 8 1 10 7", "100 90 57\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26...
UNKNOWN
PYTHON3
CODEFORCES
222
f456a5b7865384e367c56b0d2407ffe7
Composing Of String
Stepan has a set of *n* strings. Also, he has a favorite string *s*. Stepan wants to do the following. He will take some strings of his set and write them down one after another. It is possible that he will take some strings more than once, and will not take some of them at all. Your task is to determine the minimum...
[ "import sys\r\nimport math\r\n\r\nMAXN = 55\r\nINF = 1e9\r\nMOD = 1e9+7\r\nL_INF = 4e18\r\nEPS = 1e-10\r\n\r\nn = int(input())\r\ns = []\r\nfor i in range(n):\r\n s.append(input())\r\nt = input()\r\nl = len(t)\r\n\r\ndp = [INF] * (l + 1)\r\ndp[0] = 0\r\n\r\nfor i in range(l):\r\n for j in range(n):\r\n ...
{"inputs": ["3\na\naa\na\naaa", "4\nab\naab\naa\nbb\nbaaab", "2\naaa\nbbb\naaacbbb", "4\naab\naa\nbb\naba\nbaaab", "2\naaaaaaaa\nabbaaaaaaa\nbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbabbabbbbbbbbbbbbbbbbbbbabbabbbbababbbbbbbbabbbbb", "1\nlol\nlol"], "outputs": ["2", "3", "-1", "2", "52", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
1
f469a19052b871efa652018267416bc5
Regular Bracket Sequence
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some...
[ "x = list(input())\r\nc1 = 0\r\nc2 = 0\r\nfor i in range(len(x)):\r\n if x[-1] == \"(\" and c1 == 0:\r\n x.pop()\r\n elif x[-1] == \")\":\r\n x.pop()\r\n c1+=1\r\n else:\r\n x.pop()\r\n c1-=1\r\n c2+=2\r\n\r\nprint(c2)", "m=input()\r\n\r\ncont=0\r\ncont2=0\r\nB=[...
{"inputs": ["(()))(", "((()())", "(", ")", ")(()(", "))))))(", "()()(()(((", "()))(()((((()(())", "())))((()())())))))())", ")))((((())(()((()((((()()())((", "))()()((()()))())()(((((((())((((((((())()()((())(", "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))"], "ou...
UNKNOWN
PYTHON3
CODEFORCES
207
f46e2bd58d7931a2564157375a75ebe5
Pasha and Stick
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ...
[ "n = int(input())\r\n\r\nif n % 2 != 0 or n < 6:\r\n print(0)\r\nelse:\r\n k = n // 2\r\n if n % 4 == 0:\r\n print(k//2-1)\r\n else:\r\n print(k//2)", "import math\n\nn = int(input())\n\nq = n/4\n\nprint(int(math.ceil(q) - 1) if n % 2 == 0 else 0)\n\t\t \t \t \t \t \t\t\t \t\t \t...
{"inputs": ["6", "20", "1", "2", "3", "4", "2000000000", "1924704072", "73740586", "1925088820", "593070992", "1925473570", "629490186", "1980649112", "36661322", "1943590793", "71207034", "1757577394", "168305294", "1934896224", "297149088", "1898001634", "176409698", "1873025522", "5714762", "1829551192", "16269438",...
UNKNOWN
PYTHON3
CODEFORCES
381
f48a1384754b692e29f1b10ca139a643
none
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the mi...
[ "n = int(input())\r\narray = list(map(int, input().split()))\r\n\r\n\r\ndef gcd(a, b):\r\n if b > 0:\r\n return gcd(b, a % b)\r\n else:\r\n return a\r\n\r\n\r\nallGcd = array[0]\r\nfor elem in array:\r\n allGcd = gcd(allGcd, elem)\r\n\r\nif allGcd > 1:\r\n print(-1)\r\nelse:\r\n ones = ...
{"inputs": ["5\n2 2 3 4 6", "4\n2 4 6 8", "3\n2 6 9", "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21", "12\n10 10 14 14 14 14 14 14 14 14 21 21", "5\n10 10 14 21 21", "9\n10 10 10 10 10 14 14 21 21", "9\n10 10 10 10 10 10 10 10 21", "13\n10 10 10 15 15 15 15 15 15 15 15 21 21", "15\n10 10 10 10 10 10 10 10 10 10 10 ...
UNKNOWN
PYTHON3
CODEFORCES
91
f49929c441933b89f099ad18f063b303
Two TVs
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ng = sorted([list(map(int, input().split())) for i in range(n)])\r\n\r\na = -1\r\nb = -1\r\nfor i, j in g:\r\n if a > b:\r\n a, b = b, a\r\n if i > a:\r\n a = j\r\n elif i > b:\r\n b = j\r\n else:\r\n print(\...
{"inputs": ["3\n1 2\n2 3\n4 5", "4\n1 2\n2 3\n2 3\n1 2", "4\n0 1\n1 2\n2 3\n3 4", "3\n1 2\n2 3\n2 4", "3\n0 100\n0 100\n0 100", "1\n0 1000000000", "2\n0 1\n0 1", "3\n2 3\n4 5\n1 6", "5\n1 3\n1 4\n4 10\n5 8\n9 11", "3\n1 2\n1 2\n2 3", "4\n1 100\n10 15\n20 25\n30 35", "3\n1 8\n6 7\n8 11", "5\n1 2\n3 5\n4 7\n8 9\n5 10", "...
UNKNOWN
PYTHON3
CODEFORCES
81
f4a2baf1989ae44e47e1d466007d7165
Contest Balloons
One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there ...
[ "#!/usr/bin/env python3\nfrom sys import stdin,stdout\nfrom bisect import *\nfrom heapq import *\n\ndef ri():\n return map(int, input().split())\n\nn = int(input())\n\nabw = [list(ri()) for i in range(n)]\n\na1 = abw[0][0]\na = [abw[i][0] for i in range(1,n)]\na.sort()\nabw = abw[1:]\nabw.sort(key=lambda e: e[0]...
{"inputs": ["8\n20 1000\n32 37\n40 1000\n45 50\n16 16\n16 16\n14 1000\n2 1000", "7\n4 4\n4 4\n4 4\n4 4\n4 4\n4 4\n5 5", "7\n14000000003 1000000000000000000\n81000000000 88000000000\n5000000000 7000000000\n15000000000 39000000000\n46000000000 51000000000\n0 1000000000\n0 0", "2\n100 150\n5 100000", "9\n4 70\n32 56\n32 6...
UNKNOWN
PYTHON3
CODEFORCES
5
f4dc21b1bc1016c05753a806dc7c6a21
Office Keys
There are *n* people and *k* keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine th...
[ "import copy\r\nimport random\r\nimport heapq\r\nimport math\r\nimport sys\r\nimport bisect\r\nimport datetime\r\nfrom functools import lru_cache\r\nfrom collections import deque\r\nfrom collections import Counter\r\nfrom collections import defaultdict\r\nfrom itertools import combinations\r\nfrom itertools import ...
{"inputs": ["2 4 50\n20 100\n60 10 40 80", "1 2 10\n11\n15 7", "2 5 15\n10 4\n29 23 21 22 26", "3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163", "5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88", "20 20 1000000000\n911196469 574676950 884047241 98421870...
UNKNOWN
PYTHON3
CODEFORCES
25
f4f8a3dbed3bce393863f09f59c5e587
none
You are given a string *s*, consisting of small Latin letters. Let's denote the length of the string as |*s*|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string *s* so that for any prime number *p*<=≤<=|*s*| and for any integer *i* ...
[ "from collections import Counter\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nBUFSIZ = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"n\" in file.mod...
{"inputs": ["abc", "abcd", "xxxyxxx", "xxxjddyxduquybxdxx", "jjjjjjjjjjzjjjjjjjjjjjjjjjj", "mggnngggnjgnggggngnggpnggumggpg", "hfihihhfh", "ppppppopppionpppppppppwppppppppppppppppppppppb", "jntnnnnnnngnnnnntnnennannnnnnnnnnnnnnnnjnnnnngnnnnannnnnnnnnq", "dattqddidyddddmriftkdddddddddqvedwddfdrdiaddiokdddodyqqddddtdddvd...
UNKNOWN
PYTHON3
CODEFORCES
14
f53c2e77b713b9fecc9d1983adaae7e8
Sereja and Stairs
Sereja loves integer sequences very much. He especially likes stairs. Sequence *a*1,<=*a*2,<=...,<=*a*|*a*| (|*a*| is the length of the sequence) is stairs if there is such index *i* (1<=≤<=*i*<=≤<=|*a*|), that the following condition is met: For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3,...
[ "n = int(input())\r\na = list(map(int,input().split()))\r\nm = max(a)\r\ncnt = [0]*5010\r\n\r\nright = []\r\nleft = []\r\n\r\nfor i in range(n):\r\n cnt[a[i]]+=1\r\n\r\ns = set(a)\r\nn = len(s)\r\n\r\nfor i in s:\r\n if cnt[i]>0 and i<m:\r\n right.append(i)\r\n cnt[i]-=1\r\n\r\nfor i in s:\r\n ...
{"inputs": ["5\n1 2 3 4 5", "6\n1 1 2 2 3 3", "47\n3 4 5 3 1 4 4 3 4 6 1 5 1 3 5 3 6 5 1 4 3 2 6 5 3 1 4 6 4 6 2 1 1 1 4 3 6 1 6 6 3 5 1 4 6 4 4", "13\n8 23 26 8 15 13 35 36 28 8 4 33 6", "17\n15 29 28 23 20 12 9 30 4 13 1 25 11 20 6 23 10", "31\n189 73 300 133 414 23 150 301 252 21 274 272 316 291 339 356 201 267 257 ...
UNKNOWN
PYTHON3
CODEFORCES
13
f53de49dea0cc731a12013a4ca367818
Indivisibility
IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible ...
[ "n = int(input())\r\nprint(n-n//2-n//3-n//5-n//7+n//6+n//10+n//14+n//15+n//21+n//35-n//30-n//42-n//70-n//105+n//210)", "import math\r\nn = int(input())\r\nm = n - n//2 - n//3 - n//5 - n//7 + n//6 + n//10 + n//14 + n//15 + n //21 + n//35 - n//30 - n//42 - n//70 -n//105 + n//210\r\nprint(m)", "n=int(input())\r\nr...
{"inputs": ["12", "2519", "2521", "1", "314159265", "718281828459045235", "1000000000000000000", "987654321234567890", "3628800", "504000000000000000"], "outputs": ["2", "576", "577", "1", "71807832", "164178703647781768", "228571428571428571", "225749559139329804", "829440", "115200000000000000"]}
UNKNOWN
PYTHON3
CODEFORCES
9
f54731867043ce86f02c1fd79631d7cf
Bear and Up-Down
The life goes up and down, just like nice sequences. Sequence *t*1,<=*t*2,<=...,<=*t**n* is called nice if the following two conditions are satisfied: - *t**i*<=&lt;<=*t**i*<=+<=1 for each odd *i*<=&lt;<=*n*; - *t**i*<=&gt;<=*t**i*<=+<=1 for each even *i*<=&lt;<=*n*. For example, sequences (2,<=8), (1,<=5,<=1) and...
[ "n, m = int(input()), 150001\r\np = [m] + list(map(int, input().split())) + [m * (n & 1)]\r\nf = lambda i: p[i] >= p[i + 1] if i & 1 else p[i] <= p[i + 1]\r\nh = lambda i, j: sum(f(k) for k in {i, i - 1, j, j - 1})\r\nt = [f(i) for i in range(n + 1)]\r\ns = sum(t)\r\nif s > 4: exit(print(0))\r\ne = {i + 1 for i in ...
{"inputs": ["5\n2 8 4 7 7", "4\n200 150 100 50", "10\n3 2 1 4 1 4 1 4 1 4", "9\n1 2 3 4 5 6 7 8 9", "5\n1 1 1 4 3", "10\n7 7 8 10 5 10 1 5 2 6", "50\n11836 28308 72527 92281 139289 93797 134555 148444 40866 111317 21564 87813 65466 20541 99238 2287 74647 128071 18163 61672 39766 55589 138385 147443 138100 142683 60703 ...
UNKNOWN
PYTHON3
CODEFORCES
7
f555f0260b3c8873cba4bcd572c3085a
Bracket Sequence
A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([...
[ "t = list(input())\r\nd, p = [], set(range(len(t)))\r\nfor j, q in enumerate(t):\r\n if q in '([': d.append((q, j))\r\n elif d:\r\n x, i = d.pop()\r\n if x + q in '(][)': d = []\r\n else: p -= {i, j}\r\nfor i in p: t[i] = ' '\r\nn, s = 0, ''\r\nfor q in ''.join(t).split():\r\n k = q.co...
{"inputs": ["([])", "(((", "(][)", "(()[))()[]", "(][](](][[(][", "((])(]]))(](((()[[()[[[)([]()])[(]][)]])[]]()[()[[[[(([[)", "](]][)]()][[])[()(][)]))[)[]()()])[([((([[(([)][(])](][])([([)())))([(([][))[)()]][[])()[)](][[((]](](])]][(][[()(]][[)][])(][]))[])[)[(])[)()()[[))((()]]([([[(]))][(]())))))[[]]][][))[)])])()...
UNKNOWN
PYTHON3
CODEFORCES
8
f556bf48bdfac471314a32265c949ac9
Tanya and Toys
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles. Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection...
[ "n, m = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\nt = 0\r\nans = []\r\ni = 0\r\np = 1\r\nwhile m > 0:\r\n if i < n and a[i] == p:\r\n i += 1\r\n else:\r\n if m >= p:\r\n m -= p\r\n t += 1\r\n ans.append(p)\r\n else:\r\n ...
{"inputs": ["3 7\n1 3 4", "4 14\n4 6 12 8", "5 6\n97746 64770 31551 96547 65684", "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656", "30 38\n9560 64176 75619 53112 54160 68775 12655 13118 99502 89757 78434 42521 19210 1927 34097 5416 56110 44786 59126 44266 79240 65567 54602 25325 37171 2879 89291 89...
UNKNOWN
PYTHON3
CODEFORCES
93
f5636aa985f73a0c339b33d720a5f31e
Datatypes
Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G...
[ "n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\n\r\nfor i in range(1, len(a)):\r\n f, s = a[i-1], a[i]\r\n\r\n if f == s:\r\n continue\r\n if f != 1:\r\n f *= 2\r\n if f > s:\r\n print(\"YES\")\r\n exit()\r\n \r\nprint(\"NO\")\r\n", "n = int(i...
{"inputs": ["3\n64 16 32", "4\n4 2 1 3", "5\n1 5 3 3 2", "52\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 24 54 54 234 234 474 474 24 114 9 954 954 954 474", "56\n43 641 626 984 107 521 266 835 707 220 402 406 558 199 988 685 843 808 182 ...
UNKNOWN
PYTHON3
CODEFORCES
20
f5677e201ea80926f44a9e2ca0e950ce
Running with Obstacles
A sportsman starts from point *x**start*<==<=0 and runs to point with coordinate *x**finish*<==<=*m* (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than *s* meters (in this case for these *s* meters his path should have no obstacles), and after that he can...
[ "n,m,s,d=map(int,input().split())\r\nx=sorted(map(int,input().split()))+[m+s+1]\r\ncur=l=0\r\nans=[]\r\nwhile l<m:\r\n r=min(x[cur]-1,m)\r\n ans+=['RUN '+str(r-l)]\r\n if r==m: break\r\n if r-l<s: ans=['IMPOSSIBLE']; break\r\n t=x[cur]+1\r\n while x[cur+1]-1-t<s: cur+=1; t=x[cur]+1\r\n if t-r>d...
{"inputs": ["3 10 1 3\n3 4 7", "2 9 2 3\n6 4", "10 100 2 8\n93 35 24 87 39 46 86 37 73 33", "10 1000000000 8905990 20319560\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858", "100 1000 1 4\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 ...
UNKNOWN
PYTHON3
CODEFORCES
5
f56798c29ee8a6da3eda8faa5ae6e069
Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
[ "import sys\r\n\r\ndef read(T):\r\n\treturn [T(i) for i in sys.stdin.readline().split()]\r\n\r\nlsp,pr=[],[]\r\ndef sieve(n=int(1e7)):\r\n\tglobal lsp\r\n\tlsp=[i for i in range(n+1)]\r\n\tfor i in range(2,n+1):\r\n\t\tif lsp[i]!=i:\r\n\t\t\tcontinue\r\n\t\tfor j in range(i*i,n+1,i):\r\n\t\t\tlsp[j]=i\r\n\tfor i in...
{"inputs": ["3 2\n100 5 2\n50 10", "4 3\n2 5 10 20\n100 1 3", "2 3\n50 10\n100 5 2", "1 1\n1\n1", "3 2\n100 5 2\n10 100", "5 3\n16 24 36 54 81\n4 6 9", "10 10\n2 5 11 17 23 31 41 47 59 67\n3 7 13 19 29 37 43 53 61 71", "5 5\n2 9 8 3 5\n5 7 8 1 1", "10 11\n7 43 39 13 25 23 33 40 5 2\n42 22 39 1 23 37 12 48 46 2 2", "1 5...
UNKNOWN
PYTHON3
CODEFORCES
4
f5720d2aa74a1670c2180f6deeffec02
Beads
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on...
[ "#!/usr/bin/env python\n'''\n' Author: Cheng-Shih Wong\n' Email: [email protected]\n' Date: 2017-09-22\n'''\n\ndef main():\n\n def num(left, right, dp, rev, revI):\n if left > right:\n return 1\n\n key = left, rev, revI\n if key in dp:\n return dp[key]\n ...
{"inputs": ["4 4", "2 1", "2 2", "3 1", "3 2", "3 3", "4 1", "4 2", "4 3", "4 4", "4 5", "4 6", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "5 9", "5 10", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "6 7", "6 8", "6 9", "6 10", "6 11", "6 12", "6 13", "6 14", "6 15", "6 16", "6 17", "6 18", "6 19", "6 20", "7...
UNKNOWN
PYTHON3
CODEFORCES
4
f5785293d81f3553abdcb79b2d447963
Divide by three, multiply by two
Polycarp likes to play with numbers. He takes some integer number $x$, writes it down on the board, and then performs with it $n - 1$ operations of the two kinds: - divide the number $x$ by $3$ ($x$ must be divisible by $3$); - multiply the number $x$ by $2$. After each operation, Polycarp writes down the result o...
[ "from collections import defaultdict\nn=int(input())\na=list(map(int,input().split()))\ndef top(mp=defaultdict(int),x=1,n=1):\n if n==1 and mp[x]==1 or n==0:\n return [x]\n if mp[x]==0:\n return -1\n mp[x]-=1\n k=top(mp,2*x,n-1)\n mp[x]+=1\n if k!=-1:\n return k+[x]\n if x%...
{"inputs": ["6\n4 8 6 3 12 9", "4\n42 28 84 126", "2\n1000000000000000000 3000000000000000000", "19\n46875000000000000 732421875000000 5859375000000000 11444091796875 2929687500000000 187500000000000000 91552734375000 11718750000000000 3000000000000000000 22888183593750 1464843750000000 375000000000000000 4577636718750...
UNKNOWN
PYTHON3
CODEFORCES
14
f58134faa67baff47e60249ea62a672c
Dexterina’s Lab
Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re ...
[ "\r\nimport sys\r\n#sys.stdin=open(\"data.txt\")\r\ninput=sys.stdin.readline\r\n\r\nn,x=map(int,input().split())\r\n\r\ndef mult(a,b):\r\n # compute a*b\r\n c=[0]*128\r\n for i in range(128):\r\n for j in range(128):\r\n c[i^j]+=a[i]*b[j]\r\n return c\r\n\r\ndef quickpow(a,b):\r\n #...
{"inputs": ["2 2\n0.500000 0.250000 0.250000", "9 9\n0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000", "1000001 5\n0.000000 0.300000 0.000000 0.500000 0.000000 0.200000", "1000000 5\n0.000000 0.000000 1.000000 0.000000 0.000000 0.000000", "100 20\n0.065682 0.015963 0.024840 0.0...
UNKNOWN
PYTHON3
CODEFORCES
2
f597a081a3acc7008f50eae51fc18f00
Lost in Transliteration
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
[ "n = int(input())\r\ni = 1\r\nwords = []\r\nwords2 = []\r\nres = set()\r\nwhile i <= n:\r\n words.append(input())\r\n i += 1\r\nfor i in range(n):\r\n words2 = words[i]\r\n while 'u' in words2:\r\n words2 = words2.replace('u', 'oo')\r\n while 'kh' in words2:\r\n words2 = words2.replace(...
{"inputs": ["10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "2\nalex\nalex", "40\nuok\nkuu\nku\no\nkku\nuh\nu\nu\nhh\nk\nkh\nh\nh\nou\nokh\nukk\nou\nuhk\nuo\nuko\nu\nuu\nh\nh\nhk\nuhu\nuoh\nooo\nk\nh\nuk\...
UNKNOWN
PYTHON3
CODEFORCES
88
f5a3f39afda2c439a842a8a0e82872d9
Start of the session
Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size *n*<=×<=*n* (*n* is even number). Gods will never allow to start the championship without it. Matrix should contain integers from 0 to *n*<=-<=1, main diagonal should...
[ "import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn = int(input())\r\n\r\nif n == 2:\r\n print('0 1\\n1 0')\r\n exit()\r\n\r\nmatrix = [[0] * n for _ in range(n)]\r\n\r\nfor i in range(n - 1):\r\n for j in range...
{"inputs": ["2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "32", "40", "666", "66", "80", "88", "96", "100", "128", "144", "250", "284", "332", "400", "600", "700", "780", "846", "902", "1000"], "outputs": ["0 1\n1 0", "0 1 3 2\n1 0 2 3\n3 2 0 1\n2 3 1 0", "0 1 4 2 5 3\n1 0 2 5 3 4\n4 2 0 3 1 5\n2 5 3 0 4 1\n5...
UNKNOWN
PYTHON3
CODEFORCES
6
f5adec5d79907a5e2e386a91f8277578
Choosing Capital for Treeland
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decid...
[ "num_nodes = int(input())\ntime_array = [0] * (num_nodes + 1)\n\nforward_edges, backward_edges = [[] for _ in range(num_nodes + 1)], [[] for _ in range(num_nodes + 1)]\n\nfor _ in range(num_nodes - 1):\n x, y = map(int, input().split())\n time_array[y] = 1\n forward_edges[x].append(y)\n backward_edges[y...
{"inputs": ["3\n2 1\n2 3", "4\n1 4\n2 4\n3 4", "2\n1 2", "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7", "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "10\n9 3\n3 8\n4 3\n3 5\n7 8\n10 3\n2 3\n6 2\n3 1", "10\n5 4\n6 5\n10 1\n2 5\n9 8\n1 3\n7 10\n2 3\n5 9", "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "11\n3 10\n4 7...
UNKNOWN
PYTHON3
CODEFORCES
15
f5b1edc2123050877e37a9fcb3209b4a
George and Number
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers *b*. During the game, George modifies the array by using special changes. Let's mark George's current array as *b*1,<=*b*2,<=...,<=*b*|*b*| (record |*b*| denotes the current length of the array). Then one chang...
[ "s=input().strip()\r\nn=len(s)\r\n\r\ni=0\r\nk=0\r\nwhile i<n:\r\n\tj=i;\r\n\ti+=1\r\n\twhile i<n and s[i]=='0':\r\n\t\ti+=1;\r\n\tif j>(i-j) or (j==i-j and s[:j]>=s[j:i]):\r\n\t\tk+=1\r\n\telse:\r\n\t\tk=1\r\nprint(k)", "a = input()\ni = 0; ans = 1\nwhile i < len(a):\n i += 1\n c = i-1\n while i < len(...
{"inputs": ["9555", "10000000005", "800101", "45", "1000000000000001223300003342220044555", "19992000", "310200", "63100605000394089000505000600600062000170273350000", "20900000000090009000070069000026000000000000020008", "60000000000000000000000000000000000000000000000000", "7", "69442629156526594581255999781161144587...
UNKNOWN
PYTHON3
CODEFORCES
10
f5beda691ed3a24d56dfc8e156695d38
Anagram Search
A string *t* is called an anagram of the string *s*, if it is possible to rearrange letters in *t* so that it is identical to the string *s*. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not. The string *t* is called a substring of the string *s* if it can be read starting fr...
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import Counter\r\n\r\nS = input()\r\nN = len(S)\r\nP = input()\r\nM = len(P)\r\nC = Counter(P)\r\n\r\nlib = [[0]*26 for _ in range(N+1)]\r\nfor i in range(N):\r\n a = S[i]\r\n for j in range(26):\r\n lib[i+1][j] = lib[i][j...
{"inputs": ["bb??x???\naab", "ab?c\nacb", "ccaac\ncbcbca", "?bba?\nbba", "aaaaa??a?a\naaa", "?bba?b?aaa\nabb", "?b?aaabaa?\naaa", "aaaaa?ab??\naab", "?bab?a?aab\naaa", "??fb???a??\ndeeefc", "?\na", "a\na", "?\ncb", "a\naa"], "outputs": ["2", "2", "0", "3", "8", "6", "3", "5", "3", "0", "1", "1", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
3
f5de91435f10ae345408623b2344c3b1
Maximize!
You are given a multiset *S* consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to *S*, the newly added integer is not less than any number in it. 1. Find a subset *s* of the set *S* such that the value is maximum possible. Here *max*(*s*) means maximum valu...
[ "import sys\n\nsys.setrecursionlimit(2 * 10 ** 6)\n\n\ndef test():\n # print(solve([1, 4, 5], [0, 1, 5, 10]))\n pass\n\n\ndef main():\n ops = []\n n = int(input())\n for _ in range(n):\n t = input()\n if t == '2':\n ops.append([2, 0])\n else:\n ops.append(li...
{"inputs": ["6\n1 3\n2\n1 4\n2\n1 8\n2", "4\n1 1\n1 4\n1 5\n2", "8\n1 7\n1 26\n1 40\n1 45\n1 64\n2\n1 88\n1 94", "9\n1 35\n2\n2\n1 45\n1 58\n2\n2\n2\n1 100", "15\n1 300022520\n1 542407315\n2\n2\n2\n1 622764928\n1 706078395\n1 715915848\n1 933742920\n1 942115408\n2\n2\n2\n2\n2", "25\n1 134292126\n2\n1 218916741\n1 23755...
UNKNOWN
PYTHON3
CODEFORCES
8
f6050dd5b349336b7c103efd3295fa88
Dasha and friends
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if...
[ "n, L = [ int (x) for x in input().split()]\r\nt = [int (x) for x in input().split()]\r\nd = [int (x) for x in input().split()]\r\np = \"\"\r\nq = \"\"\r\nfor x in range(n-1):\r\n p += str(t[x+1]-t[x])\r\np += str(t[0] + L - t[n-1])\r\nfor x in range(n-1):\r\n q += str(d[x+1]-d[x])\r\nq += str(d[0]+L-d[n-1])\...
{"inputs": ["3 8\n2 4 6\n1 5 7", "4 9\n2 3 5 8\n0 1 3 6", "2 4\n1 3\n1 2", "5 9\n0 2 5 6 7\n1 3 6 7 8", "5 60\n7 26 27 40 59\n14 22 41 42 55", "20 29\n0 1 2 4 5 8 9 12 14 15 17 19 20 21 22 23 25 26 27 28\n0 2 4 5 6 7 8 10 11 12 13 14 15 16 18 19 22 23 26 28", "35 41\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 18 19 20 21 22 23 2...
UNKNOWN
PYTHON3
CODEFORCES
92
f61d78de4dfc8f9ad1757133850be363
Fixed Points
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A p...
[ "n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nf=1\r\nfor i in range(n):\r\n if(l[i]==i):\r\n c=c+1\r\n elif(f==1 and l[l[i]]==i):\r\n c=c+2\r\n f=0\r\nif(f==1 and c<n):\r\n c=c+1\r\nprint(c)", "s, k, n = 0, 0, int(input())\r\nt = list(map(int, input().split()))\r\nfor...
{"inputs": ["5\n0 1 3 4 2", "10\n6 9 4 7 8 2 3 5 0 1", "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34...
UNKNOWN
PYTHON3
CODEFORCES
111
f6259d8cdf46697bf882fbfca39bdc34
Number With The Given Amount Of Divisors
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). Output the smallest positive integer with exactly *n* divisors. Sample Input 4 6 Sampl...
[ "ans = 2e18\r\nnow = []\r\np = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]\r\n\r\ndef dfs(x):\r\n global ans\r\n if x == 1:\r\n res = 1\r\n for i in range(len(now)):\r\n res *= pow(p[i], now[i] - 1)\r\n if res > 1e18:\r\n return\r\n ans = min(ans, res)\r\n ...
{"inputs": ["1", "7", "8", "9", "10", "15", "20", "47", "59", "100", "159", "265", "312", "473", "637", "500", "720", "902", "940", "1000", "999", "118"], "outputs": ["1", "64", "24", "36", "48", "144", "240", "70368744177664", "288230376151711744", "45360", "40532396646334464", "364791569817010176", "14192640", "25970...
UNKNOWN
PYTHON3
CODEFORCES
36
f662d236d019258c2096118a6174c09f
Bear and Elections
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect...
[ "n=int(input())\r\narr=list(map(int,input().split()))\r\nt=ans=arr.pop(0)\r\nmx=max(arr)\r\ni=1\r\nwhile (ans)<=mx:\r\n ans+=1\r\n arr.remove(mx)\r\n arr.append(mx-1)\r\n mx=max(arr)\r\nprint(ans-t)", "import math\r\nn = int(input())\r\nv = list(map(int , input().split()))\r\nv[1:]= sorted(v[1:])\r\na...
{"inputs": ["5\n5 1 11 2 8", "4\n1 8 8 8", "2\n7 6", "2\n1 1", "10\n100 200 57 99 1 1000 200 200 200 500", "16\n7 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "100\n47 64 68 61 68 66 69 61 69 65 69 63 62 60 68 65 64 65 65 62 63 68 60 70 63 63 65 67 70 69 68 69 61 65 63 60 60 65 61 60 70 ...
UNKNOWN
PYTHON3
CODEFORCES
165