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:
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.
In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in ... | [
"```python\nfrom collections import defaultdict, deque\n \nadj = defaultdict(lambda: defaultdict(lambda: 0))\ndef bfs(graph, inicio, destino, parent):\n parent.clear()\n queue = deque()\n queue.append([inicio, float(\"Inf\")])\n parent[inicio] = -2\n while (len(queue)):\n current, flow = queue... | [{"type": "stdin_stdout", "input": "4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2\n", "output": "1.5000000000\n"}, {"type": "stdin_stdout", "input": "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30\n", "output": "10.2222222222\n"}, {"type": "stdin_stdout", "input": "10 16 63\n1 2 1\n2 10 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:
Niwel is a little golden bear. As everyone knows, bears li... | [{"type": "stdin_stdout", "input": "4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2\n", "output": "1.5000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\n3 2 30\n", "output": "10.2222222222\n", "metadata": {"func_name": null... | livecodebench | deepcoder_100 | 100 |
Solve the following coding problem using the programming language python:
Wherever the destination is, whoever we meet, let's render this song together.
On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen tha... | [
"```python\n# http://codeforces.com/problemset/problem/848/B\nfrom collections import defaultdict\n\n\ndef get_dest(start, w, h):\n if start[0] == 1:\n return (str(start[1]), str(h))\n else:\n return (str(w), str(start[1]))\n\n\nn, w, h = [int(x) for x in input().split()]\ndancers = []\ngroups =... | [{"type": "stdin_stdout", "input": "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1\n", "output": "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6\n"}, {"type": "stdin_stdout", "input": "3 2 3\n1 1 2\n2 1 1\n1 1 5\n", "output": "1 3\n2 1\n1 3\n"}, {"type": "stdin_stdout", "input": "1 10 10\n1 8 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:
Wherever the destination is, whoever we meet, let's render... | [{"type": "stdin_stdout", "input": "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1\n", "output": "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 2 3\n1 1 2\n2 1 1\n1 1 5\n", "output": "1 3\n2 1\n1 3\n", "metadata": {"func_name": n... | livecodebench | deepcoder_101 | 101 |
Solve the following coding problem using the programming language python:
For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisibl... | [
"```python\n\ndef Sieve(n): \n ret = []\n divlis = [-1] * (n+1) \n \n flag = [True] * (n+1)\n flag[0] = False\n flag[1] = False\n\n ind = 2\n while ind <= n:\n\n if flag[ind]:\n ret.append(ind)\n\n ind2 = ind ** 2\n\n while ind2 <= n:\n ... | [{"type": "stdin_stdout", "input": "2\n1 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4\n10 24 40 80\n", "output": "40\n"}, {"type": "stdin_stdout", "input": "10\n540 648 810 648 720 540 594 864 972 648\n", "output": "54\n"}, {"type": "stdin_stdout", "input": "2\n199999 200000\n", "output": "39999800000\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:
For the multiset of positive integers $s=\{s_1,s_2,\dots,s... | [{"type": "stdin_stdout", "input": "2\n1 1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n10 24 40 80\n", "output": "40\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n540 648 810 648 720 540 594 864 972 648\n", "output": "54\n", "metadata": {"f... | livecodebench | deepcoder_102 | 102 |
Solve the following coding problem using the programming language python:
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two char... | [
"```python\nclass DisjointSet(object):\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n self.num = n # number of disjoint sets\n\n def union(self, x, y):\n self._link(self.find_set(x), self.find_set(y))\n\n def _link(self, x, y):\n if x == ... | [{"type": "stdin_stdout", "input": "3 0\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "100000 0\n", "output": "303861760\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:
There are many anime that are about "love triangles": Alic... | [{"type": "stdin_stdout", "input": "3 0\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n", "output": "0\n", "metadata": {"f... | livecodebench | deepcoder_103 | 103 |
Solve the following coding problem using the programming language python:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows ... | [
"```python\n__author__ = 'Pavel Mavrin'\n\nn = int(input())\na = [int(x) for x in input().split()]\n\ns = 0\nres = 0\nfor i in a:\n if i == 0:\n res += s\n else:\n s += 1\n\nprint(res)\n\n```"
] | [{"type": "stdin_stdout", "input": "4\n0 0 1 0\n", "output": "1"}, {"type": "stdin_stdout", "input": "5\n1 0 1 0 1\n", "output": "3"}, {"type": "stdin_stdout", "input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0\n", "output": "416"}, {"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:
Iahub helps his grandfather at the farm. Today he must mil... | [{"type": "stdin_stdout", "input": "4\n0 0 1 0\n", "output": "1", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 0 1 0 1\n", "output": "3", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 ... | livecodebench | deepcoder_104 | 104 |
Solve the following coding problem using the programming language python:
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of $n$ stations, enumerated from $1$ through $n$. The train occupies one station at a time and travels around the network of stations in a circ... | [
"```python\n\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\nmii=lambda:list(map(int,input().split()))\n\nn,m=mii()\na=[0 for _ in range(n)]\nc=[123456 for _ in range(n)]\nfor _ in range(m):\n u,v=mii()\n u%=n\n v%=n\n if v<u: v+=n\n a[u]+=1\n if c[u]>v: c[u]=v\n\nans=[]\nfor... | [{"type": "stdin_stdout", "input": "5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n", "output": "10 9 10 10 9 \n"}, {"type": "stdin_stdout", "input": "2 3\n1 2\n1 2\n1 2\n", "output": "5 6 \n"}, {"type": "stdin_stdout", "input": "5 3\n2 4\n5 4\n3 2\n", "output": "8 7 6 8 7 \n"}, {"type": "stdin_stdout", "input": "10 3\n3 4\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:
Alice received a set of Toy Train™ from Bob. It consists o... | [{"type": "stdin_stdout", "input": "5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n", "output": "10 9 10 10 9 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 3\n1 2\n1 2\n1 2\n", "output": "5 6 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 3\n2 4\n5 4\n3 2\n", "output"... | livecodebench | deepcoder_105 | 105 |
Solve the following coding problem using the programming language python:
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed th... | [
"```python\n3\n\nimport sys\nfrom functools import lru_cache\n\nMOD = 1000000007\n\ncnk = [[1 for i in range(1001)] for j in range(1001)]\nfor i in range(1, 1001):\n for j in range(1, i):\n cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j]\n\n\nk = int(input())\ncs = [int(input()) for i in range(k)]\n\nans = ... | [{"type": "stdin_stdout", "input": "3\n2\n2\n1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4\n1\n2\n3\n4\n", "output": "1680\n"}, {"type": "stdin_stdout", "input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "output": "12520708\n"}, {"type": "stdin_stdout", "input": "5\n10\n10\n10\n10\n10\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:
Kyoya Ootori has a bag with n colored balls that are color... | [{"type": "stdin_stdout", "input": "3\n2\n2\n1\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1\n2\n3\n4\n", "output": "1680\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "output": "12520708... | livecodebench | deepcoder_106 | 106 |
Solve the following coding problem using the programming language python:
There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An... | [
"```python\nm = 1000000007\nn = int(input())\na = list(map(int, input().split()))\nprint(pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1) % m)\n```"
] | [{"type": "stdin_stdout", "input": "3\n-1 -1 -1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "2\n2 -1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "40\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3\n", "output": "755808950\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:
There are $n$ startups. Startups can be active or acquired... | [{"type": "stdin_stdout", "input": "3\n-1 -1 -1\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 -1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "40\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -... | livecodebench | deepcoder_107 | 107 |
Solve the following coding problem using the programming language python:
Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of $n$ nodes and $n-1$ edges. The nodes are numbered from $1$ to $n$.
Nauuo wants t... | [
"```python\nimport math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 998244353\ndd = [(-1,0),(0,1),(1,0),(0,-1)]\nddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return list(map(int... | [{"type": "stdin_stdout", "input": "4\n1 2\n1 3\n2 4\n", "output": "16"}, {"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "24"}, {"type": "stdin_stdout", "input": "6\n2 1\n3 2\n4 1\n5 4\n1 6\n", "output": "144"}, {"type": "stdin_stdout", "input": "2\n2 1\n", "output": "2"}, {"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:
Nauuo is a girl who loves drawing circles.
One day she ha... | [{"type": "stdin_stdout", "input": "4\n1 2\n1 3\n2 4\n", "output": "16", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "24", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n2 1\n3 2\n4 1\n5 4\n1 6\n", "output": "144", "metadata": {"func_name"... | livecodebench | deepcoder_108 | 108 |
Solve the following coding problem using the programming language python:
Mitya has a rooted tree with $n$ vertices indexed from $1$ to $n$, where the root has index $1$. Each vertex $v$ initially had an integer number $a_v \ge 0$ written on it. For every vertex $v$ Mitya has computed $s_v$: the sum of all values writ... | [
"```python\nfrom collections import defaultdict, deque\n\nn = int(input())\nadj = [[] for _ in range(n)]\nv = [0] * n\nl = list(map(int, input().split()))\nfor i, f in enumerate(l):\n adj[f - 1].append(i + 1)\n\ns = list(map(int, input().split()))\n\nQ = deque([(0, s[0], s[0])])\nans = 0\nflag = False\npossible ... | [{"type": "stdin_stdout", "input": "5\n1 1 1 1\n1 -1 -1 -1 -1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n1 2 3 1\n1 -1 2 -1 -1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n1 2\n2 -1 1\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "2\n1\n0 -1\n", "output": "0\n"}, {"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:
Mitya has a rooted tree with $n$ vertices indexed from $1$... | [{"type": "stdin_stdout", "input": "5\n1 1 1 1\n1 -1 -1 -1 -1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 2 3 1\n1 -1 2 -1 -1\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 2\n2 -1 1\n", "output": "-1\n", "metadata": {"fu... | livecodebench | deepcoder_109 | 109 |
Solve the following coding problem using the programming language python:
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they sh... | [
"```python\nfrom time import time\n\n\nopposite = {\n 'N': 'S',\n 'S': 'N',\n 'E': 'W',\n 'W': 'E'\n}\notr = str.maketrans(opposite)\n\nbits = {\n 'N': 0,\n 'S': 1,\n 'E': 2,\n 'W': 3,\n}\n\nQ = 4294967291\n\n\ndef combine(h, v, q):\n return (h<<2 | v) % q\n\n\ndef combinel(h, v, q, s):\n... | [{"type": "stdin_stdout", "input": "7\nNNESWW\nSWSWSW\n", "output": "YES\n"}, {"type": "stdin_stdout", "input": "3\nNN\nSS\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "3\nES\nNW\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5\nWSSE\nWNNE\n", "output": "NO\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 the spirit of the holidays, Saitama has given Genos two... | [{"type": "stdin_stdout", "input": "7\nNNESWW\nSWSWSW\n", "output": "YES\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\nNN\nSS\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\nES\nNW\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type"... | livecodebench | deepcoder_110 | 110 |
Solve the following coding problem using the programming language python:
You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$).
Let's sort $p$ in non-d... | [
"```python\n\nimport sys\nfrom sys import stdin\n\ndef modfac(n, MOD):\n \n f = 1\n factorials = [1]\n for m in range(1, n + 1):\n f *= m\n f %= MOD\n factorials.append(f)\n inv = pow(f, MOD - 2, MOD)\n invs = [1] * (n + 1)\n invs[n] = inv\n for m in range(n, 1, -1):\n ... | [{"type": "stdin_stdout", "input": "1\n1 4\n", "output": "6"}, {"type": "stdin_stdout", "input": "2\n2 1 2 1\n", "output": "12"}, {"type": "stdin_stdout", "input": "3\n2 2 2 2 2 2\n", "output": "0"}, {"type": "stdin_stdout", "input": "5\n13 8 35 94 9284 34 54 69 123 846\n", "output": "2588544"}, {"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 $a$ of length $2n$. Consider a part... | [{"type": "stdin_stdout", "input": "1\n1 4\n", "output": "6", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 1 2 1\n", "output": "12", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n2 2 2 2 2 2\n", "output": "0", "metadata": {"func_name": null}}, {"type": "stdin_stdou... | livecodebench | deepcoder_111 | 111 |
Solve the following coding problem using the programming language python:
While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers $a_1, a_2, \ldots, a_n$. Since the talk was long and not promising, Kostya created a new cyclic array $b_1, b_2, \ldots, b_{n}$ so tha... | [
"```python\nn = int(input())\n\nb = list(map(int, input().split()))\n\nm, M = min(b), max(b)\nif m == M:\n if M == 0:\n print('YES')\n print(' '.join(['1' for i in range(n)]))\n else:\n print('NO')\nelse:\n print('YES')\n\n pos = list([i for i in range(n) if b[i] == M and b[i - 1] <... | [{"type": "stdin_stdout", "input": "4\n1 3 1 0\n", "output": "YES\n7 3 8 7 \n"}, {"type": "stdin_stdout", "input": "2\n4 4\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n", "output": "YES\n5 20 16 13 11 \n"}, {"type": "stdin_stdout", "input": "10\n3 3 3 5 6 9 3 1 7 3\n", "output": "YES\n38 35 3... | 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:
While discussing a proper problem A for a Codeforces Round... | [{"type": "stdin_stdout", "input": "4\n1 3 1 0\n", "output": "YES\n7 3 8 7 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n4 4\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n5 4 3 2 1\n", "output": "YES\n5 20 16 13 11 \n", "metadata": {"func_na... | livecodebench | deepcoder_112 | 112 |
Solve the following coding problem using the programming language python:
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from $1$ to $n$. Each of its vertices also has an integer $a_i$ written on it. For each vertex $i$, Evlampiy calculated $c_i$ — the number of vertices $j$ in the subtree of... | [
"```python\nimport sys\nreadline = sys.stdin.readline \ndef parorder(Edge, p):\n N = len(Edge)\n par = [0]*N\n par[p] = -1\n stack = [p]\n order = []\n visited = set([p])\n ast = stack.append\n apo = order.append\n while stack:\n vn = stack.pop()\n apo(vn)\n fo... | [{"type": "stdin_stdout", "input": "3\n2 0\n0 2\n2 0\n", "output": "YES\n1 3 2 \n"}, {"type": "stdin_stdout", "input": "5\n0 1\n1 3\n2 1\n3 0\n2 0\n", "output": "YES\n2 5 3 1 4 \n"}, {"type": "stdin_stdout", "input": "1\n0 0\n", "output": "YES\n1 \n"}, {"type": "stdin_stdout", "input": "2\n0 1\n1 0\n", "output": "YES\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:
Evlampiy was gifted a rooted tree. The vertices of the tre... | [{"type": "stdin_stdout", "input": "3\n2 0\n0 2\n2 0\n", "output": "YES\n1 3 2 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n0 1\n1 3\n2 1\n3 0\n2 0\n", "output": "YES\n2 5 3 1 4 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n0 0\n", "output": "YES\n1 \n", "m... | livecodebench | deepcoder_113 | 113 |
Solve the following coding problem using the programming language python:
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to... | [
"```python\nn=int(input())\na=[]\nfor i in range(n):\n a.append(list(map(int,input().split())))\nans = [0]*n\nfor i in range(n):\n for j in range(n):\n if j!=i:\n ans[i] |= a[i][j]\n print(ans[i],end = ' ')\n\n```"
] | [{"type": "stdin_stdout", "input": "1\n-1\n", "output": "0 "}, {"type": "stdin_stdout", "input": "3\n-1 18 0\n18 -1 0\n0 0 -1\n", "output": "18 18 0 "}, {"type": "stdin_stdout", "input": "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\n", "output": "128 180 148 160 "}, {"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:
Recently Polycarpus has learned the "bitwise AND" operatio... | [{"type": "stdin_stdout", "input": "1\n-1\n", "output": "0 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n-1 18 0\n18 -1 0\n0 0 -1\n", "output": "18 18 0 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\... | livecodebench | deepcoder_114 | 114 |
Solve the following coding problem using the programming language python:
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can b... | [
"```python\nfrom bisect import *\n\nn, tc, td = [int(i) for i in input().split()]\nfc = []\nfd = []\nmbc = 0\nmbd = 0\nfor _ in range(n):\n b, p, ft = input().split()\n b, p = int(b), int(p)\n f = (p, b)\n if ft == 'C':\n if p <= tc:\n fc.append(f)\n mbc = max(mbc, b)\n e... | [{"type": "stdin_stdout", "input": "3 7 6\n10 8 C\n4 3 C\n5 6 D\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "2 4 5\n2 5 C\n2 1 D\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 10 10\n5 5 C\n5 5 C\n10 11 D\n", "output": "10\n"}, {"type": "stdin_stdout", "input": "6 68 40\n1 18 D\n6 16 D\n11 16 D\... | 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:
Arkady plays Gardenscapes a lot. Arkady wants to build two... | [{"type": "stdin_stdout", "input": "3 7 6\n10 8 C\n4 3 C\n5 6 D\n", "output": "9\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 4 5\n2 5 C\n2 1 D\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 10 10\n5 5 C\n5 5 C\n10 11 D\n", "output": "10\n", "me... | livecodebench | deepcoder_115 | 115 |
Solve the following coding problem using the programming language python:
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the inte... | [
"```python\n\ndef main():\n k = int(input())\n n = []\n a = []\n for i in range(k):\n line = [int(x) for x in input().split()]\n ni = line[0]\n ai = []\n n.append(ni)\n a.append(ai)\n for j in range(ni):\n ai.append(line[1 + j])\n answer, c, p = so... | [{"type": "stdin_stdout", "input": "4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n", "output": "Yes\n7 2\n2 3\n5 1\n10 4\n"}, {"type": "stdin_stdout", "input": "2\n2 3 -2\n2 -1 5\n", "output": "No\n"}, {"type": "stdin_stdout", "input": "2\n2 -10 10\n2 0 -20\n", "output": "Yes\n-10 2\n-20 1\n"}, {"type": "stdin_stdout", "input": "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:
Ujan has a lot of numbers in his boxes. He likes order and... | [{"type": "stdin_stdout", "input": "4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n", "output": "Yes\n7 2\n2 3\n5 1\n10 4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 3 -2\n2 -1 5\n", "output": "No\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 -10 10\n2 0 -20\n", "outpu... | livecodebench | deepcoder_116 | 116 |
Solve the following coding problem using the programming language python:
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string... | [
"```python\ns = input()\nt = input()\n\nn = len(s)\nm = len(t)\n\nt = t + '$' + s\n\np = [0] * (n + m + 1)\nk = 0\nfor i in range(1, n + m + 1):\n while k > 0 and t[k] != t[i]:\n k = p[k - 1]\n if t[k] == t[i]:\n k += 1\n p[i] = k\n\nans = [0] * n\nsums = [0] * (n + 1)\ncurs = 0\nwas = False\... | [{"type": "stdin_stdout", "input": "ababa\naba\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "welcometoroundtwohundredandeightytwo\nd\n", "output": "274201\n"}, {"type": "stdin_stdout", "input": "ddd\nd\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnss... | 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:
Hamed has recently found a string t and suddenly became qu... | [{"type": "stdin_stdout", "input": "ababa\naba\n", "output": "5\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "welcometoroundtwohundredandeightytwo\nd\n", "output": "274201\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "ddd\nd\n", "output": "12\n", "metadata": {"func_... | livecodebench | deepcoder_117 | 117 |
Solve the following coding problem using the programming language python:
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.
In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.
Du will chat in the group fo... | [
"```python\nimport sys\nreadline = sys.stdin.readline\n\nN, D, M = map(int, readline().split())\nA = list(map(int, readline().split()))\nAm = [a for a in A if a > M]\nAo = [a for a in A if a <= M]\nAm.sort(reverse = True)\nAo.sort(reverse = True)\nCam = Am[:]\nCao = Ao[:]\n\nfor i in range(1, len(Cam)):\n Cam[i]... | [{"type": "stdin_stdout", "input": "5 2 11\n8 10 15 23 5\n", "output": "48\n"}, {"type": "stdin_stdout", "input": "20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n", "output": "195\n"}, {"type": "stdin_stdout", "input": "1 1 0\n0\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "100 61 71\n11 18 0 47... | 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:
Have you ever used the chat application QQ? Well, in a cha... | [{"type": "stdin_stdout", "input": "5 2 11\n8 10 15 23 5\n", "output": "48\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n", "output": "195\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 1 0\n0\n", "output"... | livecodebench | deepcoder_118 | 118 |
Solve the following coding problem using the programming language python:
Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and t... | [
"```python\nn,r1,r2,r3,D = map(int,input().split())\n\nstate = [0,0] # after odd number of 2 (1st), or not (2nd)\n\na = list(map(int,input().split()))\n\n# First element\n\n# Choosing P~P + A\n\nstate[0] = r1 * a[0] + r3\n\n# Choosing L + P later or all P\n\nstate[1] = min(r2 + r1 + D, r1 * (a[0] + 2) + D)\n\n# Sec... | [{"type": "stdin_stdout", "input": "4 1 3 4 3\n3 2 5 1\n", "output": "34"}, {"type": "stdin_stdout", "input": "4 2 4 4 1\n4 5 1 2\n", "output": "31"}, {"type": "stdin_stdout", "input": "2 2 5 7 3\n4 5\n", "output": "23"}, {"type": "stdin_stdout", "input": "100 4 8 9 1\n1 8 1 8 7 8 1 8 10 4 7 7 3 2 6 7 3 7 3 7 1 8 5 7 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:
Ziota found a video game called "Monster Invaders".
Simil... | [{"type": "stdin_stdout", "input": "4 1 3 4 3\n3 2 5 1\n", "output": "34", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 2 4 4 1\n4 5 1 2\n", "output": "31", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2 5 7 3\n4 5\n", "output": "23", "metadata": {"func_name": null}},... | livecodebench | deepcoder_119 | 119 |
Solve the following coding problem using the programming language python:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains ... | [
"```python\nimport sys\n\ndef binpow(a, n, p):\n res = 1\n while n > 0:\n if n % 2 == 1:\n res = (res * a) % p\n a = (a * a) % p\n n >>= 1\n return res\n\ndef main():\n result = []\n \n t = int(sys.stdin.readline())\n for line in sys.stdin.readlines():\n p... | [{"type": "stdin_stdout", "input": "2\n6 12 10\n4 3 10\n", "output": "Finite\nInfinite\n"}, {"type": "stdin_stdout", "input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n", "output": "Finite\nFinite\nFinite\nInfinite\n"}, {"type": "stdin_stdout", "input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8... | 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 several queries. Each query consists of thre... | [{"type": "stdin_stdout", "input": "2\n6 12 10\n4 3 10\n", "output": "Finite\nInfinite\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n", "output": "Finite\nFinite\nFinite\nInfinite\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n10 ... | livecodebench | deepcoder_120 | 120 |
Solve the following coding problem using the programming language python:
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\... | [
"```python\nn, m = map(int, input().split())\na = set(map(int, input().split()))\n \ny = 2 ** n\nmk = [0] * (2 * y)\ncur = 0\nfor x in a:\n if mk[x]: continue\n mk[x] = 1\n st = [x]\n while st:\n u = st.pop()\n if u < y:\n if not mk[y + u]:\n mk[y + u] = 1\n ... | [{"type": "stdin_stdout", "input": "2 3\n1 2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 5\n5 19 10 20 12\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3 5\n3 5 0 6 7\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "0 1\n0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1 1\... | 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 set of size $m$ with integer elements betw... | [{"type": "stdin_stdout", "input": "2 3\n1 2 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 5\n5 19 10 20 12\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 5\n3 5 0 6 7\n", "output": "1\n", "metadata": {"func_name": null}}, {"ty... | livecodebench | deepcoder_121 | 121 |
Solve the following coding problem using the programming language python:
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ ... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nMOD = 987654103\n\nn = int(input())\nt = input()\n\nplace = []\nf1 = []\ne1 = []\n\ns = []\ncurr = 0\ncount1 = 0\nfor i in range(n):\n c = t[i]\n if c == '0':\n if count1:\n e1.append(i - 1)\n if count1 & 1:\n s.... | [{"type": "stdin_stdout", "input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "output": "Yes\nYes\nNo\n"}, {"type": "stdin_stdout", "input": "1\n0\n1\n1 1 1\n", "output": "Yes\n"}, {"type": "stdin_stdout", "input": "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "output": "Yes\nYes\nNo\n"}, {"type": "stdin_stdout", "input": "10\n010000... | 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 this problem, we will deal with binary strings. Each ch... | [{"type": "stdin_stdout", "input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "output": "Yes\nYes\nNo\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n0\n1\n1 1 1\n", "output": "Yes\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "output"... | livecodebench | deepcoder_122 | 122 |
Solve the following coding problem using the programming language python:
You are given an array $a$ of $n$ integers and an integer $s$. It is guaranteed that $n$ is odd.
In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the med... | [
"```python\n\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,s=list(map(int,input().split()))\n\na=list(map(int,input().split()))\na.sort()\nmed=a[n//2]\n\nans=0\nif med>s:\n for i in range(n//2+1):\n if a[i]>s:\n ans+=a[i]-s\nelif med<s:\n for i in range(n//2,n):\n... | [{"type": "stdin_stdout", "input": "3 8\n6 5 8\n", "output": "2"}, {"type": "stdin_stdout", "input": "7 20\n21 15 12 11 20 19 12\n", "output": "6"}, {"type": "stdin_stdout", "input": "3 1\n1 2 5\n", "output": "1"}, {"type": "stdin_stdout", "input": "1 100\n105\n", "output": "5"}, {"type": "stdin_stdout", "input": "5 1\... | 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 and an integer ... | [{"type": "stdin_stdout", "input": "3 8\n6 5 8\n", "output": "2", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7 20\n21 15 12 11 20 19 12\n", "output": "6", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 1\n1 2 5\n", "output": "1", "metadata": {"func_name": null}}, {"type... | livecodebench | deepcoder_123 | 123 |
Solve the following coding problem using the programming language python:
In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
W... | [
"```python\n#!/usr/bin/env python3\n\nfrom collections import defaultdict\n\nDEBUG = False\n\n\ndef main():\n if DEBUG:\n test()\n\n n = int(input())\n\n paths = cycles(n)\n\n print(len(paths))\n for p in paths:\n print('%d %s' % (len(p), ' '.join([str(v) for v in p])))\n\n\ndef cycles(... | [{"type": "stdin_stdout", "input": "3\n", "output": "2\n3 1 2 3\n3 1 2 3\n"}, {"type": "stdin_stdout", "input": "5\n", "output": "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n"}, {"type": "stdin_stdout", "input": "4\n", "output": "4\n3 4 1 2\n3 2 3 4\n3 1 2 3\n3 3 4 1\n"}, {"type": "stdin_stdout", "inpu... | 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 order to fly to the Moon Mister B just needs to solve t... | [{"type": "stdin_stdout", "input": "3\n", "output": "2\n3 1 2 3\n3 1 2 3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n", "output": "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n", "output": "4\n3 4 ... | livecodebench | deepcoder_124 | 124 |
Solve the following coding problem using the programming language python:
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this ... | [
"```python\nk, q = list(map(int, input().split()))\nt = [0] * (k + 1)\nt[1] = 1\nd = [0]\nn = i = 1\nwhile i < 1001:\n if 2000 * t[k] > i - 1e-7:\n d.append(n)\n i += 1\n else:\n t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)]\n n += 1\nfor i in range(q... | [{"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "2 2\n1\n2\n", "output": "2\n2\n"}, {"type": "stdin_stdout", "input": "3 5\n1\n4\n20\n50\n300\n", "output": "3\n3\n3\n3\n3\n"}, {"type": "stdin_stdout", "input": "4 5\n2\n4\n30\n100\n1000\n", "output": "4\n4\n4\n4\n7\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:
Jon Snow is on the lookout for some orbs required to defea... | [{"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n1\n2\n", "output": "2\n2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 5\n1\n4\n20\n50\n300\n", "output": "3\n3\n3\n3\n3\n", "metadata": {"func_name": nu... | livecodebench | deepcoder_125 | 125 |
Solve the following coding problem using the programming language python:
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout a... | [
"```python\ndef main():\n n, m = list(map(int, input().split()))\n aa = []\n for _ in range(n):\n row = list(map(int, input().split()))\n row.append(0)\n aa.append(row)\n aa.append([0] * (m + 1))\n d1, d2, d3, d4 = ([[0] * (m + 1) for _ in range(n + 1)] for _ in (1, 2, 3, 4))\n ... | [{"type": "stdin_stdout", "input": "3 3\n100 100 100\n100 1 100\n100 100 100\n", "output": "800"}, {"type": "stdin_stdout", "input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n", "output": "747898"}, {"type": "stdin_stdout", "input": "3 ... | 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:
Summer is coming! It's time for Iahub and Iahubina to work... | [{"type": "stdin_stdout", "input": "3 3\n100 100 100\n100 1 100\n100 100 100\n", "output": "800", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n", "output": "747898", "meta... | livecodebench | deepcoder_126 | 126 |
Solve the following coding problem using the programming language python:
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they... | [
"```python\nn = int(input())\nans = 'YES\\n'\nfor i in range(n):\n x1, y1, x2, y2 = map(int, input().split())\n res = (x1 & 1) * 2 + (y1 & 1) + 1\n ans += str(res) + '\\n'\nprint(ans)\n```"
] | [{"type": "stdin_stdout", "input": "8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n", "output": "YES\n1\n4\n3\n2\n3\n3\n2\n1\n"}, {"type": "stdin_stdout", "input": "1\n0 0 1 1\n", "output": "YES\n1\n"}, {"type": "stdin_stdout", "input": "4\n0 0 1 1\n1 0 2 1\n1 1 2 2\n0 1 1 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:
One of Timofey's birthday presents is a colourbook in a sh... | [{"type": "stdin_stdout", "input": "8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n", "output": "YES\n1\n4\n3\n2\n3\n3\n2\n1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n0 0 1 1\n", "output": "YES\n1\n", "metadata": {"func_name": null}}, {"type": "s... | livecodebench | deepcoder_127 | 127 |
Solve the following coding problem using the programming language python:
You are given a set Y of n distinct positive integers y_1, y_2, ..., y_{n}.
Set X of n distinct positive integers x_1, x_2, ..., x_{n} is said to generate set Y if one can transform X to Y by applying some number of the following two operation ... | [
"```python\ndef main():\n from heapq import heapify, heapreplace\n input()\n s = set(map(int, input().split()))\n xx = [-x for x in s]\n heapify(xx)\n while True:\n x = -xx[0]\n while x != 1:\n x //= 2\n if x not in s:\n s.add(x)\n ... | [{"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "4 5 2 3 1 \n"}, {"type": "stdin_stdout", "input": "6\n15 14 3 13 1 12\n", "output": "12 13 14 7 3 1 \n"}, {"type": "stdin_stdout", "input": "6\n9 7 13 17 5 11\n", "output": "4 5 2 6 3 1 \n"}, {"type": "stdin_stdout", "input": "10\n18 14 19 17 11 7 20 10 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:
You are given a set Y of n distinct positive integers y_1,... | [{"type": "stdin_stdout", "input": "5\n1 2 3 4 5\n", "output": "4 5 2 3 1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n15 14 3 13 1 12\n", "output": "12 13 14 7 3 1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n9 7 13 17 5 11\n", "output": "4 5 2 6 3 1 \n",... | livecodebench | deepcoder_128 | 128 |
Solve the following coding problem using the programming language python:
Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$.
Now given n, find a permutation of [1, ... | [
"```python\ndef comp(x):\n for i in range(2, x):\n if x % i == 0:\n return True\n return False\n\nN = int(input())\n\nif N == 4:\n print('YES', '1', '3', '2', '4', sep = '\\n')\nelif comp(N):\n print('NO')\nelse:\n print('YES', '1', sep = '\\n')\n if N > 1:\n for i in rang... | [{"type": "stdin_stdout", "input": "7\n", "output": "YES\n1\n2\n5\n6\n3\n4\n7\n"}, {"type": "stdin_stdout", "input": "6\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "7137\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "1941\n", "output": "NO\n"}, {"type": "stdin_stdout", "input": "55004\n", "outpu... | 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:
Consider a sequence [a_1, a_2, ... , a_{n}]. Define its pr... | [{"type": "stdin_stdout", "input": "7\n", "output": "YES\n1\n2\n5\n6\n3\n4\n7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7137\n", "output": "NO\n", "metadata": {"func_name": null}}, {"type": "stdin... | livecodebench | deepcoder_129 | 129 |
Solve the following coding problem using the programming language python:
Polycarp took $n$ videos, the duration of the $i$-th video is $a_i$ seconds. The videos are listed in the chronological order, i.e. the $1$-st video is the earliest, the $2$-nd video is the next, ..., the $n$-th video is the last.
Now Polycarp ... | [
"```python\nimport sys\nn,k = map(int, sys.stdin.readline().split())\narr = list(map(int, sys.stdin.readline().split()))\ntot = sum(arr)\nif tot % k != 0:\n\tprint('No')\n\treturn\ntot //= k\nidx,cur = 0,0\nans = []\nfor i in range(n):\n\tcur += arr[i]\n\tidx += 1\n\tif cur == tot:\n\t\tans.append(idx)\n\t\tidx = 0... | [{"type": "stdin_stdout", "input": "6 3\n3 3 1 4 1 6\n", "output": "Yes\n2 3 1 "}, {"type": "stdin_stdout", "input": "3 3\n1 1 1\n", "output": "Yes\n1 1 1 "}, {"type": "stdin_stdout", "input": "3 3\n1 1 2\n", "output": "No"}, {"type": "stdin_stdout", "input": "3 1\n1 10 100\n", "output": "Yes\n3 "}, {"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:
Polycarp took $n$ videos, the duration of the $i$-th video... | [{"type": "stdin_stdout", "input": "6 3\n3 3 1 4 1 6\n", "output": "Yes\n2 3 1 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\n1 1 1\n", "output": "Yes\n1 1 1 ", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\n1 1 2\n", "output": "No", "metadata": {"func_name": nul... | livecodebench | deepcoder_130 | 130 |
Solve the following coding problem using the programming language python:
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight w_{i} and some beauty b_{i}. Also each Hos may have some friends. Hoses are divided in some fri... | [
"```python\nf = lambda: map(int, input().split())\nn, m, w = f()\nwb = [(0, 0)] + list(zip(f(), f()))\nt = list(range(n + 1))\n\n\ndef g(x):\n if x == t[x]: return x\n t[x] = g(t[x])\n return t[x]\n\n\nfor i in range(m):\n x, y = f()\n x, y = g(x), g(y)\n if x != y: t[y] = x\n\np = [[] for j in ra... | [{"type": "stdin_stdout", "input": "3 1 5\n3 2 5\n2 4 2\n1 2\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\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:
Just to remind, girls in Arpa's land are really nice.
Meh... | [{"type": "stdin_stdout", "input": "3 1 5\n3 2 5\n2 4 2\n1 2\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n59643... | livecodebench | deepcoder_131 | 131 |
Solve the following coding problem using the programming language python:
Consider a tree $T$ (that is, a connected graph without cycles) with $n$ vertices labelled $1$ through $n$. We start the following process with $T$: while $T$ has more than one vertex, do the following:
choose a random edge of $T$ equiprobab... | [
"```python\nmaxn=50+10\ng=[None]*maxn\ndp=[None]*maxn\nc=[None]*maxn\nsize=[0]*maxn\n\nfor i in range(0,maxn):\n c[i]=[0]*maxn\n c[i][0]=1\n for j in range(1,i+1):\n c[i][j]=c[i-1][j-1]+c[i-1][j]\n\nn=int(input())\nfor i in range(1,n+1):\n g[i]=[]\nfor i in range(1,n):\n u,v=input().split()\n ... | [{"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "0.1250000000\n0.2916666667\n0.2916666667\n0.2916666667\n"}, {"type": "stdin_stdout", "input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "output": "0.0850694444\n0.0664062500\n0.0664062500\n0.1955295139\n0.1955295139\n0.1955295139\n0.1955295139\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:
Consider a tree $T$ (that is, a connected graph without cy... | [{"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "0.1250000000\n0.2916666667\n0.2916666667\n0.2916666667\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "output": "0.0850694444\n0.0664062500\n0.0664062500\n0.1955295139\n0.1955295139\n0.19552... | livecodebench | deepcoder_132 | 132 |
Solve the following coding problem using the programming language python:
Koa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form:
In one operation Koa selects positions $i$ and $i+1$ for some $i$ with $1 \le i < |s|$ and sets $s_i$ to $... | [
"```python\nimport sys\nreadline = sys.stdin.readline\n\nMOD = 10**9+7\nS = readline().strip().split('1')\nif len(S) == 1:\n print(len(S[0]))\nelse:\n S = [len(s)+1 for s in S]\n ans = S[0]*S[-1]\n S = S[1:-1]\n \n dp = [0]*(max(S)+2)\n dp[0] = 1\n for ai in S:\n res = 0\n rz =... | [{"type": "stdin_stdout", "input": "000\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "0101\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "0001111\n", "output": "16\n"}, {"type": "stdin_stdout", "input": "00101100011100\n", "output": "477\n"}, {"type": "stdin_stdout", "input": "0\n", "output": "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:
Koa the Koala has a binary string $s$ of length $n$. Koa c... | [{"type": "stdin_stdout", "input": "000\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "0101\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "0001111\n", "output": "16\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input... | livecodebench | deepcoder_133 | 133 |
Solve the following coding problem using the programming language python:
Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is $\{0,1,…,M-1\}$,... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\ndef main():\n n, m = map(int, input().split())\n a = list(map(int, input().split())) + [0]*500000\n ans_S = 0\n a[n] = a[0] + m\n s = [0]*600600\n for i in range(n):\n s[i] = a[i + 1] - a[i]\n s[n] = -1\n for i in range(n):\n ... | [{"type": "stdin_stdout", "input": "2 5\n3 4\n", "output": "1\n2\n"}, {"type": "stdin_stdout", "input": "4 1000000000\n5 25 125 625\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 4\n1 3\n", "output": "2\n0 2\n"}, {"type": "stdin_stdout", "input": "1 2\n1\n", "output": "1\n0\n"}, {"type": "stdin_stdout", "in... | 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:
Everybody seems to think that the Martians are green, but ... | [{"type": "stdin_stdout", "input": "2 5\n3 4\n", "output": "1\n2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1000000000\n5 25 125 625\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 4\n1 3\n", "output": "2\n0 2\n", "metadata": {"func_name": null... | livecodebench | deepcoder_134 | 134 |
Solve the following coding problem using the programming language python:
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white a... | [
"```python\ndef init_factorials(N, mod):\n f = 1\n fac = [1] * N\n for i in range(1, N):\n f *= i\n f %= mod\n fac[i] = f\n return fac\n\ndef init_inv(N, mod, fac):\n b = bin(mod-2)[2:][-1::-1]\n ret = 1\n tmp = fac[N]\n if b[0] == '1':\n ret = fac[N]\n for bi ... | [{"type": "stdin_stdout", "input": "3 4 2\n2 2\n2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "100 100 3\n15 16\n16 15\n99 88\n", "output": "545732279\n"}, {"type": "stdin_stdout", "input": "1000 1000 4\n50 50\n51 50\n50 51\n51 51\n", "output": "899660737\n"}, {"type": "stdin_stdout", "input": "100000 100... | 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:
Giant chess is quite common in Geraldion. We will not delv... | [{"type": "stdin_stdout", "input": "3 4 2\n2 2\n2 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "100 100 3\n15 16\n16 15\n99 88\n", "output": "545732279\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1000 1000 4\n50 50\n51 50\n50 51\n51 51\n", "outp... | livecodebench | deepcoder_135 | 135 |
Solve the following coding problem using the programming language python:
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.
In this game there are n objects numbered from 1 to n arranged in... | [
"```python\nf = lambda: list(map(int, input().split()))[1:]\nn = int(input())\ns, p, q = [], [], []\nfor x in [0, 1]:\n r = f()\n s.append(r)\n t = [len(r)] * n\n t[0] = 0\n p.append(t)\n q.append((x, 0))\nwhile q:\n x, i = q.pop()\n y = 1 - x\n for d in s[y]:\n j = (i - d) % n\n ... | [{"type": "stdin_stdout", "input": "5\n2 3 2\n3 1 2 3\n", "output": "Lose Win Win Loop\nLoop Win Win Win\n"}, {"type": "stdin_stdout", "input": "8\n4 6 2 3 4\n2 3 6\n", "output": "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose\n"}, {"type": "stdin_stdout", "input": "10\n3 4 7 5\n2 8 5\n", "output": "Win ... | 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:
Rick and Morty are playing their own version of Berzerk (w... | [{"type": "stdin_stdout", "input": "5\n2 3 2\n3 1 2 3\n", "output": "Lose Win Win Loop\nLoop Win Win Win\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8\n4 6 2 3 4\n2 3 6\n", "output": "Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose\n", "metadata": {"func_name": null}}, {"type"... | livecodebench | deepcoder_136 | 136 |
Solve the following coding problem using the programming language python:
A function $f : R \rightarrow R$ is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all $x, y \in R$. We'll deal with a more... discrete version of this term.
For an array $... | [
"```python\ndef read_data():\n n, q = map(int, input().split())\n As = list(map(int, input().split()))\n LRs = []\n for i in range(q):\n L, R = list(map(int, input().split()))\n LRs.append((L, R))\n return n, q, As, LRs\n\ndef solve(n, q, As, LRs):\n difs = calc_difs(As)\n Ls = ge... | [{"type": "stdin_stdout", "input": "10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9\n", "output": "17\n82\n23\n210\n"}, {"type": "stdin_stdout", "input": "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5\n", "output": "2\n0\n22\n59\n16\n8\n"}, {"type": "stdin_stdout", "input": "2 2\n0 0\n1 2\n1 2\n", "output": "0\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:
A function $f : R \rightarrow R$ is called Lipschitz conti... | [{"type": "stdin_stdout", "input": "10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9\n", "output": "17\n82\n23\n210\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5\n", "output": "2\n0\n22\n59\n16\n8\n", "metadata": {"func_name": null}}, {"type": "s... | livecodebench | deepcoder_137 | 137 |
Solve the following coding problem using the programming language python:
You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$.
Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$.
-----Input-----
The firs... | [
"```python\ndef check(num1, num2, p, k):\n v = num1 + num2\n v *= num1 * num1 + num2 * num2\n v %= p\n v += p\n v %= p\n return v == k % p\n\ndef __starting_point():\n\n n, p, k = (int(x) for x in input().split())\n idx___number = [int(x) for x in input().split()]\n\n idx___precount = [((... | [{"type": "stdin_stdout", "input": "3 3 0\n0 1 2\n", "output": "1"}, {"type": "stdin_stdout", "input": "6 7 2\n1 2 3 4 5 6\n", "output": "3"}, {"type": "stdin_stdout", "input": "5 5 3\n3 0 4 1 2\n", "output": "1"}, {"type": "stdin_stdout", "input": "7 7 3\n4 0 5 3 1 2 6\n", "output": "0"}, {"type": "stdin_stdout", "inp... | 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 prime number $p$, $n$ integers $a_1, a_2, ... | [{"type": "stdin_stdout", "input": "3 3 0\n0 1 2\n", "output": "1", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 7 2\n1 2 3 4 5 6\n", "output": "3", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 5 3\n3 0 4 1 2\n", "output": "1", "metadata": {"func_name": null}}, {"type... | livecodebench | deepcoder_138 | 138 |
Solve the following coding problem using the programming language python:
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough ca... | [
"```python\nimport heapq\n\ndef sum_sqaure(a, k):\n q, r = divmod(a, k)\n return q**2 * (k-r) + (q+1)**2 * r\n\ndef diff(a, k):\n return sum_sqaure(a, k+1) - sum_sqaure(a, k)\n\nn, k = map(int, input().split())\nnums = list(map(int, input().split()))\n\ncurr = sum(sum_sqaure(a, 1) for a in nums)\nQ = [(dif... | [{"type": "stdin_stdout", "input": "3 6\n5 3 1\n", "output": "15\n"}, {"type": "stdin_stdout", "input": "1 4\n19\n", "output": "91\n"}, {"type": "stdin_stdout", "input": "1 3\n1000000\n", "output": "333333333334\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 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:
There are some rabbits in Singapore Zoo. To feed them, Zoo... | [{"type": "stdin_stdout", "input": "3 6\n5 3 1\n", "output": "15\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 4\n19\n", "output": "91\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 3\n1000000\n", "output": "333333333334\n", "metadata": {"func_name": null}}, {"ty... | livecodebench | deepcoder_139 | 139 |
Solve the following coding problem using the programming language python:
Let's assume that v(n) is the largest prime number, that does not exceed n;
u(n) is the smallest prime number strictly greater than n.
Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$.
-----Input-----
The first line contains integer t (1 ≤ t... | [
"```python\ndef prime(n):\n m = int(n ** 0.5) + 1\n t = [1] * (n + 1)\n for i in range(3, m):\n if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)\n return [2] + [i for i in range(3, n + 1, 2) if t[i]]\n\ndef gcd(a, b):\n c = a % b\n return gcd(b, c) if c else b\n\np = prime(31... | [{"type": "stdin_stdout", "input": "2\n2\n3\n", "output": "1/6\n7/30\n"}, {"type": "stdin_stdout", "input": "1\n1000000000\n", "output": "999999941999999673/1999999887999999118\n"}, {"type": "stdin_stdout", "input": "5\n3\n6\n9\n10\n5\n", "output": "7/30\n5/14\n61/154\n9/22\n23/70\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:
Let's assume that v(n) is the largest prime number, that... | [{"type": "stdin_stdout", "input": "2\n2\n3\n", "output": "1/6\n7/30\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1000000000\n", "output": "999999941999999673/1999999887999999118\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n3\n6\n9\n10\n5\n", "output": "7/30... | livecodebench | deepcoder_140 | 140 |
Solve the following coding problem using the programming language python:
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types: ... | [
"```python\nfrom itertools import starmap\n\n\ndef main():\n n, q = list(map(int, input().split()))\n\n a = list(range(n + 1))\n flipped = False\n start = 0\n end = n\n\n for _ in range(q):\n cmd, *args = list(map(int, input().split()))\n\n if cmd == 1:\n p = args[0]\n ... | [{"type": "stdin_stdout", "input": "7 4\n1 3\n1 2\n2 0 1\n2 1 2\n", "output": "4\n3\n"}, {"type": "stdin_stdout", "input": "10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n", "output": "7\n2\n10\n4\n5\n"}, {"type": "stdin_stdout", "input": "10 5\n2 1 9\n2 4 10\n1 1\n2 0 1\n2 0 1\n", "output": "8\n6\n2\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:
Appleman has a very big sheet of paper. This sheet has a f... | [{"type": "stdin_stdout", "input": "7 4\n1 3\n1 2\n2 0 1\n2 1 2\n", "output": "4\n3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n", "output": "7\n2\n10\n4\n5\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "... | livecodebench | deepcoder_141 | 141 |
Solve the following coding problem using the programming language python:
Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}.
Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from ... | [
"```python\nn, p, q = input(), set(), set()\nfor i in map(int, input().split()):\n q = set(i | j for j in q)\n q.add(i)\n p.update(q)\nprint(len(p))\n```"
] | [{"type": "stdin_stdout", "input": "3\n1 2 0\n", "output": "4"}, {"type": "stdin_stdout", "input": "10\n1 2 3 4 5 6 1 2 9 10\n", "output": "11"}, {"type": "stdin_stdout", "input": "1\n123\n", "output": "1"}, {"type": "stdin_stdout", "input": "10\n6 8 4 5 1 9 10 2 3 7\n", "output": "15"}, {"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:
Polycarpus has a sequence, consisting of n non-negative in... | [{"type": "stdin_stdout", "input": "3\n1 2 0\n", "output": "4", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n1 2 3 4 5 6 1 2 9 10\n", "output": "11", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n123\n", "output": "1", "metadata": {"func_name": null}}, {"type": "std... | livecodebench | deepcoder_142 | 142 |
Solve the following coding problem using the programming language python:
Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price.
At every mome... | [
"```python\nimport heapq\n\nn = int(input())\n\nbuy = [] # negative\nsell = []\nunknown = []\n\nres = 1\nfor i in range(n):\n cmd, amount = input().strip().split()\n amount = int(amount)\n if cmd == 'ADD':\n if sell and sell[0] < amount:\n heapq.heappush(sell, amount)\n elif buy a... | [{"type": "stdin_stdout", "input": "6\nADD 1\nACCEPT 1\nADD 2\nACCEPT 2\nADD 3\nACCEPT 3\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4\nADD 1\nADD 2\nADD 3\nACCEPT 2\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\nADD 1\nADD 2\nADD 3\nADD 4\nADD 5\nACCEPT 3\nACCEPT 5\n", "output": "0\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:
Let's consider a simplified version of order book of some ... | [{"type": "stdin_stdout", "input": "6\nADD 1\nACCEPT 1\nADD 2\nACCEPT 2\nADD 3\nACCEPT 3\n", "output": "8\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\nADD 1\nADD 2\nADD 3\nACCEPT 2\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\nADD 1\nADD 2\nA... | livecodebench | deepcoder_143 | 143 |
Solve the following coding problem using the programming language python:
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do... | [
"```python\nn = int(input())\ns = list(map(int,input().split(' ')))\na = []\nfor i in range(max(s)):\n a.append([]) \nfor i in range(len(s)):\n a[s[i]-1].append(i)\na = list([x for x in a if x != []])\nif len(a) > 1:\n for i in range(1,len(a)):\n if len(a[i]) > 1:\n s = a[i-1][-1]\n ... | [{"type": "stdin_stdout", "input": "4\n6 3 1 2\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "1\n1000\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7\n3 3 3 3 3 3 3\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 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:
Vasily has a deck of cards consisting of n cards. There is... | [{"type": "stdin_stdout", "input": "4\n6 3 1 2\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1000\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n3 3 3 3 3 3 3\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "std... | livecodebench | deepcoder_144 | 144 |
Solve the following coding problem using the programming language python:
The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., ... | [
"```python\ninp = input().split(' ')\nval=[];\n\ntotNums = int(inp[0]); totOpt = int(inp[1]);\ninp = input().split(' '); #assert(len(inp) == totNums);\nfor it in inp: val.append(int(it))\n\ndp = [[0.0 for _ in range(0,totNums)] for __ in range(0,totNums)]\nfor i in range(0,totNums):\n for j in range(0,totNums):\... | [{"type": "stdin_stdout", "input": "2 1\n1 2\n1 2\n", "output": "0.500000000\n"}, {"type": "stdin_stdout", "input": "4 3\n1 3 2 4\n1 2\n2 3\n1 4\n", "output": "3.000000000\n"}, {"type": "stdin_stdout", "input": "7 4\n7 6 4 2 1 5 3\n1 3\n2 1\n7 2\n3 5\n", "output": "11.250000000\n"}, {"type": "stdin_stdout", "input": "1... | 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 loves permutations of integers from 1 ... | [{"type": "stdin_stdout", "input": "2 1\n1 2\n1 2\n", "output": "0.500000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 3\n1 3 2 4\n1 2\n2 3\n1 4\n", "output": "3.000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7 4\n7 6 4 2 1 5 3\n1 3\n2 1\n7 2\n3 5\n",... | livecodebench | deepcoder_145 | 145 |
Solve the following coding problem using the programming language python:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from ... | [
"```python\nq, b, c = list(map(int, input().split()))\nn = int(input())\na = list(map(int, input().split()))\nans = 0\nfor i in a:\n\tif b < i < c:\n\t\tans += 1\nprint(ans)\n\n```"
] | [{"type": "stdin_stdout", "input": "5 3 7\n8\n4 7 5 5 3 6 2 8\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6 5 7\n5\n1 5 7 92 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3 2 4\n1\n3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6\n", "output": "8\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 robber has attempted to rob a bank but failed to complet... | [{"type": "stdin_stdout", "input": "5 3 7\n8\n4 7 5 5 3 6 2 8\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 5 7\n5\n1 5 7 92 3\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 2 4\n1\n3\n", "output": "1\n", "metadata": {"func_name"... | livecodebench | deepcoder_146 | 146 |
Solve the following coding problem using the programming language python:
There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when o... | [
"```python\ndef solve():\n n1, m, a, d = list(map(int, input().split()))\n t = list(map(int, input().split()))\n from bisect import insort\n from math import floor\n insort(t, a * n1)\n pred = 0\n k = 0\n kpred = 0\n n = 0\n step = d // a + 1\n sol = 0\n fl = 0\n for i in t:\n... | [{"type": "stdin_stdout", "input": "1 1 3 4\n7\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 3 4 2\n7 9 11\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "70 10 26 17\n361 371 579 585 629 ... | 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 is an automatic door at the entrance of a factory. T... | [{"type": "stdin_stdout", "input": "1 1 3 4\n7\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 3 4 2\n7 9 11\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n", "output": "6\n", "me... | livecodebench | deepcoder_147 | 147 |
Solve the following coding problem using the programming language python:
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will... | [
"```python\nn = int(input())\n\na = list(map(int, input().split()))\n\nlp,rp = [0 for i in range(n)],[0 for i in range(n)]\nlnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)]\nmx = a[0]\nfor i in range(1,n):\n if a[i] > mx:\n mx = a[i]\n lp[i] = lp[i-1]\n else:\n mx += 1\n ... | [{"type": "stdin_stdout", "input": "5\n1 4 3 2 5\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "5\n1 2 2 2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7\n10 20 40 50 70 90 30\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "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:
Polycarp plans to conduct a load testing of its new projec... | [{"type": "stdin_stdout", "input": "5\n1 4 3 2 5\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 2 2 2 1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n10 20 40 50 70 90 30\n", "output": "0\n", "metadata": {"func_name": null}},... | livecodebench | deepcoder_148 | 148 |
Solve the following coding problem using the programming language python:
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided t... | [
"```python\noleg = input()\nigor = input()\noleg = sorted(list(oleg))\nigor = sorted(list(igor))\nn = len(oleg)\noleg_turns = (n + 1) // 2\nigor_turns = n // 2\nmin_oleg_id = 0\nmin_igor_id = n - igor_turns\nans = ['?'] * n\nmax_oleg_id = oleg_turns - 1 \nmax_igor_id = n - 1\ncurr_turn = 'o'\nnext_turn = {'o' : 'i'... | [{"type": "stdin_stdout", "input": "tinkoff\nzscoder\n", "output": "fzfsirk\n"}, {"type": "stdin_stdout", "input": "xxxxxx\nxxxxxx\n", "output": "xxxxxx\n"}, {"type": "stdin_stdout", "input": "ioi\nimo\n", "output": "ioi\n"}, {"type": "stdin_stdout", "input": "abc\naaa\n", "output": "aab\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:
Oleg the client and Igor the analyst are good friends. How... | [{"type": "stdin_stdout", "input": "tinkoff\nzscoder\n", "output": "fzfsirk\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "xxxxxx\nxxxxxx\n", "output": "xxxxxx\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "ioi\nimo\n", "output": "ioi\n", "metadata": {"func_name": nul... | livecodebench | deepcoder_149 | 149 |
Solve the following coding problem using the programming language python:
We start with a string $s$ consisting only of the digits $1$, $2$, or $3$. The length of $s$ is denoted by $|s|$. For each $i$ from $1$ to $|s|$, the $i$-th character of $s$ is denoted by $s_i$.
There is one cursor. The cursor's location $\ell... | [
"```python\nimport sys\nmod = 10**9 + 7\n\nfor _ in range(int(input())):\n x = int(input())\n s = list(map(int, input()))\n ans = len(s)\n for i in range(1, x+1):\n ans = (i + (ans-i) * s[i-1]) % mod\n r = len(s)\n for _ in range(s[i-1]-1):\n if len(s) < x:\n ... | [{"type": "stdin_stdout", "input": "4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n", "output": "25\n1438\n1101\n686531475\n"}, {"type": "stdin_stdout", "input": "9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\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:
We start with a string $s$ consisting only of the digits $... | [{"type": "stdin_stdout", "input": "4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n", "output": "25\n1438\n1101\n686531475\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\... | livecodebench | deepcoder_150 | 150 |
Solve the following coding problem using the programming language python:
This is an easier version of the next problem. In this version, $q = 0$.
A sequence of integers is called nice if its elements are arranged in blocks like in $[3, 3, 3, 4, 1, 1]$. Formally, if two elements are equal, everything in between must ... | [
"```python\nn, _q = map(int, input().split())\nmni = [-1] * 200001\nmxi = [-1] * 200001\ncnt = [0] * 200001\nnd = 0\na = list(map(int, input().split()))\nfor i, v in enumerate(a):\n if mni[v] == -1: mni[v] = i; nd += 1\n mxi[v] = i\n cnt[v] += 1\nr = 0\nz = 0\ncurrmax = 0\nfor i, v in enumerate(a):\n if... | [{"type": "stdin_stdout", "input": "5 0\n3 7 3 7 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "10 0\n1 2 1 2 3 1 1 1 50 1\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6 0\n6 6 3 3 4 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "7 0\n3 3 1 3 2 1 2\n", "output": "4\n"}, {"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:
This is an easier version of the next problem. In this ver... | [{"type": "stdin_stdout", "input": "5 0\n3 7 3 7 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10 0\n1 2 1 2 3 1 1 1 50 1\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 0\n6 6 3 3 4 4\n", "output": "0\n", "metadata": {"func_name"... | livecodebench | deepcoder_151 | 151 |
Solve the following coding problem using the programming language python:
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.
Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of c... | [
"```python\nn, m = list(map(int, input().split()))\ng = [[] for _ in range(n)]\nfor i in range(m):\n p, q = list(map(int, input().split()))\n g[p - 1].append(q - 1)\n g[q - 1].append(p - 1)\n\ncomp = [-1] * n\ndef shortest(root):\n dist = [-1] * n\n q = [0] * n\n left, right = 0, 1\n q[left] = ... | [{"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n3 5\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4 2\n1 3\n2 4\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "1 0\n", "output": "0\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:
Vova and Marina love offering puzzles to each other. Today... | [{"type": "stdin_stdout", "input": "5 4\n1 2\n2 3\n3 4\n3 5\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 6\n1 2\n2 3\n1 3\n3 4\n2 4\n1 4\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 2\n1 3\n2 4\n", "output": "2\n", "metadata"... | livecodebench | deepcoder_152 | 152 |
Solve the following coding problem using the programming language python:
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the gre... | [
"```python\n\"\"\"\nCodeforces Round 257 Div 1 Problem C\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": "6\n", "output": "2\n6 3\n2 4\n"}, {"type": "stdin_stdout", "input": "9\n", "output": "3\n9 3\n2 4\n6 8\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "10\n", "output": "4\n2 4\n6 8\n10 5\n9 3\n"}, {"type": "stdin_stdout", "input": "1... | 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:
Jzzhu has picked n apples from his big apple tree. All the... | [{"type": "stdin_stdout", "input": "6\n", "output": "2\n6 3\n2 4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "9\n", "output": "3\n9 3\n2 4\n6 8\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_st... | livecodebench | deepcoder_153 | 153 |
Solve the following coding problem using the programming language python:
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: + a_{i} — add non-negative integer a_{i}... | [
"```python\nfrom sys import stdin\n\n\ndef main():\n cnt = [0] * 2 ** 18\n t = str.maketrans(\"0123456789\", \"0101010101\")\n _, *l = stdin.read().splitlines()\n for sign, s in map(str.split, l):\n if sign == '?':\n print(cnt[int(s, 2)])\n else:\n cnt[int(s.translate... | [{"type": "stdin_stdout", "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "output": "2\n1\n2\n1\n1\n"}, {"type": "stdin_stdout", "input": "4\n+ 200\n+ 200\n- 200\n? 0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\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:
Today Sonya learned about long integers and invited all he... | [{"type": "stdin_stdout", "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "output": "2\n1\n2\n1\n1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n+ 200\n+ 200\n- 200\n? 0\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_... | livecodebench | deepcoder_154 | 154 |
Solve the following coding problem using the programming language python:
You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}.
-----Input-----
The first line conta... | [
"```python\ndef main():\n input()\n aa = sorted(map(int, input().split()))\n maxa = max(aa)\n m = [False] * (maxa + 1)\n x = []\n b = 0\n for a in aa:\n if b != a:\n m[a] = True\n for i in range(b, a):\n x.append(b)\n b = a\n x.append(b)... | [{"type": "stdin_stdout", "input": "3\n3 4 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n1 2 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n1000000\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2\n1000000 999999\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 a sequence a consisting of n integers. Find ... | [{"type": "stdin_stdout", "input": "3\n3 4 5\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 2 4\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "... | livecodebench | deepcoder_155 | 155 |
Solve the following coding problem using the programming language python:
There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within dis... | [
"```python\nn = int(input())\npos_blast = [list(map(int, input().split())) for _ in range(n)]\nMAX_N = max(pos_blast, key=lambda x: x[0])[0] + 2\npower = [0 for _ in range(MAX_N)]\ntower = [False for _ in range(MAX_N)]\ncan_destroy = [0 for _ in range(MAX_N)]\nfor pos, blast in pos_blast:\n pos += 1\n tower[p... | [{"type": "stdin_stdout", "input": "4\n1 9\n3 1\n6 1\n7 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "1\n0 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "1\n0 1000000\n", "output": "0\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:
There are n beacons located at distinct positions on a num... | [{"type": "stdin_stdout", "input": "4\n1 9\n3 1\n6 1\n7 4\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n0 1\n", "output": "0\n", "metadata": {"fun... | livecodebench | deepcoder_156 | 156 |
Solve the following coding problem using the programming language python:
John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.
There are $n$ stu... | [
"```python\ndef main():\n n = int(input())\n scores = []\n for i in range(n):\n a = list(map(int, input().split()))\n tot = sum(a)\n scores.append((-tot, i))\n\n scores.sort()\n for i in range(n):\n if scores[i][1] == 0:\n print(i + 1)\n\nmain()\n\n```"
] | [{"type": "stdin_stdout", "input": "5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "1\n0 0 0 0\... | 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:
John Smith knows that his son, Thomas Smith, is among the ... | [{"type": "stdin_stdout", "input": "5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0\n", "output": "1\n", "metadata": {"... | livecodebench | deepcoder_157 | 157 |
Solve the following coding problem using the programming language python:
Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number... | [
"```python\nn = int(input())\npos,tree,ans,sz = list(map(int,input().split())) if n > 1 else [],[],[],[]\nfor i in range(n):\n tree.append([])\n ans.append(0.0)\n sz.append(0)\n\nfor i in range(n-1):\n tree[pos[i]-1].append(i+1)\n\nfor i in range(n)[::-1]:\n sz[i] = 1\n for to in tree[i]:\n sz[i] += sz[to]... | [{"type": "stdin_stdout", "input": "7\n1 2 1 1 4 4\n", "output": "1.0 4.0 5.0 3.5 4.5 5.0 5.0 \n"}, {"type": "stdin_stdout", "input": "12\n1 1 2 2 4 4 3 3 1 10 8\n", "output": "1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 \n"}, {"type": "stdin_stdout", "input": "3\n1 2\n", "output": "1.0 2.0 3.0 \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:
Barney lives in country USC (United States of Charzeh). US... | [{"type": "stdin_stdout", "input": "7\n1 2 1 1 4 4\n", "output": "1.0 4.0 5.0 3.5 4.5 5.0 5.0 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "12\n1 1 2 2 4 4 3 3 1 10 8\n", "output": "1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout"... | livecodebench | deepcoder_158 | 158 |
Solve the following coding problem using the programming language python:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in... | [
"```python\nfrom collections import Counter\n\nn = int(input())\na = list(map(int, input().split()))\nc = Counter(a)\n\nres = 0\ncur = 0\nfor i in sorted(c.keys()):\n d = min(c[i], cur)\n cur -= d\n res += d\n cur += c[i]\n\nprint(res)\n```"
] | [{"type": "stdin_stdout", "input": "7\n10 1 1 1 5 5 3\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "5\n1 1 1 1 1\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10\n1 2 3 4 5 6 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:
You are given an array of integers. Vasya can permute (cha... | [{"type": "stdin_stdout", "input": "7\n10 1 1 1 5 5 3\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 1 1 1 1\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000\n", "outp... | livecodebench | deepcoder_159 | 159 |
Solve the following coding problem using the programming language python:
You are given a string S of length n with each character being one of the first m lowercase English letters.
Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of L... | [
"```python\nn, m = list(map(int, input().split()))\ns = input()\np = c = 0\nfor i in range(1, n):\n if s[i] == s[i - 1]:\n c += n * (m - 1)\n p = i\n elif s[i] != s[i - 2]:\n p = i - 1\n c += i - p\nans = n * n * (m - 1) - c\nprint(ans)\n\n```"
] | [{"type": "stdin_stdout", "input": "3 3\naaa\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "3 3\naab\n", "output": "11\n"}, {"type": "stdin_stdout", "input": "1 2\na\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "10 9\nabacadefgh\n", "output": "789\n"}, {"type": "stdin_stdout", "input": "15 3\nababa... | 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 string S of length n with each character b... | [{"type": "stdin_stdout", "input": "3 3\naaa\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\naab\n", "output": "11\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 2\na\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout"... | livecodebench | deepcoder_160 | 160 |
Solve the following coding problem using the programming language python:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "... | [
"```python\nn = int(input())\ns = set()\n\n\nfor a in range(n):\n name = input()\n\n name = name.replace('u', 'oo')\n\n while (name.count('kh') > 0):\n name = name.replace('kh', 'h')\n s.add(name)\n\nprint(len(s))\n\n```"
] | [{"type": "stdin_stdout", "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "output": "5\n"}, {"type": "stdin_stdout", "input": "2\nalex\nale... | 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 ambiguities when one writes Berland names w... | [{"type": "stdin_stdout", "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "output": "5\n", "metadata": {"f... | livecodebench | deepcoder_161 | 161 |
Solve the following coding problem using the programming language python:
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
[Image]
T... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nn, k = list(map(int, input().split()))\n\nbegin = [-1] * n\nend = [-1] * n\nhurt = [-1] * n\n\nadj = [[] for i in range(n)]\nfor _ in range(n-1):\n u ,v = list(map(int, input().split()))\n adj[u-1].append(v-1)\n adj[v-1].append(u-1)\n\nhurt[0] = 1\nbegi... | [{"type": "stdin_stdout", "input": "7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n", "output": "7"}, {"type": "stdin_stdout", "input": "4 1\n1 2\n1 3\n2 4\n", "output": "2"}, {"type": "stdin_stdout", "input": "8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n4 5\n", "output": "9"}, {"type": "stdin_stdout", "input": "2 1\n1 2\n", "output": "1"}... | 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:
Writing light novels is the most important thing in Linova... | [{"type": "stdin_stdout", "input": "7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n", "output": "7", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1\n1 2\n1 3\n2 4\n", "output": "2", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n4 5\n", "output": "9... | livecodebench | deepcoder_162 | 162 |
Solve the following coding problem using the programming language python:
You are given a sequence of n integers a_1, a_2, ..., a_{n}.
Determine a real number x such that the weakness of the sequence a_1 - x, a_2 - x, ..., a_{n} - x is as small as possible.
The weakness of a sequence is defined as the maximum value... | [
"```python\nimport sys\nn = int(sys.stdin.readline())\na = [int(x) for x in sys.stdin.readline().split()]\n\neps = 1e-12\n\ndef f(x):\n mx = a[0] - x\n tsmx = 0.0\n mn = a[0] - x\n tsmn = 0.0\n for ai in a:\n tsmx = max(tsmx + ai - x, ai - x)\n mx = max(tsmx, mx)\n tsmn = min(tsm... | [{"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "1.000000000000000\n"}, {"type": "stdin_stdout", "input": "4\n1 2 3 4\n", "output": "2.000000000000000\n"}, {"type": "stdin_stdout", "input": "10\n1 10 2 9 3 8 4 7 5 6\n", "output": "4.500000000000000\n"}, {"type": "stdin_stdout", "input": "1\n-10000\n", "outpu... | 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 sequence of n integers a_1, a_2, ..., a_{n... | [{"type": "stdin_stdout", "input": "3\n1 2 3\n", "output": "1.000000000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 2 3 4\n", "output": "2.000000000000000\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n1 10 2 9 3 8 4 7 5 6\n", "output": "4.5000000000... | livecodebench | deepcoder_163 | 163 |
Solve the following coding problem using the programming language python:
An array of integers $p_{1},p_{2}, \ldots,p_{n}$ is called a permutation if it contains each number from $1$ to $n$ exactly once. For example, the following arrays are permutations: $[3,1,2], [1], [1,2,3,4,5]$ and $[4,3,1,2]$. The following arra... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nn=int(input())\nA=list(map(int,input().split()))\n\nBIT=[0]*(n+1)\n\ndef update(v,w):\n while v<=n:\n BIT[v]+=w\n v+=(v&(-v))\n\ndef getvalue(v):\n ANS=0\n while v!=0:\n ANS+=BIT[v]\n v-=(v&(-v))\n return ANS\n\nfor i in r... | [{"type": "stdin_stdout", "input": "3\n0 0 0\n", "output": "3 2 1\n"}, {"type": "stdin_stdout", "input": "2\n0 1\n", "output": "1 2\n"}, {"type": "stdin_stdout", "input": "5\n0 1 1 1 10\n", "output": "1 4 3 2 5\n"}, {"type": "stdin_stdout", "input": "1\n0\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "15\n0 0... | 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:
An array of integers $p_{1},p_{2}, \ldots,p_{n}$ is called... | [{"type": "stdin_stdout", "input": "3\n0 0 0\n", "output": "3 2 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n0 1\n", "output": "1 2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n0 1 1 1 10\n", "output": "1 4 3 2 5\n", "metadata": {"func_name": null}}, {"typ... | livecodebench | deepcoder_164 | 164 |
Solve the following coding problem using the programming language python:
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as p_{i}. For all pairs of distinct integers i, j between 1 and n, he wrote the number a_{i}, j = min(p_{i}, p_{j}). He writes a_{... | [
"```python\ndef main():\n n = int(input())\n a = [[int(i) for i in input().split()] for j in range(n)]\n \n result = [-1] * n\n for i in range(n - 1):\n for j in range(n):\n d = set(a[j][k] for k in range(n) if result[k] == -1 and j != k)\n if len(d) == 1:\n ... | [{"type": "stdin_stdout", "input": "2\n0 1\n1 0\n", "output": "2 1\n"}, {"type": "stdin_stdout", "input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n", "output": "2 5 4 1 3\n"}, {"type": "stdin_stdout", "input": "10\n0 1 5 2 5 3 4 5 5 5\n1 0 1 1 1 1 1 1 1 1\n5 1 0 2 6 3 4 6 6 6\n2 1 2 0 2 2 2 2 2 2\n5 1... | 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 has a permutation of integers from 1 to n. Denote this... | [{"type": "stdin_stdout", "input": "2\n0 1\n1 0\n", "output": "2 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n", "output": "2 5 4 1 3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n0 1 5 2 5 3 4 5 5 5\n... | livecodebench | deepcoder_165 | 165 |
Solve the following coding problem using the programming language python:
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged ... | [
"```python\nn = int(input())\na = list(map(int, input().split()))\np = [0] * (n + 1)\nans = [1] * (n + 1)\nind = n\nfor i in range(n):\n p[a[i] - 1] = 1\n while ind > 0 and p[ind - 1] == 1:\n ind -= 1\n ans[i + 1] = 1 + (i + 1) - (n - ind)\nprint(' '.join(map(str, ans)))\n```"
] | [{"type": "stdin_stdout", "input": "4\n1 3 4 2\n", "output": "1 2 3 2 1\n"}, {"type": "stdin_stdout", "input": "8\n6 8 3 4 7 2 1 5\n", "output": "1 2 2 3 4 3 4 5 1\n"}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1 1\n"}, {"type": "stdin_stdout", "input": "11\n10 8 9 4 6 3 5 1 11 7 2\n", "output": "1 2 3 4 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:
Recently, Dima met with Sasha in a philatelic store, and s... | [{"type": "stdin_stdout", "input": "4\n1 3 4 2\n", "output": "1 2 3 2 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8\n6 8 3 4 7 2 1 5\n", "output": "1 2 2 3 4 3 4 5 1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1\n", "output": "1 1\n", "metadata": {"func_nam... | livecodebench | deepcoder_166 | 166 |
Solve the following coding problem using the programming language python:
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to ... | [
"```python\nn=int(input())\nta,tb,da,db=[0]*4\nfor i in range (n):\n t,x,y=list(map(int,input().split()))\n if t==1:\n ta+=(x+y)\n da+=y\n if (t==2):\n tb+=(x+y)\n db+=y \nif (ta-da>=0.5*ta):\n print ('LIVE')\nelse :\n print ('DEAD')\nif (tb-db>=0.5*tb):\n print (... | [{"type": "stdin_stdout", "input": "2\n1 5 5\n2 6 4\n", "output": "LIVE\nLIVE\n"}, {"type": "stdin_stdout", "input": "3\n1 0 10\n2 0 10\n1 10 0\n", "output": "LIVE\nDEAD\n"}, {"type": "stdin_stdout", "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9\n", "output": "DEAD\nLIVE\n"}, {"t... | 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:
Polycarpus is a system administrator. There are two server... | [{"type": "stdin_stdout", "input": "2\n1 5 5\n2 6 4\n", "output": "LIVE\nLIVE\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 0 10\n2 0 10\n1 10 0\n", "output": "LIVE\nDEAD\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10... | livecodebench | deepcoder_167 | 167 |
Solve the following coding problem using the programming language python:
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!
There are $n$ snacks flavors, numbered wit... | [
"```python\n#!usr/bin/env python3\nfrom collections import defaultdict,deque\nfrom heapq import heappush, heappop\nimport sys\nimport math\nimport bisect\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef LS():return [list(x) for x in sys.stdin.readline(... | [{"type": "stdin_stdout", "input": "5 4\n1 2\n4 3\n1 4\n3 4\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "2 1\n1 2\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "100000 12\n8 7\n1 9\n5 4\n11 12\n7 8\n3 4\n3 5\n12 ... | 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 legendary Farmer John is throwing a huge party, and an... | [{"type": "stdin_stdout", "input": "5 4\n1 2\n4 3\n1 4\n3 4\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 1\n1 2\n", "output": "0\n", "metadata": {"func_na... | livecodebench | deepcoder_168 | 168 |
Solve the following coding problem using the programming language python:
You are given a sequence a = \{a_1, ..., a_N\} with all zeros, and a sequence b = \{b_1, ..., b_N\} consisting of 0 and 1. The length of both is N.
You can perform Q kinds of operations. The i-th operation is as follows:
- Replace each of a_{l_... | [
"```python\nimport sys\n\ninput=sys.stdin.readline\n\nn=int(input())\nb=list(map(int,input().split()))\nope=[[] for i in range(n)]\nQ=int(input())\nfor i in range(Q):\n l,r=list(map(int,input().split()))\n ope[r-1].append(l-1)\n\nres=b.count(0)\n\nData=[(-1)**((b[i]==1)+1) for i in range(n)]\nfor i in range(1... | [{"type": "stdin_stdout", "input": "3\n1 0 1\n1\n1 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n1 0 1\n2\n1 1\n3 3\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "3\n1 0 1\n2\n1 1\n2 3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "5\n0 1 0 1 0\n1\n1 5\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:
You are given a sequence a = \{a_1, ..., a_N\} with all ze... | [{"type": "stdin_stdout", "input": "3\n1 0 1\n1\n1 3\n", "output": "1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 0 1\n2\n1 1\n3 3\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n1 0 1\n2\n1 1\n2 3\n", "output": "1\n", "metadata": {"func_nam... | livecodebench | deepcoder_169 | 169 |
Solve the following coding problem using the programming language python:
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he h... | [
"```python\nimport sys\n[n, q] = map(int, sys.stdin.readline().strip().split())\nqis = [int(sys.stdin.readline().strip()) for _ in range(q)]\n\ndef query(n, q):\n\td = 2 * n - q\n\twhile d % 2 == 0:\n\t\td //= 2\n\treturn (n - d // 2)\n\nfor qi in qis:\n\tprint (query(n, qi))\n```"
] | [{"type": "stdin_stdout", "input": "4 3\n2\n3\n4\n", "output": "3\n2\n4\n"}, {"type": "stdin_stdout", "input": "13 4\n10\n5\n4\n8\n", "output": "13\n3\n8\n9\n"}, {"type": "stdin_stdout", "input": "2 2\n1\n2\n", "output": "1\n2\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n", "output": "1\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:
Dima is a beginner programmer. During his working process,... | [{"type": "stdin_stdout", "input": "4 3\n2\n3\n4\n", "output": "3\n2\n4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "13 4\n10\n5\n4\n8\n", "output": "13\n3\n8\n9\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n1\n2\n", "output": "1\n2\n", "metadata": {"func_name... | livecodebench | deepcoder_170 | 170 |
Solve the following coding problem using the programming language python:
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $f(0... | [
"```python\nT = int(input())\nfor t in range(T):\n a, b, n = [int(i) for i in input().split()]\n if n%3 == 2:\n print(a^b)\n elif n%3 == 1:\n print(b)\n else:\n print(a)\n\n```"
] | [{"type": "stdin_stdout", "input": "3\n3 4 2\n4 5 0\n325 265 1231232\n", "output": "7\n4\n76\n"}, {"type": "stdin_stdout", "input": "10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 98532\n1000000000 1000000000 1000000000\n", "output": "0\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:
Cengiz recently learned Fibonacci numbers and now he is st... | [{"type": "stdin_stdout", "input": "3\n3 4 2\n4 5 0\n325 265 1231232\n", "output": "7\n4\n76\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 98532\n1000000000 10000000... | livecodebench | deepcoder_171 | 171 |
Solve the following coding problem using the programming language python:
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.
All the roads are initially bad, but t... | [
"```python\n\n\nclass Graph:\n def __init__(self, n_vertices, edges, directed=True, weighted=False):\n self.n_vertices = n_vertices\n self.edges = edges\n self.directed = directed\n self.weighted = weighted\n\n @property\n def adj(self):\n try:\n return self._a... | [{"type": "stdin_stdout", "input": "3\n1 1\n", "output": "4 3 3"}, {"type": "stdin_stdout", "input": "5\n1 2 3 4\n", "output": "5 8 9 8 5"}, {"type": "stdin_stdout", "input": "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870... | 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 country has n cities and n - 1 bidirectional roads, it... | [{"type": "stdin_stdout", "input": "3\n1 1\n", "output": "4 3 3", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n1 2 3 4\n", "output": "5 8 9 8 5", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": ... | livecodebench | deepcoder_172 | 172 |
Solve the following coding problem using the programming language python:
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city u_{i} to v_{i} (and vise versa) using the i-th road, the ... | [
"```python\n\n\n#===============================================================================================\n#importing some useful libraries.\n\n\n\nfrom fractions import Fraction\nimport sys\nimport os\nfrom io import BytesIO, IOBase\nfrom functools import cmp_to_key\n\n# from itertools import *\nfrom heapq ... | [{"type": "stdin_stdout", "input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444... | 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:
Jzzhu is the president of country A. There are n cities nu... | [{"type": "stdin_stdout", "input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 4 3\n1 2 99... | livecodebench | deepcoder_173 | 173 |
Solve the following coding problem using the programming language python:
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q_1q_2... q_{k}. The algorithm consists of two steps:
Find any c... | [
"```python\nimport sys\ns=sys.stdin.readline().split()[0]\n\nm=int(sys.stdin.readline())\n\nNumx=[]\nNumy=[]\nNumz=[]\nx=0\ny=0\nz=0\nfor i in range(len(s)):\n if(s[i]=='x'):\n x+=1\n if(s[i]=='y'):\n y+=1\n if(s[i]=='z'):\n z+=1\n Numx.append(x)\n Numy.append(y)\n Numz.append... | [{"type": "stdin_stdout", "input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6\n", "output": "YES\nYES\nNO\nYES\nNO\n"}, {"type": "stdin_stdout", "input": "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\n10\n17 67\n6 35\n12 45\n56 56\n14 30\n25 54\n1 1\n46 54\n3 33\n19 40\n", "output": "NO\nNO\nNO\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:
Sereja loves all sorts of algorithms. He has recently come... | [{"type": "stdin_stdout", "input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6\n", "output": "YES\nYES\nNO\nYES\nNO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\n10\n17 67\n6 35\n12 45\n56 56\n14 30\n25 54\n1 1\n46 54\n3 33\n... | livecodebench | deepcoder_174 | 174 |
Solve the following coding problem using the programming language python:
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social se... | [
"```python\nn=int(input())\na=list(map(int,input().split()))\nq=int(input())\nchanges=[0]*q\nfor i in range(q):\n changes[-i-1]=tuple(map(int,input().split()))\nfinal=[-1]*n\ncurr=0\nfor guy in changes:\n if guy[0]==1:\n if final[guy[1]-1]==-1:\n final[guy[1]-1]=max(guy[2],curr)\n else:\n... | [{"type": "stdin_stdout", "input": "4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n", "output": "3 2 3 4 \n"}, {"type": "stdin_stdout", "input": "5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n", "output": "8 8 20 8 10 \n"}, {"type": "stdin_stdout", "input": "10\n1 2 3 4 5 6 7 8 9 10\n10\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\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 is a country with $n$ citizens. The $i$-th of them i... | [{"type": "stdin_stdout", "input": "4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n", "output": "3 2 3 4 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n", "output": "8 8 20 8 10 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n1 2 3 4 5 6 7... | livecodebench | deepcoder_175 | 175 |
Solve the following coding problem using the programming language python:
During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder... | [
"```python\nn, q = map(int, input().split())\ns = '!' + input()\n\nnxt = [[n + 1] * (n + 2) for _ in range(26)]\nfor i in range(n - 1, -1, -1):\n c = ord(s[i + 1]) - 97\n for j in range(26):\n nxt[j][i] = nxt[j][i + 1]\n nxt[c][i] = i + 1\n\nw = [[-1], [-1], [-1]]\nidx = lambda i, j, k: i * 65536 + ... | [{"type": "stdin_stdout", "input": "6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\n"}, {"type": "stdin_stdout", "input": "6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n", "output": "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\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:
During the archaeological research in the Middle East you ... | [{"type": "stdin_stdout", "input": "6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n", "output": "YES\nYES\nY... | livecodebench | deepcoder_176 | 176 |
Solve the following coding problem using the programming language python:
Serge came to the school dining room and discovered that there is a big queue here. There are $m$ pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. A... | [
"```python\nimport sys\nfrom itertools import accumulate \nclass Lazysegtree:\n #RAQ\n def __init__(self, A, intv, initialize = True, segf = min):\n #区間は 1-indexed で管理\n self.N = len(A)\n self.N0 = 2**(self.N-1).bit_length()\n self.intv = intv\n self.segf = segf\n sel... | [{"type": "stdin_stdout", "input": "1 1\n1\n1\n1\n1 1 100\n", "output": "100\n"}, {"type": "stdin_stdout", "input": "1 1\n1\n1\n1\n2 1 100\n", "output": "-1\n"}, {"type": "stdin_stdout", "input": "4 6\n1 8 2 4\n3 3 6 1 5 2\n3\n1 1 1\n2 5 10\n1 1 6\n", "output": "8\n-1\n4\n"}, {"type": "stdin_stdout", "input": "3 5\n3 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:
Serge came to the school dining room and discovered that t... | [{"type": "stdin_stdout", "input": "1 1\n1\n1\n1\n1 1 100\n", "output": "100\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1 1\n1\n1\n1\n2 1 100\n", "output": "-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 6\n1 8 2 4\n3 3 6 1 5 2\n3\n1 1 1\n2 5 10\n1 1 6\n", "o... | livecodebench | deepcoder_177 | 177 |
Solve the following coding problem using the programming language python:
Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.
Sereja takes a blank piece of paper. Then he starts writing out the sequence in m stages. Each time he either adds a new num... | [
"```python\nn=int(input())\na=[]\nfor i in range(n):\n a.append(list(map(int,input().split())))\nm=int(input())\nb=list(map(lambda x:int(x)-1,input().split()))\nc=[]\nnow=0\nk=0\nans=[]\nfor i in range(n):\n t=a[i]\n last=now\n if t[0]==1:\n now+=1\n if len(c)<100000: c.append(t[1])\n ... | [{"type": "stdin_stdout", "input": "6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n", "output": "1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4\n"}, {"type": "stdin_stdout", "input": "2\n1 33085\n1 44638\n2\n1 2\n", "output": "33085 44638\n"}, {"type": "stdin_stdout", "input": "10\n1 57757\n1 45234\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:
Sereja loves number sequences very much. That's why he dec... | [{"type": "stdin_stdout", "input": "6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n", "output": "1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1 33085\n1 44638\n2\n1 2\n", "output": "33085 44638\n", "metadata": {"func_name":... | livecodebench | deepcoder_178 | 178 |
Solve the following coding problem using the programming language python:
The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n c... | [
"```python\ndef dfs(x, y):\n vis.append((x, y))\n y += 1\n nonlocal flag\n if flag or str.isalpha(grid[x][y]):\n return\n if y >= n - 1:\n flag = True\n return\n \n # stay idle\n if not str.isalpha(grid[x][y + 1]) and not str.isalpha(grid[x][y + 2]) and (x, y + 2) not in... | [{"type": "stdin_stdout", "input": "2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n", "output": "YES\nNO\n"}, {"type": "stdin_stdout", "input": "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n....AAAABB\n.YYYYYY...\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:
The mobile application store has a new game called "Subway... | [{"type": "stdin_stdout", "input": "2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n", "output": "YES\nNO\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY...\n10 4\ns.ZZ......\n...... | livecodebench | deepcoder_179 | 179 |
Solve the following coding problem using the programming language python:
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes).
String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters... | [
"```python\n# import atexit\n# import io\n# import sys\n#\n# _INPUT_LINES = sys.stdin.read().splitlines()\n# input = iter(_INPUT_LINES).__next__\n# _OUTPUT_BUFFER = io.StringIO()\n# sys.stdout = _OUTPUT_BUFFER\n#\n#\n# @atexit.register\n# def write():\n# sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())\n\nimport... | [{"type": "stdin_stdout", "input": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "output": "2012-03-16 16:16:43\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've got a list of program warning logs. Each record of ... | [{"type": "stdin_stdout", "input": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "output": "2012-03-16 16:16:43\n... | livecodebench | deepcoder_180 | 180 |
Solve the following coding problem using the programming language python:
Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:
Given two binary numbers $a$ and $b$ of length $n$. How many different ways of swapping two digits in $a$ (only in $a$, not $b$) so tha... | [
"```python\nn = int(input())\na = [int(x) for x in input().strip()]\nb = [int(x) for x in input().strip()]\np, q, r, s = 0, 0, 0, 0\nfor i in range(n):\n if a[i] * 2 + b[i] == 0:\n p += 1\n if a[i] * 2 + b[i] == 1:\n q += 1\n if a[i] * 2 + b[i] == 2:\n r += 1\n if a[i] * 2 + b[i] ==... | [{"type": "stdin_stdout", "input": "5\n01011\n11001\n", "output": "4\n"}, {"type": "stdin_stdout", "input": "6\n011000\n010011\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "10\n0110101101\n1010000101\n", "output": "21\n"}, {"type": "stdin_stdout", "input": "30\n011110110100010000011001000100\n110111101001011... | 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:
Rudolf is on his way to the castle. Before getting into th... | [{"type": "stdin_stdout", "input": "5\n01011\n11001\n", "output": "4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n011000\n010011\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "10\n0110101101\n1010000101\n", "output": "21\n", "metadata": {"func_na... | livecodebench | deepcoder_181 | 181 |
Solve the following coding problem using the programming language python:
For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.
Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true:
- Each string in S has a length b... | [
"```python\nimport sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import deque\n\nclass Node:\n def __init__(self,depth):\n self.depth=depth\n self.left=None\n self.right=None\n\ndef insert(node,s):\n n=node\n for i in range(len(s)):\n t=s[i]\n ... | [{"type": "stdin_stdout", "input": "2 2\n00\n01\n", "output": "Alice\n"}, {"type": "stdin_stdout", "input": "2 2\n00\n11\n", "output": "Bob\n"}, {"type": "stdin_stdout", "input": "3 3\n0\n10\n110\n", "output": "Alice\n"}, {"type": "stdin_stdout", "input": "2 1\n0\n1\n", "output": "Bob\n"}, {"type": "stdin_stdout", "inp... | 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 strings s and t, we will say that s and t are prefix-f... | [{"type": "stdin_stdout", "input": "2 2\n00\n01\n", "output": "Alice\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2 2\n00\n11\n", "output": "Bob\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 3\n0\n10\n110\n", "output": "Alice\n", "metadata": {"func_name": null}},... | livecodebench | deepcoder_182 | 182 |
Solve the following coding problem using the programming language python:
Zookeeper is buying a carton of fruit to feed his pet wabbit. The fruits are a sequence of apples and oranges, which is represented by a binary string $s_1s_2\ldots s_n$ of length $n$. $1$ represents an apple and $0$ represents an orange.
Since... | [
"```python\nclass SegmentTree:\n def __init__(self, data, default=0, func=max):\n \"\"\"initialize the segment tree with data\"\"\"\n self._default = default\n self._func = func\n self._len = len(data)\n self._size = _size = 1 << (self._len - 1).bit_length()\n\n self.dat... | [{"type": "stdin_stdout", "input": "4\n0110\n", "output": "12\n"}, {"type": "stdin_stdout", "input": "7\n1101001\n", "output": "30\n"}, {"type": "stdin_stdout", "input": "12\n011100011100\n", "output": "156\n"}, {"type": "stdin_stdout", "input": "100\n01101100110111110011100001100100100001111110011000010111011010000010... | 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:
Zookeeper is buying a carton of fruit to feed his pet wabb... | [{"type": "stdin_stdout", "input": "4\n0110\n", "output": "12\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1101001\n", "output": "30\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "12\n011100011100\n", "output": "156\n", "metadata": {"func_name": null}}, {"type": ... | livecodebench | deepcoder_183 | 183 |
Solve the following coding problem using the programming language python:
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original charact... | [
"```python\nn, k = map(int, input().split())\na = [0] * n\nb = ['0'] * n\nc = []\ns = input()\nfor i in range(n):\n if k != 0:\n if s[i] == '(':\n c.append(i)\n else:\n d = c.pop()\n a[i] = 1\n a[d] = 1\n k -= 2\nfor i in range(n):\n if a[i]... | [{"type": "stdin_stdout", "input": "6 4\n()(())\n", "output": "()()\n"}, {"type": "stdin_stdout", "input": "8 8\n(()(()))\n", "output": "(()(()))\n"}, {"type": "stdin_stdout", "input": "20 10\n((()))()((()()(())))\n", "output": "((()))()()\n"}, {"type": "stdin_stdout", "input": "40 30\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 bracket sequence is a string containing only characters ... | [{"type": "stdin_stdout", "input": "6 4\n()(())\n", "output": "()()\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "8 8\n(()(()))\n", "output": "(()(()))\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "20 10\n((()))()((()()(())))\n", "output": "((()))()()\n", "metadata"... | livecodebench | deepcoder_184 | 184 |
Solve the following coding problem using the programming language python:
There are $n$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
We want to plan a trip for every evening of $m$ days. On each trip, you have to select a group of people that ... | [
"```python\nfrom collections import deque\n\ndef solve(adj, m, k, uv):\n n = len(adj)\n nn = [len(a) for a in adj]\n q = deque()\n for i in range(n):\n if nn[i] < k:\n q.append(i)\n while q:\n v = q.popleft()\n for u in adj[v]:\n nn[u] -= 1\n if n... | [{"type": "stdin_stdout", "input": "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "output": "0\n0\n3\n3\n"}, {"type": "stdin_stdout", "input": "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "output": "0\n0\n0\n3\n3\n4\n4\n5\n"}, {"type": "stdin_stdout", "input": "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "output": "0\n0\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:
There are $n$ persons who initially don't know each other.... | [{"type": "stdin_stdout", "input": "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "output": "0\n0\n3\n3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "output": "0\n0\n0\n3\n3\n4\n4\n5\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 ... | livecodebench | deepcoder_185 | 185 |
Solve the following coding problem using the programming language python:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t ... | [
"```python\ndef sub(a, s):\n pa = 0\n ps = 0\n while pa < len(a) and ps < len(s):\n if a[pa] == s[ps]:\n ps += 1\n pa += 1\n else:\n pa += 1\n\n return ps == len(s)\n\ndef subword(t, ord_ar, n):\n t_copy = []\n for i in range(len(ord_ar)):\n if... | [{"type": "stdin_stdout", "input": "ababcba\nabb\n5 3 4 1 7 6 2\n", "output": "3"}, {"type": "stdin_stdout", "input": "bbbabb\nbb\n1 6 3 4 2 5\n", "output": "4"}, {"type": "stdin_stdout", "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2\n", "output": "9"}, {"type": "stdin_stdout", "input": "aaaabaaa... | 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 Nastya has a hobby, she likes to remove some letter... | [{"type": "stdin_stdout", "input": "ababcba\nabb\n5 3 4 1 7 6 2\n", "output": "3", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "bbbabb\nbb\n1 6 3 4 2 5\n", "output": "4", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13... | livecodebench | deepcoder_186 | 186 |
Solve the following coding problem using the programming language python:
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p_{i}, a_{i} and b_{i}, where p_{i} is the price of the i-th t-shirt, a_{i} is front color of the i-th t-shirt and b_{i} is back color of the i-th t... | [
"```python\nn = int(input())\n\np = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n\ns = []\nfor i in range(n):\n s.append([p[i], a[i], b[i]])\n\ns = sorted(s)\n\nm = int(input())\nc = [int(i) for i in input().split()]\n\nidx = [0]*4\n\nans = []\n... | [{"type": "stdin_stdout", "input": "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n", "output": "200 400 300 500 911 -1 \n"}, {"type": "stdin_stdout", "input": "2\n1000000000 1\n1 1\n1 2\n2\n2 1\n", "output": "1 1000000000 \n"}, {"type": "stdin_stdout", "input": "10\n251034796 163562337 995167403 5310463... | 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 new pack of n t-shirts came to a shop. Each of the t-shi... | [{"type": "stdin_stdout", "input": "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n", "output": "200 400 300 500 911 -1 \n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n1000000000 1\n1 1\n1 2\n2\n2 1\n", "output": "1 1000000000 \n", "metadata": {"func_name": null}}, {"type": "... | livecodebench | deepcoder_187 | 187 |
Solve the following coding problem using the programming language python:
You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a $r \times c$ grid. Each cell on the grid represents a country. Each country has a dominant religion. There ... | [
"```python\nimport sys \ninput = sys.stdin.readline\n\nMOD = 10**9 + 7\nt = int(input())\n\nfor _ in range(t):\n r, c = list(map(int, input().split()))\n s = [list(input()) for i in range(r)]\n cnt_a = 0\n flag_kado = False\n flag_hen = False\n flag_hen2 = False\n if s[0][0] == \"A\" or s[0][c-... | [{"type": "stdin_stdout", "input": "4\n7 8\nAAPAAAAA\nPPPPAAAA\nPPPPAAAA\nAPAAPPPP\nAPAPPAPP\nAAAAPPAP\nAAAAPPAA\n6 5\nAAAAA\nAAAAA\nAAPAA\nAAPAP\nAAAPP\nAAAPP\n4 4\nPPPP\nPPPP\nPPPP\nPPPP\n3 4\nPPPP\nPAAP\nPPPP\n", "output": "2\n1\nMORTAL\n4\n"}, {"type": "stdin_stdout", "input": "1\n1 1\nA\n", "output": "0\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:
You are an all-powerful being and you have created a recta... | [{"type": "stdin_stdout", "input": "4\n7 8\nAAPAAAAA\nPPPPAAAA\nPPPPAAAA\nAPAAPPPP\nAPAPPAPP\nAAAAPPAP\nAAAAPPAA\n6 5\nAAAAA\nAAAAA\nAAPAA\nAAPAP\nAAAPP\nAAAPP\n4 4\nPPPP\nPPPP\nPPPP\nPPPP\n3 4\nPPPP\nPAAP\nPPPP\n", "output": "2\n1\nMORTAL\n4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n1... | livecodebench | deepcoder_188 | 188 |
Solve the following coding problem using the programming language python:
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '$\sqrt{}$' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Co... | [
"```python\n\"\"\"\nCodeforces Round 372 Div 1 Problem A\n\nAuthor : chaotic_iak\nLanguage: Python 3.5.2\n\"\"\"\n\n################################################### SOLUTION\n\ndef main():\n n, = read()\n curr = 2\n for lv in range(1, n+1):\n tgt = (lv*(lv+1))**2\n print((tgt - curr) // l... | [{"type": "stdin_stdout", "input": "3\n", "output": "2\n17\n46\n"}, {"type": "stdin_stdout", "input": "2\n", "output": "2\n17\n"}, {"type": "stdin_stdout", "input": "4\n", "output": "2\n17\n46\n97\n"}, {"type": "stdin_stdout", "input": "1\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\n", "output": "2\n17\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:
ZS the Coder is playing a game. There is a number displaye... | [{"type": "stdin_stdout", "input": "3\n", "output": "2\n17\n46\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n", "output": "2\n17\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n", "output": "2\n17\n46\n97\n", "metadata": {"func_name": null}}, {"type": "stdin_std... | livecodebench | deepcoder_189 | 189 |
Solve the following coding problem using the programming language python:
The Bubble Cup hypothesis stood unsolved for $130$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem:
Give... | [
"```python\n\nimport os\nimport sys\nfrom io import BytesIO, IOBase\n\n\ndef main():\n pass\n\n\n# region fastio\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = \"x\" in fil... | [{"type": "stdin_stdout", "input": "2\n2 4\n", "output": "2\n4\n"}, {"type": "stdin_stdout", "input": "1\n9\n", "output": "9\n"}, {"type": "stdin_stdout", "input": "5\n4 1 8 3 9\n", "output": "4\n1\n9\n2\n9\n"}, {"type": "stdin_stdout", "input": "6\n8 7 8 6 8 9\n", "output": "9\n6\n9\n6\n9\n9\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:
The Bubble Cup hypothesis stood unsolved for $130$ years. ... | [{"type": "stdin_stdout", "input": "2\n2 4\n", "output": "2\n4\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "1\n9\n", "output": "9\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n4 1 8 3 9\n", "output": "4\n1\n9\n2\n9\n", "metadata": {"func_name": null}}, {"type": ... | livecodebench | deepcoder_190 | 190 |
Solve the following coding problem using the programming language python:
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's ... | [
"```python\nimport sys\nfrom collections import deque\ndef solve():\n sys.setrecursionlimit(10**6)\n readline = sys.stdin.readline\n writelines = sys.stdout.writelines\n N = int(readline())\n G = [[] for i in range(N)]\n for i in range(N-1):\n u, v = map(int, readline().split())\n G[... | [{"type": "stdin_stdout", "input": "4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n", "output": "1\n-1\n1\n-1\n"}, {"type": "stdin_stdout", "input": "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n5\n4 1 3 5 7\n3 2 4 6\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:
Meanwhile, the kingdom of K is getting ready for the marri... | [{"type": "stdin_stdout", "input": "4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n", "output": "1\n-1\n1\n-1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "... | livecodebench | deepcoder_191 | 191 |
Solve the following coding problem using the programming language python:
Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible i... | [
"```python\ndef main():\n def countchildren(graph,vert,memo,pard=None):\n dumi=0\n for child in graph[vert]:\n if child!=pard:\n if len(graph[child])==1:\n memo[child]=0\n else:\n memo[child]=countchildren(graph,child,me... | [{"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "6\n"}, {"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n", "output": "7\n"}, {"type": "stdin_stdout", "input": "2\n2 1\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "3\n2 1\n3 2\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "10\... | 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:
Sergey Semyonovich is a mayor of a county city N and he us... | [{"type": "stdin_stdout", "input": "4\n1 2\n1 3\n1 4\n", "output": "6\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 2\n2 3\n3 4\n", "output": "7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "2\n2 1\n", "output": "1\n", "metadata": {"func_name": null}}, {"type":... | livecodebench | deepcoder_192 | 192 |
Solve the following coding problem using the programming language python:
Let's denote as $\text{popcount}(x)$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤... | [
"```python\ndef popcount(n):\n\tres = 0\n\twhile n > 0:\n\t\tres += n & 1\n\t\tn >>= 2\n\ndef A(l, r):\n\tr += 1\n\tt = 1 << 64\n\twhile t & (l ^ r) == 0:\n\t\tt >>= 1\n\tres = l | (t - 1)\n\t#print(t, res)\n\treturn res\n\ndef __starting_point():\n\t\"\"\"assert(A(1, 2) == 1)\n\tassert(A(2, 4) == 3)\n\tassert(A(1,... | [{"type": "stdin_stdout", "input": "3\n1 2\n2 4\n1 10\n", "output": "1\n3\n7\n"}, {"type": "stdin_stdout", "input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\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:
Let's denote as $\text{popcount}(x)$ the number of bits se... | [{"type": "stdin_stdout", "input": "3\n1 2\n2 4\n1 10\n", "output": "1\n3\n7\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9... | livecodebench | deepcoder_193 | 193 |
Solve the following coding problem using the programming language python:
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) wit... | [
"```python\ndef mat(shape, inital_val=None):\n if len(shape) > 1:\n return [mat(shape[1:], inital_val) for _ in range(shape[0])] \n else:\n return [inital_val] * shape[0]\n \ndef main():\n n, m = [int(x) for x in input().split()]\n graph = [{} for _ in range(n)]\n for _ in r... | [{"type": "stdin_stdout", "input": "4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n", "output": "BAAA\nABAA\nBBBA\nBBBB\n"}, {"type": "stdin_stdout", "input": "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n", "output": "BABBB\nBBBBB\nAABBB\nAAABA\nAAAAB\n"}, {"type": "stdin_stdout", "input": "2 1\n1 2 q\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:
As we all know, Max is the best video game player among he... | [{"type": "stdin_stdout", "input": "4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n", "output": "BAAA\nABAA\nBBBA\nBBBB\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n", "output": "BABBB\nBBBBB\nAABBB\nAAABA\nAAAAB\n", "metadata": {"func_name": nu... | livecodebench | deepcoder_194 | 194 |
Solve the following coding problem using the programming language python:
There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i).
Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates.
In order to collect these balls, Snuke pre... | [
"```python\nimport sys\ninput = sys.stdin.readline\n\nMOD = 10**9 + 7\n\nN = int(input())\nball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())\n\n# x座標を1,2,...,N\n# y座標をN+1,N+2,...,N+N\n\ngraph = [set() for _ in range(N+N+1)]\nfor x,y in ball:\n graph[x].add(y+N)\n graph[y+N].add(x)\n... | [{"type": "stdin_stdout", "input": "2\n1 1\n1 2\n2 1\n2 2\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4\n3 2\n1 2\n4 1\n4 2\n2 2\n4 4\n2 1\n1 3\n", "output": "7392\n"}, {"type": "stdin_stdout", "input": "4\n1 1\n2 2\n3 3\n4 4\n1 2\n2 1\n3 4\n4 3\n", "output": "4480\n"}, {"type": "stdin_stdout", "input": "8... | 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 2N balls in the xy-plane. The coordinates of the... | [{"type": "stdin_stdout", "input": "2\n1 1\n1 2\n2 1\n2 2\n", "output": "8\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n3 2\n1 2\n4 1\n4 2\n2 2\n4 4\n2 1\n1 3\n", "output": "7392\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4\n1 1\n2 2\n3 3\n4 4\n1 2\n2 1\n3 4\... | livecodebench | deepcoder_195 | 195 |
Solve the following coding problem using the programming language python:
There are N robots and M exits on a number line.
The N + M coordinates of these are all integers and all distinct.
For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i.
Also, for each j (1 \leq j \leq M), the coord... | [
"```python\nfrom bisect import bisect\nfrom collections import defaultdict\n\n\nclass Bit:\n def __init__(self, n, MOD):\n self.size = n\n self.tree = [0] * (n + 1)\n self.depth = n.bit_length()\n self.mod = MOD\n\n def sum(self, i):\n s = 0\n while i > 0:\n ... | [{"type": "stdin_stdout", "input": "2 2\n2 3\n1 4\n", "output": "3\n"}, {"type": "stdin_stdout", "input": "3 4\n2 5 10\n1 3 7 13\n", "output": "8\n"}, {"type": "stdin_stdout", "input": "4 1\n1 2 4 5\n3\n", "output": "1\n"}, {"type": "stdin_stdout", "input": "4 5\n2 5 7 11\n1 3 6 9 13\n", "output": "6\n"}, {"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:
There are N robots and M exits on a number line.
The N + M... | [{"type": "stdin_stdout", "input": "2 2\n2 3\n1 4\n", "output": "3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3 4\n2 5 10\n1 3 7 13\n", "output": "8\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "4 1\n1 2 4 5\n3\n", "output": "1\n", "metadata": {"func_name": null}... | livecodebench | deepcoder_196 | 196 |
Solve the following coding problem using the programming language python:
AtCoDeer the deer found N rectangle lying on the table, each with height 1.
If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i]... | [
"```python\n# seishin.py\nN = int(input())\nP = [list(map(int, input().split())) for i in range(N)]\n\nfrom heapq import heappush, heappop\n\nl0, r0 = P[0]\n\nL = [-l0+1]\nR = [l0-1]\ns = t = 0\n\nres = 0\nfor i in range(N-1):\n l0, r0 = P[i]\n l1, r1 = P[i+1]\n s += (r1 - l1); t += (r0 - l0)\n if -s-L[... | [{"type": "stdin_stdout", "input": "3\n1 3\n5 7\n1 3\n", "output": "2\n"}, {"type": "stdin_stdout", "input": "3\n2 5\n4 6\n1 4\n", "output": "0\n"}, {"type": "stdin_stdout", "input": "5\n999999999 1000000000\n1 2\n314 315\n500000 500001\n999999999 1000000000\n", "output": "1999999680\n"}, {"type": "stdin_stdout", "inpu... | 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:
AtCoDeer the deer found N rectangle lying on the table, ea... | [{"type": "stdin_stdout", "input": "3\n1 3\n5 7\n1 3\n", "output": "2\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "3\n2 5\n4 6\n1 4\n", "output": "0\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "5\n999999999 1000000000\n1 2\n314 315\n500000 500001\n999999999 100000... | livecodebench | deepcoder_197 | 197 |
Solve the following coding problem using the programming language python:
In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.
More precisely, two different numbers $a$ and $b$ are friends if $gcd(a,b)$, $\frac{a}{gcd(a,b)}$, $\frac{b}{gcd(a,b)}$ can for... | [
"```python\nimport os\nimport sys\nfrom io import BytesIO, IOBase\n\n\ndef main():\n pass\n\n\n# region fastio\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = \"x\" in file.... | [{"type": "stdin_stdout", "input": "3\n1 5 10\n", "output": "1\n3\n3\n"}, {"type": "stdin_stdout", "input": "6\n12 432 21 199 7 1\n", "output": "4\n76\n7\n41\n4\n1\n"}, {"type": "stdin_stdout", "input": "7\n1 10 100 1000 10000 100000 1000000\n", "output": "1\n3\n22\n158\n1205\n9528\n78331\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:
In number world, two different numbers are friends if they... | [{"type": "stdin_stdout", "input": "3\n1 5 10\n", "output": "1\n3\n3\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "6\n12 432 21 199 7 1\n", "output": "4\n76\n7\n41\n4\n1\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "7\n1 10 100 1000 10000 100000 1000000\n", "output"... | livecodebench | deepcoder_198 | 198 |
Solve the following coding problem using the programming language python:
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>]
where: <protoco... | [
"```python\ns=\"\"\nL=[]\ns=input()\nk=0\nr=0\nc=0\nif s[0]=='h':\n L.append('http://')\n c=4\n s=s[c:]\nelif s[0]=='f':\n L.append('ftp://')\n c=3\n s=s[c:]\nr=s.find('ru',1)\nL.append(s[:r])\nL.append('.ru')\n\nk=r+2\n\nif k<len(s):\n L.append('/')\n L.append(s[k:])\n \nprint(''.join(L))... | [{"type": "stdin_stdout", "input": "httpsunrux\n", "output": "http://sun.ru/x\n"}, {"type": "stdin_stdout", "input": "ftphttprururu\n", "output": "ftp://http.ru/ruru\n"}, {"type": "stdin_stdout", "input": "httpuururrururruruurururrrrrurrurrurruruuruuu\n", "output": "http://uu.ru/rrururruruurururrrrrurrurrurruruuruuu\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 is an active Internet user. One day he came across a... | [{"type": "stdin_stdout", "input": "httpsunrux\n", "output": "http://sun.ru/x\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "ftphttprururu\n", "output": "ftp://http.ru/ruru\n", "metadata": {"func_name": null}}, {"type": "stdin_stdout", "input": "httpuururrururruruurururrrrrurrurrurruruuruuu\n"... | livecodebench | deepcoder_199 | 199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.