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
5798885d5811c8fe3f4c55cfa0dcc0b7
Cave Painting
Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp. Imp wan...
[ "n,k=[int(i) for i in input().split()]\nf=[]\nt=True\nfor i in range(1,k+1):\n if(n%i in f):\n t=False\n break\n else:\n f.append(n%i)\nif(t):\n print('Yes')\nelse:\n print('No')\n \t\t\t\t\t\t\t\t\t \t \t\t\t\t\t\t \t\t\t\t\t\t", "import math\r\nn,k = [int(x) for x in input().s...
{"inputs": ["4 4", "5 3", "1 1", "744 18", "47879 10", "1000000000000000000 1000000000000000000", "657180569218773599 42", "442762254977842799 30", "474158606260730555 1", "807873101233533988 39", "423 7", "264306177888923090 5", "998857801526481788 87", "999684044704565212 28", "319575605003866172 71", "75580456057741...
UNKNOWN
PYTHON3
CODEFORCES
29
57afa8f407534eefb24cd9f1ed75cce9
none
While Duff was resting in the beach, she accidentally found a strange array *b*0,<=*b*1,<=...,<=*b**l*<=-<=1 consisting of *l* positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, *a*0,<=...,<=*a**n*<=-<=1 that *b* can be build from *a* with formula: *b**...
[ "from collections import Counter\nmod = 10 ** 9 + 7\nn, l, k = list(map(int, input().split()))\nif k == 1:\n print(l % mod)\n exit()\na = list(map(int, input().split()))\nif l < n:\n a = a[:l]\n n = len(a)\nm = {v : i + 1 for i, v in enumerate(sorted(set(a)))}\nb = [m[i] for i in a]\ng = l // n\nr = l %...
{"inputs": ["3 5 3\n5 9 1", "5 10 3\n1 2 3 4 5", "1 1000000000000000000 1\n508953607", "13 1984343432234 32\n347580985 506695806 506695806 42598441 347580985 720568974 208035957 385072757 42598441 506695806 42598441 42598441 506695806", "1 75937459749 1000000\n521563672", "1 1 1000000\n496389707", "10 82374928374234234...
UNKNOWN
PYTHON3
CODEFORCES
1
57b85f4fcba005a67ee75fe25e8a7e4b
Array and Operations
You have written on a piece of paper an array of *n* positive integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] and *m* good pairs of integers (*i*1,<=*j*1),<=(*i*2,<=*j*2),<=...,<=(*i**m*,<=*j**m*). Each good pair (*i**k*,<=*j**k*) meets the following conditions: *i**k*<=+<=*j**k* is an odd number and 1<=≤<=*i**k*<=&lt;<=*j**...
[ "L,m=[int(e) for e in input().split()]\r\ndef pdd(x):\r\n d={}\r\n i=2\r\n while i*i<=x:\r\n if x%i==0:\r\n d[i]=1\r\n x//=i\r\n while x%i==0:\r\n x//=i\r\n d[i]+=1\r\n i+=1\r\n if x!=1:\r\n d[x]=1\r\n return d\r\nD=[...
{"inputs": ["3 2\n8 3 8\n1 2\n2 3", "3 2\n8 12 8\n1 2\n2 3", "6 4\n35 33 46 58 7 61\n4 5\n3 6\n5 6\n1 6", "10 25\n262144 262144 64 64 16 134217728 32 512 32 8192\n1 2\n3 10\n5 8\n9 10\n2 5\n5 10\n3 6\n3 8\n2 9\n4 5\n8 9\n1 4\n4 9\n3 4\n1 6\n4 7\n7 8\n5 6\n2 3\n1 10\n1 8\n6 9\n6 7\n2 7\n7 10", "10 9\n67108864 8 2 131072...
UNKNOWN
PYTHON3
CODEFORCES
3
57b85f9568ee496d7d360784500df856
Strip
Alexandra has a paper strip with *n* numbers on it. Let's call them *a**i* from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: - Each piece should contain at least *l* numbers.- The difference between the maximal and the minimal number on the p...
[ "from collections import deque\r\n\r\n# f[i] = min(f[k]) + 1 for g[i] - 1 <= k <= i - l\r\n# [g[i], i] is a valid seg\r\n# sliding window of max/min elements\r\n\"\"\"\r\ndebug qmin (increasing) qmax (decreasing), [-1] is max/min\r\ndebug deque([1]) deque([1])\r\ndebug deque([1, 2]) deque([2])\r\ndebug deque([3]) d...
{"inputs": ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1", "1 0 1\n0", "6 565 2\n31 76 162 -182 -251 214", "1 0 1\n0", "1 0 1\n-1000000000", "1 100 2\n42", "2 1000000000 1\n-1000000000 1000000000", "2 1000000000 2\n-1000000000 1000000000", "10 3 3\n1 1 1 1 1 5 6 7 8 9", "10 3 3\n1 1 1 2 2 5 6 7 8 9"], "outputs":...
UNKNOWN
PYTHON3
CODEFORCES
6
57d971eb6fe7181e2ba33519339db54d
Exams
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha...
[ "n, m = map(int, input().split())\r\nprint(max(0, n*3-m))\r\n\r\n# FMZJMSOMPMSL\r\n", "n , k = map(int,input().split())\r\nx = (3 * n) - k\r\nif x <= 0 :\r\n print(\"0\")\r\nelse:\r\n print(x)", "n, k = map(int, input().split())\r\nprint(max(3*n-k, 0))", "n, k = map(int, input().split())\r\n\r\ntwo = k/...
{"inputs": ["4 8", "4 10", "1 3", "1 2", "4 9", "50 234", "50 100", "50 250", "29 116", "20 69", "46 127", "3 7", "36 99", "45 104", "13 57", "25 106", "8 19", "20 69", "13 32", "47 128", "17 73", "3 7", "16 70", "1 5", "38 137", "7 20", "1 5", "36 155", "5 15", "27 75", "21 73", "2 5", "49 177", "7 20", "44 173", "49 ...
UNKNOWN
PYTHON3
CODEFORCES
261
57d99909d9c306e4442f6732b3ca3243
Little Elephant and Cards
The Little Elephant loves to play with color cards. He has *n* cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thin...
[ "n = int(input())\r\ncards = {}\r\n\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n\r\n if a not in cards:\r\n cards[a] = [0, 0]\r\n cards[a][0] += 1\r\n\r\n if a != b:\r\n if b not in cards:\r\n cards[b] = [0, 0]\r\n cards[b][1] += 1\r\n\r\nresult = 10**18...
{"inputs": ["3\n4 7\n4 7\n7 4", "5\n4 7\n7 4\n2 11\n9 7\n1 1", "1\n1 1", "2\n1 1\n1 1", "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8", "2\n1 2\n2 1", "3\n7 7\n1 2\n2 1", "3\n1 1\n2 5\n3 6", "4\n1000000000 1000000000\n999999999 1000000000\n999999997 999999998\n47 74", "6\n1 2\n3 1\n4 7\n4 1\n9 1\n7 2", "4\n1 2\n1 2\n2 1\n2 1",...
UNKNOWN
PYTHON3
CODEFORCES
12
57e7e421e1a36b78c8e4fde63ced274c
Anatoly and Cockroaches
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectio...
[ "N = int(input())\r\nThis, Ans = input(), []\r\nfor i in ['rb', 'br']:\r\n Should = i * (N // 2) + i[:N % 2]\r\n WasR = This.count('r')\r\n NowR = Should.count('r')\r\n Diff = sum(1 for i, j in zip(This, Should) if i != j)\r\n Ans.append((Diff - abs(WasR - NowR)) // 2 + abs(WasR - NowR))\r\nprint(min...
{"inputs": ["5\nrbbrr", "5\nbbbbb", "3\nrbr", "13\nrbbbrbrrbrrbb", "18\nrrrrrrrrrrrrrrrrrb", "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb", "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbb...
UNKNOWN
PYTHON3
CODEFORCES
110
57ee5e055f24eba95c780683a584296b
ZS and The Birthday Paradox
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland. In Udayland,...
[ "#copied\r\nimport math\r\nn, k = [int(x) for x in input().split()]\r\nif n<70 and k>2**n:\r\n print(1,1)\r\n exit(0)\r\nmod = int(1e6)+3\r\n\r\ndef fastpow(a,b):\r\n t, ans = a, 1\r\n while b:\r\n if(b&1):\r\n ans = ans*t%mod\r\n t = t*t %mod\r\n b>>=1\r\n return ans\...
{"inputs": ["3 2", "1 3", "4 3", "1000000000000000000 1000000000000000000", "59 576460752303423489", "1234567891234 100005", "2 4", "59 576460752303423488", "2016 2016", "2016 2017", "468804735183774830 244864585447548924", "172714899512474455 414514930706102803", "876625063841174080 360793239109880865", "7018187597523...
UNKNOWN
PYTHON3
CODEFORCES
1
57f6b670c52d8702a7686ef2568dbfed
The Monster
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=.... The Monster will catch them if a...
[ "#!/usr/bin/python3\n\na,b = [int(x) for x in input().split()]\nc,d = [int(x) for x in input().split()]\ni = 0\nj = 0\nflag = 0\nfor i in range(1000000):\n\ts1 = b + a*i\n\tif (s1 >= d and 0 == (s1-d)%c):\n\t\tprint(s1)\n\t\tflag = 1\n\t\tbreak\nif (not flag):\n\tprint(\"-1\")\n", "#Author: M@sud_P@rvez\r\nfrom m...
{"inputs": ["20 2\n9 19", "2 1\n16 12", "39 52\n88 78", "59 96\n34 48", "87 37\n91 29", "11 81\n49 7", "39 21\n95 89", "59 70\n48 54", "87 22\n98 32", "15 63\n51 13", "39 7\n97 91", "18 18\n71 71", "46 71\n16 49", "70 11\n74 27", "94 55\n20 96", "18 4\n77 78", "46 44\n23 55", "74 88\n77 37", "94 37\n34 7", "22 81\n80 8...
UNKNOWN
PYTHON3
CODEFORCES
210
5828394940254fd6efa3a0abedfaa1be
Genetic Engineering
You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'. ...
[ "R = lambda: map(int, input().split())\r\ns = input()\r\ncc, c = 0, 0\r\nfor r in range(len(s)):\r\n if r == 0 or s[r] == s[r - 1]:\r\n c += 1\r\n else:\r\n cc += (c % 2 == 0)\r\n c = 1\r\ncc += (c % 2 == 0)\r\nprint(cc)", "dnk = input(); l = len(dnk); para = 1; kolvo = 0\r\nfor i in ra...
{"inputs": ["GTTAAAG", "AACCAACCAAAAC", "GTGAATTTCC", "CAGGGGGCCGCCCATGAAAAAAACCCGGCCCCTTGGGAAAACTTGGGTTA", "CCCTTCACCCGGATCCAAATCCCTTAGAAATAATCCCCGACGGCGTTGTATCACCTCTGCACTTGTTAGTAAGGTCAGGCGTCCATTACGGAAGAACGTA", "GCATTACATGGGGGGGTCCTACGAGCCCGGCATCCCGGAAACTAGCCGGTTAATTTGGTTTAAACCCTCCCACCCCGGATTGTAACCCCCCTCATTGGTT", "TTC...
UNKNOWN
PYTHON3
CODEFORCES
42
582ec02a56804cc5560660c3e04cd02a
On Number of Decompositions into Multipliers
You are given an integer *m* as a product of integers *a*1,<=*a*2,<=... *a**n* . Your task is to find the number of distinct decompositions of number *m* into the product of *n* ordered positive integers. Decomposition into *n* products, given in the input, must also be considered in the answer. As the answer can be v...
[ "# Design_by_JOKER\r\nimport math\r\nimport cmath\r\n\r\nMod = 1000000007\r\n\r\nMAX = 33000\r\n\r\nn = int(input())\r\n\r\nA = list(map(int, input().split()))\r\n\r\nB = [0] * MAX\r\n\r\nbePrime = [0] * MAX;\r\n\r\nprimNum = []\r\n\r\nC = []\r\n\r\nfac = [1]\r\n\r\nfor j in range(1, MAX):\r\n fac.append(fac[-1]...
{"inputs": ["1\n15", "3\n1 1 2", "2\n5 7", "2\n5 10", "3\n1 30 1", "2\n1000000000 1000000000", "1\n1", "3\n1 1 1", "2\n1 2", "2\n1 6", "3\n8 10 8", "5\n14 67 15 28 21", "8\n836 13 77 218 743 530 404 741", "10\n6295 3400 4042 2769 3673 264 5932 4977 1776 5637", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 9...
UNKNOWN
PYTHON3
CODEFORCES
3
58300c1535aca1212396fa7342a89cff
Domino
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
[ "from math import *\r\nfrom collections import *\r\nfrom sys import *\r\nt=stdin.readline\r\np=stdout.write\r\ndef GI(): return map(int, t().strip().split())\r\ndef GS(): return map(str, t().strip().split())\r\ndef GL(): return list(map(int, t().strip().split()))\r\ndef SL(): return list(map(str, t().strip().split(...
{"inputs": ["2\n4 2\n6 4", "1\n2 3", "3\n1 4\n2 3\n4 4", "5\n5 4\n5 4\n1 5\n5 5\n3 3", "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2...
UNKNOWN
PYTHON3
CODEFORCES
236
5836b24c0f11bb4c360cb09cc7022291
Mean Requests
In this problem you will have to deal with a real algorithm that is used in the VK social network. As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a cer...
[ "a = list(input().split())\r\nn, T, c = int(a[0]), int(a[1]), float(a[2])\r\na = list(map(int, input().split()))\r\nm = int(input())\r\np = list(map(int, input().split()))\r\n\r\nsum_a = sum(a[:T - 1])\r\nmean = 0\r\nfor t in range(T - 1):\r\n mean = (mean + a[t]/T) / c\r\n\r\ni = 0\r\nfor t in range(T - 1, p[-1...
{"inputs": ["1 1 2.000000\n1\n1\n1", "11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11", "13 4 1.250000\n3 3 3 3 3 20 3 3 3 3 3 3 3\n10\n4 5 6 7 8 9 10 11 12 13", "1 1 2.000000\n4\n1\n1", "1 1 2.000000\n1121\n1\n1", "1 1 2.000000\n758432\n1\n1", "3 1 2.000000\n8 25 21\n3\n1 2 3", "19 3 1.333333\n12 15 11 10...
UNKNOWN
PYTHON3
CODEFORCES
4
5845aa1a775a0630183ec6836b5c2a58
Super M
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able ...
[ "from collections import deque\r\nn,m = [int(x) for x in input().split()]\r\nadj = [[] for x in range(n+1)]\r\nfor _ in range(1,n):\r\n\ta,b = [int(x) for x in input().split()]\r\n\tadj[a].append(b)\r\n\tadj[b].append(a)\r\nchaos = [int(x) for x in input().split()]\r\ns = chaos[0]\r\nchaos = set(chaos)\r\ncc = [0]*...
{"inputs": ["7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "2 1\n2 1\n1", "1 1\n1", "10 2\n6 9\n6 2\n1 6\n4 10\n3 7\n9 4\n9 5\n6 7\n2 8\n7 6", "15 2\n7 12\n13 11\n6 8\n2 15\n10 9\n5 1\n13 5\n5 4\n14 3\n8 9\n8 4\n4 7\n12 14\n5 2\n7 4", "20 2\n1 16\n12 5\n15 19\n18 9\n8 4\n10 16\n9 16\...
UNKNOWN
PYTHON3
CODEFORCES
4
586f37714c4649e29d7df6664178ab08
Find Color
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond...
[ "a,b=input().split( )\nc=(int(a)**2+int(b)**2)**.5\nd=int(a)*int(b)\nif d>0:\n if c%2>1:\n print('white')\n else:\n print('black')\nelif d<0:\n if 0<c%2<1:\n print('white')\n else:\n print('black')\nelse:\n print('black')", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAu...
{"inputs": ["-2 1", "2 1", "4 3", "3 3", "4 4", "-4 4", "4 -4", "-4 -4", "0 0", "0 1", "0 2", "0 1000", "1000 0", "-1000 0", "0 -1000", "1000 -1000", "12 5", "12 -5", "-12 -35", "20 -21", "-677 492", "-673 -270", "-668 970", "-220 208", "-215 -996", "-211 243", "-206 -518", "-201 278", "-196 -484", "902 479", "-441 572...
UNKNOWN
PYTHON3
CODEFORCES
67
5877a100f511348a0d6590e174c3e4fa
Fake NP
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times...
[ "n = input().split()\na = int(n[0])\nb = int(n[1])\n\nif(a==b):\n print(a)\nelse:\n print('2')\n", "l, r= map(int,input().split())\r\nif l!=r: print(2)\r\nelse: print(l)\r\n\n# Wed Jan 05 2022 09:49:47 GMT+0000 (Coordinated Universal Time)\n", "l,r = list(map(int, input().split()))\r\nprint(l) if l==r else pr...
{"inputs": ["19 29", "3 6", "39 91", "76 134", "93 95", "17 35", "94 95", "51 52", "47 52", "38 98", "30 37", "56 92", "900000000 1000000000", "37622224 162971117", "760632746 850720703", "908580370 968054552", "951594860 953554446", "347877978 913527175", "620769961 988145114", "820844234 892579936", "741254764 741254...
UNKNOWN
PYTHON3
CODEFORCES
173
587a688de32a2c20d1ca304fba736ece
Camels
Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with *t* humps, representing them as polylines in the plane. Each polyline consists of *n* vertices with coordinates (*x*1,<=*y*1), (*x*2,<=*y*2), ..., (*x**n*,...
[ "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import Counter\r\n\r\nn,t=map(int,input().split())\r\n\r\nDP=Counter()\r\n\r\nfor i in range(1,5):\r\n for j in range(1,5):\r\n if i==j:\r\n continue\r\n DP[i,j,0,0]+=1\r\n\r\nfor i in range(n-2):\r\n NDP=Counter()\r\n\r\n ...
{"inputs": ["6 1", "4 2", "3 1", "3 2", "3 3", "3 10", "4 1", "4 3", "4 9", "5 1", "5 2", "5 3", "5 5", "5 9", "5 10", "6 1", "6 2", "6 3", "6 4", "6 10", "19 1", "19 2", "19 3", "19 4", "19 5", "19 6", "19 7", "19 8", "19 9", "19 10", "20 1", "20 2", "20 3", "20 4", "20 5", "20 6", "20 7", "20 8", "20 9", "20 10"], "o...
UNKNOWN
PYTHON3
CODEFORCES
10
588081e1dbf946870f913796b2adf243
none
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
[ "def graph(e):\n e = [(w, i, b) for i, (w, b) in enumerate(e)]\n e.sort()\n\n g = [None]*len(e)\n\n mst = [(w, i) for w, i, b in e if b]\n for n, (w, i) in enumerate(mst, 2):\n g[i] = 1, n\n\n cm = 0\n available = []\n\n for w, i, b in e:\n if not b:\n if not availab...
{"inputs": ["4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "3 3\n1 0\n2 1\n3 1", "2 1\n7 1", "3 2\n8 1\n9 1", "3 3\n4 1\n5 0\n7 1", "3 3\n4 1\n5 1\n7 0", "3 3\n4 1\n4 0\n4 1", "3 3\n4 0\n5 1\n4 1", "3 3\n5 0\n4 1\n5 1", "4 4\n2 1\n3 0\n3 1\n4 1", "4 5\n4 1\n4 1\n4 0\n4 0\n6 1", "4 6\n2 1\n4 0\n3 0\n1 1\n4 1\n5 0", "4 4\n2 1\n6 0\n7 1...
UNKNOWN
PYTHON3
CODEFORCES
8
5881aa5d667ad0d66be9e421fbdb0c19
Tanya and Postcard
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s...
[ "s=input()\r\nt=input()\r\n\r\nfrom collections import Counter as C\r\nimport string\r\nlower=string.ascii_lowercase\r\nupper=string.ascii_uppercase\r\n\r\ncS=C(s)\r\ncT=C(t)\r\n\r\nyay=0\r\nwhoops=0\r\nfor c,cnt in cS.items():\r\n if c in cT.keys():\r\n subtract=min(cnt,cT[c])\r\n yay+=subtract\r\...
{"inputs": ["AbC\nDCbA", "ABC\nabc", "abacaba\nAbaCaBA", "zzzzz\nZZZZZ", "zzzZZZ\nZZZzzZ", "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop", "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM", "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK", "DpiNBmCRFWxpdbfGOzvvO...
UNKNOWN
PYTHON3
CODEFORCES
88
5892b69c55b4fe459e4286fdace16edf
Sort the Array
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers. Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr...
[ "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nst = -1\r\nend = -1\r\n\r\nfor i in range(1, n):\r\n if a[i] < a[i - 1]:\r\n if st == -1:\r\n st = i - 1\r\n end = i\r\n\r\nif st == -1:\r\n print(\"yes\")\r\n print(\"1 1\") \r\nelse:\r\n \r\n a[st:end + 1] = re...
{"inputs": ["3\n3 2 1", "4\n2 1 3 4", "4\n3 1 2 4", "2\n1 2", "2\n58 4", "5\n69 37 27 4 2", "9\n6 78 63 59 28 24 8 96 99", "6\n19517752 43452931 112792556 68417469 779722934 921694415", "6\n169793171 335736854 449917902 513287332 811627074 938727967", "6\n509329 173849943 297546987 591032670 796346199 914588283", "25\n...
UNKNOWN
PYTHON3
CODEFORCES
97
5897bd968f90d3c87e025d3df2080b70
Dominoes
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes. The teacher responded instantly at our request. He put *nm* dominoes on the table as an *n*<=×<=2*m* rectangle so that each of the *n* rows contained *m* dominoes arranged horizontall...
[ "n, m = map(int, input().split())\r\ncnt1 = 0\r\ncnt2 = 0\r\nfor i in range(n):\r\n for x in input().split():\r\n if x == \"11\": cnt2 += 1\r\n elif x == \"01\": cnt1 += 1\r\n elif x == \"10\": cnt1 += 1\r\ncnt0 = n*m - cnt1 - cnt2\r\n\r\nmat = [ [-1]*(m) for i in range(n) ]\r\ncol = [0]*(2*m)\r\n\r\nstrB...
{"inputs": ["2 3\n01 11 00\n00 01 11", "4 1\n11\n10\n01\n00", "1 1\n00", "1 1\n01", "1 1\n11", "9 9\n01 00 00 01 00 01 11 11 11\n10 10 10 01 10 01 11 01 10\n10 00 10 00 11 01 00 10 00\n01 00 01 01 11 00 00 11 11\n11 00 10 11 01 01 11 00 01\n01 10 00 00 11 10 01 01 10\n11 10 11 00 11 11 01 10 10\n10 00 01 00 00 00 11 01...
UNKNOWN
PYTHON3
CODEFORCES
6
5898c00f01fa4b898400dca4b5772eea
Puzzles
Barney lives in country USC (United States of Charzeh). USC has *n* cities numbered from 1 through *n* and *n*<=-<=1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit an...
[ "n = int(input())\npos, tree, ans, sz = list(map(int,input().split())) if n > 1 else [],[],[],[]\nfor i in range(n):\n tree.append([])\n ans.append(0.0)\n sz.append(0)\n\nfor i in range(n - 1):\n tree[pos[i] - 1].append(i + 1)\n\nfor i in range(n)[::-1]:\n sz[i] = 1\n for to in tree[i]:\n sz[i] += sz[to]\n...
{"inputs": ["7\n1 2 1 1 4 4", "12\n1 1 2 2 4 4 3 3 1 10 8", "3\n1 2", "8\n1 1 2 2 3 6 1", "85\n1 1 2 2 4 6 1 3 6 3 3 11 9 14 12 5 8 11 16 19 12 17 2 19 1 24 6 2 6 6 24 3 20 1 1 1 17 8 4 25 31 32 39 12 35 23 31 26 46 9 37 7 5 23 41 41 39 9 11 54 36 54 28 15 25 58 56 18 23 70 68 18 3 48 57 70 15 65 22 35 25 13 49 34", "1...
UNKNOWN
PYTHON3
CODEFORCES
9
58a83557040dfdbc385a042906d45d1f
Wrong Subtraction
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,...
[ "n, k = [int(z) for z in input().split(\" \")]\r\n\r\nfor i in range(1,k+1):\r\n if(n%10!=0):\r\n n=n-1\r\n else:\r\n n=n/10\r\n\r\nprint(int(n))\r\n", "a=str(input(\"\"))\r\nb=0\r\nf=-1\r\nc=''\r\nd=''\r\nwhile a[f]!=\" \":\r\n d=a[f]+d\r\n f=f-1\r\n \r\nwhile a[b]!=\" \" :\r\n c=c+a...
{"inputs": ["512 4", "1000000000 9", "131203 11", "999999999 50", "999999999 49", "131203 9", "900000000 16", "909090909 50", "1001 2", "5 2", "2 1"], "outputs": ["50", "1", "12", "9999", "99990", "130", "1", "3", "100", "3", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
428
58af402ad60c89300051482d9084e5a8
Minimum Ternary String
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For e...
[ "import copy\r\n\r\ns = input()\r\n\r\ncount = s.count('1')\r\nif count == 0:\r\n print(s)\r\n\r\nelse:\r\n\r\n s = s.replace('1','')\r\n if s.count('2') == 0:\r\n print(s,end=\"\")\r\n for j in range(count):\r\n print('1', end=\"\")\r\n else:\r\n index = -1\r\n f...
{"inputs": ["100210", "11222121", "20", "1002", "10", "000021", "021", "2", "201", "2112120", "102", "202", "220201", "12", "100022202", "01", "1"], "outputs": ["001120", "11112222", "20", "0012", "01", "000012", "012", "2", "120", "1112220", "012", "202", "122020", "12", "000122202", "01", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
151
58bb01f8136f320b940058018a44f47c
Design Tutorial: Learn from Math
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
[ "def prime(n):\r\n d = 2\r\n while d * d <= n and n % d != 0:\r\n d += 1\r\n return d * d > n\r\n\r\nn = int(input())\r\na = 0\r\nb = 0\r\nfor i in range(4, n):\r\n if prime(i) is not True and prime(n - i) is not True:\r\n a = i\r\n b = n - i\r\n break\r\nprint(a, b)", "n =...
{"inputs": ["12", "15", "23", "1000000", "63874", "14568", "192", "86", "46220", "57114", "869", "738457", "58113", "4864", "15", "74752", "6073", "1289", "20", "58134", "57756", "765", "59", "991666", "70761", "13", "999999", "17", "21", "19", "100007", "999987", "22"], "outputs": ["4 8", "6 9", "8 15", "500000 500000...
UNKNOWN
PYTHON3
CODEFORCES
597
58c5d42231d8ef54d85d53c0d3311e95
Appleman and Toastman
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman...
[ "n=int(input())\ns=input()\nx=list()\nx=s.split()\ny=sorted(x,key=int)\nans=0\nfor i in range(n):\n\tans+=int(y[i])*(i+2)\n\nans-=int(y[n-1])\nprint(ans)\n", "def main():\r\n n = int(input())\r\n a = sorted([int(c) for c in input().split()])\r\n s = sum(a)\r\n\r\n mn = score = i = 0\r\n while i < n...
{"inputs": ["3\n3 1 5", "1\n10", "10\n8 10 2 5 6 2 4 7 2 1", "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "10\n1 2 2 2 4 5 6 7 8 10", "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "1\n397870", "1\n1000000", "10\n10 8 7 6 5 4 2 2 2 1", "10\n892002 888642 724...
UNKNOWN
PYTHON3
CODEFORCES
503
58c677856c4b02ac52a4fc953812e4cd
Longest Subsequence
You are given array *a* with *n* elements and the number *m*. Consider some subsequence of *a* and the value of least common multiple (LCM) of its elements. Denote LCM as *l*. Find any longest subsequence of *a* with the value *l*<=≤<=*m*. A subsequence of *a* is an array we can get by erasing some elements of *a*. It...
[ "from time import time\nimport sys\n\nt = time()\n\ndef logger(s):\n print(s, time() - t, file = sys.stderr)\n global t\n t = time()\n\nn, m = [int(x) for x in input().split()]\nA = [int(x) for x in input().split()]\nB, C = [0]*(m+1), [0]*(m+1)\nlogger('initialization: ')\n\nfor a in A:\n if a <= m: B[a...
{"inputs": ["7 8\n6 2 9 2 7 2 3", "6 4\n2 2 2 3 3 3", "10 50\n39 22 60 88 11 65 41 85 65 100", "100 343\n999 284 486 785 176 742 856 415 992 601 600 122 460 214 338 92 627 913 376 835 384 914 335 179 409 957 96 784 531 43 584 206 971 799 592 801 870 978 437 517 466 952 1 327 731 689 816 681 383 969 452 298 114 687 314 ...
UNKNOWN
PYTHON3
CODEFORCES
5
58d9c92f6edcd490cef2fee5f38142a7
Weather
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet. Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a ther...
[ "with open('input.txt', 'r') as f:\n n = int(f.readline())\n g = list(map(int, f.readline().split()))\na = sum(x <= 0 for x in g)\nfor i in g[:-1]:\n a += (i > 0) - (i < 0)\n n = min(n, a)\nprint(n, file=open(\"output.txt\", \"w\"))\n\t \t\t \t \t \t\t\t \t \t", "file = open(\"input.txt\...
{"inputs": ["4\n-1 1 -2 1", "5\n0 -1 1 2 -5", "6\n0 0 0 0 0 0", "6\n-1 -2 -3 -4 5 6", "8\n1 2 -1 0 10 2 12 13", "7\n-1 -2 -3 3 -1 3 4", "2\n3 -5", "50\n4 -8 0 -1 -3 -9 0 -2 0 1 -1 0 7 -10 9 7 0 -10 5 0 1 -6 9 -9 3 -3 3 7 4 -8 -8 3 3 -1 0 2 -6 10 7 -1 -6 -3 -4 2 3 0 -4 0 7 -9", "90\n52 -89 17 64 11 -61 92 51 42 -92 -14 ...
UNKNOWN
PYTHON3
CODEFORCES
32
58dd3c2180285dbfc243479705c44459
none
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were not fair enough and wants to organize a demonstration at one of the squares. Bertown has *n* squares, numbered from 1 to *n*, they are ...
[ "from sys import stdin, stdout\r\n\r\nn, k = map(int, stdin.readline().split())\r\n\r\nvalue = int(stdin.readline())\r\nprices = list(map(int, stdin.readline().split()))\r\nused = {}\r\n\r\nchallengers = prices[:-1]\r\nfor i in range(n - 1):\r\n challengers[i] = (challengers[i], i)\r\n\r\nchallengers.sort(revers...
{"inputs": ["5 2\n8\n2 4 5 3 1", "5 2\n8\n3 2 4 1 5", "5 4\n1000000000000000\n5 4 3 2 1", "10 1\n55\n45 55 61 64 95 95 98 96 65 81", "10 6\n462\n33 98 95 82 91 63 61 51 68 94", "10 4\n38080\n15 3005 4725 1952 8761 8797 9712 9752 9858 9128", "10 9\n46660\n724 2304 7793 7049 7847 5593 4685 7971 2701 5643", "100 50\n42431...
UNKNOWN
PYTHON3
CODEFORCES
2
58e042e2444f9dd4fa27b74cbe69e58f
Beautiful numbers
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges. The first line of the input contains the number ...
[ "import collections\nimport math\nimport os\nfrom heapq import heapify, heappop, heappush\nimport queue\nfrom sys import stdin, stdout\nfrom itertools import *\nimport bisect\nimport sys\nfrom math import gcd\nMAXN = 100010\nmod = 1000000007\ninf = int(1e18)\nv=[0]*2525\ndp=[[[-1 for k in range(2525)]for j in range...
{"inputs": ["1\n1 9", "1\n12 15", "1\n25 53", "1\n1 1000", "1\n1 100000", "2\n234 59843\n46 3243", "4\n55 55\n1234 2348\n620 620\n4 1000", "1\n1 9000000000000000000", "5\n5397562498 1230483490253448\n39218765 5293867493184739\n99 999999999999\n546234 2394748365397856\n67 801834", "3\n1 1\n9000000000000000000 9000000000...
UNKNOWN
PYTHON3
CODEFORCES
2
5905d6dd07b7ab56dc2b9a6790ab9061
Supercentral Point
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'...
[ "n = int(input())\r\nx= []\r\ny = []\r\nc=0\r\nfor k in range(n):\r\n a,b = map(int,input().split())\r\n x.append(a)\r\n y.append(b)\r\nfor i in range(n):\r\n r1,r2,r3,r4=0,0,0,0\r\n for j in range(n):\r\n if x[i]>x[j] and y[i]==y[j]:\r\n r1+=1\r\n if x[i]<x[j] and y[i]==y[j]...
{"inputs": ["8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -...
UNKNOWN
PYTHON3
CODEFORCES
390
59114d397555cf1a5a46cb976295c8dc
Vasily the Bear and Sequence
Vasily the bear has got a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum. The beauty of the written out numbers *b*1,<=*b*2,<=...,<=*b**k* is such maximum non-negative integer *...
[ "def process(A):\r\n d = {}\r\n for x in A:\r\n i = 0\r\n i1 = 1\r\n while i1 <= x:\r\n if i1&x==i1:\r\n if i not in d:\r\n d[i] = [None, []]\r\n if d[i][0] is None:\r\n d[i][0] = x\r\n else:\r\n...
{"inputs": ["5\n1 2 3 4 5", "3\n1 2 4", "3\n1 20 22", "10\n109070199 215498062 361633800 406156967 452258663 530571268 670482660 704334662 841023955 967424642", "30\n61 65 67 71 73 75 77 79 129 131 135 137 139 141 267 520 521 522 524 526 1044 1053 6924600 32125372 105667932 109158064 192212084 202506108 214625360 26007...
UNKNOWN
PYTHON3
CODEFORCES
7
591ed0b026ba4de1b7775863a47e033e
none
You are given an array *a* with *n* distinct integers. Construct an array *b* by permuting *a* such that for every non-empty subset of indices *S*<==<={*x*1,<=*x*2,<=...,<=*x**k*} (1<=≤<=*x**i*<=≤<=*n*, 0<=&lt;<=*k*<=&lt;<=*n*) the sums of elements on that positions in *a* and *b* are different, i. e. The first line co...
[ "n = int(input())\na = list(map(int, input().split()))\nsorted_a = sorted(a)\nshifted_sorted_a = [sorted_a[-1]] + sorted_a[:-1]\n#print(sorted_a)\n#print(shifted_sorted_a)\nfor i in range(len(a)):\n\tpos_in_sorted = sorted_a.index(a[i])\n\tprint(shifted_sorted_a[pos_in_sorted], end=\" \")\nprint()\n\n\n", "n = in...
{"inputs": ["2\n1 2", "4\n1000 100 10 1", "5\n1 3 4 5 2", "1\n10000000", "4\n1 5 8 4", "3\n1 3 2", "4\n3 1 2 4", "12\n7 1 62 12 3 5 8 9 10 22 23 0", "17\n1 3 2 5 4 6 7 8 10 9 13 11 12 14 15 16 18", "22\n1 3 5 7 22 2 4 6 8 9 10 11 12 13 15 14 17 18 16 20 19 23", "22\n17 6 1 22 9 23 38 40 10 20 29 11 12 39 3 32 26 4 13 3...
UNKNOWN
PYTHON3
CODEFORCES
29
5936c23389b0b6633ac3994de8d5c7ce
Polo the Penguin and Lucky Numbers
Everybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Polo the Penguin have two positive integers *l* and *r* (*l*<=&lt;<=*r*), both of them are lucky numbers. Moreover, their le...
[ "mod = 1000000007\r\nN = 100000\r\n\r\ntwo = [0] * (N + 1)\r\nten = [0] * (N + 1)\r\nfour = [0] * (N + 1)\r\nseven = [0] * (N + 1)\r\nprod = [0] * (N + 1)\r\nsum_val = [0] * (N + 1)\r\nProd = [0] * (N + 1)\r\nlar = [0] * (N + 1)\r\ndp = [[False, False] for _ in range(N + 1)]\r\npa = [[-1, -1] for _ in range(N + 1)]...
{"inputs": ["4\n7", "474\n777", "44\n77", "444\n777", "444\n477", "444\n744", "47\n74", "447\n774", "4444\n7777", "44444\n77777", "444444\n777777", "44744\n74747", "47774\n74777", "47\n77", "474\n747", "7447\n7744", "74744\n74747", "7447777\n7774477", "747447\n777744", "4477447744\n4477744774", "77474444777444447747\n7...
UNKNOWN
PYTHON3
CODEFORCES
1
594a2bc844be518fed9dfa9b8c429849
Buses
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly *n*<=+<=1 bus stops. All of them are numbered with integers from 0 to *n* in the order in which ...
[ "from bisect import bisect_left\r\nfrom collections import defaultdict\r\nd=defaultdict(list)\r\n\r\nn,m=map(int,input().split())\r\nbus=[]\r\nseen=set()\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n d[b].append(a)\r\n seen.add(b)\r\n seen.add(a)\r\nseen=sorted(seen)\r\nif n not in seen:\r...
{"inputs": ["2 2\n0 1\n1 2", "3 2\n0 1\n1 2", "5 5\n0 1\n0 2\n0 3\n0 4\n0 5", "3 3\n1 2\n2 3\n1 3", "10 10\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10", "6 6\n3 4\n2 3\n3 5\n0 1\n1 2\n3 6", "7 7\n0 1\n1 3\n2 3\n4 6\n5 7\n4 5\n5 7", "1000000000 0", "8 8\n0 1\n4 5\n7 8\n3 4\n2 3\n6 7\n5 6\n1 2", "6 1\n0 6", "6 4\n...
UNKNOWN
PYTHON3
CODEFORCES
1
596bbbc9d1dd8f16b95163e9dd40dfc4
Toda 2
A group of *n* friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the *i*-th friend is *r**i*. The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team...
[ "# https://codeforces.com/problemset/problem/730/A\r\n# \r\n \r\nimport heapq\r\n\r\ndef solve_for_0(d, max_, ans):\r\n pos_M = list(d[max_])[0]\r\n pos_m = list(d[0])[0]\r\n \r\n for _ in range(max_):\r\n ans.append([pos_M, pos_m]) \r\n\r\ndef solve_one_seg(d, max_, min_, ans):\r\n seg = li...
{"inputs": ["5\n4 5 1 7 4", "2\n1 2", "3\n1 1 1", "10\n6 8 7 6 8 7 6 7 8 7", "5\n4 4 4 7 3", "5\n4 7 5 2 2", "6\n5 4 2 4 3 2", "7\n7 8 2 7 10 11 5", "10\n2 3 3 3 2 6 2 5 3 5", "90\n45 69 0 10 8 58 25 66 22 2 4 62 64 90 82 83 67 32 56 80 64 51 78 21 2 90 65 55 11 51 1 43 6 32 25 46 22 46 26 6 43 14 50 40 74 52 44 60 76 ...
UNKNOWN
PYTHON3
CODEFORCES
2
5981eb223dfdc830bf9b127597cd72c8
Chocolate
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces. You are asked to calculate the number of ways he can...
[ "n=int(input())\r\na = input().split()\r\np = 1;c = 1;f = 0\r\nfor i in a:\r\n\tif i == '1':\r\n\t\tp*=c;c = 1;f = 1\r\n\telse:\r\n\t\tif f:\r\n\t\t\tc+=1\r\nif f:\r\n\tprint (p)\r\nelse:\r\n\tprint (0)", "# 617B CHOCOLATE\r\n\r\n\r\nnumber_of_pieces = int(input())\r\nchocolate_bar = input()\r\n\r\n#omzetten van ...
{"inputs": ["3\n0 1 0", "5\n1 0 1 0 1", "10\n0 0 1 0 0 0 1 1 0 1", "20\n0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 1 0", "50\n0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0", "99\n0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 1 1 0 ...
UNKNOWN
PYTHON3
CODEFORCES
7
59a8a4fb362b2db5b70755c3f8abc200
Kayaking
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact...
[ "\ninf = float('inf')\n\ndef solve(A, N):\n A.sort()\n N *= 2\n ans = inf\n for i in range(N):\n for j in range(i + 1, N):\n B = []\n for k in range(N):\n if k != i and k != j:\n B.append(A[k])\n\n total = sum(B[i + 1] - B[i] for ...
{"inputs": ["2\n1 2 3 4", "4\n1 3 4 6 3 4 100 200", "3\n305 139 205 406 530 206", "3\n610 750 778 6 361 407", "5\n97 166 126 164 154 98 221 7 51 47", "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3...
UNKNOWN
PYTHON3
CODEFORCES
169
5a03252e08654084ead3b38a23622e60
Square
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa...
[ "import math\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nfor i in a:\r\n print(1 + ((4 * i * (i + 1)) // math.gcd(4 * i ,i + 1)) // (i + 1))", "from math import gcd\r\n\r\nt = int(input())\r\nsides = list(map(int, input().split()))\r\n\r\nfor n in sides:\r\n lcm = (4 * n * (n + 1)) // gcd(4...
{"inputs": ["3\n4 8 100", "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13", "3\n13 17 21"], "outputs": ["17\n33\n401", "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27", "27\n35\n43"]}
UNKNOWN
PYTHON3
CODEFORCES
51
5a234bc7c81e13b4b00b7ffd6934843d
Fruits
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of A...
[ "enter1 = list(map(int, input().split()))\nn = enter1[0]\nm = enter1[1]\n\nli = list(map(int, input().split()))\nfruits = list()\nfor i in range(m):\n fruits.append(input())\n\nse = set(fruits)\nkol_vo = []\nli_se = list(se)\n\nfor i in range(len(li_se)):\n kol_vo.append(fruits.count(li_se[i]))\n\nkol_vo.sort...
{"inputs": ["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl", "1 4\n1\nu\nu\nu\nu", "3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm", "3 4\n10 10 10\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk\nodchpcsdhldqn...
UNKNOWN
PYTHON3
CODEFORCES
114
5a24aa8483eed58623cb80e41be4360e
Three Parts of the Array
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib...
[ "n = int(input())\narr = [int(x) for x in input().split(\" \")]\n\nsoma1 = 0\nsoma2 = 0\nl = 0\nr = n-1\nans = 0\n\nwhile l<=r:\n if soma1 < soma2:\n soma1+=arr[l]\n l += 1\n else:\n soma2 += arr[r]\n r -= 1\n if soma1 == soma2:\n ans = soma1\n\nprint(ans)\n\n\t\t \t\t ...
{"inputs": ["5\n1 3 1 1 4", "5\n1 3 2 1 4", "3\n4 1 2", "1\n1000000000", "2\n1 1", "5\n1 3 5 4 5"], "outputs": ["5", "4", "0", "0", "1", "9"]}
UNKNOWN
PYTHON3
CODEFORCES
213
5a338e4f6ff782ab607304e21f0f2372
DNA Evolution
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string *s* initially. Evolution of the species is described as a sequence of changes...
[ "import sys \r\ninput = sys.stdin.buffer.readline \r\n \r\n\r\nclass SegmentTree:\r\n def __init__(self, data, default=0, func=lambda a, b:a+b):\r\n \"\"\"initialize the segment tree with data\"\"\"\r\n self._default = default\r\n self._func = func\r\n self._len = len(data)\r\n ...
{"inputs": ["ATGCATGC\n4\n2 1 8 ATGC\n2 2 6 TTT\n1 4 T\n2 2 6 TA", "GAGTTGTTAA\n6\n2 3 4 TATGGTG\n1 1 T\n1 6 G\n2 5 9 AGTAATA\n1 10 G\n2 2 6 TTGT", "TCAATCGGGCGGACTAACCC\n20\n2 4 17 CTCGGATGTT\n1 4 T\n1 1 C\n2 15 18 CA\n2 13 20 GGCACCCA\n1 20 T\n2 3 11 TCGGAG\n1 4 C\n2 13 18 A\n1 14 C\n1 18 T\n1 5 T\n1 8 T\n1 6 A\n2 3 ...
UNKNOWN
PYTHON3
CODEFORCES
1
5a3e001f740f7d6ec5e22ec35d23b8a5
none
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has *n* cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to *n* from the left to the right. Unfortunately, ...
[ "n,m,k=map(int,input().split())\r\na=[*map(int,input().split())]\r\nif n%2==0 or (n%2==1 and n//2+1>m):print(0)\r\nelse:\r\n mn=min(a[::2])\r\n k*=m//(n//2+1)\r\n print(min(mn,k))\r\n", "I=lambda:map(int,input().split())\r\nn,m,k=I()\r\na=[*I()]\r\nk*=m//(n//2+1)\r\nprint(min(min(a[::2]),k)*(n%2==1))\r\n...
{"inputs": ["2 3 1\n2 3", "3 2 2\n4 1 3", "5 10 10\n7 0 7 0 7", "6 10 4\n1 2 3 4 5 6", "7 5 2\n1 2 3 4 5 6 7", "16 100 100\n30 89 12 84 62 24 10 59 98 21 13 69 65 12 54 32", "99 999 999\n9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9...
UNKNOWN
PYTHON3
CODEFORCES
4
5a3e4daa29dd1209216eaed32f5c3fa4
Pupils Redistribution
In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ...
[ "n = int(input())\r\nG = {}\r\ns = 0\r\n\r\nfor i in range(1, 6):\r\n G[i] = 0\r\n \r\nfor x in map(int, input().split()):\r\n G[x] += 1\r\n \r\nfor x in map(int, input().split()):\r\n G[x] -= 1\r\n\r\nfor i in range(1,6):\r\n if G[i] % 2 == 1:\r\n print(-1)\r\n exit(0)\r\n s += a...
{"inputs": ["4\n5 4 4 4\n5 5 4 5", "6\n1 1 1 1 1 1\n5 5 5 5 5 5", "1\n5\n3", "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1", "1\n1\n2", "1\n1\n1", "8\n1 1 2 2 3 3 4 4\n4 4 5 5 1 1 1 1", "10\n1 1 1 1 1 1 1 1 1 1\n2 2 2 2 2 2 2 2 2 2", "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5...
UNKNOWN
PYTHON3
CODEFORCES
168
5a43cf8bfbc24f17efa03fa099792295
Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
[ "lists=[]\r\nfor _ in range(int(input())):\r\n lists.append(input())\r\ns=0\r\nfor i in lists:\r\n if i=='Tetrahedron':\r\n s+=4\r\n elif i=='Cube':\r\n s+=6\r\n elif i=='Octahedron':\r\n s+=8\r\n elif i=='Dodecahedron':\r\n s+=12\r\n elif i=='Icosahedron':\r\n s...
{"inputs": ["4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "3\nDodecahedron\nOctahedron\nOctahedron", "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetr...
UNKNOWN
PYTHON3
CODEFORCES
902
5a4bf7ceadb1d94314cfa46d3536750f
New Year Snowmen
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made *n* snowballs with radii equal to *r*1, *r*2, ..., *r**n*. To make a snowman, one nee...
[ "from heapq import *\r\nfrom collections import defaultdict\r\n \r\nn = int(input())\r\nr = map(int, input().split())\r\nassoc = defaultdict(int)\r\nfor ballsize in r:\r\n assoc[ballsize] += 1\r\n \r\navailable = [(-1 * val, key) for key, val in assoc.items()]\r\nheapify(available)\r\nret = []\r\nwhile len(avail...
{"inputs": ["7\n1 2 3 4 5 6 7", "3\n2 2 3", "1\n255317", "6\n1 1 2 2 3 3", "6\n1 2 2 2 3 3", "6\n1 1 2 2 2 2", "6\n1 2 2 3 3 3", "6\n1 1 1 2 2 3", "14\n1 1 2 2 3 3 4 4 4 4 5 5 5 5", "20\n8 2 9 1 1 4 7 3 8 3 9 4 5 1 9 7 1 6 8 8", "20\n1 3 2 2 1 2 3 4 2 4 4 3 1 4 2 1 3 1 4 4", "20\n4 2 2 2 5 2 4 2 2 3 5 2 1 3 1 2 2 5 4 3...
UNKNOWN
PYTHON3
CODEFORCES
9
5a520f7f2910b43b1571de9435761b7a
Xenia and Spies
Xenia the vigorous detective faced *n* (*n*<=≥<=2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to *n* from left to right. Spy *s* has an important note. He has to pass the note to spy *f*. Xenia interrogates the spies in several steps. During one step the spy keeping the important note c...
[ "n,m,s,f = map (int, input().split())\nwatch = {}\nfor i in range (m):\n t,l,r = map (int, input().split())\n watch[t] = (l,r)\ncur = s\nmove,symbol = (1,'R') if s < f else (-1,'L')\nstep = 1\nwhile cur != f:\n if step in watch:\n l,r = watch[step]\n if (l <= cur <= r or\n l <= (cur+move) <= r):\n ...
{"inputs": ["3 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3", "2 3 2 1\n1 1 2\n2 1 2\n4 1 2", "5 11 1 5\n1 1 5\n2 2 2\n3 1 1\n4 3 3\n5 3 3\n6 1 1\n7 4 4\n8 4 5\n10 1 3\n11 5 5\n13 1 5", "4 6 4 2\n2 2 2\n3 3 3\n4 1 1\n10 1 4\n11 2 3\n12 2 4", "7 5 7 6\n1 4 5\n2 7 7\n3 6 6\n4 3 4\n5 1 3", "4 4 3 4\n1 2 4\n2 1 2\n3 3 4\n4 2 ...
UNKNOWN
PYTHON3
CODEFORCES
10
5a587b91d3cc6bf57740e0b2e69de3a2
Factory
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu...
[ "a, m = map(int, input().split())\r\ns = set()\r\nwhile True:\r\n a %= m\r\n if a in s:\r\n print('Yes' if 0 in s else 'No')\r\n break\r\n s.add(a)\r\n a *= 2\r\n", "# _\r\n###################################################################################################################...
{"inputs": ["1 5", "3 6", "1 8", "2 3", "3 24", "1 1", "100000 100000", "1 99989", "512 2", "100 24", "1 100000", "100000 1", "3 99929", "99961 99971", "1 65536", "4 65536", "3 65536", "32768 65536", "65535 65536", "1 65535", "98812 100000", "10 5", "6 8"], "outputs": ["No", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "No...
UNKNOWN
PYTHON3
CODEFORCES
143
5a5e1e98fe1734fbbdcb54b182736712
Almost Arithmetical Progression
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: - *a*1<==<=*p*, where *p* is some integer; - *a**i*<==<=*a**i*<=-<=1<=+<=(<=-<=1)*i*<=+<=1·...
[ "n=int(input())\r\narr=[0]+list(map(int,input().split()))\r\ndp=[[0]*(n+1) for _ in range(n+1)]\r\nans=0\r\nfor i in range(1,n+1):\r\n pos=0\r\n for j in range(i):\r\n dp[i][j]=max(dp[i][j],1+dp[j][pos])\r\n if arr[j]==arr[i]:\r\n pos=j\r\n ans=max(ans,dp[i][j])\r\nprint(ans)\r...
{"inputs": ["2\n3 5", "4\n10 20 10 30", "5\n4 4 3 5 1", "6\n2 3 2 2 1 3", "8\n2 2 5 3 4 3 3 2", "2\n468 335", "1\n170", "5\n479 359 963 465 706", "6\n282 828 962 492 996 943", "8\n437 392 605 903 154 293 383 422", "42\n68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 48 27 72 39 70 13 ...
UNKNOWN
PYTHON3
CODEFORCES
16
5a69561084767484a896765b580a3e2c
The Eternal Immortality
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno...
[ "l = input().split(\" \")\r\nn =int(l[0])\r\nm = int(l[1])\r\nres=1\r\nif m-n>=10:\r\n print(0)\r\nelse:\r\n while m>n:\r\n \tres = ((m%10)*res)%10\r\n \tm-=1\r\n print(res)", "# Author : Mohamed Yousef \r\n# Date : 2022-12-06\r\nimport sys,math,bisect,collections,itertools,heapq\r\nfrom co...
{"inputs": ["2 4", "0 10", "107 109", "10 13", "998244355 998244359", "999999999000000000 1000000000000000000", "2 3", "3 15", "24 26", "14 60", "11 79", "1230 1232", "2633 2634", "535 536", "344319135 396746843", "696667767 696667767", "419530302 610096911", "238965115 821731161", "414626436 728903812", "274410639 293...
UNKNOWN
PYTHON3
CODEFORCES
275
5a6cf8639416a46ab7eda2b3000d21e2
Simple Game
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*. Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n*...
[ "n,m = [int(i) for i in input().split()]\r\nprint(m+1 if m<=n/2.0 else max(m-1,1))\r\n", "n, m = map(int,input().split())\nprint( 1 if n==1 else (m+(-1 if m-1 >= n-m else +1)) )", "import sys\r\nimport math\r\ninput=sys.stdin.readline\r\nn,m=list(map(int,input().strip().split(\" \")))\r\nif(n==m==1):\r\n pri...
{"inputs": ["3 1", "4 3", "5 5", "10 5", "20 13", "51 1", "100 50", "100 51", "100 49", "1000000000 1000000000", "1000000000 1", "1000000000 100000000", "1000000000 500000000", "1000000000 123124", "12412523 125123", "54645723 432423", "1 1", "262833325 131416663", "477667530 238833766", "692501734 346250868", "9073359...
UNKNOWN
PYTHON3
CODEFORCES
120
5a88c52a8e48a0bb5db9c989b05f3b7c
Safe cracking
Right now you are to solve a very, very simple problem — to crack the safe. Four positive integers stand one by one on a circle protecting the safe. You know that to unlock this striking safe you have to make all four numbers equal to one. Operations are as follows: you may choose two adjacent numbers and increase both...
[ "from sys import stdin\r\ninput = stdin.buffer.readline\r\n\r\nans = ''\r\ndef f(a, b, c):\r\n global ans\r\n if (a & 1) & (b & 1) and not a == b == 1:\r\n ans += f'+{c}\\n'\r\n a += 1\r\n b += 1\r\n while (a & 1 ^ 1) & (b & 1 ^ 1):\r\n ans += f'/{c}\\n'\r\n a >>= 1\r\n ...
{"inputs": ["1 2 4 2", "3 3 1 1", "2 1 2 4", "5 5 1 1", "4 4 4 4", "1 1 1 2", "1 1 1 3", "1 2 1 2", "657276544 772661397 705084822 888450280", "414333101 226069413 997273309 495622139", "242246693 78731970 483090981 265550001", "688606352 535518276 574101164 397812691", "214168203 414790853 766098599 644798097", "28588...
UNKNOWN
PYTHON3
CODEFORCES
4
5aadac2815c9ae74cba7aae270fa2bab
Tavas and Nafas
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without...
[ "first = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen',\r\n 'fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']\r\nsecond = ['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']\r\n\r\nn = int(input())\r\n\r\nif(n < 20):...
{"inputs": ["6", "99", "20", "10", "15", "27", "40", "63", "0", "1", "2", "8", "9", "11", "12", "13", "14", "16", "17", "18", "19", "21", "29", "30", "32", "38", "43", "47", "50", "54", "56", "60", "66", "70", "76", "80", "82", "90", "91", "95", "71", "46", "84", "22", "23", "24", "25", "26", "28", "31", "33", "34", "3...
UNKNOWN
PYTHON3
CODEFORCES
95
5aadd7c6ae2e239904112e924628ef9b
Swap Adjacent Elements
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array. For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T...
[ "n=int(input())\r\na=input().split()\r\nb=input()+'1'\r\nc=[]\r\nk=0\r\nfor u in b:\r\n c.append(k)\r\n if u=='0':\r\n k+=1\r\nfor i in range(0,n):\r\n if c[i]!=c[int(a[i])-1]:\r\n print('NO')\r\n exit()\r\nprint('YES')\r\nexit()\r\n", "n = int(input())\r\na = list(map(int, input().s...
{"inputs": ["6\n1 2 5 3 4 6\n01110", "6\n1 2 5 3 4 6\n01010", "6\n1 6 3 4 5 2\n01101", "6\n2 3 1 4 5 6\n01111", "4\n2 3 1 4\n011", "2\n2 1\n0", "5\n1 2 4 5 3\n0101", "5\n1 2 4 5 3\n0001", "5\n1 4 5 2 3\n0110", "5\n4 5 1 2 3\n0111", "3\n3 1 2\n10", "5\n2 3 4 5 1\n0011", "16\n3 4 14 16 11 7 13 9 10 8 6 5 15 12 1 2\n11111...
UNKNOWN
PYTHON3
CODEFORCES
85
5ab9c601c9a94cdb1168ab643f4355bf
Lieges of Legendre
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are *n* piles of cows, with the *i*-th pile containing *a**i* cows. During each player's turn, that player calls upon...
[ "b= lambda: map(int, input().split())\nn, k = b()\ns = 0\nfor a in b():\n d = 0\n while a & 1 << d == 0: d += 1\n t = (a == 3 << d) ^ (d & 1)\n x = a & 1 if a < 4 else 0 if a & 1 else 2 - t\n y = a if a < 3 else a & 1 ^ 1\n s ^= x if k & 1 else y\nprint('Kevin' if s else 'Nicky')\n\t \t \t \t ...
{"inputs": ["2 1\n3 4", "1 2\n3", "4 5\n20 21 22 25", "5 1\n1 7 7 6 6", "7 1\n8 6 10 10 1 5 8", "10 1\n2 3 5 2 7 4 7 7 4 2", "10 1\n5 6 3 10 6 6 1 1 5 3", "6 1\n1 4 4 4 2 2", "10 2\n3 10 10 8 6 10 9 9 5 7", "6 2\n5 3 5 6 2 2", "9 2\n8 2 9 4 7 5 2 4 9", "9 2\n2 8 4 2 5 7 1 8 10", "7 2\n9 1 7 6 10 3 5", "2 2\n1 2", "2 2\...
UNKNOWN
PYTHON3
CODEFORCES
2
5aba9714089213b40d5a9627e3af22e9
Replacing Digits
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. ...
[ "s = list(input())\r\na = sorted(input(), reverse = True)\r\n\r\ni = 0 # индексы по s\r\nj = 0 # индексы по a\r\n\r\nwhile i < len(s) and j < len(a):\r\n \r\n if a[j]>s[i]:\r\n s[i] = a[j]\r\n j+=1\r\n i+=1\r\n \r\nprint(*s, sep = \"\")", "a = [i for i in input()]\r\ns = sorted([i for i ...
{"inputs": ["1024\n010", "987\n1234567", "10\n1", "11\n1", "12\n2", "1\n0", "123456\n9999", "909090\n000111", "588\n24", "25206\n88", "9776247464\n8629", "3666566898\n3001", "3338860467\n5848", "9768757689\n1010", "6669490269\n6240849376", "1794210278\n50931901955213461294", "6997854871\n15113453341706470344", "8947769...
UNKNOWN
PYTHON3
CODEFORCES
61
5abfc1559fdbd07702d539e4c4bf2ae9
Mahmoud and a Triangle
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments...
[ "n = int(input())\r\na = list(sorted([int(i) for i in input().split()]))\r\nflag = True\r\nfor i in range(2, n):\r\n if a[i - 2] + a[i - 1] > a[i] and flag:\r\n print('YES')\r\n flag = False\r\nif flag:\r\n print('NO')", "n=int(input())\r\nl=sorted(list(map(int,input().split())))\r\nfor i in r...
{"inputs": ["5\n1 5 3 2 4", "3\n4 1 2", "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576", "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 17711539...
UNKNOWN
PYTHON3
CODEFORCES
269
5ae999481a4320688b1d6b02a240dada
Queue
There are *n* schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes. Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginni...
[ "def main():\r\n s = input()\r\n cnt, ans = 0, 0\r\n for c in s:\r\n if c == \"M\":\r\n cnt += 1\r\n if c == \"F\" and cnt:\r\n ans = max(ans+1, cnt)\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "s = input()\nans, m = 0, 0\nfor c in s:\...
{"inputs": ["MFM", "MMFF", "FFMMM", "MMFMMFFFFM", "MFFFMMFMFMFMFFFMMMFFMMMMMMFMMFFMMMFMMFMFFFMMFMMMFFMMFFFFFMFMFFFMMMFFFMFMFMFMFFFMMMMFMMFMMFFMMMMMMFFM", "MFFMFMFFMM", "MFFFFFMFFM", "MMMFMFFFFF", "MMMMMFFMFMFMFMMFMMFFMMFMFFFFFFFMFFFMMMMMMFFMMMFMFMMFMFFMMFMMMFFFFFMMMMMFMMMMFMMMFFMFFMFFFMFFMFFMMFFM", "MMMMFMMMMMFFMMFMFMM...
UNKNOWN
PYTHON3
CODEFORCES
6
5af3996112509cc07f8add53fa6f0c12
Cookies
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in...
[ "n = int(input())\r\nif n == 0:\r\n print(1)\r\nelse:\r\n ans = 1\r\n for i in range(n - 1):\r\n ans *= 3\r\n print(ans % 1000003)", "mod=1000003\r\nc=int(input())\r\nans=1\r\ni = 2\r\nwhile i<=c:\r\n ans=(ans%mod + (ans%mod * 2)%mod)%mod\r\n i+=1\r\n \r\nprint(ans)", "print(pow(3,ma...
{"inputs": ["3", "1", "2", "4", "6", "11", "14", "15", "7", "0", "1000", "657", "561", "823", "850", "298", "262", "910", "617", "857", "69", "589", "928", "696", "226"], "outputs": ["9", "1", "3", "27", "243", "59049", "594320", "782957", "729", "1", "691074", "874011", "842553", "858672", "557186", "999535", "946384"...
UNKNOWN
PYTHON3
CODEFORCES
46
5af75c396e8515ffc1c890d93db329c3
Shell Game
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so ...
[ "f = open(\"input.txt\",\"r\")\r\nv = open(\"output.txt\",\"w\")\r\nx = int(f.readline())\r\n#y = f.readline()\r\n#print(int(y[0]),int(y[2]))\r\nlst = [1, 2, 3]\r\nq = []\r\ncpy = list(lst)\r\n\r\nfor i in range(3):\r\n o = f.readline()\r\n q = [int(o[0]) - 1 , int(o[2]) - 1]\r\n #print(q)\r\n lst[q[0]]...
{"inputs": ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3", "3\n3 1\n2 1\n1 2", "1\n1 3\n1 2\n2 3", "3\n3 2\n3 1\n3 1", "1\n2 1\n1 3\n1 3", "3\n3 1\n2 3\n3 2", "2\n1 3\n1 2\n2 1", "1\n1 3\n3 2\n1 2", "1\n1 3\n1 3\n2 3", "2\n1 2\n2 3\n2 1", "3\n1 3\n3 2\n2 1", "1\n1 2\n2 1\n2 3", "1\n2 3\n1 3\n1 2", "2\n3 1\n3 2\n2 3", "2\n1 3\...
UNKNOWN
PYTHON3
CODEFORCES
99
5b1f6ea3b80876a99fa3edeb8b62611e
none
As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers *k* and *p*, w...
[ "M = 10**9 + 7\n\n\ndef period(p, k):\n c = 1\n ek = k\n while ek != 1:\n ek = (ek * k) % p\n c += 1\n return c\n\n\ndef functions(p, k):\n if k == 0:\n return pow(p, p-1, M)\n elif k == 1:\n return pow(p, p, M)\n else:\n c = (p-1)//period(p, k)\n retur...
{"inputs": ["3 2", "5 4", "7 2", "7 6", "10007 25", "40037 4", "5 0", "5 3", "7 1", "13 5", "13 4", "5 2", "11 1", "11 10", "6907 2590", "3229 153", "727 282", "7621 6195", "4649 4648", "5527 1711", "1901 633", "463 408", "6871 5566", "4177 556", "65213 29960", "375103 52131", "990037 453792", "95531 94787", "498653 11...
UNKNOWN
PYTHON3
CODEFORCES
16
5b430d79388af1e2fbbc9587b9a391b7
Brain Network (medium)
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology ...
[ "def solution(idx):\r\n visited = [False] * n # visited\r\n max_distance = (0, idx) # (distance, index)\r\n stack = [max_distance] # stack\r\n while stack:\r\n distance, idx = stack.pop() # distance, index\r\n visited[idx] = True\r\n if distance > max_distance[0]:\r\n ...
{"inputs": ["2 1\n1 2", "3 2\n2 1\n3 2", "10 9\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4", "4 3\n1 2\n1 3\n1 4", "5 4\n1 2\n2 3\n3 4\n3 5"], "outputs": ["1", "2", "6", "2", "3"]}
UNKNOWN
PYTHON3
CODEFORCES
21
5b996c84a4e9b643847702897cd4376e
Shovel Sale
There are *n* shovels in Polycarp's shop. The *i*-th shovel costs *i* burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with ...
[ "n = int(input())\r\nl = 9\r\nk = 0\r\nwhile True:\r\n p = l//2+1\r\n if n>=p:\r\n k+=1\r\n l = l*10+9\r\n else:\r\n break\r\nif k==0:\r\n print((n*(n-1))//2)\r\nelse:\r\n l = \"9\"*k\r\n l = int(l)\r\n z = l+1\r\n cnt = 0\r\n for i in range(9):\r\n p = z*i+l\r...
{"inputs": ["7", "14", "50", "999999999", "15", "3", "6500", "4", "13", "10", "499999", "6", "8", "9", "11", "12", "5", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "4...
UNKNOWN
PYTHON3
CODEFORCES
15
5bb0e40b287748d6afecc3d5be073136
Anya and Ghosts
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by *m* ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly *t* seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one...
[ "import sys,math,heapq,queue\r\nfast_input=sys.stdin.readline \r\nm,t,r=map(int,fast_input().split())\r\na=list(map(int,fast_input().split())) \r\nif t<r:\r\n print(-1)\r\nelse:\r\n count=0 \r\n heap=[] \r\n for i in a:\r\n while heap and heap[0]+t<=i:\r\n heapq.heappop(heap) \r\n \...
{"inputs": ["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10", "21 79 1\n13 42 51 60 69 77 94 103 144 189 196 203 210 215 217 222 224 234 240 260 282", "125 92 2\n1 2 3 4 5 7 8 9 10 12 17 18 20 21 22 23 24 25 26 28 30 32 33 34 35 36 37 40 41 42 43 44 45 46 50 51 53 54 55 57 60 61 62 63 69 70 74 75 77 79 80 81 82 83 84 85 86 88 8...
UNKNOWN
PYTHON3
CODEFORCES
9
5bb44940fe915dd1fa210408ac57c145
Yet Another Maxflow Problem
In this problem you will have to deal with a very special network. The network consists of two parts: part *A* and part *B*. Each part consists of *n* vertices; *i*-th vertex of part *A* is denoted as *A**i*, and *i*-th vertex of part *B* is denoted as *B**i*. For each index *i* (1<=≤<=*i*<=&lt;<=*n*) there is a dire...
[ "import heapq\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef make_graph(n, m):\r\n x, y, s = [0] * (2 * m), [0] * m, [0] * (n + 3)\r\n for i in range(0, 2 * m, 2):\r\n u, v, w = map(int, input().split())\r\n s[u + 2] += 1\r\n x[i], x[i + 1...
{"inputs": ["4 3 2\n1 2\n3 4\n5 6\n2 2 7\n1 4 8\n4 3 9\n1 100\n2 100", "10 10 10\n291546518 199012865\n327731857 137263959\n145140225 631959974\n559674936 815057131\n677050070 949982094\n839693202 160045764\n967872826 489258292\n706535160 594950620\n230389718 274785590\n1 10 861488983\n7 10 994974516\n4 3 117635148\n6 ...
UNKNOWN
PYTHON3
CODEFORCES
1
5bea950a4b3692c0b55275b4bd4d1133
Conan and Agasa play a Card Game
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it. They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he remov...
[ "input()\r\nd={}\r\nc=0\r\nfor i in input().split():\r\n d[i] = d.get(i,0)+1;c+=d[i]%2*2-1\r\nprint([\"Conan\",\"Agasa\"][not c])", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\na.sort(reverse=True)\r\nai = [1] * n\r\n\r\nj = 0\r\nfor i in range(1, n):\r\n if a[i] == a[i - 1]:\r\n a...
{"inputs": ["3\n4 5 7", "2\n1 1", "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282", "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165", "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176", "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846", "3\n1 2 3", "4\n2 3...
UNKNOWN
PYTHON3
CODEFORCES
70
5c05aa54bdafe322b5a3076e15032999
Ping-Pong (Easy Version)
In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=&lt;<=*a*<=&lt;<=*d* or *c*<=&lt;<=*b*<=&lt;<=*d*. Also there is a path from interval *I*1 from our set to interval *I*2 from our set if there is a seq...
[ "\r\nn = 0;\r\ndef dfs(i):\r\n vis[i] = 1;\r\n for k in range(n+1):\r\n if vis[k] == 1:\r\n continue;\r\n if (a[i] > a[k] and a[i] < b[k]):\r\n dfs(k);\r\n elif(b[i] > a[k] and b[i] < b[k]):\r\n dfs(k);\r\n \r\n \r\n\r\nk = int(input());\...
{"inputs": ["5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2", "10\n1 -311 -186\n1 -1070 -341\n1 -1506 -634\n1 688 1698\n2 2 4\n1 70 1908\n2 1 2\n2 2 4\n1 -1053 1327\n2 5 4", "10\n1 -1365 -865\n1 1244 1834\n2 1 2\n1 -1508 -752\n2 3 2\n2 2 1\n1 -779 595\n1 -1316 877\n2 2 1\n1 -698 1700", "20\n1 1208 1583\n1 -258 729\n1 -409 1201\...
UNKNOWN
PYTHON3
CODEFORCES
43
5c31552aa05de8e16664f4d645bf4d91
Longtail Hedgehog
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of *n* points connected by *m* segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a...
[ "n,m=map(int,input().split())\r\ngraph=[[] for _ in range(n)]\r\nfor _ 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\ndp=[0]*n\r\ndp[0]=1\r\nfor i in range(1,n):\r\n for child in graph[i]:\r\n if child<i:\r\n dp[i]...
{"inputs": ["8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 7\n1 3\n2 4\n4 5\n5 3\n2 1\n1 4\n3 2", "5 9\n1 3\n2 4\n4 5\n5 3\n2 1\n1 4\n3 2\n1 5\n2 5", "10 10\n6 3\n2 9\n9 4\n4 5\n10 3\n8 3\n10 5\n7 6\n1 4\n6 8", "100 50\n66 3\n92 79\n9 44\n84 45\n30 63\n30 20\n33 86\n8 83\n40 75\n7 36\n91 4...
UNKNOWN
PYTHON3
CODEFORCES
10
5c4478806ba085b0df028f9fe6a6e89b
Harry Potter and the Sorting Hat
As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a hat on his head and, after some thought, the hat solemnly announces the nam...
[ "import sys\nfrom typing import Set, List\n\nN = 0\nseq = ''\n\n\ndef read_input():\n global N, seq\n readline = sys.stdin.readline\n N = int(readline().rstrip())\n seq = readline().rstrip()\n\ndef solve():\n dp: Set[tuple] = {(0, 0, 0, 0)}\n order = {ch: i for i, ch in enumerate('GHRS')}\n for...
{"inputs": ["11\nG????SS???H", "2\nH?", "1\n?", "1\nG", "3\nGHS", "4\n????", "5\nGH??S", "5\nH?S?G", "7\n???????", "10\n??HS??HSGR", "55\n??RS?HGH?S?GS?HRGHRHRR?G?GSGSSHGS?HRSHRSR?HGHGRH?GGGHHH", "108\n??RS?HGH?S?GS?HRGHRHRR?G?GSGSSHGS?HRSHRSR?HGHGRH??????????????RS?HGH?S?GS?HRGHRHRR?G?GSGSSHGS?HRSHRSR?HGHGRH", "20\n?H...
UNKNOWN
PYTHON3
CODEFORCES
2
5c467ca04386f97d028df6a21043acfd
Mischievous Mess Makers
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limeligh...
[ "n, k = map(int, input().split())\r\nans = 0\r\nd = n\r\nfor i in range(min(k, n // 2)):\r\n ans += (d*2-3)\r\n d -= 2\r\nprint(ans)", "__author__ = 'Utena'\r\nn,k=map(int,input().split())\r\nt=0\r\nfor i in range(k):\r\n if n<2:break\r\n else:\r\n t+=2*n-3\r\n n-=2\r\nprint(t)", "n, k...
{"inputs": ["5 2", "1 10", "100000 2", "1 1", "8 3", "7 1", "100000 40000", "1 1000", "100 45", "9 2", "456 78", "100000 50000", "100000 50001", "100000 50002", "100000 50003", "100000 49998", "100000 49997", "99999 49998", "99999 49997", "99999 49996", "99999 50000", "99999 50001", "99999 50002", "30062 9", "13486 3",...
UNKNOWN
PYTHON3
CODEFORCES
87
5c49c54a42a6a4ed55defba272f7a724
Shop
Vasya plays one very well-known and extremely popular MMORPG game. His game character has *k* skill; currently the *i*-th of them equals to *a**i*. Also this game has a common rating table in which the participants are ranked according to the product of all the skills of a hero in the descending order. Vasya decided t...
[ "def euclid(a, b):\n\tif b == 0:\n\t\treturn (1, 0, a)\n\telse:\n\t\t(x, y, g) = euclid(b, a%b)\n\t\treturn (y, x - a//b*y, g)\n\ndef modDivide(a, b, p):\n\t(x, y, g) = euclid(b, p)\n\treturn a // g * (x + p) % p\n\ndef comb(n, k):\n\treturn modDivide(fac[n], fac[k] * fac[n-k] % P, P)\n\nk, n, m = list(map(int, inp...
{"inputs": ["2 4 3\n13 20\n1 1 14\n1 2 30\n2 1 6\n3 2 2", "1 0 0\n1", "1 1 1\n1\n3 1 8", "1 1 1\n1\n2 1 8", "1 1 1\n1\n1 1 8", "1 0 0\n8", "1 1 1\n8\n3 1 8", "1 1 1\n8\n2 1 8", "1 1 1\n8\n1 1 8", "2 10 10\n8 8\n1 2 8\n1 1 8\n1 1 8\n1 1 8\n1 2 8\n1 2 8\n1 2 8\n1 1 8\n1 1 8\n1 2 8", "10 7 6\n7 1 8 7 1 2 1 3 3 5\n3 1 5\n3...
UNKNOWN
PYTHON3
CODEFORCES
1
5c6b49b83886363de94d6f84869ae958
Next Round
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate...
[ "n, k = map(int, input().split())\r\nscores = list(map(int, input().split()))\r\n\r\nt = 0\r\nmin_score = scores[k-1]\r\nfor s in scores:\r\n if s >= min_score and s > 0:\r\n t += 1\r\nprint(t)\r\n ", "import decimal\nimport math\nimport sys\nimport time\ninp=input().split()\nnum=int(inp[0])\nk=i...
{"inputs": ["8 5\n10 9 8 7 7 7 5 5", "4 2\n0 0 0 0", "5 1\n1 1 1 1 1", "5 5\n1 1 1 1 1", "1 1\n10", "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "5 5\n3 2 1 0 0", "8 6\n10 9 8 7 7 7 5 5", "8 7\n10 9 8 7 7 7 5 5", "8 4\n10 9 8 7 7 7 5 5", "8 3\n10 9 8 7 7 7 5 5", "8 1\n10 9 8 7 7 7 5 5", "8 2\n10 9 8 7 7 7 5 5", "...
UNKNOWN
PYTHON3
CODEFORCES
235
5c7e34e3e37936ee6716f219e3a22ed8
One-Based Arithmetic
Prof. Vasechkin wants to represent positive integer *n* as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum. The first line of the input contains integer *n* (1<=≤<=*n*<=&lt;<=1015)...
[ "\"\"\"\r\nCodeforces Testing Round 10 Problem C\r\n\r\nAuthor : chaotic_iak\r\nLanguage: Python 3.3.4\r\n\"\"\"\r\n\r\ndef read(mode=2):\r\n # 0: String\r\n # 1: List of strings\r\n # 2: List of integers\r\n inputs = input().strip()\r\n if mode == 0:\r\n return inputs\r\n if mode == 1:\r\...
{"inputs": ["121", "10", "72", "1", "2", "3", "4", "5", "6", "7", "11", "12", "2038946593", "81924761239462", "973546235465729", "999999999999999", "21", "79", "33", "185", "513", "634", "5300", "3724", "2148", "82415", "35839", "79263", "274634", "690762", "374186", "2673749", "5789877", "1873301", "30272863", "333889...
UNKNOWN
PYTHON3
CODEFORCES
8
5ca219f9efcff505576207e1dd0ceb89
Treasure Hunt
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be perfo...
[ "import sys\r\ninput=sys.stdin.readline\r\nfrom collections import defaultdict as dc\r\nfrom collections import Counter\r\nfrom bisect import bisect_right, bisect_left,bisect\r\nimport math\r\nfrom operator import itemgetter\r\nfrom heapq import heapify, heappop, heappush\r\nx1,y1,x2,y2=map(int,input().split())\r\n...
{"inputs": ["0 0 0 6\n2 3", "1 1 3 6\n1 5", "5 4 6 -10\n1 1", "6 -3 -7 -7\n1 2", "2 -5 -8 8\n2 1", "70 -81 -17 80\n87 23", "41 366 218 -240\n3456 1234", "-61972 -39646 -42371 -24854\n573 238", "-84870 -42042 94570 98028\n8972 23345", "-58533 -50999 -1007 -59169\n8972 23345", "-100000 -100000 100000 100000\n100000 10000...
UNKNOWN
PYTHON3
CODEFORCES
166
5cbdab2b174eb6f2360e10275bea52ea
Polycarp and Letters
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters. Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met: - letters on positions from *A* in the string are all distinct and lowerc...
[ "n = int(input())\r\ns = str(input())\r\nres = 0\r\n\r\nfor start in range(n):\r\n vals = set()\r\n for end in range(start, n):\r\n if s[end].islower():\r\n vals.add(s[end])\r\n else:\r\n break\r\n\r\n res = max(res, len(vals))\r\nprint(res)", "##a = list(map(int, ...
{"inputs": ["11\naaaaBaabAbA", "12\nzACaAbbaazzC", "3\nABC", "1\na", "2\naz", "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh", "2\nAZ", "28\nAabcBabcCBNMaaaaabb...
UNKNOWN
PYTHON3
CODEFORCES
115
5cd7e775c7c97932f3b29d2af3121b29
Jeff and Periods
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold: - *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ...
[ "n= int(input())\r\nt = list(map(int,input().split()))\r\nu=[]\r\nf={}\r\np=0\r\nfor j in range(n):\r\n if t[j] not in f:\r\n f[t[j]]=[0,j]\r\n else:\r\n if f[t[j]][0]==0:\r\n f[t[j]][0]= j-f[t[j]][-1]\r\n f[t[j]].append(j)\r\n elif f[t[j]][0]!='a':\r\n if...
{"inputs": ["1\n2", "8\n1 2 1 3 1 2 1 5", "3\n1 10 5", "4\n9 9 3 5", "6\n1 2 2 1 1 2", "6\n2 6 3 8 7 2", "7\n2 1 2 1 2 1 2", "8\n1 1 1 1 1 1 1 1", "9\n2 3 3 3 2 1 2 3 2", "10\n3 1 1 1 1 3 1 2 2 1", "12\n10 9 8 7 7 8 9 10 10 9 8 7"], "outputs": ["1\n2 0", "4\n1 2\n2 4\n3 0\n5 0", "3\n1 0\n5 0\n10 0", "3\n3 0\n5 0\n9 1",...
UNKNOWN
PYTHON3
CODEFORCES
64
5cf7fec69f77240413a6649520c63d03
Help General
Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot h...
[ "n,m=sorted(list(map(int,input().split())))\r\nif n==1:\r\n print(m)\r\nelif n==2:\r\n print(4*((n*m)//8)+min((n*m)%8,4))\r\nelse:\r\n print(n*m//2+n*m%2)", "n, m = map(int, input().split())\r\nif n > m:\r\n n, m = m, n\r\nif n > 2 and m > 2:\r\n print(((n * m) + 1) // 2)\r\nelif n == 1:\r\n pri...
{"inputs": ["2 4", "3 4", "4 4", "4 3", "4 2", "1 1", "3 5", "5 3", "506 44", "555 349", "757 210", "419 503", "515 19", "204 718", "862 330", "494 982", "967 4", "449 838", "635 458", "156 911", "409 295", "755 458", "936 759", "771 460", "563 802", "953 874", "354 720", "915 72", "860 762", "396 387", "675 710", "728...
UNKNOWN
PYTHON3
CODEFORCES
10
5d1998d3222e1d5f64d103af6720a3ee
Trading Business
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
[ "import io, os, sys\n\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\n\n\ndef solve():\n n, m, k = map(int, input().split())\n ps = []\n for _ in range(n):\n input()\n p = []\n for _ in range(m):\n p.append(tuple(map(int, input().split())))\n ps.append(...
{"inputs": ["3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5", "2 1 5\nA\n6 5 5\nB\n10 9 0", "2 2 5\nAbcdefghij\n20 15 20\n10 5 13\nKlmopqrstu\n19 16 20\n12 7 14", "3 1 5\nTomato\n10 7 20\nBanana\n13 11 0\nApple\n15 14 10", "3 2 11\nMars\n15 10 4\n7 6 3\nSnickers\n20 17 2\n...
UNKNOWN
PYTHON3
CODEFORCES
13
5d26438dd2e65309025b672de207b5c1
Monsters and Diamonds
Piegirl has found a monster and a book about monsters and pies. When she is reading the book, she found out that there are *n* types of monsters, each with an ID between 1 and *n*. If you feed a pie to a monster, the monster will split into some number of monsters (possibly zero), and at least one colorful diamond. Mon...
[ "import sys\r\n\r\n_BLANCO, _GRIS, _NEGRO = 0, 1, 2\r\n_OO = int(1e18)\r\n\r\n\r\nclass Regla:\r\n def __init__(self, id, diamantes, deMonstruo, monstruos):\r\n self.id = id\r\n self.diamantes = diamantes\r\n self.deMonstruo = deMonstruo\r\n self.monstruos = monstruos\r\n\r\n\r\ndef e...
{"inputs": ["6 4\n1 3 -1 1 -1\n1 2 -1 -1\n2 3 -1 3 -1\n2 3 -1 -1 -1\n3 2 -1 -1\n4 2 4 -1", "3 2\n1 2 1 -1\n2 2 -1 -1\n2 3 2 1 -1", "2 1\n1 3 -1 1 -1\n1 5 -1 -1 -1 -1 -1", "5 4\n1 2 2 -1\n2 2 1 -1\n3 4 4 4 4 -1\n4 3 -1 -1 -1\n3 5 -1 -1 -1 -1 -1", "11 10\n1 9 -1 -1 -1 -1 -1 -1 -1 -1 -1\n1 10 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...
UNKNOWN
PYTHON3
CODEFORCES
1
5d4fdd95fa479ea92ad5478277d97c62
Zebra Tower
Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color *c**i* and size *s**i*. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the c...
[ "from collections import defaultdict\r\nn=int(input())\r\ng=defaultdict(list)\r\nfor i in range(n):\r\n c,s=map(int,input().strip().split())\r\n g[c].append((s,i+1))\r\npref=defaultdict(list)\r\nfor i in g:\r\n g[i].sort(key=lambda s:s[0],reverse=True)\r\n pre=g[i][0][0]\r\n sz=1\r\n pref[sz].ap...
{"inputs": ["4\n1 2\n1 3\n2 4\n3 3", "2\n1 1\n2 1", "3\n1 2\n2 2\n2 1", "4\n2 1\n2 1\n1 1\n1 2", "6\n1 1\n1 1\n2 2\n1 2\n1 2\n2 2", "20\n1 2\n3 2\n4 2\n2 2\n5 2\n2 5\n3 2\n3 4\n4 4\n5 3\n2 1\n5 2\n5 3\n2 1\n5 5\n2 3\n1 5\n5 2\n3 4\n3 3", "100\n2 5\n1 4\n1 2\n5 4\n1 3\n5 2\n4 4\n5 2\n3 5\n2 2\n5 5\n4 5\n5 3\n5 3\n1 1\n1...
UNKNOWN
PYTHON3
CODEFORCES
1
5d6f4738ba2052d7b15af604afb86be9
Sereja and Dima
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
[ "n=int(input())\r\nl=[]\r\nSereja , Dima, i = 0, 0, 0\r\nt=map(int,input().split())\r\nl+=t\r\ny=len(l)\r\na=True\r\nwhile(y!=0):\r\n if(l[0]>=l[y-1]):\r\n x=l[0]\r\n l.pop(0)\r\n else:\r\n x=l[y-1]\r\n l.pop(y-1)\r\n if(a==True):\r\n Sereja+=x\r\n a=False\r\n e...
{"inputs": ["4\n4 1 2 10", "7\n1 2 3 4 5 6 7", "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "1\n3", "45\n553 40 ...
UNKNOWN
PYTHON3
CODEFORCES
867
5d8ef656cdf086c8101d576fae62302e
Square Subsets
Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer. Two ways are considered different if sets of indexes of ele...
[ "import sys\r\nimport os\r\nfrom io import BytesIO\r\n\r\nsys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))\r\n\r\nfct = sys.stdin\r\nif os.environ.get('USER') == \"loic\":\r\n fct = open(\"data.in\")\r\n\r\nline = lambda: fct.readline().split()\r\n\r\ndef write(w):\r\n sys.stdout.write(w)\r\n sys.stdou...
{"inputs": ["4\n1 1 1 1", "4\n2 2 2 2", "5\n1 2 4 5 8", "1\n64", "5\n2 2 2 2 2", "6\n1 2 3 4 5 6", "2\n70 70", "7\n4 9 16 25 36 49 64", "13\n64 65 40 26 36 46 53 31 63 11 2 46 59", "15\n66 34 43 45 61 14 12 67 38 25 55 9 30 41 16", "17\n44 57 54 57 54 65 40 57 59 16 39 51 32 51 20 9 8", "18\n22 41 40 8 36 48 23 5 58 12...
UNKNOWN
PYTHON3
CODEFORCES
11
5dacd674c9a16102502820681cad23bc
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
[ "n = int(input())\narr = []\nfor i in range(n):\n arr.append(list(input()))\n\ncnt = set()\nx = arr[0][0]\ny = arr[0][1]\nans = \"YES\"\nfor i in range(n):\n for j in range(n):\n cnt.add(arr[i][j])\n if i == j or i == n-1-j:\n if arr[i][j] != x:\n ans = \"NO\"\n ...
{"inputs": ["5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "3\nwsw\nsws\nwsw", "3\nxpx\npxp\nxpe", "5\nliiil\nilili\niilii\nilili\nliiil", "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt", "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososoo...
UNKNOWN
PYTHON3
CODEFORCES
157
5db2e7f14bd88a44a444bfbc8f828386
none
Профиль горного хребта схематично задан в виде прямоугольной таблицы из символов «.» (пустое пространство) и «*» (часть горы). Каждый столбец таблицы содержит хотя бы одну «звёздочку». Гарантируется, что любой из символов «*» либо находится в нижней строке матрицы, либо непосредственно под ним находится другой символ «...
[ "def main():\r\n n, m = [int(i) for i in input().split()]\r\n d = [list(input()) for i in range(n)]\r\n \r\n a = [0] * m\r\n for i in range(m):\r\n for j in range(n):\r\n if d[j][i] == '*':\r\n a[i] += 1\r\n \r\n x = y = 0\r\n for i in range(1, m):\r\n ...
{"inputs": ["6 11\n...........\n.........*.\n.*.......*.\n**.......*.\n**..*...**.\n***********", "5 5\n....*\n...**\n..***\n.****\n*****", "8 7\n.......\n.*.....\n.*.....\n.**....\n.**.*..\n.****.*\n.******\n*******", "1 1\n*", "2 2\n**\n**", "1 10\n**********", "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*", "5 5\n.....\n........
UNKNOWN
PYTHON3
CODEFORCES
32
5dda3e0143c8d305726f93da43852f5d
Carrot Cakes
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
[ "n, t, k, d = map(int, input().split())\r\n\r\ng = int((n + k - 1) / k)\r\n\r\no1, o2 = 0, d\r\n\r\ni = 0\r\nwhile i < g:\r\n if o1 <= o2:\r\n o1 += t\r\n else:\r\n o2 += t\r\n\r\n i += 1\r\n\r\nif max(o1, o2) < g * t:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import math\r\nn,...
{"inputs": ["8 6 4 5", "8 6 4 6", "10 3 11 4", "4 2 1 4", "28 17 16 26", "60 69 9 438", "599 97 54 992", "11 22 18 17", "1 13 22 11", "1 1 1 1", "3 1 1 1", "1000 1000 1000 1000", "1000 1000 1 1", "1000 1000 1 400", "1000 1000 1 1000", "1000 1000 1 999", "53 11 3 166", "313 2 3 385", "214 9 9 412", "349 9 5 268", "611 1...
UNKNOWN
PYTHON3
CODEFORCES
280
5df9d8e573c06fc045114e08ee7bca33
Extract Numbers
You are given string *s*. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string *s*=";;" contains three empty words separated by ';'. ...
[ "import re\r\n\r\nstr = input()\r\n\r\nlst = re.split('[,;]', str)\r\n\r\nans1 = []\r\nans2 = []\r\n\r\nfor s in lst:\r\n if s.isdigit() and (s == '0' or s[0] != '0') and s[0] != '-':\r\n ans1.append(s)\r\n else:\r\n ans2.append(s)\r\n\r\n\r\nif len(ans1) == 0:\r\n print('-')\r\nelse:\r\n ...
{"inputs": ["aba,123;1a;0", "1;;01,a0,", "1", "a", ",;,,;", "123;abacab,123;1,sadasfas,123213132g;02131313;aaa,0,012;0;03242;1", ".", ";", "6;2,", "000", "5345rhhr34t.k;k;k;k;k;5677;000000,000000;000098,0.70k;89.;;;", "100.000", ",,;,;,5345rh;hr;34t.k;k;k0,;,0,;k;k;5677.;000000,000000;000098,000.70k;89.;;;", "01", "ash...
UNKNOWN
PYTHON3
CODEFORCES
39
5e4e2e8c7c34063b37d1d4c3797d8ccc
Gadgets for dollars and pounds
Nura wants to buy *k* gadgets. She has only *s* burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for *n* days. For each day you know the exchange rates ...
[ "'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n College: Jalpaiguri Govt Enggineering College\r\n\r\n'''\r\nfrom os import path\r\nfrom io import BytesIO, IOBase\r\nimport sys\r\nfrom heapq import heappush,heappop\r\nfrom functools import cmp_to_key as ctk\r\nfrom collections import deque,Counter,defaultdict a...
{"inputs": ["5 4 2 2\n1 2 3 2 1\n3 2 1 2 3\n1 1\n2 1\n1 2\n2 2", "4 3 2 200\n69 70 71 72\n104 105 106 107\n1 1\n2 2\n1 2", "4 3 1 1000000000\n900000 910000 940000 990000\n990000 999000 999900 999990\n1 87654\n2 76543\n1 65432", "5 5 3 1000000\n921 853 547 187 164\n711 462 437 307 246\n2 94\n2 230\n1 373\n1 476\n2 880",...
UNKNOWN
PYTHON3
CODEFORCES
2
5e5d9db11c7acd51d33b3de0186daa19
Dima and Friends
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
[ "n=int(input())\r\na=list(map(int,input().split()))\r\nk = sum(a)\r\nn+=1\r\nc=0\r\nfor i in range(1,6):\r\n if (k+i)%n==1:\r\n c+=1\r\nprint(5-c)\r\n", "n = int(input())\r\narr = sum(list(map(int,input().split())))\r\ncnt=0\r\nfor i in range(1,6):\r\n if ((arr+i)%(n+1) )!=1:\r\n cnt+=1\r\npri...
{"inputs": ["1\n1", "1\n2", "2\n3 5", "2\n3 5", "1\n5", "5\n4 4 3 5 1", "6\n2 3 2 2 1 3", "8\n2 2 5 3 4 3 3 2", "7\n4 1 3 2 2 4 5", "3\n3 5 1", "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3...
UNKNOWN
PYTHON3
CODEFORCES
646
5e684bd707170b65c68bb4d8d2a77f83
Solitaire
A boy named Vasya wants to play an old Russian solitaire called "Accordion". In this solitaire, the player must observe the following rules: - A deck of *n* cards is carefully shuffled, then all *n* cards are put on the table in a line from left to right; - Before each move the table has several piles of cards lying...
[ "hitler = {}\r\nn = int(input())\r\na = [s for s in input().split()]\r\ndef ok(c1, c2):\r\n return (c1[0] == c2[0]) or (c1[1] == c2[1])\r\ndef dfs(i, c1, c2, c3):\r\n k = (i, c1, c2, c3)\r\n if k in hitler:\r\n return hitler[k]\r\n if i < 0:\r\n hitler[k] = ok(c1, c2) and ok(c1, c3)\r\n ...
{"inputs": ["4\n2S 2S 2C 2C", "2\n3S 2C", "5\n2S 2S 4S 3S 2S", "5\n5S 5S 7S 4S 3H", "5\n7S 7S 4S 8H 4H", "5\n4S 2H 3S 3S 2H", "52\n3H 6S 3S 2S 2S 3S 4S 3H 2C 4S 3C 3S 2S 2C 2S 6S 4C 3S 5C 3S 2S 4S 3S 5S 2H 2S 4H 3S 3S 4H 4S 2C 2H 2S 4S 6D 4C 4H 2H 4S 3H 6D 6S 3C 3C 4H 5S 3S 3S 2H 2S 4C", "52\n2S 4S 3S 2S 4S 3S 4S 4S 8S...
UNKNOWN
PYTHON3
CODEFORCES
1
5e705e49fe98a254385e215185763e89
STL
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer. We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integer...
[ "n = input()\narr = input().split()\nres, s = [], []\nfor i in arr:\n res.append(i)\n while i == 'int' and s and s[-1]:\n res.append('>')\n if s: s.pop()\n if s: s.pop()\n s.append(i == 'int')\n res.append(',' if i == 'int' else '<')\nif res.count('<') == res.count('>'):\n res.po...
{"inputs": ["3\npair pair int int int", "1\npair int", "4\npair pair int int pair int int", "4\npair pair pair int int int int", "5\npair pair int pair int pair int int int", "2\nint int", "1\nint", "2\npair int int", "3\npair pair int int int", "5\npair pair pair pair int int int int int", "6\npair pair pair pair pair...
UNKNOWN
PYTHON3
CODEFORCES
5
5e87611ad3c19c8e572fd38f664c1e27
Foe Pairs
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x...
[ "import sys\r\nif __name__=='__main__':\r\n n,m=map(int,input().split())\r\n line=sys.stdin.readline()\r\n pos={int(v):i for i,v in enumerate(line.split())}\r\n check=[300004]*(n+1)\r\n for line in sys.stdin.readlines():\r\n a,b=map(int,line.split())\r\n if pos[a]>pos[b]:\r\n ...
{"inputs": ["4 2\n1 3 2 4\n3 2\n2 4", "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7", "2 1\n1 2\n1 2", "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1", "50 10\n41 15 17 1 5 31 7 38 30 39 43 35 2 26 20 42 48 25 19 32 50 4 8 10 44 12 9 18 13 36 28 6 27 23 40 24 3 14 29 11 49 47 45 46 34 21 37 16 22 33\n13 48\n24 12\n2 3...
UNKNOWN
PYTHON3
CODEFORCES
16
5ec25699a1e8a3a06113525155678244
Felicity is Coming!
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has *n* gyms. The *i*-th gym has *g**i* Pokemon in it. There are *m* distinct Pokemon types in the Himalayan region numbered from 1 to *m*. There is a special evolution camp...
[ "from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\nl = max(n, m) + 5\r\nfact = [1] * (l + 1)\r\nfor i in range(1, l + 1):\r\n fact[i] = i * fact[i - 1] % mod\r\nx = [[] for _...
{"inputs": ["2 3\n2 1 2\n2 2 3", "1 3\n3 1 2 3", "2 4\n2 1 2\n3 2 3 4", "2 2\n3 2 2 1\n2 1 2", "3 7\n2 1 2\n2 3 4\n3 5 6 7", "10 100\n16 25 7 48 43 16 23 66 3 17 31 64 27 7 17 11 60\n62 76 82 99 77 19 26 66 46 9 54 77 8 34 76 70 48 53 35 69 29 84 22 16 53 36 27 24 81 2 86 67 45 22 54 96 37 8 3 22 9 30 63 61 86 19 16 47...
UNKNOWN
PYTHON3
CODEFORCES
1
5ecc297312cc4b918f5e71caed554d42
New Year Present
The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception. Vasily knows that the best present is (no, it's not a contest) money. He's put *n* empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided...
[ "\r\nimport string\r\n\r\n\r\ndef main_function():\r\n n = int(input())\r\n a = [int(i) for i in input().split(\" \")]\r\n sum_of_a = sum(a)\r\n command_list = []\r\n current_index = 0\r\n right_move = True\r\n while sum_of_a > 0:\r\n if a[current_index] > 0:\r\n sum_of_a -= 1...
{"inputs": ["2\n1 2", "4\n0 2 0 2", "10\n2 3 4 0 0 1 1 3 4 2", "10\n0 0 0 0 0 0 0 0 1 0", "5\n2 2 2 2 2", "2\n6 0"], "outputs": ["PRPLRP", "RPRRPLLPLRRRP", "PRPRPRRRPRPRPRPRPLPLPLLLLLPLPLPRPRPRRRRRPRPRPLPLLLLLLPLL", "RRRRRRRRPR", "PRPRPRPRPLPLPLPLPRRRRP", "PRLPRLPRLPRLPRLP"]}
UNKNOWN
PYTHON3
CODEFORCES
10
5ed7cffa8b0078ab40b7a770e5f54ea3
Sereja and the Arrangement of Numbers
Let's call an array consisting of *n* integer numbers *a*1, *a*2, ..., *a**n*, beautiful if it has the following property: - consider all pairs of numbers *x*,<=*y* (*x*<=≠<=*y*), such that number *x* occurs in the array *a* and number *y* occurs in the array *a*; - for each pair *x*,<=*y* must exist some position *...
[ "import sys, bisect\r\n(n, m), *s = [map(int, s.split()) for s in sys.stdin.readlines()]\r\ng = [n * (n - 1) // 2 + (n - 1) % 2 * (n // 2 - 1) for n in range(1, 2002)]\r\nprint(sum(sorted([w for _, w in s], reverse=True)[:min(m, bisect.bisect_left(g, n))]))", "n,m = map(int,input().split())\r\nq = [0] * (m)\r\nw ...
{"inputs": ["5 2\n1 2\n2 3", "100 3\n1 2\n2 1\n3 1", "1 2\n1 1\n2 100", "25 29\n82963 53706\n63282 73962\n14996 48828\n84392 31903\n96293 41422\n31719 45448\n46772 17870\n9668 85036\n36704 83323\n73674 63142\n80254 1548\n40663 44038\n96724 39530\n8317 42191\n44289 1041\n63265 63447\n75891 52371\n15007 56394\n55630 6008...
UNKNOWN
PYTHON3
CODEFORCES
3
5f055246626e15ae85a2320bf48ff035
Wilbur and Array
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ...
[ "a=int(input())\r\nx=list(map(int,input().split()))\r\nt=abs(x[0])\r\nif a>1:\r\n for i in range(1,a):\r\n t+=abs(x[i-1]-x[i])\r\nprint(t)\r\n", "n=int(input())\r\nl=input().split()\r\nm,s=0,0\r\ndef dif(a,b):\r\n if(a>b):\r\n return a-b\r\n return b-a\r\nfor i in range(n):\r\n x=int(l[i...
{"inputs": ["5\n1 2 3 4 5", "4\n1 2 2 1", "3\n1 2 4", "6\n1 2 3 6 5 4", "10\n2 1 4 3 6 5 8 7 10 9", "7\n12 6 12 13 4 3 2", "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "6\n1000 1 2000 1 3000 1", "1\n0", "5\n1000000000 1 1000000000 1 1000000000", "5\n1000000000 0 1000000000 0 ...
UNKNOWN
PYTHON3
CODEFORCES
183
5f1cd4a396749b78daf8cc5487e0a46a
Tanya and Stairways
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ ...
[ "n=int(input())\r\na=input()\r\na1=a.split()\r\nfor i in range(n): a1[i]=int(a1[i])\r\ns=0\r\nfor i in range(n):\r\n if a1[i]==1: s=s+1\r\nprint(s)\r\nfor i in range(n-1):\r\n if a1[i]>=a1[i+1]: print(a1[i],end=\" \")\r\nprint(a1[-1])\r\n \r\n", "from itertools import groupby\n\ninput()\nans = [\n sum...
{"inputs": ["7\n1 2 3 1 2 3 4", "4\n1 1 1 1", "5\n1 2 3 4 5", "5\n1 2 1 2 1", "1\n1", "48\n1 2 3 4 1 2 3 1 1 2 3 1 2 3 4 1 1 2 3 4 1 2 3 4 1 2 3 4 1 1 2 1 2 1 2 1 1 2 1 2 1 2 3 1 2 1 2 1", "2\n1 2", "3\n1 1 2", "4\n1 1 2 3", "8\n1 2 3 1 2 3 4 5", "5\n1 1 1 2 3"], "outputs": ["2\n3 4 ", "4\n1 1 1 1 ", "1\n5 ", "3\n2 2 1...
UNKNOWN
PYTHON3
CODEFORCES
192
5f292eed4d5faa894c50048b3cebaf39
Lesson Timetable
When Petya has free from computer games time, he attends university classes. Every day the lessons on Petya’s faculty consist of two double classes. The floor where the lessons take place is a long corridor with *M* classrooms numbered from 1 to *M*, situated along it. All the students of Petya’s year are divided into...
[ "import sys\nfrom functools import cache\n\n\nMOD = 10**9 + 7\ndef make_comb_matrix(n: int) -> list:\n comb = [[1] * (n + 1) for i in range(n + 1)]\n for i in range(2, n + 1):\n for j in range(1, i):\n comb[i][j] = (comb[i - 1][j] + comb[i - 1][j -1]) % MOD\n return comb\n\nreadline = sys...
{"inputs": ["3\n1 1 1\n1 2 3", "3\n1 1 1\n1 1 1", "3\n2 1 1\n5 1 2", "5\n2 1 1 1 1\n5 3 1 1 3", "5\n1 3 15 3 18\n2 6 18 5 19", "6\n3 8 2 6 18 2\n6 20 9 6 19 3", "7\n3 4 7 8 6 5 2\n6 12 19 16 15 7 5", "9\n1 1 1 3 6 1 4 2 1\n1 14 1 6 15 2 14 5 2", "9\n7 1 4 7 8 4 5 7 1\n12 10 6 15 13 7 5 17 1", "11\n4 12 2 1 2 9 13 1 12 ...
UNKNOWN
PYTHON3
CODEFORCES
2
5f2c9558381de1736909b582f70980f6
none
Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order. After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in l...
[ "n = int(input())\r\np = [set() for _ in range(26)]\r\na = input()\r\nfor _ in range(n-1):\r\n b = input() \r\n for i in range(min(len(a), len(b))):\r\n if a[i] != b[i]:\r\n p[ord(b[i])-ord('a')].add(ord(a[i])-ord('a'))\r\n for e in p[ord(a[i])-ord('a')]:\r\n p[or...
{"inputs": ["3\nrivest\nshamir\nadleman", "10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer", "10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever", "7\ncar\ncare\ncareful\ncarefully\nbeca...
UNKNOWN
PYTHON3
CODEFORCES
25
5f389135c7741bbbe16125a372058e67
Lomsat gelral
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour *c* dominating in the subtree of vertex *v* if there are no other colours that appear in the subtree of vertex *v* more times than colour *c*. So it's possible that two or more colours will be dominating in the...
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\n\r\nclass SegmentTree:\r\n def __init__(self, n, op, e):\r\n self.n = n\r\n self.op = op\r\n self.e = e\r\n self.size = 2 ** ((n - 1).bit_length())\r\n self.node = [self.e] * (2 * self.size)\r\n\r\n def __getitem__(self...
{"inputs": ["4\n1 2 3 4\n1 2\n2 3\n2 4", "15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13"], "outputs": ["10 9 3 4", "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3"]}
UNKNOWN
PYTHON3
CODEFORCES
10
5f41442c2de274280c23e2f1c8c8dd84
Dice Tower
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). Alice...
[ "import sys\nf = sys.stdin\n#f = open(\"input.txt\", \"r\")\nn = int(f.readline().strip())\nu = int(f.readline().strip())\na, b = [], []\nfor i in f:\n a.append(int(i.split()[0]))\n b.append(int(i.split()[1]))\nc = [[1, 2, 3, 4, 5, 6] for i in range(n)]\nfor i in range(n):\n c[i].remove(a[i])\n c[i].rem...
{"inputs": ["3\n6\n3 2\n5 4\n2 4", "3\n3\n2 6\n4 1\n5 3", "1\n3\n2 1", "2\n2\n3 1\n1 5", "3\n2\n1 4\n5 3\n6 4", "4\n3\n5 6\n1 3\n1 5\n4 1", "2\n2\n3 1\n1 3", "3\n2\n1 4\n3 1\n4 6", "4\n3\n5 6\n1 5\n5 1\n1 5", "5\n1\n2 3\n5 3\n5 4\n5 1\n3 5", "10\n5\n1 3\n2 3\n6 5\n6 5\n4 5\n1 3\n1 2\n3 2\n4 2\n1 2", "15\n4\n2 1\n2 4\n6...
UNKNOWN
PYTHON3
CODEFORCES
243