problem_id
int64
0
4.72k
problem_content
stringlengths
152
5.64k
code_prompt
stringclasses
1 value
difficulty
stringclasses
3 values
solutions
stringlengths
98
1.12M
test_cases
stringlengths
70
1.03M
0
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, ...
interview
[{"code": "s = input()\nn = len(s)\nind = -1\nf = False\nfor i in range(n):\n if s[i] == '[':\n f = True\n elif s[i] == ':':\n if f:\n ind = i\n break\nbind = -1\nf = False\nfor i in range(n-1,-1,-1):\n if s[i] == ']':\n f = True\n elif s[i] == ':':\n if f:\...
[{"input": "|[a:b:|]\n", "output": "4\n"}, {"input": "|]:[|:]\n", "output": "-1\n"}, {"input": ":][:\n", "output": "-1\n"}, {"input": ":[]:\n", "output": "-1\n"}, {"input": "[[:]]\n", "output": "-1\n"}, {"input": "[::]\n", "output": "4\n"}, {"input": "]:|:[\n", "output": "-1\n"}, {"input": ":::::]\n", "output": "-1\n"}...
1
Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. -----Input----- The first line contains the positive inte...
interview
[{"code": "num = list(map(int, input()))\nbest = num[:]\nfor i in range(-1, -len(num) - 1, -1):\n if num[i] == 0:\n continue\n num[i] -= 1\n for j in range(i + 1, 0):\n num[j] = 9\n if sum(num) > sum(best):\n best = num[:]\ns = ''.join(map(str, best)).lstrip('0')\nprint(s)\n", "passed":...
[{"input": "100\n", "output": "99\n"}, {"input": "48\n", "output": "48\n"}, {"input": "521\n", "output": "499\n"}, {"input": "1\n", "output": "1\n"}, {"input": "2\n", "output": "2\n"}, {"input": "3\n", "output": "3\n"}, {"input": "39188\n", "output": "38999\n"}, {"input": "5\n", "output": "5\n"}, {"input": "6\n", "outp...
2
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not. You are given current year in Berland. Your task is to find how long...
interview
[{"code": "def main():\n s = input()\n n = len(s)\n t = int(str(int(s[0]) + 1) + '0' * (n - 1))\n\n print(t - int(s))\n\nmain()\n", "passed": true, "time": 0.16, "memory": 15128.0, "status": "done"}, {"code": "s = input()\nx = int(s)\ny = int(str(int(s[0]) + 1) + '0' * (len(s) - 1))\nprint(y - x)", "passed"...
[{"input": "4\n", "output": "1\n"}, {"input": "201\n", "output": "99\n"}, {"input": "4000\n", "output": "1000\n"}, {"input": "9\n", "output": "1\n"}, {"input": "10\n", "output": "10\n"}, {"input": "1\n", "output": "1\n"}, {"input": "100000000\n", "output": "100000000\n"}, {"input": "900000000\n", "output": "100000000\n...
3
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$. Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters yo...
interview
[{"code": "from collections import defaultdict as dd\nimport math\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n\n\nn, q=mi()\n\nints=[]\n\n\nfor _ in range(q):\n\tst, end=mi()\n\tints...
[{"input": "7 5\n1 4\n4 5\n5 6\n6 7\n3 5\n", "output": "7\n"}, {"input": "4 3\n1 1\n2 2\n3 4\n", "output": "2\n"}, {"input": "4 4\n1 1\n2 2\n2 3\n3 4\n", "output": "3\n"}, {"input": "3 3\n1 3\n1 1\n2 2\n", "output": "3\n"}, {"input": "6 3\n1 6\n1 3\n4 6\n", "output": "6\n"}, {"input": "3 3\n1 1\n2 3\n2 3\n", "output": ...
4
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to kno...
interview
[{"code": "x=int(input())\nh,m=list(map(int,input().split()))\ndef ok(mm):\n while mm<0: mm+=1440\n hh=mm//60\n mm=mm%60\n return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7\nfor y in range(999):\n if ok(h*60+m-y*x):\n print(y)\n return\n", "passed": true, "time": 0.17, "memory": 15204.0, "status": "done"...
[{"input": "3\n11 23\n", "output": "2\n"}, {"input": "5\n01 07\n", "output": "0\n"}, {"input": "34\n09 24\n", "output": "3\n"}, {"input": "2\n14 37\n", "output": "0\n"}, {"input": "14\n19 54\n", "output": "9\n"}, {"input": "42\n15 44\n", "output": "12\n"}, {"input": "46\n02 43\n", "output": "1\n"}, {"input": "14\n06 41...
5
Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this se...
interview
[{"code": "n, pos, l, r = map(int, input().split())\n\nif l > 1 and r < n:\n if l <= pos and pos <= r:\n if pos - l < r - pos:\n print(pos - l + 1 + r - l + 1)\n else:\n print(r - pos + 1 + r - l + 1)\n elif pos > r:\n print(pos - r + 1 + r - l + 1)\n else:\n p...
[{"input": "6 3 2 4\n", "output": "5\n"}, {"input": "6 3 1 3\n", "output": "1\n"}, {"input": "5 2 1 5\n", "output": "0\n"}, {"input": "100 1 1 99\n", "output": "99\n"}, {"input": "100 50 1 99\n", "output": "50\n"}, {"input": "100 99 1 99\n", "output": "1\n"}, {"input": "100 100 1 99\n", "output": "2\n"}, {"input": "100...
6
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! $m$ Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $cur...
interview
[{"code": "for _ in range(int(input())):\n n, x = list(map(int, input().split()))\n A = []\n for _1 in range(n):\n d, h = list(map(int, input().split()))\n A.append([d, h])\n A.sort(reverse=True)\n if A[0][0] >= x:\n print(1)\n else:\n x -= A[0][0]\n mz = 0\n fo...
[{"input": "3\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n", "output": "2\n3\n-1\n"}, {"input": "7\n5 1000000000\n2 1\n1 10\n1 1\n4 1000000000\n3 3\n1 1000000000\n5 1\n2 999999999\n3 1\n2 10000000\n4 10000000\n10000000 999999999\n9999900 12\n9999999 55\n9999999 1\n2 1000000\n1000000 1000000\n...
7
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that ba...
interview
[{"code": "n, m = map(int, input().split())\nif (m >= n): print(n)\nelse:\n c = n - m\n l = 0\n r = 10 ** 18\n while r - l > 1:\n md = (r + l) // 2\n if (1 + md) * md // 2 < c:\n l = md\n else:\n r = md\n print(r + m)", "passed": true, "time": 0.18, "memory": 14...
[{"input": "5 2\n", "output": "4\n"}, {"input": "8 1\n", "output": "5\n"}, {"input": "32 5\n", "output": "12\n"}, {"input": "1024 1024\n", "output": "1024\n"}, {"input": "58044 52909\n", "output": "53010\n"}, {"input": "996478063 658866858\n", "output": "658892843\n"}, {"input": "570441179141911871 511467058318039545\n...
8
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the fir...
interview
[{"code": "cards=list(input().split())\nlm=[0]*9\nlp=[0]*9\nls=[0]*9\nfor item in cards:\n if item[1]=='m':\n lm[int(item[0])-1]+=1\n elif item[1]=='p':\n lp[int(item[0])-1]+=1\n else :\n ls[int(item[0])-1]+=1\nif max(lm)==3 or max(lp)==3 or max(ls)==3:\n print(0)\nelse :\n flag=0\n ...
[{"input": "1s 2s 3s\n", "output": "0\n"}, {"input": "9m 9m 9m\n", "output": "0\n"}, {"input": "3p 9m 2p\n", "output": "1\n"}, {"input": "8p 2s 9m\n", "output": "2\n"}, {"input": "5s 8m 5s\n", "output": "1\n"}, {"input": "9s 4s 3m\n", "output": "2\n"}, {"input": "4p 8m 9s\n", "output": "2\n"}, {"input": "8s 5s 7p\n", "...
9
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss? Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ...
interview
[{"code": "#!/usr/bin/env python3\n\n\nd = int(input().strip())\n[n, m] = list(map(int, input().strip().split()))\nHxds = [0 for _ in range(n)]\nHyds = [0 for _ in range(m)]\nVxds = [0 for _ in range(n)]\nVyds = [0 for _ in range(m)]\nds = []\nfor i in range(d):\n\tx1, y1, x2, y2 = list(map(int, input().strip().split()...
[{"input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n", "output": "1\n"}, {"input": "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n", "output": "2\n"}, {"input": "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n", "output": "-1\n"}, {"input": "1\n1 2\n1 1 1 2\n0 0 0 0\n", "output": "1\n"}, {"input": "1\n2 1\n2 1 1 1\n0 0 0 0\n", "output"...
10
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. -----Input----- The first line of the input ...
interview
[{"code": "n=int(input())\nr=n%7\nd=n//7\nprint(2*d+max(0,r-5),2*d+min(r,2))\n", "passed": true, "time": 0.15, "memory": 14624.0, "status": "done"}, {"code": "minday = maxday = 0\n\nfor i in range(int(input())) :\n k = i % 7\n if k == 0 or k == 1 : maxday += 1\n if k == 5 or k == 6 : minday += 1\n\nprint(minda...
[{"input": "14\n", "output": "4 4\n"}, {"input": "2\n", "output": "0 2\n"}, {"input": "1\n", "output": "0 1\n"}, {"input": "3\n", "output": "0 2\n"}, {"input": "4\n", "output": "0 2\n"}, {"input": "5\n", "output": "0 2\n"}, {"input": "6\n", "output": "1 2\n"}, {"input": "7\n", "output": "2 2\n"}, {"input": "8\n", "outp...
11
Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a a...
interview
[{"code": "3\n# Copyright (C) 2016 Sayutin Dmitry.\n#\n# This program is free software; you can redistribute it and/or\n# modify it under the terms of the GNU General Public License as\n# published by the Free Software Foundation; version 3\n#\n# This program is distributed in the hope that it will be useful,\n# but WI...
[{"input": "5 2 3 12 15\n", "output": "39\n"}, {"input": "20 2 3 3 5\n", "output": "51\n"}, {"input": "1 1 1 1 1\n", "output": "1\n"}, {"input": "1 2 2 2 2\n", "output": "0\n"}, {"input": "2 1 3 3 3\n", "output": "6\n"}, {"input": "3 1 1 3 3\n", "output": "9\n"}, {"input": "4 1 5 4 3\n", "output": "16\n"}, {"input": "8...
12
Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement a...
interview
[{"code": "n = int(input())\nA = input()\nx = A.count('G')\nnum_1 = 0\nnum_2 = 0\nmax_num = 0\nflag = 0\nfor i in range(n):\n if A[i] == 'G' and flag == 0:\n num_1 += 1\n elif A[i] == 'G' and flag == 1:\n num_2 += 1\n elif A[i] == 'S' and flag == 0:\n flag = 1\n else:\n if num_1 ...
[{"input": "10\nGGGSGGGSGG\n", "output": "7\n"}, {"input": "4\nGGGG\n", "output": "4\n"}, {"input": "3\nSSS\n", "output": "0\n"}, {"input": "11\nSGGGGSGGGGS\n", "output": "8\n"}, {"input": "300\nSSGSGSSSGSGSSSSGGSGSSGGSGSGGSSSGSSGSGGSSGGSGSSGGSGGSSGSSSGSGSGSSGSGGSSSGSSGSSGGGGSSGSSGSSGSGGSSSSGGGGSSGSSSSSSSSGSSSSGSGSSSSS...
15
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that ...
interview
[{"code": "import sys\na,b,c=map(int,input().split())\nif c==0:\n if a==b:\n print('YES')\n else:\n print('NO')\n return\nif (b-a)%c==0 and (b-a)//c>=0:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.16, "memory": 14516.0, "status": "done"}, {"code": "a, b, c = list(map(int...
[{"input": "1 7 3\n", "output": "YES\n"}, {"input": "10 10 0\n", "output": "YES\n"}, {"input": "1 -4 5\n", "output": "NO\n"}, {"input": "0 60 50\n", "output": "NO\n"}, {"input": "1 -4 -5\n", "output": "YES\n"}, {"input": "0 1 0\n", "output": "NO\n"}, {"input": "10 10 42\n", "output": "YES\n"}, {"input": "-1000000000 10...
16
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; ")...
interview
[{"code": "cnt1 = int(input())\ncnt2 = int(input())\ncnt3 = int(input())\ncnt4 = int(input())\nif cnt1 != cnt4:\n\tprint(0)\n\treturn\n\nif (cnt3 != 0 and cnt1 == 0):\n\tprint(0)\n\treturn\n\nprint(1)", "passed": true, "time": 0.93, "memory": 14888.0, "status": "done"}, {"code": "cnt = [int(input()) for _ in range(4)]\...
[{"input": "3\n1\n4\n3\n", "output": "1\n"}, {"input": "0\n0\n0\n0\n", "output": "1\n"}, {"input": "1\n2\n3\n4\n", "output": "0\n"}, {"input": "1000000000\n1000000000\n1000000000\n1000000000\n", "output": "1\n"}, {"input": "1000000000\n1000000000\n1000000000\n999999999\n", "output": "0\n"}, {"input": "1000000000\n99999...
17
Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator stands. At time k + 1, the (k + 1)-th spectator stands and th...
interview
[{"code": "def read_ints():\n\treturn [int(i) for i in input().split()]\n\nn, k, t = read_ints()\nif t <= k:\n\tprint(t)\nelif t > n:\n\tprint(k + n - t)\nelse:\n\tprint(k)", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "def list_input():\n return list(map(int,input().split()))\ndef m...
[{"input": "10 5 3\n", "output": "3\n"}, {"input": "10 5 7\n", "output": "5\n"}, {"input": "10 5 12\n", "output": "3\n"}, {"input": "840585600 770678331 788528791\n", "output": "770678331\n"}, {"input": "25462281 23343504 8024619\n", "output": "8024619\n"}, {"input": "723717988 205757169 291917494\n", "output": "205757...
18
Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this charact...
interview
[{"code": "from collections import deque\nS = input()\nmn = [ 300 for i in range( len( S ) ) ]\nfor i in range( len( S ) - 1, -1, -1 ):\n if i == len( S ) - 1:\n mn[ i ] = ord( S[ i ] )\n else:\n mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) )\nans = \"\"\ndq = deque()\nfor i in range( len( S ) ):\n dq.append( ord...
[{"input": "cab\n", "output": "abc\n"}, {"input": "acdb\n", "output": "abdc\n"}, {"input": "a\n", "output": "a\n"}, {"input": "ab\n", "output": "ab\n"}, {"input": "ba\n", "output": "ab\n"}, {"input": "dijee\n", "output": "deeji\n"}, {"input": "bhrmc\n", "output": "bcmrh\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
19
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases...
interview
[{"code": "import sys\ninput = sys.stdin.readline\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n lastP = 0\n lastC = 0\n works = True\n for _ in range(n):\n p, c = list(map(int, input().split()))\n pDiff = p-lastP\n cDiff = c-lastC\n if 0 <= cDiff <= pDiff:\n ...
[{"input": "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n", "output": "NO\nYES\nNO\nYES\nNO\nYES\n"}, {"input": "1\n2\n10 1\n11 3\n", "output": "NO\n"}, {"input": "1\n2\n5 2\n8 6\n", "output": "NO\n"}, {"input": "1\n2\n43 34\n44 35\n", "output": "Y...
20
Karen is getting ready for a new school day! [Image] It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time...
interview
[{"code": "s = input()\nh = int(s[:2])\nm = int(s[3:])\n\ndef ispalin(h, m):\n s = \"%02d:%02d\"%(h,m)\n return s == s[::-1]\n\nfor d in range(999999):\n if ispalin(h, m):\n print(d)\n break\n m+= 1\n if m == 60:\n h = (h+1)%24\n m = 0\n", "passed": true, "time": 0.17, "memory...
[{"input": "05:39\n", "output": "11\n"}, {"input": "13:31\n", "output": "0\n"}, {"input": "23:59\n", "output": "1\n"}, {"input": "13:32\n", "output": "69\n"}, {"input": "14:40\n", "output": "1\n"}, {"input": "14:00\n", "output": "41\n"}, {"input": "05:50\n", "output": "0\n"}, {"input": "12:22\n", "output": "69\n"}, {"i...
21
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance...
interview
[{"code": "read = lambda: list(map(int, input().split()))\nn = int(input())\na = list(read())\nx, y = a.index(1), a.index(n)\nans = max(x, y, n - x - 1, n - y - 1)\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14788.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\ni, j = ...
[{"input": "5\n4 5 1 3 2\n", "output": "3\n"}, {"input": "7\n1 6 5 3 4 7 2\n", "output": "6\n"}, {"input": "6\n6 5 4 3 2 1\n", "output": "5\n"}, {"input": "2\n1 2\n", "output": "1\n"}, {"input": "2\n2 1\n", "output": "1\n"}, {"input": "3\n2 3 1\n", "output": "2\n"}, {"input": "4\n4 1 3 2\n", "output": "3\n"}, {"input":...
22
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. [Image] English alphabet You are given...
interview
[{"code": "import sys, math\ns=input()\npal='AHIMOoTUVvWwXxY'\nn=len(s)\nl=0\nr=n-1\nflag=True\nfir='pq'\nsec='bd'\nwhile l<=r:\n if s[l]==s[r] and s[l] in pal:\n l+=1\n r-=1\n continue\n elif s[l]==s[r]:\n flag=False\n break\n elif (s[l] in fir) and (s[r] in fir):\n l...
[{"input": "oXoxoXo\n", "output": "TAK\n"}, {"input": "bod\n", "output": "TAK\n"}, {"input": "ER\n", "output": "NIE\n"}, {"input": "o\n", "output": "TAK\n"}, {"input": "a\n", "output": "NIE\n"}, {"input": "opo\n", "output": "NIE\n"}, {"input": "HCMoxkgbNb\n", "output": "NIE\n"}, {"input": "vMhhXCMWDe\n", "output": "NIE...
23
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. -----Input----- The first line contains integer a (1 ≤ a ≤ 10^18). The second lin...
interview
[{"code": "a = list(input())\nb = int(input())\na.sort()\na = a[::-1]\nprefix = \"\"\nwhile(len(a) > 0):\n\tfor i in range(len(a)):\n\t\tnum = prefix + a[i] + \"\".join(sorted(a[:i] + a[i + 1:]))\n\t\tif (int(num) <= b):\n\t\t\tprefix += a[i]\n\t\t\ta = a[:i] + a[i+1:]\n\t\t\tbreak\nprint(prefix)\n", "passed": true, "t...
[{"input": "123\n222\n", "output": "213\n"}, {"input": "3921\n10000\n", "output": "9321\n"}, {"input": "4940\n5000\n", "output": "4940\n"}, {"input": "23923472834\n23589234723\n", "output": "23498743322\n"}, {"input": "102391019\n491010301\n", "output": "399211100\n"}, {"input": "123456789123456789\n276193619183618162\...
24
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins imm...
interview
[{"code": "s = [ [ c for c in input() ] for i in range(10) ]\ndef win():\n for i in range(10):\n for j in range(10):\n ok = True\n for k in range(5):\n if j+k>9: ok = False\n elif s[i][j+k] != 'X': ok = False\n if ok: return True\n ok = True\n for k in range(5):\n if i+...
[{"input": "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "output": "YES\n"}, {"input": "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "output": "NO\n"}, {"input": "X...
25
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically...
interview
[{"code": "def main():\n n, k = map(int, input().split())\n\n if k > n**2:\n print(-1)\n return\n\n A = [[0] * n for _ in range(n)]\n\n i = 0\n j = 0\n while k > 1:\n A[i][j] = 1\n k -= 1\n j += 1\n while k > 1 and j < n:\n A[i][j] = 1\n ...
[{"input": "2 1\n", "output": "1 0 \n0 0 \n"}, {"input": "3 2\n", "output": "1 0 0 \n0 1 0 \n0 0 0 \n"}, {"input": "2 5\n", "output": "-1\n"}, {"input": "1 0\n", "output": "0 \n"}, {"input": "1 1\n", "output": "1 \n"}, {"input": "20 401\n", "output": "-1\n"}, {"input": "100 10001\n", "output": "-1\n"}, {"input": "2 3\n...
26
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point. Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ...
interview
[{"code": "from math import log\nfrom decimal import Decimal\n\ns = ['x^y^z', 'x^z^y', '(x^y)^z', 'y^x^z', 'y^z^x', '(y^x)^z', 'z^x^y', 'z^y^x', '(z^x)^y']\n\nx, y, z = list(map(Decimal, input().split()))\n\nf = []\nf += [(Decimal(log(x)) * (y ** z), 0)]\nf += [(Decimal(log(x)) * (z ** y), -1)]\nf += [(Decimal(log(x))...
[{"input": "1.1 3.4 2.5\n", "output": "z^y^x\n"}, {"input": "2.0 2.0 2.0\n", "output": "x^y^z\n"}, {"input": "1.9 1.8 1.7\n", "output": "(x^y)^z\n"}, {"input": "2.0 2.1 2.2\n", "output": "x^z^y\n"}, {"input": "1.5 1.7 2.5\n", "output": "(z^x)^y\n"}, {"input": "1.1 1.1 1.1\n", "output": "(x^y)^z\n"}, {"input": "4.2 1.1 ...
27
You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the end of the string. Besides, at most once you may perform one addit...
interview
[{"code": "n = int(input())\nst = input()\nans = n\nnow = ''\nma = 0\nfor i in range(n // 2):\n now += st[i]\n t = ''\n for j in range(i + 1, 2 * i + 2):\n t += st[j]\n if t == now:\n ma = i\nprint(ans - ma)\n", "passed": true, "time": 0.17, "memory": 14404.0, "status": "done"}, {"code": "n = ...
[{"input": "7\nabcabca\n", "output": "5\n"}, {"input": "8\nabcdefgh\n", "output": "8\n"}, {"input": "100\nmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxc\n", "output": "51\n"}, {"input": "99\ntrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjhhkqmlzuhrplrtrolnjmzxxrfxuexcqpjvefndw...
29
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
interview
[{"code": "s = input()\n\nans = 6\n\nfor i in range (0, 10):\n for j in range (0, 10):\n for k in range(0, 10):\n for f in range (0, 10):\n for f1 in range(0, 10):\n for f2 in range(0, 10):\n if(i + j + k == f + f1 + f2):\n ...
[{"input": "000000\n", "output": "0\n"}, {"input": "123456\n", "output": "2\n"}, {"input": "111000\n", "output": "1\n"}, {"input": "120111\n", "output": "0\n"}, {"input": "999999\n", "output": "0\n"}, {"input": "199880\n", "output": "1\n"}, {"input": "899889\n", "output": "1\n"}, {"input": "899888\n", "output": "1\n"},...
30
The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of ...
interview
[{"code": "from math import gcd\ndef powmod(a,b,m):\n a%=m\n r=1\n while b:\n if b&1:r=r*a%m\n a=a*a%m\n b>>=1\n return r\n\ndef f(n):\n r=[]\n if (n&1)==0:\n e=0\n while (n&1)==0:n>>=1;e+=1\n yield (2,e)\n p=3\n while n>1:\n if p*p>n:p=n\n if n%p:\n p+=2\n continue\n e=1;n//=p\n while n%p==0:n//=p;e+=1\n...
[{"input": "4 3\n", "output": "3\n"}, {"input": "5 2\n", "output": "2\n"}, {"input": "7 2\n", "output": "3\n"}, {"input": "2 1\n", "output": "2\n"}, {"input": "100000000000000 1\n", "output": "100000000000000\n"}, {"input": "100000000000000 99999999999999\n", "output": "50000000000001\n"}, {"input": "12 1\n", "output":...
32
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers. Limak, a polar bear, lives on the N...
interview
[{"code": "\"\"\"\nCodeforces Good Bye 2016 Contest Problem B\n\nAuthor : chaotic_iak\nLanguage: Python 3.5.2\n\"\"\"\n\n################################################### SOLUTION\n\ndef main():\n latitude = 0\n n, = read()\n for i in range(n):\n l, d = read(str)\n l = int(l)\n if latit...
[{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n", "output": "YES\n"}, {"input": "2\n15000 South\n4000 East\n", "output": "NO\n"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North\n", "output": "YES\n"}, {"input": "3\n20000 South\n10 East\n20000 North\n", "output": ...
33
You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0. -----Input----- The only line contains six integers a_1, b_1, a_2, b_2, L, R (0 < a_1, a_2 ≤ 2·10^9, - 2·10^9 ≤ b_1, b_2, L, R ≤ 2·...
interview
[{"code": "import sys, collections\n\ndef gcd(a, b):\n if b == 0: return a\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return a // gcd(a, b) * b\n\ndef extgcd(a, b):\n if b == 0: return 1, 0\n x, y = extgcd(b, a % b)\n return y, x - a // b * y\n\ndef prime_factor(n):\n res = collections.defaultdict(...
[{"input": "2 0 3 3 5 21\n", "output": "3\n"}, {"input": "2 4 3 0 6 17\n", "output": "2\n"}, {"input": "2 0 4 2 -39 -37\n", "output": "0\n"}, {"input": "1 9 3 11 49 109\n", "output": "20\n"}, {"input": "3 81 5 72 -1761 501\n", "output": "28\n"}, {"input": "8 -89 20 67 8771 35222\n", "output": "661\n"}, {"input": "1 -22...
34
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat...
interview
[{"code": "n, a, b = map(int, input().split())\nans = 0\nfor i in range(1, n):\n ans = max(ans, min(a // i, b // (n - i)))\nprint(ans)", "passed": true, "time": 0.16, "memory": 14828.0, "status": "done"}, {"code": "n,a,b = [int(x) for x in input().split()]\nmxmn = max(min(a//i,b//(n-i)) for i in range(1,n))\nprint(m...
[{"input": "5 2 3\n", "output": "1\n"}, {"input": "4 7 10\n", "output": "3\n"}, {"input": "100 100 100\n", "output": "2\n"}, {"input": "10 100 3\n", "output": "3\n"}, {"input": "2 9 29\n", "output": "9\n"}, {"input": "4 6 10\n", "output": "3\n"}, {"input": "3 70 58\n", "output": "35\n"}, {"input": "5 7 10\n", "output":...
35
The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each col...
interview
[{"code": "n,m=list(map(int,input().split()))\nf=[input() for _ in range(n)]\ndef clr(ss):\n cc = None\n for s in ss:\n for c in s:\n if cc is None:\n cc = c\n elif cc != c:\n return None\n return cc\nif n%3 == 0:\n s = set()\n for i in range(0,n...
[{"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n", "output": "YES\n"}, {"input": "4 3\nBRG\nBRG\nBRG\nBRG\n", "output": "YES\n"}, {"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n", "output": "NO\n"}, {"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG\n", "output": "NO\n"}, {"input": "1 3\nGRB\n", "...
36
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: [Image] [Image] Ayrat is searching through the field. He started at point (...
interview
[{"code": "def f(n):\n\tleft, right = -1, n + 1\n\twhile right - left > 1:\n\t\tmid = (left + right) // 2\n\t\tx = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1)\n\t\tif x > n:\n\t\t\tright = mid\n\t\telse:\n\t\t\tleft = mid\n\tif left >= 0:\n\t\tmid = left\n\t\tx = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1)\n\t\tn -= x\n\tret...
[{"input": "3\n", "output": "-2 0\n"}, {"input": "7\n", "output": "3 2\n"}, {"input": "39\n", "output": "5 6\n"}, {"input": "14\n", "output": "-2 -4\n"}, {"input": "94\n", "output": "8 8\n"}, {"input": "60\n", "output": "8 0\n"}, {"input": "60\n", "output": "8 0\n"}, {"input": "59\n", "output": "7 -2\n"}, {"input": "18...
37
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama...
interview
[{"code": "a, b, c = list(map(int, input().split()))\np = [0] * 100000\np[0] = 1\np[a] = 1\np[b] = 1\nfor i in range(c + 1):\n if p[i]:\n p[i + a] = 1\n p[i + b] = 1\nif p[c]:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.21, "memory": 14824.0, "status": "done"}, {"code": "# Y...
[{"input": "4 6 15\n", "output": "No\n"}, {"input": "3 2 7\n", "output": "Yes\n"}, {"input": "6 11 6\n", "output": "Yes\n"}, {"input": "3 12 15\n", "output": "Yes\n"}, {"input": "5 5 10\n", "output": "Yes\n"}, {"input": "6 6 7\n", "output": "No\n"}, {"input": "1 1 20\n", "output": "Yes\n"}, {"input": "12 14 19\n", "out...
38
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you...
interview
[{"code": "def main():\n\tn, l = map(int, input().split())\n\n\tx = list(map(int, input().split()))\n\ty = list(map(int, input().split()))\n\n\tx.append(x[0] + l)\n\ty.append(y[0] + l)\n\n\ta = [x[i + 1] - x[i] for i in range(n)]\n\tb = [y[i + 1] - y[i] for i in range(n)]\n\n\tfor i in range(n):\n\t\tif (a == b[i:] + b...
[{"input": "3 8\n2 4 6\n1 5 7\n", "output": "YES\n"}, {"input": "4 9\n2 3 5 8\n0 1 3 6\n", "output": "YES\n"}, {"input": "2 4\n1 3\n1 2\n", "output": "NO\n"}, {"input": "5 9\n0 2 5 6 7\n1 3 6 7 8\n", "output": "YES\n"}, {"input": "5 60\n7 26 27 40 59\n14 22 41 42 55\n", "output": "YES\n"}, {"input": "20 29\n0 1 2 4 5 8...
39
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1 \leq l \leq r \leq |s|$) of a string $s = s_{1}s_{2} \ldots ...
interview
[{"code": "s = input()\nmx = 0\nn = len(s)\nfor l in range(n):\n for r in range(l, n):\n if s[l:r+1] != s[l:r+1][::-1]:\n mx = max(mx, r - l + 1)\nprint(mx)", "passed": true, "time": 0.28, "memory": 14504.0, "status": "done"}, {"code": "ans = 0\ns = input()\nn = len(s)\nfor i in range(n):\n for ...
[{"input": "mew\n", "output": "3\n"}, {"input": "wuffuw\n", "output": "5\n"}, {"input": "qqqqqqqq\n", "output": "0\n"}, {"input": "ijvji\n", "output": "4\n"}, {"input": "iiiiiii\n", "output": "0\n"}, {"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow\n", "output": "49\n"}, {"input": "wwwwwwwwwwwwwwwwwwwwwwww...
40
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
interview
[{"code": "'''input\n5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'''\nn = int(input())\nx = []\nf = 0\nfor _ in range(n):\n\ta, b = list(map(int, input().split()))\n\tif a != b:\n\t\tf = 1\n\tx.append(a)\nif f == 1:\n\tprint(\"rated\")\nelif sorted(x)[::-1] == x:\n\tprint(\"maybe\")\nelse:\n\tprint(\"unra...
[{"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "output": "rated\n"}, {"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "output": "unrated\n"}, {"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n", "output": "maybe\n"}, {"input": "2\n1 1\n1 1\n", "output"...
41
You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. -----Input----- The first line contains integer n (1 ≤ n ≤ 2·10^5) — length of the array a. The sec...
interview
[{"code": "from collections import deque\nimport sys\n\n# def search(matrix, inicial, dirs, final):\n# queue = deque()\n# queue.append(inicial)\n# matrix[inicial[0]][inicial[1]] = 0\n# while len(queue) > 0:\n# aux = queue.popleft()\n# \n# tupla = (aux[0], aux[1] + 1)\n# if matrix...
[{"input": "9\n2 1 0 3 0 0 3 2 4\n", "output": "2 1 0 1 0 0 1 2 3 "}, {"input": "5\n0 1 2 3 4\n", "output": "0 1 2 3 4 "}, {"input": "7\n5 6 0 1 -2 3 4\n", "output": "2 1 0 1 2 3 4 "}, {"input": "1\n0\n", "output": "0 "}, {"input": "2\n0 0\n", "output": "0 0 "}, {"input": "2\n0 1\n", "output": "0 1 "}, {"input": "2\n1 ...
43
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them. Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ...
interview
[{"code": "from functools import cmp_to_key\n\nn = int(input())\n\ndef dot(p1,p2):\n x1,y1 = p1\n x2,y2 = p2\n return x1 * x2 + y1 * y2\n \ndef cross(p1,p2):\n x1,y1 = p1\n x2,y2 = p2\n return x1 * y2 - x2 * y1\n\ndef top(p):\n x,y = p\n return y > 0 or (y == 0 and x > 0)\n\ndef polarCmp(p1,p...
[{"input": "4\n-1 0\n0 -1\n1 0\n1 1\n", "output": "3 4\n"}, {"input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n", "output": "5 6\n"}, {"input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7\n", "output": "1 3\n"}, {"input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8...
44
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers. Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will ...
interview
[{"code": "d, k, a, b, t = list(map(int, input().split()))\n\nt1 = d * b\nt2 = d * a + ((d - 1) // k) * t\nt3 = max(0, d - k) * b + min(k, d) * a\ndd = d % k\nd1 = d - dd\nt4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b\n\nprint(min([t1, t2, t3, t4]))\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "don...
[{"input": "5 2 1 4 10\n", "output": "14\n"}, {"input": "5 2 1 4 5\n", "output": "13\n"}, {"input": "1 1 1 2 1\n", "output": "1\n"}, {"input": "1000000000000 1000000 999999 1000000 1000000\n", "output": "999999999999000000\n"}, {"input": "997167959139 199252 232602 952690 802746\n", "output": "231947279018960454\n"}, {...
45
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by the...
interview
[{"code": "n, k = map(int, input().split())\ndiv = []\ni = 1\nn1 = n\nwhile i * i <= n:\n if n % i == 0:\n div.append(i)\n div.append(n // i)\n i += 1\ndiv.sort()\nmx = -1\nfor i in range(len(div)):\n a = div[i] * k * (k + 1) // 2\n if a <= n:\n mx = div[i]\nif mx == -1:\n print(-1)\...
[{"input": "6 3\n", "output": "1 2 3\n"}, {"input": "8 2\n", "output": "2 6\n"}, {"input": "5 3\n", "output": "-1\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "1 2\n", "output": "-1\n"}, {"input": "2 1\n", "output": "2\n"}, {"input": "2 10000000000\n", "output": "-1\n"}, {"input": "5 1\n", "output": "5\n"}, {"in...
46
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column ...
interview
[{"code": "ct=0\na, b = list(map(int, input().split(' ')))\nx=[0]*5\nfor i in range(1, b+1):\n x[i%5]+=1\nfor i in range(1, a+1):\n ct+=x[(0-i)%5]\nprint(ct)\n", "passed": true, "time": 5.64, "memory": 14532.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ntry:\n while True:\n n, m = list(map(i...
[{"input": "6 12\n", "output": "14\n"}, {"input": "11 14\n", "output": "31\n"}, {"input": "1 5\n", "output": "1\n"}, {"input": "3 8\n", "output": "5\n"}, {"input": "5 7\n", "output": "7\n"}, {"input": "21 21\n", "output": "88\n"}, {"input": "10 15\n", "output": "30\n"}, {"input": "1 1\n", "output": "0\n"}, {"input": "1...
47
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0. You may choose at most one consecutive subarr...
interview
[{"code": "N, X = list(map(int, input().split()))\nA = [int(a) for a in input().split()]\n\ndp = [[0]*4 for _ in range(N+1)]\n\nfor i in range(1, N+1):\n dp[i][0] = max(dp[i-1][0] + A[i-1], 0)\n dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0])\n dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1])\n dp[i][3] = ma...
[{"input": "5 -2\n-3 8 -2 1 -6\n", "output": "22\n"}, {"input": "12 -3\n1 3 3 7 1 3 3 7 1 3 3 7\n", "output": "42\n"}, {"input": "5 10\n-1 -2 -3 -4 -5\n", "output": "0\n"}, {"input": "10 100\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "100...
48
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and ...
interview
[{"code": "def main():\n from math import sqrt\n m, n, k = list(map(int, input().split()))\n if n < m:\n n, m = m, n\n lo, hi = 1, k + 1\n while lo + 1 < hi:\n mid = (lo + hi) // 2\n t = mid - 1\n v = min(int(sqrt(t)), m)\n tn, tm = (t - 1) // m, t // n\n vv = [t...
[{"input": "2 2 2\n", "output": "2\n"}, {"input": "2 3 4\n", "output": "3\n"}, {"input": "1 10 5\n", "output": "5\n"}, {"input": "1 1 1\n", "output": "1\n"}, {"input": "10 1 7\n", "output": "7\n"}, {"input": "10 10 33\n", "output": "14\n"}, {"input": "500000 500000 1\n", "output": "1\n"}, {"input": "500000 500000 25000...
49
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The fir...
interview
[{"code": "k = int(input())\n\nif k<=9:\n print(k)\nelse:\n num_arr = [9*(i+1)* 10**i for i in range(11)]\n\n index = 0\n\n while True:\n if k<=num_arr[index]:\n break\n else:\n k -= num_arr[index]\n index += 1\n\n digit = index+1\n k += digit-1\n\n\n ...
[{"input": "7\n", "output": "7\n"}, {"input": "21\n", "output": "5\n"}, {"input": "1\n", "output": "1\n"}, {"input": "2\n", "output": "2\n"}, {"input": "3\n", "output": "3\n"}, {"input": "4\n", "output": "4\n"}, {"input": "5\n", "output": "5\n"}, {"input": "6\n", "output": "6\n"}, {"input": "8\n", "output": "8\n"}, {"i...
50
Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market! In the morning, there are $n$ opportunities to buy shares. The $i$-th of them allows to buy as many shares as you want, each at the pri...
interview
[{"code": "n, m, r = map(int, input().split())\nS = list(map(int, input().split()))\nB = list(map(int, input().split()))\nx = min(S)\ny = max(B)\ncnt = r % x\nact = r // x\ncnt += act * y\nprint(max(r, cnt))", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "n, m, r = map(int, input().split...
[{"input": "3 4 11\n4 2 5\n4 4 5 4\n", "output": "26\n"}, {"input": "2 2 50\n5 7\n4 2\n", "output": "50\n"}, {"input": "1 1 1\n1\n1\n", "output": "1\n"}, {"input": "1 1 35\n5\n7\n", "output": "49\n"}, {"input": "1 1 36\n5\n7\n", "output": "50\n"}, {"input": "3 5 20\n1000 4 6\n1 2 7 6 5\n", "output": "35\n"}, {"input": ...
51
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение мо...
interview
[{"code": "s = input()\nt = 0\nif len(s)%2==0:\n n = (len(s)-1)//2+1\nelse:\n n = (len(s)-1)//2\nfor i in range(n, len(s)-1):\n a = i\n b = len(s)-i-1\n if s[:a+1]==s[b:]:\n print('YES')\n print(s[:a+1])\n t = 1\n break\nif t==0:\n print('NO')", "passed": true, "time": 0.15...
[{"input": "abrakadabrabrakadabra\n", "output": "YES\nabrakadabra\n"}, {"input": "acacacaca\n", "output": "YES\nacaca\n"}, {"input": "abcabc\n", "output": "NO\n"}, {"input": "abababab\n", "output": "YES\nababab\n"}, {"input": "tatbt\n", "output": "NO\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
52
Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are...
interview
[{"code": "n = int(input())\nres = set()\nfor r in range(100):\n a = 1\n b = 2**(r + 1) - 3\n c = -2 * n\n d = b * b - 4 * a * c\n if d < 0:\n continue\n le = 0\n ri = d\n while le < ri:\n c = (le + ri) // 2\n if c * c < d:\n le = c + 1\n else:\n ...
[{"input": "3\n", "output": "3\n4\n"}, {"input": "25\n", "output": "20\n"}, {"input": "2\n", "output": "-1\n"}, {"input": "1\n", "output": "2\n"}, {"input": "15\n", "output": "10\n16\n"}, {"input": "314\n", "output": "-1\n"}, {"input": "524800\n", "output": "1025\n"}, {"input": "5149487579894806\n", "output": "-1\n"}, ...
53
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b_{i}...
interview
[{"code": "from collections import Counter\n\nr = lambda: list(map(int, input().split()))\n\ndef main():\n\tn, = r()\n\ts = input()\n\tcost = list(r())\n\n\tans = 0\n\n\tcnt = Counter()\n\n\tfor i in range(n // 2):\n\t\tif s[i] == s[n - 1 - i]:\n\t\t\tans += min(cost[i], cost[n - 1 - i])\n\t\t\tcnt[s[i]] += 1\n\ttotal ...
[{"input": "8\nabacabac\n1 1 1 1 1 1 1 1\n", "output": "8\n"}, {"input": "8\nabaccaba\n1 2 3 4 5 6 7 8\n", "output": "26\n"}, {"input": "8\nabacabca\n1 2 3 4 4 3 2 1\n", "output": "17\n"}, {"input": "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9...
54
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ...
interview
[{"code": "w,m=map(int,input().split())\n\nbb=True\n\nwhile(m>0 and bb):\n\tx=m%w\n\tif x==1:m-=1\n\telif x==w-1:m+=1\n\telif x!=0:bb=False\n\tm//=w\n\t\nif bb:print(\"YES\")\nelse:print(\"NO\")", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "def f(w, m):\n\tif m == 0:\n\t\treturn True\n...
[{"input": "3 7\n", "output": "YES\n"}, {"input": "100 99\n", "output": "YES\n"}, {"input": "100 50\n", "output": "NO\n"}, {"input": "1000000000 1\n", "output": "YES\n"}, {"input": "100 10002\n", "output": "NO\n"}, {"input": "4 7\n", "output": "NO\n"}, {"input": "4 11\n", "output": "YES\n"}, {"input": "5 781\n", "outpu...
55
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As t...
interview
[{"code": "n, k = map(int, input().split())\ncnt = [0] * 200010\nans = ''\nfor i in range(64):\n if (n >> i)&1:\n k -= 1\n cnt[i] = 1;\nif k < 0:\n print(\"No\")\nelse:\n print(\"Yes\")\n for i in range(64, -64, -1):\n if k >= cnt[i]:\n cnt[i - 1] += cnt[i] * 2\n k -= cnt[i]\n cnt[i] = 0\n ...
[{"input": "23 5\n", "output": "Yes\n3 3 2 1 0 \n"}, {"input": "13 2\n", "output": "No\n"}, {"input": "1 2\n", "output": "Yes\n-1 -1 \n"}, {"input": "1 1\n", "output": "Yes\n0 \n"}, {"input": "7 2\n", "output": "No\n"}, {"input": "7 3\n", "output": "Yes\n2 1 0 \n"}, {"input": "7 4\n", "output": "Yes\n1 1 1 0 \n"}, {"in...
56
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (co...
interview
[{"code": "n, t = list(map(int,input().split()))\ng = [[0.0] * i for i in range(1,n+1)]\n\n\nfor _ in range(t):\n g[0][0] += 1.0\n for i in range(n):\n for j in range(i+1):\n spill = max(0, g[i][j] - 1.0)\n g[i][j] -= spill\n if i < n - 1:\n g[i + 1][j] += sp...
[{"input": "3 5\n", "output": "4\n"}, {"input": "4 8\n", "output": "6\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "10 10000\n", "output": "55\n"}, {"input": "1 10000\n", "output": "1\n"}, {"input": "10 1\n", "output": "1\n"}, {"input": "1 0\n", "output": "0\n"}, {"input": "10 0\n", "output": "0\n"}, {"input": "...
57
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned...
interview
[{"code": "n = int(input())\npoints = [[int(x) for x in input().split()] for _ in range(n)]\nif n <= 1:\n\tprint(-1)\n\treturn\ndx = [1e9, -1e9]\ndy = [1e9, -1e9]\nfor x, y in points:\n\tdx[0] = min(dx[0], x)\n\tdx[1] = max(dx[1], x)\n\tdy[0] = min(dy[0], y)\n\tdy[1] = max(dy[1], y)\narea = (dx[1] - dx[0]) * (dy[1] - d...
[{"input": "2\n0 0\n1 1\n", "output": "1\n"}, {"input": "1\n1 1\n", "output": "-1\n"}, {"input": "1\n-188 17\n", "output": "-1\n"}, {"input": "1\n71 -740\n", "output": "-1\n"}, {"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174\n", "output": "570456\n"}, {"input": "2\n14 153\n566 -13\n", "output": "91632\n"}, {"input...
58
Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side. Determine a minimal number of wooden bars which are needed t...
interview
[{"code": "'''input\n6\n4\n2\n'''\n\ndef list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input().split()\n \ndef f(n,a,b,left,cnta = 4,cntb = 2):\n\tif(cnta == 0 and cntb == 0): return 0\n\tif(cnta < 0 or cntb < 0): return 10...
[{"input": "8\n1\n2\n", "output": "1\n"}, {"input": "5\n3\n4\n", "output": "6\n"}, {"input": "6\n4\n2\n", "output": "4\n"}, {"input": "20\n5\n6\n", "output": "2\n"}, {"input": "1\n1\n1\n", "output": "6\n"}, {"input": "3\n1\n2\n", "output": "3\n"}, {"input": "3\n2\n1\n", "output": "4\n"}, {"input": "1000\n1\n1\n", "outp...
59
You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array. For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the ...
interview
[{"code": "n = int(input())\na = list(map(int,input().split()))\np = input()\nm = 0\nsuc = True\nfor i in range(n-1):\n m = max(m,a[i])\n if p[i] == '0' and m>(i+1):\n suc = False\n break\nif suc:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14616.0, "status"...
[{"input": "6\n1 2 5 3 4 6\n01110\n", "output": "YES\n"}, {"input": "6\n1 2 5 3 4 6\n01010\n", "output": "NO\n"}, {"input": "6\n1 6 3 4 5 2\n01101\n", "output": "NO\n"}, {"input": "6\n2 3 1 4 5 6\n01111\n", "output": "NO\n"}, {"input": "4\n2 3 1 4\n011\n", "output": "NO\n"}, {"input": "2\n2 1\n0\n", "output": "NO\n"}, ...
60
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats...
interview
[{"code": "seat = input()\ntime_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3}\ncol = seat[-1]\nrow = int(seat[:-1])\nrow -= 1\n\nblocks_to_serve = row // 4\ntime = (6 * 2 + 4) * blocks_to_serve\n\nif row % 2 == 1:\n time += 6 + 1\n\ntime += time_to[col]\n\nprint(time)\n", "passed": true, "time": 0.26, "memor...
[{"input": "1f\n", "output": "1\n"}, {"input": "2d\n", "output": "10\n"}, {"input": "4a\n", "output": "11\n"}, {"input": "5e\n", "output": "18\n"}, {"input": "2c\n", "output": "13\n"}, {"input": "1b\n", "output": "5\n"}, {"input": "1000000000000000000d\n", "output": "3999999999999999994\n"}, {"input": "9999999999999999...
61
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented in base b_{y}. Compare those two numbers. -----Input----- The first line...
interview
[{"code": "n, bx = list(map(int, input().split()))\nx1 = list(map(int, input().split()))\nx = 0\nfor i in range(n):\n\tx *= bx\n\tx += x1[i]\n\nn, by = list(map(int, input().split()))\ny1 = list(map(int, input().split()))\ny = 0\nfor i in range(n):\n\ty *= by\n\ty += y1[i]\n\nif x == y:\n\tprint('=')\nelif x < y:\n\tpr...
[{"input": "6 2\n1 0 1 1 1 1\n2 10\n4 7\n", "output": "=\n"}, {"input": "3 3\n1 0 2\n2 5\n2 4\n", "output": "<\n"}, {"input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n", "output": ">\n"}, {"input": "2 2\n1 0\n2 3\n1 0\n", "output": "<\n"}, {"input": "2 2\n1 0\n1 3\n1\n", "output": ">\n"}, {"input": "10 2\n1 0 1 0 1...
63
Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck. After receiving...
interview
[{"code": "def gcd(a,b):\n if a == 0:\n return b\n return gcd(b%a,a)\n\nn,k = [int(x) for x in input().split()]\na = [gcd(int(x),k) for x in input().split()]\n\nif k == 1:\n print(((n+1)*(n+2))//2-n-1)\nelse:\n s = 0\n e = 0\n total = ((n+1)*(n+2))//2-1-n\n #print(total)\n #extra = {}\n c = 1\n \n while e...
[{"input": "3 4\n6 2 8\n", "output": "4\n"}, {"input": "3 6\n9 1 14\n", "output": "1\n"}, {"input": "5 1\n1 3 1 3 1\n", "output": "15\n"}, {"input": "5 1\n5 5 5 5 5\n", "output": "15\n"}, {"input": "5 1\n5 4 4 4 4\n", "output": "15\n"}, {"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
64
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloon...
interview
[{"code": "alpha = [chr(ord('a')+i) for i in range(26)]\nn,k = list(map(int,input().split()))\ns = input()\narr = [s.count(alpha[i]) for i in range(26)]\n\nprint('YES' if max(arr) <= k else 'NO')\n", "passed": true, "time": 1.88, "memory": 14468.0, "status": "done"}, {"code": "n, k = map(int, input().split())\ns = inpu...
[{"input": "4 2\naabb\n", "output": "YES\n"}, {"input": "6 3\naacaab\n", "output": "NO\n"}, {"input": "2 2\nlu\n", "output": "YES\n"}, {"input": "5 3\novvoo\n", "output": "YES\n"}, {"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf\n", "output": "YES\n"}, {"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdm...
65
You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. -----Input----- The first line contains positive integer n (2 ≤ n ≤ 10^5) — size of the given array. The second...
interview
[{"code": "n = int(input())\nA = [int(x) for x in input().split()]\nmn = min(A)\n\nI = [i for i in range(len(A)) if A[i] == mn]\nmindiff = min(I[i]-I[i-1] for i in range(1,len(I)))\nprint(mindiff)\n", "passed": true, "time": 0.17, "memory": 14708.0, "status": "done"}, {"code": "n = int(input())\nL = list(map(int, input...
[{"input": "2\n3 3\n", "output": "1\n"}, {"input": "3\n5 6 5\n", "output": "2\n"}, {"input": "9\n2 1 3 5 4 1 2 3 1\n", "output": "3\n"}, {"input": "6\n4 6 7 8 6 4\n", "output": "5\n"}, {"input": "2\n1000000000 1000000000\n", "output": "1\n"}, {"input": "42\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
66
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. [Image] Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner....
interview
[{"code": "def gcd(a,b):\n if b == 0:\n return a\n return gcd(b,a%b)\ndef lcm(a,b):\n return (a*b)//gcd(a,b)\nt,w,b = map(int,input().split())\nlc = lcm(w,b)\nmn = 0\nif w > b:\n mn = b\nelse:\n mn = w\nans = mn*(t//lc+1)-1\nval = (t//lc)*lc + mn - 1\nif t - val < 0:\n ans += t-val\ng = gcd(ans...
[{"input": "10 3 2\n", "output": "3/10\n"}, {"input": "7 1 2\n", "output": "3/7\n"}, {"input": "1 1 1\n", "output": "1/1\n"}, {"input": "5814 31 7\n", "output": "94/2907\n"}, {"input": "94268 813 766\n", "output": "765/94268\n"}, {"input": "262610 5583 4717\n", "output": "2358/131305\n"}, {"input": "3898439 96326 71937...
68
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move from $(x, y)$ to $(x - 1, y)$; R — move from $(x, y)$ to $(x + 1...
interview
[{"code": "# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\ntry :\n #raise ModuleNotFoundError\n import numpy\n def dprint(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n dprin...
[{"input": "5\nRURUU\n-2 3\n", "output": "3\n"}, {"input": "4\nRULR\n1 1\n", "output": "0\n"}, {"input": "3\nUUU\n100 100\n", "output": "-1\n"}, {"input": "6\nUDUDUD\n0 1\n", "output": "-1\n"}, {"input": "100\nURDLDDLLDDLDDDRRLLRRRLULLRRLUDUUDUULURRRDRRLLDRLLUUDLDRDLDDLDLLLULRURRUUDDLDRULRDRUDDDDDDULRDDRLRDDL\n-59 -1\n...
69
You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010... Calculate the number of prefixes of $t$ with balance equal to $x$. The balance of so...
interview
[{"code": "t=int(input())\nfor i in ' '*t:\n n,x=map(int,input().split())\n s=input()\n L=[0]\n for i in s:\n if i=='0':L.append(L[-1]+1)\n else:L.append(L[-1]-1)\n L.pop(0)\n k=L[-1]\n c=0\n if x==0:c+=1\n if k>0:\n for i in L:\n if i%k==x%k and i<=x:c+=1\n ...
[{"input": "4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01\n", "output": "3\n0\n1\n-1\n"}, {"input": "2\n1 -548706795\n0\n1 -735838406\n1\n", "output": "0\n1\n"}, {"input": "1\n5 5\n00000\n", "output": "1\n"}, {"input": "19\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1...
70
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the r...
interview
[{"code": "s = input().split()\nk = int(s[1])\ns = s[0]\nif s.count('0') < k:\n if s.count('0') > 0:\n print(len(s) - 1)\n else:\n print(len(s))\n return\nhave = 0\nits = 0\nfor i in range(len(s) - 1, -1, -1):\n its += 1\n if s[i] == '0':\n have += 1\n if have == k:\n print...
[{"input": "30020 3\n", "output": "1\n"}, {"input": "100 9\n", "output": "2\n"}, {"input": "10203049 2\n", "output": "3\n"}, {"input": "0 1\n", "output": "0\n"}, {"input": "0 9\n", "output": "0\n"}, {"input": "100 2\n", "output": "0\n"}, {"input": "102030404 2\n", "output": "2\n"}, {"input": "1000999999 3\n", "output":...
72
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination...
interview
[{"code": "turns = int(input())\ns0 = input()\ns1 = input()\ns2 = input()\n\nd0 = dict()\nd1 = dict()\nd2 = dict()\n\nalphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'\nfor char in alphabet:\n\td0[char] = 0\n\td1[char] = 0\n\td2[char] = 0\n\nfor char in s0:\n\td0[char] += 1\nfor char in s1:\n\td1[char] ...
[{"input": "3\nKuroo\nShiro\nKatie\n", "output": "Kuro\n"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces\n", "output": "Shiro\n"}, {"input": "1\nabcabc\ncbabac\nababca\n", "output": "Katie\n"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n", "output": "Draw\n"}, {"input": "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbb...
73
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages. At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v_0 pages, at second...
interview
[{"code": "read = lambda: map(int, input().split())\nc, v0, v1, a, l = read()\ncur = 0\ncnt = 0\nwhile cur < c:\n cur = max(0, cur - l)\n cur += min(v1, v0 + a * cnt)\n cnt += 1\nprint(cnt)", "passed": true, "time": 0.17, "memory": 14600.0, "status": "done"}, {"code": "c,v0,v1,a,l = map(int,input().split())\nc...
[{"input": "5 5 10 5 4\n", "output": "1\n"}, {"input": "12 4 12 4 1\n", "output": "3\n"}, {"input": "15 1 100 0 0\n", "output": "15\n"}, {"input": "1 1 1 0 0\n", "output": "1\n"}, {"input": "1000 999 1000 1000 998\n", "output": "2\n"}, {"input": "1000 2 2 5 1\n", "output": "999\n"}, {"input": "1000 1 1 1000 0\n", "outp...
76
Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil...
interview
[{"code": "n, m, a, b = list(map(int, input().split()))\n\nk = n%m\nprint(min(k*b, (m - k)*a))\n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "n,m,a,b=list(map(int,input().split()))\nprint(min((n%m)*b,(m-(n%m))*a))\n", "passed": true, "time": 0.15, "memory": 14668.0, "status": "done"},...
[{"input": "9 7 3 8\n", "output": "15\n"}, {"input": "2 7 3 7\n", "output": "14\n"}, {"input": "30 6 17 19\n", "output": "0\n"}, {"input": "500000000001 1000000000000 100 100\n", "output": "49999999999900\n"}, {"input": "1000000000000 750000000001 10 100\n", "output": "5000000000020\n"}, {"input": "1000000000000 750000...
77
You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by de...
interview
[{"code": "n = int(input())\na = list(map(int, input().split()))\nres = 0\nnew_a = []\nfor i in range(n):\n if a[i] % 2 == 0:\n if a[i] > 0:\n res += a[i]\n else:\n new_a.append(a[i])\na = new_a\na.sort()\nres += a[-1]\na.pop()\nwhile len(a) > 1:\n if a[-1] + a[-2] > 0:\n res +=...
[{"input": "4\n-2 2 -3 1\n", "output": "3\n"}, {"input": "3\n2 -5 -3\n", "output": "-1\n"}, {"input": "1\n1\n", "output": "1\n"}, {"input": "1\n-1\n", "output": "-1\n"}, {"input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\n", "output": "53507\n"}, {"input": "2\n-5439 -6705\n", "...
78
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
interview
[{"code": "from math import factorial\n\n\ndef lol(n):\n if n == 1:\n yield [0]\n yield [1]\n else:\n for p in lol(n - 1):\n p.append(0)\n yield p\n p[-1] = 1\n yield p\n p.pop()\n\n\ndef sp(g1, g2, g3, f):\n if g1 == 0:\n if g2...
[{"input": "3 3\n1 1\n1 2\n1 3\n", "output": "6\n"}, {"input": "3 3\n1 1\n1 1\n1 3\n", "output": "2\n"}, {"input": "4 10\n5 3\n2 1\n3 2\n5 1\n", "output": "10\n"}, {"input": "1 1\n1 1\n", "output": "1\n"}, {"input": "1 1\n1 3\n", "output": "1\n"}, {"input": "1 2\n1 2\n", "output": "0\n"}, {"input": "1 15\n15 1\n", "out...
79
Vivek initially has an empty array $a$ and some integer constant $m$. He performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the greatest common divisor of integers in $a$. In case it equals to $1$, break Otherwise, return to ste...
interview
[{"code": "big = 100010\ndef gen_mu():\n mu = [1]*big\n mu[0] = 0\n P = [True]*big\n P[0] = P[1] = False\n for i in range(2,big):\n if P[i]:\n j = i\n while j<big:\n P[j] = False\n mu[j] *= -1\n j += i\n j = i*i\n ...
[{"input": "1\n", "output": "1\n"}, {"input": "2\n", "output": "2\n"}, {"input": "4\n", "output": "333333338\n"}, {"input": "3\n", "output": "2\n"}, {"input": "5\n", "output": "166666670\n"}, {"input": "6\n", "output": "500000006\n"}, {"input": "7\n", "output": "716666674\n"}, {"input": "8\n", "output": "476190482\n"},...
80
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well. We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common...
interview
[{"code": "# Codeforces Round #489 (Div. 2)\nimport collections\nfrom functools import cmp_to_key\n#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )\n\nimport sys\ndef getIntList():\n return list(map(int, input().split())) \nimport bisect\n \n \ndef getfactor(t):\n r = {}\n for x in range...
[{"input": "1 2 1 2\n", "output": "2\n"}, {"input": "1 12 1 12\n", "output": "4\n"}, {"input": "50 100 3 30\n", "output": "0\n"}, {"input": "1 1000000000 1 1000000000\n", "output": "4\n"}, {"input": "1 1000000000 158260522 200224287\n", "output": "0\n"}, {"input": "1 1000000000 2 755829150\n", "output": "8\n"}, {"input...
82
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, wh...
interview
[{"code": "from sys import stdin, stdout\nimport math\n\nn, k = map(int, stdin.readline().split())\nvalues = list(map(int, stdin.readline().split()))\nans = sum(values)\ncnt = 0\n\ndef round(v):\n if math.ceil(v) - v <= 1 / 2:\n return math.ceil(v)\n else:\n return math.floor(v)\n \n\nwhile round...
[{"input": "2 10\n8 9\n", "output": "4"}, {"input": "3 5\n4 4 4\n", "output": "3"}, {"input": "3 10\n10 8 9\n", "output": "3"}, {"input": "2 23\n21 23\n", "output": "2"}, {"input": "5 10\n5 10 10 9 10\n", "output": "7"}, {"input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12\n", "output": "712"}, {"input": "38 12\n2 7 1...
84
There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with severa...
interview
[{"code": "from sys import stdin as cin\nfrom sys import stdout as cout\n\ndef main():\n n = int(cin.readline())\n o = 0\n for x in range(9, 0, -1):\n if 10 ** x // 2 <= n:\n ##print(x)\n for i in range(9):\n q = 10 ** x * (i + 1) // 2 - 1\n if q <= n:...
[{"input": "7\n", "output": "3\n"}, {"input": "14\n", "output": "9\n"}, {"input": "50\n", "output": "1\n"}, {"input": "999999999\n", "output": "499999999\n"}, {"input": "15\n", "output": "11\n"}, {"input": "3\n", "output": "3\n"}, {"input": "6500\n", "output": "1501\n"}, {"input": "4\n", "output": "6\n"}, {"input": "13...
85
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one him...
interview
[{"code": "a,b=list(map(int,input().split()))\nc,d=list(map(int,input().split()))\ne=a*b\nf=c*d\nn=0\nwhile e%2==0:e=e//2\nwhile e%3==0:e=e//3\nwhile f%2==0:f=f//2\nwhile f%3==0:f=f//3\nif e!=f:print(\"-1\")\nelse:\n i=0\n j=0\n e=a*b\n f=c*d\n while e%3==0:\n e=e//3\n i+=1\n while f%3==0:\n ...
[{"input": "2 6\n2 3\n", "output": "1\n1 6\n2 3\n"}, {"input": "36 5\n10 16\n", "output": "3\n16 5\n5 16\n"}, {"input": "3 5\n2 1\n", "output": "-1\n"}, {"input": "36 5\n10 12\n", "output": "1\n24 5\n10 12\n"}, {"input": "1 1\n1 1\n", "output": "0\n1 1\n1 1\n"}, {"input": "2 1\n1 2\n", "output": "0\n2 1\n1 2\n"}, {"inp...
86
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: ...
interview
[{"code": "a, b, x, y = map(int, input().split())\nif a >= x:\n if b >= y:\n print('Vasiliy')\n else:\n z = y - b\n t = max(x - z, 0)\n if a - z <= t:\n print('Polycarp')\n else:\n print('Vasiliy')\nelse:\n if b <= y:\n print('Polycarp')\n else...
[{"input": "2 1 2 2\n", "output": "Polycarp\n"}, {"input": "4 7 7 4\n", "output": "Vasiliy\n"}, {"input": "20 0 7 22\n", "output": "Polycarp\n"}, {"input": "80 100 83 97\n", "output": "Vasiliy\n"}, {"input": "80 100 77 103\n", "output": "Vasiliy\n"}, {"input": "55000 60000 55003 60100\n", "output": "Polycarp\n"}, {"inp...
87
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: $\left. \begin{...
interview
[{"code": "import sys\narr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\na, b = list(map(int, input().split()))\na -= 1\nb -= 1\nctr = 1\nfor i in range(arr[a] - 1):\n b += 1\n if (b == 7):\n b = 0\n ctr += 1\nprint(ctr)\n \n", "passed": true, "time": 0.15, "memory": 14648.0, "statu...
[{"input": "1 7\n", "output": "6\n"}, {"input": "1 1\n", "output": "5\n"}, {"input": "11 6\n", "output": "5\n"}, {"input": "2 7\n", "output": "5\n"}, {"input": "2 1\n", "output": "4\n"}, {"input": "8 6\n", "output": "6\n"}, {"input": "1 1\n", "output": "5\n"}, {"input": "1 2\n", "output": "5\n"}, {"input": "1 3\n", "ou...
88
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he doesn't care about the number of zeros in the decimal representation. Lim...
interview
[{"code": "def zero(strx):\n k = []\n str2 = list(strx)\n for i in range(1, len(str2)):\n str3 = str2[:]\n str3[i] = '0'\n k.append(''.join(str3))\n return k\na = []\nfor i in range(1, 64):\n a += zero('1'*i)\n\nct = 0\nx, y = list(map(int, input().split(' ')))\nfor i in a:\n if x...
[{"input": "5 10\n", "output": "2\n"}, {"input": "2015 2015\n", "output": "1\n"}, {"input": "100 105\n", "output": "0\n"}, {"input": "72057594000000000 72057595000000000\n", "output": "26\n"}, {"input": "1 100\n", "output": "16\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "1 1...
89
You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be $\frac{n(n + 1)}{2}$ of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touc...
interview
[{"code": "n=int(input())\nprint(max((i+1)*(n-i)for i in range(n)))\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n = int(input())\n\na = (n + 1) // 2\nb = (n + 2) // 2\n\nprint(a * b)", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "import sys\nn = int...
[{"input": "2\n", "output": "2\n"}, {"input": "3\n", "output": "4\n"}, {"input": "4\n", "output": "6\n"}, {"input": "21\n", "output": "121\n"}, {"input": "100\n", "output": "2550\n"}, {"input": "1\n", "output": "1\n"}, {"input": "5\n", "output": "9\n"}, {"input": "6\n", "output": "12\n"}, {"input": "7\n", "output": "16...
90
Anya loves to fold and stick. Today she decided to do just that. Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes. Anya can stick a...
interview
[{"code": "fact = [ 1 ]\nfor i in range( 1, 20, 1 ):\n fact.append( fact[ i - 1 ] * i )\n\nfrom collections import defaultdict\n\nN, K, S = list(map( int, input().split() ))\nA = list( map( int, input().split() ) )\n\nldp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]\nldp[ 0 ][ 0 ][ 0 ] = 1\...
[{"input": "2 2 30\n4 3\n", "output": "1\n"}, {"input": "2 2 7\n4 3\n", "output": "1\n"}, {"input": "3 1 1\n1 1 1\n", "output": "6\n"}, {"input": "25 25 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "33554432\n"}, {"input": "13 1 60\n3 6 3 4 3 5 1 4 4 4 3 4 3\n", "output": "155\n"}, {"input": "10 ...
91
Suppose you are performing the following algorithm. There is an array $v_1, v_2, \dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you can: either choose position $pos$ ($1 \le pos \le n$) and increase $v_{pos}$ by $k^i$; or not choo...
interview
[{"code": "t = int(input())\nfor _ in range(t):\n n,k = list(map(int,input().split()))\n a = list(map(int,input().split()))\n for i in range(60, -1, -1):\n m = k ** i\n for j in range(n):\n if a[j] >= m:\n a[j] -= m\n break\n if all(i == 0 for i in a):\...
[{"input": "5\n4 100\n0 0 0 0\n1 2\n1\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810\n", "output": "YES\nYES\nNO\nNO\nYES\n"}, {"input": "3\n5 2\n1 2 4 8 17\n2 3\n1 2\n4 3\n10 4 13 12\n", "output": "NO\nNO\nNO\n"}, {"input": "1\n1 10\n10000000000000000\n", "output": "YES\n"}, {"input": "1\n1 100\n10000000000000000\n", "outp...
92
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: $\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$ Find the sum modulo 1073741824 (2^30). -----Input----- The first line contains three s...
interview
[{"code": "a, b, c = map(int, input().split())\nd = 1073741824\np = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\nt = [{} for i in range(101)]\nans = {}\nfor i in p:\n j = i\n m = 1\n while j < 101:\n for k in range(j, 101, j):\n t[k][i] = m...
[{"input": "2 2 2\n", "output": "20\n"}, {"input": "5 6 7\n", "output": "1520\n"}, {"input": "91 42 25\n", "output": "3076687\n"}, {"input": "38 47 5\n", "output": "160665\n"}, {"input": "82 29 45\n", "output": "3504808\n"}, {"input": "40 15 33\n", "output": "460153\n"}, {"input": "35 5 21\n", "output": "55282\n"}, {"i...
93
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the em...
interview
[{"code": "a, b, c, d = input(), input(), input(), input()\na = a + b[::-1]\nx = \"X\"\nfor i in range(4):\n if a[i] == x:\n a = a[:i] + a[i + 1:]\n break\nc = c + d[::-1]\n\nfor i in range(4):\n if c[i] == x:\n c = c[:i] + c[i + 1:]\n break\nflag = False\nfor i in range(4):\n if a ...
[{"input": "AB\nXC\nXB\nAC\n", "output": "YES\n"}, {"input": "AB\nXC\nAC\nBX\n", "output": "NO\n"}, {"input": "XC\nBA\nCB\nAX\n", "output": "NO\n"}, {"input": "AB\nXC\nAX\nCB\n", "output": "YES\n"}, {"input": "CB\nAX\nXA\nBC\n", "output": "YES\n"}, {"input": "BC\nXA\nBA\nXC\n", "output": "NO\n"}, {"input": "CA\nXB\nBA\...
95
Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays a...
interview
[{"code": "n = int(input())\nL = list(map(int, input().split()))\ni = 0\na = 0\nwhile i < n and L[i] > a:\n a = L[i]\n i += 1\nwhile i < n and L[i] == a:\n i += 1\nwhile i < n and L[i] < a:\n a = L[i]\n i += 1\nif i == n:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "me...
[{"input": "6\n1 5 5 5 4 2\n", "output": "YES\n"}, {"input": "5\n10 20 30 20 10\n", "output": "YES\n"}, {"input": "4\n1 2 1 2\n", "output": "NO\n"}, {"input": "7\n3 3 3 3 3 3 3\n", "output": "YES\n"}, {"input": "6\n5 7 11 11 2 1\n", "output": "YES\n"}, {"input": "1\n7\n", "output": "YES\n"}, {"input": "100\n527 527 527...
96
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$ We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, an...
interview
[{"code": "def gg(n,lol):\n\tans = 0\n\tcur = 1\n\tlol2 = lol\n\twhile(2*lol+1<=n):\n\t\tcur *= 2\n\t\tans += cur\n\t\tlol = 2*lol+1\n\t\tlol2 *= 2\n\tif lol2*2 <= n:\n\t\tans += n-lol2*2+1\t\n\treturn ans\n\nn,k = list(map(int,input().split()))\nlow = 1\nhigh = n//2\nres = 1\nwhile low <= high:\n\tmid = (low+high)//2\...
[{"input": "11 3\n", "output": "5\n"}, {"input": "11 6\n", "output": "4\n"}, {"input": "20 20\n", "output": "1\n"}, {"input": "14 5\n", "output": "6\n"}, {"input": "1000000 100\n", "output": "31248\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "2 1\n", "output": "2\n"}, {"input": "100 4\n", "output": "48\n"}, {"i...
98
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a_1 × b_1 rectangle, the paintings have shape of a a_2 × b_2 and a_3 × b_3 rectangles. Si...
interview
[{"code": "a, b = [int(i) for i in input().split()]\nc, d = [int(i) for i in input().split()]\ne, f = [int(i) for i in input().split()]\nif c+e <=a and max(d,f) <=b:\n print(\"YES\")\nelif c+e <=b and max(d,f) <=a:\n print(\"YES\")\nelif c+f <=a and max(d,e) <=b:\n print(\"YES\")\nelif c+f <=b and max(d,e) <=a...
[{"input": "3 2\n1 3\n2 1\n", "output": "YES\n"}, {"input": "5 5\n3 3\n3 3\n", "output": "NO\n"}, {"input": "4 2\n2 3\n1 2\n", "output": "YES\n"}, {"input": "3 3\n1 1\n1 1\n", "output": "YES\n"}, {"input": "1000 1000\n999 999\n1 1000\n", "output": "YES\n"}, {"input": "7 7\n5 5\n2 4\n", "output": "YES\n"}, {"input": "3 ...
99
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., where for each i > 1 the respective term satisfies the condition b...
interview
[{"code": "from sys import stdin, stdout\n\nb, q, l, n = map(int, stdin.readline().split())\na = set(list(map(int, stdin.readline().split())))\nans = 0\nind = 0\n\nwhile abs(b) <= l and ind < 100:\n if not b in a:\n ans += 1\n \n b *= q\n ind += 1\n \nif ans > 40:\n stdout.write('inf')\...
[{"input": "3 2 30 4\n6 14 25 48\n", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245\n", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124\n", "output": "inf"}, {"input": "3 2 25 2\n379195692 -69874783\n", "output": "4"}, {"input": "3 2 30 3\n-691070108 -934106649 -220744807\n", "output": "4"}...
101
Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles. I...
interview
[{"code": "def egcd(a, b):\n x,y, u,v = 0,1, 1,0\n while a != 0:\n q, r = b//a, b%a\n m, n = x-u*q, y-v*q\n b,a, x,y, u,v = a,r, u,v, m,n\n gcd = b\n return gcd, x, y\n\n\nimport math\nn=int(input())\na=int(input())\nb=int(input())\ngcd,x,y=(egcd(a,b))\n\n\nstatus=0\nif((n%gcd)!=0):\n ...
[{"input": "7\n2\n3\n", "output": "YES\n2 1\n"}, {"input": "100\n25\n10\n", "output": "YES\n0 10\n"}, {"input": "15\n4\n8\n", "output": "NO\n"}, {"input": "9960594\n2551\n2557\n", "output": "YES\n1951 1949\n"}, {"input": "10000000\n1\n1\n", "output": "YES\n0 10000000\n"}, {"input": "9999999\n9999\n9999\n", "output": "N...
102
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. [Image] He ate coffee mi...
interview
[{"code": "n = int(input())\nif n == 0:\n\tprint('zero')\nelif n == 1:\n\tprint('one')\nelif n == 2:\n\tprint('two')\nelif n == 3:\n\tprint('three')\nelif n == 4:\n\tprint('four')\nelif n == 5:\n\tprint('five')\nelif n == 6:\n\tprint('six')\nelif n == 7:\n\tprint('seven')\nelif n == 8:\n\tprint('eight')\nelif n == 9:\n...
[{"input": "6\n", "output": "six\n"}, {"input": "99\n", "output": "ninety-nine\n"}, {"input": "20\n", "output": "twenty\n"}, {"input": "10\n", "output": "ten\n"}, {"input": "15\n", "output": "fifteen\n"}, {"input": "27\n", "output": "twenty-seven\n"}, {"input": "40\n", "output": "forty\n"}, {"input": "63\n", "output": ...
103
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom. JATC decided to prank his friend by erasing some consecutive elements in th...
interview
[{"code": "from sys import stdin, stdout\nfrom math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial\n\nn = int(stdin.readline())\nvl = list(map(int, stdin.readline().split()))\nans = 0\n\nfor i in range(n):\n cnt = 0\n while i + cnt < n and vl[i + cnt] == vl[i] + cnt:\n cnt += 1\n \n ans...
[{"input": "6\n1 3 4 5 6 9\n", "output": "2"}, {"input": "3\n998 999 1000\n", "output": "2"}, {"input": "5\n1 2 3 4 5\n", "output": "4"}, {"input": "1\n1\n", "output": "0"}, {"input": "2\n1 2\n", "output": "1"}, {"input": "2\n999 1000\n", "output": "1"}, {"input": "9\n1 4 5 6 7 100 101 102 103\n", "output": "2"}, {"inp...
104
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
interview
[{"code": "def main():\n n = int(input())\n a = list(int(x) for x in input().split())\n s = sum(a)\n t = 0\n for i in range(n):\n t += a[i]\n if 2 * t >= s:\n print(i + 1)\n return\n\nmain()\n", "passed": true, "time": 0.16, "memory": 14672.0, "status": "done"}, {"code...
[{"input": "4\n1 3 2 1\n", "output": "2\n"}, {"input": "6\n2 2 2 2 2 2\n", "output": "3\n"}, {"input": "1\n10000\n", "output": "1\n"}, {"input": "3\n2 1 1\n", "output": "1\n"}, {"input": "2\n1 3\n", "output": "2\n"}, {"input": "4\n2 1 1 3\n", "output": "3\n"}, {"input": "3\n1 1 3\n", "output": "3\n"}, {"input": "3\n1 1...
105
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise distinct. The $j$-th square in the $i$-th row has a number $A_{ij}$...
interview
[{"code": "n=int(input())\ngraph=[{},{},{}]\nfor i in range(n):\n for j in range(n):\n graph[0][(i,j)]=[(k,j) for k in range(n)]+[(i,k) for k in range(n)]\n graph[0][(i,j)].remove((i,j))\n graph[0][(i,j)].remove((i,j))\n graph[1][(i,j)]=[]\n for k in range(n):\n for l in...
[{"input": "3\n1 9 3\n8 6 7\n4 2 5\n", "output": "12 1\n"}, {"input": "3\n1 5 8\n9 2 4\n3 6 7\n", "output": "12 1\n"}, {"input": "4\n5 4 1 13\n8 3 6 16\n15 9 14 12\n11 2 7 10\n", "output": "23 0\n"}, {"input": "5\n21 14 2 3 12\n19 8 16 18 7\n9 17 10 15 4\n24 5 1 23 11\n25 13 22 6 20\n", "output": "38 2\n"}, {"input": "...
106
Есть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором этаже первого подъ...
interview
[{"code": "n, m, k = map(int, input().split())\na, b = map(int, input().split())\na -= 1\nb -= 1\ndef p(x):\n\treturn x // (m * k)\ndef e(x):\n\treturn (x - p(x) * m * k) // k\ndef lift(x):\n\treturn min(5 * x, 10 + x)\n\t\nif p(a) == p(b):\n\tdif = abs(e(a) - e(b))\n\tprint(lift(dif))\nelse:\n\tprint(lift(e(a)) + 15 *...
[{"input": "4 10 5\n200 6\n", "output": "39\n"}, {"input": "3 1 5\n7 2\n", "output": "15\n"}, {"input": "100 100 100\n1 1000000\n", "output": "124\n"}, {"input": "1000 1000 1000\n1 1000000000\n", "output": "1024\n"}, {"input": "125 577 124\n7716799 6501425\n", "output": "1268\n"}, {"input": "624 919 789\n436620192 4517...
108
You are given a string s consisting of |s| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of ...
interview
[{"code": "s = list(input())\ntarget = 'abcdefghijklmnopqrstuvwxyz'\nind_t = 0\nind_s = 0\nwhile ind_s < len(s) and ind_t < 26:\n if ord(s[ind_s]) <= ord(target[ind_t]):\n s[ind_s] = target[ind_t]\n ind_t += 1\n ind_s += 1\n else:\n ind_s += 1\nif ind_t == 26:\n print(''.join(s))\nelse:\n print(-1)", "p...
[{"input": "aacceeggiikkmmooqqssuuwwyy\n", "output": "abcdefghijklmnopqrstuvwxyz\n"}, {"input": "thereisnoanswer\n", "output": "-1\n"}, {"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs\n", "output": "-1\n"}, {"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy\n", "output"...
111
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist. Divisor of n is any such natural number, that n can be divided by it without remainder. -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 10^15, 1 ≤ k ≤ 10^9). -----Output----- If n has less ...
interview
[{"code": "import sys\nimport math\n\ndef factorization(n):\n res = []\n limit = math.ceil(math.sqrt(n))\n p = 2\n cnt = 0\n\n while n % p == 0:\n cnt += 1\n n //= p\n\n if cnt > 0:\n res.append((p, cnt))\n\n cnt = 0\n for p in range(3, limit + 1, 2):\n if n % p == 0:...
[{"input": "4 2\n", "output": "2\n"}, {"input": "5 3\n", "output": "-1\n"}, {"input": "12 5\n", "output": "6\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "866421317361600 26880\n", "output": "866421317361600\n"}, {"input": "866421317361600 26881\n", "output": "-1\n"}, {"input": "1000000000000000 1000000000\n", "...
113
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n. For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program...
interview
[{"code": "def main():\n\tn, k = map(int, input().split())\n\tnum_2 = 0\n\tnum_5 = 0\n\tx = n\n\twhile (x % 2 == 0):\n\t\tnum_2 += 1\n\t\tx //= 2\n\t\t\n\twhile (x % 5 == 0):\n\t\tnum_5 += 1\n\t\tx //= 5\n\tnum_2 = k - min(num_2, k)\n\tnum_5 = k - min(num_5, k)\n\tprint(n * 5 ** num_5 * 2 ** num_2)\n\n\nmain()", "passe...
[{"input": "375 4\n", "output": "30000\n"}, {"input": "10000 1\n", "output": "10000\n"}, {"input": "38101 0\n", "output": "38101\n"}, {"input": "123456789 8\n", "output": "12345678900000000\n"}, {"input": "1 0\n", "output": "1\n"}, {"input": "2 0\n", "output": "2\n"}, {"input": "100 0\n", "output": "100\n"}, {"input": ...
114
You are given two matrices $A$ and $B$. Each matrix contains exactly $n$ rows and $m$ columns. Each element of $A$ is either $0$ or $1$; each element of $B$ is initially $0$. You may perform some operations with matrix $B$. During each operation, you choose any submatrix of $B$ having size $2 \times 2$, and replace ev...
interview
[{"code": "n, m = map(int, input().split())\nA = [list(map(int, input().split())) for _ in range(n)]\nB = [[0] * m for _ in range(n)]\nans = []\nfor i in range(n - 1):\n for j in range(m - 1):\n if A[i][j] == 1 and A[i + 1][j] == 1 and A[i][j + 1] == 1 and A[i + 1][j + 1] == 1:\n B[i][j] = 1\n ...
[{"input": "3 3\n1 1 1\n1 1 1\n0 1 1\n", "output": "3\n1 1\n1 2\n2 2\n"}, {"input": "3 3\n1 0 1\n1 0 1\n0 0 0\n", "output": "-1\n"}, {"input": "3 2\n0 0\n0 0\n0 0\n", "output": "0\n"}, {"input": "2 50\n0 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1\n0 1 1 1 1 1 1 1 0...
116
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visi...
interview
[{"code": "read = lambda: list(map(int, input().split()))\nl1, r1, l2, r2, k = read()\nR = min(r1, r2)\nL = max(l1, l2)\nans = max(R - L + 1, 0)\nif L <= k <= R: ans = max(ans - 1, 0)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14556.0, "status": "done"}, {"code": "l1,r1,l2,r2,k = (int(i) for i in input().s...
[{"input": "1 10 9 20 1\n", "output": "2\n"}, {"input": "1 100 50 200 75\n", "output": "50\n"}, {"input": "6 6 5 8 9\n", "output": "1\n"}, {"input": "1 1000000000 1 1000000000 1\n", "output": "999999999\n"}, {"input": "5 100 8 8 8\n", "output": "0\n"}, {"input": "1 1000000000000000000 2 99999999999999999 1000000000\n",...
118
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc. [Image] Barney woke up in the morning and wants to eat th...
interview
[{"code": "t, s, x = list(map(int, input().split()))\nf = False\nif x - 1 > t and (x - 1 - t) % s == 0:\n f = True\nif x >= t and (x - t) % s == 0:\n f = True\nif f:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.21, "memory": 14476.0, "status": "done"}, {"code": "# You lost the game.\nt,...
[{"input": "3 10 4\n", "output": "NO\n"}, {"input": "3 10 3\n", "output": "YES\n"}, {"input": "3 8 51\n", "output": "YES\n"}, {"input": "3 8 52\n", "output": "YES\n"}, {"input": "456947336 740144 45\n", "output": "NO\n"}, {"input": "33 232603 599417964\n", "output": "YES\n"}, {"input": "4363010 696782227 701145238\n", ...
119
You are given a sequence a_1, a_2, ..., a_{n} of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment a_{i} lies within segment a_{j}. Segment [l_1, r_1] lies within segment [l_2, r_2] iff l_1 ≥ l_2 and r_1 ≤ r_2. Print indices i and j. If there are multip...
interview
[{"code": "n = int(input())\na = []\nfor i in range(1, n + 1):\n l, r = list(map(int, input().split()))\n a.append([l, -r, i])\na.sort()\nhh = a[0][1]\nwahh = max(-1, a[0][2])\nfor i in range(1, n):\n if a[i][1] >= hh:\n print(a[i][2], wahh)\n return\n else:\n hh = a[i][1]\n wahh...
[{"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9\n", "output": "2 1\n"}, {"input": "3\n1 5\n2 6\n6 20\n", "output": "-1 -1\n"}, {"input": "1\n1 1000000000\n", "output": "-1 -1\n"}, {"input": "2\n1 1000000000\n1 1000000000\n", "output": "2 1\n"}, {"input": "2\n1 1000000000\n500000000 500000000\n", "output": "2 1\n"}, {"input": "...
120
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is...
interview
[{"code": "\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn=int(input())\nif n%4: print(\"===\")\nelse:\n t=input().strip()\n a=[n//4]*4\n for i in t:\n if i=='A': a[0]-=1\n elif i=='C': a[1]-=1\n elif i=='G': a[2]-=1\n elif i=='T': a[3]-=1\n if min(a)<0...
[{"input": "8\nAG?C??CT\n", "output": "AGACGTCT\n"}, {"input": "4\nAGCT\n", "output": "AGCT\n"}, {"input": "6\n????G?\n", "output": "===\n"}, {"input": "4\nAA??\n", "output": "===\n"}, {"input": "4\n????\n", "output": "ACGT\n"}, {"input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?C...