problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
962cf33a1adcfb26737ccaf45cf8e75b
UNKNOWN
Polycarp has $n$ different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100". Polycarp wants to offer his set of $n$ binary words to play a game "words". In this game, players name words and each next word (starting from ...
["for _ in range(int(input())):\n n = int(input())\n mass = []\n zo = 0\n oz = 0\n zz = 0\n oo = 0\n ozs = []\n zos = []\n ozss = set()\n zoss = set()\n for j in range(n):\n k = input()\n mass.append(k)\n if k[0] == '0' and k[-1] == '1':\n zoss.add(k)\n ...
{ "inputs": [ "4\n4\n0001\n1000\n0011\n0111\n3\n010\n101\n0\n2\n00000\n00001\n4\n01\n001\n0001\n00001\n" ], "outputs": [ "1\n3 \n-1\n0\n\n2\n1 2 \n" ] }
INTERVIEW
PYTHON3
CODEFORCES
7,488
330c01483ac5cf93445094814ccde9e9
UNKNOWN
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
PYTHON3
CODEFORCES
11,766
e8ae3ea804a726415e12e2b0619d8657
UNKNOWN
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
PYTHON3
CODEFORCES
4,987
77bff89f88fb331d10ada7fdf7516a0c
UNKNOWN
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
PYTHON3
CODEFORCES
5,604
5fed32e40953d04d2484a2e3c0a9e115
UNKNOWN
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
PYTHON3
CODEFORCES
14,822
73e105d7ecbf71b65982171480b3b320
UNKNOWN
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
PYTHON3
CODEFORCES
9,925
0909957229d6cebb473d76a737ec91b6
UNKNOWN
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
PYTHON3
CODEFORCES
6,332
3405eaaaadf349f12c390f72fd7dd221
UNKNOWN
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
PYTHON3
CODEFORCES
7,221
176d90c3d6f26d628f367b8ed9ac04fa
UNKNOWN
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
PYTHON3
CODEFORCES
8,769
34d1cc0b6161bd0cd79c6a67e1533327
UNKNOWN
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
PYTHON3
CODEFORCES
11,078
cf77b3b0ee986a69f70a5c26d45d17d1
UNKNOWN
Given a permutation $p$ of length $n$, find its subsequence $s_1$, $s_2$, $\ldots$, $s_k$ of length at least $2$ such that: $|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$ is as big as possible over all subsequences of $p$ with length at least $2$. Among all such subsequences, choose the one whose length, $k$, is as small...
["for _ in range(int(input())):\n # n, x = map(int, input().split())\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [arr[0]]\n for i in range(1, n - 1):\n if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:\n ans.append(arr[i])\n elif arr[i - 1] > arr[i] and arr[i...
{ "inputs": [ "2\n3\n3 2 1\n4\n1 3 4 2\n" ], "outputs": [ "2\n3 1 \n3\n1 4 2 \n" ] }
INTERVIEW
PYTHON3
CODEFORCES
7,495
6269d284c882ec6a08449515dc3640db
UNKNOWN
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
PYTHON3
CODEFORCES
7,466
b8138a1c593e81eadfa6b4b55c1adb7c
UNKNOWN
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
PYTHON3
CODEFORCES
3,530
8bbcfe67ed06bab743eed68fb6c75934
UNKNOWN
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
PYTHON3
CODEFORCES
11,787
f305514873bf816cc4b4f6fc064ec05e
UNKNOWN
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
PYTHON3
CODEFORCES
1,169
12cb6e576009ac7ca5ac7810dd86bf23
UNKNOWN
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
PYTHON3
CODEFORCES
3,281
ae8a323cbaf30027ead06c956c5bac03
UNKNOWN
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
PYTHON3
CODEFORCES
10,403
70dd36d6409c10ac2589d1860ec0e1cd
UNKNOWN
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
PYTHON3
CODEFORCES
16,421
b05f1df459126a4f036a18abc0bc4b2b
UNKNOWN
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it. Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all custo...
["q = int(input())\nfor _ in range(q):\n n, m = list(map(int, input().split()))\n info = [list(map(int, input().split())) for i in range(n)]\n info = sorted(info)\n now =(m, m)\n time = 0\n flag = True\n for i in range(n):\n t, l, h = info[i]\n l_now = now[0] - (t - time)\n h_n...
{ "inputs": [ "4\n3 0\n5 1 2\n7 3 5\n10 -1 0\n2 12\n5 7 10\n10 16 20\n3 -100\n100 0 0\n100 -50 50\n200 100 100\n1 100\n99 -100 0\n" ], "outputs": [ "YES\nNO\nYES\nNO\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
8,600
4642ebe77d4cb8cab781896d0188c4d0
UNKNOWN
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
PYTHON3
CODEFORCES
3,806
5ff89e62fecd77b5632ad48313c4857b
UNKNOWN
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
PYTHON3
CODEFORCES
12,755
3698be65e0f72b250d7498516713b2ef
UNKNOWN
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
PYTHON3
CODEFORCES
9,883
d0f275c0ed8f48da7b2199374f52cd05
UNKNOWN
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
PYTHON3
CODEFORCES
740
cdce6afd2605a002667c5d17e0afee8b
UNKNOWN
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
PYTHON3
CODEFORCES
19,233
1184c873ca6b3244bb71485489feeea5
UNKNOWN
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
PYTHON3
CODEFORCES
7,642
caf3daa3a3a4bf2ef4307c20496620c2
UNKNOWN
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
PYTHON3
CODEFORCES
11,523
5742fbb878f1c7bbab970810dee208dd
UNKNOWN
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
PYTHON3
CODEFORCES
7,678
9400eb0a8c23476237f6217d0e005666
UNKNOWN
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
PYTHON3
CODEFORCES
23,456
3d41912002ffa53e9de75ed97958e890
UNKNOWN
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
PYTHON3
CODEFORCES
1,528
70c44f48d6fb89dd0378022514985a7e
UNKNOWN
Numbers $1, 2, 3, \dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $\frac{a + b}{2}$ rounded up instead. You should perform the given operation $n - 1$ times and make the resulting number that will be le...
["t=int(input())\nfor i in range(t):\n n=int(input())\n print(2)\n print(n-1,n)\n for i in range(n-2,0,-1):\n print(i,i+2)", "for _ in range (int(input())):\n n=int(input())\n hold=n\n res=[]\n for i in range (n-1,0,-1):\n res.append((hold,i))\n hold=(hold+i+1)//2\n print...
{"inputs": ["1\n4\n"], "outputs": ["2\n4 3\n4 2\n3 1\n"]}
INTERVIEW
PYTHON3
CODEFORCES
8,161
09ce0b60e40747fb55a0475458c8efcc
UNKNOWN
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
PYTHON3
CODEFORCES
1,983
3a87df4d8e5d57902077ab2533cde9a0
UNKNOWN
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains a_{i} worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a_1, worms in second pile are labeled with nu...
["n=int(input())\na=list(map(int,input().split()))\nk=[]\nfor i in range(n):\n for j in range(a[i]):\n k.append(i+1)\nm=int(input())\nb=list(map(int,input().split()))\nfor i in b:\n print(k[i-1])", "n, p, m, w = int(input()), list(map(int, input().split())), int(input()), sorted(enumerate(map(int, input()....
{ "inputs": [ "5\n2 7 3 4 9\n3\n1 25 11\n" ], "outputs": [ "1\n5\n3\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
9,674
aa8fed4bab5f857fb8819e6a9793828f
UNKNOWN
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
PYTHON3
CODEFORCES
13,112
3ecff7fdd72aad97a72c79eed8193fae
UNKNOWN
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
PYTHON3
CODEFORCES
9,927
45080f5995ef67bf5cb15ac3ffb97ae1
UNKNOWN
You are given a sequence $a_1, a_2, \dots, a_n$, consisting of integers. You can apply the following operation to this sequence: choose some integer $x$ and move all elements equal to $x$ either to the beginning, or to the end of $a$. Note that you have to move all these elements in one direction in one operation. Fo...
["def main():\n from sys import stdin, stdout\n for _ in range(int(stdin.readline())):\n n = int(stdin.readline())\n inp1 = [-1] * (n + 1)\n inp2 = [-1] * (n + 1)\n for i, ai in enumerate(map(int, stdin.readline().split())):\n if inp1[ai] < 0:\n inp1[ai] = i\n...
{ "inputs": [ "3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n4 2 5 2 6 2 7\n" ], "outputs": [ "2\n0\n1\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
7,048
a34fdf6e5d629ce2a4856bd208d40f37
UNKNOWN
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
PYTHON3
CODEFORCES
17,397
7428af4b53adc42bee5ae2467e82262d
UNKNOWN
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
PYTHON3
CODEFORCES
19,903
e6d5b1a06d4594b2c9120a59886854bb
UNKNOWN
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
PYTHON3
CODEFORCES
6,311
ad991921e47052be4332f485455911cd
UNKNOWN
Today the kindergarten has a new group of $n$ kids who need to be seated at the dinner table. The chairs at the table are numbered from $1$ to $4n$. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers $a$ and $b$ ($a \neq b$) will indulge if: $gcd(a, b) = 1$ or, $a$ divides...
["t=int(input())\nfor you in range(t):\n n=int(input())\n for i in range(n):\n print(4*n-2*i,end=\" \")\n print()\n", "for _ in range(int(input())):\n n = int(input())\n for i in range(4 * n, 2 * n, -2):\n print(i, end=' ')\n print(' ')\n", "import sys\ninput=sys.stdin.readline\nfrom col...
{"inputs": ["3\n2\n3\n4\n"], "outputs": ["8 6 \n12 10 8 \n16 14 12 10 \n"]}
INTERVIEW
PYTHON3
CODEFORCES
4,701
3f380bfdc57085bbe99440e1cb679c11
UNKNOWN
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \dots s_{n}$ of length $n$ where each letter is either R, S or P. While initializing, the bot is choosing a starting index $pos$ ($1 \le pos \le n$), and then it can ...
["#\n# ------------------------------------------------\n# ____ _ Generatered using\n# / ___| | |\n# | | __ _ __| | ___ _ __ ______ _\n# | | / _` |/ _` |/ _ \\ '_ \\|_ / _` |\n# | |__| (_| | (_| | __/ | | |/ / (_| |\n# \\____\\____|\\__...
{ "inputs": [ "3\nRRRR\nRSP\nS\n" ], "outputs": [ "PPPP\nPPP\nR\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
8,049
cbfc05c9e54582272770ee87004cbd8b
UNKNOWN
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
PYTHON3
CODEFORCES
3,060
c39d4fe77ac8882f4a720a71680148df
UNKNOWN
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
PYTHON3
CODEFORCES
4,540
fea3ac166aedcbe0acb378203af8a857
UNKNOWN
Let's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers $4$, $200000$, $10203$ are classy and numbers $4231$, $102306$, $7277420000$ are not. You are given a segment $[L; R]$. Count the number of classy integers $x$ such that $L \le x \le R$...
["\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\n# this math tutorial is boring\n\nclassy=set()\n\nfor i in range(19):\n for j in range(i):\n for k in range(j):\n for a in range(10): # a=0 for good measure\n for b in range(10):\n for c...
{ "inputs": [ "4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n" ], "outputs": [ "1000\n1\n0\n2\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
22,343
bf34818d72785a00a810fca87ac31c3c
UNKNOWN
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
["def main():\n t = int(input())\n for z in range(t):\n n, k, d1, d2 = map(int, input().split())\n if n % 3 != 0:\n print('no')\n continue\n f = 0\n for i in [-1, +1]:\n for j in [-1, +1]:\n w = (k - i * d1 - j * d2)\n if f...
{ "inputs": [ "5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2\n" ], "outputs": [ "yes\nyes\nyes\nno\nno\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
17,287
6b43b13060dc2e1325fd246b3f9b4377
UNKNOWN
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ...
["n=int(input())\na=sorted(int(input()) for _ in range(n))\nprint(sum(a[i]*a[-i-1] for i in range(n))%10007)", "n = int(input())\nA = [0] * n\nfor i in range(n):\n per = int(input())\n A[i] = per\nA.sort()\nanswer = 0\nfor i in range(n):\n answer = (answer + A[i] * A[n - i - 1]) % 10007\nprint(answer)", "n = ...
{ "inputs": [ "2\n1\n3\n" ], "outputs": [ "6\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
5,103
f64a48b61c57a42d550670725b5626d5
UNKNOWN
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
PYTHON3
CODEFORCES
8,156
43f75813af6ba312c2ee52668ba77739
UNKNOWN
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
PYTHON3
CODEFORCES
7,057
0345b1ab308e92892c27e572184a99b9
UNKNOWN
A penguin Rocher has $n$ sticks. He has exactly one stick with length $i$ for all $1 \le i \le n$. He can connect some sticks. If he connects two sticks that have lengths $a$ and $b$, he gets one stick with length $a + b$. Two sticks, that were used in the operation disappear from his set and the new connected stick a...
["for __ in range(int(input())):\n n = int(input())\n print((n + 1) // 2)", "from math import ceil\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n print(int(ceil(n/2)))", "for _ in range(int(input())):\n print((int(input())+1)//2)", "tests = int(input())\nfor _ in range(tests):\n n = in...
{ "inputs": [ "4\n1\n2\n3\n4\n" ], "outputs": [ "1\n1\n2\n2\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
7,204
45523960cb7e92e330274344eb490f58
UNKNOWN
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
PYTHON3
CODEFORCES
12,910
96756e67830a26d73b479d7ebcfae22f
UNKNOWN
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
PYTHON3
CODEFORCES
2,562
2e9150d76319709b063c9f39f99b51c4
UNKNOWN
You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically...
["mem = [[[0 for i in range(51)] for j in range(31)] for k in range(31)]\n\n\ndef f(n, m, k):\n if mem[n][m][k]:\n return mem[n][m][k]\n if (n*m == k) or (k == 0):\n return 0\n cost = 10**9\n for x in range(1, n//2 + 1):\n for z in range(k+1):\n cost = min(cost, m*m + f(n-x, ...
{ "inputs": [ "4\n2 2 1\n2 2 3\n2 2 2\n2 2 4\n" ], "outputs": [ "5\n5\n4\n0\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
18,476
4a694943c96faa8ca81da9fdf0b4b3f2
UNKNOWN
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
PYTHON3
CODEFORCES
2,469
4da3efcf0364e852643c12ef68f3da4c
UNKNOWN
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game. Tzuyu gave Sana two integers $a$ and $b$ and a really important quest. In order to complete the quest, Sana has to output the smallest possible value of ($a \oplus x$) + ($b \oplus x$) for any given $x$, where $\oplus$ denotes the b...
["n = int(input())\nfor _ in range(n):\n a, b = list(map(int, input().split()))\n print(a ^ b)\n", "for __ in range(int(input())):\n a, b = list(map(int, input().split()))\n print(a ^ b)", "import sys\ninput = sys.stdin.readline\n\ndef main():\n a, b = map(int, input().split())\n print(a^b)\n \nfor...
{ "inputs": [ "6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1\n" ], "outputs": [ "10\n13\n891\n18\n6237\n0\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
8,914
72b37142da4a7140b4e8ef0143009db5
UNKNOWN
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
PYTHON3
CODEFORCES
6,140
00a563be2f4d772d9390996de2cd9d90
UNKNOWN
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
PYTHON3
CODEFORCES
3,905
3c8e1dc9d85e07e26f094fbee563e88c
UNKNOWN
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
PYTHON3
CODEFORCES
5,109
a63956cea9ab484c367a89dc804c6a7d
UNKNOWN
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
PYTHON3
CODEFORCES
9,396
01058be4ce16a63a49d36d45482cce07
UNKNOWN
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
PYTHON3
CODEFORCES
5,502
6f2066a79c853c0f1f37a861facca93f
UNKNOWN
Kuroni has $n$ daughters. As gifts for them, he bought $n$ necklaces and $n$ bracelets: the $i$-th necklace has a brightness $a_i$, where all the $a_i$ are pairwise distinct (i.e. all $a_i$ are different), the $i$-th bracelet has a brightness $b_i$, where all the $b_i$ are pairwise distinct (i.e. all $b_i$ are differ...
["#list(map(int,input().split()))\nt=int(input())\nfor _ in range(t):\n n=int(input())\n aa=list(map(int,input().split()))\n bb=list(map(int,input().split()))\n aa.sort()\n bb.sort()\n print(*aa)\n print(*bb)\n", "for _ in range(int(input())):\n n = int(input())\n a = sorted(list(map(int, inp...
{ "inputs": [ "2\n3\n1 8 5\n8 4 5\n3\n1 7 5\n6 1 2\n" ], "outputs": [ "1 8 5\n8 4 5\n5 1 7\n6 2 1\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
1,955
de0e47ec67446c8a2c25526053407f6e
UNKNOWN
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
PYTHON3
CODEFORCES
4,061
2f345fa817575a0e1926d4858bea16c3
UNKNOWN
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
PYTHON3
CODEFORCES
11,087
8e87dc09a38221d2c8b3461b100ef899
UNKNOWN
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
PYTHON3
CODEFORCES
15,009
425333f74b6e0ea12ad11714f0656ad6
UNKNOWN
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
PYTHON3
CODEFORCES
3,779
97fe4bcf4daa5313302a1b149a29d423
UNKNOWN
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
PYTHON3
CODEFORCES
12,903
fca57a49548835e7bbd36ceacf3c61bf
UNKNOWN
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
PYTHON3
CODEFORCES
5,071
5629443420cba392598c0da96431047d
UNKNOWN
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
PYTHON3
CODEFORCES
1,903
9dcb177a1e099f245f8032b6c1c3df50
UNKNOWN
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
PYTHON3
CODEFORCES
7,937
106b52dd1adb96d87812baa8b1bbc0d3
UNKNOWN
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
PYTHON3
CODEFORCES
17,886
fbb611a360cadb9286d829956e2da67a
UNKNOWN
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
PYTHON3
CODEFORCES
26,602
78252506379bee572d0d1cbfc496d62e
UNKNOWN
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
PYTHON3
CODEFORCES
25,270
7c888644ba54ffff07997269f817924e
UNKNOWN
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
PYTHON3
CODEFORCES
4,980
c9ca800858e8ba8c3a72820e6cd8a795
UNKNOWN
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
PYTHON3
CODEFORCES
3,301
b792407e010acb73c248656b01defe2b
UNKNOWN
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
PYTHON3
CODEFORCES
7,164
d86eeb6094b4de21faa254e3fa7fdae7
UNKNOWN
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
PYTHON3
CODEFORCES
2,047
7f35f4ca04f0b171b3bbf5b3890723ca
UNKNOWN
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
PYTHON3
CODEFORCES
10,249
a28b1284127b963997ea375ce7faa9d5
UNKNOWN
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
PYTHON3
CODEFORCES
6,133
af49d0be035ce5991510b80f4e26e764
UNKNOWN
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
PYTHON3
CODEFORCES
3,746
ed02f382347c47dcf4c06f94f72671f7
UNKNOWN
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
PYTHON3
CODEFORCES
11,854
3e1d543822997dd506b828c85595b3c7
UNKNOWN
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
PYTHON3
CODEFORCES
16,249
ace890f75b4f7f98e0bea9f47d542c1e
UNKNOWN
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
PYTHON3
CODEFORCES
4,846
ad5dd3db9b4d722ec164f04dd435c57d
UNKNOWN
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
PYTHON3
CODEFORCES
6,668
6ba09ff83a835e7cc9d73635338450e4
UNKNOWN
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
PYTHON3
CODEFORCES
11,704
4e0c658043c27446e5cc03f4783eae9d
UNKNOWN
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
PYTHON3
CODEFORCES
1,624
e8a743640c756d86f22f2dce022061e8
UNKNOWN
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
PYTHON3
CODEFORCES
8,558
90bce746f6b86242e0a6d89025737de4
UNKNOWN
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
PYTHON3
CODEFORCES
8,459
07c72e281391e8f97f7212c754e0496f
UNKNOWN
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
PYTHON3
CODEFORCES
5,997
d897515f2f005003479fed6273354846
UNKNOWN
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
PYTHON3
CODEFORCES
8,848
d0a59d676c07821ca8fd6021e4c91b8e
UNKNOWN
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
PYTHON3
CODEFORCES
5,815
3b8fbd05e11f14b9195be3d296ef1815
UNKNOWN
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
PYTHON3
CODEFORCES
26,513
58b1882d409f9276498a5494be542cd9
UNKNOWN
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
PYTHON3
CODEFORCES
10,384
3c4b27a68e971ae8a1d5eac6c3902b6e
UNKNOWN
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
PYTHON3
CODEFORCES
6,787
2e68d1d4c767a8354c0b5e2f58a01a97
UNKNOWN
— 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
PYTHON3
CODEFORCES
6,762
35224ae31851e2ea5fe3ebbaac0b08cf
UNKNOWN
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
PYTHON3
CODEFORCES
16,436
22231d367e819336561f0dea54c15eff
UNKNOWN
Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification: The first box stores toys with fun values in range of $(-\infty,-1]$. The second box stores toys with fun values in range of $(-1, 0)$. The third box stor...
["t = int(input())\nfor _ in range(t):\n a, b, c, d = [int(i) for i in input().split(\" \")]\n sgn = (a+b)%2\n small = False\n large = False\n if a == 0 and d == 0:\n small = True\n if b == 0 and c == 0:\n large = True\n okay = [True] * 4\n if sgn == 0:\n okay[0] = False\n okay[1] = False\n else:\n...
{ "inputs": [ "2\n1 2 0 1\n0 1 0 0\n" ], "outputs": [ "Ya Ya Tidak Tidak\nTidak Ya Tidak Tidak\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
5,384
d0c9a5ac8f5dcb2ab50c6efb17934741
UNKNOWN
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
PYTHON3
CODEFORCES
2,648
29e905dbde46eec529b202c9bf400938
UNKNOWN
You have a bag of size $n$. Also you have $m$ boxes. The size of $i$-th box is $a_i$, where each $a_i$ is an integer non-negative power of two. You can divide boxes into two parts of equal size. Your goal is to fill the bag completely. For example, if $n = 10$ and $a = [1, 1, 32]$ then you have to divide the box of s...
["import sys\nimport math\nfrom collections import defaultdict\nfrom collections import deque\nfrom itertools import combinations\nfrom itertools import permutations\ninput = lambda : sys.stdin.readline().rstrip()\nread = lambda : list(map(int, input().split()))\ngo = lambda : 1/0\ndef write(*args, sep=\"\\n\"):\n for...
{ "inputs": [ "3\n10 3\n1 32 1\n23 4\n16 1 4 1\n20 5\n2 1 16 1 8\n" ], "outputs": [ "2\n-1\n0\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
2,694
2b8620a5b814a6dbb4f5fd0702b0b0cc
UNKNOWN
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
PYTHON3
CODEFORCES
8,272
86d3ae13c5ad8c72a4cb7bebcb114f94
UNKNOWN
You are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integer k > 1 and split the image into k by k blocks. If n and m are not divisib...
["#!/usr/bin/env python\n# coding:utf-8\n# Copyright (C) dirlt\n\nfrom sys import stdin\n\n\ndef run(n, m, pixels):\n ans = 1 << 30\n\n acc = [[0] * (m + 1) for _ in range(n + 1)]\n for i in range(n):\n for j in range(m):\n acc[i + 1][j + 1] = acc[i + 1][j] + int(pixels[i][j])\n for j ...
{ "inputs": [ "3 5\n00100\n10110\n11001\n" ], "outputs": [ "5\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
1,270
cc8b5554fabb248d64b5b0c8a98208bd
UNKNOWN
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
PYTHON3
CODEFORCES
11,093
3ea1a97b50f3224d68b845395347e447
UNKNOWN
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
PYTHON3
CODEFORCES
23,746