problem_id
int64
0
5k
question
stringlengths
50
14k
solutions
stringlengths
0
1.21M
input_output
stringlengths
0
74M
difficulty
stringclasses
3 values
url
stringlengths
34
108
starter_code
stringlengths
0
1.1k
solutions_list
listlengths
1
990
n_sols
int64
1
990
non_interactive_idx
listlengths
1
929
interaction_reason
listlengths
1
990
requires_input()
bool
2 classes
1
Mikhail walks on a Cartesian plane. He starts at the point $(0, 0)$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $(0, 0)$, he can go to any of the following points in one move: $(1, 0)$; $(1, 1)$; $(0, 1)$; $(-1, 1)$; $(-1, 0)$; $(-1, -1)$; $(0, -...
["q=int(input())\n\nfor e in range(q):\n x,y,k=list(map(int,input().split()))\n x,y=abs(x),abs(y)\n x,y=max(x,y),min(x,y)\n \n if(x%2!=k%2):\n k-=1\n y-=1\n \n \n if(x>k):\n print(-1)\n continue\n if((x-y)%2):\n k-=1\n x-=1\n print(k)\n \n \n...
{ "inputs": [ "3\n2 2 3\n4 3 7\n10 1 9\n" ], "outputs": [ "1\n6\n-1\n" ] }
interview
https://codeforces.com/problemset/problem/1036/B
[ "q=int(input())\n\nfor e in range(q):\n x,y,k=list(map(int,input().split()))\n x,y=abs(x),abs(y)\n x,y=max(x,y),min(x,y)\n \n if(x%2!=k%2):\n k-=1\n y-=1\n \n \n if(x>k):\n print(-1)\n continue\n if((x-y)%2):\n k-=1\n x-=1\n print(k)\n \n ...
24
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "in...
true
2
You are given three sequences: $a_1, a_2, \ldots, a_n$; $b_1, b_2, \ldots, b_n$; $c_1, c_2, \ldots, c_n$. For each $i$, $a_i \neq b_i$, $a_i \neq c_i$, $b_i \neq c_i$. Find a sequence $p_1, p_2, \ldots, p_n$, that satisfy the following conditions: $p_i \in \{a_i, b_i, c_i\}$ $p_i \neq p_{(i \mod n) + 1}$. In o...
["import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef...
{ "inputs": [ "5\n3\n1 1 1\n2 2 2\n3 3 3\n4\n1 2 1 2\n2 1 2 1\n3 4 3 4\n7\n1 3 3 1 1 1 1\n2 4 4 3 2 2 4\n4 2 2 2 4 4 2\n3\n1 2 1\n2 3 3\n3 1 2\n10\n1 1 1 2 2 2 3 3 3 1\n2 2 2 3 3 3 1 1 1 2\n3 3 3 1 1 1 2 2 2 3\n" ], "outputs": [ "1 2 3\n1 2 1 2\n1 3 4 1 2 1 4\n1 2 3\n1 2 1 2 3 2 3 1 3 2\n" ] }
interview
https://codeforces.com/problemset/problem/1408/A
[ "import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \n...
6
[ -1 ]
[ "sys.stdin.read*()", "input()", "input()", "input()", "input()", "sys.stdin" ]
true
3
You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $x$ and $y$ (the $x$-th barrel shouldn't be empty) and pour any possible ...
["def solve():\n n, k = map(int,input().split())\n lst = list(map(int,input().split()))\n lst.sort()\n ans = 0\n for i in range(n - k - 1, n):\n ans += lst[i]\n print(ans)\nfor i in range(int(input())):\n solve()", "t=int(input())\nfor i in range(t):\n n,k=[int(i) for i in input().split()...
{ "inputs": [ "2\n4 1\n5 5 5 5\n3 2\n0 0 0\n" ], "outputs": [ "10\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1430/B
[ "def solve():\n n, k = map(int,input().split())\n lst = list(map(int,input().split()))\n lst.sort()\n ans = 0\n for i in range(n - k - 1, n):\n ans += lst[i]\n print(ans)\nfor i in range(int(input())):\n solve()", "t=int(input())\nfor i in range(t):\n n,k=[int(i) for i in input().sp...
17
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "sys.stdin", "input()", "input()", "sys.stdin", "stdin-alias.read*()", "input()", "input()", "input()", "input()", "input()" ]
true
4
You are given a permutation $p=[p_1, p_2, \ldots, p_n]$ of integers from $1$ to $n$. Let's call the number $m$ ($1 \le m \le n$) beautiful, if there exists two indices $l, r$ ($1 \le l \le r \le n$), such that the numbers $[p_l, p_{l+1}, \ldots, p_r]$ is a permutation of numbers $1, 2, \ldots, m$. For example, let $p ...
["for _ in range(int(input())):\n input()\n nums = [int(x) for x in input().split()]\n new_ar = list(zip(nums,[i for i in range(len(nums))]))\n new_ar.sort()\n \n maxx = new_ar[0][1]\n minn = new_ar[0][1]\n s=\"1\"\n for j in range(1,len(new_ar)):\n if(new_ar[j][1]>maxx):\n ...
{ "inputs": [ "3\n6\n4 5 1 3 2 6\n5\n5 3 1 2 4\n4\n1 4 3 2\n" ], "outputs": [ "101011\n11111\n1001\n" ] }
interview
https://codeforces.com/problemset/problem/1265/B
[ "for _ in range(int(input())):\n input()\n nums = [int(x) for x in input().split()]\n new_ar = list(zip(nums,[i for i in range(len(nums))]))\n new_ar.sort()\n \n maxx = new_ar[0][1]\n minn = new_ar[0][1]\n s=\"1\"\n for j in range(1,len(new_ar)):\n if(new_ar[j][1]>maxx):\n ...
23
[ -1 ]
[ "input()", "sys.stdin.read*()", "stdin-alias.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin....
true
5
The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation. Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$. Now Dreamoon concatenates these two permutations into another sequ...
["def possible(a):\n ans = set()\n s = set()\n lmax = 0\n for i in range(len(a)):\n lmax = max(lmax, a[i])\n s.add(a[i])\n if lmax == i + 1 and len(s) == i + 1:\n ans.add(i + 1)\n return ans\n\n\nt = int(input())\nfor case_num in range(t):\n n = int(input())\n a = li...
{ "inputs": [ "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n" ], "outputs": [ "2\n1 4\n4 1\n1\n4 2\n0\n0\n1\n2 10\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1330/B
[ "def possible(a):\n ans = set()\n s = set()\n lmax = 0\n for i in range(len(a)):\n lmax = max(lmax, a[i])\n s.add(a[i])\n if lmax == i + 1 and len(s) == i + 1:\n ans.add(i + 1)\n return ans\n\n\nt = int(input())\nfor case_num in range(t):\n n = int(input())\n a =...
12
[ -1 ]
[ "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "sys.stdin", "sys.stdin.read*()" ]
true
6
Arthur owns a ski resort on a mountain. There are $n$ landing spots on the mountain numbered from $1$ to $n$ from the top to the foot of the mountain. The spots are connected with one-directional ski tracks. All tracks go towards the foot of the mountain, so there are no directed cycles formed by the tracks. There are ...
["import sys\ninput = sys.stdin.readline\nfor f in range(int(input())):\n n,m=list(map(int,input().split()))\n neig=[0]*n\n for i in range(n):\n neig[i]=[0]\n \n for i in range(m):\n a,b=list(map(int,input().split()))\n a-=1\n b-=1\n neig[a][0]+=1\n neig[a].appen...
{ "inputs": [ "2\n4 6\n1 2\n1 3\n2 3\n2 4\n3 4\n3 4\n7 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n" ], "outputs": [ "2\n3 4 \n4\n4 5 6 7 \n" ] }
interview
https://codeforces.com/problemset/problem/1368/E
[ "import sys\ninput = sys.stdin.readline\nfor f in range(int(input())):\n n,m=list(map(int,input().split()))\n neig=[0]*n\n for i in range(n):\n neig[i]=[0]\n \n for i in range(m):\n a,b=list(map(int,input().split()))\n a-=1\n b-=1\n neig[a][0]+=1\n neig[a].ap...
7
[ -1 ]
[ "sys.stdin", "sys.stdin", "sys.stdin.read*()", "sys.stdin.read*()", "sys.stdin.read*()", "sys.stdin", "sys.stdin.read*()" ]
true
7
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are $n$ voters, and two ways to convince each of them to vote for you. The first way to convince the $i$-th voter is to pay him $p_i$ ...
["import sys\ndef I():\n return sys.stdin.readline().rstrip()\n\nclass Heap:\n def __init__( self ):\n self.l = [ -1 ]\n self.n = 0\n def n( self ):\n return self.n\n def top( self ):\n return self.l[ 1 ]\n def ins( self, x ):\n self.l.append( x )\n n = len( self...
{ "inputs": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n" ], "outputs": [ "8\n0\n7\n" ] }
interview
https://codeforces.com/problemset/problem/1251/E2
[ "import sys\ndef I():\n return sys.stdin.readline().rstrip()\n\nclass Heap:\n def __init__( self ):\n self.l = [ -1 ]\n self.n = 0\n def n( self ):\n return self.n\n def top( self ):\n return self.l[ 1 ]\n def ins( self, x ):\n self.l.append( x )\n n = len( s...
8
[ -1 ]
[ "sys.stdin.read*()", "sys.stdin", "sys.stdin", "sys.stdin", "sys.stdin", "sys.stdin", "sys.stdin.read*()", "sys.stdin.read*()" ]
true
8
You like playing chess tournaments online. In your last tournament you played $n$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $0$ points. When you win you get $1$ or $2$ points: if you have won also the previous game you get $2$ points, otherwise ...
["import sys\ninput = sys.stdin.readline\n\ndef main():\n n, k = map(int, input().split())\n string = input().strip()\n if \"W\" not in string:\n ans = min(n, k) * 2 - 1\n print(max(ans, 0))\n return\n \n L_s = []\n cnt = 0\n bef = string[0]\n ans = 0\n for s in strin...
{ "inputs": [ "8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n" ], "outputs": [ "7\n11\n6\n26\n46\n0\n1\n6\n" ] }
interview
https://codeforces.com/problemset/problem/1427/B
[ "import sys\ninput = sys.stdin.readline\n\ndef main():\n n, k = map(int, input().split())\n string = input().strip()\n if \"W\" not in string:\n ans = min(n, k) * 2 - 1\n print(max(ans, 0))\n return\n \n L_s = []\n cnt = 0\n bef = string[0]\n ans = 0\n for s in st...
9
[ -1 ]
[ "sys.stdin", "sys.stdin", "sys.stdin", "input()", "stdin-alias.read*()", "stdin-alias.read*()", "input()", "sys.stdin", "input()" ]
true
9
Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less than one) of consecutive equal characters in $s$ and delete them. For example...
["for _ in range(int(input())):\n s = input()\n p = [i for i in s.split(\"0\") if i!=\"\"]\n p.sort(reverse=True)\n ans = 0\n for i in range(0,len(p),2):\n ans+=len(p[i])\n print(ans)\n\n", "for _ in range(int(input())):\n s=[len(i)for i in input().split('0')]\n s.sort()\n print(sum(s[...
{ "inputs": [ "5\n01111001\n0000\n111111\n101010101\n011011110111\n" ], "outputs": [ "4\n0\n6\n3\n6\n" ] }
interview
https://codeforces.com/problemset/problem/1398/B
[ "for _ in range(int(input())):\n s = input()\n p = [i for i in s.split(\"0\") if i!=\"\"]\n p.sort(reverse=True)\n ans = 0\n for i in range(0,len(p),2):\n ans+=len(p[i])\n print(ans)\n\n", "for _ in range(int(input())):\n s=[len(i)for i in input().split('0')]\n s.sort()\n print(s...
27
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "sys.stdin", "sys.stdin.read*()", "sys.stdin", "input()", "input()", "sys.stdin", "sys.stdin", "input()", "input()", "input()", "input()", "sys.stdin", ...
true
11
You have a string $s$ — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — move one cell down; 'A' — move one cell left; 'D' — move one cell right. Let $Grid(s)$ be the grid of minimum possible area such th...
["n = int(input())\n\ndef area(width, height) :\n return (width+1) * (height+1)\n\ndef calcul(s1, c, s2) :\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n for k in range(len(s1)) :\n if s1[k] == \"W\" :\n y += 1\n if s1[k] == \"S\" :\n y -= 1\n if s1[k] == \"...
{ "inputs": [ "3\nDSAWWAW\nD\nWA\n" ], "outputs": [ "8\n2\n4\n" ] }
interview
https://codeforces.com/problemset/problem/1202/C
[ "n = int(input())\n\ndef area(width, height) :\n return (width+1) * (height+1)\n\ndef calcul(s1, c, s2) :\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n for k in range(len(s1)) :\n if s1[k] == \"W\" :\n y += 1\n if s1[k] == \"S\" :\n y -= 1\n if s1[k] ==...
23
[ -1 ]
[ "input()", "sys.stdin", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "sys.stdin", "sys.stdin" ]
true
12
Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem: There are two arrays of integers $a$ and $b$ of length $n$. It turned out that array $a$ contains only elements from the set $\{-1, 0, 1\}$. Anton can perform the following sequence of operations any nu...
["from math import *\n\nmod = 1000000007\n\nfor zz in range(int(input())):\n n = int(input())\n a = [ int(i) for i in input().split()]\n b = [int(i) for i in input().split()]\n ha = True\n hp = False\n hm = False\n for i in range(n):\n if b[i] != a[i]:\n if b[i] > a[i]:\n ...
{ "inputs": [ "5\n3\n1 -1 0\n1 1 -2\n3\n0 1 1\n0 2 2\n2\n1 0\n1 41\n2\n-1 0\n-1 -41\n5\n0 1 -1 1 -1\n1 1 -1 1 -1\n" ], "outputs": [ "YES\nNO\nYES\nYES\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1333/B
[ "from math import *\n\nmod = 1000000007\n\nfor zz in range(int(input())):\n n = int(input())\n a = [ int(i) for i in input().split()]\n b = [int(i) for i in input().split()]\n ha = True\n hp = False\n hm = False\n for i in range(n):\n if b[i] != a[i]:\n if b[i] > a[i]:\n ...
10
[ -1 ]
[ "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()" ]
true
13
Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing. Skipping the repair is necessary because of the climate. The climate in your region is periodical: there ar...
["for i in range(int(input())):\n n,g,b=map(int,input().split())\n nn=(n+1)//2\n print(max(nn+(nn-1)//g*b,n))", "for _ in range(int(input())):\n n, g, b = list(map(int, input().split()))\n half = (n - 1) // 2 + 1\n\n ans = (g + b) * (half // g) - b # + (half % g)\n if half % g != 0:\n ans +...
{ "inputs": [ "3\n5 1 1\n8 10 10\n1000000 1 1000000\n" ], "outputs": [ "5\n8\n499999500000\n" ] }
interview
https://codeforces.com/problemset/problem/1303/B
[ "for i in range(int(input())):\n n,g,b=map(int,input().split())\n nn=(n+1)//2\n print(max(nn+(nn-1)//g*b,n))", "for _ in range(int(input())):\n n, g, b = list(map(int, input().split()))\n half = (n - 1) // 2 + 1\n\n ans = (g + b) * (half // g) - b # + (half % g)\n if half % g != 0:\n ...
10
[ -1 ]
[ "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "builtin input()", "input()" ]
true
14
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
["for _ in range(int(input())):\n a1, b1 = list(map(int, input().split()))\n a2, b2 = list(map(int, input().split()))\n if a1 > b1:\n a1, b1 = b1, a1\n if a2 > b2:\n a2, b2 = b2, a2\n flag = False\n if a1 == a2 and a1 == b1 + b2:\n flag = True\n if b1 == b2 and b1 == a1 + a2:\n...
{ "inputs": [ "3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n" ], "outputs": [ "Yes\nYes\nNo\n" ] }
interview
https://codeforces.com/problemset/problem/1351/B
[ "for _ in range(int(input())):\n a1, b1 = list(map(int, input().split()))\n a2, b2 = list(map(int, input().split()))\n if a1 > b1:\n a1, b1 = b1, a1\n if a2 > b2:\n a2, b2 = b2, a2\n flag = False\n if a1 == a2 and a1 == b1 + b2:\n flag = True\n if b1 == b2 and b1 == a1 + a2...
18
[ -1 ]
[ "input()", "input()", "input()", "input()", "sys.stdin.read*()", "open(stdin fd)", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()" ]
true
15
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$. Polycarp wants to open a rectangular window ...
["from math import *\n\nzzz = int(input())\nfor zz in range(zzz):\n a, b, x, y = list(map(int, input().split()))\n print(max(x*b, (a-x-1)*b, y*a, (b - y - 1)*a))\n", "for t in range(int(input())):\n a, b, x, y = [int(i) for i in input().split()]\n l = max(x, a - 1 - x)\n h = max(y, b - 1 - y)\n print(...
{ "inputs": [ "6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 1 0 0\n5 10 3 9\n10 10 4 8\n" ], "outputs": [ "56\n6\n442\n1\n45\n80\n" ] }
interview
https://codeforces.com/problemset/problem/1315/A
[ "from math import *\n\nzzz = int(input())\nfor zz in range(zzz):\n a, b, x, y = list(map(int, input().split()))\n print(max(x*b, (a-x-1)*b, y*a, (b - y - 1)*a))\n", "for t in range(int(input())):\n a, b, x, y = [int(i) for i in input().split()]\n l = max(x, a - 1 - x)\n h = max(y, b - 1 - y)\n p...
29
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "sys.stdin", "input()", "builtin input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()", "input()", "stdin-ali...
true
16
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of $n$ problems and lasts for $T$ minutes. Each of the problems is defined by two positive integers $a_i$ and $p_i$ — its difficulty and the score awarded by its solution. Polycarp's experience sugge...
["from math import sqrt\nclass pro(object):\n def __init__(self,dif,sc):\n self.dif=dif\n self.sc=sc\n\n def __lt__(self,other):\n return self.dif>other.dif\n\nT=int(input())\nmul=[1]\nfor i in range(100):\n mul.append(mul[i]*10/9)\ninf=1000000007\nfor t in range(T):\n n=int(input())\n ...
{ "inputs": [ "2\n4\n1.000 31.000\n12 3\n20 6\n30 1\n5 1\n3\n1.000 30.000\n1 10\n10 10\n20 8\n" ], "outputs": [ "7\n20\n" ] }
interview
https://codeforces.com/problemset/problem/1056/F
[ "from math import sqrt\nclass pro(object):\n def __init__(self,dif,sc):\n self.dif=dif\n self.sc=sc\n\n def __lt__(self,other):\n return self.dif>other.dif\n\nT=int(input())\nmul=[1]\nfor i in range(100):\n mul.append(mul[i]*10/9)\ninf=1000000007\nfor t in range(T):\n n=int(input())...
1
[ -1 ]
[ "input()" ]
true
17
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$; -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The first line of each test case contains a...
["class BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n wh...
{ "inputs": [ "2\n5\n2 2 2 2 2\n6\n1 3 3 1 2 3\n" ], "outputs": [ "5\n2\n" ] }
interview
https://codeforces.com/problemset/problem/1400/D
[ "class BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n ...
5
[ -1 ]
[ "sys.stdin", "stdin-alias.read*()", "input()", "input()", "sys.stdin.read*()" ]
true
18
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd. You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's n...
["import math\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n print(1/math.tan(math.pi/2/n))\n", "t=int(input())\nimport math as m\nwhile t:\n t-=1\n a=int(input())\n print(1/(m.tan(m.pi/(2*a))))\n", "import sys\nimport math\n\nreadline = sys.stdin.readline\nread = sys.stdin.read\nns = lambd...
{"inputs": ["3\n2\n4\n200\n"], "outputs": ["1.000000000\n2.414213562\n127.321336469\n"]}
interview
https://codeforces.com/problemset/problem/1354/C1
[ "import math\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n print(1/math.tan(math.pi/2/n))\n", "t=int(input())\nimport math as m\nwhile t:\n t-=1\n a=int(input())\n print(1/(m.tan(m.pi/(2*a))))\n", "import sys\nimport math\n\nreadline = sys.stdin.readline\nread = sys.stdin.read\nns ...
38
[ -1 ]
[ "input()", "input()", "sys.stdin", "sys.stdin.read*()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "sys.stdin", "input()",...
true
19
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown i...
["for _ in range(int(input())):\n n, k, d = list(map(int, input().split()))\n a = list(map(int, input().split()))\n s = {}\n for q in range(d):\n s[a[q]] = s.get(a[q], 0)+1\n ans = len(s)\n for q in range(d, n):\n if s[a[q-d]] == 1:\n del s[a[q-d]]\n else:\n ...
{ "inputs": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n" ], "outputs": [ "2\n1\n4\n5\n" ] }
interview
https://codeforces.com/problemset/problem/1225/B2
[ "for _ in range(int(input())):\n n, k, d = list(map(int, input().split()))\n a = list(map(int, input().split()))\n s = {}\n for q in range(d):\n s[a[q]] = s.get(a[q], 0)+1\n ans = len(s)\n for q in range(d, n):\n if s[a[q-d]] == 1:\n del s[a[q-d]]\n else:\n ...
25
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "i...
true
21
Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble. There is a set $S$ containing very important numb...
["t = int(input())\n\nfor _ in range(t):\n n = list(input().strip())\n s = list(map(int, input().strip().split()))\n\n check = set(s)\n found = False\n for i in range(1, 1025):\n newset = set([e^i for e in s])\n if check == newset:\n print(i)\n found = True\n ...
{ "inputs": [ "6\n4\n1 0 2 3\n6\n10 7 14 8 3 12\n2\n0 2\n3\n1 2 3\n6\n1 4 6 10 11 12\n2\n0 1023\n" ], "outputs": [ "1\n4\n2\n-1\n-1\n1023\n" ] }
interview
https://codeforces.com/problemset/problem/1362/B
[ "t = int(input())\n\nfor _ in range(t):\n n = list(input().strip())\n s = list(map(int, input().strip().split()))\n\n check = set(s)\n found = False\n for i in range(1, 1025):\n newset = set([e^i for e in s])\n if check == newset:\n print(i)\n found = True\n ...
10
[ -1 ]
[ "input()", "sys.stdin", "sys.stdin", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()" ]
true
22
Let's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).$$ Here $minDigit(x)$ and $maxDigit(x)$ are the minimal and maximal digits in the decimal representation of $x$ without leading zeroes. For examples refer to notes. Your task is calculate $a_{K}$ for given $a_{1}$ and $K$...
["import sys\n\ninput = sys.stdin.readline\n\nfor _ in range(int(input())):\n\ta, k = list(map(int, input().split()))\n\tfor _ in range(k - 1):\n\t\tif '0' in str(a):\n\t\t\tbreak\n\t\ta += int(min(list(str(a)))) * int(max(list(str(a))))\n\tprint(a)\n", "for _ in range(int(input())):\n n,k = map(int,input().split())...
{ "inputs": [ "8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n" ], "outputs": [ "42\n487\n519\n528\n544\n564\n588\n628\n" ] }
interview
https://codeforces.com/problemset/problem/1355/A
[ "import sys\n\ninput = sys.stdin.readline\n\nfor _ in range(int(input())):\n\ta, k = list(map(int, input().split()))\n\tfor _ in range(k - 1):\n\t\tif '0' in str(a):\n\t\t\tbreak\n\t\ta += int(min(list(str(a)))) * int(max(list(str(a))))\n\tprint(a)\n", "for _ in range(int(input())):\n n,k = map(int,input().spl...
35
[ -1 ]
[ "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "builtin input()", "sys.stdin", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()...
true
23
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are $n$ voters, and two ways to convince each of them to vote for you. The first way to convince the $i$-th voter is to pay him $p_i$ ...
["import heapq\n\nfor _ in range(int(input())):\n n = int(input())\n voters = []\n for i in range(n):\n m,p = list(map(int, input().split()))\n voters.append((m, -p))\n voters.sort()\n for i in range(n):\n voters[i] = (voters[i][0], -voters[i][1])\n\n ans = 0\n costs = []\n ...
{ "inputs": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n" ], "outputs": [ "8\n0\n7\n" ] }
interview
https://codeforces.com/problemset/problem/1251/E1
[ "import heapq\n\nfor _ in range(int(input())):\n n = int(input())\n voters = []\n for i in range(n):\n m,p = list(map(int, input().split()))\n voters.append((m, -p))\n voters.sort()\n for i in range(n):\n voters[i] = (voters[i][0], -voters[i][1])\n\n ans = 0\n costs = []\n ...
11
[ -1 ]
[ "input()", "input()", "sys.stdin.read*()", "input()", "sys.stdin", "input()", "input()", "sys.stdin", "sys.stdin", "sys.stdin", "input()" ]
true
24
Try guessing the statement from this picture: $3$ You are given a non-negative integer $d$. You have to find two non-negative real numbers $a$ and $b$ such that $a + b = d$ and $a \cdot b = d$. -----Input----- The first line contains $t$ ($1 \le t \le 10^3$) — the number of test cases. Each test case contains on...
["for _ in range(int(input())):\n d=int(input())\n anws=False\n if d**2>=4*d:\n root=(d**2-4*d)**0.5\n a=(d+root)/2\n b=(d-root)/2\n anws=True\n if anws:\n print(\"Y {:.9f} {:.9f}\".format(a,b))\n else:\n print(\"N\")", "n=int(input())\n\nfor i in range(n):\n ...
{ "inputs": [ "7\n69\n0\n1\n4\n5\n999\n1000\n" ], "outputs": [ "Y 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005\n" ] }
interview
https://codeforces.com/problemset/problem/1076/C
[ "for _ in range(int(input())):\n d=int(input())\n anws=False\n if d**2>=4*d:\n root=(d**2-4*d)**0.5\n a=(d+root)/2\n b=(d-root)/2\n anws=True\n if anws:\n print(\"Y {:.9f} {:.9f}\".format(a,b))\n else:\n print(\"N\")", "n=int(input())\n\nfor i in range(n):\...
2
[ -1 ]
[ "input()", "input()" ]
true
26
You are given a special jigsaw puzzle consisting of $n\cdot m$ identical pieces. Every piece has three tabs and one blank, as pictured below. $\{3$ The jigsaw puzzle is considered solved if the following conditions hold: The pieces are arranged into a grid with $n$ rows and $m$ columns. For any two pieces that shar...
["for _ in range(int(input())):\n n, m = list(map(int, input().split()))\n if n < m:\n n, m = m, n # n > m\n\n if m == 1:\n print(\"YES\")\n continue\n\n if m == 2 and n == 2:\n print(\"YES\")\n continue\n\n print(\"NO\")\n", "for zz in range(int(input())):\n n, m = ...
{ "inputs": [ "3\n1 3\n100000 100000\n2 2\n" ], "outputs": [ "YES\nNO\nYES\n" ] }
interview
https://codeforces.com/problemset/problem/1345/A
[ "for _ in range(int(input())):\n n, m = list(map(int, input().split()))\n if n < m:\n n, m = m, n # n > m\n\n if m == 1:\n print(\"YES\")\n continue\n\n if m == 2 and n == 2:\n print(\"YES\")\n continue\n\n print(\"NO\")\n", "for zz in range(int(input())):\n n,...
40
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "sys.stdin.read*()", "input()", "input()", "input()", ...
true
27
There are $n$ positive integers $a_1, a_2, \dots, a_n$. For the one move you can choose any even value $c$ and divide by two all elements that equal $c$. For example, if $a=[6,8,12,6,3,12]$ and you choose $c=6$, and $a$ is transformed into $a=[3,8,12,3,3,12]$ after the move. You need to find the minimal number of mov...
["tests = int(input())\nfor test in range(tests):\n n = int(input())\n a = [int(i) for i in input().split()]\n d = {}\n for i in range(n):\n s = 0\n while a[i] % 2 == 0:\n a[i] //= 2\n s += 1\n if a[i] in list(d.keys()):\n d[a[i]] = max(s, d[a[i]])\n ...
{ "inputs": [ "4\n6\n40 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7\n" ], "outputs": [ "4\n10\n4\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1259/B
[ "tests = int(input())\nfor test in range(tests):\n n = int(input())\n a = [int(i) for i in input().split()]\n d = {}\n for i in range(n):\n s = 0\n while a[i] % 2 == 0:\n a[i] //= 2\n s += 1\n if a[i] in list(d.keys()):\n d[a[i]] = max(s, d[a[i]])\n ...
43
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", ...
true
28
Acacius is studying strings theory. Today he came with the following problem. You are given a string $s$ of length $n$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a res...
["import sys\nINF = 10**20\nMOD = 10**9 + 7\nI = lambda:list(map(int,input().split()))\nfrom math import gcd\nfrom math import ceil\nfrom collections import defaultdict as dd, Counter\nfrom bisect import bisect_left as bl, bisect_right as br\n\n\n\"\"\"\nFacts and Data representation\nConstructive? Top bottom up down\n...
{ "inputs": [ "6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba\n" ], "outputs": [ "Yes\nabacaba\nYes\nabacaba\nYes\nabazabacaba\nYes\nabacabazaba\nNo\nNo\n" ] }
interview
https://codeforces.com/problemset/problem/1379/A
[ "import sys\nINF = 10**20\nMOD = 10**9 + 7\nI = lambda:list(map(int,input().split()))\nfrom math import gcd\nfrom math import ceil\nfrom collections import defaultdict as dd, Counter\nfrom bisect import bisect_left as bl, bisect_right as br\n\n\n\"\"\"\nFacts and Data representation\nConstructive? Top bottom up dow...
6
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()" ]
true
29
You are given an array $a$ consisting of $n$ integers numbered from $1$ to $n$. Let's define the $k$-amazing number of the array as the minimum number that occurs in all of the subsegments of the array having length $k$ (recall that a subsegment of $a$ of length $k$ is a contiguous part of $a$ containing exactly $k$ e...
["input=__import__('sys').stdin.readline\nfor _ in range(int(input())):\n\tn=int(input())\n\ts=list(map(int,input().split()))\n\tg=[[-1]for _ in range(n+1)]\n\tfor i in range(n):\n\t\tg[s[i]].append(i)\n\tinf=10**10\n\tans=[-1]*n\n\tlstunused=n\n\tfor i in range(1,n+1):\n\t\tg[i].append(n)\n\t\tmx=0\n\t\tfor j in range...
{ "inputs": [ "3\n5\n1 2 3 4 5\n5\n4 4 4 4 2\n6\n1 3 1 5 3 1\n" ], "outputs": [ "-1 -1 3 2 1 \n-1 4 4 4 2 \n-1 -1 1 1 1 1 \n" ] }
interview
https://codeforces.com/problemset/problem/1417/C
[ "input=__import__('sys').stdin.readline\nfor _ in range(int(input())):\n\tn=int(input())\n\ts=list(map(int,input().split()))\n\tg=[[-1]for _ in range(n+1)]\n\tfor i in range(n):\n\t\tg[s[i]].append(i)\n\tinf=10**10\n\tans=[-1]*n\n\tlstunused=n\n\tfor i in range(1,n+1):\n\t\tg[i].append(n)\n\t\tmx=0\n\t\tfor j in ra...
13
[ -1 ]
[ "input()", "sys.stdin.read*()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()" ]
true
30
You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's. String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even). In one operation you can reverse any substring of $s$. A substring of a string is a contiguous subsequence of that string...
["t = int(input())\nfor i in range(t):\n n = int(input())\n s = input()\n ans = 0\n for y in range(1, n):\n if s[y] == s[y-1]:\n ans += 1\n print((ans + ans % 2) // 2)\n \n", "import sys\ninput=sys.stdin.readline\nfor _ in range(int(input())):\n n = int(input())\n s = input().s...
{ "inputs": [ "3\n2\n10\n4\n0110\n8\n11101000\n" ], "outputs": [ "0\n1\n2\n" ] }
interview
https://codeforces.com/problemset/problem/1437/B
[ "t = int(input())\nfor i in range(t):\n n = int(input())\n s = input()\n ans = 0\n for y in range(1, n):\n if s[y] == s[y-1]:\n ans += 1\n print((ans + ans % 2) // 2)\n \n", "import sys\ninput=sys.stdin.readline\nfor _ in range(int(input())):\n n = int(input())\n s = inpu...
19
[ -1 ]
[ "input()", "sys.stdin", "input()", "input()", "sys.stdin", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "sys.stdin.read*()", "sys.stdin", "input()", "input()", "input()" ]
true
31
Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to $1$ meter movement in the south, north, west or east direction respectively). It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visi...
["DIR = {\"N\": (0, 1), \"S\": (0, -1), \"W\": (-1, 0), \"E\": (1, 0)}\n\nfor t in range(int(input())):\n path = input()\n tracks = set()\n x, y = 0, 0\n time = 0\n for char in path:\n x1 = x + DIR[char][0]\n y1 = y + DIR[char][1]\n if (x, y, x1, y1) in tracks or (x1, y1, x, y) in tracks:\n ...
{ "inputs": [ "5\nNNN\nNS\nWWEN\nWWEE\nNWNWS\n" ], "outputs": [ "15\n6\n16\n12\n25\n" ] }
interview
https://codeforces.com/problemset/problem/1351/C
[ "DIR = {\"N\": (0, 1), \"S\": (0, -1), \"W\": (-1, 0), \"E\": (1, 0)}\n\nfor t in range(int(input())):\n path = input()\n tracks = set()\n x, y = 0, 0\n time = 0\n for char in path:\n x1 = x + DIR[char][0]\n y1 = y + DIR[char][1]\n if (x, y, x1, y1) in tracks or (x1, y1, x, y) in tracks:\n ...
22
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "open(stdin fd)", "input()", "input()", "input()", "builtin input()", "input()", "input()", "sys.stdin" ]
true
32
Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia. The game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing $...
["from sys import stdin, stdout\nfrom collections import defaultdict\ninput = stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tchanek = 0\n\tflag = 1\n\twhile n>0:\n\t\tif n%4==0 and n!=4:\n\t\t\tif flag:\n\t\t\t\tchanek += 1\n\t\t\t\tn-=1\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn-=1\n\t\t\t\tflag =...
{ "inputs": [ "2\n5\n6\n" ], "outputs": [ "2\n4\n" ] }
interview
https://codeforces.com/problemset/problem/1425/A
[ "from sys import stdin, stdout\nfrom collections import defaultdict\ninput = stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tchanek = 0\n\tflag = 1\n\twhile n>0:\n\t\tif n%4==0 and n!=4:\n\t\t\tif flag:\n\t\t\t\tchanek += 1\n\t\t\t\tn-=1\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn-=1\n\t\t\t\tfla...
3
[ -1 ]
[ "builtin input()", "builtin input()", "input()" ]
true
34
You have a large electronic screen which can display up to $998244353$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $7$ segments which can be turned on and off to compose different digits. The following picture describes how you can...
["for _ in range(int(input())):\n\tn = int(input())\n\tif(n%2):\n\t\tprint(\"7\"+\"1\"*((n-3)//2))\n\telse:\n\t\tprint(\"1\"*(n//2))\t", "t=int(input())\nfor i in ' '*t:\n n=int(input())\n if n%2==1:print('7'+'1'*((n-3)//2))\n else:print('1'*(n//2))", "for _ in range(int(input())):\n\tn = int(input())\n\n\tif ...
{"inputs": ["2\n3\n4\n"], "outputs": ["7\n11\n"]}
interview
https://codeforces.com/problemset/problem/1295/A
[ "for _ in range(int(input())):\n\tn = int(input())\n\tif(n%2):\n\t\tprint(\"7\"+\"1\"*((n-3)//2))\n\telse:\n\t\tprint(\"1\"*(n//2))\t", "t=int(input())\nfor i in ' '*t:\n n=int(input())\n if n%2==1:print('7'+'1'*((n-3)//2))\n else:print('1'*(n//2))", "for _ in range(int(input())):\n\tn = int(input())\n...
21
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
35
Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties... Most of the young explorer...
["import sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n N=int(input())\n e=list(map(int,input().split()))\n e.sort()\n ans=0\n val=0\n g=0\n for i in range(0,N):\n g+=1\n val=e[i]\n if g>=val:\n ans+=1\n g=0\n val=0\n prin...
{ "inputs": [ "2\n3\n1 1 1\n5\n2 3 1 2 2\n" ], "outputs": [ "3\n2\n" ] }
interview
https://codeforces.com/problemset/problem/1355/B
[ "import sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n N=int(input())\n e=list(map(int,input().split()))\n e.sort()\n ans=0\n val=0\n g=0\n for i in range(0,N):\n g+=1\n val=e[i]\n if g>=val:\n ans+=1\n g=0\n val=0\n p...
5
[ -1 ]
[ "sys.stdin", "stdin-alias.read*()", "sys.stdin", "sys.stdin", "sys.stdin" ]
true
37
Yeah, we failed to make up a New Year legend for this problem. A permutation of length $n$ is an array of $n$ integers such that every integer from $1$ to $n$ appears in it exactly once. An element $y$ of permutation $p$ is reachable from element $x$ if $x = y$, or $p_x = y$, or $p_{p_x} = y$, and so on. The decom...
["3\n\nfrom math import factorial as fact\n\nN = 55\nc = [1]\nfor i in range(N):\n\tc.append(fact(i))\ndp = [0] * N\ndp[0] = 1\nfor i in range(1, N):\n\tfor j in range(i):\n\t\tdp[i] += dp[j] * c[i - j - 1]\n\ndef get_kth_cycle(n, k):\n\tif n == 1:\n\t\treturn [1]\n\tans = [-1] * n\n\tans[0] = n - 1\n\tfin = [i for i i...
{ "inputs": [ "5\n3 3\n5 15\n4 13\n6 8\n4 2\n" ], "outputs": [ "2 1 3 \n3 1 2 5 4 \n-1\n1 2 6 3 4 5 \n1 2 4 3 \n" ] }
interview
https://codeforces.com/problemset/problem/1279/E
[ "3\n\nfrom math import factorial as fact\n\nN = 55\nc = [1]\nfor i in range(N):\n\tc.append(fact(i))\ndp = [0] * N\ndp[0] = 1\nfor i in range(1, N):\n\tfor j in range(i):\n\t\tdp[i] += dp[j] * c[i - j - 1]\n\ndef get_kth_cycle(n, k):\n\tif n == 1:\n\t\treturn [1]\n\tans = [-1] * n\n\tans[0] = n - 1\n\tfin = [i for ...
9
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
38
Two players decided to play one interesting card game. There is a deck of $n$ cards, with values from $1$ to $n$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player...
["q = int(input())\nfor z in range(q):\n n, k1, k2 = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n if max(arr1) > max(arr2):\n print('YES')\n else:\n print('NO')", "t = int(input())\n\nfor _ in range(t):\n n, k1, k2 = list(m...
{ "inputs": [ "2\n2 1 1\n2\n1\n5 2 3\n2 3\n1 4 5\n" ], "outputs": [ "YES\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1270/A
[ "q = int(input())\nfor z in range(q):\n n, k1, k2 = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n if max(arr1) > max(arr2):\n print('YES')\n else:\n print('NO')", "t = int(input())\n\nfor _ in range(t):\n n, k1, k2 = l...
29
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input(...
true
39
After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are $n$ crossroads in the line in the town, and there is either the bus or the tram station at each crossroad. The crossroads are represented as a string $s$ of length $n$, where $s_i = \texttt...
["t=int(input())\n\nfor tt in range(t):\n a,b,p=map(int,input().split())\n s=input()\n n=len(s)\n cost = [0]*n\n cost[-1] = 0\n typ = ''\n i=n-2\n while i>=0:\n if s[i]==typ:\n cost[i] = cost[i+1]\n else:\n typ = s[i]\n cost[i] = cost[i+1] + (a if t...
{ "inputs": [ "5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n" ], "outputs": [ "2\n1\n3\n1\n6\n" ] }
interview
https://codeforces.com/problemset/problem/1315/B
[ "t=int(input())\n\nfor tt in range(t):\n a,b,p=map(int,input().split())\n s=input()\n n=len(s)\n cost = [0]*n\n cost[-1] = 0\n typ = ''\n i=n-2\n while i>=0:\n if s[i]==typ:\n cost[i] = cost[i+1]\n else:\n typ = s[i]\n cost[i] = cost[i+1] + (a i...
21
[ -1 ]
[ "input()", "stdin-alias.read*()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "sys.stdin", "input()", "input()", "builtin input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()" ]
true
41
You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence $s=s_{1}s_{2}\dots s_{n}$ of length $n$. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choose any consecutive substring of $s$ and reverse it. In othe...
["t = int(input())\nfor tt in range(t):\n n,k=list(map(int,input().split()))\n s = input()\n ans = []\n if s[0] == ')':\n for i in range(n):\n if s[i] == '(':\n ans.append([1,i+1])\n s = s[i::-1] + s[i+1:]\n break\n for i in range(1,(k-1)*2):...
{ "inputs": [ "4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n" ], "outputs": [ "1\n5 7\n5\n1 3\n3 5\n5 7\n6 9\n7 10\n0\n1\n1 2\n" ] }
interview
https://codeforces.com/problemset/problem/1227/C
[ "t = int(input())\nfor tt in range(t):\n n,k=list(map(int,input().split()))\n s = input()\n ans = []\n if s[0] == ')':\n for i in range(n):\n if s[i] == '(':\n ans.append([1,i+1])\n s = s[i::-1] + s[i+1:]\n break\n for i in range(1,(k-1)*...
17
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
42
You are given a binary string $s$ (recall that a string is binary if each character is either $0$ or $1$). Let $f(t)$ be the decimal representation of integer $t$ written in binary form (possibly with leading zeroes). For example $f(011) = 3, f(00101) = 5, f(00001) = 1, f(10) = 2, f(000) = 0$ and $f(000100) = 4$. The...
["LOG = 20\n\ndef solve(s):\n\tn = len(s)\n\tres = 0\n\tz = 0\n\tfor t in range(0, n):\n\t\tif s[t] == '0':\n\t\t\tz += 1\n\t\t\tcontinue\n\t\tfor l in range(1, min(LOG, n - t + 1)):\n\t\t\tx = int(s[t:t+l], 2)\n\t\t\t# print(l, t, x, l + z)\n\t\t\tif l + z >= x:\n\t\t\t\tres += 1\n\n#\t\t\tprint(t, l, x, res, z)\n\t\t...
{ "inputs": [ "4\n0110\n0101\n00001000\n0001000\n" ], "outputs": [ "4\n3\n4\n3\n" ] }
interview
https://codeforces.com/problemset/problem/1217/C
[ "LOG = 20\n\ndef solve(s):\n\tn = len(s)\n\tres = 0\n\tz = 0\n\tfor t in range(0, n):\n\t\tif s[t] == '0':\n\t\t\tz += 1\n\t\t\tcontinue\n\t\tfor l in range(1, min(LOG, n - t + 1)):\n\t\t\tx = int(s[t:t+l], 2)\n\t\t\t# print(l, t, x, l + z)\n\t\t\tif l + z >= x:\n\t\t\t\tres += 1\n\n#\t\t\tprint(t, l, x, res, z)\n\...
22
[ -1 ]
[ "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "builtin input()", "input()", "input()", "stdin-alias.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
43
Petya is preparing for his birthday. He decided that there would be $n$ different dishes on the dinner table, numbered from $1$ to $n$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants. Unfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up h...
["def check(M):\n sm = 0\n for i in range(n):\n if a[i] > M:\n sm += b[i]\n return sm <= M\n\n\ngans = []\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n L = 0\n R = max(a)\n while R - L > 1:\n ...
{ "inputs": [ "4\n4\n3 7 4 5\n2 1 2 4\n4\n1 2 3 4\n3 3 3 3\n2\n1 2\n10 10\n2\n10 10\n1 2\n" ], "outputs": [ "5\n3\n2\n3\n" ] }
interview
https://codeforces.com/problemset/problem/1443/C
[ "def check(M):\n sm = 0\n for i in range(n):\n if a[i] > M:\n sm += b[i]\n return sm <= M\n\n\ngans = []\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n L = 0\n R = max(a)\n while R - L > 1:\...
11
[ -1 ]
[ "input()", "input()", "sys.stdin", "input()", "input()", "input()", "sys.stdin.read*()", "sys.stdin.read*()", "input()", "builtin input()", "input()" ]
true
45
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases. A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase ha...
["import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef...
{ "inputs": [ "4\n1\n8\n6\n1000000000000000000\n" ], "outputs": [ "1\n2\n1\n30\n" ] }
interview
https://codeforces.com/problemset/problem/1419/B
[ "import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \n...
23
[ -1 ]
[ "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()...
true
47
This is the easy version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in the wild pikachu herd. But it has become known recently that infamous team R...
["import sys\ninput = sys.stdin.readline\nfrom bisect import bisect_right\n\nbin_s = [1]\nwhile bin_s[-1] <= 10 ** 9:\n bin_s.append(bin_s[-1] * 2)\n\n\ndef main():\n n, q = map(int, input().split())\n alst = list(map(int, input().split()))\n dp = [[-1, -1] for _ in range(n)]\n dp[0] = [alst[0], 0]\n ...
{ "inputs": [ "3\n3 0\n1 3 2\n2 0\n1 2\n7 0\n1 2 5 4 3 6 7\n" ], "outputs": [ "3\n2\n9\n" ] }
interview
https://codeforces.com/problemset/problem/1420/C1
[ "import sys\ninput = sys.stdin.readline\nfrom bisect import bisect_right\n\nbin_s = [1]\nwhile bin_s[-1] <= 10 ** 9:\n bin_s.append(bin_s[-1] * 2)\n\n\ndef main():\n n, q = map(int, input().split())\n alst = list(map(int, input().split()))\n dp = [[-1, -1] for _ in range(n)]\n dp[0] = [alst[0], 0]\n ...
7
[ -1 ]
[ "sys.stdin", "input()", "sys.stdin", "sys.stdin", "input()", "stdin-alias.read*()", "input()" ]
true
48
You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $k$ torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: exchange $1$ stick for $x$ sticks (you lose $1$ stick and gain $x$ ...
["for haaghfj in range(int(input())):\n x,y,k = list(map(int,input().split()))\n print(k + (y * k + k - 1 +x-2) // (x - 1))\n", "import sys\nimport math\nimport collections\nimport bisect\nimport itertools\nimport decimal\nimport copy\nimport heapq\n\n# import numpy as np\n\n# sys.setrecursionlimit(10 ** 6)\nINF ...
{ "inputs": [ "5\n2 1 5\n42 13 24\n12 11 12\n1000000000 1000000000 1000000000\n2 1000000000 1000000000\n" ], "outputs": [ "14\n33\n25\n2000000003\n1000000001999999999\n" ] }
interview
https://codeforces.com/problemset/problem/1418/A
[ "for haaghfj in range(int(input())):\n x,y,k = list(map(int,input().split()))\n print(k + (y * k + k - 1 +x-2) // (x - 1))\n", "import sys\nimport math\nimport collections\nimport bisect\nimport itertools\nimport decimal\nimport copy\nimport heapq\n\n# import numpy as np\n\n# sys.setrecursionlimit(10 ** 6)\...
17
[ -1 ]
[ "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "sys.stdin.read*()", "sys.stdin.read*()", "sys.stdin", "input()" ]
true
50
Karlsson has recently discovered a huge stock of berry jam jars in the basement of the house. More specifically, there were $2n$ jars of strawberry and blueberry jam. All the $2n$ jars are arranged in a row. The stairs to the basement are exactly in the middle of that row. So when Karlsson enters the basement, he sees...
["for tcase in range(int(input())):\n n=int(input())\n ls = list(map(int, input().split()))\n oneneed = 2*(n - ls.count(1))\n ldct = {0:0}\n ctr = 0\n eaten = 0\n for i in range(n-1,-1,-1):\n eaten += 1\n ctr += (1 if ls[i] == 2 else -1)\n if ctr not in ldct:\n ldct[...
{ "inputs": [ "4\n6\n1 1 1 2 2 1 2 1 2 1 1 2\n2\n1 2 1 2\n3\n1 1 1 1 1 1\n2\n2 1 1 1\n" ], "outputs": [ "6\n0\n6\n2\n" ] }
interview
https://codeforces.com/problemset/problem/1278/C
[ "for tcase in range(int(input())):\n n=int(input())\n ls = list(map(int, input().split()))\n oneneed = 2*(n - ls.count(1))\n ldct = {0:0}\n ctr = 0\n eaten = 0\n for i in range(n-1,-1,-1):\n eaten += 1\n ctr += (1 if ls[i] == 2 else -1)\n if ctr not in ldct:\n ld...
10
[ -1 ]
[ "input()", "sys.stdin", "sys.stdin", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "sys.stdin", "sys.stdin" ]
true
53
Gildong recently learned how to find the longest increasing subsequence (LIS) in $O(n\log{n})$ time for a sequence of length $n$. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though there are actually many of them). So instead he's going to mak...
["import sys\ninput = sys.stdin.readline\n\n\ndef compress(array):\n array2 = sorted(set(array))\n memo = {value : index for index, value in enumerate(array2)}\n for i in range(len(array)):\n array[i] = memo[array[i]] + 1\n return array\n\n\nt = int(input())\nbase = 10 ** 6\nfor _ in range(t):\n n...
{ "inputs": [ "3\n3 <<\n7 >><>><\n5 >>><\n" ], "outputs": [ "1 2 3\n1 2 3\n5 4 3 7 2 1 6\n4 3 1 7 5 2 6\n4 3 2 1 5\n5 4 2 1 3\n" ] }
interview
https://codeforces.com/problemset/problem/1304/D
[ "import sys\ninput = sys.stdin.readline\n\n\ndef compress(array):\n array2 = sorted(set(array))\n memo = {value : index for index, value in enumerate(array2)}\n for i in range(len(array)):\n array[i] = memo[array[i]] + 1\n return array\n\n\nt = int(input())\nbase = 10 ** 6\nfor _ in range(t):\n ...
9
[ -1 ]
[ "sys.stdin", "sys.stdin", "stdin-alias.read*()", "sys.stdin.read*()", "input()", "input()", "sys.stdin", "input()", "input()" ]
true
54
You are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations with this multiset. During each operation you choose two equal integers from $s$, remove them from $s$ and insert the n...
["for i in range(int(input())):\n n=int(input())\n s=list(map(int,input().split()))\n a=0\n for i in s:\n if i<2049:a+=i\n if a<2048:print(\"NO\")\n else:print(\"YES\")", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n ...
{ "inputs": [ "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n" ], "outputs": [ "YES\nYES\nNO\nNO\nYES\nYES\n" ] }
interview
https://codeforces.com/problemset/problem/1221/A
[ "for i in range(int(input())):\n n=int(input())\n s=list(map(int,input().split()))\n a=0\n for i in s:\n if i<2049:a+=i\n if a<2048:print(\"NO\")\n else:print(\"YES\")", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)...
22
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "input()" ]
true
56
A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it! You are given integers $n,k$. Construct a grid $A$ with size $n \times n$ consisting of integers $0$ and $1$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $k$. In other words, the numb...
["for _ in range(int(input())):\n n, k = map(int, input().split())\n mat = [[0] * n for _ in range(n)]\n for i in range(n):\n b = False\n for j in range(n):\n if i*n+j == k:\n b = True\n break\n mat[(i+j)%n][j] = 1\n if b:\n br...
{"inputs": ["4\n2 2\n3 8\n1 0\n4 16\n"], "outputs": ["0\n10\n01\n2\n111\n111\n101\n0\n0\n0\n1111\n1111\n1111\n1111\n"]}
interview
https://codeforces.com/problemset/problem/1371/D
[ "for _ in range(int(input())):\n n, k = map(int, input().split())\n mat = [[0] * n for _ in range(n)]\n for i in range(n):\n b = False\n for j in range(n):\n if i*n+j == k:\n b = True\n break\n mat[(i+j)%n][j] = 1\n if b:\n ...
22
[ -1 ]
[ "input()", "input()", "input()", "sys.stdin", "sys.stdin.read*()", "sys.stdin", "input()", "builtin input()", "sys.stdin", "sys.stdin", "input()", "input()", "sys.stdin", "sys.stdin", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin"...
true
57
You are given an array $a$ of length $n$, which initially is a permutation of numbers from $1$ to $n$. In one operation, you can choose an index $i$ ($1 \leq i < n$) such that $a_i < a_{i + 1}$, and remove either $a_i$ or $a_{i + 1}$ from the array (after the removal, the remaining parts are concatenated). For exampl...
["t = int(input())\nfor case in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n if arr[-1] > arr[0]:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n if a[-1]>a[0]:\n print...
{ "inputs": [ "4\n3\n1 2 3\n4\n3 1 2 4\n3\n2 3 1\n6\n2 4 6 1 3 5\n" ], "outputs": [ "YES\nYES\nNO\nYES\n" ] }
interview
https://codeforces.com/problemset/problem/1375/C
[ "t = int(input())\nfor case in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n if arr[-1] > arr[0]:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n if a[-1]>a[0]:\n ...
10
[ -1 ]
[ "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "sys.stdin", "input()", "input()" ]
true
59
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with ...
["for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans,small,big=0,2*10**9,-1\n for i in range(len(a)-1):\n if a[i]==-1 and a[i+1]!=-1:\n small=min(small, a[i+1])\n big=max(big, a[i+1])\n if a[i]!=-1 and a[i+1]==-1:\n small = ...
{ "inputs": [ "7\n5\n-1 10 -1 12 -1\n5\n-1 40 35 -1 35\n6\n-1 -1 9 -1 3 -1\n2\n-1 -1\n2\n0 -1\n4\n1 -1 3 -1\n7\n1 -1 7 5 2 -1 5\n" ], "outputs": [ "1 11\n5 37\n3 6\n0 0\n0 0\n1 2\n3 4\n" ] }
interview
https://codeforces.com/problemset/problem/1301/B
[ "for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans,small,big=0,2*10**9,-1\n for i in range(len(a)-1):\n if a[i]==-1 and a[i+1]!=-1:\n small=min(small, a[i+1])\n big=max(big, a[i+1])\n if a[i]!=-1 and a[i+1]==-1:\n small...
4
[ -1 ]
[ "input()", "input()", "sys.stdin", "input()" ]
true
61
You are given a permutation $p_1, p_2, \dots, p_n$. Recall that sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once. Find three indices $i$, $j$ and $k$ such that: $1 \le i < j < k \le n$; $p_i < p_j$ and $p_j > p_k$. Or say that there are no such indices. --...
["import sys\nimport math\n#from queue import *\nimport random\n#sys.setrecursionlimit(int(1e6))\ninput = sys.stdin.readline\n \n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inara():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\...
{ "inputs": [ "3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n" ], "outputs": [ "YES\n2 3 4\nYES\n1 2 3\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1380/A
[ "import sys\nimport math\n#from queue import *\nimport random\n#sys.setrecursionlimit(int(1e6))\ninput = sys.stdin.readline\n \n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inara():\n return(list(map(int,input().split())))\ndef insr():\n s = input...
12
[ -1 ]
[ "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin" ]
true
62
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $26$ lowercase Latin letters will be arranged in some order. Polycarp uses the same password $s$ on all websites where he is registered (it is bad, but he doesn't c...
["T = int(input())\n\n\n\ndef solve(S):\n res = [S[0]]\n pos = 0 # think...\n for s in S[1:]:\n # can we change?\n if 0 <= pos-1 < len(res) and res[pos-1] == s:\n pos = pos-1\n elif 0 <= pos+1 < len(res) and res[pos+1] == s:\n pos = pos+1\n elif pos == 0 and s ...
{ "inputs": [ "5\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghijklmnopqrstuvwxyza\n" ], "outputs": [ "YES\nbacdefghijklmnopqrstuvwxyz\nYES\nedocabfghijklmnpqrstuvwxyz\nNO\nYES\nxzytabcdefghijklmnopqrsuvw\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1303/C
[ "T = int(input())\n\n\n\ndef solve(S):\n res = [S[0]]\n pos = 0 # think...\n for s in S[1:]:\n # can we change?\n if 0 <= pos-1 < len(res) and res[pos-1] == s:\n pos = pos-1\n elif 0 <= pos+1 < len(res) and res[pos+1] == s:\n pos = pos+1\n elif pos == 0 and...
4
[ -1 ]
[ "input()", "input()", "input()", "input()" ]
true
63
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally... Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack and he has $k$ friends. Lee would like to distribute all integers in his b...
["def solve():\n n, k = map(int,input().split())\n lst1 = list(map(int,input().split()))\n lst1.sort(reverse=True)\n ind = 0\n ans = 0\n lst2 = list(map(int,input().split()))\n lst2.sort()\n for i in range(k):\n lst2[i] -= 1\n if lst2[i] == 0: ans += lst1[ind]\n ans += lst1[...
{ "inputs": [ "3\n4 2\n1 13 7 17\n1 3\n6 2\n10 10 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n" ], "outputs": [ "48\n42\n8000000000\n" ] }
interview
https://codeforces.com/problemset/problem/1369/C
[ "def solve():\n n, k = map(int,input().split())\n lst1 = list(map(int,input().split()))\n lst1.sort(reverse=True)\n ind = 0\n ans = 0\n lst2 = list(map(int,input().split()))\n lst2.sort()\n for i in range(k):\n lst2[i] -= 1\n if lst2[i] == 0: ans += lst1[ind]\n ans += ls...
9
[ -1 ]
[ "input()", "input()", "sys.stdin", "stdin-alias.read*()", "input()", "input()", "sys.stdin", "input()", "input()" ]
true
64
There is a road with length $l$ meters. The start of the road has coordinate $0$, the end of the road has coordinate $l$. There are two cars, the first standing at the start of the road and the second standing at the end of the road. They will start driving simultaneously. The first car will drive from the start to th...
["import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef...
{ "inputs": [ "5\n2 10\n1 9\n1 10\n1\n5 7\n1 2 3 4 6\n2 1000000000\n413470354 982876160\n9 478\n1 10 25 33 239 445 453 468 477\n" ], "outputs": [ "3.000000000000000\n3.666666666666667\n2.047619047619048\n329737645.750000000000000\n53.700000000000000\n" ] }
interview
https://codeforces.com/problemset/problem/1408/C
[ "import sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \n...
11
[ -1 ]
[ "sys.stdin.read*()", "input()", "input()", "sys.stdin", "builtin input()", "sys.stdin", "input()", "input()", "sys.stdin", "input()", "builtin input()" ]
true
65
You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $n$ bosses in this tower, numbered from $1$ to $n$. The type of the $i$-th boss is $a_i$. If the $i$-th boss is easy then its type is $a_i = 0$, otherwise this boss is hard and its type is $a_i = 1$. During o...
["import math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [999999999] * n\n...
{ "inputs": [ "6\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0\n" ], "outputs": [ "2\n2\n2\n2\n1\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1418/C
[ "import math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [999999999] * ...
9
[ -1 ]
[ "builtin input()", "input()", "input()", "input()", "input()", "builtin input()", "sys.stdin", "input()", "stdin-alias.read*()" ]
true
67
This problem is different from the easy version. In this version Ujan makes at most $2n$ swaps. In addition, $k \le 1000, n \le 50$ and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. After struggling and faili...
["for _ in range(int(input())):\n n = int(input())\n s = input()\n t = input()\n\n d = {}\n for i in range(ord('a'), ord('z') + 1):\n d[chr(i)] = 0\n\n for cs in s:\n d[cs] += 1\n for ct in t:\n d[ct] += 1\n\n ok = True\n for e in d:\n if d[e] % 2 == 1:\n ...
{ "inputs": [ "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n" ], "outputs": [ "Yes\n1\n1 4\nNo\nNo\nYes\n3\n2 2\n1 2\n2 3\n" ] }
interview
https://codeforces.com/problemset/problem/1243/B2
[ "for _ in range(int(input())):\n n = int(input())\n s = input()\n t = input()\n\n d = {}\n for i in range(ord('a'), ord('z') + 1):\n d[chr(i)] = 0\n\n for cs in s:\n d[cs] += 1\n for ct in t:\n d[ct] += 1\n\n ok = True\n for e in d:\n if d[e] % 2 == 1:\n ...
2
[ -1 ]
[ "input()", "sys.stdin.read*()" ]
true
68
You have a string $s$ consisting of $n$ characters. Each character is either 0 or 1. You can perform operations on the string. Each operation consists of two steps: select an integer $i$ from $1$ to the length of the string $s$, then delete the character $s_i$ (the string length gets reduced by $1$, the indices of ch...
["from itertools import groupby\ndef main():\n N = int(input())\n S = input()\n \n C = [len(list(x[1])) for x in groupby(S)]\n M = len(C)\n dup_idx = []\n for i, c in enumerate(C):\n if c > 1:\n dup_idx.append(i)\n \n dup_idx.reverse()\n\n curr = 0\n while dup_idx:\n ...
{ "inputs": [ "5\n6\n111010\n1\n0\n1\n1\n2\n11\n6\n101010\n" ], "outputs": [ "3\n1\n1\n1\n3\n" ] }
interview
https://codeforces.com/problemset/problem/1430/D
[ "from itertools import groupby\ndef main():\n N = int(input())\n S = input()\n \n C = [len(list(x[1])) for x in groupby(S)]\n M = len(C)\n dup_idx = []\n for i, c in enumerate(C):\n if c > 1:\n dup_idx.append(i)\n \n dup_idx.reverse()\n\n curr = 0\n while dup_idx:\...
13
[ -1 ]
[ "input()", "sys.stdin.read*()", "sys.stdin", "input()", "input()", "input()", "input()", "sys.stdin", "sys.stdin.read*()", "input()", "input()", "input()", "sys.stdin" ]
true
69
Bertown is a city with $n$ buildings in a straight line. The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $n$, where the $i$-th character is "1" if there is a mine under the building number $i$ and "0" otherwise. Bertown's best sapper knows how to ...
["t = int(input())\n\nfor case in range(t):\n a, b = list(map(int, input().split()))\n s = input()\n\n z = 10000\n total = 0\n act = False\n\n for i in range(len(s)):\n cur = s[i]\n if cur == '0':\n z += 1\n act = False\n else:\n if not act:\n ...
{ "inputs": [ "2\n1 1\n01000010\n5 1\n01101110\n" ], "outputs": [ "2\n6\n" ] }
interview
https://codeforces.com/problemset/problem/1443/B
[ "t = int(input())\n\nfor case in range(t):\n a, b = list(map(int, input().split()))\n s = input()\n\n z = 10000\n total = 0\n act = False\n\n for i in range(len(s)):\n cur = s[i]\n if cur == '0':\n z += 1\n act = False\n else:\n if not act:\n ...
22
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "sys.stdin.read*()", "sys.stdin", "builtin input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()", "inpu...
true
70
Word $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$; $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \le i \le n-k$. For example, "abaaba" is a $3$-complete word, while "abccba" is not. Bob is given a word $s$ of length $n$ consisting of only l...
["import sys\ninput = sys.stdin.readline\nfrom collections import defaultdict\n\nclass Unionfind:\n def __init__(self, n):\n self.par = [-1]*n\n self.rank = [1]*n\n \n def root(self, x):\n r = x\n \n while not self.par[r]<0:\n r = self.par[r]\n \n t =...
{ "inputs": [ "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n" ], "outputs": [ "2\n0\n23\n16\n" ] }
interview
https://codeforces.com/problemset/problem/1332/C
[ "import sys\ninput = sys.stdin.readline\nfrom collections import defaultdict\n\nclass Unionfind:\n def __init__(self, n):\n self.par = [-1]*n\n self.rank = [1]*n\n \n def root(self, x):\n r = x\n \n while not self.par[r]<0:\n r = self.par[r]\n \n ...
4
[ -1 ]
[ "sys.stdin", "sys.stdin", "builtin input()", "sys.stdin" ]
true
71
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$. In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin. How many coins do you have to...
["t=int(input())\nwhile t>0 :\n n=int(input())\n a=list(map(int,input().split()))\n an=0\n s=0\n for i in a :\n if s+i>=0 :\n s+=i \n else :\n s+=i\n an-=s \n s=0\n print(an)\n t-=1 ", "\nT = int(input())\n\n#lets = 'abcdefghijklmnopqrstuvwx...
{ "inputs": [ "7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0\n" ], "outputs": [ "3\n0\n4\n1\n8\n3000000000\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1405/B
[ "t=int(input())\nwhile t>0 :\n n=int(input())\n a=list(map(int,input().split()))\n an=0\n s=0\n for i in a :\n if s+i>=0 :\n s+=i \n else :\n s+=i\n an-=s \n s=0\n print(an)\n t-=1 ", "\nT = int(input())\n\n#lets = 'abcdefghijklmnopqrs...
31
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "sys.stdin", "stdin-alias.read*()", "input()", "input()", "stdin-alias.read*()", "input()", "sys.stdin.read*()", "input()", "sys.std...
true
72
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements. Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes be...
["t = int(input())\n\nfor _ in range(t):\n n, k = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()]\n if len(set(a)) > k:\n print(-1)\n continue\n l = list(set(a))\n l.extend([1]*(k - len(l)))\n\n print(n*k)\n for _ in range(n):\n print(*l, end=\" \")\n ...
{ "inputs": [ "4\n4 2\n1 2 2 1\n4 3\n1 2 2 1\n3 2\n1 2 3\n4 4\n4 3 4 2\n" ], "outputs": [ "8\n1 2 1 2 1 2 1 2 \n12\n1 2 1 1 2 1 1 2 1 1 2 1 \n-1\n16\n2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 \n" ] }
interview
https://codeforces.com/problemset/problem/1348/B
[ "t = int(input())\n\nfor _ in range(t):\n n, k = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()]\n if len(set(a)) > k:\n print(-1)\n continue\n l = list(set(a))\n l.extend([1]*(k - len(l)))\n\n print(n*k)\n for _ in range(n):\n print(*l, end=\" \")...
11
[ -1 ]
[ "input()", "input()", "stdin alias", "input()", "input()", "input()", "sys.stdin", "sys.stdin", "input()", "input()", "input()" ]
true
73
You're given an array of $n$ integers between $0$ and $n$ inclusive. In one operation, you can choose any element of the array and replace it by the MEX of the elements of the array (which may change after the operation). For example, if the current array is $[0, 2, 2, 1, 4]$, you can choose the second element and re...
["def solve():\n n = int(input())\n a = list(map(int, input().split()))\n c = [0] * (n + 1)\n def inc():\n for i in range(n - 1):\n if a[i] > a[i + 1]:\n return False\n return True\n def calc():\n for i in range(n + 1):\n c[i] = 0\n for i i...
{ "inputs": [ "5\n3\n2 2 3\n3\n2 1 0\n7\n0 7 3 1 3 7 7\n9\n2 0 1 1 2 4 4 2 0\n9\n8 4 7 6 1 2 3 0 5\n" ], "outputs": [ "0\n\n2\n3 1\n4\n2 5 5 4\n11\n3 8 9 7 8 5 9 6 4 1 2\n10\n1 8 1 9 5 2 4 6 3 7\n" ] }
interview
https://codeforces.com/problemset/problem/1375/D
[ "def solve():\n n = int(input())\n a = list(map(int, input().split()))\n c = [0] * (n + 1)\n def inc():\n for i in range(n - 1):\n if a[i] > a[i + 1]:\n return False\n return True\n def calc():\n for i in range(n + 1):\n c[i] = 0\n for ...
2
[ -1 ]
[ "input()", "input()" ]
true
74
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other. Polycarp can summon $n$ different minions. The initial power level of the $i$-th minion is $a_i$, and when it is summoned, all previously summoned minions' power levels are increased by $b_i$. The m...
["def read_int():\n return int(input())\n\n\ndef read_ints():\n return list(map(int, input().split(' ')))\n\n\nt = read_int()\nfor case_num in range(t):\n n, k = read_ints()\n p = []\n for i in range(n):\n ai, bi = read_ints()\n p.append((bi, ai, i + 1))\n p.sort()\n dp = [[0 for j in...
{ "inputs": [ "3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n" ], "outputs": [ "8\n5 1 -1 3 -3 4 -4 2 \n3\n1 -1 2 \n5\n5 4 3 2 1 \n" ] }
interview
https://codeforces.com/problemset/problem/1354/F
[ "def read_int():\n return int(input())\n\n\ndef read_ints():\n return list(map(int, input().split(' ')))\n\n\nt = read_int()\nfor case_num in range(t):\n n, k = read_ints()\n p = []\n for i in range(n):\n ai, bi = read_ints()\n p.append((bi, ai, i + 1))\n p.sort()\n dp = [[0 for j...
4
[ -1 ]
[ "input()", "sys.stdin.read*()", "sys.stdin", "sys.stdin" ]
true
75
The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd. You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's n...
["import math\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n diags = 1/math.sin(math.pi/2/n)\n print(diags * math.cos(math.pi/4/n))\n", "import math\nimport sys\n\n#sys.stdin = open(\"in.txt\")\n\nt = int(input())\nfor i in range(t):\n n = int(input())\n n *= 2\n a = (n - 2) * math.pi / ...
{"inputs": ["3\n3\n5\n199\n"], "outputs": ["1.931851653\n3.196226611\n126.687663595\n"]}
interview
https://codeforces.com/problemset/problem/1354/C2
[ "import math\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n diags = 1/math.sin(math.pi/2/n)\n print(diags * math.cos(math.pi/4/n))\n", "import math\nimport sys\n\n#sys.stdin = open(\"in.txt\")\n\nt = int(input())\nfor i in range(t):\n n = int(input())\n n *= 2\n a = (n - 2) * math....
40
[ -1 ]
[ "input()", "input()", "sys.stdin", "input()", "sys.stdin", "stdin-alias.read*()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "sys.stdin", "builtin input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()",...
true
76
Lee is going to fashionably decorate his house for a party, using some regular convex polygons... Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-...
["t = int(input())\n\nfor _ in range(t):\n n = int(input())\n if n%4 == 0:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n # a, b = map(int, input().split())\n n = int(input())\n # arr = list(map(int, input().split()))\n if n % 4 == 0:\n print('YES')...
{ "inputs": [ "4\n3\n4\n12\n1000000000\n" ], "outputs": [ "NO\nYES\nYES\nYES\n" ] }
interview
https://codeforces.com/problemset/problem/1369/A
[ "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n if n%4 == 0:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n # a, b = map(int, input().split())\n n = int(input())\n # arr = list(map(int, input().split()))\n if n % 4 == 0:\n print('...
22
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "stdin-alias.read*()", "input()", "input()", "input()" ]
true
77
You have a fence consisting of $n$ vertical boards. The width of each board is $1$. The height of the $i$-th board is $a_i$. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from $2$ to $n$, the condition $a...
["3\n\nimport math\nimport os\nimport sys\n\n\nDEBUG = 'DEBUG' in os.environ\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\nINF = 10 ** 20\n\n\ndef solve(N, A, B):\n dp = {A[0]: 0, A[0] + 1: B[0], A[0...
{ "inputs": [ "3\n3\n2 4\n2 1\n3 5\n3\n2 3\n2 10\n2 6\n4\n1 7\n3 3\n2 6\n1000000000 2\n" ], "outputs": [ "2\n9\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1221/D
[ "3\n\nimport math\nimport os\nimport sys\n\n\nDEBUG = 'DEBUG' in os.environ\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\nINF = 10 ** 20\n\n\ndef solve(N, A, B):\n dp = {A[0]: 0, A[0] + 1: B[0], ...
21
[ -1 ]
[ "sys.stdin.read*()", "sys.stdin", "sys.stdin", "builtin input()", "stdin-alias.read*()", "sys.stdin", "sys.stdin", "sys.stdin", "sys.stdin", "stdin-alias.read*()", "input()", "stdin-alias.read*()", "stdin-alias.read*()", "stdin-alias.read*()", "stdin-alias.read*()", "sys.stdin", "std...
true
78
You are given a picture consisting of $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from the top to the bottom, columns are numbered from $1$ to $m$ from the left to the right. Each cell is painted either black or white. You think that this picture is not interesting enough. You consider a picture to be...
["import sys\n\nq = int(sys.stdin.readline().strip())\nfor t in range(0, q):\n n, m = list(map(int, sys.stdin.readline().strip().split()))\n L = []\n R = [0] * n\n C = [0] * m\n for i in range (0, n):\n L.append(sys.stdin.readline().strip())\n for j in range (0, m):\n if L[i][j] ...
{ "inputs": [ "9\n5 5\n..*..\n..*..\n*****\n..*..\n..*..\n3 4\n****\n.*..\n.*..\n4 3\n***\n*..\n*..\n*..\n5 5\n*****\n*.*.*\n*****\n..*.*\n..***\n1 4\n****\n5 5\n.....\n..*..\n.***.\n..*..\n.....\n5 3\n...\n.*.\n.*.\n***\n.*.\n3 3\n.*.\n*.*\n.*.\n4 4\n*.**\n....\n*.**\n*.**\n" ], "outputs": [ "0\n0\n0\n0\...
interview
https://codeforces.com/problemset/problem/1194/B
[ "import sys\n\nq = int(sys.stdin.readline().strip())\nfor t in range(0, q):\n n, m = list(map(int, sys.stdin.readline().strip().split()))\n L = []\n R = [0] * n\n C = [0] * m\n for i in range (0, n):\n L.append(sys.stdin.readline().strip())\n for j in range (0, m):\n if L[i][...
21
[ -1 ]
[ "sys.stdin.read*()", "input()", "sys.stdin", "input()", "stdin-alias.read*()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "input()" ]
true
79
An agent called Cypher is decrypting a message, that contains a composite number $n$. All divisors of $n$, which are greater than $1$, are placed in a circle. Cypher can choose the initial order of numbers in the circle. In one move Cypher can choose two adjacent numbers in a circle and insert their least common multi...
["from math import ceil\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n pf = []\n for i in range(2, ceil(n**0.5)+1):\n while n % i == 0:\n pf.append(i)\n n //= i\n if n > 1:\n pf.append(n)\n if len(pf) == 2 and pf[0] != pf[1]:\n print(pf[0], pf[1], pf[0]*pf[1])\n print(1)\n else...
{ "inputs": [ "3\n6\n4\n30\n" ], "outputs": [ "2 3 6 \n1\n2 4 \n0\n2 30 6 3 15 5 10 \n0\n" ] }
interview
https://codeforces.com/problemset/problem/1419/E
[ "from math import ceil\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n pf = []\n for i in range(2, ceil(n**0.5)+1):\n while n % i == 0:\n pf.append(i)\n n //= i\n if n > 1:\n pf.append(n)\n if len(pf) == 2 and pf[0] != pf[1]:\n print(pf[0], pf[1], pf[0]*pf[1])\n print(1)\n e...
12
[ -1 ]
[ "input()", "input()", "input()", "input()", "sys.stdin", "builtin input()", "sys.stdin", "builtin input()", "stdin-alias.read*()", "input()", "input()", "input()" ]
true
80
While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute $1 + 3$ using the calculator, he gets $2$ instead of $4$. But when he tries computing $1 + 4$, he gets the correct answer, $5$. Puzzled by this mystery, he opened up his ...
["def solve(L, R):\n res = 0\n for i in range(32):\n for j in range(32):\n l = (L >> i) << i\n r = (R >> j) << j\n #print(l, r)\n if l>>i&1==0 or r>>j&1==0:\n continue\n l -= 1<<i\n r -= 1<<j\n if l & r:\n ...
{ "inputs": [ "3\n1 4\n323 323\n1 1000000\n" ], "outputs": [ "8\n0\n3439863766\n" ] }
interview
https://codeforces.com/problemset/problem/1245/F
[ "def solve(L, R):\n res = 0\n for i in range(32):\n for j in range(32):\n l = (L >> i) << i\n r = (R >> j) << j\n #print(l, r)\n if l>>i&1==0 or r>>j&1==0:\n continue\n l -= 1<<i\n r -= 1<<j\n if l & r:\n ...
6
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()" ]
true
81
You are given three strings $a$, $b$ and $c$ of the same length $n$. The strings consist of lowercase English letters only. The $i$-th letter of $a$ is $a_i$, the $i$-th letter of $b$ is $b_i$, the $i$-th letter of $c$ is $c_i$. For every $i$ ($1 \leq i \leq n$) you must swap (i.e. exchange) $c_i$ with either $a_i$ or...
["for _ in range(int(input())):\n\ta, b, c = input(), input(), input()\n\tn = len(a)\n\n\tok = True\n\tfor i in range(n):\n\t\tif c[i] not in [a[i], b[i]]:\n\t\t\tok = False\n\n\tprint('YES' if ok else 'NO')\n", "for _ in range(int(input())):\n a=input()\n b=input()\n c=input()\n ans=\"YES\"\n for i in r...
{ "inputs": [ "4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim\n" ], "outputs": [ "NO\nYES\nYES\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1301/A
[ "for _ in range(int(input())):\n\ta, b, c = input(), input(), input()\n\tn = len(a)\n\n\tok = True\n\tfor i in range(n):\n\t\tif c[i] not in [a[i], b[i]]:\n\t\t\tok = False\n\n\tprint('YES' if ok else 'NO')\n", "for _ in range(int(input())):\n a=input()\n b=input()\n c=input()\n ans=\"YES\"\n for i...
12
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
82
A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). Let $p$ be any ...
["for __ in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n ar.reverse()\n print(*ar)", "for _ in range(int(input())):\n am = int(input())\n arr = list(map(int,input().split()))\n print(*list(reversed(arr)))", "for _ in range(int(input())):\n n = int(input())\n ...
{ "inputs": [ "3\n2\n1 2\n6\n2 1 6 5 4 3\n5\n2 4 3 1 5\n" ], "outputs": [ "2 1 \n3 4 5 6 1 2 \n5 1 3 4 2 \n" ] }
interview
https://codeforces.com/problemset/problem/1405/A
[ "for __ in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n ar.reverse()\n print(*ar)", "for _ in range(int(input())):\n am = int(input())\n arr = list(map(int,input().split()))\n print(*list(reversed(arr)))", "for _ in range(int(input())):\n n = int(input...
34
[ -1 ]
[ "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "i...
true
83
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other. He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits ...
["def one():\n return int(input())\n\n\ndef two():\n return list(map(int, input().split()))\n\n\ndef lis():\n return list(map(int, input().split()))\n\n\ndef st():\n return input()\n\n\nfor _ in range(one()):\n x, y, a, b = list(map(int, input().split()))\n d = y - x\n if d%(a+b)==0:\n print...
{ "inputs": [ "5\n0 10 2 3\n0 10 3 3\n900000000 1000000000 1 9999999\n1 2 1 1\n1 3 1 1\n" ], "outputs": [ "2\n-1\n10\n-1\n1\n" ] }
interview
https://codeforces.com/problemset/problem/1304/A
[ "def one():\n return int(input())\n\n\ndef two():\n return list(map(int, input().split()))\n\n\ndef lis():\n return list(map(int, input().split()))\n\n\ndef st():\n return input()\n\n\nfor _ in range(one()):\n x, y, a, b = list(map(int, input().split()))\n d = y - x\n if d%(a+b)==0:\n pr...
15
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()" ]
true
84
Let's look at the following process: initially you have an empty stack and an array $s$ of the length $l$. You are trying to push array elements to the stack in the order $s_1, s_2, s_3, \dots s_{l}$. Moreover, if the stack is empty or the element at the top of this stack is not equal to the current element, then you j...
["# encoding: utf-8\nfrom sys import stdin\n\ndef solve(a):\n\n # root node of tries denotes empty stack\n stack = [None]\n node_stack = [[1, {}]]\n trie = node_stack[-1]\n\n counter = 0\n for i in range(len(a)):\n el = a[i]\n\n if len(stack) == 0 or stack[-1] != el:\n\n curre...
{ "inputs": [ "3\n5\n2 1 1 2 2\n6\n1 2 1 1 3 2\n9\n3 1 2 2 1 6 6 3 3\n" ], "outputs": [ "4\n1\n8\n" ] }
interview
https://codeforces.com/problemset/problem/1241/F
[ "# encoding: utf-8\nfrom sys import stdin\n\ndef solve(a):\n\n # root node of tries denotes empty stack\n stack = [None]\n node_stack = [[1, {}]]\n trie = node_stack[-1]\n\n counter = 0\n for i in range(len(a)):\n el = a[i]\n\n if len(stack) == 0 or stack[-1] != el:\n\n cu...
2
[ -1 ]
[ "stdin-alias.read*()", "stdin-alias.read*()" ]
true
85
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows: if the character $w_{i-x}$ exists and is equal to 1, then $...
["import sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n s=input().rstrip()\n x=int(input())\n n=len(s)\n ans=[\"1\" for i in range(n)]\n for i in range(n):\n if s[i]==\"0\":\n if i-x>=0:\n ans[i-x]=\"0\"\n if i+x<n:\n ans[i+x]...
{ "inputs": [ "3\n101110\n2\n01\n1\n110\n1\n" ], "outputs": [ "111011\n10\n-1\n" ] }
interview
https://codeforces.com/problemset/problem/1400/C
[ "import sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n s=input().rstrip()\n x=int(input())\n n=len(s)\n ans=[\"1\" for i in range(n)]\n for i in range(n):\n if s[i]==\"0\":\n if i-x>=0:\n ans[i-x]=\"0\"\n if i+x<n:\n ans[i...
12
[ -1 ]
[ "sys.stdin", "sys.stdin", "input()", "input()", "stdin-alias.read*()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()" ]
true
86
Alexandra has an even-length array $a$, consisting of $0$s and $1$s. The elements of the array are enumerated from $1$ to $n$. She wants to remove at most $\frac{n}{2}$ elements (where $n$ — length of array) in the way that alternating sum of the array will be equal $0$ (i.e. $a_1 - a_2 + a_3 - a_4 + \dotsc = 0$). In o...
["def solve():\n n = int(input())\n lst = list(map(int,input().split()))\n if sum(lst) <= n // 2:\n print(n//2)\n print(\"0 \" * (n // 2))\n else:\n print(n//2 + (n // 2) % 2)\n print(\"1 \" * (n//2 + (n // 2) % 2))\nfor i in range(int(input())):\n solve()", "t = int(input())\...
{ "inputs": [ "4\n2\n1 0\n2\n0 0\n4\n0 1 1 1\n4\n1 1 0 0\n" ], "outputs": [ "1\n0 \n2\n0 0 \n2\n1 1 \n2\n0 0 \n" ] }
interview
https://codeforces.com/problemset/problem/1407/A
[ "def solve():\n n = int(input())\n lst = list(map(int,input().split()))\n if sum(lst) <= n // 2:\n print(n//2)\n print(\"0 \" * (n // 2))\n else:\n print(n//2 + (n // 2) % 2)\n print(\"1 \" * (n//2 + (n // 2) % 2))\nfor i in range(int(input())):\n solve()", "t = int(inpu...
14
[ -1 ]
[ "input()", "input()", "sys.stdin", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "sys.stdin.read*()" ]
true
87
Berland year consists of $m$ months with $d$ days each. Months are numbered from $1$ to $m$. Berland week consists of $w$ days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than $w$ days. A pair $(x, y)$ such that $x < y$ is ambiguous if day $x$ of m...
["import sys\n\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nns = lambda: readline().rstrip()\nni = lambda: int(readline().rstrip())\nnm = lambda: map(int, readline().split())\nnl = lambda: list(map(int, readline().split()))\nprn = lambda x: print(*x, sep='\\n')\n\ndef gcd(a, b):\n while b:\n ...
{ "inputs": [ "5\n6 7 4\n10 7 12\n12 30 7\n1 1 1\n3247834 10298779 625324\n" ], "outputs": [ "6\n9\n5\n0\n116461800\n" ] }
interview
https://codeforces.com/problemset/problem/1389/E
[ "import sys\n\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nns = lambda: readline().rstrip()\nni = lambda: int(readline().rstrip())\nnm = lambda: map(int, readline().split())\nnl = lambda: list(map(int, readline().split()))\nprn = lambda x: print(*x, sep='\\n')\n\ndef gcd(a, b):\n while b:\n ...
6
[ -1 ]
[ "sys.stdin", "input()", "sys.stdin.read*()", "input()", "input()", "input()" ]
true
88
Bob is playing with $6$-sided dice. A net of such standard cube is shown below. [Image] He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice. ...
["n = input()\na = list(map(int, input().split()))\nfor i in a:\n\tif i % 7 == 0 or (i // 7) % 2 == 1 or i <= 14:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')", "n = int(input())\narr = list(map(int, input().split()))\nfor x in arr:\n if x < 15:\n print('NO')\n continue\n if x % 14 >= 7 or x % 14 == ...
{ "inputs": [ "4\n29 34 19 38\n" ], "outputs": [ "YES\nYES\nYES\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1266/B
[ "n = input()\na = list(map(int, input().split()))\nfor i in a:\n\tif i % 7 == 0 or (i // 7) % 2 == 1 or i <= 14:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')", "n = int(input())\narr = list(map(int, input().split()))\nfor x in arr:\n if x < 15:\n print('NO')\n continue\n if x % 14 >= 7 or x % 1...
5
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()" ]
true
89
Monocarp had a tree which consisted of $n$ vertices and was rooted at vertex $1$. He decided to study BFS (Breadth-first search), so he ran BFS on his tree, starting from the root. BFS can be described by the following pseudocode:a = [] # the order in which vertices were processed q = Queue() q.put(1) # place the roo...
["from sys import stdin\n\ntt = int(stdin.readline())\n\nfor loop in range(tt):\n\n n = int(stdin.readline())\n a = list(map(int,stdin.readline().split()))\n\n lis = [ [1] ]\n\n now = []\n tmp = 0\n\n for i in range(1,n):\n if len(now) == 0:\n now.append(a[i])\n tmp = 1\n ...
{ "inputs": [ "3\n4\n1 4 3 2\n2\n1 2\n3\n1 2 3\n" ], "outputs": [ "3\n1\n1\n" ] }
interview
https://codeforces.com/problemset/problem/1437/D
[ "from sys import stdin\n\ntt = int(stdin.readline())\n\nfor loop in range(tt):\n\n n = int(stdin.readline())\n a = list(map(int,stdin.readline().split()))\n\n lis = [ [1] ]\n\n now = []\n tmp = 0\n\n for i in range(1,n):\n if len(now) == 0:\n now.append(a[i])\n tmp = 1...
3
[ -1 ]
[ "stdin-alias.read*()", "input()", "sys.stdin" ]
true
90
You are given an array $a$, consisting of $n$ integers. Each position $i$ ($1 \le i \le n$) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new on...
["import math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n can = list(map(int, inp...
{ "inputs": [ "5\n3\n1 3 2\n0 0 0\n4\n2 -3 4 -1\n1 1 1 1\n7\n-8 4 -2 -6 4 7 1\n1 0 0 0 1 1 0\n5\n0 1 -4 6 3\n0 0 0 1 1\n6\n-1 7 10 4 -8 -1\n1 0 0 0 0 1\n" ], "outputs": [ "3 2 1 \n2 -3 4 -1 \n-8 4 1 -2 4 7 -6 \n1 0 -4 6 3 \n-1 10 7 4 -8 -1 \n" ] }
interview
https://codeforces.com/problemset/problem/1418/B
[ "import math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n can = list(map(int, ...
22
[ -1 ]
[ "builtin input()", "sys.stdin", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "stdin-alias.re...
true
91
Permutation $p$ is a sequence of integers $p=[p_1, p_2, \dots, p_n]$, consisting of $n$ distinct (unique) positive integers between $1$ and $n$, inclusive. For example, the following sequences are permutations: $[3, 4, 1, 2]$, $[1]$, $[1, 2]$. The following sequences are not permutations: $[0]$, $[1, 2, 1]$, $[2, 3]$, ...
["t = int(input())\nfor faw in range(t):\n n = int(input())\n a = [0] + list(map(int,input().split()))\n nun = []\n ans = []\n f = True\n for i in range(1, n + 1):\n if a[i] == a[i-1]:\n if len(nun) == 0:\n f = False\n break\n else:\n ...
{ "inputs": [ "4\n5\n1 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n" ], "outputs": [ "1 3 4 5 2 \n-1\n2 1 \n1 \n" ] }
interview
https://codeforces.com/problemset/problem/1227/B
[ "t = int(input())\nfor faw in range(t):\n n = int(input())\n a = [0] + list(map(int,input().split()))\n nun = []\n ans = []\n f = True\n for i in range(1, n + 1):\n if a[i] == a[i-1]:\n if len(nun) == 0:\n f = False\n break\n else:\n ...
24
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
92
You are given two strings of equal length $s$ and $t$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice ver...
["for _ in range(int(input())):\n print(\"YES\" if set(input()).intersection(input()) else \"NO\")\n", "for _ in range(int(input())):\n s = input()\n t = input()\n ans = 'NO'\n for c in s:\n if c in t:\n ans = 'YES'\n break\n print(ans)", "q = int(input())\nfor z in range(...
{ "inputs": [ "3\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n" ], "outputs": [ "YES\nYES\nNO\n" ] }
interview
https://codeforces.com/problemset/problem/1223/B
[ "for _ in range(int(input())):\n print(\"YES\" if set(input()).intersection(input()) else \"NO\")\n", "for _ in range(int(input())):\n s = input()\n t = input()\n ans = 'NO'\n for c in s:\n if c in t:\n ans = 'YES'\n break\n print(ans)", "q = int(input())\nfor z in...
20
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()" ]
true
93
Santa has to send presents to the kids. He has a large stack of $n$ presents, numbered from $1$ to $n$; the topmost present has number $a_1$, the next present is $a_2$, and so on; the bottom present has number $a_n$. All numbers are distinct. Santa has a list of $m$ distinct presents he has to send: $b_1$, $b_2$, ...,...
["for tc in range(int(input())):\n n,m = list(map(int, input().split()))\n al = list(map(int, input().split()))\n bl = list(map(int, input().split()))\n aidx = {}\n for i,e in enumerate(al):\n aidx[e]=i\n midx = -1\n res = 0\n for i,e in enumerate(bl):\n idx = aidx[e]\n if i...
{ "inputs": [ "2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n3 1\n" ], "outputs": [ "5\n8\n" ] }
interview
https://codeforces.com/problemset/problem/1279/C
[ "for tc in range(int(input())):\n n,m = list(map(int, input().split()))\n al = list(map(int, input().split()))\n bl = list(map(int, input().split()))\n aidx = {}\n for i,e in enumerate(al):\n aidx[e]=i\n midx = -1\n res = 0\n for i,e in enumerate(bl):\n idx = aidx[e]\n i...
12
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "sys.stdin", "input()", "input()", "sys.stdin", "sys.stdin" ]
true
94
RedDreamer has an array $a$ consisting of $n$ non-negative integers, and an unlucky integer $T$. Let's denote the misfortune of array $b$ having length $m$ as $f(b)$ — the number of pairs of integers $(i, j)$ such that $1 \le i < j \le m$ and $b_i + b_j = T$. RedDreamer has to paint each element of $a$ into one of two...
["T = int(input())\nfor test in range(T):\n n,t = list(map(int,input().split()))\n a = list(map(int,input().split()))\n res = []\n j=0\n for i in a:\n if(i*2<t):\n res+=[\"0\"]\n elif(i*2>t):\n res+=[\"1\"]\n else:\n res.append([\"0\",\"1\"][j])\n ...
{ "inputs": [ "2\n6 7\n1 2 3 4 5 6\n3 6\n3 3 3\n" ], "outputs": [ "0 0 0 1 1 1 \n1 0 1 \n" ] }
interview
https://codeforces.com/problemset/problem/1417/B
[ "T = int(input())\nfor test in range(T):\n n,t = list(map(int,input().split()))\n a = list(map(int,input().split()))\n res = []\n j=0\n for i in a:\n if(i*2<t):\n res+=[\"0\"]\n elif(i*2>t):\n res+=[\"1\"]\n else:\n res.append([\"0\",\"1\"][j])\n ...
19
[ -1 ]
[ "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "stdin-alias.read*()", "sys.stdin", "input()", "input()", "input()", "input()" ]
true
95
You are given a integer $n$ ($n > 0$). Find any integer $s$ which satisfies these conditions, or report that there are no such numbers: In the decimal representation of $s$: $s > 0$, $s$ consists of $n$ digits, no digit in $s$ equals $0$, $s$ is not divisible by any of it's digits. -----Input----- The input c...
["#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competitive ...
{"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["-1\n23\n233\n2333\n"]}
interview
https://codeforces.com/problemset/problem/1326/A
[ "#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competiti...
4
[ -1 ]
[ "stdin alias", "input()", "sys.stdin", "input()" ]
true
96
Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes. The exam consists of $n$ problems that can be solved in $T$ minutes. Thus, the exam begins at time $0$ and ends at time $T$. Petya can leave the exam at any integer tim...
["import sys\nfrom operator import itemgetter\n\ndef count(a, b, num_a, num_b, cur_time):\n\tcurrent_result = 0\n\t#print('count time = ', cur_time, \"num_a =\", num_a, 'num_b = ', num_b)\n\tif num_a * a + num_b * b <= cur_time and cur_time >= 0:\n\t\tcur_time -= num_a * a + num_b * b\n\t\tcurrent_result = num_a + num_...
{ "inputs": [ "10\n3 5 1 3\n0 0 1\n2 1 4\n2 5 2 3\n1 0\n3 2\n1 20 2 4\n0\n16\n6 20 2 5\n1 1 0 1 0 0\n0 8 2 9 11 6\n4 16 3 6\n1 0 1 1\n8 3 5 6\n6 20 3 6\n0 1 0 0 1 0\n20 11 3 20 16 17\n7 17 1 6\n1 1 0 1 0 0 0\n1 7 0 11 10 15 10\n6 17 2 6\n0 0 1 0 0 1\n7 6 3 7 10 12\n5 17 2 5\n1 1 1 1 0\n17 11 10 6 4\n1 1 1 2\n0\n1...
interview
https://codeforces.com/problemset/problem/1282/C
[ "import sys\nfrom operator import itemgetter\n\ndef count(a, b, num_a, num_b, cur_time):\n\tcurrent_result = 0\n\t#print('count time = ', cur_time, \"num_a =\", num_a, 'num_b = ', num_b)\n\tif num_a * a + num_b * b <= cur_time and cur_time >= 0:\n\t\tcur_time -= num_a * a + num_b * b\n\t\tcurrent_result = num_a + n...
6
[ -1 ]
[ "input()", "sys.stdin", "input()", "sys.stdin.read*()", "input()", "input()" ]
true
97
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better ...
["import sys\nreader = (s.rstrip() for s in sys.stdin)\ninput = reader.__next__\n\ndef solve():\n s,c = input().split()\n # i,j\u3067j\u304c\u8907\u6570\u3042\u308b\u3068\u304d\n n = len(s)\n for i in range(n-1):\n prev = s[i]\n pos = i\n for j in range(i+1, n):\n if s[j]<pre...
{ "inputs": [ "3\nAZAMON APPLE\nAZAMON AAAAAAAAAAALIBABA\nAPPLE BANANA\n" ], "outputs": [ "AAZMON\n---\nAEPLP\n" ] }
interview
https://codeforces.com/problemset/problem/1281/B
[ "import sys\nreader = (s.rstrip() for s in sys.stdin)\ninput = reader.__next__\n\ndef solve():\n s,c = input().split()\n # i,jでjが複数あるとき\n n = len(s)\n for i in range(n-1):\n prev = s[i]\n pos = i\n for j in range(i+1, n):\n if s[j]<prev:\n prev = s[j]\n ...
12
[ -1 ]
[ "sys.stdin", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "sys.stdin" ]
true
98
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time. So the team is considered perfect if it includ...
["q = int(input())\nfor _ in range(q):\n\tc, m, x = list(map(int, input().split()))\n\tprint(min([c, m, (c + m + x) // 3]))", "q = int(input())\nfor i in range(q):\n c, m, x = map(int, input().split())\n ans = min(c, m, x)\n c -= ans\n m -= ans\n x -= ans\n ans += min(c, m, (c + m) // 3)\n print(an...
{ "inputs": [ "6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1\n" ], "outputs": [ "1\n3\n0\n0\n1\n3\n" ] }
interview
https://codeforces.com/problemset/problem/1221/C
[ "q = int(input())\nfor _ in range(q):\n\tc, m, x = list(map(int, input().split()))\n\tprint(min([c, m, (c + m + x) // 3]))", "q = int(input())\nfor i in range(q):\n c, m, x = map(int, input().split())\n ans = min(c, m, x)\n c -= ans\n m -= ans\n x -= ans\n ans += min(c, m, (c + m) // 3)\n pri...
25
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "inp...
true
99
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way... The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s). In one move he can choose two consecutive characters $s_i$ an...
["for _ in range(int(input())):\n # a, b = map(int, input().split())\n n = int(input())\n # arr = list(map(int, input().split()))\n s = input()\n l = 0\n r = n - 1\n if s.count('0') == n:\n print(s)\n continue\n if s.count('1') == n:\n print(s)\n continue\n while s...
{ "inputs": [ "5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n" ], "outputs": [ "0001111111\n001\n01\n0\n1\n" ] }
interview
https://codeforces.com/problemset/problem/1369/B
[ "for _ in range(int(input())):\n # a, b = map(int, input().split())\n n = int(input())\n # arr = list(map(int, input().split()))\n s = input()\n l = 0\n r = n - 1\n if s.count('0') == n:\n print(s)\n continue\n if s.count('1') == n:\n print(s)\n continue\n whil...
15
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "sys.stdin", "sys.stdin.read*()", "input()", "stdin-alias.read*()", "input()", "input()", "input()", "input()", "sys.stdin", "input()" ]
true
100
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it. Each day Tanya eats exactly...
["n = int(input())\n\nfor _ in range(n):\n a, b, c = list(map(int, input().split()))\n\n print(min((a+b+c)//2, a+b, a+c, b+c))\n", "t = int(input())\nfor _ in range(t):\n li = list(map(int, input().split()))\n li = sorted(li)\n if li[0] + li[1] <= li[2]:\n print(li[0] + li[1])\n else:\n ...
{ "inputs": [ "6\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n" ], "outputs": [ "1\n2\n2\n10\n5\n9\n" ] }
interview
https://codeforces.com/problemset/problem/1263/A
[ "n = int(input())\n\nfor _ in range(n):\n a, b, c = list(map(int, input().split()))\n\n print(min((a+b+c)//2, a+b, a+c, b+c))\n", "t = int(input())\nfor _ in range(t):\n li = list(map(int, input().split()))\n li = sorted(li)\n if li[0] + li[1] <= li[2]:\n print(li[0] + li[1])\n else:\n ...
25
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "sys.stdin", ...
true
101
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute. On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polyc...
["import os\nfrom io import BytesIO\n\n# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nfor i in range(int(input())):\n a, b, c, r = list(map(int, input().split()))\n a, b = min(a, b), max(a, b)\n left = max(c - r, a)\n right = min(c + r, b)\n if right >= a and left <= right:\n print(b...
{ "inputs": [ "9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n" ], "outputs": [ "7\n0\n4\n0\n30\n5\n4\n0\n3\n" ] }
interview
https://codeforces.com/problemset/problem/1282/A
[ "import os\nfrom io import BytesIO\n\n# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nfor i in range(int(input())):\n a, b, c, r = list(map(int, input().split()))\n a, b = min(a, b), max(a, b)\n left = max(c - r, a)\n right = min(c + r, b)\n if right >= a and left <= right:\n prin...
16
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()" ]
true
102
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp! Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years? According to Polycarp, a positive integer is beautiful if it cons...
["s = []\nfor i in range(1, 10):\n k = 0\n for l in range(1, 10):\n k *= 10\n k += i\n s.append(k)\ns.sort()\nq = int(input())\nwhile q:\n n = int(input())\n l = 0\n r = len(s)\n while l + 1 < r:\n m = (l + r) // 2\n if s[m] <= n:\n l = m\n else:\n ...
{ "inputs": [ "6\n18\n1\n9\n100500\n33\n1000000000\n" ], "outputs": [ "10\n1\n9\n45\n12\n81\n" ] }
interview
https://codeforces.com/problemset/problem/1259/A
[ "s = []\nfor i in range(1, 10):\n k = 0\n for l in range(1, 10):\n k *= 10\n k += i\n s.append(k)\ns.sort()\nq = int(input())\nwhile q:\n n = int(input())\n l = 0\n r = len(s)\n while l + 1 < r:\n m = (l + r) // 2\n if s[m] <= n:\n l = m\n else:...
99
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "inp...
true
103
Ashish and Vivek play a game on a matrix consisting of $n$ rows and $m$ columns, where they take turns claiming cells. Unclaimed cells are represented by $0$, while claimed cells are represented by $1$. The initial state of the matrix is given. There can be some claimed cells in the initial state. In each turn, a play...
["t = int(input())\n\nfor _ in range(t):\n n, m = [int(x) for x in input().split()]\n grid = [[int(x) for x in input().split()] for _ in range(n)]\n\n rows = sum(1 for x in grid if all(y == 0 for y in x))\n cols = sum(1 for j in range(m) if all(grid[i][j] == 0 for i in range(n)))\n\n res = min(rows, cols...
{ "inputs": [ "4\n2 2\n0 0\n0 0\n2 2\n0 0\n0 1\n2 3\n1 0 1\n1 1 0\n3 3\n1 0 0\n0 0 0\n1 0 0\n" ], "outputs": [ "Vivek\nAshish\nVivek\nAshish\n" ] }
interview
https://codeforces.com/problemset/problem/1365/A
[ "t = int(input())\n\nfor _ in range(t):\n n, m = [int(x) for x in input().split()]\n grid = [[int(x) for x in input().split()] for _ in range(n)]\n\n rows = sum(1 for x in grid if all(y == 0 for y in x))\n cols = sum(1 for j in range(m) if all(grid[i][j] == 0 for i in range(n)))\n\n res = min(rows, c...
19
[ -1 ]
[ "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()", "input()", "input()", "input()", "stdin-alias.read*()", "input()", "input()", "input()", "input()" ]
true
104
You are given a colored permutation $p_1, p_2, \dots, p_n$. The $i$-th element of the permutation has color $c_i$. Let's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \dots$ where all elements have same color ($c[i] = c[p[i]] = c[p[p[i]]] = \dots$). We can also define a multiplication of ...
["from sys import stdin\ninput = stdin.readline\nq = int(input())\nfor rwerew in range(q):\n\tn = int(input())\n\tp = list(map(int,input().split()))\n\tc = list(map(int,input().split()))\n\tfor i in range(n):\n\t\tp[i] -= 1\n\tprzyn = [0] * n\n\tgrupa = []\n\ti = 0\n\twhile i < n:\n\t\tif przyn[i] == 1:\n\t\t\ti += 1\n...
{ "inputs": [ "3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n" ], "outputs": [ "1\n5\n2\n" ] }
interview
https://codeforces.com/problemset/problem/1327/D
[ "from sys import stdin\ninput = stdin.readline\nq = int(input())\nfor rwerew in range(q):\n\tn = int(input())\n\tp = list(map(int,input().split()))\n\tc = list(map(int,input().split()))\n\tfor i in range(n):\n\t\tp[i] -= 1\n\tprzyn = [0] * n\n\tgrupa = []\n\ti = 0\n\twhile i < n:\n\t\tif przyn[i] == 1:\n\t\t\ti += ...
5
[ -1 ]
[ "builtin input()", "input()", "sys.stdin.read*()", "builtin input()", "sys.stdin.read*()" ]
true
105
— Hey folks, how do you like this problem? — That'll do it. BThero is a powerful magician. He has got $n$ piles of candies, the $i$-th pile initially contains $a_i$ candies. BThero can cast a copy-paste spell as follows: He chooses two piles $(i, j)$ such that $1 \le i, j \le n$ and $i \ne j$. All candies from pi...
["import math\nt = int(input())\nfor test in range(t):\n n,k = map(int,input().split())\n A = list(map(int,input().split()))\n A.sort()\n ans = 0\n for i in range(1,n):\n if(A[i]>k):\n ans = 0\n break\n rem = k-A[i]\n ans+=rem//A[0]\n print(ans)", "t = int(in...
{ "inputs": [ "3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n" ], "outputs": [ "1\n5\n4\n" ] }
interview
https://codeforces.com/problemset/problem/1417/A
[ "import math\nt = int(input())\nfor test in range(t):\n n,k = map(int,input().split())\n A = list(map(int,input().split()))\n A.sort()\n ans = 0\n for i in range(1,n):\n if(A[i]>k):\n ans = 0\n break\n rem = k-A[i]\n ans+=rem//A[0]\n print(ans)", "t = i...
16
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "stdin-alias.read*()", "input()", "input()", "sys.stdin.read*()", "sys.stdin.read*()", "input()", "input()", "input()", "builtin input()" ]
true
106
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group. To optimize ...
["t = int(input())\n\nfor ti in range(t):\n\tn = int(input())\n\n\tlri = [None for _ in range(n)]\n\n\tfor _ in range(n):\n\t\tli, ri = list(map(int, input().split()))\n\t\tlri[_] = (li, ri, _)\n\n\tlri.sort()\n\n\tt = [None for _ in range(n)]\n\n\tct, t[lri[0][2]], eg = 1, 1, lri[0][1]\n\n\tfor i in range(1, n):\n\t\t...
{ "inputs": [ "3\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n" ], "outputs": [ "2 1 \n-1\n1 1 2 \n" ] }
interview
https://codeforces.com/problemset/problem/1101/C
[ "t = int(input())\n\nfor ti in range(t):\n\tn = int(input())\n\n\tlri = [None for _ in range(n)]\n\n\tfor _ in range(n):\n\t\tli, ri = list(map(int, input().split()))\n\t\tlri[_] = (li, ri, _)\n\n\tlri.sort()\n\n\tt = [None for _ in range(n)]\n\n\tct, t[lri[0][2]], eg = 1, 1, lri[0][1]\n\n\tfor i in range(1, n):\n\...
23
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()" ]
true
108
You're given an array $a_1, \ldots, a_n$ of $n$ non-negative integers. Let's call it sharpened if and only if there exists an integer $1 \le k \le n$ such that $a_1 < a_2 < \ldots < a_k$ and $a_k > a_{k+1} > \ldots > a_n$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: ...
["for _ in range(int(input())):\n n=int(input())\n li=list(map(int,input().split()))\n ans=0\n for i in range(n):\n if li[i]>=i:\n ans+=1\n else:\n break\n for i in range(n):\n if li[n-1-i]>=i:\n ans+=1\n else:\n break\n if ans>n:...
{ "inputs": [ "10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n" ], "outputs": [ "Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\n" ] }
interview
https://codeforces.com/problemset/problem/1291/B
[ "for _ in range(int(input())):\n n=int(input())\n li=list(map(int,input().split()))\n ans=0\n for i in range(n):\n if li[i]>=i:\n ans+=1\n else:\n break\n for i in range(n):\n if li[n-1-i]>=i:\n ans+=1\n else:\n break\n if ans...
6
[ -1 ]
[ "input()", "input()", "input()", "input()", "sys.stdin", "input()" ]
true
110
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $k$ ($k \ge 3$). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of h...
["for _ in range(int(input())):\n n, k = tuple(map(int, input().split()))\n arr = list(map(int, input().split()))\n\n peaks = [0 for i in range(n)]\n for i in range(1, n - 1):\n if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:\n peaks[i] = 1\n\n cnt = 0\n max_peaks = 0\n answer = 0...
{ "inputs": [ "5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 0 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n" ], "outputs": [ "3 2\n2 2\n2 1\n3 1\n2 3\n" ] }
interview
https://codeforces.com/problemset/problem/1341/B
[ "for _ in range(int(input())):\n n, k = tuple(map(int, input().split()))\n arr = list(map(int, input().split()))\n\n peaks = [0 for i in range(n)]\n for i in range(1, n - 1):\n if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:\n peaks[i] = 1\n\n cnt = 0\n max_peaks = 0\n answer ...
13
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "sys.stdin", "input()", "input()", "input()" ]
true
112
Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of the lattice, Heidi knows the level of Zombie Contamination – the number of ...
["import math\n\ndef lexComp(a, b):\n if a[0] != b[0]:\n return -1 if a[0] < b[0] else 1\n if a[1] != b[1]:\n return -1 if a[1] < b[1] else 1\n return 0\n\ndef turn(a, b, c):\n return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])\n \ndef dist2(a, b):\n return (a[0] - b[0]...
{ "inputs": [ "8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0\n" ], "outputs": [ "4\n2 3\n2 4\n6 6\n5 2\n4\n2 2\n2 3\n3 3\n3 2\n3\n2 5\n4 5\n4 2\n" ] }
interview
https://codeforces.com/problemset/problem/690/B2
[ "import math\n\ndef lexComp(a, b):\n if a[0] != b[0]:\n return -1 if a[0] < b[0] else 1\n if a[1] != b[1]:\n return -1 if a[1] < b[1] else 1\n return 0\n\ndef turn(a, b, c):\n return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])\n \ndef dist2(a, b):\n return (a[0] - b...
1
[ -1 ]
[ "input()" ]
true
113
Bob watches TV every day. He always sets the volume of his TV to $b$. However, today he is angry to find out someone has changed the volume to $a$. Of course, Bob has a remote control that can change the volume. There are six buttons ($-5, -2, -1, +1, +2, +5$) on the control, which in one press can either increase or ...
["import math\nfrom decimal import Decimal\nimport heapq\nfrom collections import deque\ndef na():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\treturn n,b\n \n \ndef nab():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tc = [int(x) for x in input().split()]\n\treturn n,b,c\n \n \ndef...
{ "inputs": [ "3\n4 0\n5 14\n3 9\n" ], "outputs": [ "2\n3\n2\n" ] }
interview
https://codeforces.com/problemset/problem/1255/A
[ "import math\nfrom decimal import Decimal\nimport heapq\nfrom collections import deque\ndef na():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\treturn n,b\n \n \ndef nab():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tc = [int(x) for x in input().split()]\n\treturn n,b,c\n \n \n...
23
[ -1 ]
[ "input()", "input()", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "stdin alias", "input()", "input()", "input()", "input()", "sys.stdin.read*()", "input()", "input()", "input...
true
114
You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$. The heroes clear the dungeon day by day. In the beginning of each day, you choo...
["import sys\ninput = sys.stdin.readline\nimport bisect\n\nt=int(input())\n\nfor testcases in range(t):\n n=int(input())\n A=list(map(int,input().split()))\n m=int(input())\n PS=[tuple(map(int,input().split())) for i in range(m)]\n\n PS.sort()\n K=[PS[-1]]\n\n for a,b in PS[::-1][1:]:\n if b...
{ "inputs": [ "2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n" ], "outputs": [ "5\n-1\n" ] }
interview
https://codeforces.com/problemset/problem/1257/D
[ "import sys\ninput = sys.stdin.readline\nimport bisect\n\nt=int(input())\n\nfor testcases in range(t):\n n=int(input())\n A=list(map(int,input().split()))\n m=int(input())\n PS=[tuple(map(int,input().split())) for i in range(m)]\n\n PS.sort()\n K=[PS[-1]]\n\n for a,b in PS[::-1][1:]:\n i...
19
[ -1 ]
[ "sys.stdin", "sys.stdin", "sys.stdin.read*()", "builtin input()", "sys.stdin", "input()", "stdin-alias.read*()", "builtin input()", "input()", "sys.stdin", "sys.stdin", "sys.stdin", "stdin alias", "input()", "sys.stdin.read*()", "input()", "sys.stdin.read*()", "sys.stdin", "sys.s...
true
115
Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells. There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell c...
["class BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n wh...
{ "inputs": [ "6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n" ], "outputs": [ "5\n25\n10\n15\n36\n21\n" ] }
interview
https://codeforces.com/problemset/problem/1398/E
[ "class BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n ...
2
[ -1 ]
[ "sys.stdin", "sys.stdin" ]
true
116
Let's call an array $a_1, a_2, \dots, a_m$ of nonnegative integer numbers good if $a_1 + a_2 + \dots + a_m = 2\cdot(a_1 \oplus a_2 \oplus \dots \oplus a_m)$, where $\oplus$ denotes the bitwise XOR operation. For example, array $[1, 2, 3, 6]$ is good, as $1 + 2 + 3 + 6 = 12 = 2\cdot 6 = 2\cdot (1\oplus 2 \oplus 3 \oplu...
["for nt in range(int(input())):\n\tn=int(input())\n\tl=list(map(int,input().split()))\n\ts=sum(l)\n\te=l[0]\n\tfor i in range(1,n):\n\t\te=e^l[i]\n\tif s==2*e:\n\t\tprint(0)\n\t\tprint ()\n\telse:\n\t\tprint(2)\n\t\tprint(e,s+e)\n", "for _ in range(int(input())):\n\tn=int(input())\n\tl=list(map(int,input().split()))\n...
{ "inputs": [ "3\n4\n1 2 3 6\n1\n8\n2\n1 1\n" ], "outputs": [ "0\n\n2\n4 4\n3\n2 2 6\n" ] }
interview
https://codeforces.com/problemset/problem/1270/C
[ "for nt in range(int(input())):\n\tn=int(input())\n\tl=list(map(int,input().split()))\n\ts=sum(l)\n\te=l[0]\n\tfor i in range(1,n):\n\t\te=e^l[i]\n\tif s==2*e:\n\t\tprint(0)\n\t\tprint ()\n\telse:\n\t\tprint(2)\n\t\tprint(e,s+e)\n", "for _ in range(int(input())):\n\tn=int(input())\n\tl=list(map(int,input().split(...
2
[ -1 ]
[ "input()", "input()" ]
true
117
All techniques in the ninja world consist of hand seals. At the moment Naruto is learning a new technique, which consists of $n\cdot m$ different seals, denoted by distinct numbers. All of them were written in an $n\times m$ table. The table is lost now. Naruto managed to remember elements of each row from left to rig...
["from sys import stdin\ninput = stdin.readline\n\ntests = int(input())\nfor test in range(tests):\n n, m = list(map(int, input().split()))\n a = [[0] * m for _ in range(n)]\n r = [[int(i) for i in input().split()] for _ in range(n)]\n c = [[int(i) for i in input().split()] for _ in range(m)]\n z = [[-1,...
{ "inputs": [ "2\n2 3\n6 5 4\n1 2 3\n1 6\n2 5\n3 4\n3 1\n2\n3\n1\n3 1 2\n" ], "outputs": [ "1 2 3 \n6 5 4 \n3 \n1 \n2 \n" ] }
interview
https://codeforces.com/problemset/problem/1413/B
[ "from sys import stdin\ninput = stdin.readline\n\ntests = int(input())\nfor test in range(tests):\n n, m = list(map(int, input().split()))\n a = [[0] * m for _ in range(n)]\n r = [[int(i) for i in input().split()] for _ in range(n)]\n c = [[int(i) for i in input().split()] for _ in range(m)]\n z = [[...
3
[ -1 ]
[ "builtin input()", "input()", "builtin input()" ]
true
118
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the...
["__MULTITEST = True\n\n## solve\ndef solve():\n n, x = map(int, input().split())\n a = list(map(int, input().split()))\n a.sort()\n\n group = 0\n ptr = n-1\n members = 0\n\n currentMin = int(1e10)\n while ptr > -1:\n currentMin = min(currentMin, a[ptr])\n members += 1\n\n i...
{ "inputs": [ "3\n5 10\n7 11 2 9 5\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n" ], "outputs": [ "2\n1\n0\n" ] }
interview
https://codeforces.com/problemset/problem/1380/C
[ "__MULTITEST = True\n\n## solve\ndef solve():\n n, x = map(int, input().split())\n a = list(map(int, input().split()))\n a.sort()\n\n group = 0\n ptr = n-1\n members = 0\n\n currentMin = int(1e10)\n while ptr > -1:\n currentMin = min(currentMin, a[ptr])\n members += 1\n\n ...
16
[ -1 ]
[ "input()", "sys.stdin.read*()", "input()", "sys.stdin", "sys.stdin", "sys.stdin", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "input()", "builtin input()" ]
true