problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
John is developing a system to report fuel usage but needs help with the coding.
First, he needs you to write a function that, given the actual consumption (in l/100 km) and remaining amount of petrol (in l), will give you how many kilometers you'll be ... | {"functional": "_inputs = [[10, 60], [8, 0], [6.4, 54], [9.3, 87.3], [11.7, 63.4]]\n_outputs = [[600], [0], [843.75], [938.71], [541.88]]\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, (... | coding | 269 |
Solve the programming task below in a Python markdown code block.
You survived several months of exam wars and were able to enter ICPC University on a sunny day. On the day of admission, there was an enthusiastic recruitment of circles on the campus of the university, and you received a large number of pamphlets and re... | {"inputs": ["9\n4\n0", "9\n8\n0", "9\n2\n0", "9\n5\n0", "9\n3\n0", "9\n6\n0", "9\n9\n0", "9\n0\n0"], "outputs": ["2\n0\n", "2\n0\n", "2\n0\n", "2\n1\n", "2\n1\n", "2\n1\n", "2\n2\n", "2\n"]} | coding | 301 |
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"]} | coding | 332 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
Please complete the following python code precisely:
```python
class Solutio... | {"functional": "def check(candidate):\n assert candidate(nums = [3,0,1]) == 2\n assert candidate(nums = [0,1]) == 2\n assert candidate(nums = [9,6,4,2,3,5,7,0,1]) == 8\n assert candidate(nums = [0]) == 1\n\n\ncheck(Solution().missingNumber)"} | coding | 78 |
Solve the programming task below in a Python markdown code block.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.
As ... | {"inputs": ["2 1 1\n7 7\n", "2 1 1\n7 3\n", "2 1 1\n10 2\n", "2 1 1\n7 13\n", "3 1 2\n6 5 5\n", "2 1 1\n10 13\n", "3 2 1\n4 10 8\n", "3 2 1\n7 16 0\n"], "outputs": ["0", "4\n", "8", "6\n", "1", "3\n", "4\n", "7\n"]} | coding | 420 |
Solve the programming task below in a Python markdown code block.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a s... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "2\n1 2\n", "2\n3 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 578 |
Solve the programming task below in a Python markdown code block.
We all know that Share market is place where drastic change occurs within moments. So we have one Stockholder, Isabella, who wants to maximize her profit by selling her shares. She has $N$ shares of a Doofenshmirtz Corporation which is represented by $N$... | {"inputs": ["1\n4\n1 2\n4 3\n3 5\n2 4"], "outputs": ["3"]} | coding | 454 |
Solve the programming task below in a Python markdown code block.
Let's call a sequence of integers $x_1, x_2, \dots, x_k$ MEX-correct if for all $i$ ($1 \le i \le k$) $|x_i - \operatorname{MEX}(x_1, x_2, \dots, x_i)| \le 1$ holds. Where $\operatorname{MEX}(x_1, \dots, x_k)$ is the minimum non-negative integer that doe... | {"inputs": ["4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 0\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 1 3\n", "4\n3\n0 2 0\n2\n1 0\n5\n0 0 1 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 1\n2\n1 1\n5\n0 0 0 0 0\n4\n0 1 1 3\n", "4\n3\n1 2 0\n2\n1 0\n5\n0 0 1 0 0\n4\n0 1 2 3\n", "4... | coding | 664 |
Solve the programming task below in a Python markdown code block.
You are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly grea... | {"inputs": ["1\n3\n1 2 3\n4 5 6\n7 8 9"], "outputs": ["18"]} | coding | 417 |
Solve the programming task below in a Python markdown code block.
Jack and Daniel are friends. Both of them like letters, especially uppercase ones.
They are cutting uppercase letters from newspapers, and each one of them has his collection of letters stored in a stack.
One beautiful day, Morgan visited Jack and Da... | {"inputs": ["2\nJACK\nDANIEL\nABACABA\nABACABA\n"], "outputs": ["DAJACKNIEL\nAABABACABACABA\n"]} | coding | 539 |
Solve the programming task below in a Python markdown code block.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can ... | {"inputs": ["5 5 1\n1 5\n", "5 5 1\n1 4\n", "9 5 1\n1 4\n", "5 6 1\n1 4\n", "4 6 1\n1 4\n", "5 7 1\n1 5\n", "9 5 1\n1 7\n", "9 5 1\n1 5\n"], "outputs": ["0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 ... | coding | 693 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A series of highways connect n cities numbered from 0 to n - 1. You are given a 2D integer array highways where highways[i] = [city1i, city2i, tolli] indicates that there is a highway that connects city1i and city2i, ... | {"functional": "def check(candidate):\n assert candidate(n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], discounts = 1) == 9\n assert candidate(n = 4, highways = [[1,3,17],[1,2,7],[3,2,5],[0,1,6],[3,0,20]], discounts = 20) == 8\n assert candidate(n = 4, highways = [[0,1,3],[2,3,2]], discounts = 0... | coding | 239 |
Solve the programming task below in a Python markdown code block.
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decide... | {"inputs": ["1\na\n", "1\na\n", "1\nb\n", "1\nc\n", "2\nz\nz\n", "1\nabc\n", "1\nabc\n", "2\nz\nz\n"], "outputs": ["1", "1\n", "1\n", "1\n", "2", "0", "0\n", "2\n"]} | coding | 397 |
Solve the programming task below in a Python markdown code block.
Eugene must do his homework, but he is struggling.
He has three integer numbers: A, N, M. He writes number A on the board N times in a row. Let's call the resulting big number X.
Help Eugene find X modulo M.
Input Format
First line contains T, the n... | {"inputs": ["2 \n12 2 17 \n523 3 11 \n"], "outputs": ["5\n6\n"]} | coding | 278 |
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"]} | coding | 486 |
Solve the programming task below in a Python markdown code block.
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2.
This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actuall... | {"inputs": ["6\n1\n3\n0", "6\n4\n2\n0", "6\n0\n2\n0", "6\n4\n0\n0", "6\n1\n0\n0", "6\n5\n8\n0", "6\n2\n2\n0", "6\n2\n3\n0"], "outputs": ["1\n0\n0\n", "1\n1\n0\n", "1\n", "1\n1\n", "1\n0\n", "1\n1\n1\n", "1\n0\n0\n", "1\n0\n0\n"]} | coding | 290 |
Solve the programming task below in a Python markdown code block.
Input
The input contains two integers a1, a2 (0 ≤ ai ≤ 109), separated by a single space.
Output
Output a single integer.
Examples
Input
3 14
Output
44
Input
27 12
Output
48
Input
100 200
Output
102 | {"inputs": ["0 0\n", "2 3\n", "1 3\n", "2 14\n", "3 12\n", "2 21\n", "3 19\n", "2 19\n"], "outputs": ["0\n", "5\n", "4\n", "43\n", "24\n", "14\n", "94\n", "93\n"]} | coding | 90 |
Solve the programming task below in a Python markdown code block.
You certainly can tell which is the larger number between 2^(10) and 2^(15).
But what about, say, 2^(10) and 3^(10)? You know this one too.
Things tend to get a bit more complicated with **both** different bases and exponents: which is larger between 3... | {"functional": "_inputs = [[[2, 10], [2, 15]], [[1, 10], [3, 10]], [[2, 10], [2, 10]], [[3, 9], [1, 6]], [[1, 7], [1, 8]], [[2, 100], [2, 150]], [[2, 100], [3, 100]], [[2, 100], [2, 100]], [[34, 98], [51, 67]], [[1024, 97], [1024, 81]]]\n_outputs = [[1], [1], [0], [-1], [0], [1], [1], [0], [-1], [-1]]\nimport math\ndef... | coding | 319 |
Solve the programming task below in a Python markdown code block.
Chef bought car insurance. The policy of the insurance is:
The maximum rebatable amount for any damage is Rs X lakhs.
If the amount required for repairing the damage is ≤ X lakhs, that amount is rebated in full.
Chef's car meets an accident and require... | {"inputs": ["4\n5 3\n5 8\n4 4\n15 12\n"], "outputs": ["3\n5\n4\n12\n"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
We have N weights indexed 1 to N. The mass of the weight indexed i is W_i.
We will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \leq T < N. Let S_1 be the sum... | {"inputs": ["3\n1 2 2", "3\n1 1 2", "3\n1 2 3", "3\n1 2 3\n", "4\n2 3 1 1", "4\n2 3 1 0", "4\n1 3 1 1", "4\n1 3 1 1\n"], "outputs": ["1\n", "0\n", "0", "0\n", "3\n", "2\n", "2", "2\n"]} | coding | 273 |
Solve the programming task below in a Python markdown code block.
Give you N cards. Only one natural number is written on each card. However, the same number is never written.
From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the number on... | {"inputs": ["3 3\n9 3 8\n6\n6\n5", "3 3\n9 3 8\n4\n6\n3", "3 3\n9 3 8\n6\n6\n2", "3 2\n1 3 8\n4\n6\n3", "3 3\n9 2 8\n4\n6\n5", "3 3\n9 3 8\n4\n6\n1", "3 2\n0 3 8\n4\n3\n3", "3 2\n0 3 4\n4\n6\n4"], "outputs": ["3\n3\n4\n", "3\n3\n2\n", "3\n3\n1\n", "3\n3\n", "2\n3\n4\n", "3\n3\n0\n", "3\n2\n", "3\n4\n"]} | coding | 428 |
Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.
A message is a sequence of n integers a1, a2... | {"inputs": ["3 1 5\n1 2 5\n4\n", "3 1 5\n1 2 3\n4\n", "5 2 7\n0 0 1 2 4\n3 5\n", "5 2 7\n0 0 1 2 4\n3 0\n", "4 3 2\n1 1 1 1\n1 1 2\n", "4 3 2\n1 1 1 1\n0 1 2\n", "4 3 2\n1 2 1 1\n0 1 2\n", "4 3 2\n1 1 1 1\n0 1 1\n"], "outputs": ["0 1 4\n", "0 1 2 \n", "3 1 2 3 2 \n", "3 3 4 5 4\n", "0 1 0 1\n", "1 0 0 1\n", "1 1 0 1\n"... | coding | 580 |
Solve the programming task below in a Python markdown code block.
Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share referenc... | {"inputs": ["340\n5277\n9302\n7274\n3\n5968\n1327\n255\n27\n5665\n8104\n138\n4051\n4168\n507\n7773\n2688\n3497\n4074\n1403\n3599\n2007\n7621\n3124\n1195\n7245\n1979\n3365\n6607\n4816\n9336\n3620\n1557\n3404\n5451\n3739\n2504\n1845\n5533\n8298\n2893\n7814\n2505\n9785\n4709\n7880\n6262\n5135\n2088\n9309\n7259\n9993\n325\... | coding | 208 |
Solve the programming task below in a Python markdown code block.
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unr... | {"inputs": ["4\nAGCT\n", "4\nAA??\n", "4\n????\n", "4\n??A?\n", "4\n?C??\n", "4\nT???\n", "4\n???G\n", "4\n??AC\n"], "outputs": ["AGCT\n", "===\n", "ACGT\n", "CGAT\n", "ACGT\n", "TACG\n", "ACTG\n", "GTAC\n"]} | coding | 427 |
Solve the programming task below in a Python markdown code block.
Consider the following pseudocode, run on an array $A=[a_0,a_1,...,a_{n-1}]$ of length $n$:
rep := 0
while A not empty:
B := []
for x in A, y in A:
if x != y: append absolute_value(x - y) to B
A := B
rep := rep + 1
Given the val... | {"inputs": ["3\n1 3 4\n"], "outputs": ["4\n"]} | coding | 438 |
Solve the programming task below in a Python markdown code block.
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.
T... | {"inputs": ["5\n2 1 8 15 3\n", "5\n0 1 8 15 3\n", "5\n1 1 8 15 3\n", "5\n1 2 8 15 3\n", "5\n1 2 9 15 3\n", "5\n1 2 9 15 4\n", "5\n0 2 9 15 4\n", "5\n15 1 8 15 3\n"], "outputs": ["0 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "-1 -1 1 0 -1 ", "3 -1 1 0 -1 "]} | coding | 438 |
Solve the programming task below in a Python markdown code block.
Write a function that removes every lone 9 that is inbetween 7s.
```python
seven_ate9('79712312') => '7712312'
seven_ate9('79797') => '777'
```
Input: String
Output: String
Also feel free to reuse/extend the following starter code:
```python
def seven_... | {"functional": "_inputs = [['165561786121789797'], ['797'], ['7979797'], ['16797'], ['77'], ['7927'], ['1779'], ['a779'], ['17797a'], ['797 9 7']]\n_outputs = [['16556178612178977'], ['77'], ['7777'], ['1677'], ['77'], ['7927'], ['1779'], ['a779'], ['1777a'], ['77 9 7']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ... | coding | 108 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$.
You are also given a set of distinct positions $p_1, p_2, \dots, p_m$, where $1 \le p_i < n$. The position $p_i$ means that you can swap elements $a[p_i]$ and $a[p_i + 1]$. You can apply this operation any numbe... | {"inputs": ["1\n3 1\n3 1 1\n1\n", "1\n3 1\n3 1 1\n1\n", "1\n3 1\n3 2 1\n1\n", "1\n4 2\n4 4 1 2\n2 1\n", "1\n4 2\n4 4 1 2\n2 1\n", "1\n4 2\n4 3 1 2\n2 1\n", "1\n4 2\n6 3 1 2\n2 1\n", "1\n4 1\n4 4 1 2\n2 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 723 |
Solve the programming task below in a Python markdown code block.
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city.
For this reason, he made the n prisoners to stand in a line, with a numb... | {"inputs": ["1 1 1\n2\n", "1 0 1\n2\n", "1 1 1\n2\n", "1 -1 1\n2\n", "1 -2 1\n2\n", "1 228 1\n1\n", "1 228 1\n1\n", "1 230 1\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n"]} | coding | 391 |
Solve the programming task below in a Python markdown code block.
Sunuke-kun's dictionary contains the words s1, ..., sn, which consist of n lowercase letters. This satisfies s1 <... <sn when compared in lexicographical order. Unfortunately, some characters are faint and unreadable. Unreadable characters are represente... | {"inputs": ["3\nsnuje\n????e\neluns", "3\nsunje\n????e\neluns", "3\nsunje\n@???e\neluns", "3\nsunje\n@???e\nsnule", "3\njunse\n@???e\nsnule", "3\nesnuj\n@???e\nsnule", "3\nesnuj\n@?e??\nsnule", "3\nesnuj\n@?f??\nsnule"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 205 |
Solve the programming task below in a Python markdown code block.
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:
Given a number ... | {"inputs": ["1\n9\n", "1\n5\n", "1\n1\n", "1\n18\n", "1\n20\n", "1\n10\n", "2\n2 3\n", "2\n2 5\n"], "outputs": ["9\n", "4\n", "1\n", "30\n", "36\n", "12\n", "2\n2\n", "2\n4\n"]} | coding | 292 |
Solve the programming task below in a Python markdown code block.
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue... | {"inputs": ["1 1 10\n10\nR\n", "1 1 10\n10\nR\n", "1 1 20\n10\nR\n", "2 1 15\n5 6\nRG\n", "2 1 10\n5 5\nRG\n", "2 1 10\n5 6\nRR\n", "2 1 10\n5 5\nRG\n", "2 1 10\n5 6\nRR\n"], "outputs": ["0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 715 |
Solve the programming task below in a Python markdown code block.
B-Mansion and courier
Problem Statement
Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study.
However, on this day, $ N $... | {"inputs": ["1 1 5\n6", "1 2 9\n9", "1 1 5\n5", "1 1 5\n1", "1 1 2\n3", "1 2 4\n3", "1 1 0\n1", "1 1 5\n3"], "outputs": ["5\n", "7\n", "4\n", "3\n", "2\n", "1\n", "0\n", "3"]} | coding | 535 |
Solve the programming task below in a Python markdown code block.
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size.... | {"inputs": ["1 1\n1 2\n", "2 1\n2 1\n", "4 1\n2 2\n", "3 1\n2 1\n", "4 1\n4 2\n", "4 1\n4 4\n", "2 1\n4 4\n", "5 1\n10 5\n"], "outputs": ["2\n", "2\n", "4\n", "2\n", "8\n", "16\n", "8\n", "25\n"]} | coding | 273 |
Solve the programming task below in a Python markdown code block.
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of ... | {"inputs": ["1 1\n1\n1\n1\n", "1 20\n1\n1\n200000000\n", "2 2\n1 2\n1\n200000000\n", "2 5\n1 2\n1\n200000000\n", "1 1\n42\n5\n1\n41\n42\n43\n84\n", "1 1\n42\n5\n1\n39\n42\n43\n84\n", "1 1\n1000000\n1\n200000000\n", "1 1\n1000000\n1\n179035188\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n-1\n1\n-1\n-1\n", "-1\n-... | coding | 632 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:
i < j < k,
nums[j] - nums[i] == diff, a... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,4,6,7,10], diff = 3) == 2\n assert candidate(nums = [4,5,6,7,8,9], diff = 2) == 2\n\n\ncheck(Solution().arithmeticTriplets)"} | coding | 130 |
Solve the programming task below in a Python markdown code block.
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smalles... | {"inputs": ["8\n", "7\n", "1\n", "9\n", "2\n", "3\n", "5\n", "6\n"], "outputs": ["24", "64", "1", "36", "2\n", "4\n", "16\n", "12"]} | coding | 102 |
Solve the programming task below in a Python markdown code block.
A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with n vertices and a positive number k. Find the number... | {"inputs": ["5 3\n1 2\n2 3\n3 4\n1 5\n", "5 6\n1 2\n2 3\n3 4\n4 5\n", "5 6\n1 2\n2 3\n3 4\n3 5\n", "5 2\n1 2\n2 3\n3 4\n2 5\n", "5 3\n1 2\n2 3\n3 4\n4 5\n", "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6\n", "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6\n", "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6... | coding | 366 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.
Note that:
A number greater than 1 is called prime if it is divisible by only 1 and itself... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,3,7,10,6]) == 4\n assert candidate(nums = [2,4,8,16]) == 1\n\n\ncheck(Solution().distinctPrimeFactors)"} | coding | 118 |
Solve the programming task below in a Python markdown code block.
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to pla... | {"inputs": ["1 4\n", "2 2\n", "3 2\n", "2 1\n", "5 3\n", "5 2\n", "8 5\n", "1 3\n"], "outputs": ["3B\n", "Impossible\n", "1A1B\n", "1A\n", "1A1B1A\n", "2A1B\n", "1A1B1A1B\n", "2B\n"]} | coding | 671 |
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 has a sequence of integers $A_{1}, A_{2}, \ldots, A_{N}$. He takes a sheet of paper and for each non-empty subsequence $B$ of this sequence, he ... | {"inputs": ["3\n3\n2 2 3\n2\n1 2\n3\n1 2 2"], "outputs": ["0 6 1\n2 1\n3 4 0"]} | coding | 678 |
Solve the programming task below in a Python markdown code block.
------Read problems statements in Mandarin chinese
, Russian and Vietnamese as well. ------
Tumut, the best programmer in his village Applidz, invented a problem and decided to share it with you:
You are given two integer sequences $S_{1}, S_{2}, \dot... | {"inputs": ["2 2 3\n1 8\n2 3"], "outputs": ["2"]} | coding | 759 |
Solve the programming task below in a Python markdown code block.
Given is a positive even number N.
Find the number of strings s of length N consisting of `A`, `B`, and `C` that satisfy the following condition:
* s can be converted to the empty string by repeating the following operation:
* Choose two consecutive ch... | {"inputs": ["4", "8", "6", "0", "2", "14", "12", "16"], "outputs": ["63\n", "5407\n", "583\n", "1\n", "7", "4231815\n", "460815\n", "38745279\n"]} | coding | 266 |
Solve the programming task below in a Python markdown code block.
Chef has recently learnt some new facts about the famous number π. For example, he was surprised that ordinary fractions are sometimes used to represent this number approximately. For example, 22/7, 355/113 or even 103993/33102.
Soon, by calculating the ... | {"inputs": ["3\n1\n0\n0", "3\n1\n1\n0", "3\n2\n1\n0", "3\n2\n1\n1", "3\n0\n1\n1", "3\n1\n1\n1", "3\n1\n1\n2", "3\n1\n0\n1"], "outputs": ["3.1\n3\n3\n", "3.1\n3.1\n3\n", "3.14\n3.1\n3\n", "3.14\n3.1\n3.1\n", "3\n3.1\n3.1\n", "3.1\n3.1\n3.1\n", "3.1\n3.1\n3.14\n", "3.1\n3\n3.1\n"]} | coding | 566 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of length $n$ consisting only of lowercase Latin letters.
A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.
Your task is to... | {"inputs": ["2\naz\n", "2\nza\n", "2\nya\n", "2\nyb\n", "2\nby\n", "2\naz\n", "3\nabc\n", "3\nabc\n"], "outputs": ["3", "3\n", "3\n", "3\n", "3\n", "3\n", "3", "3\n"]} | coding | 575 |
Solve the programming task below in a Python markdown code block.
Consider the following expansion:
```Haskell
solve("3(ab)") = "ababab" -- "ab" repeats 3 times
solve("2(a3(b))" = "abbbabbb" -- "a3(b)" == "abbb" repeats twice.
```
Given a string, return the expansion of that string.
Input will consist of only lowerc... | {"functional": "_inputs = [['3(ab)'], ['2(a3(b))'], ['3(b(2(c)))'], ['k(a3(b(a2(c))))']]\n_outputs = [['ababab'], ['abbbabbb'], ['bccbccbcc'], ['kabaccbaccbacc']]\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... | coding | 187 |
Solve the programming task below in a Python markdown code block.
Joisino wants to evaluate the formula "A op B".
Here, A and B are integers, and the binary operator op is either + or -.
Your task is to evaluate the formula instead of her.
-----Constraints-----
- 1≦A,B≦10^9
- op is either + or -.
-----Input-----
Th... | {"inputs": ["0 + 2", "1 - 1", "1 - 7", "2 - 7", "1 - 4", "3 - 7", "9 - 4", "0 - 7"], "outputs": ["2\n", "0\n", "-6\n", "-5\n", "-3\n", "-4\n", "5\n", "-7\n"]} | coding | 141 |
Solve the programming task below in a Python markdown code block.
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.
Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboa... | {"inputs": ["aaa aaaaaa\n", "aaa aaaaaa\n", "aaa aabaaa\n", "aaa aaabaa\n", "aaa aaabab\n", "aaa baaaab\n", "'co-co-co, codeforces?!'\n", "'co-co-co, '!?secrofedoc\n"], "outputs": ["10\n", "10\n", "11\n", "10\n", "10\n", "11\n", "25\n", "25\n"]} | coding | 610 |
Solve the programming task below in a Python markdown code block.
Polycarp has n different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".
Polycarp wants to offer his set of n binary words to play a game "words". In th... | {"inputs": ["4\n4\n0001\n1000\n0011\n0111\n3\n010\n111\n0\n2\n00000\n00001\n4\n0\n001\n0001\n00001\n", "4\n4\n0001\n1000\n0011\n0111\n3\n010\n111\n0\n2\n00000\n00001\n4\n0\n101\n0001\n00001\n", "4\n4\n0001\n1000\n0011\n0111\n3\n011\n111\n0\n2\n00000\n00001\n4\n0\n001\n0011\n00000\n", "4\n4\n0001\n0000\n0011\n0111\n3\n0... | coding | 730 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.
The path does not need to start or end at the root or a leaf, but it mu... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([10,5,-3,3,2,None,11,3,-2,None,1]), targetSum = 8) == 3\n assert candidate(root = tree_node([5,4,8,11,None,13,4,7,2,None,None,5,1]), targetSum = 22) == 3\n\n\ncheck(Solution().pathSum)"} | coding | 172 |
Solve the programming task below in a Python markdown code block.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the... | {"inputs": ["2\n2 1", "2\n2 0", "2\n4 0", "2\n3 1", "2\n3 1\n", "2\n2 -1", "2\n4 -1", "2\n5 -2"], "outputs": ["1\n", "2\n", "4\n", "2", "2\n", "3\n", "5\n", "7\n"]} | coding | 269 |
Solve the programming task below in a Python markdown code block.
The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and $n$ cities in a circle around the capital. The capital already has a good network coverage (so the government igno... | {"inputs": ["1\n4\n3 3 3 3\n3 3 3 2\n", "1\n4\n3 3 3 3\n3 3 3 2\n", "1\n4\n3 3 3 4\n3 3 3 2\n", "1\n4\n3 3 3 4\n3 3 6 2\n", "1\n4\n3 3 3 4\n3 3 3 3\n", "1\n4\n3 3 3 4\n3 3 4 3\n", "1\n4\n3 3 3 8\n3 3 4 3\n", "1\n4\n3 3 3 15\n3 3 4 3\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n"]} | coding | 742 |
Solve the programming task below in a Python markdown code block.
Concatenate
Two or more arrays can be concatenated together using the concatenate function with a
tuple of the arrays to be joined:
import numpy
array_1 = numpy.array([1,2,3])
array_2 = numpy.array([4,5,6])
array_3 = numpy.array([7,8,9])
print nump... | {"inputs": ["4 3 2\n1 2\n1 2 \n1 2\n1 2\n3 4\n3 4\n3 4 \n"], "outputs": ["[[1 2]\n [1 2]\n [1 2]\n [1 2]\n [3 4]\n [3 4]\n [3 4]] \n"]} | coding | 490 |
Solve the programming task below in a Python markdown code block.
C: Only one subsequence --Unique Subsequence-
problem
One day Ebi-chan noticed that a text string T of length n and a pattern string P (m \ leq n) of length m were placed on the desk. Ebi-chan loves the "only one subsequence" that appears in strings, s... | {"inputs": ["aizucamp\nuza", "aziucamp\nazu", "azjucamp\nazu", "azjucamp\nazt", "azjucamp\nzat", "pmacujza\nzat", "pmacuiza\nzat", "pmicuaza\nzat"], "outputs": ["no\n", "yes\n", "yes\n", "no\n", "no\n", "no\n", "no\n", "no\n"]} | coding | 433 |
Solve the programming task below in a Python markdown code block.
Snuke lives at position x on a number line.
On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.
Snuke decided to get food delivery from the closer of stores A and B.
Find out which store is closer t... | {"inputs": ["5 1 7", "1 3 1", "1 3 0", "0 2 7", "6 1 7", "8 1 7", "4 2 9", "2 3 0"], "outputs": ["B\n", "B\n", "B\n", "A\n", "B\n", "B\n", "A\n", "A\n"]} | coding | 266 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Two strings, X and Y, are considered similar if either they are identical or we can make them equivalent by swapping at most two letters (in distinct positions) within the string X.
For example, "tars" and "rats" are ... | {"functional": "def check(candidate):\n assert candidate(strs = [\"tars\",\"rats\",\"arts\",\"star\"]) == 2\n assert candidate(strs = [\"omv\",\"ovm\"]) == 1\n\n\ncheck(Solution().numSimilarGroups)"} | coding | 252 |
Solve the programming task below in a Python markdown code block.
A positive integer is called a 2-3-integer, if it is equal to 2^{x}·3^{y} for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 10... | {"inputs": ["1 1\n", "2 2\n", "2 2\n", "1 1\n", "1 2\n", "1 10\n", "2 10\n", "1 10\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "7\n", "6\n", "7\n"]} | coding | 337 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.
Please complete the following python code precisely:
```python
class Solution:
def generateMatrix(self, n: ... | {"functional": "def check(candidate):\n assert candidate(n = 3) == [[1,2,3],[8,9,4],[7,6,5]]\n assert candidate(n = 1) == [[1]]\n\n\ncheck(Solution().generateMatrix)"} | coding | 74 |
Solve the programming task below in a Python markdown code block.
Implement a modified Fibonacci sequence using the following definition:
Given terms $t\left[i\right]$ and $t[i+1]$ where $i\in(1,\infty)$, term $t[i+2]$ is computed as:
$t_{i+2}=t_{i}+(t_{i+1})^{2}$
Given three integers, $\mbox{t1}$, $\mbox{t2}... | {"inputs": ["0 1 5\n"], "outputs": ["5\n"]} | coding | 504 |
Solve the programming task below in a Python markdown code block.
The Bitlandians are quite weird people. They have very peculiar customs.
As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.
The kids are excited because just as is cus... | {"inputs": ["1\n1 23\n", "1\n0 23\n", "1\n0 28\n", "1\n0 48\n", "1\n0 19\n", "1\n1 999\n", "1\n1 999\n", "1\n1 397\n"], "outputs": ["A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n"]} | coding | 545 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:
subtexti is a non-empty string.
The concatenation of all the substrings is equal to text (i.e., subtext1... | {"functional": "def check(candidate):\n assert candidate(text = \"ghiabcdefhelloadamhelloabcdefghi\") == 7\n assert candidate(text = \"merchant\") == 1\n assert candidate(text = \"antaprezatepzapreanta\") == 11\n\n\ncheck(Solution().longestDecomposition)"} | coding | 159 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:
Pick a non-empty prefix from the string s where all the characters i... | {"functional": "def check(candidate):\n assert candidate(s = \"ca\") == 2\n assert candidate(s = \"cabaabac\") == 0\n assert candidate(s = \"aabccabba\") == 3\n\n\ncheck(Solution().minimumLength)"} | coding | 171 |
Solve the programming task below in a Python markdown code block.
Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n steps. On... | {"inputs": ["1\n0\n1\n", "1\n0\n1\n", "2\n0 5\n4 0\n1 2\n", "2\n0 5\n7 0\n1 2\n", "2\n0 4\n7 0\n1 2\n", "2\n0 9\n7 0\n1 2\n", "2\n0 1\n7 0\n1 2\n", "2\n0 5\n4 0\n1 2\n"], "outputs": ["0 ", "0 \n", "9 0 ", "12 0", "11 0", "16 0", "8 0", "9 0 \n"]} | coding | 510 |
Solve the programming task below in a Python markdown code block.
Two players are playing a game of Tower Breakers! Player $1$ always moves first, and both players always play optimally.The rules of the game are as follows:
Initially there are $n$ towers.
Each tower is of height $m$.
The players move in alternat... | {"inputs": ["2\n2 2\n1 4\n"], "outputs": ["2\n1\n"]} | coding | 706 |
Solve the programming task below in a Python markdown code block.
You are given positive integers $L$ and $R$. You have to find the sum
S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,,
where $\wedge$ denotes the bitwise AND operation. Since the sum could ... | {"inputs": ["2\n1 4\n4 10"], "outputs": ["1\n16"]} | coding | 407 |
Solve the programming task below in a Python markdown code block.
Find the symmetric difference of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$
... | {"inputs": ["7\n1 2 3 4 5 6 8\n4\n2 4 6 8", "7\n1 2 3 4 5 6 7\n4\n1 4 6 8", "7\n1 2 3 4 5 6 8\n0\n4 9 6 9", "7\n1 2 3 4 5 6 7\n4\n2 4 6 8", "7\n1 2 3 4 5 6 7\n4\n2 4 6 11", "7\n1 2 3 4 5 6 7\n1\n2 4 6 11", "7\n1 2 3 4 5 6 10\n4\n1 4 6 8", "7\n1 2 3 4 5 6 10\n3\n1 4 6 8"], "outputs": ["1\n3\n5\n", "2\n3\n5\n7\n8\n", "1\... | coding | 288 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.
A word matches the pattern if there exists a permutation of letters p so that a... | {"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"deq\",\"mee\",\"aqq\",\"dkd\",\"ccc\"], pattern = \"abb\") == [\"mee\",\"aqq\"]\n\n\ncheck(Solution().findAndReplacePattern)"} | coding | 152 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
In Chefland, there are $N$ cities (numbered $1$ through $N$). Initially, there are no roads between them. The Mayor of Chefland has ordered engineer... | {"inputs": ["2\n3\n5"], "outputs": ["3\n8"]} | coding | 388 |
Solve the programming task below in a Python markdown code block.
A number is algebraic if it is a root of some nonzero polynomial with integer coefficients. A number is transcendental if it is not algebraic.
For example, ${11}$, ${i}$, $\sqrt[3]{2}$ and $\phi$ (golden ratio) are algebraic, because they are roots of $... | {"inputs": ["3\n1\n4\n3\n2 4 4\n4\n1 2 3 5\n"], "outputs": ["1\n2\n8\n"]} | coding | 657 |
Solve the programming task below in a Python markdown code block.
You are given an array of positive integers $a_1, a_2, \ldots, a_n$.
Make the product of all the numbers in the array (that is, $a_1 \cdot a_2 \cdot \ldots \cdot a_n$) divisible by $2^n$.
You can perform the following operation as many times as you lik... | {"inputs": ["6\n1\n2\n2\n3 2\n3\n10 6 11\n4\n13 17 1 1\n5\n1 1 12 1 1\n6\n20 7 14 18 3 5\n"], "outputs": ["0\n1\n1\n-1\n2\n1\n"]} | coding | 699 |
Solve the programming task below in a Python markdown code block.
You are given three positive integers N, x, and y.
Count the number of arrays P of length N such that:
P_{1} = P_{N} = 1
There are exactly x indices i such that P_{i}=1
There are exactly y indices i such that P_{i}=2
There are exactly N-x-y indices i su... | {"inputs": ["5 3 1\n", "10 4 3\n"], "outputs": ["2", "44"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.
This problem is similar to a standard pr... | {"inputs": ["1 1\n1 0\n1\n", "1 1\n1 1\n1\n", "1 1\n1 -1\n1\n", "2 1\n2 -4 -6\n5 6 8 3 5 -2\n1\n", "2 1\n2 -4 -6\n5 6 8 3 5 -3\n1\n", "2 1\n2 -4 -10\n5 6 8 3 5 -3\n1\n", "3 4\n3 1 6 -2\n2 4 3\n2 -5 1\n2 3 1 3\n", "3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3\n"], "outputs": ["0", "1", "-1", "-4", "-4\n", "-4\n", "10\n", "9"]} | coding | 724 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.
For every i and j where 0 <= i < j < arr.length, we consider the frac... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,5], k = 3) == [2,5]\n assert candidate(arr = [1,7], k = 1) == [1,7]\n\n\ncheck(Solution().kthSmallestPrimeFraction)"} | coding | 155 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. In one move, you can either multiply $n$ by two or divide $n$ by $6$ (if it is divisible by $6$ without the remainder).
Your task is to find the minimum number of moves needed to obtain $1$ from $n$ or determine if it's imp... | {"inputs": ["1\n64693265\n", "1\n10872979\n", "1\n21674312\n", "1\n32114318\n", "1\n54097276\n", "1\n65971871\n", "1\n93108643\n", "1\n30365546\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
It's the most hotly anticipated game of the school year - Gryffindor vs Slytherin! Write a function which returns the winning team.
You will be given two arrays with two values.
The first given value is the number of points scored by the team's Chase... | {"functional": "_inputs = [[[100, 'yes'], [100, 'no']], [[350, 'no'], [250, 'yes']], [[100, 'yes'], [250, 'no']], [[0, 'yes'], [150, 'no']], [[150, 'no'], [0, 'yes']]]\n_outputs = [['Gryffindor wins!'], ['Slytherin wins!'], [\"It's a draw!\"], [\"It's a draw!\"], [\"It's a draw!\"]]\nimport math\ndef _deep_eq(a, b, tol... | coding | 205 |
Solve the programming task below in a Python markdown code block.
You are playing a very popular computer game. The next level consists of $n$ consecutive locations, numbered from $1$ to $n$, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the... | {"inputs": ["3\n2\n1 1\n5\n1 0 1 0 1\n4\n1 0 1 1\n"], "outputs": ["0\n4\n2\n"]} | coding | 576 |
Solve the programming task below in a Python markdown code block.
The city of Gridland is represented as an $n\times m$ matrix where the rows are numbered from $1$ to $n$ and the columns are numbered from $1$ to $m$.
Gridland has a network of train tracks that always run in straight horizontal lines along a row. In ot... | {"inputs": ["4 4 3\n2 2 3\n3 1 4\n4 4 4\n"], "outputs": ["9\n"]} | coding | 702 |
Solve the programming task below in a Python markdown code block.
You recently received a bag of chocolate sticks for Halloween. To prevent you from compulsively eating all the chocolate sticks in one go, your dietician devises the following fun game.
In each move, you choose one of the sticks from your bag. Then, you... | {"inputs": ["1\n6\n", "3\n1 7 24\n"], "outputs": ["10\n", "55\n"]} | coding | 507 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given ind... | {"functional": "def check(candidate):\n assert candidate(s = \"LeetcodeHelpsMeLearn\", spaces = [8,13,15]) == \"Leetcode Helps Me Learn\"\n assert candidate(s = \"icodeinpython\", spaces = [1,5,7,9]) == \"i code in py thon\"\n assert candidate(s = \"spacing\", spaces = [0,1,2,3,4,5,6]) == \" s p a c i n g\"\n\... | coding | 160 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array houses where houses[i] is the location of the ith house along a street and an integer k, allocate k mailboxes in the street.
Return the minimum total distance between each house and its nearest mailbox... | {"functional": "def check(candidate):\n assert candidate(houses = [1,4,8,10,20], k = 3) == 5\n assert candidate(houses = [2,3,5,12,18], k = 2) == 9\n assert candidate(houses = [7,4,6,1], k = 1) == 8\n assert candidate(houses = [3,6,14,10], k = 4) == 0\n\n\ncheck(Solution().minDistance)"} | coding | 114 |
Solve the programming task below in a Python markdown code block.
You are given a binary string S. A binary string is a string consisting of only 0's and 1's.
A binary string is called *good* if it has an equal number of occurrences of \texttt{01} substrings and \texttt{10} substrings. Note that these substrings may o... | {"inputs": ["2\n10100\n11111"], "outputs": ["2\n3"]} | coding | 712 |
Solve the programming task below in a Python markdown code block.
Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.
Polycarp decided to store the hash of the password, generated by the following algorithm: take the passwor... | {"inputs": ["1\na\nabcd\n", "1\na\nabcd\n", "1\na\ndbca\n", "1\na\nebca\n", "1\na\nabce\n", "1\ndaaaaaaaa\nbbbbbbbbb\n", "1\ndaaaaaaaa\nbbbbbbbbb\n", "1\ndaaaaaaba\nbbbbbbbbb\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | coding | 613 |
Solve the programming task below in a Python markdown code block.
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that ... | {"inputs": ["5\n", "7\n", "4\n", "9\n", "6\n", "2\n", "8\n", "3\n"], "outputs": ["5\n01111\n10111\n11010\n11100\n11000\n", "5\n01111\n10111\n11011\n11100\n11100\n", "4\n0111\n1011\n1101\n1110\n", "7\n0111111\n1011111\n1101100\n1110000\n1110000\n1100000\n1100000\n", "6\n011111\n101111\n110100\n111000\n110000\n110000\n",... | coding | 356 |
Solve the programming task below in a Python markdown code block.
We define a magic square to be an $n\times n$ matrix of distinct positive integers from $\mbox{1}$ to $n^2$ where the sum of any row, column, or diagonal of length $n$ is always equal to the same number: the magic constant.
You will be given a $3\time... | {"inputs": ["4 9 2\n3 5 7\n8 1 5\n", "4 8 2\n4 5 7\n6 1 6\n"], "outputs": ["1\n", "4\n"]} | coding | 650 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the ith car does not contain illegal goods and s[i] = '1' denotes that the ith car does contain illegal good... | {"functional": "def check(candidate):\n assert candidate(s = \"1100101\") == 5\n assert candidate(s = \"0010\") == 2\n\n\ncheck(Solution().minimumTime)"} | coding | 234 |
Solve the programming task below in a Python markdown code block.
There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.
Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.
Recently, they learned the operation called xor (exclusive OR).What is xor?
For n non-negative int... | {"inputs": ["4\n1 2 0 49", "4\n2 2 0 49", "4\n2 0 0 49", "4\n2 0 1 49", "4\n0 0 1 49", "4\n1 0 1 49", "4\n1 0 2 49", "4\n1 0 3 49"], "outputs": ["51 48 50 3\n", "51 51 49 0\n", "49 51 51 2\n", "48 50 51 3\n", "48 48 49 1\n", "48 49 48 0\n", "51 50 48 3\n", "50 51 48 2\n"]} | coding | 666 |
Solve the programming task below in a Python markdown code block.
It is a simplified version of problem F2. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is ca... | {"inputs": ["1\n4320 2\n", "1\n9319 2\n", "1\n5952 2\n", "1\n7778 2\n", "1\n5878 2\n", "1\n4025 2\n", "1\n89258 1\n", "1\n76353 2\n"], "outputs": ["4333\n", "9333\n", "5955\n", "7778\n", "5885\n", "4040\n", "99999\n", "76666\n"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given two numbers, n and k and your task will be to return the k-digit array that sums to n and has the maximum possible GCD.
For example, given `n = 12, k = 3`, there are a number of possible `3-digit` arrays that sum to `12`,... | {"functional": "_inputs = [[12, 7], [12, 3], [12, 4], [18, 3], [18, 5], [24, 3], [24, 4], [24, 5], [24, 6], [276, 12]]\n_outputs = [[[]], [[2, 4, 6]], [[1, 2, 3, 6]], [[3, 6, 9]], [[1, 2, 3, 4, 8]], [[4, 8, 12]], [[2, 4, 6, 12]], [[1, 2, 3, 4, 14]], [[1, 2, 3, 4, 5, 9]], [[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 78]]]... | coding | 225 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
Please complete the following python code precisely:
```python
class Solution:
def topKF... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,1,2,2,3], k = 2) == [1,2]\n assert candidate(nums = [1], k = 1) == [1]\n\n\ncheck(Solution().topKFrequent)"} | coding | 80 |
Solve the programming task below in a Python markdown code block.
A newly opened multinational brand has decided to base their company logo on the three most common characters in the company name. They are now trying out various combinations of company names and logos based on this condition. Given a string $\boldsymbo... | {"inputs": ["aabbbccde\n"], "outputs": ["b 3\na 2\nc 2\n"]} | coding | 380 |
Solve the programming task below in a Python markdown code block.
Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path.
To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help him to f... | {"inputs": ["1\n2 L 2 R 2 L 1"], "outputs": ["5.0NW"]} | coding | 308 |
Solve the programming task below in a Python markdown code block.
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?
-----Constraints-----
- N is an integer between 1 and ... | {"inputs": ["0", "1", "2", "3", "6", "9", "5", "8"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 147 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer 2D array nodes, your task is to determine if the given array represents the preorder traversal of some binary tree.
For each index i, nodes[i] = [id, parentId], where id is the id of the node... | {"functional": "def check(candidate):\n assert candidate(nodes = [[0,-1],[1,0],[2,0],[3,2],[4,2]]) == True\n assert candidate(nodes = [[0,-1],[1,0],[2,0],[3,1],[4,1]]) == False\n\n\ncheck(Solution().isPreorder)"} | coding | 197 |
Solve the programming task below in a Python markdown code block.
You have an array of numbers.
Your task is to sort ascending odd numbers but even numbers must be on their places.
Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it.
*Example*
```python
sort_arr... | {"functional": "_inputs = [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]]\n_outputs = [[[1, 3, 2, 8, 5, 4, 11]], [[2, 22, 1, 5, 4, 11, 37, 0]], [[1, 1, 5, 11, 2, 11, 111, 0]], ... | coding | 135 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. The array is sorted if $a_1 \le a_2 \le \dots \le a_n$.
You want to make the array $a$ sorted by applying the following operation exactly once:
choose an integer $x$, then for every $i \in [1, n]$,... | {"inputs": ["2\n2\n1 2\n2\n1 2\n", "2\n3\n1 2 3\n3\n1 2 3\n", "8\n5\n5 3 3 3 5\n4\n5 3 4 5\n8\n1 2 3 4 5 6 7 8\n6\n10 5 4 3 2 1\n3\n3 3 1\n3\n42 43 42\n2\n100000000 99999999\n6\n29613295 52036613 75100585 78027446 81409090 73215\n"], "outputs": ["0\n0\n", "0\n0\n", "4\n-1\n0\n8\n2\n-1\n100000000\n40741153\n"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Consider an ordered tree with N vertices. Your task is to calculate the expected value of the number of vertices having exactly one child in such tree assuming that it is uni... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["0 0\n1 1\n1 1\n400000004 200000003"]} | coding | 466 |
Solve the programming task below in a Python markdown code block.
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in t... | {"inputs": ["1\n1 2\n", "1\n2 1\n", "1\n1 2\n", "1\n2 1\n", "1\n1 4\n", "1\n2 0\n", "1\n0 1\n", "1\n2 4\n"], "outputs": ["1\n0\n", "0\n1\n", "1\n0\n", "0\n1\n", "1\n0\n", "0\n1\n", "1\n0\n", "1\n0\n"]} | coding | 761 |
Solve the programming task below in a Python markdown code block.
To give credit where credit is due: This problem was taken from the ACMICPC-Northwest Regional Programming Contest. Thank you problem writers.
You are helping an archaeologist decipher some runes. He knows that this ancient society used a Base 10 system... | {"functional": "_inputs = [['123?45*?=?'], ['?*123?45=?'], ['??605*-63=-73???5'], ['123?45+?=123?45'], ['?8?170-1?6256=7?2?14'], ['?38???+595???=833444'], ['123?45-?=123?45'], ['-7715?5--484?00=-28?9?5'], ['50685?--1?5630=652?8?'], ['??+??=??'], ['-?56373--9216=-?47157']]\n_outputs = [[0], [0], [1], [0], [9], [2], [0],... | coding | 520 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Mike takes part in programming contests. His favourite topic is dynamic programming(DP). As he said, that he likes problems on DP, because "you spend a lot of time on thinking and a litt... | {"inputs": ["5\n1 1\n2 2\n2 3\n2 4\n2 5"], "outputs": ["1 5 6 9 10 12 13 14 15 "]} | coding | 599 |
Solve the programming task below in a Python markdown code block.
As we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters... | {"inputs": ["4\nabcd\nxyz\nabcd\nbcda\nacba\nacaa\nCodechef\nelfedcc", "4\nbdca\nxyz\nabcd\nbcda\nabca\nacaa\nCodechff\nelfedcc", "4\nbdca\nyyz\nabdd\nbcda\nabca\nacaa\nCodechff\nelfedcc", "4\nabcd\nxyz\nabcd\nbcda\nacba\nacba\nCodechef\nelfedcc", "4\nbdca\nxyz\nabcd\nbcea\nabca\nacaa\nCodechef\nelfedcc", "4\nbdca\nyyz... | coding | 426 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.