task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. Alice (uniformly and independently) randomly picks two integers a, b from the range [1,10^{4}], and writes down the values of a + b, a - b, a \cdot b and \lfloor \frac{a}{b} \rfloor (integer division) in some random order. Unfortunately, she forgot the v...
{"inputs": ["2\n-1 72 0 17\n1 4 5 6"], "outputs": ["8 9\n-1 -1"]}
563
38
coding
Solve the programming task below in a Python markdown code block. You are given a permutation $a$ of size $n$ and you should perform $n$ operations on it. In the $i$-th operation, you can choose a non-empty suffix of $a$ and increase all of its elements by $i$. How can we perform the operations to minimize the number o...
{"inputs": ["1\n8\n7 6 5 4 3 2 8 1\n", "1\n8\n8 1 7 6 5 4 3 2\n", "1\n9\n9 1 8 7 6 5 4 3 2\n", "1\n10\n10 3 2 1 9 8 7 6 5 4\n", "1\n10\n10 1 9 8 7 6 5 4 3 2\n", "1\n10\n8 7 6 5 4 3 9 2 10 1\n", "1\n10\n6 5 4 2 9 8 7 1 10 3\n", "1\n10\n9 8 7 6 5 4 3 2 10 1\n"], "outputs": ["7 1 2 3 4 5 6 8 \n", "1 3 4 5 6 7 8 2 \n", "1 ...
696
393
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid. You can arrange for the planet to co...
{"functional": "def check(candidate):\n assert candidate(mass = 10, asteroids = [3,9,19,5,21]) == True\n assert candidate(mass = 5, asteroids = [4,9,23,4]) == False\n\n\ncheck(Solution().asteroidsDestroyed)"}
158
72
coding
Solve the programming task below in a Python markdown code block. HackerLand Enterprise is adopting a new viral advertising strategy. When they launch a new product, they advertise it to exactly $5$ people on social media. On the first day, half of those $5$ people (i.e., $floor(\frac{5}{2})=2$) like the advertisemen...
{"inputs": ["3\n"], "outputs": ["9\n"]}
437
14
coding
Solve the programming task below in a Python markdown code block. Your colleagues have been looking over you shoulder. When you should have been doing your boring real job, you've been using the work computers to smash in endless hours of codewars. In a team meeting, a terrible, awful person declares to the group that...
{"functional": "_inputs = [[{'tim': 0, 'jim': 2, 'randy': 0, 'sandy': 7, 'andy': 0, 'katie': 5, 'laura': 1, 'saajid': 2, 'alex': 3, 'john': 2, 'mr': 0}, 'laura'], [{'tim': 1, 'jim': 3, 'randy': 9, 'sandy': 6, 'andy': 7, 'katie': 6, 'laura': 9, 'saajid': 9, 'alex': 9, 'john': 9, 'mr': 8}, 'katie'], [{'tim': 2, 'jim': 4,...
366
397
coding
Solve the programming task below in a Python markdown code block. You are given a permutation$^\dagger$ $p$ of length $n$. In one operation, you can choose two indices $1 \le i < j \le n$ and swap $p_i$ with $p_j$. Find the minimum number of operations needed to have exactly one inversion$^\ddagger$ in the permutatio...
{"inputs": ["1\n10\n9 6 7 10 3 2 1 4 5 8\n", "4\n2\n2 1\n2\n1 2\n4\n3 4 1 2\n4\n2 4 3 1\n"], "outputs": ["8\n", "0\n1\n3\n1\n"]}
650
84
coding
Solve the programming task below in a Python markdown code block. Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped. The bits are numbered from the least significant bit (index 1). Example: ```python flip_bit(15, 4) == 7 # 15 in binary is 1111, a...
{"functional": "_inputs = [[0, 16], [2147483647, 31], [127, 8]]\n_outputs = [[32768], [1073741823], [255]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(...
246
204
coding
Solve the programming task below in a Python markdown code block. In computer science, cycle detection is the algorithmic problem of finding a cycle in a sequence of iterated function values. For any function ƒ, and any initial value x0 in S, the sequence of iterated function values x0,x1=f(x0), x2=f(x1), ...,xi=...
{"functional": "_inputs = [[[2, 3, 4, 2, 3, 4]], [[1, 2, 3, 4, 2, 3, 4]], [[1, 1, 1, 1, 1, 1, 1, 1]], [[]], [[7]], [[1, 2, 3, 4]]]\n_outputs = [[[0, 3]], [[1, 3]], [[0, 1]], [[]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a...
508
252
coding
Solve the programming task below in a Python markdown code block. Decompose a number `num` into an array (tuple in Haskell, array of arrays `long[][]` in C# or Java) of the form `[[k1,k2,k3...], r]`, `([k1,k2,k3...], r)` in Haskell, `[[k1,k2,k3...], [r]]` in C# or Java) such that: 1. each kn is more than one 2. eack ...
{"functional": "_inputs = [[0], [4], [9], [25], [8330475], [9819938], [8331299], [8328441]]\n_outputs = [[[[], 0]], [[[2], 0]], [[[3], 1]], [[[4, 2], 0]], [[[22, 13, 10, 8, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 0]], [[[23, 12, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 0]]...
555
555
coding
Solve the programming task below in a Python markdown code block. The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The se...
{"inputs": ["7 7\n", "9 5\n", "3 0\n", "5 0\n", "7 9\n", "5 4\n", "5 1\n", "9 4\n"], "outputs": ["YES\n.......\n.#####.\n.#...#.\n.......\n", "YES\n.........\n..#####..\n.........\n.........\n", "YES\n...\n...\n...\n...\n", "YES\n.....\n.....\n.....\n.....\n", "YES\n.......\n.#####.\n.##.##.\n.......\n", "YES\n.....\n....
363
193
coding
Solve the programming task below in a Python markdown code block. Takahashi found an undirected connected graph with N vertices and M edges. The vertices are numbered 1 through N. The i-th edge connects vertices a_i and b_i, and has a weight of c_i. He will play Q rounds of a game using this graph. In the i-th round, ...
{"inputs": ["4 3\n1 2 3\n2 3 6\n3 4 5\n2\n2 3\n1 4", "4 3\n1 2 3\n2 3 6\n3 4 6\n2\n2 3\n1 4", "4 3\n1 2 3\n2 3 6\n3 4 7\n2\n2 3\n1 4", "4 3\n1 2 0\n2 3 6\n3 4 5\n2\n2 3\n1 4", "4 3\n1 2 3\n2 3 4\n3 4 5\n2\n2 3\n1 4", "4 6\n1 3 5\n4 2 6\n2 4 6\n3 2 2\n2 4 5\n2 2 3\n1\n2 3", "4 6\n2 3 7\n4 2 3\n2 4 3\n3 2 2\n2 4 5\n1 2 3...
434
355
coding
Solve the programming task below in a Python markdown code block. You are given a positive integer $n$ greater or equal to $2$. For every pair of integers $a$ and $b$ ($2 \le |a|, |b| \le n$), you can transform $a$ into $b$ if and only if there exists an integer $x$ such that $1 < |x|$ and ($a \cdot x = b$ or $b \cdot ...
{"inputs": ["4\n", "6\n", "2\n", "3\n", "5\n", "7\n", "8\n", "9\n"], "outputs": ["8", "28", "0", "0", "8", "28", "52", "64"]}
349
66
coding
Solve the programming task below in a Python markdown code block. You have $r$ red and $b$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet: has at least one red bean (or the number of red beans $r_i \ge 1$); has at least one blue bean (or the number of blue ...
{"inputs": ["1\n1 1 1\n", "1\n2 1 1\n", "1\n2 1 1\n", "1\n1 1 1\n", "1\n2 1 0\n", "1\n1 1 2\n", "1\n2 2 0\n", "1\n2 2 1\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
498
118
coding
Solve the programming task below in a Python markdown code block. A simple string contains a large repetition of letters within it. This problem is related to string handling and manipulation. An original message is sent from planet Earth to planet Cybertron in form of a string. However, the letter position and string...
{"inputs": ["information"], "outputs": ["i2n2f1o2r1m1a1t1"]}
214
27
coding
Solve the programming task below in a Python markdown code block. The prime numbers are not regularly spaced. For example from `2` to `3` the step is `1`. From `3` to `5` the step is `2`. From `7` to `11` it is `4`. Between 2 and 50 we have the following pairs of 2-steps primes: `3, 5 - 5, 7, - 11, 13, - 17, 19, - 29,...
{"functional": "_inputs = [[2, 100, 110], [4, 100, 110], [6, 100, 110], [8, 300, 400], [10, 300, 400], [4, 30000, 100000], [6, 30000, 100000], [8, 30000, 100000], [11, 30000, 100000], [16, 5, 20], [2, 10000000, 11000000], [52, 1300, 15000], [10, 4900, 5000], [30, 4900, 5000], [2, 4900, 5000], [2, 104000, 105000], [2, 4...
720
716
coding
Solve the programming task below in a Python markdown code block. Pushkar is very good in Number Theory. He takes two numbers $A\ and\ B$ and declares them a Pushkar Pair. Pushkar Pair has a property that $A$ has a $Modular\ Inverse$ modulo $B$. He asks you to tell him the largest number $L$ that divides both of them...
{"inputs": ["1\n3 4"], "outputs": ["1"]}
199
16
coding
Solve the programming task below in a Python markdown code block. Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers: * The number of numbers which have the same place with numbers A imagined (Hit) * The number of numbers included (but different p...
{"inputs": ["9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 0", "9 1 8 2\n6 1 5 9\n4 6 8 2\n2 6 3 0", "9 1 8 2\n4 1 5 9\n2 6 8 2\n4 6 3 0", "9 1 8 2\n6 2 5 9\n4 6 8 2\n4 6 3 0", "9 1 8 2\n6 2 5 9\n4 6 8 2\n4 9 3 0", "9 1 8 2\n6 0 5 9\n4 6 5 2\n4 6 3 0", "9 1 8 2\n6 2 8 9\n4 6 8 2\n4 9 3 1", "9 1 8 4\n6 2 5 9\n4 1 8 2\n4 9 6 0"], "ou...
320
350
coding
Solve the programming task below in a Python markdown code block. You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'. In one move, you can choose exactly one bracket and move it t...
{"inputs": ["4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n", "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n)))((((())\n", "4\n2\n)(\n4\n()()\n8\n())()()(\n10\n())((()())\n", "4\n2\n)(\n4\n()()\n8\n()()())(\n10\n)))((((())\n", "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n))((((()))\n", "4\n2\n)(\n4\n)()(\n8\n())()()(\n10\n())(()(())\...
552
324
coding
Solve the programming task below in a Python markdown code block. Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something. One day, however, he doubt if this way is really efficient. When he pays more number o...
{"inputs": ["123 3 0 4 0 1 1\n999 9 9 9 9 9 9\n0 0 0 0 0 0 0", "123 3 0 4 0 1 0\n999 9 9 9 9 9 9\n0 0 0 0 0 0 0", "123 3 0 2 3 2 2\n999 9 9 9 9 7 8\n0 0 0 0 0 0 0", "123 3 0 2 3 2 2\n999 9 9 9 9 4 8\n0 0 0 0 0 0 0", "123 3 0 4 0 2 1\n999 9 9 9 9 9 9\n0 0 0 0 0 0 0", "123 3 1 2 3 2 2\n999 9 9 9 9 7 8\n0 0 0 0 0 0 0", "1...
404
430
coding
Solve the programming task below in a Python markdown code block. Chef is watching a football match. The current score is A:B, that is, team 1 has scored A goals and team 2 has scored B goals. Chef wonders if it is possible for the score to become C:D at a later point in the game (i.e. team 1 has scored C goals and tea...
{"inputs": ["3\n1 5\n3 5\n3 4\n2 6\n2 2\n2 2\n"], "outputs": ["POSSIBLE\nIMPOSSIBLE\nPOSSIBLE\n"]}
497
49
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array target and an integer n. You have an empty stack with the two following operations: "Push": pushes an integer to the top of the stack. "Pop": removes the integer on the top of the stack...
{"functional": "def check(candidate):\n assert candidate(target = [1,3], n = 3) == [\"Push\",\"Push\",\"Pop\",\"Push\"]\n assert candidate(target = [1,2,3], n = 3) == [\"Push\",\"Push\",\"Push\"]\n assert candidate(target = [1,2], n = 4) == [\"Push\",\"Push\"]\n\n\ncheck(Solution().buildArray)"}
260
99
coding
Solve the programming task below in a Python markdown code block. You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 <...
{"inputs": ["3\n0 2 3", "3\n2 3 8", "3\n0 0 8", "3\n0 2 4", "3\n3 3 8", "3\n0 2 8", "3\n6 3 8", "3\n0 4 8"], "outputs": ["2\n", "6\n", "1\n", "2\n", "6\n", "2\n", "6\n", "2\n"]}
435
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].   Please complete the following python code precisely: ```python class Solution: def findKthNumber(self, n: int, k...
{"functional": "def check(candidate):\n assert candidate(n = 13, k = 2) == 10\n assert candidate(n = 1, k = 1) == 1\n\n\ncheck(Solution().findKthNumber)"}
77
57
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There is a robot in the cell $(0, 0)$ of an infinite grid. One cell $(X, Y)$ contains an obstacle and all other cells are free. We only know that $1 ...
{"inputs": ["1 2\n"], "outputs": ["UR\n"]}
623
16
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string. Please complete the following python code precisely: ```python class Solution: def fi...
{"functional": "def check(candidate):\n assert candidate(words = [\"at\", \"\", \"\", \"\", \"ball\", \"\", \"\", \"car\", \"\", \"\",\"dad\", \"\", \"\"], s = \"ta\") == -1\n assert candidate(words = [\"at\", \"\", \"\", \"\", \"ball\", \"\", \"\", \"car\", \"\", \"\",\"dad\", \"\", \"\"], s = \"ball\") == 4\n\n...
78
109
coding
Solve the programming task below in a Python markdown code block. Luke, an intergalactic traveller went on a trip across the universe and got candies from the different planets he visited. He comes back with $N$ candies and decides to distribute them among his $M$ friends. However, Luke only wants a fair distribution o...
{"inputs": ["2 \n28 6 2 \n78 5 3"], "outputs": ["2\n1"]}
382
32
coding
Solve the programming task below in a Python markdown code block. Given a set of $n$ intervals, find the size of its largest possible subset of intervals such that no three intervals in the subset share a common point. Input Format The first line contains an integer, $\boldsymbol{\mathrm{~S~}}$, denoting the number o...
{"inputs": ["4\n3\n1 2\n2 3\n2 4\n3\n1 5\n1 5\n1 5\n4\n1 10\n1 3\n4 6\n7 10\n4\n1 10\n1 3\n3 6\n7 10\n"], "outputs": ["2\n2\n4\n3\n"]}
598
88
coding
Solve the programming task below in a Python markdown code block. There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task. Every task should have a worker assigned to it. If a worker is proficient in the task, t...
{"inputs": ["4\n2 4\n1 2 1 2\n2 4\n1 1 1 1\n5 5\n5 1 3 2 4\n1 1\n1\n"], "outputs": ["2\n3\n1\n1\n"]}
574
64
coding
Solve the programming task below in a Python markdown code block. Our Chef is very happy that his son was selected for training in one of the finest culinary schools of the world. So he and his wife decide to buy a gift for the kid as a token of appreciation. Unfortunately, the Chef hasn't been doing good business late...
{"inputs": ["2 2\n9 7\n10 8", "2 2\n9 7\n8 10", "2 2\n10 7\n3 0", "2 2\n9 7\n3 10", "2 2\n2 7\n10 8", "2 2\n9 7\n6 10", "2 2\n9 7\n6 16", "2 2\n11 4\n6 2"], "outputs": ["8\n", "GUESS\n", "7\n", "GUESS\n", "8\n", "GUESS\n", "GUESS\n", "4\n"]}
661
158
coding
Solve the programming task below in a Python markdown code block. In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no...
{"inputs": ["2\n3 20\n1 3", "2\n3 20\n0 3", "2\n8 20\n1 13", "2\n8 40\n1 10", "2\n3 20\n1 13", "2\n12 20\n1 6", "2\n8 40\n2 10", "2\n16 20\n1 6"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
359
140
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef got interested in bits and wanted to learn about them, so his friend Pintu gave him a special function $F(X,Y,Z) = (X \wedge Z) \cdot (Y \wedge ...
{"inputs": ["2\n7 12 4 17\n7 12 0 8"], "outputs": ["15\n7"]}
675
34
coding
Solve the programming task below in a Python markdown code block. It is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2. Given an integer r, find the area of a regular dodecagon inscribed in a circle of radius r. -----Constraints----- - 1 \leq r \leq 100 - r is an integer. -----...
{"inputs": ["6", "3", "2", "0", "9", "8", "4", "4\n"], "outputs": ["108\n", "27\n", "12\n", "0\n", "243\n", "192\n", "48", "48\n"]}
158
72
coding
Solve the programming task below in a Python markdown code block. Shefin gives you a string S and you have to find a non-empty string P such that: P is a substring of S. No non-empty substring of P is a prefix of S. No non-empty substring of P is a suffix of S. For all such possible strings, find the length of the l...
{"inputs": ["2\nabcdab\naaa\n"], "outputs": ["2\n-1\n"]}
484
22
coding
Solve the programming task below in a Python markdown code block. A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: a_{i} ≥ a_{i} - 1 for all even i, a_{i} ≤ a_{i} - 1 for all odd i > 1. For example the arrays [1,2,1,2] and [1,1,1,1] are ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n0\n", "1\n4\n", "3\n1 2 6\n", "3\n1 2 3\n", "3\n1 2 3\n"], "outputs": ["1\n", "1 ", "2 ", "0 ", "4 ", "1 6 2\n", "1 3 2\n", "1 3 2 "]}
290
106
coding
Solve the programming task below in a Python markdown code block. # Task Given a binary number, we are about to do some operations on the number. Two types of operations can be here: * ['I', i, j] : Which means invert the bit from i to j (inclusive). * ['Q', i] : Answer whether the i'th bit is 0 or 1. The MSB (most...
{"functional": "_inputs = [['0011001100', [['I', 1, 10], ['I', 2, 7], ['Q', 2], ['Q', 1], ['Q', 7], ['Q', 5]]], ['1011110111', [['I', 1, 10], ['I', 2, 7], ['Q', 2], ['Q', 1], ['Q', 7], ['Q', 5]]], ['1011110111', [['I', 1, 10], ['I', 2, 7]]], ['0000000000', [['I', 1, 10], ['Q', 2]]]]\n_outputs = [[['0', '1', '1', '0']],...
375
352
coding
Solve the programming task below in a Python markdown code block. In this problem, you should process T testcases. For each testcase, you are given four integers N, M, A, B. Calculate \sum_{i = 0}^{N - 1} floor((A \times i + B) / M). Constraints * 1 \leq T \leq 100,000 * 1 \leq N, M \leq 10^9 * 0 \leq A, B < M Inp...
{"inputs": ["5\n3 16 6 3\n2 2 2 3\n2 3 0 0\n31415 92653 97266 32384\n1000000000 1000001000 11747768 999999999", "5\n4 16 6 6\n6 5 4 3\n1 2 0 0\n31415 92653 58979 3909\n1000000000 1000000000 999999999 999999999", "5\n4 10 6 6\n6 5 4 3\n1 1 0 0\n31415 92653 58979 32384\n1000000000 1000000000 999999999 999999999", "5\n4 1...
332
1,057
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The beauty of a string is the difference in frequencies between the most frequent and least frequent characters. For example, the beauty of "abaacc" is 3 - 1 = 2. Given a string s, return the sum of beauty of all of...
{"functional": "def check(candidate):\n assert candidate(s = \"aabcb\") == 5\n assert candidate(s = \"aabcbaa\") == 17\n\n\ncheck(Solution().beautySum)"}
103
49
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph ca...
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]) == True\n assert candidate(n = 4, edges = [[1,2],[3,4]]) == True\n assert candidate(n = 4, edges = [[1,2],[1,3],[1,4]]) == False\n\n\ncheck(Solution().isPossible)"}
175
105
coding
Solve the programming task below in a Python markdown code block. You are given n segments on a number line, numbered from 1 to n. The i-th segments covers all integer points from l_i to r_i and has a value w_i. You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it...
{"inputs": ["1 2\n1 2 10\n", "1 10\n1 10 23\n", "4 10\n6 10 4\n1 5 7\n2 6 5\n5 9 8\n", "4 10\n6 10 4\n1 5 7\n2 9 5\n5 9 8\n", "4 10\n6 10 4\n1 5 2\n2 9 5\n5 9 4\n", "4 10\n6 10 4\n1 5 7\n1 9 5\n5 9 8\n", "4 10\n6 10 4\n1 5 7\n2 9 5\n6 9 8\n", "4 10\n6 10 4\n1 5 7\n2 9 7\n6 9 8\n"], "outputs": ["0\n", "0\n", "3\n", "3\n...
350
258
coding
Solve the programming task below in a Python markdown code block. There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem). Let's simplify this game a bit. Formally, there are $n$ participants...
{"inputs": ["2\n2\n1 1\n1\n1\n", "2\n2\n1 1\n1\n1\n", "2\n2\n1 2\n1\n1\n", "2\n6\n1 1 1 3 3 3\n4\n1 1 1 3\n", "2\n6\n1 1 1 3 3 3\n4\n1 1 1 3\n", "2\n6\n1 1 1 3 6 3\n4\n1 1 1 3\n", "2\n6\n1 1 1 3 6 3\n4\n1 1 1 1\n", "2\n6\n1 1 2 3 6 3\n4\n1 1 1 1\n"], "outputs": ["-1\n1\n", "-1\n1\n", "1\n1\n", "-1\n4\n", "-1\n4\n", "5\...
503
239
coding
Solve the programming task below in a Python markdown code block. # How many ways can you make the sum of a number? From wikipedia: https://en.wikipedia.org/wiki/Partition_(number_theory)# >In number theory and combinatorics, a partition of a positive integer *n*, also called an *integer partition*, is a way of writi...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [20], [30], [40], [43], [60], [70], [90], [200], [275]]\n_outputs = [[1], [2], [3], [5], [7], [627], [5604], [37338], [63261], [966467], [4087968], [56634173], [3972999029388], [1520980492851175]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float...
426
301
coding
Solve the programming task below in a Python markdown code block. There are N turkeys. We number them from 1 through N. M men will visit here one by one. The i-th man to visit will take the following action: * If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it. * If either...
{"inputs": ["6 1\n1 2", "7 1\n1 2", "7 0\n1 2", "7 0\n1 4", "7 0\n0 4", "7 0\n0 8", "2 1\n1 2", "6 1\n1 4"], "outputs": ["14\n", "20\n", "21\n", "21\n", "21\n", "21\n", "0\n", "14\n"]}
370
117
coding
Solve the programming task below in a Python markdown code block. A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n...
{"inputs": ["5\n1\n1\n2\n1 2\n5\n1 4 2 3 5\n5\n2 1 5 3 4\n10\n7 4 8 1 6 10 3 5 2 9\n"], "outputs": ["0\n1\n1\n4\n6\n"]}
706
80
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(s = \"abab\") == True\n assert candidate(s = \"aba\") == False\n assert candidate(s = \"abcabcabcabc\") == True\n\n\ncheck(Solution().repeatedSubstringPattern)"}
74
58
coding
Solve the programming task below in a Python markdown code block. AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. -----Constraints----- - 1 ≤ a,b ≤ 100 - a and b are integers. -----Input----- Input is given from Standard In...
{"inputs": ["7 6", "9 6", "5 6", "5 2", "5 4", "5 0", "3 0", "2 0"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
148
78
coding
Solve the programming task below in a Python markdown code block. You are given three positive integers $a$, $b$, $c$ ($a < b < c$). You have to find three positive integers $x$, $y$, $z$ such that: $$x mod y = a,$$ $$y mod z = b,$$ $$z mod x = c.$$ Here $p mod q$ denotes the remainder from dividing $p$ by $q$. It is...
{"inputs": ["1\n1 2 2002\n", "1\n1 2 1000000\n", "1\n1 2 100000000\n", "4\n1 3 4\n127 234 421\n2 7 8\n59 94 388\n"], "outputs": ["2005 2004 2002\n", "1000003 1000002 1000000\n", "100000003 100000002 100000000\n", "8 7 4\n782 655 421\n17 15 8\n541 482 388\n"]}
413
206
coding
Solve the programming task below in a Python markdown code block. The chef has a recipe he wishes to use for his guests, but the recipe will make far more food than he can serve to the guests. The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less ...
{"inputs": ["3\n2 4 4\n3 2 3 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 4\n4 3 20 9 6", "3\n2 4 4\n3 2 1 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 4\n4 3 20 9 8", "3\n2 4 7\n3 2 1 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 6\n4 3 20 9 8", "3\n2 4 4\n3 2 3 8\n4 3 15 9 6", "3\n2 4 8\n3 2 3 4\n4 3 20 9 6"], "outputs": ["1 1\n2 3 4\n1 5 3 2", "1 1\n2 ...
317
393
coding
Solve the programming task below in a Python markdown code block. -----Input----- The input contains a single integer a (10 ≤ a ≤ 999). -----Output----- Output 0 or 1. -----Examples----- Input 13 Output 1 Input 927 Output 1 Input 48 Output 0
{"inputs": ["13\n", "48\n", "10\n", "33\n", "25\n", "10\n", "33\n", "25\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
74
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1: Choose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3) == 2\n assert candidate(nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1) == -1\n\n\ncheck(Solution().minOperations)"}
202
91
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has a sequence $A$ consisting of $N$ positive integers. He is playing a game with this sequence. The goal of the game is to maximize the greatest common divisor of all...
{"inputs": ["2\n2\n1 25\n5\n27 3 15 1024 15"], "outputs": ["1\n6"]}
384
39
coding
Solve the programming task below in a Python markdown code block. There are 10 problems in a contest. You know that the score of each problem is either 1 or 100 points. Chef came to know the total score of a participant and he is wondering how many problems were actually solved by that participant. Given the total sc...
{"inputs": ["5\n103\n0\n6\n142\n1000\n"], "outputs": ["4\n0\n6\n-1\n10\n"]}
382
41
coding
Solve the programming task below in a Python markdown code block. A bulb company claims that the average lifetime of its bulbs is at least X units. The company ran a test on N bulbs. You are given the lifetime of N-1 of these bulbs. What is the minimum non-negative integer value of lifetime the remaining bulb can have...
{"inputs": ["3\n3 4\n1 5\n4 2\n5 8 6\n3 1000\n0 0\n"], "outputs": ["6\n0\n3000\n"]}
486
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums consisting of positive integers. You can do the following operation on the array any number of times: Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,7,9,3]) == 21\n assert candidate(nums = [5,3,3]) == 11\n\n\ncheck(Solution().maxArrayValue)"}
153
58
coding
Solve the programming task below in a Python markdown code block. There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, an...
{"inputs": ["2 2\n", "1 7\n", "1 1\n", "2 8\n", "314 1592\n", "237891668 1\n", "1 1000000000\n", "17890722 23878637\n"], "outputs": ["0\n", "5\n", "1\n", "0\n", "496080\n", "237891666\n", "999999998\n", "427205972767200\n"]}
263
157
coding
Solve the programming task below in a Python markdown code block. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $v$ (different from root) is the previous to $v$ vertex on the shortest path from the root to the vertex $v$. Children of the vertex $v...
{"inputs": ["5\n7\n1 2\n1 3\n1 4\n2 5\n2 6\n4 7\n6\n1 2\n1 3\n2 4\n2 5\n3 6\n2\n1 2\n7\n7 3\n1 5\n1 3\n4 6\n4 7\n2 1\n6\n2 1\n2 3\n4 5\n3 4\n3 6\n", "5\n7\n1 2\n1 3\n1 4\n2 5\n2 6\n4 7\n6\n1 2\n1 3\n2 4\n2 5\n3 6\n2\n1 2\n7\n6 3\n1 5\n1 3\n4 6\n4 7\n2 1\n6\n2 1\n2 3\n4 5\n3 4\n3 6\n", "5\n7\n1 2\n1 3\n1 7\n2 5\n2 6\n4 ...
752
950
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting only of characters 'a' and 'b'​​​​. You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b...
{"functional": "def check(candidate):\n assert candidate(s = \"aababbab\") == 2\n assert candidate(s = \"bbaaaaabb\") == 2\n\n\ncheck(Solution().minimumDeletions)"}
130
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer number n, return the difference between the product of its digits and the sum of its digits.   Please complete the following python code precisely: ```python class Solution: def subtractProductAnd...
{"functional": "def check(candidate):\n assert candidate(n = 234) == 15 \n assert candidate(n = 4421) == 21\n\n\ncheck(Solution().subtractProductAndSum)"}
71
53
coding
Solve the programming task below in a Python markdown code block. Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably...
{"inputs": ["1\n2\n3\n", "1\n1\n1\n", "1\n2\n1\n", "5\n1\n3\n", "3\n1\n5\n", "6\n7\n1\n", "1\n8\n3\n", "9\n7\n2\n"], "outputs": ["9\n", "3\n", "4\n", "20\n", "20\n", "48\n", "27\n", "126\n"]}
313
108
coding
Solve the programming task below in a Python markdown code block. There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for ...
{"inputs": ["...\nX.X\n...\n", "X..\nX..\nX..\n", "...\nXXX\nXXX\n", "...\nX.X\nX..\n", "..X\nX..\n..X\n", "...\n...\n..X\n", "X..\n...\n...\n", "...\nX..\n...\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
362
113
coding
Solve the programming task below in a Python markdown code block. Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try ...
{"inputs": ["1\nZ\n", "1\nK\n", "1\nV\n", "1\nY\n", "1\nL\n", "2\nKV\n", "2\nVK\n", "2\nVL\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]}
499
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms: "xi==yi" or "xi!=yi".Here, xi and yi are l...
{"functional": "def check(candidate):\n assert candidate([\"a==b\",\"b!=a\"]) == False\n assert candidate([\"b==a\",\"a==b\"]) == True\n assert candidate([\"a==b\",\"b==c\",\"a==c\"]) == True\n assert candidate([\"a==b\",\"b!=c\",\"c==a\"]) == False\n assert candidate([\"c==c\",\"b==d\",\"x!=z\"]) == Tru...
136
117
coding
Solve the programming task below in a Python markdown code block. You have an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. You are allowed to perform the following operation on it: Choose two elements from the array $a_i$ and $a_j$ ($i \ne j$) such that $\gcd(a_i, a_j)$ is not present in the array...
{"inputs": ["3\n6 10 15\n", "2\n1 1000000\n", "5\n4 20 1 25 30\n", "7\n838695 559130 335478 98670 152490 129030 72930\n", "10\n239529 302993 398153 204081 370085 184103 337965 450634 411842 217101\n", "57\n241 444 553 126 612 550 441 420 742 879 520 664 590 198 910 731 308 740 791 680 904 629 324 606 621 75 350 253 57 ...
507
427
coding
Solve the programming task below in a Python markdown code block. Given are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353. * Let us repeat the following operation on the integer k. Operation: if t...
{"inputs": ["3\n011", "3\n001", "3\n000", "3\n010", "3\n101", "3\n110", "3\n100", "3\n111"], "outputs": ["20", "12", "6", "14", "28", "34", "26", "40"]}
348
93
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S. In one operation, you can pick an index i (1≤ i < |S|) and swap the characters S_{i} and S_{(i+1)}. Find the minimum number of operations required, such that, the decimal representation of the final binary string is di...
{"inputs": ["3\n0000\n111\n11001"], "outputs": ["0\n-1\n1"]}
451
32
coding
Solve the programming task below in a Python markdown code block. Tenten runs a weapon shop for ninjas. Today she is willing to sell n shurikens which cost 1, 2, ..., n ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly si...
{"inputs": ["1\n+\n- 1\n", "1\n- 1\n+\n", "3\n+\n+\n+\n- 2\n- 1\n- 2\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "4\n+\n- 1\n+\n+\n- 4\n+\n- 2\n- 3\n", "4\n+\n+\n+\n- 3\n- 4\n+\n- 1\n- 2\n", "4\n+\n+\n+\n- 4\n- 4\n+\n- 1\n- 2\n", "4\n+\n+\n+\n- 3\n- 2\n+\n- 1\n- 2\n"], "outputs": ["YES\n1 ", "NO\n", "NO\n", "NO\n", "NO\n", "NO\...
694
215
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array coins (1-indexed) of length n and an integer maxJump. You can jump to any index i of the array coins if coins[i] != -1 and you have to pay coins[i] when you visit index i. In addition to...
{"functional": "def check(candidate):\n assert candidate([1,2,4,-1,2], 2) == [1,3,5]\n assert candidate([1,2,4,-1,2], 1) == []\n\n\ncheck(Solution().cheapestJump)"}
318
67
coding
Solve the programming task below in a Python markdown code block. You are teaching students to generate strings consisting of unique lowercase latin characters (a-z). You give an example reference string $s$ to the students. You notice that your students just copy paste the reference string instead of creating their ow...
{"inputs": ["4\nhelowrd 0\nbackground 0\nabcdefghijklmnopqrstuvwxyz 0\nb 1"], "outputs": ["abcfgij\nefhijlmpqs\nNOPE\na"]}
456
44
coding
Solve the programming task below in a Python markdown code block. Chef is playing a mobile game. In the game, Chef's character *Chefario* can perform special attacks. However, one special attack costs X mana points to Chefario. If Chefario currently has Y mana points, determine the maximum number of special attacks h...
{"inputs": ["3\n10 30\n6 41\n50 2\n"], "outputs": ["3\n6\n0\n"]}
344
34
coding
Solve the programming task below in a Python markdown code block. G: Palindromic Subsequences problem Given a string S consisting only of lowercase letters, find out how many subsequences of this string S are not necessarily continuous and are palindromes. Here, a subsequence that is not necessarily continuous with ...
{"inputs": ["ccpa", "cnbc", "emec", "ccoa", "aocc", "pcca", "ccao", "pcda"], "outputs": ["4\n", "6\n", "5\n", "4\n", "4\n", "4\n", "4\n", "4\n"]}
474
70
coding
Solve the programming task below in a Python markdown code block. You are given a string of numbers between 0-9. Find the average of these numbers and return it as a floored whole number (ie: no decimal places) written out as a string. Eg: "zero nine five two" -> "four" If the string is empty or includes a number gre...
{"functional": "_inputs = [['zero nine five two'], ['four six two three'], ['one two three four five'], ['five four'], ['zero zero zero zero zero'], ['one one eight one'], ['one'], [''], ['ten'], ['pippi']]\n_outputs = [['four'], ['three'], ['three'], ['four'], ['zero'], ['two'], ['one'], ['n/a'], ['n/a'], ['n/a']]\nim...
106
230
coding
Solve the programming task below in a Python markdown code block. As a New Year's gift, Dolphin received a string s of length 19. The string s has the following format: `[five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]`. Dolphin wants to convert the comma-separated str...
{"inputs": ["gaiku,atcoder,tasks", "abgde,fchihgf,edcba", "ha,pypnewyear,enjoy", "gaiku,atcoeer,tasks", "abcde,fghihcf,edgba", "ha,pypnewzear,enjoy", "gaiku,atcoeer-tasks", "abgde,fchihgf+edcba"], "outputs": ["gaiku atcoder tasks\n", "abgde fchihgf edcba\n", "ha pypnewyear enjoy\n", "gaiku atcoeer tasks\n", "abcde fghi...
200
171
coding
Solve the programming task below in a Python markdown code block. Chef has many friends, but his best friend is Hemant. They both love to watch anime. In fact, their weekends are meant for that only. Also, Hemant is highly into games, of which Chef is unaware. Hemant once gave a game to Chef and asked him to determine ...
{"inputs": ["3\n1\n3\n7"], "outputs": ["B\nA\nB"]}
294
22
coding
Solve the programming task below in a Python markdown code block. There are N towns numbered 1 to N and M roads. The i-th road connects Town A_i and Town B_i bidirectionally and has a length of C_i. Takahashi will travel between these towns by car, passing through these roads. The fuel tank of his car can contain at mo...
{"inputs": ["4 0 0\n1\n2 1", "4 0 1\n1\n2 1", "4 0 1\n1\n2 1\n", "3 2 5\n1 2 3\n2 2 3\n2\n3 2\n1 3", "3 2 5\n2 2 3\n2 3 3\n2\n3 2\n1 3", "3 2 5\n1 2 3\n1 3 3\n2\n3 2\n1 3", "3 2 5\n1 2 3\n1 3 3\n2\n1 2\n1 3", "3 2 2\n1 2 3\n1 3 0\n2\n3 2\n1 3"], "outputs": ["-1\n", "-1", "-1\n", "-1\n-1\n", "0\n-1\n", "1\n0\n", "0\n0\n...
634
235
coding
Solve the programming task below in a Python markdown code block. Some new animals have arrived at the zoo. The zoo keeper is concerned that perhaps the animals do not have the right tails. To help her, you must correct the broken function to make sure that the second argument (tail), is the same as the last letter of ...
{"functional": "_inputs = [['Fox', 'x'], ['Rhino', 'o'], ['Meerkat', 't'], ['Emu', 't'], ['Badger', 's'], ['Giraffe', 'd']]\n_outputs = [[True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,...
126
209
coding
Solve the programming task below in a Python markdown code block. Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substr...
{"inputs": ["3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi", "3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nipp", "3\ncodechef\n2\ncode\ndhef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nipp", "3\ncodechef\n2\ncode\ndhef\nfoo\n1\nbar\nmississippi\n4\ns...
380
391
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n and an integer p representing an array arr of length n where all elements are set to 0's, except position p which is set to 1. You are also given an integer array banned containing restricte...
{"functional": "def check(candidate):\n assert candidate(n = 4, p = 0, banned = [1,2], k = 4) == [0,-1,-1,1]\n assert candidate(n = 5, p = 0, banned = [2,4], k = 3) == [0,-1,-1,-1,-1]\n assert candidate(n = 4, p = 2, banned = [0,1,3], k = 1) == [-1,-1,0,-1]\n\n\ncheck(Solution().minReverseOperations)"}
178
132
coding
Solve the programming task below in a Python markdown code block. Bob has an account in the Bobby Bank. His current account balance is W rupees. Each month, the office in which Bob works deposits a fixed amount of X rupees to his account. Y rupees is deducted from Bob's account each month as bank charges. Find hi...
{"inputs": ["3\n100 11 1 10\n999 25 36 9\n2500 100 125 101\n"], "outputs": ["200\n900\n-25"]}
532
64
coding
Solve the programming task below in a Python markdown code block. Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если a является другом b, то b также является другом a. В этой же сети есть функция,...
{"inputs": ["1 0\n42 23\n", "1 1\n42 23\n", "1 50\n42 23\n", "1 99\n42 23\n", "1 100\n42 23\n", "2 49\n42 23\n23 14\n", "2 50\n42 23\n23 19\n", "2 51\n42 23\n23 19\n"], "outputs": ["23: 0\n42: 0\n", "23: 0\n42: 0\n", "23: 0\n42: 0\n", "23: 0\n42: 0\n", "23: 0\n42: 0\n", "14: 1 42\n23: 0\n42: 1 14\n", "19: 1 42\n23: 0\n...
685
275
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A critical point in a linked list is defined as either a local maxima or a local minima. A node is a local maxima if the current node has a value strictly greater than the previous node and the next node. A node is a ...
{"functional": "def check(candidate):\n assert candidate(head = list_node([3,1])) == [-1,-1]\n assert candidate(head = list_node([5,3,1,2,5,1,2])) == [1,3]\n assert candidate(head = list_node([1,3,2,2,3,2,2,2,7])) == [3,3]\n assert candidate(head = list_node([2,3,3,2])) == [-1,-1]\n\n\ncheck(Solution().node...
254
125
coding
Solve the programming task below in a Python markdown code block. There is a contest containing 2 problems A and B. 2 strong participants P and Q participated in the contest and solved both the problems. P made AC submissions on problems A and B at time instants P_{A} and P_{B} respectively while Q made AC submissio...
{"inputs": ["4\n5 10 2 12\n10 30 15 15\n20 8 4 20\n6 6 6 6\n"], "outputs": ["P\nQ\nTIE\nTIE\n"]}
571
62
coding
Solve the programming task below in a Python markdown code block. Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? -----Input----- The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and...
{"inputs": ["9 5\n", "3 3\n", "5 2\n", "6 0\n", "2 0\n", "2 2\n", "3 1\n", "6 2\n"], "outputs": ["4\n", "2\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n"]}
219
86
coding
Solve the programming task below in a Python markdown code block. Palindrome Problem Statement Find the number of palindromes closest to the integer n. Note that the non-negative integer x is the number of palindromes, which means that the character string in which x is expressed in decimal notation and the characte...
{"inputs": ["4", "8", "7", "6", "5", "1", "2", "3"], "outputs": ["4\n", "8\n", "7\n", "6\n", "5\n", "1\n", "2\n", "3\n"]}
215
62
coding
Solve the programming task below in a Python markdown code block. There are several (or no) spiders, butterflies, and dragonflies. In this kata, a spider has eight legs. A dragonfly or a butterfly has six legs. A __dragonfly__ has __two__ pairs of wings, while a __butterfly__ has __one__ pair of wings. __I am not sur...
{"functional": "_inputs = [[3, 20, 3]]\n_outputs = [[[1, 1, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return...
314
168
coding
Solve the programming task below in a Python markdown code block. Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely fu...
{"inputs": ["1 1\n1\n", "2 1\n2\n", "2 1\n2\n", "1 1\n1\n", "2 1\n4\n", "2 1\n1\n", "2 1\n7\n", "3 1\n7\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "1 0\n", "1 2\n", "1 0\n", "1 0\n"]}
413
118
coding
Solve the programming task below in a Python markdown code block. Ashley wrote a random number generator code. Due to some reasons, the code only generates random positive integers which are not evenly divisible by 10. She gives $N$ and $S$ as input to the random number generator. The code generates a random number wit...
{"inputs": ["2\n1 5\n2 2"], "outputs": ["5\n1"]}
332
22
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are $N$ athletes (numbered $1$ through $N$) in a line. For each valid $i$, the $i$-th athlete starts at the position $i$ and his speed is $V_{i...
{"inputs": ["4\n3\n1 2 3\n3\n3 2 1\n3\n0 0 0\n3\n1 3 2"], "outputs": ["1 1\n3 3\n1 1\n1 2"]}
612
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed two-dimensional integer array nums. Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0. Note th...
{"functional": "def check(candidate):\n assert candidate(nums = [[1,2,3],[5,6,7],[9,10,11]]) == 11\n assert candidate(nums = [[1,2,3],[5,17,7],[9,11,10]]) == 17\n\n\ncheck(Solution().diagonalPrime)"}
199
83
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings strs. You could concatenate these strings together into a loop, where for each string, you could choose to reverse it or not. Among all the possible loops Return the lexicographically...
{"functional": "def check(candidate):\n assert candidate(strs = [\"abc\",\"xyz\"]) == \"zyxcba\"\n assert candidate(strs = [\"abc\"]) == \"cba\"\n\n\ncheck(Solution().splitLoopedString)"}
210
57
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.   ...
{"functional": "def check(candidate):\n assert candidate(low = 100, high = 300) == [123,234]\n assert candidate(low = 1000, high = 13000) == [1234,2345,3456,4567,5678,6789,12345]\n\n\ncheck(Solution().sequentialDigits)"}
99
106
coding
Solve the programming task below in a Python markdown code block. You just got done with your set at the gym, and you are wondering how much weight you could lift if you did a single repetition. Thankfully, a few scholars have devised formulas for this purpose (from [Wikipedia](https://en.wikipedia.org/wiki/One-repetit...
{"functional": "_inputs = [[135, 20], [200, 8], [270, 2], [360, 1], [400, 0]]\n_outputs = [[282], [253], [289], [360], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):...
233
215
coding
Solve the programming task below in a Python markdown code block. Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya needs to...
{"inputs": ["2 3 4 5 6\n1 2\n", "2 3 1 5 6\n1 2\n", "2 1 1 5 6\n1 2\n", "2 1 1 5 1\n1 3\n", "2 1 1 5 1\n1 2\n", "2 1 1 5 1\n2 3\n", "3 4 2 19 0\n5 3 99\n", "3 4 2 19 0\n2 3 99\n"], "outputs": ["11\n", "5\n", "3\n", "4\n", "3\n", "5\n", "214\n", "208\n"]}
578
179
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane. We define the distance between two points (x1, y1) and (x2, y2) as (x1...
{"functional": "def check(candidate):\n assert candidate(coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5) == 2\n assert candidate(coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0) == 10\n\n\ncheck(Solution().countPairs)"}
166
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). "k!" means factorial: k! = 1 * 2 * .. * k Chef wants to calculate F(p_{1}) + F(p_{2}) + ......
{"inputs": ["5 7\n1 2 3 4 5", "5 7\n1 2 3 4 4", "5 7\n1 2 3 4 3", "5 7\n1 0 0 5 4", "5 6\n0 2 4 4 6", "5 7\n1 2 3 5 4", "5 7\n0 2 3 4 3", "5 7\n1 2 0 5 4"], "outputs": ["6", "1\n", "2\n", "3\n", "4\n", "6\n", "0\n", "0\n"]}
655
157
coding
Solve the programming task below in a Python markdown code block. Solve the mystery. Input : First line contains T - No. of test cases. For each test case there are two lines. first line contains N. Second line contains N space separated integers A[1] to A[N]. Output : Print answer of the mystery in separate...
{"inputs": ["10\n10\n9 83 61 91 57 0 89 87 83 68 \n10\n9 41 12 70 73 85 85 79 3 49 \n10\n25 14 34 85 24 19 0 13 72 15 \n10\n24 66 54 97 85 91 45 64 42 39 \n10\n44 39 78 94 54 81 35 18 10 67 \n10\n58 29 36 52 77 34 64 10 3 24 \n10\n8 42 31 40 6 53 66 77 76 58 \n10\n63 55 67 9 91 77 23 30 91 50 \n10\n36 12 34 78 45 18 21...
191
379
coding
Solve the programming task below in a Python markdown code block. You are a game designer and want to make an obstacle course. The player will walk from left to right. You have $n$ heights of mountains already selected and want to arrange them so that the absolute difference of the heights of the first and last mountai...
{"inputs": ["2\n4\n4 2 1 2\n2\n3 1\n"], "outputs": ["2 4 1 2 \n1 3\n"]}
633
41
coding
Solve the programming task below in a Python markdown code block. Mr. Pr and Ms. Ad are at $a$ and $b$ respectively on an infinite number line. Mr. Pr wants to meet Ms. Ad. Mr. Pr can choose to move $c$ or $d$ units in 1 second. If Mr. Pr moves $c$ units then Ms. Ad will move $d$ units and vice versa. (Both of them a...
{"inputs": ["2\n3 4 1 2\n10 20 3 7"], "outputs": ["YES\nNO"]}
349
32
coding
Solve the programming task below in a Python markdown code block. Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connec...
{"inputs": ["3\n1 2\n2 3\n3\n", "3\n1 2\n1 3\n2 3\n", "3\n1 2\n1 3\n3 2\n", "4\n1 2\n1 3\n1 4\n4 3 2\n", "5\n1 2\n4 3\n1 4\n4 5\n5 2 3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n", "8\n4 3\n1 4\n8 5\n7 6\n3 5\n7 3\n4 2\n2 6 8\n"], "outputs": ["1 2 3 2 1 ", "1 2 1 3 1 ", "1 3 1 2 1 ",...
434
307
coding
Solve the programming task below in a Python markdown code block. This kata is a continuation of [Part 1](http://www.codewars.com/kata/the-fibfusc-function-part-1). The `fibfusc` function is defined recursively as follows: fibfusc(0) = (1, 0) fibfusc(1) = (0, 1) fibfusc(2n) = ((x + y)(x - y), y(2x + 3y)), ...
{"functional": "_inputs = [[0], [1]]\n_outputs = [[[1, 0]], [[0, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n r...
561
167
coding
Solve the programming task below in a Python markdown code block. We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path...
{"inputs": ["2\n0 2", "2\n0 4", "2\n0 5", "2\n0 9", "2\n2 8", "2\n0 8", "2\n0 3", "2\n1 3"], "outputs": ["1", "1", "1", "1", "1", "1", "1", "1"]}
512
86
coding
Solve the programming task below in a Python markdown code block. You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, ret...
{"functional": "_inputs = [[[1, 2, 3, 4, 3, 2, 1]], [[1, 100, 50, -51, 1, 1]], [[1, 2, 3, 4, 5, 6]], [[20, 10, 30, 10, 10, 15, 35]], [[20, 10, -80, 10, 10, 15, 35]], [[10, -80, 10, 10, 15, 35, 20]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ...
519
1,275