problem stringlengths 35 13.2k | solutions listlengths 1 3.42k | tests stringlengths 120 74M | starter_code stringclasses 0
values | metadata stringclasses 1
value | question stringlengths 600 13.8k | ground_truth stringlengths 450 74M | data_source stringclasses 1
value | uid stringlengths 11 15 | index int64 0 17.1k |
|---|---|---|---|---|---|---|---|---|---|
Solve the following coding problem using the programming language python:
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. F... | [
"```python\n# Bartek Kostka\n# You are not prepared!\n\n#include \"bits/stdc++.h\"\n\nn = int(input())\nW = {}\nfor i in range(n):\n adr = input()\n adr = adr.split(\"/\")\n if adr[-1] == '':\n adr[-1] = '?'\n domena = \"/\".join(adr[:3])\n adres = \"/\".join(adr[3:])\n #print(domena, adre... | [{"type": "stdin_stdout", "input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n", "output": "1\nhttp://abacaba.de http://abacaba.ru \n... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
There are some websites that are accessible through severa... | [{"type": "stdin_stdout", "input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n", "output": "1\nhttp://abacaba.de http://abacaba.ru \n... | livecodebench | deepcoder_0 | 0 |
Solve the following coding problem using the programming language python:
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\opera... | [
"```python\na,b=map(int,input().split())\nprint(((b-1)*a*b//2+(a+1)*a*b*b*(b-1)//4)%1000000007)\n```"
] | [{"type": "stdin_stdout", "input": "1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 2\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "4 2\n", "output": "24\n"}, {"type": "stdin_stdout", "input": "4 3\n", "output": "102\n"}, {"type": "s... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Dreamoon loves summing up something for no reason. One day... | [{"type": "stdin_stdout", "input": "1 1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n", "output": "8\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 ... | livecodebench | deepcoder_1 | 1 |
Solve the following coding problem using the programming language python:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except... | [
"```python\nl,r = map(int, input().split(\" \"))\nif l == r:\n print (l)\nelse:\n print (2)\n```"
] | [{"type": "stdin_stdout", "input": "19 29\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 6\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "39 91\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "76 134\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "93 95\n", "output": "2\n"}, {"typ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Tavak and Seyyed are good friends. Seyyed is very funny an... | [{"type": "stdin_stdout", "input": "19 29\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 6\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "39 91\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input":... | livecodebench | deepcoder_2 | 2 |
Solve the following coding problem using the programming language python:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (... | [
"```python\ns=input()\nans = 0\nfor i in range(len(s)):\n if s[i] == 'A':\n ans += s[:i].count('Q') * s[i:].count('Q')\nprint(ans)\n```"
] | [{"type": "stdin_stdout", "input": "QAQAQYSYIOIWIN\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "QAQQQZZYNOIWIN\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "QA\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "IAQVAQZLQBQVQFTQQQADAQJA\n", "output": "24\n"}, {"type": "stdin_stdout", "input"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
"QAQ" is a word to denote an expression of crying. Imagine... | [{"type": "stdin_stdout", "input": "QAQAQYSYIOIWIN\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "QAQQQZZYNOIWIN\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "QA\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_... | livecodebench | deepcoder_3 | 3 |
Solve the following coding problem using the programming language python:
Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to... | [
"```python\nimport heapq\nn,m,a,b=map(int,input().split())\ngraph={i:[] for i in range(n)}\nfor i in range(m):\n u,v,w=map(int,input().split())\n graph[u-1].append((v-1,w))\n graph[v-1].append((u-1,w))\ncomponents=[-1]*n\ncomp=-1\nfor i in range(n):\n if components[i]==-1:\n comp+=1\n comp... | [{"type": "stdin_stdout", "input": "5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\n5 1 20\n", "output": "0 25 60 40 20\n"}, {"type": "stdin_stdout", "input": "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 1 13\n", "output": "0 13 26 39 26 13\n"}, {"type": "stdin_stdout", "input": "2 1 1 2\n2 1 1\n", "output"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Codefortia is a small island country located somewhere in ... | [{"type": "stdin_stdout", "input": "5 5 20 25\n1 2 25\n2 3 25\n3 4 20\n4 5 20\n5 1 20\n", "output": "0 25 60 40 20\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 7 13 22\n1 2 13\n2 3 13\n1 4 22\n3 4 13\n4 5 13\n5 6 13\n6 1 13\n", "output": "0 13 26 39 26 13\n", "metadata": {"func_name": null... | livecodebench | deepcoder_4 | 4 |
Solve the following coding problem using the programming language python:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences... | [
"```python\nX, D = list(map(int, input().split()))\ncn = 1\nadd0 = 1 if (X&1) else 0\nans = []\nfor i in range(30,0,-1):\n\tif not (X & (1<<i)): continue\n\tans += [cn]*i\n\tadd0 += 1\n\tcn += D\nfor i in range(add0):\n\tans.append(cn)\n\tcn += D\nprint(len(ans))\nprint(' '.join(map(str, ans)))\n\n```"
] | [{"type": "stdin_stdout", "input": "10 5\n", "output": "6\n1 1 1 7 13 19 "}, {"type": "stdin_stdout", "input": "4 2\n", "output": "3\n1 1 4 "}, {"type": "stdin_stdout", "input": "4 1\n", "output": "3\n1 1 3 "}, {"type": "stdin_stdout", "input": "1 1\n", "output": "1\n1 "}, {"type": "stdin_stdout", "input": "63 1\n", "o... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Pikachu had an array with him. He wrote down all the non-e... | [{"type": "stdin_stdout", "input": "10 5\n", "output": "6\n1 1 1 7 13 19 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 2\n", "output": "3\n1 1 4 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1\n", "output": "3\n1 1 3 ", "metadata": {"func_name": null}}, {"type": "... | livecodebench | deepcoder_5 | 5 |
Solve the following coding problem using the programming language python:
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this stri... | [
"```python\nstr = input()\nl = len(str)\na = [0] * (2 * l)\npos = [[] for i in range(26)]\nfor i, c in enumerate(str):\n t = ord(c) - ord('a')\n a[i] = t\n a[i + l] = t\n pos[t].append(i)\nans = 0\nfor c in range(26):\n cur = 0\n for k in range(1, l):\n cnt = [0] * 26\n for i in pos[... | [{"type": "stdin_stdout", "input": "technocup\n", "output": "1.000000000000000\n"}, {"type": "stdin_stdout", "input": "tictictactac\n", "output": "0.333333333333333\n"}, {"type": "stdin_stdout", "input": "bbaabaabbb\n", "output": "0.100000000000000\n"}, {"type": "stdin_stdout", "input": "cbbbbcaaca\n", "output": "0.800... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Vasya and Kolya play a game with a string, using the follo... | [{"type": "stdin_stdout", "input": "technocup\n", "output": "1.000000000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "tictictactac\n", "output": "0.333333333333333\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "bbaabaabbb\n", "output": "0.100000000000000\n", "... | livecodebench | deepcoder_6 | 6 |
Solve the following coding problem using the programming language python:
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the... | [
"```python\nfrom bisect import *\nfrom math import *\n\nn = int(input())\na, b, c, d = list(map(int,input().replace('/',' ').split()))\n\nalpha = atan2(c,d) - atan2(a,b)\ntan_alpha = tan(alpha)\n\nlis = []\n\nfor x,y in sorted((y/tan_alpha - x,y) for x,y in [ (x,y) for x,y in [(b*x + a*y,-a*x + b*y) for x, y in [li... | [{"type": "stdin_stdout", "input": "15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 5\n4 5\n1 6\n6 6\n", "output": "1\n"}, {"type": "stdin_stdout", "i... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
In the evenings Donkey would join Shrek to look at the sta... | [{"type": "stdin_stdout", "input": "15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5\n2 1\n4 2\n5 3\n7 4\n1 3\n3 4\n2 5\n4 5\n1 6\n6 6\n", "output": "1... | livecodebench | deepcoder_7 | 7 |
Solve the following coding problem using the programming language python:
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from n... | [
"```python\nx = input ()\n\nflag = 0\ns = 0\n\nfor each_item in x:\n if each_item == '0':\n if flag == 0:\n flag = 1;\n continue\n else:\n print (each_item, end = '')\n else:\n if (s == len (x) - 1 and flag == 0) :\n continue\n print (eac... | [{"type": "stdin_stdout", "input": "101\n", "output": "11\n"}, {"type": "stdin_stdout", "input": "110010\n", "output": "11010\n"}, {"type": "stdin_stdout", "input": "10000\n", "output": "1000\n"}, {"type": "stdin_stdout", "input": "1111111110\n", "output": "111111111\n"}, {"type": "stdin_stdout", "input": "101001010111... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
The Little Elephant has an integer a, written in the binar... | [{"type": "stdin_stdout", "input": "101\n", "output": "11\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "110010\n", "output": "11010\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10000\n", "output": "1000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout",... | livecodebench | deepcoder_8 | 8 |
Solve the following coding problem using the programming language python:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, e... | [
"```python\ndef gcd(a, b):\n while b > 0:\n a, b = b, a % b\n return a\n\nn = int(input())\nA = list(map(int, input().split()))\n\nGCD = A[0]\nfor x in A[1:]:\n GCD = gcd(GCD, x)\nnum = max(A) // GCD - n\nif num % 2 == 0:\n print(\"Bob\")\nelse:\n print(\"Alice\")\n\n\n```"
] | [{"type": "stdin_stdout", "input": "2\n2 3\n", "output": "Alice\n"}, {"type": "stdin_stdout", "input": "2\n5 3\n", "output": "Alice\n"}, {"type": "stdin_stdout", "input": "3\n5 6 7\n", "output": "Bob\n"}, {"type": "stdin_stdout", "input": "10\n72 96 24 66 6 18 12 30 60 48\n", "output": "Bob\n"}, {"type": "stdin_stdout"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
It is so boring in the summer holiday, isn't it? So Alice ... | [{"type": "stdin_stdout", "input": "2\n2 3\n", "output": "Alice\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n5 3\n", "output": "Alice\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n5 6 7\n", "output": "Bob\n", "metadata": {"func_name": null}}, {"type": "stdin_... | livecodebench | deepcoder_9 | 9 |
Solve the following coding problem using the programming language python:
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the a... | [
"```python\nimport sys\nfrom itertools import *\nfrom math import *\ndef solve():\n n, m = map(int, input().split())\n h = list(map(int, input().split()))\n p = list(map(int, input().split()))\n ss, ll = 0, int(2.2e10)\n while ss < ll:\n avg = (ss + ll) // 2\n works = True\n hidx... | [{"type": "stdin_stdout", "input": "3 4\n2 5 6\n1 3 6 8\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 3\n1 2 3\n1 2 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 2\n165\n142 200\n", "output": "81\n"}, {"type": "stdin_stdout", "input": "1 2\n5000000000\n1 10000000000\n", "output": "1499999999... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Mad scientist Mike does not use slow hard disks. His modif... | [{"type": "stdin_stdout", "input": "3 4\n2 5 6\n1 3 6 8\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\n1 2 3\n1 2 3\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 2\n165\n142 200\n", "output": "81\n", "metadata": {"func_name": ... | livecodebench | deepcoder_10 | 10 |
Solve the following coding problem using the programming language python:
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya... | [
"```python\nfrom sys import stdin\n\n#stdin = open('input.txt')\n\nn = int(stdin.readline())\n\nseq = [int(x) for x in stdin.readline().split()]\ncarry = seq[0]\nresult = [carry]\n\nmark = False\ncur_len = 0\nmax_len = 0\n\ni = 1\nwhile i < len(seq) - 1:\n if mark:\n if seq[i] != seq[i + 1]:\n ... | [{"type": "stdin_stdout", "input": "4\n0 0 1 1\n", "output": "0\n0 0 1 1\n"}, {"type": "stdin_stdout", "input": "5\n0 1 0 1 0\n", "output": "2\n0 0 0 0 0\n"}, {"type": "stdin_stdout", "input": "3\n1 0 0\n", "output": "0\n1 0 0\n"}, {"type": "stdin_stdout", "input": "4\n1 0 0 1\n", "output": "0\n1 0 0 1\n"}, {"type": "s... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
A schoolboy named Vasya loves reading books on programming... | [{"type": "stdin_stdout", "input": "4\n0 0 1 1\n", "output": "0\n0 0 1 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n0 1 0 1 0\n", "output": "2\n0 0 0 0 0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 0 0\n", "output": "0\n1 0 0\n", "metadata": {"func_name... | livecodebench | deepcoder_11 | 11 |
Solve the following coding problem using the programming language python:
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense... | [
"```python\nimport random\n\nn = int(input())\nv = []\na = []\nfor i in range(n):\n a.append(i)\n\nfor _ in range(0, n):\n x, y = list(map(int, input().split()))\n v.append([x, y, x*x+y*y])\n\nwhile 1>0:\n x = 0\n y = 0\n ans = [0]*n\n random.shuffle(a)\n for i in range(n):\n if (x+v[... | [{"type": "stdin_stdout", "input": "3\n999999 0\n0 999999\n999999 0\n", "output": "1 1 -1 \n"}, {"type": "stdin_stdout", "input": "1\n-824590 246031\n", "output": "1 \n"}, {"type": "stdin_stdout", "input": "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 7... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 +... | [{"type": "stdin_stdout", "input": "3\n999999 0\n0 999999\n999999 0\n", "output": "1 1 -1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n-824590 246031\n", "output": "1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8\n-67761 603277\n640586 -396671\n46147 -122580... | livecodebench | deepcoder_12 | 12 |
Solve the following coding problem using the programming language python:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample.
Limak will repeat the fo... | [
"```python\n\nx = int(input())\ny = list(map(int, input().split(' ')))\n\ny[0] = 1\ny[x-1] = 1\n\nz = y[:]\nfor i in range(1, x):\n z[i] = min(z[i], z[i-1] + 1)\n\nw = y[:]\nfor i in range(x-2, -1, -1):\n w[i] = min(w[i], w[i+1]+1)\n\nans = 0\nfor i in range(x):\n ans = max(ans, min(z[i], w[i]))\n\nprint(a... | [{"type": "stdin_stdout", "input": "6\n2 1 4 6 2 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "7\n3 3 3 1 3 3 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\n5128 5672 5805 5452 5882 5567 5032\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10\n1 2 2 3 5 5 5 4 2 1\n", "output": "5\n"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Limak is a little bear who loves to play. Today he is play... | [{"type": "stdin_stdout", "input": "6\n2 1 4 6 2 2\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n3 3 3 1 3 3 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n5128 5672 5805 5452 5882 5567 5032\n", "output": "4\n", "metadata": {... | livecodebench | deepcoder_13 | 13 |
Solve the following coding problem using the programming language python:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answe... | [
"```python\nn=int(input())\nq=[]\nfor i in range(max(0,n-100),n+1):\n\tj=i\n\tres=i\n\twhile j:\n\t\tres+=j%10\n\t\tj//=10\n\tif res==n:\n\t\tq.append(i)\nprint(len(q))\nfor i in q:\n\tprint(i)\n```"
] | [{"type": "stdin_stdout", "input": "21\n", "output": "1\n15\n"}, {"type": "stdin_stdout", "input": "20\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "1\n1\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "0\n"}, {"type": "stdin... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Eighth-grader Vova is on duty today in the class. After cl... | [{"type": "stdin_stdout", "input": "21\n", "output": "1\n15\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "20\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\... | livecodebench | deepcoder_14 | 14 |
Solve the following coding problem using the programming language python:
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' $\rightarrow$ 'y' $\rightarrow$ 'x' $\rightarrow \ldots \rightarrow$ 'b' $\rightarrow... | [
"```python\n#!/usr/bin/env python3\n\nimport re\n\ntry:\n while True:\n s = input()\n m = re.search(r\"[^a]\", s)\n if m is None:\n print(s[:-1], end=\"z\\n\")\n else:\n j = s.find('a', m.end())\n if j == -1:\n j = len(s)\n pr... | [{"type": "stdin_stdout", "input": "codeforces\n", "output": "bncdenqbdr\n"}, {"type": "stdin_stdout", "input": "abacaba\n", "output": "aaacaba\n"}, {"type": "stdin_stdout", "input": "babbbabaababbaa\n", "output": "aabbbabaababbaa\n"}, {"type": "stdin_stdout", "input": "bcbacaabcababaccccaaaabacbbcbbaa\n", "output": "a... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given a non-empty string s consisting of lowercase... | [{"type": "stdin_stdout", "input": "codeforces\n", "output": "bncdenqbdr\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "abacaba\n", "output": "aaacaba\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "babbbabaababbaa\n", "output": "aabbbabaababbaa\n", "metadata": {"func_... | livecodebench | deepcoder_15 | 15 |
Solve the following coding problem using the programming language python:
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking... | [
"```python\nmod = 1000000007\n\ndef sum(x, y, k, add) :\n if k < add : return 0\n up = x + add\n if up > k : up = k\n add = add + 1\n return y * ( ( (add + up) * (up - add + 1) // 2 ) % mod ) % mod\n\ndef solve(x, y, k, add = 0) :\n if x == 0 or y == 0 : return 0\n if x > y :\n x, y = y,... | [{"type": "stdin_stdout", "input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n", "output": "1\n13\n93\n0\n"}, {"type": "stdin_stdout", "input": "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16\n", "output": "22\n130\n0\n0\n25\n3\n0\... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
After a wonderful evening in the restaurant the time to go... | [{"type": "stdin_stdout", "input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n", "output": "1\n13\n93\n0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16\n", "o... | livecodebench | deepcoder_16 | 16 |
Solve the following coding problem using the programming language python:
Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers f... | [
"```python\nimport sys\n\nn = int(input())\n\nv = [ list(map(int, input().split())) for i in range(n)]\n\nres = []\n\nfor i in range(n):\n\tif v[i][2] >= 0:\n\t\tres.append(i + 1)\n\t\tdec = 0\n\t\tfor j in range(i + 1, n):\n\t\t\tif v[j][2] >= 0:\n\t\t\t\tif v[i][0] > 0:\n\t\t\t\t\tv[j][2] -= v[i][0]\n\t\t\t\t\tv[... | [{"type": "stdin_stdout", "input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "output": "2\n1 3 "}, {"type": "stdin_stdout", "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n", "output": "4\n1 2 4 5 "}, {"type": "stdin_stdout", "input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Gennady is one of the best child dentists in Berland. Toda... | [{"type": "stdin_stdout", "input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "output": "2\n1 3 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n", "output": "4\n1 2 4 5 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n10 7 10\n3 6 1... | livecodebench | deepcoder_17 | 17 |
Solve the following coding problem using the programming language python:
This problem is the most boring one you've ever seen.
Given a sequence of integers a_1, a_2, ..., a_{n} and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements).... | [
"```python\nn,m=map(int,input().split());a=list(map(int,input().split()));p=0;t=[0]*3\nfor i in range(n):\n if(a[i]<a[p]):p=i \nif(n==2):print('0\\n1 1\\n')\nelse:\n a.sort();t[0]=min(a[0]+a[1]+m,a[1]+a[2]);t[1]=max(a[0]+a[n-1]+m,a[n-2]+a[n-1]);t[2]=(a[n-2]+a[n-1])-(a[0]+a[1])\n if(t[1]-t[0]>t[2]):p=n\n ... | [{"type": "stdin_stdout", "input": "3 2\n1 2 3\n", "output": "1\n1 2 2 \n"}, {"type": "stdin_stdout", "input": "5 10\n0 1 0 2 1\n", "output": "3\n2 2 2 2 2 \n"}, {"type": "stdin_stdout", "input": "9 0\n11 22 33 44 55 66 77 88 99\n", "output": "154\n2 2 2 2 2 2 2 2 2 \n"}, {"type": "stdin_stdout", "input": "10 100\n2705... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
This problem is the most boring one you've ever seen.
Gi... | [{"type": "stdin_stdout", "input": "3 2\n1 2 3\n", "output": "1\n1 2 2 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 10\n0 1 0 2 1\n", "output": "3\n2 2 2 2 2 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "9 0\n11 22 33 44 55 66 77 88 99\n", "output": "154\n2 2 2... | livecodebench | deepcoder_18 | 18 |
Solve the following coding problem using the programming language python:
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remain... | [
"```python\nimport math\n#import fractions\nfrom functools import reduce\n\nn = int(input())\nodd = -1\nbeads = [int(x) for x in input().split()]\nfor i in range(n):\n if beads[i]%2:\n if odd >= 0:\n print(0)\n print(''.join(chr(ord('a') + i)*beads[i] for i in range(n)))\n ... | [{"type": "stdin_stdout", "input": "3\n4 2 1\n", "output": "1\naabcbaa\n"}, {"type": "stdin_stdout", "input": "1\n4\n", "output": "4\naaaa\n"}, {"type": "stdin_stdout", "input": "2\n1 1\n", "output": "0\nab\n"}, {"type": "stdin_stdout", "input": "1\n2\n", "output": "2\naa\n"}, {"type": "stdin_stdout", "input": "1\n3\n"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Ivan wants to make a necklace as a present to his beloved ... | [{"type": "stdin_stdout", "input": "3\n4 2 1\n", "output": "1\naabcbaa\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n4\n", "output": "4\naaaa\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1 1\n", "output": "0\nab\n", "metadata": {"func_name": null}}, {"type": ... | livecodebench | deepcoder_19 | 19 |
Solve the following coding problem using the programming language python:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge u... | [
"```python\ndef main():\n n, m = list(map(int, input().split()))\n l = [[] for _ in range(n + 1)]\n for _ in range(m):\n u, v = list(map(int, input().split()))\n l[u].append(v)\n l[v].append(u)\n res = [0] * (n + 1)\n for u, x in enumerate(res):\n if not x:\n x,... | [{"type": "stdin_stdout", "input": "4 2\n1 2\n2 3\n", "output": "1\n2 \n2\n1 3 \n"}, {"type": "stdin_stdout", "input": "3 3\n1 2\n2 3\n1 3\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "10 11\n4 10\n8 10\n2 3\n2 ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Recently, Pari and Arya did some research about NP-Hard pr... | [{"type": "stdin_stdout", "input": "4 2\n1 2\n2 3\n", "output": "1\n2 \n2\n1 3 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\n1 2\n2 3\n1 3\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5\n", "output": "-1\... | livecodebench | deepcoder_20 | 20 |
Solve the following coding problem using the programming language python:
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a ne... | [
"```python\nn,m=map(int,input().split())\nif n==1and m==1:print('YES\\n1')\nelif n==3and m==3:\n print('YES')\n print(6, 1, 8)\n print(7,5,3)\n print(2,9,4)\nelif n<4and m<4:print('NO')\nelif n==1 or m==1:\n t=max(n,m)\n a=[i for i in range(2,t+1,2)]\n a+=[i for i in range(1,t+1,2)]\n print(... | [{"type": "stdin_stdout", "input": "2 4\n", "output": "YES\n5 4 7 2 \n3 6 1 8 \n"}, {"type": "stdin_stdout", "input": "2 1\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1 1\n", "output": "YES\n1\n"}, {"type": "stdin_stdout", "input": "1 2\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1 3\n", "ou... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Students went into a class to write a test and sat in some... | [{"type": "stdin_stdout", "input": "2 4\n", "output": "YES\n5 4 7 2 \n3 6 1 8 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 1\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 1\n", "output": "YES\n1\n", "metadata": {"func_name": null}}, {"type": ... | livecodebench | deepcoder_21 | 21 |
Solve the following coding problem using the programming language python:
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!
The only thing Mrs. Smith remembered was that any permutation of $n$ can be a secret phone number. Only those permutations that minimize secret val... | [
"```python\nfrom math import sqrt\nn = int(input())\nk = int(sqrt(n))\nb = []\nlast = 0\nwhile last < n:\n b.append([last + j for j in range(k)])\n last = b[-1][-1] + 1\nk = len(b)\nfor i in range(k - 1, -1, -1):\n for j in b[i]:\n if j < n:\n print(1 + j, end=' ')\nprint()\n\n```"
] | [{"type": "stdin_stdout", "input": "4\n", "output": "3 4 1 2\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "2 1\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n", "output": "3 2 1\n"}, {"type": "stdin_stdout", "input": "5\n", "output": "4 5 2 3 1\n"}, {"ty... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Mrs. Smith is trying to contact her husband, John Smith, b... | [{"type": "stdin_stdout", "input": "4\n", "output": "3 4 1 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n", "output": "2 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "... | livecodebench | deepcoder_22 | 22 |
Solve the following coding problem using the programming language python:
You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence ... | [
"```python\nn = input()\nread = input()\np = []\nfor x in read.split():\n p.append((float)(x))\n \nv = 0.0\nl = 0.0\nfor item in p:\n v = v*(1-item) + item*(v + 2*l + 1)\n l = (l + 1)*item\nprint(v)\n\n```"
] | [{"type": "stdin_stdout", "input": "3\n0.5 0.5 0.5\n", "output": "2.750000000000000\n"}, {"type": "stdin_stdout", "input": "4\n0.7 0.2 0.1 0.9\n", "output": "2.489200000000000\n"}, {"type": "stdin_stdout", "input": "5\n1 1 1 1 1\n", "output": "25.000000000000000\n"}, {"type": "stdin_stdout", "input": "10\n0.684846 0.15... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You're playing a game called Osu! Here's a simplified vers... | [{"type": "stdin_stdout", "input": "3\n0.5 0.5 0.5\n", "output": "2.750000000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n0.7 0.2 0.1 0.9\n", "output": "2.489200000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 1 1 1 1\n", "output": "25.0000000... | livecodebench | deepcoder_23 | 23 |
Solve the following coding problem using the programming language python:
Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (x_{i... | [
"```python\nn, d = map(int, input().split())\na = [0] + list(map(int, input().split())) + [0]\nx = []\ny = []\nfor i in range(n):\n xx, yy = map(int, input().split())\n x += [xx]\n y += [yy]\nb = [-1] * n\nb[0] = 0\nc = True\nwhile c:\n c = False\n for i in range(n):\n for j in range(1, n):\n if i != j... | [{"type": "stdin_stdout", "input": "3 1000\n1000\n0 0\n0 1\n0 3\n", "output": "2000\n"}, {"type": "stdin_stdout", "input": "3 1000\n1000\n1 0\n1 1\n1 2\n", "output": "1000\n"}, {"type": "stdin_stdout", "input": "5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67\n", "output": "169099\n"}, {"type": "stdin_stdout... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Yaroslav is playing a game called "Time". The game has a t... | [{"type": "stdin_stdout", "input": "3 1000\n1000\n0 0\n0 1\n0 3\n", "output": "2000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 1000\n1000\n1 0\n1 1\n1 2\n", "output": "1000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 1421\n896 448 727\n-19 -40\n-87 40\n69 5... | livecodebench | deepcoder_24 | 24 |
Solve the following coding problem using the programming language python:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered ... | [
"```python\nt = input()\na, b = [i for i, d in enumerate(t, 1) if d == 'l'], [i for i, d in enumerate(t, 1) if d == 'r']\na.reverse()\nprint('\\n'.join(map(str, b)))\nprint('\\n'.join(map(str, a)))\n```"
] | [{"type": "stdin_stdout", "input": "llrlr\n", "output": "3\n5\n4\n2\n1\n"}, {"type": "stdin_stdout", "input": "rrlll\n", "output": "1\n2\n5\n4\n3\n"}, {"type": "stdin_stdout", "input": "lrlrr\n", "output": "2\n4\n5\n3\n1\n"}, {"type": "stdin_stdout", "input": "lllrlrllrl\n", "output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1\n"}... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Squirrel Liss lived in a forest peacefully, but unexpected... | [{"type": "stdin_stdout", "input": "llrlr\n", "output": "3\n5\n4\n2\n1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "rrlll\n", "output": "1\n2\n5\n4\n3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "lrlrr\n", "output": "2\n4\n5\n3\n1\n", "metadata": {"func_name": nul... | livecodebench | deepcoder_25 | 25 |
Solve the following coding problem using the programming language python:
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn t... | [
"```python\n\ndef solve(s):\n n = len(s)\n\n for i in range(n):\n s2 = s[i:] + s[:i]\n # print(s2)\n if s != s2 and s2[::-1] == s2:\n return 1\n\n for i in range( (n // 2) + 1, n):\n if s[i] != s[0]:\n return 2\n # print(s[i])\n return \"Impossibl... | [{"type": "stdin_stdout", "input": "nolon\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "otto\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "qqqq\n", "output": "Impossible\n"}, {"type": "stdin_stdout", "input": "kinnikkinnik\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "nnnnnnnnnnnnnnnnnn... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Reading books is one of Sasha's passions. Once while he wa... | [{"type": "stdin_stdout", "input": "nolon\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "otto\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "qqqq\n", "output": "Impossible\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout",... | livecodebench | deepcoder_26 | 26 |
Solve the following coding problem using the programming language python:
A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are $\frac{n \cdot(n - 1)}{2}$ roads in total. It takes exactly y seconds to traverse any single road.
A spanning tree is... | [
"```python\nfrom collections import defaultdict\nfrom collections import deque\nfrom functools import reduce\nn, x, y = [int(x) for x in input().split()]\nE = defaultdict(set)\nfor i in range(n-1):\n u, v = [int(x) for x in input().split()]\n E[u].add(v)\n E[v].add(u)\n\nif x > y:\n for v in E:\n ... | [{"type": "stdin_stdout", "input": "5 2 3\n1 2\n1 3\n3 4\n5 3\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5 3 2\n1 2\n1 3\n3 4\n5 3\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n32 3\n44 41\n50 31\n50 34\n5 14\n36 13\n22 40\n20 9\n9 43\n19 47\n... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
A group of n cities is connected by a network of roads. Th... | [{"type": "stdin_stdout", "input": "5 2 3\n1 2\n1 3\n3 4\n5 3\n", "output": "9\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 3 2\n1 2\n1 3\n3 4\n5 3\n", "output": "8\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n... | livecodebench | deepcoder_27 | 27 |
Solve the following coding problem using the programming language python:
Dreamoon likes coloring cells very much.
There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$.
You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l... | [
"```python\ndef main():\n import sys\n input = sys.stdin.readline\n\n N, M = list(map(int, input().split()))\n L = list(map(int, input().split()))\n\n if sum(L) < N:\n print(-1)\n return\n\n ans = [0] * M\n left = N\n for i in range(M-1, -1, -1):\n if left - L[i] >= i:\n... | [{"type": "stdin_stdout", "input": "5 3\n3 2 2\n", "output": "1 2 4\n"}, {"type": "stdin_stdout", "input": "10 1\n1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 2\n1 2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "200 50\n49 35 4... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Dreamoon likes coloring cells very much.
There is a row o... | [{"type": "stdin_stdout", "input": "5 3\n3 2 2\n", "output": "1 2 4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 1\n1\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_st... | livecodebench | deepcoder_28 | 28 |
Solve the following coding problem using the programming language python:
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a_0 = v, a_1, ..., a_{k}, and b_0 = v, b_1, ..., b_{k}. Additionally, vertices a_1, .... | [
"```python\nimport math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\ndef LI(): return list(map(int, input().split()))\ndef II(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\n\ndef m... | [{"type": "stdin_stdout", "input": "6\n1 2\n2 3\n2 4\n4 5\n1 6\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n3 1\n1 2\n", "output": "1\n"}, {"type": "st... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Vanya wants to minimize a tree. He can perform the followi... | [{"type": "stdin_stdout", "input": "6\n1 2\n2 3\n2 4\n4 5\n1 6\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "1\n", "metadata": {"fu... | livecodebench | deepcoder_29 | 29 |
Solve the following coding problem using the programming language python:
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should mat... | [
"```python\nh = int(input())\na = list(map(int, input().split()))\n\nw, q = [], []\np = r = 0\n\nfor i in a:\n for j in range(i):\n w.append(r)\n q.append(r - (j and p > 1))\n\n p = i\n r += i\n\nif w == q:\n print('perfect')\nelse:\n print('ambiguous')\n print(*w)\n print(*q)\n\n... | [{"type": "stdin_stdout", "input": "2\n1 1 1\n", "output": "perfect\n"}, {"type": "stdin_stdout", "input": "2\n1 2 2\n", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"}, {"type": "stdin_stdout", "input": "10\n1 1 1 1 1 1 1 1 1 1 1\n", "output": "perfect\n"}, {"type": "stdin_stdout", "input": "10\n1 1 1 1 1 2 1 1 1 1 1\n... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Sasha is taking part in a programming competition. In one ... | [{"type": "stdin_stdout", "input": "2\n1 1 1\n", "output": "perfect\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1 2 2\n", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n1 1 1 1 1 1 1 1 1 1 1\n", "output": "perfect\n... | livecodebench | deepcoder_30 | 30 |
Solve the following coding problem using the programming language python:
You are given $n$ points on the plane. The polygon formed from all the $n$ points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from $1... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nn = int(input())\nx = []\ny = []\nfor i in range(n):\n xi, yi = map(int, input().split())\n x.append(xi)\n y.append(yi)\nmin_x = min(x)\nmax_x = max(x)\nmin_y = min(y)\nmax_y = max(y)\nanswer = 0\nfor i in range(n):\n dx = max(max_x - x[i], x[i] - mi... | [{"type": "stdin_stdout", "input": "4\n2 4\n4 3\n3 0\n1 3\n", "output": "12 14 "}, {"type": "stdin_stdout", "input": "3\n0 0\n0 2\n2 0\n", "output": "8 "}, {"type": "stdin_stdout", "input": "8\n0 3\n2 2\n3 0\n2 -2\n0 -3\n-2 -2\n-3 0\n-2 2\n", "output": "20 24 24 24 24 24 "}, {"type": "stdin_stdout", "input": "4\n-10000... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given $n$ points on the plane. The polygon formed ... | [{"type": "stdin_stdout", "input": "4\n2 4\n4 3\n3 0\n1 3\n", "output": "12 14 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n0 0\n0 2\n2 0\n", "output": "8 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8\n0 3\n2 2\n3 0\n2 -2\n0 -3\n-2 -2\n-3 0\n-2 2\n", "output": "... | livecodebench | deepcoder_31 | 31 |
Solve the following coding problem using the programming language python:
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. $2^n$ teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify ... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nn,k=list(map(int,input().split()))\nif k==0:\n print(0)\n return\n\nA=sorted(map(int,input().split()))\n\n# DP[UL][n][left]\n# [left*pow(2,n),left*pow(2,n)+pow(2,n))の間のチームで,\n# ファンのチームが\n# UL=0: upperでもlowerでも勝ち残っている\n# UL=1: upperでのみ勝ち残っている\n# UL=2: lower... | [{"type": "stdin_stdout", "input": "3 1\n6\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "3 3\n1 7 8\n", "output": "11\n"}, {"type": "stdin_stdout", "input": "3 4\n1 3 5 7\n", "output": "14\n"}, {"type": "stdin_stdout", "input": "10 10\n334 588 666 787 698 768 934 182 39 834\n", "output": "138\n"}, {"type": "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
The biggest event of the year – Cota 2 world championship ... | [{"type": "stdin_stdout", "input": "3 1\n6\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\n1 7 8\n", "output": "11\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 4\n1 3 5 7\n", "output": "14\n", "metadata": {"func_name": null}}, {"type": "stdin_... | livecodebench | deepcoder_32 | 32 |
Solve the following coding problem using the programming language python:
You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.
Today you are late, so there are queues on some floors already. For each person you know... | [
"```python\n# python3\nimport sys\nfrom collections import namedtuple\n\n\ndef readline(): return list(map(int, input().split()))\n\n\ndef readlines():\n for line in sys.stdin.readlines():\n yield list(map(int, line.split()))\n\n\nclass State(namedtuple('State', 'payload time floor')):\n def hook(self,... | [{"type": "stdin_stdout", "input": "2\n3 5\n5 3\n", "output": "10"}, {"type": "stdin_stdout", "input": "2\n5 3\n3 5\n", "output": "12"}, {"type": "stdin_stdout", "input": "9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1\n", "output": "34"}, {"type": "stdin_stdout", "input": "50\n9 5\n2 6\n5 4\n7 5\n3 6\n5 8\n1 2\n6 1\n9... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You work in a big office. It is a 9 floor building with an... | [{"type": "stdin_stdout", "input": "2\n3 5\n5 3\n", "output": "10", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n5 3\n3 5\n", "output": "12", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1\n", "output": "34", "metadata": {"f... | livecodebench | deepcoder_33 | 33 |
Solve the following coding problem using the programming language python:
Logical quantifiers are very useful tools for expressing claims about a set. For this problem, let's focus on the set of real numbers specifically. The set of real numbers includes zero and negatives. There are two kinds of quantifiers: universa... | [
"```python\nimport sys\n\nn, m = [int(x) for x in input().split()]\n\nadj_for = [[] for _ in range(n)]\nadj_back = [[] for _ in range(n)]\n\nfor _ in range(m):\n a, b = [int(x) for x in sys.stdin.readline().split()]\n a -= 1\n b -= 1\n adj_for[a].append(b)\n adj_back[b].append(a)\n\n\nlens = [len(adj... | [{"type": "stdin_stdout", "input": "2 1\n1 2\n", "output": "1\nAE\n"}, {"type": "stdin_stdout", "input": "4 3\n1 2\n2 3\n3 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "3 2\n1 3\n2 3\n", "output": "2\nAAE\n"}, {"type": "stdin_stdout", "input": "6 3\n1 3\n2 5\n4 6\n", "output": "3\nAAEAEE\n"}, {"type": "st... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Logical quantifiers are very useful tools for expressing c... | [{"type": "stdin_stdout", "input": "2 1\n1 2\n", "output": "1\nAE\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 3\n1 2\n2 3\n3 1\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 2\n1 3\n2 3\n", "output": "2\nAAE\n", "metadata": {"func_name": null}... | livecodebench | deepcoder_34 | 34 |
Solve the following coding problem using the programming language python:
Toad Zitz has an array of integers, each integer is between $0$ and $m-1$ inclusive. The integers are $a_1, a_2, \ldots, a_n$.
In one operation Zitz can choose an integer $k$ and $k$ indices $i_1, i_2, \ldots, i_k$ such that $1 \leq i_1 < i_2 <... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nn,m=list(map(int,input().split()))\nA=list(map(int,input().split()))\n\n\nMIN=0\nMAX=m\n\nwhile MIN!=MAX:\n x=(MIN+MAX)//2\n #print(x,MIN,MAX)\n #print()\n\n M=0\n for a in A:\n #print(a,M)\n if a<=M and a+x>=M:\n continue... | [{"type": "stdin_stdout", "input": "5 3\n0 0 0 1 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 7\n0 6 1 3 2\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 10\n5 0 5 9 4 6 4 5 0 0\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "4 6\n0 3 5 1\n", "output": "3\n"}, {"type": "stdin_stdou... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Toad Zitz has an array of integers, each integer is betwee... | [{"type": "stdin_stdout", "input": "5 3\n0 0 0 1 2\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 7\n0 6 1 3 2\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 10\n5 0 5 9 4 6 4 5 0 0\n", "output": "6\n", "metadata": {"func_name": ... | livecodebench | deepcoder_35 | 35 |
Solve the following coding problem using the programming language python:
Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces ... | [
"```python\nn, h = map(int,input().split())\nunit = h*h/n\nfor i in range(1,n):\n print((unit*i)**0.5, end=' ')\n```"
] | [{"type": "stdin_stdout", "input": "3 2\n", "output": "1.154700538379 1.632993161855\n"}, {"type": "stdin_stdout", "input": "2 100000\n", "output": "70710.678118654752\n"}, {"type": "stdin_stdout", "input": "2 1\n", "output": "0.707106781187\n"}, {"type": "stdin_stdout", "input": "20 17\n", "output": "3.801315561750 5.... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Igor the analyst has adopted n little bunnies. As we all k... | [{"type": "stdin_stdout", "input": "3 2\n", "output": "1.154700538379 1.632993161855\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 100000\n", "output": "70710.678118654752\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 1\n", "output": "0.707106781187\n", "metadat... | livecodebench | deepcoder_36 | 36 |
Solve the following coding problem using the programming language python:
The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied: t_{i} < t_{i} + 1 for each odd i < n; t_{i} > t_{i} + 1 for each even i < n.
For example, seque... | [
"```python\ndef main():\n n, l = int(input()), list(map(int, input().split()))\n if not (n & 1):\n l.append(0)\n l.append(150001)\n i, b, c, fails0, fails1 = 0, 0, 150001, [], []\n try:\n while True:\n a, b, c = b, c, l[i]\n if a >= b or b <= c:\n if... | [{"type": "stdin_stdout", "input": "5\n2 8 4 7 7\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n200 150 100 50\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10\n3 2 1 4 1 4 1 4 1 4\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "9\n1 2 3 4 5 6 7 8 9\n", "output": "0\n"}, {"type": "stdin... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
The life goes up and down, just like nice sequences. Seque... | [{"type": "stdin_stdout", "input": "5\n2 8 4 7 7\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n200 150 100 50\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n3 2 1 4 1 4 1 4 1 4\n", "output": "8\n", "metadata": {"func_name": nu... | livecodebench | deepcoder_37 | 37 |
Solve the following coding problem using the programming language python:
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Simila... | [
"```python\ndef main():\n n, a, b, t = list(map(int, input().split()))\n a1 = a + 1\n b += a1\n l, res = [b if c == \"w\" else a1 for c in input()], []\n l[0] = x = l[0] - a\n if t <= x:\n print(int(t == x))\n return\n f = res.append\n for dr in 0, 1:\n if dr:\n ... | [{"type": "stdin_stdout", "input": "4 2 3 10\nwwhw\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 2 4 13\nhhwhh\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "5 2 4 1000\nhhwhh\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "3 1 100 10\nwhw\n", "output": "0\n"}, {"type": "stdin_stdout", "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Vasya's telephone contains n photos. Photo number 1 is cur... | [{"type": "stdin_stdout", "input": "4 2 3 10\nwwhw\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 2 4 13\nhhwhh\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 2 4 1000\nhhwhh\n", "output": "5\n", "metadata": {"func_name": null}}, ... | livecodebench | deepcoder_38 | 38 |
Solve the following coding problem using the programming language python:
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e.... | [
"```python\nn = int(input())\narr = []\nfor i in range(n):\n l,r = map(int, input().split())\n arr.append([l,r])\n \nlts = []\nfor i in range(n):\n if arr[i][0] == 0:\n l = i\n j = i\n while arr[j][1] != 0:\n j = arr[j][1] - 1\n r = j\n lts.append([l,r])\n\n... | [{"type": "stdin_stdout", "input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0\n", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0\n"}, {"type": "stdin_stdout", "input": "2\n2 0\n0 1\n", "output": "2 0\n0 1\n"}, {"type": "stdin_stdout", "input": "1\n0 0\n", "output": "0 0\n"}, {"type": "stdin_stdout", "input": "4\n0 2\n1 0\n0 4... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Doubly linked list is one of the fundamental data structur... | [{"type": "stdin_stdout", "input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0\n", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 0\n0 1\n", "output": "2 0\n0 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n0 0\n", "outp... | livecodebench | deepcoder_39 | 39 |
Solve the following coding problem using the programming language python:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There'... | [
"```python\nn, m = map(int, input().split())\np, d = [0] * (n + 2), [0] * (n + 2)\nfor i in range(m):\n l, r, x = map(int, input().split())\n while l < x:\n if d[l]:\n k = d[l]\n d[l] = x - l\n l += k\n else:\n d[l], p[l] = x - l, x\n l += 1... | [{"type": "stdin_stdout", "input": "4 3\n1 2 1\n1 3 3\n1 4 4\n", "output": "3 1 4 0 "}, {"type": "stdin_stdout", "input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n", "output": "0 8 4 6 4 8 6 1 "}, {"type": "stdin_stdout", "input": "2 1\n1 2 1\n", "output": "0 1 "}, {"type": "stdin_stdout", "input": "2 1\n1 2 2\n", "output": "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Hooray! Berl II, the king of Berland is making a knight to... | [{"type": "stdin_stdout", "input": "4 3\n1 2 1\n1 3 3\n1 4 4\n", "output": "3 1 4 0 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n", "output": "0 8 4 6 4 8 6 1 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 1\n1 2 1\n", "output": "0 1... | livecodebench | deepcoder_40 | 40 |
Solve the following coding problem using the programming language python:
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, h... | [
"```python\ndef main():\n n, k = map(int, input().split())\n a, b, c, d = (list(map(int, input().split())) for _ in 'abcd')\n ss, tt, n2, res = [*b, *c[::-1]], [*a, *d[::-1]], n * 2, []\n yx = [*[(2, i + 1) for i in range(n)], *[(3, i) for i in range(n, 0, -1)]]\n\n def park():\n for i, s, t, ... | [{"type": "stdin_stdout", "input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n2\n1\n2\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n1\n2\n2\n", "output": "2\n1 1 1\n2 4 1\n"}, {"type": "stdin_std... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Allen dreams of one day owning a enormous fleet of electri... | [{"type": "stdin_stdout", "input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 2\n1\n2\n1\n2\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 2\n... | livecodebench | deepcoder_41 | 41 |
Solve the following coding problem using the programming language python:
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekoland, each person has c_{i} coins. Each day, Robin Hood will ta... | [
"```python\nimport sys\n\nn, k = map(int, sys.stdin.readline().split())\nnums = list(map(int, sys.stdin.readline().split()))\ntotal = sum(nums)\navg = int(total / n)\n\ndef check1(nums, target, K):\n for x in nums:\n if K < 0:\n return False\n if x < target:\n K -= target - x\... | [{"type": "stdin_stdout", "input": "4 1\n1 1 4 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 1\n2 2 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "10 20\n6 4 7 10 4 5 5 3 7 10\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
We all know the impressive story of Robin Hood. Robin Hood... | [{"type": "stdin_stdout", "input": "4 1\n1 1 4 2\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 1\n2 2 2\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 20\n6 4 7 10 4 5 5 3 7 10\n", "output": "1\n", "metadata": {"func_name": null... | livecodebench | deepcoder_42 | 42 |
Solve the following coding problem using the programming language python:
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.
Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will cons... | [
"```python\nimport sys\ndef calc(b0, b1, q):\n if q == 0:\n return b0 ^ b1\n if q == 1:\n return b0 | b1\n if q == 2:\n return b0 & b1\nn, m = list(map(int,sys.stdin.readline().split()))\narr1 = {}\nopt = ['XOR', 'OR', 'AND']\narr2 = []\nfor j in range(n):\n a, b = list(map(str,sys.... | [{"type": "stdin_stdout", "input": "3 3\na := 101\nb := 011\nc := ? XOR b\n", "output": "011\n100\n"}, {"type": "stdin_stdout", "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n", "output": "0\n0\n"}, {"type": "stdin_stdout", "input": "2 10\nb := 0100101101\na := ? XOR b\n", "output": "0100101... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Bob recently read about bitwise operations used in compute... | [{"type": "stdin_stdout", "input": "3 3\na := 101\nb := 011\nc := ? XOR b\n", "output": "011\n100\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n", "output": "0\n0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "i... | livecodebench | deepcoder_43 | 43 |
Solve the following coding problem using the programming language python:
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.
Metropolis airport is the main transport h... | [
"```python\nfrom heapq import heappush,heappop,heapify\nn,k=map(int,input().split())\n*l,=map(int,input().split())\nq=[(-l[i],i)for i in range(k)];heapify(q)\na=[0]*n\ns=0\nfor i in range(k,n):\n heappush(q,(-l[i],i))\n x,j=heappop(q)\n s-=x*(i-j)\n a[j]=i+1\nfor i in range(n,n+k):\n x,j=heappop(q)\n... | [{"type": "stdin_stdout", "input": "5 2\n4 2 1 10 2\n", "output": "20\n3 6 7 4 5 \n"}, {"type": "stdin_stdout", "input": "3 2\n3 1 2\n", "output": "11\n3 5 4 \n"}, {"type": "stdin_stdout", "input": "5 5\n5 5 9 100 3\n", "output": "321\n9 8 7 6 10 \n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n2 \n"},... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Helen works in Metropolis airport. She is responsible for ... | [{"type": "stdin_stdout", "input": "5 2\n4 2 1 10 2\n", "output": "20\n3 6 7 4 5 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 2\n3 1 2\n", "output": "11\n3 5 4 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 5\n5 5 9 100 3\n", "output": "321\n9 8 7 6 10 \n", "m... | livecodebench | deepcoder_44 | 44 |
Solve the following coding problem using the programming language python:
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute ... | [
"```python\nn, m = list(map(int, input().split()))\nused = [1] * 2 * n\nfor i in range(m):\n\tx, y = list(map(int, input().split()))\n\tused[x - 1] = used[n + y - 1] = 0\n\t\nif n % 2 and used[n // 2]:\n\tused[n // 2 + n] = 0\nres = sum(used)\nfor i in [0, n - 1, n, 2 * n - 1]:\n\tres -= used[i]\nprint(res)\n\n\n``... | [{"type": "stdin_stdout", "input": "3 1\n2 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 3\n3 1\n3 2\n3 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 1\n1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 3\n1 2\n2 1\n... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Gerald plays the following game. He has a checkered field ... | [{"type": "stdin_stdout", "input": "3 1\n2 2\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 0\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 3\n3 1\n3 2\n3 3\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_s... | livecodebench | deepcoder_45 | 45 |
Solve the following coding problem using the programming language python:
$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1 \leq i... | [
"```python\nn,m=map(int,input().split())\nb=list(map(int,input().split()))\ng=list(map(int,input().split()))\nif max(b)>min(g):\n print(-1)\nelse:\n maxi=0\n maxi2=0\n for guy in b:\n if guy>maxi:\n maxi2,maxi=maxi,guy\n elif guy>maxi2:\n maxi2=guy\n sumi=m*sum(b)+... | [{"type": "stdin_stdout", "input": "3 2\n1 2 1\n3 4\n", "output": "12"}, {"type": "stdin_stdout", "input": "2 2\n0 1\n1 0\n", "output": "-1"}, {"type": "stdin_stdout", "input": "2 3\n1 0\n1 1 2\n", "output": "4"}, {"type": "stdin_stdout", "input": "2 2\n0 0\n100000000 100000000\n", "output": "200000000"}, {"type": "std... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
$n$ boys and $m$ girls came to the party. Each boy present... | [{"type": "stdin_stdout", "input": "3 2\n1 2 1\n3 4\n", "output": "12", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n0 1\n1 0\n", "output": "-1", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 3\n1 0\n1 1 2\n", "output": "4", "metadata": {"func_name": null}}, {"type"... | livecodebench | deepcoder_46 | 46 |
Solve the following coding problem using the programming language python:
Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color c_{i}.
Now it's time for Timofey birthday, and his mother asked him to remov... | [
"```python\ndef main():\n n = int(input())\n edges = []\n for _ in range(n - 1):\n u, v = list(map(int, input().split()))\n u -= 1\n v -= 1\n edges.append((u, v))\n\n colors = list(map(int, input().split()))\n suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]... | [{"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "output": "YES\n2"}, {"type": "stdin_stdout", "input": "3\n1 2\n2 3\n1 2 3\n", "output": "YES\n2"}, {"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n1 2 1 2\n", "output": "NO"}, {"type": "stdin_stdout", "input": "3\n2 1\n2 3\n1 2 3\n", "output": "YES... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Each New Year Timofey and his friends cut down a tree of n... | [{"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "output": "YES\n2", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 2\n2 3\n1 2 3\n", "output": "YES\n2", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n1 2 1 2\n", "output": "NO", "metada... | livecodebench | deepcoder_47 | 47 |
Solve the following coding problem using the programming language python:
Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "d_{i} → t_{i}", that means "replace all digits d_{i} in string s with substrings equal to t_{i}". For examp... | [
"```python\nMOD = 10**9+7\n\ns = input()\nn = int(input())\nqs = [['',s]]+[input().split('->') for i in range(n)]\n\nds = {}\nfor i in range(10):\n ds[str(i)] = (10,i)\n\nfor i in range(n,-1,-1):\n out = 0\n mul = 1\n for d in qs[i][1]:\n out = (out * ds[d][0] + ds[d][1]) % MOD\n mul = (mu... | [{"type": "stdin_stdout", "input": "123123\n1\n2->00\n", "output": "10031003\n"}, {"type": "stdin_stdout", "input": "123123\n1\n3->\n", "output": "1212\n"}, {"type": "stdin_stdout", "input": "222\n2\n2->0\n0->7\n", "output": "777\n"}, {"type": "stdin_stdout", "input": "1000000008\n0\n", "output": "1\n"}, {"type": "stdi... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Andrew and Eugene are playing a game. Initially, Andrew ha... | [{"type": "stdin_stdout", "input": "123123\n1\n2->00\n", "output": "10031003\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "123123\n1\n3->\n", "output": "1212\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "222\n2\n2->0\n0->7\n", "output": "777\n", "metadata": {"func_n... | livecodebench | deepcoder_48 | 48 |
Solve the following coding problem using the programming language python:
You are given two binary strings $a$ and $b$ of the same length. You can perform the following two operations on the string $a$:
Swap any two bits at indices $i$ and $j$ respectively ($1 \le i, j \le n$), the cost of this operation is $|i - j... | [
"```python\n# \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 ... | [{"type": "stdin_stdout", "input": "3\n100\n001\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n0101\n0011\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "8\n10001001\n01101110\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1\n0\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given two binary strings $a$ and $b$ of the same l... | [{"type": "stdin_stdout", "input": "3\n100\n001\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n0101\n0011\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8\n10001001\n01101110\n", "output": "4\n", "metadata": {"func_name": null}}, {... | livecodebench | deepcoder_49 | 49 |
Solve the following coding problem using the programming language python:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the mi... | [
"```python\n\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\n# so the ending sequence is b...ba...a\n\n# find length of ending sequence\n\nextra=0\nneed=0\nfor ch in input().strip():\n if ch=='a':\n need=(need*2+1)%1000000007\n else:\n extra=(extra+need)%1000000007\n\npri... | [{"type": "stdin_stdout", "input": "ab\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "aab\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "aaaaabaabababaaaaaba\n", "output": "17307\n"}, {"type": "stdin_stdout", "input": "abaabaaabbabaabab\n", "output": "1795\n"}, {"type": "stdin_stdout", "input": "abb... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
We have a string of letters 'a' and 'b'. We want to perfor... | [{"type": "stdin_stdout", "input": "ab\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "aab\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "aaaaabaabababaaaaaba\n", "output": "17307\n", "metadata": {"func_name": null}}, {"type": "stdin_s... | livecodebench | deepcoder_50 | 50 |
Solve the following coding problem using the programming language python:
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the... | [
"```python\nimport heapq\nn = int(input())\nd = list(map(int,input().split()))\npq = [-d[0]]\nheapq.heapify(pq)\nans = 0\nfor i in range(1,n):\n temp = i - d[i]\n heapq.heappush(pq,temp)\n if heapq.nsmallest(1,pq)[0] < temp:\n ans += temp - heapq.nsmallest(1,pq)[0]\n heapq.heappushpop(pq,temp... | [{"type": "stdin_stdout", "input": "7\n2 1 5 11 5 9 11\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "2\n1 1000\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n1000 1\n", "output": "1000\n"}, {"type": "stdin_stdout", "input": "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Sonya was unable to think of a story for this problem, so ... | [{"type": "stdin_stdout", "input": "7\n2 1 5 11 5 9 11\n", "output": "9\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n", "output": "12\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1 1000\n", "output": "0\n", "metadata": {"func_name": null}}, {"type... | livecodebench | deepcoder_51 | 51 |
Solve the following coding problem using the programming language python:
Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k... | [
"```python\ndef f(m):\n nonlocal dp, sdp\n l = 0\n for i in range(n):\n while l < n and v[l] < v[i] - m:\n l += 1\n if l - 1 > i - k:\n dp[i] = False\n else:\n dp[i] = (sdp[i - k + 1] != sdp[l - 1])\n sdp[i + 1] = sdp[i] + (1 if dp[i] else 0)\n ... | [{"type": "stdin_stdout", "input": "5 2\n50 110 130 40 120\n", "output": "20\n"}, {"type": "stdin_stdout", "input": "4 1\n2 3 4 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 1\n4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 2\n7 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 2... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Evlampiy has found one more cool application to process ph... | [{"type": "stdin_stdout", "input": "5 2\n50 110 130 40 120\n", "output": "20\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1\n2 3 4 1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 1\n4\n", "output": "0\n", "metadata": {"func_name": null}}, {"typ... | livecodebench | deepcoder_52 | 52 |
Solve the following coding problem using the programming language python:
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows... | [
"```python\nrd = lambda: list(map(int, input().split()))\n\ndef root(x):\n if f[x]!=x: f[x] = root(f[x])\n return f[x]\n\nn, m = rd()\nN = list(range(n))\nf = list(N)\nlang = [0]*n\nfor i in N: lang[i] = set(rd()[1:])\nfor i in N:\n for j in N[:i]:\n rj = root(j)\n if lang[rj].intersection(lang[i]):\n ... | [{"type": "stdin_stdout", "input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2 2\n1 2\n0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 2\n0\n0\n", ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
The "BerCorp" company has got n employees. These employees... | [{"type": "stdin_stdout", "input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n1 2\n0\n", "... | livecodebench | deepcoder_53 | 53 |
Solve the following coding problem using the programming language python:
3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl fro... | [
"```python\nimport sys\nreadline = sys.stdin.readline\n\nN, Q = list(map(int, readline().split()))\nstate = [[False]*(N+2) for _ in range(2)]\n\ncnt = 0\n\nAns = [None]*Q\nfor qu in range(Q):\n r, c = list(map(int, readline().split()))\n r -= 1\n c -= 1\n state[r][c] = not state[r][c]\n res = state[r... | [{"type": "stdin_stdout", "input": "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "output": "Yes\nNo\nNo\nNo\nYes\n"}, {"type": "stdin_stdout", "input": "2 2\n2 1\n1 2\n", "output": "Yes\nNo\n"}, {"type": "stdin_stdout", "input": "2 4\n2 1\n1 2\n1 2\n1 2\n", "output": "Yes\nNo\nYes\nNo\n"}, {"type": "stdin_stdout", "input": "4 1\n1... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is d... | [{"type": "stdin_stdout", "input": "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "output": "Yes\nNo\nNo\nNo\nYes\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n2 1\n1 2\n", "output": "Yes\nNo\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 4\n2 1\n1 2\n1 2\n1 2\n", "output"... | livecodebench | deepcoder_54 | 54 |
Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka... | [
"```python\nn, k = [int(c) for c in input().split()]\na = []\nfor i in range(k):\n ak = [int(c) for c in input().split()]\n a.append(ak[1:])\n\ntotal = k - 1\n\nfor ak in a:\n if ak[0] == 1:\n j = 1\n while j <= len(ak) - 1:\n if ak[j] != ak[j-1] + 1:\n break\n ... | [{"type": "stdin_stdout", "input": "3 2\n2 1 2\n1 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "1 1\n1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 2\n1 2\n2 1 3\n", "output": "3\n"}, {"type": "stdin_stdout... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-famous detective. He is n... | [{"type": "stdin_stdout", "input": "3 2\n2 1 2\n1 3\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n", "output": "10\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 1\n1 1\n", "output": "0\n", "metadata": {"func_name": null... | livecodebench | deepcoder_55 | 55 |
Solve the following coding problem using the programming language python:
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and mod... | [
"```python\nimport os\nimport random\nimport sys\nfrom typing import List, Dict\n\n\nclass Int:\n def __init__(self, val):\n self.val = val\n\n def get(self):\n return self.val + 111\n\nclass Unique:\n def __init__(self):\n self.s = set()\n\n def add(self, val : int):\n self.... | [{"type": "stdin_stdout", "input": "6\n0 1 3 7 15 31\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "2\n73 37\n", "output": "36\n"}, {"type": "stdin_stdout", "input": "2\n0 1000000000\n", "output": "1000000000\n"}, {"type": "stdin_stdout", "input": "8\n729541013 135019377 88372488 319157478 682081360 558614617... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
In the official contest this problem has a different state... | [{"type": "stdin_stdout", "input": "6\n0 1 3 7 15 31\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n73 37\n", "output": "36\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n0 1000000000\n", "output": "1000000000\n", "metadata": {"func_name": null}... | livecodebench | deepcoder_56 | 56 |
Solve the following coding problem using the programming language python:
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will ca... | [
"```python\nn = int(input())\nt = [list(map(int, input().split())) for q in range(n)]\nt[0][0] = 0\nn += 1\nu = [-1e7] * n\nv = [0] * n\nfor i, (j, a) in list(enumerate(t, 1))[::-1]:\n u[i] = max(u[i], v[i] + a)\n v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])\nprint(u[1])\n```"
] | [{"type": "stdin_stdout", "input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n", "output": "17\n"}, {"type": "stdin_stdout", "input": "1\n-1 42\n", "output": "42\n"}, {"type": "stdin_stdout", "input": "2\n-1 3\n1 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3\n-1 3\n1 1\n1 2\n", "output": "6\n"}, {"type": "s... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
One Big Software Company has n employees numbered from 1 t... | [{"type": "stdin_stdout", "input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n", "output": "17\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n-1 42\n", "output": "42\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n-1 3\n1 2\n", "output": "3\n", "metadata": {"func_na... | livecodebench | deepcoder_57 | 57 |
Solve the following coding problem using the programming language python:
The Fair Nut is going to travel to the Tree Country, in which there are $n$ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car ... | [
"```python\nimport sys\nreadline = sys.stdin.readline\n\nfrom collections import Counter \n\ndef getpar(Edge, p):\n N = len(Edge)\n par = [0]*N\n par[0] = -1\n par[p] -1\n stack = [p]\n visited = set([p])\n while stack:\n vn = stack.pop()\n for vf in Edge[vn]:\n if vf ... | [{"type": "stdin_stdout", "input": "3\n1 3 3\n1 2 2\n1 3 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "1\n42\n", "output": "42\n"}, {"type": "stdin_stdout", "input": "10\n11 43 11 96 18 53 25 89 31 41\n2 4 41... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
The Fair Nut is going to travel to the Tree Country, in wh... | [{"type": "stdin_stdout", "input": "3\n1 3 3\n1 2 2\n1 3 2\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n42\n", "output": "42\n", "metadata":... | livecodebench | deepcoder_58 | 58 |
Solve the following coding problem using the programming language python:
You are given an array $a$ of $n$ integers.
You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where ... | [
"```python\nn=int(input())\nL=list(map(int,input().split()))\nif n==1:\n print(1,1)\n print(0)\n print(1,1)\n print(0)\n print(1,1)\n print(-L[0])\nelse:\n print(1,n-1)\n for i in range(n-1):print(L[i]*(n-1),end=' ')\n print()\n print(n,n)\n print(-L[n-1])\n print(1,n)\n for i... | [{"type": "stdin_stdout", "input": "4\n1 3 2 4\n", "output": "1 4\n-4 -12 -8 0\n1 3\n3 9 6 \n4 4\n-4\n"}, {"type": "stdin_stdout", "input": "1\n34688642\n", "output": "1 1\n-34688642\n1 1\n0\n1 1\n0\n"}, {"type": "stdin_stdout", "input": "2\n-492673762 -496405053\n", "output": "1 2\n985347524 0\n1 1\n-492673762 \n2 2\n... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given an array $a$ of $n$ integers.
You want to m... | [{"type": "stdin_stdout", "input": "4\n1 3 2 4\n", "output": "1 4\n-4 -12 -8 0\n1 3\n3 9 6 \n4 4\n-4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n34688642\n", "output": "1 1\n-34688642\n1 1\n0\n1 1\n0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n-492673762 -... | livecodebench | deepcoder_59 | 59 |
Solve the following coding problem using the programming language python:
Karen has just arrived at school, and she has a math test today! [Image]
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. S... | [
"```python\n#!/usr/bin/env pypy3\n\nimport math\n\ndef make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7):\n fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)\n fact[0] = 1\n for i in range(max_n):\n fact[i + 1] = fact[i] * (i + 1) % mod\n\n inv_fact[-1] = pow(fact[-1], mod - 2, mod)\n for i... | [{"type": "stdin_stdout", "input": "5\n3 6 9 12 15\n", "output": "36\n"}, {"type": "stdin_stdout", "input": "4\n3 7 5 2\n", "output": "1000000006\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Karen has just arrived at school, and she has a math test ... | [{"type": "stdin_stdout", "input": "5\n3 6 9 12 15\n", "output": "36\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n3 7 5 2\n", "output": "1000000006\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type":... | livecodebench | deepcoder_60 | 60 |
Solve the following coding problem using the programming language python:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (x_{i}, y_{i}).
They need to arrange a plan, but... | [
"```python\nfrom collections import Counter\nn = int(input())\npoints = Counter([tuple(map(int, input().split(' '))) for i in range(n)])\n\nx, y = Counter([k for k, v in points.elements()]), Counter([v for k, v in points.elements()])\n\nans = sum([v*(v-1)//2 for k, v in list(x.items())])+sum([v*(v-1)//2 for k, v in... | [{"type": "stdin_stdout", "input": "3\n1 1\n7 5\n1 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n", "output": "11\n"}, {"type": "stdin_stdout", "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55\n", "output": "33\n"}, {"type": "stdin_std... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Watchmen are in a danger and Doctor Manhattan together wit... | [{"type": "stdin_stdout", "input": "3\n1 1\n7 5\n1 5\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n", "output": "11\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 4... | livecodebench | deepcoder_61 | 61 |
Solve the following coding problem using the programming language python:
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door mus... | [
"```python\nfrom sys import*\n#\ndef check(u, d, l, r):\n used = [pointsx[i][1] for i in range(l)]\n used += [pointsx[-1 - i][1] for i in range(r)]\n used += [pointsy[i][1] for i in range(u)]\n used += [pointsy[-1 - i][1] for i in range(d)]\n if len(set(used)) > k:\n return DOHERA\n dx = po... | [{"type": "stdin_stdout", "input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "output": "64\n"}, {"type": "stdin_stdout", "input": "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n", "output": "249999999000000001\n"}, {"typ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Edo has got a collection of n refrigerator magnets!
He de... | [{"type": "stdin_stdout", "input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "output": "64\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 0\n1 1 2 2\n1 1 1000000000... | livecodebench | deepcoder_62 | 62 |
Solve the following coding problem using the programming language python:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x_1, x_2, ..., x_{k} (k > 1) is such maximum element x_{j}, that the following inequality holds: $x_{j} \neq \opera... | [
"```python\ndef maximum_xor_secondary(sequence):\n stack, answer = [], 0\n for x in sequence:\n while stack:\n answer = max(answer, stack[-1] ^ x)\n if stack[-1] > x:\n break\n else:\n stack.pop()\n stack.append(x)\n\n return answ... | [{"type": "stdin_stdout", "input": "5\n5 2 1 4 3\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "5\n9 8 3 5 7\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\n", "output": "128869996\n"}, {"type": "stdin_stdou... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Bike loves looking for the second maximum element in the s... | [{"type": "stdin_stdout", "input": "5\n5 2 1 4 3\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n9 8 3 5 7\n", "output": "15\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 178... | livecodebench | deepcoder_63 | 63 |
Solve the following coding problem using the programming language python:
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be w_{i}, then 0 < w_1 ≤ w_2 ≤ ... ≤... | [
"```python\nrd = lambda: list(map(int, input().split()))\n\nrd()\na = sorted(rd(), reverse=True)\nb = sorted(rd(), reverse=True)\nif len(a) > len(b): print(\"YES\"); return\nfor i in range(len(a)):\n if a[i] > b[i]: print(\"YES\"); return\nprint(\"NO\")\n```"
] | [{"type": "stdin_stdout", "input": "3 3 3\n2 2 2\n1 1 3\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5 5 10\n8 2 8 5 9\n9 1 7 5 1\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "7 7 10\n8 2 8 10 6 9 10\n2 4 ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
It is known that there are k fish species in the polar oce... | [{"type": "stdin_stdout", "input": "3 3 3\n2 2 2\n1 1 3\n", "output": "YES\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 5 10\n8 2 8 5 9\n9 1 7 5 1\n", "output": "YES\n",... | livecodebench | deepcoder_64 | 64 |
Solve the following coding problem using the programming language python:
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors... | [
"```python\nn = int(input())\np = [tuple(map(int, input().split())) for i in range(n)]\n\ndef d(a, b):\n return (a[0]-b[0], a[1]-b[1], a[2]-b[2], a[3]-b[3], a[4]-b[4])\n\ndef m(a, b):\n t = 0\n for i in range(5):\n t += a[i] * b[i]\n return t\n\ngood_points = []\nfor i in range(n):\n good = Tr... | [{"type": "stdin_stdout", "input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n", "output": "1\n1\n"}, {"type": "stdin_stdout", "input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n0 0 0 0 0\n", "output": "1\n1\n"}, {"type": "stdin_stdout", "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given set of n points in 5-dimensional space. The ... | [{"type": "stdin_stdout", "input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n", "output": "1\n1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input":... | livecodebench | deepcoder_65 | 65 |
Solve the following coding problem using the programming language python:
Little X has n distinct integers: p_1, p_2, ..., p_{n}. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number a - x must also belong to set A. If number ... | [
"```python\nfrom collections import defaultdict\n\ndef solve(n, a, b, xs):\n group = [None] * n\n id_ = {x: i for i, x in enumerate(xs)}\n if a == b:\n for x in xs:\n if a - x not in id_:\n return False\n group = [0] * n\n else:\n for i, x in enumerate(xs):... | [{"type": "stdin_stdout", "input": "4 5 9\n2 3 4 5\n", "output": "YES\n0 0 1 1\n"}, {"type": "stdin_stdout", "input": "3 3 4\n1 2 4\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 127... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Little X has n distinct integers: p_1, p_2, ..., p_{n}. He... | [{"type": "stdin_stdout", "input": "4 5 9\n2 3 4 5\n", "output": "YES\n0 0 1 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3 4\n1 2 4\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 37... | livecodebench | deepcoder_66 | 66 |
Solve the following coding problem using the programming language python:
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. Y... | [
"```python\nq = int(input())\n\n\n\ndef full_way(u):\n res = set()\n\n while u >= 1:\n res.add(u)\n u //= 2\n\n return res\n\n\ndef get_way(u, v):\n res1 = full_way(u)\n res2 = full_way(v)\n\n m = max(res1 & res2)\n\n res = set()\n for x in res1 | res2:\n if x > m:\n ... | [{"type": "stdin_stdout", "input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4\n", "output": "94\n0\n32\n"}, {"type": "stdin_stdout", "input": "1\n2 666077344481199252 881371880336470888\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "10\n1 1 63669439577744021 396980128\n1 2582240553355225 63... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Barney lives in NYC. NYC has infinite number of intersecti... | [{"type": "stdin_stdout", "input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4\n", "output": "94\n0\n32\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n2 666077344481199252 881371880336470888\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "i... | livecodebench | deepcoder_67 | 67 |
Solve the following coding problem using the programming language python:
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer tak... | [
"```python\nimport sys\n\nn_discounts = int(sys.stdin.readline())\ndiscount_values = [int(x) for x in sys.stdin.readline().split()]\nn_items = int(sys.stdin.readline())\nitem_values = [int(x) for x in sys.stdin.readline().split()]\n\nmin_discount_req = 10000000\nfor discount_value in discount_values:\n min_disco... | [{"type": "stdin_stdout", "input": "1\n2\n4\n50 50 100 100\n", "output": "200\n"}, {"type": "stdin_stdout", "input": "2\n2 3\n5\n50 50 50 50 50\n", "output": "150\n"}, {"type": "stdin_stdout", "input": "1\n1\n7\n1 1 1 1 1 1 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "60\n7 4 20 15 17 6 2 2 3 18 13 14 16 ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Maxim always goes to the supermarket on Sundays. Today the... | [{"type": "stdin_stdout", "input": "1\n2\n4\n50 50 100 100\n", "output": "200\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 3\n5\n50 50 50 50 50\n", "output": "150\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1\n7\n1 1 1 1 1 1 1\n", "output": "3\n", "metada... | livecodebench | deepcoder_68 | 68 |
Solve the following coding problem using the programming language python:
Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th num... | [
"```python\nfrom math import pi\nfrom cmath import exp\ndef fft(a, lgN, rot=1): # rot=-1 for ifft\n N = 1<<lgN\n assert len(a)==N\n rev = [0]*N\n for i in range(N):\n rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1)\n A = [a[rev[i]] for i in range(N)]\n h = 1\n while h<N:\n w_m = exp((0+1j) * rot * (pi / h))\n ... | [{"type": "stdin_stdout", "input": "5 3\n1 2 3 4 5\n", "output": "6 5 4 0 0 0 "}, {"type": "stdin_stdout", "input": "2 6\n-5 9\n", "output": "1 2 0 "}, {"type": "stdin_stdout", "input": "6 99\n-1 -1 -1 -1 -1 -1\n", "output": "0 6 5 4 3 2 1 "}, {"type": "stdin_stdout", "input": "5 -2\n-1 -1 -4 -5 1\n", "output": "4 5 6 ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Nikita likes tasks on order statistics, for example, he ca... | [{"type": "stdin_stdout", "input": "5 3\n1 2 3 4 5\n", "output": "6 5 4 0 0 0 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 6\n-5 9\n", "output": "1 2 0 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 99\n-1 -1 -1 -1 -1 -1\n", "output": "0 6 5 4 3 2 1 ", "metadata":... | livecodebench | deepcoder_69 | 69 |
Solve the following coding problem using the programming language python:
Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2... | [
"```python\nMOD = 998244353\n\nn = int(input())\n\na = list(map(int, input().split()))\ntot = sum(a)\n\ndef inv(x):\n return pow(x, MOD - 2, MOD)\n\nl = [0, pow(n, tot, MOD) - 1]\n\nfor i in range(1, tot):\n aC = i\n cC = (n - 1) * (tot - i)\n curr = (aC + cC) * l[-1]\n curr -= tot * (n - 1)\n cur... | [{"type": "stdin_stdout", "input": "2\n1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "5\n0 0 0 0 35\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5\n8 4 2 0 1\n", "output": "801604029\n"}, {"type": "stdin_stdout", "input": "5\n2434... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Slime and his $n$ friends are at a party. Slime has design... | [{"type": "stdin_stdout", "input": "2\n1 1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1 2\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n0 0 0 0 35\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdou... | livecodebench | deepcoder_70 | 70 |
Solve the following coding problem using the programming language python:
Levko loves array a_1, a_2, ... , a_{n}, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
Increase all elements fro... | [
"```python\nn, m = map(int, input().split())\na = [10**9 for _ in range(n)]\nextra = [0 for _ in range(n)]\nquery = list()\nfor _ in range(m):\n t, l, r, x = map(int, input().split())\n l -= 1\n r -= 1\n query.append((t, l, r, x))\n if t == 1:\n for j in range(l, r + 1):\n ... | [{"type": "stdin_stdout", "input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "output": "YES\n8 7 4 7 \n"}, {"type": "stdin_stdout", "input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n", "output": "YES... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Levko loves array a_1, a_2, ... , a_{n}, consisting of int... | [{"type": "stdin_stdout", "input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "output": "YES\n8 7 4 7 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "i... | livecodebench | deepcoder_71 | 71 |
Solve the following coding problem using the programming language python:
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is dir... | [
"```python\nimport heapq\n\ndef coor_neighbor(coor, dxs, dys):\n x, y = coor\n for dx in dxs:\n for dy in dys:\n yield x + dx, y + dy\n\n\ndef coor_bottoms(coor):\n return coor_neighbor(coor, (-1, 0, 1), (-1, ))\n\n\ndef coor_tops(coor):\n return coor_neighbor(coor, (-1, 0, 1), (1, ))\... | [{"type": "stdin_stdout", "input": "3\n2 1\n1 0\n0 1\n", "output": "19\n"}, {"type": "stdin_stdout", "input": "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "output": "2930\n"}, {"type": "stdin_stdout", "input": "10\n-1 2\n-3 0\n5 5\n4 4\n-2 1\n1 1\n3 3\n2 2\n0 0\n-1000000000 0\n", "output": "41236677\n"}, {"type": "stdin_stdout", "i... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Once Vasya and Petya assembled a figure of m cubes, each o... | [{"type": "stdin_stdout", "input": "3\n2 1\n1 0\n0 1\n", "output": "19\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "output": "2930\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n-1 2\n-3 0\n5 5\n4 4\n-2 1\n1 1\n3 3\n2 2\n0 0\n-100... | livecodebench | deepcoder_72 | 72 |
Solve the following coding problem using the programming language python:
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $n$ elements. The $i$-th element is $a_i$ ($i$ = $1, 2, \ldots, n$). He gradually takes the first two leftmost elements f... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\n\nfrom collections import deque\nN, Q = list(map(int, input().split()))\nque = deque([int(a) for a in input().split()])\nma = max(que)\n\nX = []\nk = -1\nc = 0\nwhile c <= k+N+5:\n a = deque.popleft(que)\n b = deque.popleft(que)\n \n X.append((a, b))... | [{"type": "stdin_stdout", "input": "5 3\n1 2 3 4 5\n1\n2\n10\n", "output": "1 2\n2 3\n5 2\n"}, {"type": "stdin_stdout", "input": "2 0\n0 0\n", "output": ""}, {"type": "stdin_stdout", "input": "2 1\n1 2\n1\n", "output": "1 2\n"}, {"type": "stdin_stdout", "input": "3 2\n1000000 999999 999998\n98\n999999999999\n", "output... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Recently, on the course of algorithms and data structures,... | [{"type": "stdin_stdout", "input": "5 3\n1 2 3 4 5\n1\n2\n10\n", "output": "1 2\n2 3\n5 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 0\n0 0\n", "output": "", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 1\n1 2\n1\n", "output": "1 2\n", "metadata": {"func_name": ... | livecodebench | deepcoder_73 | 73 |
Solve the following coding problem using the programming language python:
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights w_{i} kilograms.
Va... | [
"```python\n3\n\nimport sys\n\nn, l, r, ql, qr = list(map(int, sys.stdin.readline().strip().split()))\nw = [int(x) for x in sys.stdin.readline().strip().split()]\n\ns = [0]\nfor i in range(0, n):\n s.append(s[-1] + w[i])\n\ndef cost(left):\n right = n - left\n diff = left - right\n bonus = 0\n if dif... | [{"type": "stdin_stdout", "input": "3 4 4 19 1\n42 3 99\n", "output": "576\n"}, {"type": "stdin_stdout", "input": "4 7 2 3 9\n1 2 3 4\n", "output": "34\n"}, {"type": "stdin_stdout", "input": "2 100 100 10000 10000\n100 100\n", "output": "20000\n"}, {"type": "stdin_stdout", "input": "2 3 4 5 6\n1 2\n", "output": "11\n"}... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Vasya has n items lying in a line. The items are consecuti... | [{"type": "stdin_stdout", "input": "3 4 4 19 1\n42 3 99\n", "output": "576\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 7 2 3 9\n1 2 3 4\n", "output": "34\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 100 100 10000 10000\n100 100\n", "output": "20000\n", "metad... | livecodebench | deepcoder_74 | 74 |
Solve the following coding problem using the programming language python:
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color c_{i}. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is... | [
"```python\nn = int(input())\nC = list(map(int, input().split()))\n\ndp = [[0]*n for _ in range(n)]\nfor i in range(n) :\n dp[i][i] = 1\n\nfor i in range(n-2, -1, -1) :\n for j in range(i+1, n) :\n dp[i][j] = 1 + dp[i+1][j]\n if C[i] == C[i+1] : dp[i][j] = min( dp[i][j], 1 + (dp[i+2][j] if i+2 <... | [{"type": "stdin_stdout", "input": "3\n1 2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "7\n1 4 4 2 3 2 1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n1 1\n", "outp... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Genos recently installed the game Zuma on his phone. In Zu... | [{"type": "stdin_stdout", "input": "3\n1 2 1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1 4 4 2 3 2 1\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdi... | livecodebench | deepcoder_75 | 75 |
Solve the following coding problem using the programming language python:
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or... | [
"```python\nfrom operator import __or__, __and__, __xor__\nfrom sys import stdin, stdout\nn, b, c = int(stdin.readline()), 0, 1023\nm = {'|': __or__, '&': __and__, '^': __xor__}\nfor i in range(n):\n t, v = [i for i in stdin.readline().split()]\n b = m[t](b, int(v))\n c = m[t](c, int(v))\nx, o, a = 0, 0, 1... | [{"type": "stdin_stdout", "input": "3\n| 3\n^ 2\n| 1\n", "output": "2\n| 3\n^ 2\n"}, {"type": "stdin_stdout", "input": "3\n& 1\n& 3\n& 5\n", "output": "1\n& 1\n"}, {"type": "stdin_stdout", "input": "3\n^ 1\n^ 2\n^ 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n| 999\n^ 689\n", "output": "2\n| 999\n^ 689\... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Petya learned a new programming language CALPAS. A program... | [{"type": "stdin_stdout", "input": "3\n| 3\n^ 2\n| 1\n", "output": "2\n| 3\n^ 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n& 1\n& 3\n& 5\n", "output": "1\n& 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n^ 1\n^ 2\n^ 3\n", "output": "0\n", "metadata": {"fun... | livecodebench | deepcoder_76 | 76 |
Solve the following coding problem using the programming language python:
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a t... | [
"```python\nfrom itertools import combinations_with_replacement \nfrom collections import deque\n\n#sys.stdin = open(\"input_py.txt\",\"r\")\n\nn, m = map(int, input().split())\nG = [ [] for i in range(n)]\n\nfor i in range(m):\n x, y = map(int, input().split())\n x-=1; y-=1\n G[x].append(y)\n G[y].appe... | [{"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input":... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
In some country there are exactly n cities and m bidirecti... | [{"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3... | livecodebench | deepcoder_77 | 77 |
Solve the following coding problem using the programming language python:
Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ ... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\ns = input()\n\nM = int(input())\n\n\ndef next_pow_2(n):\n p = 1\n while p < n:\n p <<= 1\n return p\n\n\ndef represented_range(node, size):\n l = node\n r = node\n while l < size:\n l = 2*l\n r = 2*r + 1\n return l-size,... | [{"type": "stdin_stdout", "input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n", "output": "0\n0\n2\n10\n4\n6\n6\n"}, {"type": "stdin_stdout", "input": "(((((()((((((((((()((()(((((\n1\n8 15\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in... | [{"type": "stdin_stdout", "input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n", "output": "0\n0\n2\n10\n4\n6\n6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "(((((()((((((((((()((()(((((\n1\n8 15\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "i... | livecodebench | deepcoder_78 | 78 |
Solve the following coding problem using the programming language python:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konsta... | [
"```python\nn = int(input())\nif n % 2:\n print(\"contest\")\nelse:\n print(\"home\")\n```"
] | [{"type": "stdin_stdout", "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n", "output": "home\n"}, {"type": "stdin_stdout", "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n", "output": "contest\n"}, {"type": "stdin_stdout", "input": "1\nESJ\nESJ->TSJ\n", "output": "contest\n"}, {"type": "stdin_stdout", "input"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
There are literally dozens of snooker competitions held ea... | [{"type": "stdin_stdout", "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n", "output": "home\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n", "output": "contest\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\nESJ\nESJ... | livecodebench | deepcoder_79 | 79 |
Solve the following coding problem using the programming language python:
Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into o... | [
"```python\nn = int(input())\nfrom bisect import bisect_left\n\n\na = list(map(int, input().split()))\nss = []\nms = []\nfor i in range(n):\n k = a[i]\n ind = bisect_left(ms, -k)\n if ind == len(ms):\n ss.append([])\n ms.append(0)\n ss[ind].append(k)\n ms[ind] = -k\n\nfor s in ss:\n ... | [{"type": "stdin_stdout", "input": "5\n1 3 2 5 4\n", "output": "1 3 5 \n2 4 \n"}, {"type": "stdin_stdout", "input": "4\n4 3 2 1\n", "output": "4 \n3 \n2 \n1 \n"}, {"type": "stdin_stdout", "input": "4\n10 30 50 101\n", "output": "10 30 50 101 \n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1 \n"}, {"type": ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Ivan has an array consisting of n different integers. He d... | [{"type": "stdin_stdout", "input": "5\n1 3 2 5 4\n", "output": "1 3 5 \n2 4 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n4 3 2 1\n", "output": "4 \n3 \n2 \n1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n10 30 50 101\n", "output": "10 30 50 101 \n", "metada... | livecodebench | deepcoder_80 | 80 |
Solve the following coding problem using the programming language python:
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately... | [
"```python\ndef main():\n import sys\n input = sys.stdin.readline\n \n n = int(input())\n arr = input()\n \n one = arr.count('n')\n zero = arr.count('z')\n \n ans = [1] * one + [0] * zero\n \n print(*ans)\n \n return 0\n\nmain()\n\n```"
] | [{"type": "stdin_stdout", "input": "4\nezor\n", "output": "0 \n"}, {"type": "stdin_stdout", "input": "10\nnznooeeoer\n", "output": "1 1 0 \n"}, {"type": "stdin_stdout", "input": "4\neorz\n", "output": "0 \n"}, {"type": "stdin_stdout", "input": "3\nnoe\n", "output": "1 \n"}, {"type": "stdin_stdout", "input": "40\noeerzz... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
When Serezha was three years old, he was given a set of ca... | [{"type": "stdin_stdout", "input": "4\nezor\n", "output": "0 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\nnznooeeoer\n", "output": "1 1 0 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\neorz\n", "output": "0 \n", "metadata": {"func_name": null}}, {"type": "s... | livecodebench | deepcoder_81 | 81 |
Solve the following coding problem using the programming language python:
DZY loves planting, and he enjoys solving tree problems.
DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge ... | [
"```python\nn = int(input())\nedges = [[int(x) for x in input().split()] for i in range(n-1)]\nedges = sorted(edges)\nuse_count = [0]+[int(input()) for i in range(n)]\nlo,hi = 0,10000\ndef getpar(par,u):\n if par[par[u]] == par[u]:\n return par[u]\n par[u] = getpar(par,par[u])\n return par[u]\ndef u... | [{"type": "stdin_stdout", "input": "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 3 4465\n9 7 8886\n10 3 9362\n2\n5\... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
DZY loves planting, and he enjoys solving tree problems.
... | [{"type": "stdin_stdout", "input": "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n2 1 8760\n3 1 3705\n4 1 1862\n... | livecodebench | deepcoder_82 | 82 |
Solve the following coding problem using the programming language python:
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the numbe... | [
"```python\n\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,m=list(map(int,input().split()))\n\nparty=[[] for _ in range(m+5)]\npc=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1])\nchoose=[0]*n\n\nfor i in range(n):\n party[pc[i][0]].append(i)\n\n\n\nwant=10... | [{"type": "stdin_stdout", "input": "1 2\n1 100\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n", "output": "500\n"}, {"type": "stdin_stdout", "input": "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n", "output": "600\n"}, {"type": "stdin_stdout", "input": "5 5\n1 3\n1 6\n5 4\n... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
As you know, majority of students and teachers of Summer I... | [{"type": "stdin_stdout", "input": "1 2\n1 100\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n", "output": "500\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n", "output":... | livecodebench | deepcoder_83 | 83 |
Solve the following coding problem using the programming language python:
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}.
Your task is to find such permutation ... | [
"```python\n3\n\nimport sys\n\ndef __starting_point():\n \n n, k = list(map(int, sys.stdin.readline().split()))\n l = []\n i = 1\n j = k + 1\n while i <= j:\n l.append(str(i))\n i += 1\n if j > i:\n l.append(str(j))\n j -= 1\n for i in range(k+2, n+1):... | [{"type": "stdin_stdout", "input": "3 2\n", "output": "1 3 2\n"}, {"type": "stdin_stdout", "input": "3 1\n", "output": "1 2 3\n"}, {"type": "stdin_stdout", "input": "5 2\n", "output": "1 3 2 4 5\n"}, {"type": "stdin_stdout", "input": "5 4\n", "output": "1 5 2 4 3\n"}, {"type": "stdin_stdout", "input": "10 4\n", "output... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Permutation p is an ordered set of integers p_1, p_2, ... | [{"type": "stdin_stdout", "input": "3 2\n", "output": "1 3 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 1\n", "output": "1 2 3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 2\n", "output": "1 3 2 4 5\n", "metadata": {"func_name": null}}, {"type": "stdin_stdou... | livecodebench | deepcoder_84 | 84 |
Solve the following coding problem using the programming language python:
There are $n$ water tanks in a row, $i$-th of them contains $a_i$ liters of water. The tanks are numbered from $1$ to $n$ from left to right.
You can perform the following operation: choose some subsegment $[l, r]$ ($1\le l \le r \le n$), and r... | [
"```python\nn = int(input())\nl = list(map(int, input().split()))\n\nstack = []\nfor v in l:\n currVal = v\n currSize = 1\n div = v\n \n while stack:\n nex, nexS, nDiv = stack[-1]\n\n if div < nDiv:\n currSize += nexS\n currVal += nex\n stack.pop()\n\n ... | [{"type": "stdin_stdout", "input": "4\n7 5 5 7\n", "output": "5.666666667\n5.666666667\n5.666666667\n7.000000000\n"}, {"type": "stdin_stdout", "input": "5\n7 8 8 10 12\n", "output": "7.000000000\n8.000000000\n8.000000000\n10.000000000\n12.000000000\n"}, {"type": "stdin_stdout", "input": "10\n3 9 5 5 1 7 5 3 8 7\n", "ou... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
There are $n$ water tanks in a row, $i$-th of them contain... | [{"type": "stdin_stdout", "input": "4\n7 5 5 7\n", "output": "5.666666667\n5.666666667\n5.666666667\n7.000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n7 8 8 10 12\n", "output": "7.000000000\n8.000000000\n8.000000000\n10.000000000\n12.000000000\n", "metadata": {"func_name": null}}, ... | livecodebench | deepcoder_85 | 85 |
Solve the following coding problem using the programming language python:
Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.
It is an undirected weighted ... | [
"```python\nimport sys\ninput = lambda: sys.stdin.readline().rstrip()\n\nN, M = list(map(int, input().split()))\nD = [{} for _ in range(N)]\nfor _ in range(M):\n a, b = list(map(int, input().split()))\n a -= 1\n b -= 1\n D[a][b] = 1\n D[b][a] = 1\n\nL = [i-1 for i in range(N)]\nR = [i+1 for i in rang... | [{"type": "stdin_stdout", "input": "6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1 0\n", "output": "0\n"}, {"type": "stdin_std... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Ujan has a lot of useless stuff in his drawers, a consider... | [{"type": "stdin_stdout", "input": "6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 0\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 0\n", "output": "0\n", "metadata": {"f... | livecodebench | deepcoder_86 | 86 |
Solve the following coding problem using the programming language python:
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates... | [
"```python\n# \nimport collections, atexit, math, sys\nfrom functools import cmp_to_key\n#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )\n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\nimport bisect \ntry :\n #raise ModuleNotFoundError\n impor... | [{"type": "stdin_stdout", "input": "4\n4 1 3 2 3 2 1 3\n", "output": "1"}, {"type": "stdin_stdout", "input": "3\n5 8 5 5 7 5\n", "output": "0"}, {"type": "stdin_stdout", "input": "1\n553296794 23577639\n", "output": "0"}, {"type": "stdin_stdout", "input": "2\n100000001 95312501 97600001 1\n", "output": "228750000000000... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Pavel made a photo of his favourite stars in the sky. His ... | [{"type": "stdin_stdout", "input": "4\n4 1 3 2 3 2 1 3\n", "output": "1", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n5 8 5 5 7 5\n", "output": "0", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n553296794 23577639\n", "output": "0", "metadata": {"func_name": null}},... | livecodebench | deepcoder_87 | 87 |
Solve the following coding problem using the programming language python:
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Ups... | [
"```python\n\ndef main():\n s = input()\n l = len(s)\n \n pretty_count = 0\n for i in range(l):\n left_paren_count = 0\n right_paren_count = 0\n wild_count = 0\n for j in range(i, l):\n if s[j] == '(':\n left_paren_count += 1\n elif s[j... | [{"type": "stdin_stdout", "input": "((?))\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "??()??\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "?????)(???\n", "output": "21\n"}, {"type": "stdin_stdout", "input": "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))\n"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
As Will is stuck in the Upside Down, he can still communic... | [{"type": "stdin_stdout", "input": "((?))\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "??()??\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "?????)(???\n", "output": "21\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout",... | livecodebench | deepcoder_88 | 88 |
Solve the following coding problem using the programming language python:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two po... | [
"```python\nimport sys\n\ns1, s2 = input().split()\nn = int(input())\n\nfor _ in range(n):\n print(s1, s2)\n killed, new = input().split()\n if s1 == killed:\n s1 = new\n else:\n s2 = new\n\nprint(s1, s2)\n\n```"
] | [{"type": "stdin_stdout", "input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n"}, {"type": "stdin_stdout", "input": "icm codeforces\n1\ncodeforces technex\n", "output": "icm codeforces\nicm technex\n"}, {"ty... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Our beloved detective, Sherlock is currently trying to cat... | [{"type": "stdin_stdout", "input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "icm codeforces\n1\ncodeforces technex\n", "output": "icm ... | livecodebench | deepcoder_89 | 89 |
Solve the following coding problem using the programming language python:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2^{w}_{i} pounds. In each step, Duff can lift some of the remaining weights and throw them... | [
"```python\nn = int(input())\na = [int(x) for x in input().split()]\nl = [0] * (10**6 + 100)\nfor x in a:\n\tl[x] += 1\ncur = 0\nans = 0\nfor x in l:\n\tcur += x\n\tif cur % 2:\n\t\tans += 1\n\tcur //= 2\nprint(ans)\n\n```"
] | [{"type": "stdin_stdout", "input": "5\n1 1 2 3 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "4\n0 1 2 3\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "1\n120287\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2\n28288 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2\n95745 95... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Recently, Duff has been practicing weight lifting. As a ha... | [{"type": "stdin_stdout", "input": "5\n1 1 2 3 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n0 1 2 3\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n120287\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin... | livecodebench | deepcoder_90 | 90 |
Solve the following coding problem using the programming language python:
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i} — ... | [
"```python\nimport itertools\nimport bisect\n\nn, A, cf, cm, m = [int(x) for x in input().split()]\nskills = [int(x) for x in input().split()]\nsorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))\nbottom_lift = [0 for i in range(n)]\nfor i in range(1, n):\n bottom_lift[i] = bottom_lift[i-1] + i * ... | [{"type": "stdin_stdout", "input": "3 5 10 1 5\n1 3 1\n", "output": "12\n2 5 2 \n"}, {"type": "stdin_stdout", "input": "3 5 10 1 339\n1 3 1\n", "output": "35\n5 5 5 \n"}, {"type": "stdin_stdout", "input": "2 6 0 1 4\n5 1\n", "output": "5\n5 5 \n"}, {"type": "stdin_stdout", "input": "1 1000000000 1000 1000 1000000000000... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Lesha plays the recently published new version of the lege... | [{"type": "stdin_stdout", "input": "3 5 10 1 5\n1 3 1\n", "output": "12\n2 5 2 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 5 10 1 339\n1 3 1\n", "output": "35\n5 5 5 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 6 0 1 4\n5 1\n", "output": "5\n5 5 \n", "metad... | livecodebench | deepcoder_91 | 91 |
Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ d... | [
"```python\nn = int(input())\nl = list(map(int, input().split()))\n\ninv = 0\nout = 0\nmult = 1\nfor i in range(32):\n curr = dict()\n opp = 0\n same = 0\n\n for v in l:\n if v ^ 1 in curr:\n if v & 1:\n opp += curr[v ^ 1]\n else:\n same += curr... | [{"type": "stdin_stdout", "input": "4\n0 1 3 2\n", "output": "1 0\n"}, {"type": "stdin_stdout", "input": "9\n10 7 9 10 7 5 5 3 5\n", "output": "4 14\n"}, {"type": "stdin_stdout", "input": "3\n8 10 3\n", "output": "0 8\n"}, {"type": "stdin_stdout", "input": "5\n1000000000 1000000000 1000000000 0 0\n", "output": "0 53687... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ non-negative ... | [{"type": "stdin_stdout", "input": "4\n0 1 3 2\n", "output": "1 0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "9\n10 7 9 10 7 5 5 3 5\n", "output": "4 14\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n8 10 3\n", "output": "0 8\n", "metadata": {"func_name": null}}... | livecodebench | deepcoder_92 | 92 |
Solve the following coding problem using the programming language python:
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p_1, p_2, ..., p_{n}. Then the guys take... | [
"```python\n3\n\nimport sys\n\nclass CumTree:\n \n def __init__(self, a, b):\n self.a = a\n self.b = b\n self.count = 0\n if a == b:\n return\n mid = (a + b) // 2\n self.levo = CumTree(a, mid)\n self.desno = CumTree(mid+1, b)\n \n def manjs... | [{"type": "stdin_stdout", "input": "2\n1 2\n", "output": "0.000000\n"}, {"type": "stdin_stdout", "input": "5\n3 5 2 4 1\n", "output": "13.000000\n"}, {"type": "stdin_stdout", "input": "16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\n", "output": "108.000000\n"}, {"type": "stdin_stdout", "input": "9\n1 7 8 5 3 4 6 9 2\n", "... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Jeff has become friends with Furik. Now these two are goin... | [{"type": "stdin_stdout", "input": "2\n1 2\n", "output": "0.000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n3 5 2 4 1\n", "output": "13.000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\n", "output": "108.000000\... | livecodebench | deepcoder_93 | 93 |
Solve the following coding problem using the programming language python:
DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: $\left\{\begin{array}{ll}{\frac{v}{e}} ... | [
"```python\n\"\"\"\nCodeforces Round 254 Div 1 Problem A\n\nAuthor : chaotic_iak\nLanguage: Python 3.3.4\n\"\"\"\n\ndef read(mode=2):\n # 0: String\n # 1: List of strings\n # 2: List of integers\n inputs = input().strip()\n if mode == 0:\n return inputs\n if mode == 1:\n return inpu... | [{"type": "stdin_stdout", "input": "1 0\n1\n", "output": "0.000000000000000\n"}, {"type": "stdin_stdout", "input": "2 1\n1 2\n1 2 1\n", "output": "3.000000000000000\n"}, {"type": "stdin_stdout", "input": "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63\n", "output": "2.965517241379311\n"}, {"type": ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
DZY loves Physics, and he enjoys calculating density.
Alm... | [{"type": "stdin_stdout", "input": "1 0\n1\n", "output": "0.000000000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 1\n1 2\n1 2 1\n", "output": "3.000000000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 ... | livecodebench | deepcoder_94 | 94 |
Solve the following coding problem using the programming language python:
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d... | [
"```python\ndef Search(L,aa,x):\n a=aa\n b=len(L)\n while(b-a>1):\n i=(b+a)//2\n if(L[i]>x):\n b=i\n elif(L[i]<x):\n a=i\n else:\n return (i+1)-aa-1\n return b-aa-1\n\nimport math\n\nn,d=list(map(int,input().split()))\n\nP=list(map(int,input()... | [{"type": "stdin_stdout", "input": "4 3\n1 2 3 4\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "4 2\n-3 -2 -1 0\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 19\n1 10 20 30 50\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 5\n31 36 43 47 48 50 56 69 71 86\n", "output": "2\n"}, {"type... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Little Petya likes points a lot. Recently his mom has pres... | [{"type": "stdin_stdout", "input": "4 3\n1 2 3 4\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 2\n-3 -2 -1 0\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 19\n1 10 20 30 50\n", "output": "1\n", "metadata": {"func_name": null}}, ... | livecodebench | deepcoder_95 | 95 |
Solve the following coding problem using the programming language python:
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly a_{i} feet high.
[Image... | [
"```python\ndef read_data():\n n = int(input())\n hs = list(map(int, input().split()))\n return n, hs\n\n\ndef solve(n, hs):\n left = get_left_index(n, hs)\n right = get_right_index(n, hs)\n vals = [[] for i in range(n)]\n for h, l, r in zip(hs, left, right):\n vals[r - l - 2].append(h)\... | [{"type": "stdin_stdout", "input": "10\n1 2 3 4 5 4 3 2 1 6\n", "output": "6 4 4 3 3 2 2 1 1 1 \n"}, {"type": "stdin_stdout", "input": "3\n524125987 923264237 374288891\n", "output": "923264237 524125987 374288891 \n"}, {"type": "stdin_stdout", "input": "5\n585325539 365329221 412106895 291882089 564718673\n", "output"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Mike is the president of country What-The-Fatherland. Ther... | [{"type": "stdin_stdout", "input": "10\n1 2 3 4 5 4 3 2 1 6\n", "output": "6 4 4 3 3 2 2 1 1 1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n524125987 923264237 374288891\n", "output": "923264237 524125987 374288891 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": ... | livecodebench | deepcoder_96 | 96 |
Solve the following coding problem using the programming language python:
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile conta... | [
"```python\nn = int(input())\narr = [int(input()) for i in range(n)]\nb = [0 for i in range(n)]\ns = 0\nfor i in range(n):\n j = int((arr[i] << 1) ** 0.5)\n if j * (j + 1) > (arr[i] << 1):\n j -= 1\n s ^= j\nif s != 0:\n print('NO')\nelse:\n print('YES')\n\n```"
] | [{"type": "stdin_stdout", "input": "1\n5\n", "output": "NO"}, {"type": "stdin_stdout", "input": "2\n1\n2\n", "output": "YES"}, {"type": "stdin_stdout", "input": "3\n34\n44\n21\n", "output": "NO"}, {"type": "stdin_stdout", "input": "6\n34\n44\n21\n55\n1\n36\n", "output": "NO"}, {"type": "stdin_stdout", "input": "14\n34\... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Sam has been teaching Jon the Game of Stones to sharpen hi... | [{"type": "stdin_stdout", "input": "1\n5\n", "output": "NO", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1\n2\n", "output": "YES", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n34\n44\n21\n", "output": "NO", "metadata": {"func_name": null}}, {"type": "stdin_stdout",... | livecodebench | deepcoder_97 | 97 |
Solve the following coding problem using the programming language python:
You are given an array consisting of n non-negative integers a_1, a_2, ..., a_{n}.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array a... | [
"```python\n__author__ = 'Think'\nn=int(input())\naints=[int(i) for i in input().split()]\npermutes=[int(i)-1 for i in input().split()]\nresults=[0]\n\nrebuilt={}\nm=0\nfor numby in range(n-1, 0, -1):\n\tp=permutes[numby]\n\tbelow=False\n\tabove=False\n\tif p-1 in rebuilt:\n\t\tbelow=True\n\tif p+1 in rebuilt:\n\t\... | [{"type": "stdin_stdout", "input": "4\n1 3 2 5\n3 4 1 2\n", "output": "5\n4\n3\n0\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n4 2 3 5 1\n", "output": "6\n5\n5\n1\n0\n"}, {"type": "stdin_stdout", "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n", "output": "18\n16\n11\n8\n8\n6\n6\n0\n"}, {"type": "stdin_stdout"... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
You are given an array consisting of n non-negative intege... | [{"type": "stdin_stdout", "input": "4\n1 3 2 5\n3 4 1 2\n", "output": "5\n4\n3\n0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n4 2 3 5 1\n", "output": "6\n5\n5\n1\n0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n",... | livecodebench | deepcoder_98 | 98 |
Solve the following coding problem using the programming language python:
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collec... | [
"```python\nfrom bisect import bisect_left, insort_left\na = []\nn = int(input())\nfor _ in range(n):\n #print(a)\n s, d = list(map(int, input().split()))\n if len(a) == 0:\n print(s, s+d - 1)\n a.append((s, s + d - 1))\n continue\n p = bisect_left(a, (s, s + d - 1))\n #print('p'... | [{"type": "stdin_stdout", "input": "3\n9 2\n7 3\n2 4\n", "output": "9 10\n1 3\n4 7\n"}, {"type": "stdin_stdout", "input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000\n"}, {"type": "stdin_stdout", ... | null | null | You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
Solve the following coding problem using the programming language python:
Polycarp starts his own business. Tomorrow will be the fir... | [{"type": "stdin_stdout", "input": "3\n9 2\n7 3\n2 4\n", "output": "9 10\n1 3\n4 7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 20000... | livecodebench | deepcoder_99 | 99 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.