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
ab1ba7a3a8c64af0d4dacb38a45591ed
Sanatorium
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes ho...
[ "def answer(a, b, c):\r\n if a == b and b == c:\r\n return 0\r\n if a + b + c == 1:\r\n return 0\r\n m = max(a,b,c)\r\n if m == a:\r\n pass\r\n elif m == b:\r\n a,b,c=b,c,a\r\n else:\r\n a,b,c=c,a,b\r\n if a == b:\r\n d = c\r\n elif a == c:\r\n ...
{"inputs": ["3 2 1", "1 0 0", "1 1 1", "1000000000000000000 0 1000000000000000000", "1000 0 0", "0 1 0", "0 0 1", "1 1 0", "0 1 1", "1000000000000000000 999999999999999999 999999999999999999", "1000000000000000000 1000000000000000000 999999999999999999", "1000000000000000000 1000000000000000000 1000000000000000000", "9...
UNKNOWN
PYTHON3
CODEFORCES
16
ab243f42ee37afd8273312305780af22
Electric Charges
Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals. A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: a...
[ "from sys import stdin, stdout, maxsize\r\nfrom typing import List\r\n\r\ndef sdiameter_axes(axis_one, axes_two):\r\n \"\"\"calcula el diametro**2 entre elementos de un mismo eje\"\"\"\r\n return int(pow(axis_one-axes_two, 2))\r\n\r\ndef sdiameter_xy(x, y):\r\n \"\"\"calcula el diametro**2 entre elementos ...
{"inputs": ["3\n1 10\n1 20\n1 30", "2\n1 10\n10 1", "10\n1 6\n2 2\n-1 9\n-8 8\n-4 10\n-10 -6\n5 -1\n-3 -7\n-4 3\n9 4", "18\n-14 -745\n87 -4611\n89 -3748\n-77 273\n-21 -4654\n-86 -5108\n-70 3232\n25 -6313\n-71 -4846\n88 -1894\n-65 9707\n-51 -3290\n-19 -580\n-62 -2408\n1 -6832\n52 -4279\n21 -7322\n55 9392", "12\n996 -72\...
UNKNOWN
PYTHON3
CODEFORCES
1
ab514d2189903ec3467ac95baa7abde1
Table Decorations
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color? Your task is to write a pro...
[ "import math\r\nl = [int(x) for x in input().split(\" \")]\r\nl.sort(reverse=True)\r\nif l[0] > (l[1]+l[2])*2:\r\n l[0] = (l[1]+l[2])*2\r\nprint(math.floor(sum(l)/3))", "r,g,b=map(int,input().split())\r\nprint(min((r+g+b)//3,r+g,g+b,b+r))", "[r,g,b] = [int(x) for x in input().split()]\r\nprint(min(r+g,r+b,b+...
{"inputs": ["5 4 3", "1 1 1", "2 3 3", "0 1 0", "0 3 3", "4 0 4", "1000000000 1000000000 1000000000", "100 99 56", "1000 1000 1002", "0 1 1000000000", "500000000 1000000000 500000000", "1000000000 2000000000 1000000000", "2000000000 2000000000 2000000000", "0 0 0", "1 2000000000 1000000000", "1585222789 1889821127 2000...
UNKNOWN
PYTHON3
CODEFORCES
77
ab6d5d8599c453ad60eda6bce18f0d4c
File List
Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where: - name is a string consisting of lowercase Latin lette...
[ "s = input()\r\na = []\r\nfor i, c in enumerate(s):\r\n if c == '.':\r\n a.append(i)\r\nn = len(s)\r\nif not a or not 1 <= a[0] <= 8 or not 1 <= n - a[-1] - 1 <= 3:\r\n print('NO')\r\nelif not all(2 <= abs(y - x - 1) <= 11 for x, y in zip(a, a[1:])):\r\n print('NO')\r\nelse:\r\n print('YES')\r\n ...
{"inputs": ["read.meexample.txtb.cpp", "version.infontldrcontestdata.zip", "thisis.text.txt", "oops.t", "thisislongfilename", "double..dot", "one.one.one.one.one.one.one.one.one.one", ".", "z", "a.", ".a", "za", "..", "xlq", ".r.", "ulmc", "nja.", "t..kz", "twaha", "m..dw.", "utsvfg.", ".we.voae", "kw.gkcxk.", ".c.v.hp...
UNKNOWN
PYTHON3
CODEFORCES
13
ab84e591c27936e4ef3d86b9651f6fd0
Optimal Point on a Line
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coo...
[ "n = int(input())\na = [int(i) for i in input().split()]\n\na.sort()\n\nif n % 2 == 0:\n\tx = n // 2\nelse:\n\tx = (n + 1) // 2\n\nprint(a[x-1])\n\n", "n=int(input())\nintList=list(map(int,input().split()))\nintList.sort()\nif(n%2):\n print(intList[n//2])\nelse:\n print(intList[n//2-1])\n\t\t\t\t\t\t\t\t \...
{"inputs": ["4\n1 2 3 4", "5\n-1 -10 2 6 7", "10\n-68 10 87 22 30 89 82 -97 -52 25", "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -7...
UNKNOWN
PYTHON3
CODEFORCES
107
ab9570f400b71baf4b0f8f8379616f4c
Not Afraid
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are *n* parallel universes participating in this event (*n* Ricks and *n* Mortys). I. e. each of *n* universes has one Rick...
[ "n, m = map(int, input().split())\r\nstop = False\r\nfor _ in range(m):\r\n k, *a = map(int, input().split())\r\n s = set(a)\r\n if all(x > 0 or -x not in s for x in a):\r\n stop = True\r\nif stop:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def compare(x):\r\n\treturn abs(x)\r\n\r\...
{"inputs": ["4 2\n1 -3\n4 -2 3 2 -3", "5 2\n5 3 -2 1 -1 5\n3 -5 2 5", "7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4", "2 1\n2 -2 2", "7 7\n1 -2\n1 6\n2 7 -6\n2 -6 4\n2 -4 -6\n3 -5 7 -5\n1 -6", "100 50\n2 62 -62\n2 19 -19\n2 38 -38\n2 -84 84\n2 -16 16\n2 67 -67\n2 41 -41\n2 -32 32\n2 32 -32\n2 -62 62\n2 89 -89\n2 -84 84\n2 96 -96\n...
UNKNOWN
PYTHON3
CODEFORCES
69
ab9bbca22e4ebbfac690204da5b4e636
pSort
One day *n* cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move *i*-th cell can exchange it's value with the value of some other *j*-th cell, if |*i*<=-<=*j*|<...
[ "n = int(input())\r\nper = list(map(int,input().split()))\r\nd = [0] + list(map(int,input().split()))\r\np = [i for i in range(n+1)]\r\ndef find(node):\r\n while p[node] != node:\r\n p[node] = p[p[node]]\r\n node = p[node]\r\n return node\r\n\r\ndef union(n1,n2):\r\n p1 = find(n1)\r\n p2 =...
{"inputs": ["5\n5 4 3 2 1\n1 1 1 1 1", "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "6\n3 2 1 4 6 5\n3 6 1 6 6 1", "6\n3 5 1 4 6 2\n3 6 1 6 6 1", "4\n1 2 3 4\n1 1 1 1", "71\n1 63 3 4 5 6 7 8 9 44 29 12 13 14 55 34 42 18 52 20 21 33 23 24 25 26 27 28 19 30 47 32 15 71 37 36 69 38 39 40 41 17 43 ...
UNKNOWN
PYTHON3
CODEFORCES
27
aba1ae6e26971be89042dc7797363ba2
The Road to Berland is Paved With Good Intentions
Berland has *n* cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not. The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every day Valera chooses exactly one city and orders the crew to asphalt all roa...
[ "import sys\r\nreadline=sys.stdin.readline\r\n\r\ndef SCC(N,edges):\r\n start = [0] * (N + 1)\r\n elist = [0] * len(edges)\r\n for e in edges:\r\n start[e[0] + 1] += 1\r\n for i in range(1, N + 1):\r\n start[i] += start[i - 1]\r\n counter = start[:]\r\n for e in edges:\r\n eli...
{"inputs": ["4 4\n1 2 1\n2 4 0\n4 3 1\n3 2 0", "3 3\n1 2 0\n2 3 0\n3 1 0", "4 5\n3 2 0\n1 4 0\n4 3 1\n3 1 0\n1 2 0", "2 1\n2 1 0", "6 13\n4 6 0\n4 2 1\n6 2 0\n5 4 1\n1 3 1\n5 6 1\n1 5 1\n1 4 1\n2 3 1\n1 2 1\n3 6 0\n6 1 1\n2 5 1", "7 13\n5 7 1\n1 2 0\n5 3 0\n6 1 1\n6 3 0\n2 7 0\n7 1 1\n6 4 1\n6 2 1\n4 7 1\n2 5 0\n1 5 0\...
UNKNOWN
PYTHON3
CODEFORCES
1
abbad00030e70b95b58997b453592058
Playing with Dice
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
[ "m=list(map(int,input().split()))\r\nresult_a_win=result_draw=result_b_win=0\r\nfor i in range(1,7):\r\n if abs(m[0]-i)<abs(m[1]-i):\r\n result_a_win += 1 \r\n if abs(m[0]-i)==abs(m[1]-i):\r\n result_draw += 1 \r\n if abs(m[0]-i)>abs(m[1]-i):\r\n result_b_win += 1 \r\nprint(result_a_wi...
{"inputs": ["2 5", "2 4", "5 3", "1 6", "5 1", "6 3", "2 3", "5 6", "4 4", "1 1", "6 4", "1 4", "5 5", "4 5", "4 3", "1 5", "6 5", "2 2", "1 3", "3 6", "3 1", "3 2", "3 5", "3 3", "6 2", "4 1", "5 2", "4 2", "2 1", "6 1", "4 6", "2 6", "3 4", "1 2", "6 6", "5 4", "3 3", "1 1"], "outputs": ["3 0 3", "2 1 3", "2 1 3", "3...
UNKNOWN
PYTHON3
CODEFORCES
672
abc27619c76daf559804e27c90524aa3
Black and White Tree
The board has got a painted tree graph, consisting of *n* nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles. Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each ed...
[ "import io\nimport os\n\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\n\n\ndef solve():\n n = int(input())\n blacks = []\n whites = []\n for i in range(n):\n ci, si = map(int, input().split())\n if ci == 0:\n whites.append((i, si))\n else:\n bla...
{"inputs": ["3\n1 3\n1 2\n0 5", "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0", "2\n0 0\n1 0", "5\n1 11\n0 9\n1 4\n0 4\n0 2", "10\n0 24\n1 164\n0 206\n0 45\n1 110\n0 66\n1 59\n1 92\n0 152\n1 68", "20\n0 569\n1 328\n1 74\n1 88\n1 90\n1 124\n0 78\n0 39\n1 9\n1 59\n1 41\n1 73\n1 45\n0 45\n0 13\n1 39\n0 24\n0 37\n0 95\n0 70", "30\n0 11...
UNKNOWN
PYTHON3
CODEFORCES
1
abe3564167e92c6206670f366b48b0e5
none
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. ...
[ "s = input()\r\nt = input()\r\nd, u = set(), set()\r\nfor i in range(len(s)):\r\n mn, mx = min(s[i], t[i]), max(s[i], t[i])\r\n if (s[i] in u or t[i] in u) and (mn, mx) not in d:\r\n print(-1)\r\n exit()\r\n u.add(s[i])\r\n u.add(t[i])\r\n d.add((mn, mx))\r\n\r\nres = [x for x in d if x...
{"inputs": ["helloworld\nehoolwlroz", "hastalavistababy\nhastalavistababy", "merrychristmas\nchristmasmerry", "kusyvdgccw\nkusyvdgccw", "bbbbbabbab\naaaaabaaba", "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx", "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc", "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjd...
UNKNOWN
PYTHON3
CODEFORCES
52
abf11aeddeb0af07ea9ac20715e7c810
Solution for Cube
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef f(a1, b1, c1, d1, e1, f1, g):\r\n a, b, c, d, e, f = a1.copy(), b1.copy(), c1.copy(), d1.copy(), e1.copy(), f1.copy()\r\n if len(set(a)) == len(set(b)) == 1:\r\n if g == 1:\r\n for i in [c, d, e, f]:\r\n i[1], i[2] = i[2...
{"inputs": ["2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4", "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3", "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1", "3 4 2 3 5 5 6 6 4 5 4 6 5 1 1 1 6 2 1 3 3 2 4 2", "5 5 2 5 3 3 2 6 6 4 2 4 6 1 4 3 1 6 2 1 3 4 5 1", "6 6 1 2 6 1 1 3 5 4 3 4 3 5 5 2 4 4 6 2 1 5 3 2", "2...
UNKNOWN
PYTHON3
CODEFORCES
29
ac0c2716962ff08b4b4c6c7396f716d9
Tree Requests
Roman planted a tree consisting of *n* vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the *n*<=-<=1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex *i* is vertex *p**i*, the parent index is always les...
[ "import sys\r\nfrom types import GeneratorType\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def _read():\r\n return sys.stdin.readline().strip()\r\n\r\n def read_int(self):\r\n return int(self._read())\r\n\r\n def read_float(self):\r\n ...
{"inputs": ["6 5\n1 1 1 3 3\nzacccd\n1 1\n3 3\n4 1\n6 1\n1 2", "5 6\n1 1 2 3\ncbcab\n3 1\n5 2\n1 3\n4 1\n4 2\n1 1", "5 6\n1 2 2 1\nbaabb\n1 1\n1 2\n5 1\n4 1\n4 2\n3 2", "5 9\n1 1 1 2\nedbcb\n1 3\n2 1\n1 3\n2 1\n2 2\n2 2\n1 1\n1 3\n2 1", "8 12\n1 1 1 2 1 1 4\ncbecdcce\n1 2\n1 2\n2 1\n1 1\n2 1\n1 3\n1 3\n1 3\n1 2\n2 3\n1...
UNKNOWN
PYTHON3
CODEFORCES
4
ac413e3d23d2317e4f1b0c9a24087720
Fix a Tree
A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with *n* vertices, numbered 1 through *n*. There are many ways to represent such a tree. One way is to create an array with *n* integers *p*1,<=*p*2,<=...,<=*p**n*, where *p**i* denotes a parent of vertex *i* (here, for con...
[ "n = int(input())\narr = list(map(int, input().split(' ')))\nroot=-1\nfor i,a in enumerate(arr) :\n if i == a-1 :\n root = i\n break\nv = [False]*len(arr)\nif root>-1 :\n v[root]=True\nans = 0\nfor i,a in enumerate(arr) :\n if v[i] :\n continue\n v[i]= True\n l=[i]\n a-=1\n ...
{"inputs": ["4\n2 3 3 4", "5\n3 2 2 5 3", "8\n2 3 5 4 1 6 6 7", "2\n1 2", "7\n4 3 2 6 3 5 2", "6\n6 2 6 2 4 2", "7\n1 6 4 4 5 6 7", "7\n7 5 3 1 2 1 5", "7\n1 2 3 4 5 6 7", "18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18", "8\n2 1 2 2 6 5 6 6", "3\n2 1 1"], "outputs": ["1\n2 3 4 4 ", "0\n3 2 2 5 3 ", "2\n2 3 7 8 1 6 6...
UNKNOWN
PYTHON3
CODEFORCES
12
ac689f494ff393c5b62ac0af2dd8b902
Bar
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec...
[ "a='ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE'.split()\r\nn=int(input())\r\nans=0\r\nfor i in range(n):\r\n x=input()\r\n if x in a or x.isdigit() and int(x)<18:ans+=1\r\nprint(ans)", "\r\nn = int(input())\r\n\r\ncount = 0\r\na=['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'R...
{"inputs": ["5\n18\nVODKA\nCOKE\n19\n17", "2\n2\nGIN", "3\nWHISKEY\n3\nGIN", "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW", "4\nSAKE\nSAKE\n13\n2", "2\n0\n17", "1\n0"], "outputs": ["2", "2", "3", "1", "4", "2", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
272
ac9108f0e82902b1ab432959abb62764
Counterexample
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i...
[ "l,r = map(int,input().split())\nrange = r - l + 1\nif (range < 3) or (l % 2 == 1 and range < 4):\n print(-1)\nelse:\n if (l % 2 == 0):\n print(l,l+1,l+2)\n else:\n print(l+1,l+2,l+3)", "import sys\n\nl, r = map(int, sys.stdin.readline().split())\nif l % 2 is not 0:\n l += 1\n\nif r - l ...
{"inputs": ["2 4", "10 11", "900000000000000009 900000000000000029", "640097987171091791 640097987171091835", "19534350415104721 19534350415104725", "933700505788726243 933700505788726280", "1 3", "1 4", "1 1", "266540997167959130 266540997167959164", "267367244641009850 267367244641009899", "268193483524125978 2681934...
UNKNOWN
PYTHON3
CODEFORCES
367
ac9bff232861d45cba367272ddb2c80e
Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too ...
[ "# LUOGU_RID: 111555286\nfrom sys import stdin \ninput = stdin.readline \n\ndef get() : \n return map(int,input().split())\n\ndef dfs(u, fa) : \n\n f[u] = 0 \n for v in Map[u].keys() : \n if v == fa : continue \n dfs(v, u) \n f[u] += f[v] + Map[u][v] \n\ndef find(u, fa, tot) : \n gl...
{"inputs": ["3\n1 2 3\n2 3 4", "3\n1 2 3\n1 3 3", "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14", "3\n2 1 63\n3 1 78", "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6 4 18\n7 1 79\n3 2 58\n9 7 92\n10 6 62\n4 3 5\n12 4 87\n5 3 66", "2\n2 1 89", "12\n3 1 31\n5 2 94\n9 8 37\n10 9 45\n7 5 75\n4 2 77\n6 3 31\n11 6 14\n8 7 19\n2 1 68\n12 1 6...
UNKNOWN
PYTHON3
CODEFORCES
18
acd4c4fb1076614e330c5341053f7a0a
Rectangle and Square
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the ...
[ "from itertools import permutations as p \r\nl = [list(map(int, input().split())) + [_] for _ in range(1, 9)]\r\n\r\ndef dist(a, b):\r\n return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2\r\n\r\ndef rect(a, b, c, d):\r\n return dist(a, b) == dist(c, d) and dist(a, c) == dist(b, d) and dist(a, d) == dist(b, c) and...
{"inputs": ["0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1", "-160 336\n-76 672\n8 168\n-580 588\n-1000 504\n-496 840\n-496 84\n-664 0", "8 -328\n-440 568\n-104 8\n-1000 -664\n8 456\n-328 8\n-552 120\n-664 -1000", "65 852\n-645 284\n-361 7...
UNKNOWN
PYTHON3
CODEFORCES
8
ad14725a5fe6b814b4b6bbb9fe4458f0
Destroying Roads
In some country there are exactly *n* cities and *m* bidirectional roads connecting the cities. Cities are numbered with integers from 1 to *n*. If cities *a* and *b* are connected by a road, then in an hour you can go along this road either from city *a* to city *b*, or from city *b* to city *a*. The road network is s...
[ "from collections import deque\r\n\r\n\r\nn,m=map(int,input().split())\r\ngraph=[[] for _ in range(n)]\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n a-=1\r\n b-=1\r\n graph[a].append(b)\r\n graph[b].append(a)\r\nd=[[-1]*n for _ in range(n)]\r\nfor i in range(n):\r\n q=deque()\r\n q...
{"inputs": ["5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2", "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1", "9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 3", "9 9\n1 2\n2 3\n2 4\n4 5\n5 7\n5 6\n3 8\n8 9\n9 6\n1 7 4\n3 6 4", "10 11\n1 3\n2 3\n3 4\n4 5\n4 6\n3 7\n3 8\n4 9\n4 10\...
UNKNOWN
PYTHON3
CODEFORCES
1
ad19bf2016662dc02a3757bd711fb08f
Sereja and Prefixes
Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm. Sereja takes a blank piece of paper. Then he starts writing out the sequence in *m* stages. Each time he either adds a new number to the end of the sequence or takes *l* first elements of the current...
[ "from sys import stdout, stdin, setrecursionlimit\nfrom io import BytesIO, IOBase\nfrom collections import *\nfrom itertools import *\nfrom random import * \nfrom bisect import *\nfrom string import *\nfrom queue import *\nfrom heapq import *\nfrom math import *\nfrom re import *\nfrom os import *\n\n##############...
{"inputs": ["6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16", "2\n1 33085\n1 44638\n2\n1 2", "10\n1 57757\n1 45234\n1 80807\n1 38496\n1 27469\n1 42645\n1 72643\n1 33235\n1 10843\n1 80598\n10\n1 2 3 4 5 6 7 8 9 10", "3\n1 97601\n1 32580\n1 70519\n3\n1 2 3", "7\n1 53989\n1 47249\n1 71935\...
UNKNOWN
PYTHON3
CODEFORCES
3
ad1f8a840e84be956b38eac4b391343f
Petr and Permutations
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times takes a random pair of different elements and swaps them. Alex envies Petr ...
[ "n=int(input())\r\narr=list(map(int,input().split()))\r\ngap=n//2\r\ncount =0\r\nwhile gap >=1:\r\n for j in range(gap ,n):\r\n i= j-gap\r\n while i >=0:\r\n if arr[i +gap] >arr[i]:\r\n break\r\n else:\r\n arr[i +gap],arr[i] =arr[i] ,arr[i +gap]\r...
{"inputs": ["5\n2 4 5 1 3"], "outputs": ["Petr"]}
UNKNOWN
PYTHON3
CODEFORCES
13
ad220da3e1b05b8f889f1484c2d540f7
Drazil and Park
Drazil is a monkey. He lives in a circular park. There are *n* trees around the park. The distance between the *i*-th tree and (*i*<=+<=1)-st trees is *d**i*, the distance between the *n*-th tree and the first tree is *d**n*. The height of the *i*-th tree is *h**i*. Drazil starts each day with the morning run. The mor...
[ "from math import inf\nimport sys\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\nfast_print = lambda p: sys.stdout.write(str(p) + \"\\n\") \n\nn, m = [int(component) for component in input().split(\" \")]\nd = [int(component) for component in input().split(\" \")]\nh = [int(component) for component in in...
{"inputs": ["5 3\n2 2 2 2 2\n3 5 2 1 4\n1 3\n2 2\n4 5", "3 3\n5 1 4\n5 1 4\n3 3\n2 2\n1 1", "10 10\n8477 33103 38654 6582 27496 1106 15985 3644 29818 8849\n88745 72099 87767 85285 73517 94562 87214 63194 83791 77619\n2 8\n1 5\n9 5\n7 8\n6 9\n8 1\n6 1\n4 9\n8 10\n5 10", "9 9\n1 1 1 1 1 1 1 1 1\n1 1 1 1 1000000000 1 1 1 ...
UNKNOWN
PYTHON3
CODEFORCES
1
ad656fd9fb168c5779c1eec25fd50ee2
Sagheer and Crossroads
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane...
[ "def main():\r\n l1, s1, r1, p1 = map(int, input().split())\r\n l2, s2, r2, p2 = map(int, input().split())\r\n l3, s3, r3, p3 = map(int, input().split())\r\n l4, s4, r4, p4 = map(int, input().split())\r\n if p1 == 1:\r\n if s1 == 1 or l1 == 1 or r1 == 1 or s3 == 1 or l2 == 1 or r4 == 1:\r\n ...
{"inputs": ["1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0", "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "1 1 1 0\n0 1 0 1\n1 1 1 0\n1 1 1 1", "0 1 1 0\n0 1 0 0\n1 0 0 1\n1 0 0 0", "1 0 0 0\n0 1 0 0\n1 1 0 0\n0 1 1 0", "0 0 0 0\n0 1 0 1\n1 0 1 1\n1 1 1 0", "1 1...
UNKNOWN
PYTHON3
CODEFORCES
74
ad7defe219bd7fa8acbe1890ffa08b24
none
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte...
[ "n,k=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nif k==1:\r\n print (min(a))\r\nelif k>2:\r\n print(max(a))\r\nelse:\r\n l1=[0 for i in range(n)]\r\n l2=[0 for j in range(n)]\r\n l1[0]=a[0]\r\n for i in range(1,n):\r\n l1[i]=min(l1[i-1],a[i])\r\n l2[n-2]=a...
{"inputs": ["5 2\n1 2 3 4 5", "5 1\n-4 -5 -3 -2 -1", "10 2\n10 9 1 -9 -7 -9 3 8 -10 5", "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9", "1 1\n504262064", "3 3\n-54481850 -878017339 -486296116", "2 2\n-333653905 224013643", "14 2\n-14 84 44 46 -75 -75 77 -49 44 -82 -74 -51 -9 -50", "88 71\n-497 -488 182 104 40 183 201 282 -384 44 -29...
UNKNOWN
PYTHON3
CODEFORCES
140
adb059482de1a081f75f56e8d0085745
Position in Fraction
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=&lt;<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). Print position of the first occurrence of digit *c* into the fraction. Posi...
[ "from decimal import *\r\ngetcontext().prec=10**5+500\r\na,b,c=map(int,input().split())\r\nr = Decimal(a)/Decimal(b)\r\nr=(str(r)+'0'*100).split('.')[1][:10**5]\r\nif str(c) not in r:print(-1)\r\nelse:print(r.index(str(c))+1)", "def first( a , b , c ): \n a %= b \n for i in range(1, b + 1): \n a = ...
{"inputs": ["1 2 0", "2 3 7", "1 100000 1", "1 7 7", "99999 100000 8", "44102 73848 2", "7 31 3", "8880 81608 9", "4942 62768 5", "69168 84860 4", "971 1883 3", "1636 3269 6", "6873 7769 3", "13805 15538 3", "10958 21926 3", "8 51 0", "1 10 1", "1 9 0", "53 101 6", "1 10001 9", "25102 31579 2", "38790 39359 0", "47117 ...
UNKNOWN
PYTHON3
CODEFORCES
86
adbf79a9d4af5e615e98841bd63ff9b3
Meeting of Old Friends
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to ...
[ "import operator as op\r\nimport re\r\nimport sys\r\nfrom bisect import bisect, bisect_left, insort, insort_left\r\nfrom collections import Counter, defaultdict, deque\r\nfrom copy import deepcopy\r\nfrom decimal import Decimal\r\nfrom functools import reduce\r\nfrom itertools import (\r\n accumulate, combinatio...
{"inputs": ["1 10 9 20 1", "1 100 50 200 75", "6 6 5 8 9", "1 1000000000 1 1000000000 1", "5 100 8 8 8", "1 1000000000000000000 2 99999999999999999 1000000000", "1 1 1 1 1", "1 2 3 4 5", "1 1000000000 2 999999999 3141592", "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "1080184299348 3466682...
UNKNOWN
PYTHON3
CODEFORCES
142
adc74535feb0901a59a1c5135823da3b
Word Correction
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
[ "vowels = ['a', 'e', 'i', 'o', 'u', 'y']\r\n\r\ndef word_correction(s):\r\n result = []\r\n result.append(s[0])\r\n left = 0\r\n right = 1\r\n while right < len(s):\r\n if not s[left] in vowels or not s[right] in vowels:\r\n result.append(s[right])\r\n left = right\r\n ...
{"inputs": ["5\nweird", "4\nword", "5\naaeaa", "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "12\nmmmmmmmmmmmm", "18\nyaywptqwuyiqypwoyw", "85\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
UNKNOWN
PYTHON3
CODEFORCES
307
adcd6dbdc21f29d273d9dcf1d6cb45ab
Tavas and Karafs
Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s*...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\na, b, n, l, t, m = -1, -1, -1, -1, -1, -1\r\n\r\ndef is_valid(mid):\r\n biggest = a + (mid - 1) * b;\r\n if t < biggest: \r\n return False\r\n sum = ((mid - l + 1) * (a + (l - 1) * b + biggest)) // 2\r\n return t >= biggest and m * t >= sum\r\n\r\n...
{"inputs": ["2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8", "1 5 2\n1 5 10\n2 7 4", "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1", "1000000 1000000 1\n1000000 1000000 1000000", "999999 1000000 1\n1 1000000 1000000", "1 1000000 1\n1 1000000 1000000", "1 5000 1\n1 1000000 1000000", "1 1 1\n1 1000000 1000000", "447 7...
UNKNOWN
PYTHON3
CODEFORCES
10
ade770083603ea41310a40d70e1f2c83
Recover the String
For each string *s* consisting of characters '0' and '1' one can define four integers *a*00, *a*01, *a*10 and *a*11, where *a**xy* is the number of subsequences of length 2 of the string *s* equal to the sequence {*x*,<=*y*}. In these problem you are given four integers *a*00, *a*01, *a*10, *a*11 and have to find any...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\ndef process(a1, a2, a3, a4):\r\n \"\"\"\r\n a1 = count of 00\r\n a2 = count of 01\r\n a3 = count of 10\r\n a4 = count of 11\r\n \r\n a1 = zero_count*(zero_count-1)//2\r\n 2a1 = z2-z\r\n z2-z-2a = 0\r\n (1+root(1+8a))//2\r\n \"\...
{"inputs": ["1 2 3 4", "1 2 2 1", "10 7 28 21", "0 0 0 0", "499928010 820999488 178951395 499991253", "49995000 11667 4308334 93096", "499928010 601314341 398636540 499991253", "0 2548 1752 650", "4950 53524 2876 158766", "20946628 20410736 263003096 958497436", "49995000 1061 8939 0", "0 0 0 45", "49995000 302076 4017...
UNKNOWN
PYTHON3
CODEFORCES
6
ae083f1956b67b67e4911b0d0a0c0ecf
Preparing for Merge Sort
Ivan has an array consisting of *n* different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array. Ivan represent his array with increasing sequences with...
[ "from bisect import bisect_left\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\np = []\r\nresult = []\r\nfor x in a:\r\n r = bisect_left(p, -x)\r\n if r == len(result):\r\n result.append([])\r\n p.append(0)\r\n\r\n result[r].append(x)\r\n p[r] = -x\r\n\r\nfor arr in resul...
{"inputs": ["5\n1 3 2 5 4", "4\n4 3 2 1", "4\n10 30 50 101", "1\n1", "1\n200000", "2\n1 2", "2\n2 1", "2\n1 200000", "2\n200000 1", "10\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967", "3\n1 100 1000000000", "3\n1000000000 100 1"], "outputs": ["1 3 5 \n2 4 ", "4 \n3 \...
UNKNOWN
PYTHON3
CODEFORCES
32
ae0fdc5010d3494e36f04cc00ad43570
Cutting
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
[ "n,b=map(int,input().split())\r\na=list(map(int,input().split()))\r\nq,w,l,m=0,0,[],0\r\nfor i in range(n-1):\r\n if a[i]&1:q+=1\r\n else:w+=1\r\n if q==w:l.append(abs(a[i]-a[i+1]))\r\nl.sort()\r\nfor i in l:\r\n if i<=b:m+=1;b-=i\r\n else:break\r\nprint(m)", "import math\r\nfrom decimal import *\r...
{"inputs": ["6 4\n1 2 5 10 15 20", "4 10\n1 3 2 4", "6 100\n1 2 3 4 5 6", "2 100\n13 78", "10 1\n56 56 98 2 11 64 97 41 95 53", "10 100\n94 65 24 47 29 98 20 65 6 17", "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100...
UNKNOWN
PYTHON3
CODEFORCES
234
ae1ae244542fda4e96c524e9b099768c
President and Roads
Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer. Once a year the President visited his historic home town *t*, for which his motorc...
[ "from heapq import *\r\nfrom collections import defaultdict\r\ndef D(v,g):\r\n\th,p,o=[],defaultdict(lambda:1e99),[]\r\n\theappush(h,(0,v))\r\n\twhile h:\r\n\t\tl,w=heappop(h)\r\n\t\tif w in p:continue\r\n\t\tp[w]=l\r\n\t\to.append(w)\r\n\t\tfor u,L in g[w]:\r\n\t\t\theappush(h,(L+l,u))\r\n\treturn p,o\r\nn,m,s,t=m...
{"inputs": ["6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 100", "2 2 1 2\n1 2 1\n1 2 2", "2 1 1 2\n1 2 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 19", "4 3 1 4\n1 2 1\n2 3 1\n3 4 1", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 2", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "6 6 1 6\n1 2 2\n2 3 4\...
UNKNOWN
PYTHON3
CODEFORCES
2
ae4d4ce41de468ab0ba2162a03886e45
Imbalance Value of a Tree
You are given a tree *T* consisting of *n* vertices. A number is written on each vertex; the number written on vertex *i* is *a**i*. Let's denote the function *I*(*x*,<=*y*) as the difference between maximum and minimum value of *a**i* on a simple path connecting vertices *x* and *y*. Your task is to calculate . The f...
[ "import sys\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\nRILST = lambda: list(RI())\r\n\r\ndef find(x):\r\n # 不会被卡爆栈的并查集find函数 省空间\r\n t = x\r\n while fa[x] != x:\r\n x = fa[x]\r\n while t != x:\r\n fa[t], t = x, fa[t]\r\n return x\r\n\r\nn, = RI()\r\na = RILST()\r\n...
{"inputs": ["4\n2 2 3 1\n1 2\n1 3\n1 4"], "outputs": ["6"]}
UNKNOWN
PYTHON3
CODEFORCES
2
ae50d398ed874b0841e12d0650f2eb68
Harry Potter and Three Spells
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of lead, the second one allows you to convert *c* grams of lead into *d* grams o...
[ "# LUOGU_RID: 112089745\na, b, c, d, e, f = map(int, input().split());\r\nif a * c * e < b * d * f or a == 0 and b * d > 0 or c == 0 and d > 0:\r\n print(\"Ron\");\r\nelse:\r\n print(\"Hermione\");", "a, b, c, d, e, f = [int(x) for x in input().split()]\n\ndef main(a, b, c, d, e, f):\n if d == 0:\n ...
{"inputs": ["100 200 250 150 200 250", "100 50 50 200 200 100", "100 10 200 20 300 30", "0 0 0 0 0 0", "1 1 0 1 1 1", "1 0 1 2 1 2", "100 1 100 1 0 1", "1 1 2 2 1 1", "4 4 1 3 1 4", "3 3 2 1 4 4", "5 1 2 9 1 10", "63 65 21 41 95 23", "913 0 0 0 0 0", "0 333 0 0 0 0", "842 538 0 0 0 0", "0 0 536 0 0 0", "324 0 495 0 0 0...
UNKNOWN
PYTHON3
CODEFORCES
21
ae7533016ff1ec3e7dabb9774657d2da
Orientation of Edges
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximiz...
[ "import sys\ninput = sys.stdin.readline\n\ndef put():\n return map(int, input().split())\n\n\n\n\ndef dfs0(x):\n s = [x]\n vis = [0] * n\n ans = ['+'] * m\n vis[x] = 1\n while s:\n i = s.pop()\n for j, k in graph[i]:\n if (vis[j] == 0):\n if (k < 0):\n ans[-k - 1] = '-'\n eli...
{"inputs": ["2 2 1\n1 1 2\n2 2 1", "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3", "5 5 5\n2 5 3\n1 2 3\n1 4 5\n2 5 2\n1 2 1", "13 18 9\n2 3 10\n1 12 10\n1 11 4\n2 2 8\n1 5 1\n1 7 12\n1 5 13\n1 9 7\n1 10 11\n2 3 12\n1 9 2\n1 3 9\n1 8 12\n2 11 3\n1 3 1\n1 8 4\n2 9 11\n1 12 13", "5 10 2\n2 2 4\n1 1 2\n2 2 3\n1 3 1\n1 ...
UNKNOWN
PYTHON3
CODEFORCES
2
aeabf288c17b785fce5cd0529c46eca2
none
Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего бра...
[ "print(*{'1','2','3'}.difference(set(input().split())))\n", "a = [int(i) for i in input().split()]\r\nprint(6-a[0]-a[1])\r\n", "print(list({1, 2, 3}.difference({int(i) for i in input().split()}))[0])", "print(*set(\"123\")-set(input()))", "a, b = map(int,input().split())\r\nprint(6-a-b)", "a,b=map(int,inp...
{"inputs": ["3 1", "2 1", "2 3", "1 2", "1 3", "3 2"], "outputs": ["2", "3", "1", "3", "2", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
57
aecef1b89d6a39bf7b952679007eaaa3
Generous Kefa
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his...
[ "import string\r\n\r\na , b = map(int , input().split())\r\ns = input()\r\n\r\nf = True\r\nfor i in string.ascii_lowercase:\r\n if s.count(i) > b:\r\n f = False\r\n break\r\n\r\n\r\nif f: print(\"YES\")\r\nelse: print(\"NO\")", "n,k=map(int,input().split())\r\ns=input()\r\nd=dict()\r\nfor i in s:...
{"inputs": ["4 2\naabb", "6 3\naacaab", "2 2\nlu", "5 3\novvoo", "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv", "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "100...
UNKNOWN
PYTHON3
CODEFORCES
374
aee0924b4cca049564aa0eadf0161593
Naughty Stone Piles
There are *n* piles of stones of sizes *a*1,<=*a*2,<=...,<=*a**n* lying on the table in front of you. During one move you can take one pile and add it to the other. As you add pile *i* to pile *j*, the size of pile *j* increases by the current size of pile *i*, and pile *i* stops existing. The cost of the adding opera...
[ "n = int(input())\r\nstones = list(map(lambda t : int(t), input().split()))\r\nq = int(input())\r\nqueries = list(map(lambda t : int(t), input().split()))\r\n\r\nstones.sort()\r\n\r\nadded_stones = []\r\nadded_stones.append(stones[0])\r\nfor i in range(1, n, 1):\r\n added_stones.append(stones[i] + added_stones[i...
{"inputs": ["5\n2 3 4 1 1\n2\n2 3", "2\n2 9\n5\n4 10 7 3 4", "1\n7\n4\n6 2 3 3", "2\n7 10\n2\n2 4", "1\n10\n5\n5 3 7 7 1", "1\n2\n5\n7 3 9 8 1", "4\n8 10 4 4\n3\n7 8 1", "2\n7 9\n1\n9", "3\n4 5 4\n2\n10 2", "3\n1 6 8\n1\n6", "2\n9 3\n1\n6", "5\n9 5 7 3 3\n1\n3", "2\n7 4\n1\n7", "4\n7 4 1 7\n3\n6 8 3", "3\n3 7 3\n1\n5",...
UNKNOWN
PYTHON3
CODEFORCES
1
aef94126262696add047250d8bd2e8b3
Comparing Strings
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
[ "a = input()\r\nb = input()\r\nd = 0\r\nf = []\r\n\r\nif not len(a) == len(b):\r\n print('NO')\r\nelse:\r\n for i in range(len(a)):\r\n if not a[i] == b[i]:\r\n d += 1\r\n if d == 3:\r\n break\r\n f.append([a[i], b[i]])\r\n\r\n if d == 2:\r\n pr...
{"inputs": ["ab\nba", "aa\nab", "a\nza", "vvea\nvvae", "rtfabanpc\natfabrnpc", "mt\ntm", "qxolmbkkt\naovlajmlf", "b\ng", "ab\naba", "ba\na", "a\nab", "a\naa", "a\nz", "aabb\nbbaa", "ab\nbd", "bac\ndae", "abc\nakl", "cb\naa", "abaab\naabba", "aab\naaa", "abcde\nedcba", "abab\nbaba", "ab\nbac", "abcd\naqcb", "abc\nbad", ...
UNKNOWN
PYTHON3
CODEFORCES
225
aefa85430ea1173192e6b6f9c74fd279
Stock Trading
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to predict the stock price of a company over the next *n* days and wants to design...
[ "import sys\r\n\r\n\r\nammount_prices, days_for_trading=map(int, input().split())\r\nstonks=[]\r\nfor i in range (0, ammount_prices):\r\n price=int(sys.stdin.readline())\r\n stonks.append(price)\r\n\r\ndef get_max(days_for_trading, stonks):\r\n size_prices = len(stonks)\r\n if size_prices == 0 or size_p...
{"inputs": ["10 2\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9", "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9", "2 1\n2\n1"], "outputs": ["15", "21", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
1
af59dd9996523593121fa4b9cf34e438
Cut Length
Given simple (without self-intersections) *n*-gon. It is not necessary convex. Also you are given *m* lines. For each line find the length of common part of the line and the *n*-gon. The boundary of *n*-gon belongs to polygon. It is possible that *n*-gon contains 180-degree angles. The first line contains integers *n*...
[ "I = lambda: [float(x) for x in input().split()]\r\nn, m = [int(i) for i in input().split()]\r\nV = [I() for _ in range(n)]\r\ncmp = lambda x: (x >= 0) - (x <= 0)\r\n\r\nfor _ in range(m):\r\n x0, y0, x1, y1 = I()\r\n p0, p1 = x1 - x0, y1 - y0\r\n V3 = [((x - x0)*p0 + (y - y0)*p1, (y - y0)*p0 - (x - x0)*p1...
{"inputs": ["4 3\n0 0\n1 0\n1 1\n0 1\n0 0 1 1\n0 0 0 1\n0 0 1 -1", "4 9\n0 0\n0 1\n1 1\n1 0\n0 0 1 1\n1 1 0 0\n0 0 1 0\n0 0 0.5 0\n0 0.5 1 0.5\n0 1 1 1\n1 1 1 0\n0.75 0.75 0.75 0.25\n0 0.25 1 0.75", "9 7\n0 0\n0 2\n1 1\n2 2\n3 1\n4 2\n5 1\n6 2\n6 0\n0 1 6 1\n0 1.5 6 1.5\n0 2 6 1\n0 1 6 2\n0 2 6 2\n0 0 0 2\n0 0 6 0", "1...
UNKNOWN
PYTHON3
CODEFORCES
1
af5f04d22de82fd87cf9bb229eab8480
Coupons and Discounts
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
[ "\r\ninput()\r\np=0\r\nfor x in map(int, input().split()):\r\n p=1<<20 if x<p else p^x&1\r\nprint('NO' if p>0 else 'YES')", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split())) + [0]\r\nc = 0\r\nans = \"YES\"\r\nfor i...
{"inputs": ["4\n1 2 1 2", "3\n1 0 1", "3\n1 3 1", "3\n2 0 2", "1\n179", "10\n0 0 5 9 9 3 0 0 0 10", "3\n3 2 3", "1\n0", "2\n0 0", "10\n0 0 0 0 0 0 0 0 0 0", "1\n1", "1\n2", "1\n3", "1\n10000", "2\n10000 10000", "3\n2 2 2", "10\n3 3 3 2 2 2 2 2 2 3", "100\n2 3 2 3 3 3 3 3 3 2 2 2 2 2 2 3 2 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 ...
UNKNOWN
PYTHON3
CODEFORCES
13
af6fd1f8b47ad4a8cb5edd3e6f27bd47
Big Secret
Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence $a_1, \ldots, a_n$. In order to not reveal the secret earlier than needed, Vitya encrypted the answer and obtained the sequence $b_1, \ldots, b_n$ using the foll...
[ "n=int(input())\r\ns=[[] for i in range(60)]\r\nfor b in list(map(int,input().split())):\r\n\tfor i in range(59,-1,-1):\r\n\t\tif b>>i&1:\r\n\t\t\ts[i].append(b)\r\n\t\t\tbreak\r\nans=[]\r\ncur=0\r\nfor i in range(n):\r\n\tfl=False\r\n\tfor j in range(60):\r\n\t\tif s[j]!=[] and cur>>j&1==0:\r\n\t\t\tans.append(s[j...
{"inputs": ["3\n1 2 3", "6\n4 7 7 12 31 61", "1\n4", "2\n531 108", "5\n3 1 1 7 1", "10\n10 1 1 1 1 1 3 6 7 3", "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 7 7 7 7 15 15 31"], "outputs": ["No", "Yes\n4 12 7 31 7 61 ", "Yes\n4 ", "Yes\n108 531 ", "Yes\n1 3 1 7 1 ", "No", "Yes\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1...
UNKNOWN
PYTHON3
CODEFORCES
1
af76d57665ec0d3906929fd78129da17
Game
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor. The game is played on a square field consisting of *n*<=×<=*n* cells. Initially all cells are empty. On each turn...
[ "n = int(input())\r\nif n%2: print(1)\r\nelse: print(2)", "n = int(input())\r\nprint(1 if n % 2 == 1 else 2)\n# Sun Aug 06 2023 11:19:08 GMT+0300 (Moscow Standard Time)\n", "n = int(input())\nif n % 2 == 0:\n print(2)\nelse:\n print(1)\n# Mon Oct 02 2023 10:20:23 GMT+0300 (Moscow Standard Time)\n", "pri...
{"inputs": ["1", "2", "3", "4", "5", "1000000000000000000", "999999999999999999", "321392715309062180", "95451113283177888", "25496382240130775"], "outputs": ["1", "2", "1", "2", "1", "2", "1", "2", "2", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
14
af8e776ecce3012c92468d9f26c336ae
Polycarp and Div 3
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
[ "# LUOGU_RID: 96253599\nn = input()\r\na = [int(i) for i in n]\r\ntmp = 0\r\ncnt = 0\r\nans = 0\r\nfor i in a:\r\n t = i % 3\r\n tmp = (tmp + t) % 3\r\n cnt += 1\r\n if t == 0 or tmp == 0 or cnt == 3:\r\n ans += 1\r\n cnt = 0\r\n tmp = 0\r\n\r\nprint(ans)", "str = input()\r\npre =...
{"inputs": ["3121", "6", "1000000000000000000000000000000000", "201920181", "4", "10", "11", "12", "13", "31", "14139582796", "1670000", "604500", "40041", "10000170"], "outputs": ["2", "1", "33", "4", "0", "1", "0", "1", "1", "1", "6", "5", "5", "2", "5"]}
UNKNOWN
PYTHON3
CODEFORCES
38
afa852c6849e4803756fa6a798340840
Cifera
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
[ "import math\r\nk=int(input())\r\nl=int(input())\r\nn=0\r\ntmp=k\r\nwhile(l>tmp and l!=tmp):\r\n\ttmp=tmp*k\r\n\tn+=1\r\nif(l==tmp):\r\n\tprint(\"YES\")\r\n\tprint(n)\r\nelse:\r\n\tprint(\"NO\")\r\n", "m=int(input())\r\nn=int(input())\r\nc=0\r\nwhile n!=1:\r\n if n%m!=0:\r\n break\r\n n=n//m\r\n c...
{"inputs": ["5\n25", "3\n8", "123\n123", "99\n970300", "1000\n6666666", "59\n3571", "256\n16777217", "4638\n21511044", "24\n191102976", "52010\n557556453", "61703211\n1750753082", "137\n2571353", "8758\n1746157336", "2\n64", "96\n884736", "1094841453\n1656354409", "1154413\n1229512809", "2442144\n505226241", "11548057\...
UNKNOWN
PYTHON3
CODEFORCES
285
afb4ecc56a557ebea6c5c2cc817dade9
New Year Permutation
User ainta has a permutation *p*1,<=*p*2,<=...,<=*p**n*. As the New Year is coming, he wants to make his permutation as pretty as possible. Permutation *a*1,<=*a*2,<=...,<=*a**n* is prettier than permutation *b*1,<=*b*2,<=...,<=*b**n*, if and only if there exists an integer *k* (1<=≤<=*k*<=≤<=*n*) where *a*1<==<=*b*1,...
[ "from typing import List\n\ndef prettiest_permutation(n :int, arr: List[int], s: List[str]) -> List[int]:\n par=[0]*310\n rank=[0]*310\n def init_union_find(V):#initial state\n for i in range(V):\n par[i]=i\n rank[i]=0\n def find(x):#where the root\n if par[x]==x:\n ...
{"inputs": ["7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000", "5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010", "7\n1 7 6 4 2 3 5\n0000100\n0000010\n0000001\n0000000\n1000000\n0100000\n0010000", "15\n6 1 2 7 9 13 14 8 4 5 3 12 10 15 11\n000100100100100\n000010010010010\n000001001001001...
UNKNOWN
PYTHON3
CODEFORCES
15
afc137fa5a962d684a56715dbca760b3
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines *x*<==<=*a* and *x*<==<=*b* (0<=&lt;<=*a*<=&lt;<=*b*). The west village lies i...
[ "import sys\r\n \r\ndef pro():\r\n\treturn sys.stdin.readline().strip()\r\n \r\ndef rop():\r\n\treturn map(int, pro().split())\r\n \r\ndef main():\r\n\ts = list(rop())\r\n\ta = list(rop())\r\n\tq = list(rop())\r\n\to = list(rop())\r\n\tp = -1\r\n\tt = (1e100, -1, -1)\r\n\tfor i in range(s[1]):\r\n\t\twhile not((p =...
{"inputs": ["3 2 3 5\n-2 -1 4\n-1 2\n7 3", "1 1 10 20\n5\n-5\n1", "2 2 1 2\n-1 10\n8 9\n3 7", "10 20 50 60\n-96 -75 32 37 42 43 44 57 61 65\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94 100\n138 75 132 116 49 43 96 166 96 161 146 112 195 192 201 186 251 254 220 227"], "outputs": ["2 2", "1 1", "1 1", ...
UNKNOWN
PYTHON3
CODEFORCES
2
afce321eed9748e7064a4a220749c8fa
Sea and Islands
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to...
[ "import sys\r\ninput = sys.stdin.readline\r\nread_tuple = lambda _type: map(_type, input().split(' '))\r\n\r\n\r\ndef solve():\r\n n, k = read_tuple(int)\r\n grid = [['S' for _ in range(n)] for _ in range(n)]\r\n flag = True\r\n for i in range(n):\r\n for j in range(n):\r\n if k and fl...
{"inputs": ["5 2", "5 25", "82 6047", "6 5", "10 80", "48 1279", "40 1092", "9 12", "43 146", "100 5000", "100 4999", "100 5001", "99 4901", "99 4900", "99 4902", "99 9801", "99 10", "99 1", "100 10000", "100 10", "50 1200", "50 1438", "50 2447", "49 1719", "51 1996", "51 1981", "34 1060", "74 3901", "65 617", "89 497"...
UNKNOWN
PYTHON3
CODEFORCES
76
afd400a266998a37cdf2ef78c5bccf81
New Year and Counting Cards
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a c...
[ "from sys import stdin, stdout\n\ndef need_to_check(card, vowels=['a','e','i','o','u']):\n return (ord(card) >= ord('0') and ord(card) <= ord('9') and int(card) % 2 == 1) or (card in vowels)\n\ndef number_of_reveals(cards):\n count = 0\n for card in cards:\n count = count+1 if need_to_check(card) el...
{"inputs": ["ee", "z", "0ay1", "0abcdefghijklmnopqrstuvwxyz1234567896", "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "01234567890123456789012345678901234567890123456789", "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "cjw2dwmr10pku4yxohe0wglktd", "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "kaq7jyialrfp4ilkni90e...
UNKNOWN
PYTHON3
CODEFORCES
516
afe46d2a54a9a4ad277b0a9335a8c557
Level Generation
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level. Ivan decided that there should be exactly *n**i* vertices in the graph representing level *i*, and the edges have to be bidirectional. ...
[ "from math import floor, ceil, sqrt\ndef solve(n):\n quad = sqrt(2*n+1/4)-1/2\n x = floor(quad)\n y = ceil(quad)\n a = int(x*(x-1)/2 + n - x)\n b = n - x\n c = n - y\n d = 2*c\n if a > d:\n print(a)\n else:\n print(d)\n return\nn=int(input())\nfor i in range (n):\n sol...
{"inputs": ["3\n3\n4\n6", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "1\n212055293", "1\n508427854", "1\n398561321", "1\n322647200", "1\n827388716", "1\n596007358"], "outputs": ["2\n3\n6", "0\n1\n2\n3\n4\n6\n7\n8\n10\n12", "424069398", "1016791932", "797066176", "645243594", "1654696074", "1191945664"]}
UNKNOWN
PYTHON3
CODEFORCES
6
aff24e43df4b5d490c24e19139f73783
Secret
The Greatest Secret Ever consists of *n* words, indexed by positive integers from 1 to *n*. The secret needs dividing between *k* Keepers (let's index them by positive integers from 1 to *k*), the *i*-th Keeper gets a non-empty set of words with numbers from the set *U**i*<==<=(*u**i*,<=1,<=*u**i*,<=2,<=...,<=*u**i*,<=...
[ "import sys\r\ninput = sys.stdin.readline\r\nn, k = map(int,input().split())\r\nif n//k < 3 :\r\n print(-1)\r\nelse :\r\n ans = []\r\n for i in range(k-1) :\r\n ans.append(i+2)\r\n ans.append(1)\r\n for i in range(n-k) :\r\n ans.append(i%k+1)\r\n print(*ans)", "from collections imp...
{"inputs": ["11 3", "5 2", "2 2", "3 2", "6 2", "1000000 333333", "999999 333334", "9 3", "365561 47560", "950059 292110", "20354 1334", "365561 143151", "119057 33031", "189351 39909", "773849 154607", "950059 419028", "844143 181133", "942846 251898", "13141 3789", "20354 8642", "999999 333333", "18 6", "10 2"], "out...
UNKNOWN
PYTHON3
CODEFORCES
2
aff9b4bab8c8ff94a6fa629c6d9832f9
Appleman and Easy Task
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells...
[ "def solve(n, arr):\r\n for i in range(n):\r\n for j in range(n):\r\n cnt = 0\r\n for x, y in [(-1, 0), (0, 1), (1, 0), (0, -1)]:\r\n ni, nj = x + i, y + j\r\n if ni >= 0 and ni < n and nj >= 0 and nj < n:\r\n if arr[ni][nj] == \"o\":\...
{"inputs": ["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx", "1\no", "2\nox\nxo", "2\nxx\nxo", "3\nooo\noxo\nxoo", "3\nxxx\nxxo\nxxo", "4\nxooo\nooxo\noxoo\nooox", "4\noooo\noxxo\nxoxo\noooo", "5\noxoxo\nxxxxx\noxoxo\nxxxxx\noxoxo", "5\nxxxox\nxxxxo\nxoxox\noxoxx\nxoxxx", "10\nxoxooooooo\noxxoxxxxxo\nxxooxoooxo\noooxxo...
UNKNOWN
PYTHON3
CODEFORCES
235
b01311449213ba97ff7f23f86f7275cb
Magic Trick
Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal dec...
[ "def cal(m,n,i):\r\n tot=1\r\n for j in range(1,n-i+1):\r\n tot=tot*(n*m-m-n+i+j)/(n*m-n+i+j)\r\n for j in range(1,i+1):\r\n tot=tot*(m-i+j)/(n*m-n+j)\r\n for j in range(1,i+1):\r\n tot=tot/j*(n-i+j)\r\n return tot\r\n\r\n\r\nn,m = input().split()\r\nn = int(n)\r\nm = int(m)\r\na...
{"inputs": ["2 2", "4 4", "1 2", "2 1", "10 10", "1000 1000", "1 1", "987 123", "999 999", "1 999", "998 1", "2 987", "555 543", "321 123", "2 3", "461 1000", "678 231"], "outputs": ["0.6666666666666666", "0.4000000000000000", "1.0000000000000000", "0.5000000000000000", "0.1818181818181818", "0.0019980019980020", "1", ...
UNKNOWN
PYTHON3
CODEFORCES
26
b01d89e844d20a28c22cf2f507f6bb34
Bots
Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative and turn based. In each turn, one of the players makes a move (it doesn’t matter which pl...
[ "def f(n, mod=10**9+7):\r\n ans = 1\r\n for i in range(1, n + 1): ans = ans * i % mod\r\n return ans\r\n \r\ndef g(n, mod=10**9+7):\r\n num1 = f(n * 2)\r\n den1 = f(n) ** 2 % mod\r\n return num1 * pow(den1, mod - 2, mod) % mod\r\n \r\nn = int(input()) + 1\r\nprint(g(n) - 1)", "p = 10**9+7\...
{"inputs": ["2", "1", "3", "4", "5", "6", "7", "8", "9", "10", "99", "999", "9999", "99999", "999999", "524287", "131071", "178481", "524288", "1000000"], "outputs": ["19", "5", "69", "251", "923", "3431", "12869", "48619", "184755", "705431", "407336794", "72475737", "703593269", "879467332", "192151599", "295397547",...
UNKNOWN
PYTHON3
CODEFORCES
13
b02df58ebac02db8a5a755d9dc9bc169
none
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr...
[ "word = input()\r\nn = len(word)\r\nbreaks = [False] * n\r\nvowels = set({'a', 'e', 'i', 'o', 'u'})\r\nstreak = 1 if word[0] not in vowels else 0\r\nnumdiff = streak\r\nfor i in range(1, n):\r\n if word[i] not in vowels:\r\n streak += 1\r\n if word[i] != word[i - 1]:\r\n numdiff += 1\r\n...
{"inputs": ["hellno", "abacaba", "asdfasdf", "ooo", "moyaoborona", "jxegxxx", "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz", "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte", "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcfl...
UNKNOWN
PYTHON3
CODEFORCES
87
b03c79ea04736d01575a9c3b6cc57f36
Vlad and Cafes
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes...
[ "n = input()\r\nstol = input()\r\nstol = stol.split(' ')\r\nnums = {}\r\nfor i in range(0,len(stol)):\r\n nums[stol[i]] = [i, len(stol)-i]\r\ndif = []\r\nmax = -1\r\nimax = 0\r\nfl = 0\r\nfor num in nums:\r\n if max<nums[num][1]:\r\n max = nums[num][1]\r\n imax = num\r\nprint(imax)", "from...
{"inputs": ["5\n1 3 2 1 2", "6\n2 1 2 2 4 1", "1\n0", "1\n200000", "2\n2018 2017", "5\n100 1000 1000 1000 1000", "8\n200000 1 200000 1 200000 1 200000 2", "5\n20000 1 2 3 4", "2\n200000 1", "3\n2 100 2", "2\n10 1", "11\n1 1 1 1 1 1 1 1 1 1 1", "3\n5 5 5", "2\n5 1"], "outputs": ["3", "2", "0", "200000", "2018", "100", "...
UNKNOWN
PYTHON3
CODEFORCES
215
b076fa79c40c941c6131eeb39a5cd55c
Password Check
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
[ "import string\r\n\r\n\r\ndef selection_sort(l):\r\n for i in range(len(l)):\r\n min_val = l[i]\r\n min_val_index = i\r\n for j in range(i, len(l)):\r\n if l[j] < min_val:\r\n min_val = l[j]\r\n min_val_index = j\r\n l[i], l[min_val_index] = l[...
{"inputs": ["abacaba", "X12345", "CONTEST_is_STARTED!!11", "1zA__", "1zA_", "zA___", "1A___", "z1___", "0", "_", "a", "D", "_", "?", "?", "._,.!.,...?_,!.", "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.", "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!", "XZX", "R", "...
UNKNOWN
PYTHON3
CODEFORCES
269
b0812b4eedab563aed52cf35f6846cfd
MUH and Cube Walls
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of di...
[ "def diff(s) : return [s[i] - s[i - 1] for i in range(1, len(s))]\nn, m = map(int, input().split())\nif m > n : print(0) ; exit(0)\nif m == 1 : print(n) ; exit(0)\nt = diff(list(map(int, input().split())))\np = diff(list(map(int, input().split())))\nw = p + [10 ** 9] + t\nres = 0\npi = [0] * len(w)\nfor i in range ...
{"inputs": ["13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2", "5 1\n8 71 1 24 2\n31", "6 3\n2 2 2 2 2 2\n5 5 5", "1 1\n576560149\n691846236", "10 5\n5 10 8 10 11 9 11 12 10 15\n4 2 4 5 3", "10 10\n6 8 1 2 5 1 4 24 2 4\n6 8 1 2 5 1 4 24 2 4", "10 10\n6 8 1 2 5 1 14 24 12 4\n7 9 2 3 6 2 15 25 13 5", "8 4\n1 2 3 4 5 6 7 8\n10...
UNKNOWN
PYTHON3
CODEFORCES
27
b08dbd26974567078cb495691437a90d
Fox And Two Dots
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this: Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors. The key of this game is to find a cycle that contain dots...
[ "import sys, threading\r\n\r\ndef main():\r\n n , m = map(int, input().split())\r\n\r\n board = []\r\n for _ in range(n):\r\n board.append(input())\r\n\r\n\r\n visited = {}\r\n directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]\r\n\r\n def inbound(row, col):\r\n return 0 <= row < len(bo...
{"inputs": ["3 4\nAAAA\nABCA\nAAAA", "3 4\nAAAA\nABCA\nAADA", "4 4\nYYYR\nBYBY\nBBBY\nBBBY", "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB", "2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ", "2 2\nAA\nAA", "2 2\nAA\nAB", "3 3\nAAA\nABA\nAAA", "3 3\nAAA\nABA\nABA", "10 10\nEGFJGJKGEI\nAKJHBGHIHF\nJBABBCFGEJ\nCJDJHJJK...
UNKNOWN
PYTHON3
CODEFORCES
29
b0b0128b58e825ce948d38812c7c807b
Magic Box
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0,<=0,<=0), and the opposite one is at point (*x*1...
[ "x,y,z = list(map(int,input().strip().split()))\r\n\r\nxb,yb,zb = list(map(int,input().strip().split()))\r\n\r\nlabels = list(map(int,input().strip().split()))\r\n\r\nsm = 0\r\n\r\nsm += labels[0] * (y < 0) + labels[1] * (y > yb)\r\nsm += labels[2] * (z < 0) + labels[3] * (z > zb)\r\nsm += labels[4] * (x < 0)...
{"inputs": ["2 2 2\n1 1 1\n1 2 3 4 5 6", "0 0 10\n3 2 3\n1 2 3 4 5 6", "0 1 2\n1 1 1\n634728 627299 454463 927148 298618 186257", "5 2 -4\n1 1 1\n279519 704273 181008 670653 198973 996401", "5 5 0\n3 1 3\n832224 636838 995053 211585 505442 341920", "-1 -9 14\n9 8 10\n172575 215800 344296 98651 566390 47011", "95892 794...
UNKNOWN
PYTHON3
CODEFORCES
2
b0bb2cceffae753ad0c44398af1d35b6
Tree Folding
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*0<==<=*v*, *a*1, ..., *a**k*, and *b*0<==<=*v*, *b*1, ..., *b**k*. Additionally, vertices *a*1, ..., *a**k*, *b*1, ..., *b**k* must not have any neighbou...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nG = [set() for _ in range(n + 1)]\r\nfor _ in range(n - 1):\r\n u, v = map(int, input().split())\r\n G[u].add(v)\r\n G[v].add(u)\r\nq = []\r\nx = [set() for _ in range(n + 1)]\r\ncnt = [len(g) for...
{"inputs": ["6\n1 2\n2 3\n2 4\n4 5\n1 6", "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7", "2\n1 2", "3\n3 1\n1 2", "10\n5 10\n7 8\n8 3\n2 6\n3 2\n9 7\n4 5\n10 1\n6 4", "11\n11 9\n6 7\n7 1\n8 11\n5 6\n3 5\n9 3\n10 8\n2 4\n4 10", "10\n4 2\n7 4\n2 6\n2 5\n4 8\n10 3\n2 9\n9 1\n5 10", "11\n8 9\n2 7\n1 11\n3 2\n9 1\n8 5\n8 6\n5 4\n4 10\n...
UNKNOWN
PYTHON3
CODEFORCES
1
b0cebf1428f9b491c8ffc03cbc5489db
New Year and Arbitrary Arrangement
You are given three integers *k*, *p**a* and *p**b*. You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability *p**a*<=/<=(*p**a*<=+<=*p**b*), add 'a' to the end of the sequence. Otherwise (with probability *p**b*<=/<=(*p**...
[ "import sys\r\n#input=sys.stdin.readline\r\ndp={}\r\nmod=int(1000000007)\r\nsys.setrecursionlimit(100000)\r\ndef bigmod(n,p):\r\n p=int(p)\r\n if p==0:\r\n return 1\r\n x=bigmod(n,p/2)\r\n x=(x*x)%mod\r\n if p%2==1:\r\n x=(x*n)%mod\r\n return x\r\nk,pa,pb=map(int,input().split())\r\...
{"inputs": ["1 1 1", "3 1 4", "1000 123456 654321", "305 337309 378395", "108 531040 908573", "575 39377 68346", "66 199449 266025", "781 817338 452871", "99 534023 117289", "156 78149 46740", "57 339480 774350", "270 967166 795005", "628 446579 365440", "97 119368 2062", "757 869978 224540", "892 777143 664073", "177 ...
UNKNOWN
PYTHON3
CODEFORCES
10
b103e357a8b3fc76da8f96346971ffdc
none
На тренировку по подготовке к соревнованиям по программированию пришли *n* команд. Тренер для каждой команды подобрал тренировку, комплект задач для *i*-й команды занимает *a**i* страниц. В распоряжении тренера есть *x* листов бумаги, у которых обе стороны чистые, и *y* листов, у которых только одна сторона чистая. При...
[ "n,x,y = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nx *= 2\r\nfor i in range(n):\r\n kol = x+y\r\n# print(x,y,kol,a[i])\r\n if kol>=a[i]:\r\n if a[i]%2!=0:\r\n if y>0:\r\n y-=1\r\n a[i]-=1\r\n else:\r\n ...
{"inputs": ["2 3 5\n4 6", "2 3 5\n4 7", "6 3 5\n12 11 12 11 12 11", "1 4 3\n12", "10 1 17\n3 1 1 2 1 3 4 4 1 4", "3 6 3\n2 5 9", "7 26 8\n5 11 8 10 12 12 3", "11 5 85\n19 20 6 7 6 2 1 5 8 15 6", "7 7 2\n5 2 4 2 4 1 1", "8 5 10\n1 7 2 5 2 1 6 5", "10 27 34\n11 8 11 5 14 1 12 10 12 6", "4 2 2\n1 2 3 1", "5 1 45\n7 14 15 ...
UNKNOWN
PYTHON3
CODEFORCES
6
b1100d048e7ba28e17212b983fbf3967
Optimal Number Permutation
You have array *a* that contains all integers from 1 to *n* twice. You can arbitrary permute any numbers in *a*. Let number *i* be in positions *x**i*,<=*y**i* (*x**i*<=&lt;<=*y**i*) in the permuted array *a*. Let's define the value *d**i*<==<=*y**i*<=-<=*x**i* — the distance between the positions of the number *i*. P...
[ "n = int(input())\nans = [n] * (2 * n)\nfor i in range(1, n + 1):\n x = i // 2 if i & 1 else n - 1 + i // 2\n y = x + n - i\n ans[x], ans[y] = i, i\nprint(*ans)\n", "N = int( input() )\r\nans = [ N for i in range( 2 * N ) ]\r\nfor i in range( 1, N + 1 ):\r\n x = i // 2 if i & 1 else N - 1 + i // 2\r\n ...
{"inputs": ["2", "1", "3", "4", "10", "100", "1232", "1233", "100000", "499998", "499999", "500000", "45464", "44444", "1134", "1234"], "outputs": ["1 1 2 2", "1 1", "1 3 1 2 2 3", "1 3 3 1 2 4 2 4", "1 3 5 7 9 9 7 5 3 1 2 4 6 8 10 8 6 4 2 10", "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 5...
UNKNOWN
PYTHON3
CODEFORCES
14
b11ca1b50948f0baad8c094d14768791
Arrival of the General
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their...
[ "n = int(input())\r\nlst = list(map(int,input().split()))\r\na=0\r\nb=100\r\nmax_ind=0\r\nmin_ind=0\r\n\r\nfor i in range(n):\r\n if lst[i]>a:\r\n a=lst[i]\r\n max_ind = i\r\n if lst[i]<=b:\r\n b = lst[i]\r\n min_ind = i\r\nif max_ind<min_ind:\r\n print(max_ind+(n-min_ind)-1)\r\...
{"inputs": ["4\n33 44 11 22", "7\n10 10 58 31 63 40 76", "2\n88 89", "5\n100 95 100 100 88", "7\n48 48 48 48 45 45 45", "10\n68 47 67 29 63 71 71 65 54 56", "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "3\n1 2 1", "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "35\n37 41 46 39 47 39 44 47 44 ...
UNKNOWN
PYTHON3
CODEFORCES
399
b12bd65b3396aa552b938e40b123297a
Lust
A false witness that speaketh lies! You are given a sequence containing *n* integers. There is a variable *res* that is equal to 0 initially. The following process repeats *k* times. Choose an index from 1 to *n* uniformly at random. Name it *x*. Add to *res* the multiply of all *a**i*'s such that 1<=≤<=*i*<=≤<=*n*, ...
[ "mod=1000000007\r\ndef powmod(a, b, mod):\r\n res = 1\r\n a %= mod\r\n assert b >= 0\r\n while b:\r\n if b & 1:\r\n res = res * a % mod\r\n a = a * a % mod\r\n b >>= 1\r\n return res\r\nN = 10100\r\nn, k = map(int, input().split())\r\npoly = [0] * N\r\nq = [0] * N\r\nr...
{"inputs": ["2 1\n5 5", "1 10\n80", "2 2\n0 0", "9 4\n0 11 12 9 20 7 8 18 2", "5 1\n14 2 0 0 1", "2 4\n0 16", "7 2\n0 9 4 0 7 14 4", "10 3\n12 15 19 16 19 0 4 3 5 11", "3 3\n18 7 17", "8 3\n20 15 1 4 20 16 6 12", "7 405871919\n4 4 12 5 7 10 10", "2 753394402\n3 15", "2 34825250\n10 12", "5 585751779\n18 17 6 12 11", "7...
UNKNOWN
PYTHON3
CODEFORCES
1
b13c3679b0567a34b479291087a98757
Suitable Replacement
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters. Suitability of string *s* is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all...
[ "def solve(mid):\r\n tmp = 0\r\n for i in cnt_t:\r\n if cnt_t[i] * mid <= cnt_s[i]:\r\n pass\r\n else:\r\n tmp += cnt_t[i] * mid - cnt_s[i]\r\n return tmp <= cnt_s[\"?\"]\r\n\r\ndef solve2(mid):\r\n tmp = deque([])\r\n for i in cnt_t:\r\n if cnt_t[i] * mid <...
{"inputs": ["?aa?\nab", "??b?\nza", "abcd\nabacaba", "mqwstphetbfrsyxuzdww\nrutseqtsbh", "????????????????????\nxwkxsxlrre", "fzjqgrgzzzghrwgwhfjq\nggwfrjzzqh", "ng?\nvu", "???\nb", "??a?\na", "c?aa???a?cdcc??\nabcadbaccb", "cc?cdb?????b?cc?b?\ncabdacd", "ccaaa?bc?baccbccccbca?cccab??aacccbaac?bccacc?accccaccbcbbcbc\nc...
UNKNOWN
PYTHON3
CODEFORCES
18
b15447fdee4f739dae59e58f8f36f1ae
Mahmoud and a Message
Mahmoud wrote a message *s* of length *n*. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number *i* in the English...
[ "n = int(input())\r\nans = 0\r\ns = input()\r\nmod = 1000000007\r\nnums = [int(x) for x in input().split()]\r\ndp1 = [0]*1002\r\ndp2 = [0]*1002\r\ndp1[0]=1\r\nfor i in range(1,n+1):\r\n curr = 0\r\n dp2[i]=n\r\n for j in range(i-1,-1,-1):\r\n curr= max(curr,i-nums[ord(s[j])-ord(\"a\")])\r\n i...
{"inputs": ["3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\naaaaaaaaaa\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "55\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1000 1000 1000 1000 1000 1000 1000 1000 1...
UNKNOWN
PYTHON3
CODEFORCES
6
b1636b10d82c8f683a812bbdcddcadef
Dynamic Problem Scoring
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends...
[ "def f(v, x, n):\n\tif v<0:\n\t\treturn 0\n\tfor i in range(1, 7):\n\t\tif x<<i>n or i==6:\n\t\t\treturn (250-v)*i<<1\n\nn=int(input())\na=[list(map(int, input().split())) for _ in range(n)]\nc=[sum(_[i]>=0 for _ in a) for i in range(5)]\nans=-1\nfor i in range(10000):\n\tp, q=0, 0\n\tfor j in range(5):\n\t\tif a[0...
{"inputs": ["2\n5 15 40 70 115\n50 45 40 30 15", "3\n55 80 10 -1 -1\n15 -1 79 60 -1\n42 -1 13 -1 -1", "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62", "4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1", "2\n33 15 51 7 101\n41 80 40 13 46", "9\n57 52 60 56 91\n32...
UNKNOWN
PYTHON3
CODEFORCES
7
b17e773c2574469d872c482f71085b89
Greedy Arkady
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ...
[ "s=list(map(int,input().split()))\r\nn=s[0]\r\nk=s[1]\r\nM=s[2]\r\nD=s[3]\r\nans=0\r\nfor d in range(0,D+1):\r\n x=n//((d-1)*k+1)\r\n if x>M:\r\n x=M\r\n if x*d>ans:\r\n ans=x*d\r\nprint(ans)\r\n", "n, k, m, d = map(int, input().split())\r\nans = int(0)\r\nfor i in range(1, d + 1):\r\n l...
{"inputs": ["20 4 5 2", "30 9 4 1", "2 2 1 1", "42 20 5 29", "1000000000000000000 135 1000000000000000 1000", "100 33 100 100", "1000000000 1000000000 1000000000 1000", "1000000000 32428 1000000000 1000", "1000000000 324934 1000 1000", "1000000000000000000 32400093004 10000000 1000", "885 2 160 842", "216 137 202 208",...
UNKNOWN
PYTHON3
CODEFORCES
105
b189968890f87cf088faa76aca366947
The Child and Zoo
Of course our child likes walking in a zoo. The zoo has *n* areas, that are numbered from 1 to *n*. The *i*-th area contains *a**i* animals in it. Also there are *m* roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area usin...
[ "read = lambda: map(int, input().split())\r\nn, m = read()\r\nv = list(read())\r\n\r\ne = []\r\nfor i in range(m):\r\n x, y = map(lambda x: int(x) - 1, input().split())\r\n e.append((x, y, min(v[x], v[y])))\r\ne.sort(key = lambda x: x[2], reverse = True)\r\n\r\nbelong = list(range(n))\r\nunion = [[i] for i in...
{"inputs": ["4 3\n10 20 30 40\n1 3\n2 3\n4 3", "3 3\n10 20 30\n1 2\n2 3\n3 1", "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7", "10 14\n594 965 90 327 549 206 514 993 803 635\n1 2\n1 3\n3 4\n2 5\n5 6\n5 7\n4 8\n4 9\n5 10\n10 4\n7 8\n2 6\n6 4\n5 4", "10 19\n15704 19758 26631 25050 22778 15041 8487 26...
UNKNOWN
PYTHON3
CODEFORCES
5
b1a7683f8f490dfff73965d4604a89df
Lawnmower
You have a garden consisting entirely of grass and weeds. Your garden is described by an *n*<=×<=*m* grid, with rows numbered 1 to *n* from top to bottom, and columns 1 to *m* from left to right. Each cell is identified by a pair (*r*,<=*c*) which means that the cell is located at row *r* and column *c*. Each cell may ...
[ "n, m = map(int, input().split())\r\nans = 0\r\nx, y = 0, 0\r\n\r\nfor i in range(n):\r\n a = input()\r\n d = 1 - i % 2 * 2\r\n\r\n j = (m-1) * (i % 2)\r\n while j >= 0 and j < m:\r\n if a[j] == 'G':\r\n t =0\r\n j += d\r\n else:\r\n ans += abs(x - i) + abs...
{"inputs": ["4 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG", "3 3\nGWW\nWWW\nWWG", "1 1\nG", "4 3\nGWW\nWWW\nWWW\nWWG", "6 5\nGWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW", "3 5\nGGWWW\nWWWWW\nWWWGG", "20 1\nG\nG\nW\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nW\nG\nW\nG\nG", "2 2\nGG\nGW", "1 20\nGGGGWGGGGWWWWGGGWGGG", "3 112\nGGWGGWWGGGWWGWWG...
UNKNOWN
PYTHON3
CODEFORCES
4
b1fa9f7905495c93b5d17875a9e6c3ae
none
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings *s* and *t* have the same length *n*, then the function *h*(*s*,<=*t*) is defined as the number of posi...
[ "MOD = 10**9 + 7\r\nn = int(input())\r\nS = input()\r\ncnt = [S.count('A'), S.count('C'), S.count('G'), S.count('T')]\r\nmax_val = max(cnt)\r\nop = cnt.count(max_val)\r\nprint((op**n)%MOD )\r\n", "length, dna = int(input()), input()\r\nnums = [dna.count('A'), dna.count('C'), dna.count('G'), dna.count('T')]\r\npri...
{"inputs": ["1\nC", "2\nAG", "3\nTTT", "4\nGACT", "1\nT", "2\nAG", "3\nGCA", "5\nACGTC", "15\nAGCGAATCCCATTGT", "20\nTAAGCGACCAGGTGCTTTAC", "30\nCCTTTCGGGGCGCGTTGGCCTTTGTCCTGC", "318\nTATCAATCGGTACGTGCGCATCATTGTCAATCGGGCTTCATGGCTTGCGGGCGCTACCCGAGGGGAAGCTGCGGACAGGTAGGTAAGATACACACGAACCAAACGGAGTTATGTTGGATAAATTGGCTGGAAGGGC...
UNKNOWN
PYTHON3
CODEFORCES
17
b20e641c8f6083e0d376e4b8234b8dc1
Colorful Stones (Simplified Edition)
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
[ "#A. Colorful Stones\r\n\r\nfrom tkinter import S\r\n\r\n\r\ns = input()\r\nt = input()\r\ni = 0\r\nj = 0\r\ncounter = 1\r\n\r\nwhile j < len(t):\r\n if s[i] != t[j]:\r\n j += 1\r\n elif s[i] == t[j]:\r\n i += 1\r\n j += 1\r\n counter += 1\r\n\r\nprint(counter)", "input1=list(inp...
{"inputs": ["RGB\nRRR", "RRRBGBRBBB\nBBBRR", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "G\nRRBBRBRRBR", "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB", "RRGGBRGRBG\nBRRGGBBGGR", "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG", "GBRRBGBGBBBB...
UNKNOWN
PYTHON3
CODEFORCES
1,032
b21a9aed6384dfd606028423fd6a57da
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=&gt;<=1 the respective term satisfi...
[ "def main():\r\n b1, q, l, m = map(int, input().split())\r\n a = set(map(int, input().split()))\r\n\r\n if b1 == 0:\r\n if 0 in a:\r\n return 0\r\n else:\r\n return 'inf'\r\n\r\n if q == 0:\r\n if abs(b1) > l:\r\n return 0\r\n\r\n if b1 in a:\...
{"inputs": ["3 2 30 4\n6 14 25 48", "123 1 2143435 4\n123 11 -5453 141245", "123 1 2143435 4\n54343 -13 6 124", "3 2 25 2\n379195692 -69874783", "3 2 30 3\n-691070108 -934106649 -220744807", "3 3 104 17\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -2...
UNKNOWN
PYTHON3
CODEFORCES
14
b2209d817d16f79a9c5da14d63e189c4
Memory Manager
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: ...
[ "from sys import stdin, stdout\r\n\r\nclass Block:\r\n def __init__(self, id, offset, size):\r\n self.id = id\r\n self.offset = offset\r\n self.size = size\r\n\r\n def __str__(self):\r\n return \"{0} {1} {2}\".format(self.id, self.offset, self.size)\r\n\r\n\r\nclass MemoryManager:\...
{"inputs": ["6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6", "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1", "14 100\nalloc 99\nalloc 1\nalloc 1\nerase 2\nalloc 1\nerase 4\nerase 1\nalloc 100\nalloc 1\nalloc 99\ndefragment\nerase 4\nalloc 100\nalloc 99", "26 25\ndefragment\nerase 1\ner...
UNKNOWN
PYTHON3
CODEFORCES
14
b23d4e1c4186e101d28a0d2f197f29d7
Plate Game
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located with...
[ "A = list(map(int,input().split()))\r\na = A[0];b = A[1];r = A[2]\r\nif 2*r <= min(a,b):\r\n\tprint('First')\r\nelse:\r\n\tprint('Second')", "a, b, c = map(int, input().split())\r\nif a < c * 2 or b < c * 2:\r\n print(\"Second\")\r\nelse :\r\n print(\"First\")", "# https://codeforces.com/problemset/proble...
{"inputs": ["5 5 2", "6 7 4", "100 100 1", "1 1 100", "13 7 3", "23 7 3", "9 9 2", "13 13 2", "21 21 10", "20 21 10", "20 20 10", "9 13 2", "19 7 3", "19 19 10", "19 20 10", "19 21 10", "1 100 1", "2 100 1", "3 100 1", "100 100 49", "100 100 50", "100 100 51", "100 99 50", "4 10 5", "8 11 2", "3 12 5", "14 15 5", "61 2...
UNKNOWN
PYTHON3
CODEFORCES
98
b26cb8af6d3796ecce005a0e74a69acd
Help Vasilisa the Wise 2
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
[ "row1 , row2 = map(int,input().split())\r\ncol1 , col2 = map(int,input().split())\r\ndia1 , dia2 = map(int,input().split())\r\nmessage=1\r\nb1 , b2 = 0,0\r\nb3 , b4 = 0,0\r\nfor a in range(1,10):\r\n b1 = a\r\n for b in range(1,10):\r\n b2 = b\r\n for c in range(1,10):\r\n b3 = c\r\n ...
{"inputs": ["3 7\n4 6\n5 5", "11 10\n13 8\n5 16", "1 2\n3 4\n5 6", "10 10\n10 10\n10 10", "5 13\n8 10\n11 7", "12 17\n10 19\n13 16", "11 11\n17 5\n12 10", "12 11\n11 12\n16 7", "5 9\n7 7\n8 6", "10 7\n4 13\n11 6", "18 10\n16 12\n12 16", "13 6\n10 9\n6 13", "14 16\n16 14\n18 12", "16 10\n16 10\n12 14", "11 9\n12 8\n11 9...
UNKNOWN
PYTHON3
CODEFORCES
155
b27355b98f1c7abb80f3cf7c1f7f8bcf
Fafa and the Gates
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first quadrant of a plane and the wall is built along the identity line (...
[ "# =========== IMPORTS ============#\r\n\r\n\r\n# =========== GLOBAL =============#\r\n\r\n\r\n# =========== FUNCTIONS ========= #\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n s = input()\r\n state = None # 'N' at the North kingdom - 'S' at the south kingdom\r\n pos = [0, 0]\r\n co...
{"inputs": ["1\nU", "6\nRURUUR", "7\nURRRUUU", "100\nRUURUURRUURUUUUURRUUURRRRUURRURRURRRRUUUUUURRUURRRRURUUURUURURRRRRURUURRUURUURRUUURUUUUUURRUUUURUUUR", "7\nURURRUR", "15\nRUURRRRURRUUUUU", "6\nUURRRU", "7\nRRRRRRR", "2\nUR", "2\nUU"], "outputs": ["0", "1", "2", "3", "1", "3", "1", "0", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
64
b29987a03c17f317e1680bc7d76d8422
Vasya and String
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original strin...
[ "import sys\r\nfrom collections import defaultdict as dd\r\nfrom collections import deque\r\nfrom fractions import Fraction as f\r\nfrom copy import *\r\nfrom bisect import *\t\r\nfrom heapq import *\r\n#from math import *\r\nfrom itertools import permutations \r\n \r\ndef eprint(*args):\r\n print(*args, file=sy...
{"inputs": ["4 2\nabba", "8 1\naabaabaa", "1 0\na", "1 1\nb", "1 0\nb", "1 1\na", "10 10\nbbbbbbbbbb", "10 2\nbbbbbbbbbb", "10 1\nbbabbabbba", "10 10\nbbabbbaabb", "10 9\nbabababbba", "10 4\nbababbaaab", "10 10\naabaaabaaa", "10 10\naaaabbbaaa", "10 1\nbaaaaaaaab", "10 5\naaaaabaaaa", "10 4\naaaaaaaaaa", "100 10\nbbbbb...
UNKNOWN
PYTHON3
CODEFORCES
233
b2f5fba9b8e97e6890c933cd1dac3363
Intense Heat
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal...
[ "from sys import stdin,stdout\r\nn,k = map(int,stdin.readline().split())\r\n\r\n#Nhap du lieu\r\na = list(map(int,stdin.readline().split()))\r\npref = [0]*(n+5)\r\npref[0] = a[0];\r\nfor i in range(1,n):\r\n\tpref[i] = pref[i-1] + a[i]\r\n#pref[i] la tong cua day a[1 -> i]\r\n#Xu li\r\n#Xet tat ca cac day a[i -> j]...
{"inputs": ["4 3\n3 4 1 2", "5 1\n3 10 9 10 6", "5 2\n7 3 3 1 8", "5 3\n1 7 6 9 1", "5 4\n5 1 10 6 1", "5 5\n4 6 6 6 2", "3 2\n2 1 2", "1 1\n5000"], "outputs": ["2.666666666666667", "10.000000000000000", "5.000000000000000", "7.333333333333333", "5.500000000000000", "4.800000000000000", "1.666666666666667", "5000.00000...
UNKNOWN
PYTHON3
CODEFORCES
53
b2fd1c4297cbc9c1b1dd2d009ad3ee81
K-special Tables
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\nd = [[0]*n for _ in range(n)]\r\n\r\nx = (k-1)*n + 1\r\nc = 1\r\nif k > 1:\r\n for i in range(n):\r\n for j in range(k-1):\r\n d[i][j] = c\r\n c += 1\r\nfor i in range(n):\r\n for j in range(k-1, ...
{"inputs": ["4 1", "5 3", "1 1", "2 1", "2 2", "500 1", "3 1", "3 2", "3 3", "4 2", "4 3", "4 4", "5 1", "5 2", "5 4", "5 5", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "500 500", "500 250", "94 3", "22 4", "15 12", "37 35", "87 51", "15 4", "183 2", "103 6", "131 11", "193 186", "117 109", "116 91", "140 79", "350 14",...
UNKNOWN
PYTHON3
CODEFORCES
68
b2fe3a302ea58f97079a3b77af2a8fc5
Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
[ "import sys\r\n\r\ndef check(text):\r\n legal = 'AHIMOTUVWXY'\r\n for i in text:\r\n if i not in legal:\r\n return False\r\n rev = list(text)\r\n rev.reverse()\r\n if text != ''.join(rev):\r\n return False\r\n return True\r\n\r\nif __name__ == '__main__':\r\n text = sys...
{"inputs": ["AHA", "Z", "XO", "AAA", "AHHA", "BAB", "OMMMAAMMMO", "YYHUIUGYI", "TT", "UUU", "WYYW", "MITIM", "VO", "WWS", "VIYMAXXAVM", "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM", "CC", "QOQ", "AEEA", "OQQQO", "HNCMEEMCNH", "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEW...
UNKNOWN
PYTHON3
CODEFORCES
156
b30741b23947b318b5d31bcc60129d38
Erasing Substrings
You are given a string *s*, initially consisting of *n* lowercase Latin letters. After that, you perform *k* operations with it, where . During *i*-th operation you must erase some substring of length exactly 2*i*<=-<=1 from *s*. Print the lexicographically minimal string you may obtain after performing *k* such opera...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ns = list(input().rstrip())\r\nn = len(s)\r\npow2 = [1]\r\nfor _ in range(14):\r\n pow2.append(2 * pow2[-1])\r\nk = 0\r\nwhile pow2[k + 1] <= n:\r\n k += 1\r\nm = pow2[k]\r\npow2 = pow2[:k]\r\nl = n - m + 1\r\nx = [[] fo...
{"inputs": ["adcbca", "abacabadabacaba", "a", "b"], "outputs": ["aba", "aabacaba", "a", "b"]}
UNKNOWN
PYTHON3
CODEFORCES
1
b3188abe3b8beeaaa413f315936812bc
Slightly Decreasing Permutations
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The ...
[ "a, b = map(int, input().split())\r\nm = []\r\nj = 0\r\nfor i in range(a, 1, -1):\r\n if j != b:\r\n m.append(i)\r\n j += 1\r\n if j == b:\r\n break\r\nprint(*m, end = ' ')\r\nv = []\r\nfor i in range(1, a-b+1):\r\n v.append(i)\r\nprint(*v)\r\n", "(n, k) = map(int, input().split(' ')...
{"inputs": ["5 2", "3 0", "3 2", "1 0", "2 0", "2 1", "10 4", "56893 5084", "6 3", "1 0", "310 186", "726 450", "438 418", "854 829", "214 167", "85705 56268", "11417 4583", "53481 20593", "79193 77281", "42607 42144", "100000 0", "100000 99999", "100000 53860", "4 0", "4 1", "4 2", "4 3", "3 1"], "outputs": ["1 5 2 4 ...
UNKNOWN
PYTHON3
CODEFORCES
207
b3754923cc8c78966e744fe77b658aa0
Jeff and Removing Periods
Cosider a sequence, consisting of *n* integers: *a*1, *a*2, ..., *a**n*. Jeff can perform the following operation on sequence *a*: - take three integers *v*, *t*, *k* (1<=≤<=*v*,<=*t*<=≤<=*n*; 0<=≤<=*k*; *v*<=+<=*tk*<=≤<=*n*), such that *a**v* = *a**v*<=+<=*t*, *a**v*<=+<=*t* = *a**v*<=+<=2*t*, ..., *a**v*<=+<=*t*(*k...
[ "# ====== author: kuanc (www.hank.fyi) | created: 04/15/23 01:14:36 CST ====== #\r\nfrom sys import stdin, stderr, stdout, setrecursionlimit\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import defaultdict, deque, Counter\r\nfrom itertools import accumulate, combina...
{"inputs": ["5\n2 2 1 1 2\n5\n1 5\n1 1\n2 2\n1 3\n2 3", "10\n2 1 3 3 3 3 1 3 1 1\n10\n4 8\n2 10\n1 10\n4 4\n1 3\n2 4\n6 7\n1 9\n2 5\n1 1", "15\n3 3 2 2 1 2 4 1 3 1 1 3 1 4 1\n15\n4 10\n8 9\n12 12\n7 9\n11 12\n1 1\n4 10\n12 13\n2 2\n3 5\n5 6\n1 1\n2 3\n2 4\n7 14", "20\n3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1 2 3 1\n20\n13 17\...
UNKNOWN
PYTHON3
CODEFORCES
1
b38f225bf9f5e181525a2b18b9c782a3
Clique in the Divisibility Graph
As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively. Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are conn...
[ "n = int(input()) \r\nbase = list(map(int, input().split())) \r\nstock = [0 for k in range(int(1e6+1))]\r\nfor zbi in base : \r\n stock[zbi] = 1 \r\nt = base[-1] \r\nfor k in range(2,n+1) : \r\n num = base[n-k]\r\n for i in range(2, (t//num)+1) : \r\n if stock[i*num] >= 1 : \r\n stock[nu...
{"inputs": ["8\n3 4 6 8 10 18 21 24", "5\n2 3 4 8 16", "2\n10 20", "2\n10 21", "5\n250000 333333 500000 666666 1000000", "50\n1 2 5 7 9 14 19 24 25 29 31 34 37 40 43 44 46 53 54 57 58 59 60 61 62 64 66 68 69 70 72 75 78 79 80 81 82 84 85 86 87 88 89 90 91 92 93 94 96 98", "20\n1 2 4 8 16 32 64 128 256 512 1024 2048 409...
UNKNOWN
PYTHON3
CODEFORCES
12
b3b6ae12716c1573c491359fc2544ce2
Love Rescue
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long. This story c...
[ "from collections import defaultdict\r\n\r\n\r\nn=int(input())\r\ns1=input().strip()\r\ns2=input().strip()\r\ng=defaultdict(list)\r\ntq=[]\r\nfor i in range(n):\r\n ord1=ord(s1[i])-ord(\"a\")\r\n ord2=ord(s2[i])-ord(\"a\")\r\n g[ord1].append(ord2)\r\n tq.append(ord1)\r\n g[ord2].append(ord1)\r\n\r\...
{"inputs": ["3\nabb\ndad", "8\ndrpepper\ncocacola", "1\nh\np", "2\nxc\nda", "3\nbab\naab", "15\nxrezbaoiksvhuww\ndcgcjrkafntbpbl", "3\nbaa\nbba", "10\ndaefcecfae\nccdaceefca", "10\nfdfbffedbc\ncfcdddfbed", "100\nbltlukvrharrgytdxnbjailgafwdmeowqvwwsadryzquqzvfhjnpkwvgpwvohvjwzafcxqmisgyyuidvvjqljqshflzywmcccksk\njmgilz...
UNKNOWN
PYTHON3
CODEFORCES
36
b3c73f74dc012f6f249628bcecbe8894
Strange Radiation
*n* people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all peop...
[ "import sys\r\nimport math\r\n\r\ndef main():\r\n n, si = map(int, input().split())\r\n s = float(si)\r\n x = []\r\n v = []\r\n dir = []\r\n ev = []\r\n\r\n EPS = 1e-8\r\n\r\n for _ in range(n):\r\n xi, vi, d = map(int, input().split())\r\n x.append(xi)\r\n v.append(vi)\...
{"inputs": ["2 999\n400000 1 2\n500000 1 1", "2 1000\n400000 500 1\n600000 500 2", "2 99999\n500 1 1\n499 10000 2", "26 10\n495492 7 1\n256604 5 2\n511773 3 2\n590712 4 1\n206826 7 2\n817878 4 2\n843915 1 1\n349160 3 1\n351298 4 1\n782251 8 2\n910928 4 1\n662354 4 2\n468621 2 2\n466991 7 2\n787303 6 2\n221623 8 2\n3435...
UNKNOWN
PYTHON3
CODEFORCES
2
b3e02bf738ea0166342afd572bed02f8
Plus and xor
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions ...
[ "a = int(input())\r\nb = int(input())\r\nif a < b or ((a & 1) != (b & 1)):\r\n print(-1)\r\nelse:\r\n print((a - b) // 2, (a + b) // 2)", "a = int(input())\nb = int(input())\n\nx = (a - b) // 2\ny = a - x\nif x ^ y == b:\n print(x, y)\nelse:\n print(-1)\n", "import math\r\nfrom collections import de...
{"inputs": ["142\n76", "638\n126", "1639\n1176", "12608\n0", "104066\n104066", "1024996\n990106", "1215996781\n108302929", "1870807699\n259801747", "339671107814\n208405902980", "1367480970723947\n584615739735395", "9992164445234764941\n8162963574901971597"], "outputs": ["33 109", "256 382", "-1", "6304 6304", "0 10406...
UNKNOWN
PYTHON3
CODEFORCES
34
b41aff4b8c6e0ade8d4f97f7ee1a8118
New Bus Route
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d...
[ "n = int(input())\r\nar = list(map(int,input().split()))\r\nar.sort()\r\nl = [abs(ar[i+1] - ar[i]) for i in range(0,n-1)]\r\nk = min(l)\r\nprint(k,l.count(k),sep = ' ')\r\n", "def solve():\n n = int(input().rstrip())\n ls = list(map(int, input().rstrip().split()))\n ls.sort()\n mindist = 102000134234\...
{"inputs": ["4\n6 -3 0 4", "3\n-2 0 2", "2\n1 2", "2\n1000000000 -1000000000", "5\n-979619606 -979619602 -979619604 -979619605 -979619603", "5\n-799147771 -799147773 -799147764 -799147774 -799147770", "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 5532...
UNKNOWN
PYTHON3
CODEFORCES
213
b49dba691f82dec9bff8965c7101a5d8
A polyline
The input contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=10,<=0<=≤<=*b*<=≤<=22·*a*<=-<=1) separated by a single space. Output two integers separated by a single space. Sample Input 1 0 2 15 4 160 Sample Output 0 0 3 0 12 12
[ "replacements = {\r\n \"A\":\"+BF-AFA-FB+\",\r\n \"B\":\"-AF+BFB+FA-\",\r\n \"+\":\"+\",\r\n \"-\":\"-\",\r\n \"F\":\"F\",\r\n}\r\n\r\ndef curve_sequence(n):\r\n if n==0:\r\n yield \"A\"\r\n return\r\n for t in curve_sequence(n-1):\r\n yield from replacements[t]\r\n\r\na, b...
{"inputs": ["1 0", "2 15", "4 160", "3 14", "10 2", "2 0", "2 15", "2 7", "2 6", "2 9", "3 0", "3 63", "3 51", "3 17", "3 63", "4 0", "4 255", "4 74", "4 236", "4 41", "5 0", "5 1023", "5 205", "5 186", "5 939", "6 0", "6 4095", "6 498", "6 3835", "6 2531", "7 0", "7 16383", "7 8518", "7 124", "7 8898", "8 0", "8 65535...
UNKNOWN
PYTHON3
CODEFORCES
4
b4cb240302791e8ce80d244ae2e55014
Book of Evil
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains *n* settlements numbered from 1 to *n*. Moving through the swamp is very difficult, so people tramped exactly *n*<=-<=1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possi...
[ "# Problem: D. Book of Evil\r\n# Contest: Codeforces - Codeforces Round 196 (Div. 2)\r\n# URL: https://codeforces.com/problemset/problem/337/D\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n\r\nimport sys\r\nimport bisect\r\nimport random\r\nimport io, os\r\nfrom bisect import *\r\nfrom collections import *\...
{"inputs": ["6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6", "2 2 1\n2 1\n1 2", "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\n35 ...
UNKNOWN
PYTHON3
CODEFORCES
3
b4d511f706e2bc8c6f024a955cc31d15
Sorting the Coins
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then...
[ "import io, os\r\ninput=io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn=int(input())\r\nw=[int(k) for k in input().decode('utf-8').split()]\r\neta=[1]\r\niota=[0 for j in range(n)]\r\nc=n-1\r\nfor j in range(n-1):\r\n iota[w[j]-1]=1\r\n while iota[c]==1:\r\n c-=1\r\n eta.append(j+1-(n-...
{"inputs": ["4\n1 3 4 2", "8\n6 8 3 4 7 2 1 5", "1\n1", "11\n10 8 9 4 6 3 5 1 11 7 2", "11\n10 8 9 4 3 5 1 11 7 2 6", "100\n1 72 43 50 58 87 10 94 29 51 99 86 92 80 36 31 9 100 85 59 66 30 3 78 17 73 93 37 57 71 45 15 24 2 64 44 65 22 38 79 23 8 16 52 98 97 96 95 91 90 89 88 84 83 82 81 77 76 75 74 70 69 68 67 63 62 61...
UNKNOWN
PYTHON3
CODEFORCES
34
b4d9105ef9a9a251914f6909fd51454d
Remembering Strings
You have multiset of *n* strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position *i* and some letter *c* of the English alphabet, such that this string is the only string in the multiset that has letter *c* in pos...
[ "'''\r\nhttps://codeforc.es/contest/543/problem/C\r\n题意:“好记”字符串组:每个字符串都包含一个相对其他字符相同位置的唯一字符,\r\n给出修改每个位置字符需要的硬币数,求使得给定字符串组“好记”需要的最少硬币。\r\nf[mask]表示每一行的选择状态为mask时的解\r\n对于第j列、任意状态mask,枚举其选择的第一行(二进制中的最低位lowbit)的选择:\r\n1.将第low行修改为不存在于第j列中的一个字母,子问题为f[mask^(1<<low)],即将mask中第low行取消选择\r\n2.修改与第low行(第j列)值相同的其他行\r\n'''\r\nI=i...
{"inputs": ["4 5\nabcde\nabcde\nabcde\nabcde\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "4 3\nabc\naba\nadc\nada\n10 10 10\n10 1 10\n10 10 10\n10 1 10", "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1", "5 2\naa\naa\nab\nbb\nbb\n1 100\n100 100\n1 1\n100 100\n100 1", "3 3\nabc\nabc\nabc\n1 100 100\n100 1 100\n100 100 1", "1...
UNKNOWN
PYTHON3
CODEFORCES
2
b4eb2890c5643e69ebc890ea4edc66eb
Parity Game
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") *a* and *b*. Then you try to turn *a* into *b* using two types of operations: - Write *...
[ "a = input()\r\nb = input()\r\ncnt1 = a.count('1') + (a.count('1') % 2 == 1)\r\ncnt2 = b.count('1')\r\nprint('YES'if cnt1 >= cnt2 else'NO')\r\n", "a = input()\r\nb = input() # ris finale\r\nif a == b:\r\n print(\"YES\")\r\nelse:\r\n a1 = a.count(\"1\")\r\n b1 = b.count(\"1\")\r\n if a1 % 2 == 1:\r\n ...
{"inputs": ["01011\n0110", "0011\n1110", "11111\n111111", "0110011\n01100110", "10000100\n011110", "1\n0", "0\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
UNKNOWN
PYTHON3
CODEFORCES
30
b4efdc24295286054870ab19e37d0e4b
Cutlet
Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2*n* seconds, in particular, it should be fried for *n* seconds on one side and *n* seconds on the other side. Arkady has already got a frying pan and turn o...
[ "INF = (1 << 62)\r\nN = 200005\r\nMOD = 1000000007\r\n\r\nflips = [[INF] * N for _ in range(2)]\r\nflip_intervals = [0] * N\r\ncooking_time, num_intervals = 0, 0\r\n\r\ndef solve():\r\n global cooking_time, num_intervals\r\n for i in range(N):\r\n flips[0][i] = INF\r\n flips[0][0] = 0\r\n cooking...
{"inputs": ["10 2\n3 5\n11 13", "10 3\n3 5\n9 10\n11 13", "20 1\n3 19", "10 1\n0 20", "10 1\n0 1", "10 1\n10 10", "10 2\n4 4\n14 14", "1 1\n0 0", "10 5\n3 3\n5 5\n8 8\n13 13\n16 16", "10 7\n0 0\n2 6\n8 10\n12 12\n14 14\n17 17\n19 19", "100 10\n18 18\n30 30\n37 37\n59 59\n83 83\n90 90\n141 141\n149 149\n173 173\n189 189...
UNKNOWN
PYTHON3
CODEFORCES
2
b4f01cf990c7577c3d9702ff5433b451
Maximum Questions
Vasya wrote down two strings *s* of length *n* and *t* of length *m* consisting of small English letters 'a' and 'b'. What is more, he knows that string *t* has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions. Suddenly in the morning, Vasya found that somebody spoiled ...
[ "n = int(input()); s = input(); m = int(input())\na = [0]*(n+2); b = [0]*(n+2); q = [0]*(n+1);\ndp = [(0, 0)]*(n+2)\n\nfor i in range(0, n):\n b[i] = b[i-2]+(s[i] == 'b')\n a[i] = a[i-2]+(s[i] == 'a')\n q[i] = q[i-1]+(s[i] == '?')\n\nfor i in range(n-1, -1, -1):\n if i+m-1 >= n:\n continue\n dp[i] = dp[i+1]...
{"inputs": ["5\nbb?a?\n1", "9\nab??ab???\n3", "6\nab??ab\n4", "14\n?abaa?abb?b?a?\n3", "17\nb??a?abbbaaababba\n4", "1\nb\n1", "3\nb?a\n1", "12\naba?bbaaabbb\n1", "43\n????aabaababa?aaaa?abbbabbb?ab??baabbbbbabb\n5", "36\nbbaa??aab?aabbb?ba?b?bba?bbaa??bb?ab\n4", "14\na?a?b????b?ba?\n3", "47\na??a??abbaaa?a??aaabaa?abbb...
UNKNOWN
PYTHON3
CODEFORCES
4
b4f150096d024711c692c784f8da6959
Hometask
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a set of digits, your task is to find the maximum integer that you can mak...
[ "n = int(input())\r\na = sorted(map(int, input().split()), reverse=1)\r\nif a[-1] == 0:\r\n k = sum(a)\r\n l1 = []\r\n l2 = []\r\n F = 1\r\n for i in range(n):\r\n if a[i] % 3 == 1:\r\n l1.append(a[i])\r\n elif a[i] % 3 == 2:\r\n l2.append(a[i])\r\n if k % 3 == ...
{"inputs": ["1\n0", "11\n3 4 5 4 5 3 5 3 4 4 0", "8\n3 2 5 1 5 2 2 3", "12\n5 3 3 3 2 5 5 1 2 1 4 1", "8\n5 5 4 1 5 5 5 3", "12\n3 1 2 3 2 0 2 2 2 0 2 3", "12\n5 1 4 4 2 1 7 7 4 2 5 1", "5\n3 6 1 6 2", "11\n3 9 9 6 4 3 6 4 9 6 0", "5\n9 6 6 6 1", "10\n2 0 0 0 0 0 0 0 0 0", "10\n1 0 0 0 0 0 0 0 0 0", "5\n1 1 0 0 0", "5\...
UNKNOWN
PYTHON3
CODEFORCES
6