problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.
The mapped value of an integer i... | {"functional": "def check(candidate):\n assert candidate(mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]) == [338,38,991]\n assert candidate(mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]) == [123,456,789]\n\n\ncheck(Solution().sortJumbled)"} | coding | 198 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
English description is not available for the problem. Please switch to Chinese.
Please complete the following python code precisely:
```python
class Solution:
def fraction(self, cont: List[int]) -> List[int]:
... | {"functional": "def check(candidate):\n assert candidate(cont = [3, 2, 0, 2]) == [13, 4]\n assert candidate(cont = [0, 0, 3]) == [3, 1]\n\n\ncheck(Solution().fraction)"} | coding | 63 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a b... | {"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2) == True\n assert candidate(n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5) == False\n\n\ncheck(Solution().validPath)"} | coding | 196 |
Solve the programming task below in a Python markdown code block.
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length $n$ consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard;... | {"inputs": ["3\nxdd\n1 2 3\n", "3\nxdd\n1 2 3\n", "3\nxdd\n2 2 3\n", "3\nxdd\n2 3 3\n", "3\nxdd\n1 3 3\n", "3\nxdd\n1 4 3\n", "3\nxdd\n1 8 3\n", "3\nxdd\n1 8 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 559 |
Solve the programming task below in a Python markdown code block.
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radi... | {"inputs": ["2 4 2 2 1", "2 8 2 0 0", "5 4 2 0 1", "2 4 2 2 2", "5 8 2 0 1", "2 6 2 2 2", "2 8 2 0 1", "3 6 2 2 2"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 206 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. You may perform the following operation any number of times: select any two adjacent elements... | {"inputs": ["4\n2\n7 4\n3\n1 2 2\n5\n5 5 5 5 5\n8\n7 2 4 1 6 8 3 9"], "outputs": ["No\nYes\nNo\nYes"]} | coding | 667 |
Solve the programming task below in a Python markdown code block.
There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)
What is the area of ... | {"inputs": ["6 7", "2 1", "0 2", "0 4", "9 2", "2 4", "0 0", "7 2"], "outputs": ["30\n", "0\n", "-1\n", "-3\n", "8\n", "3\n", "1\n", "6\n"]} | coding | 192 |
Solve the programming task below in a Python markdown code block.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
- In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q)... | {"inputs": ["4\n1 2 3 3\n3\n1 2\n3 4\n2 4", "4\n2 1 1 1\n3\n1 2\n2 1\n3 5", "4\n1 2 3 3\n3\n1 2\n3 4\n0 4", "4\n0 1 1 1\n3\n1 2\n2 1\n3 5", "4\n1 3 3 3\n3\n1 2\n3 4\n0 4", "4\n1 3 4 3\n3\n1 2\n3 4\n0 4", "4\n0 2 4 3\n3\n1 2\n3 4\n0 4", "4\n0 2 4 4\n3\n1 4\n3 4\n0 4"], "outputs": ["10\n12\n16\n", "8\n4\n4\n", "10\n12\n1... | coding | 380 |
Solve the programming task below in a Python markdown code block.
We are given a sequence of coplanar points and see all the possible triangles that may be generated which all combinations of three points.
We have the following list of points with the cartesian coordinates of each one:
```
Points [x, y]
A [1, 2]
... | {"functional": "_inputs = [[[[1, 2], [3, 3], [4, 1], [1, 1], [4, -1]]], [[[1, 2], [4, -1], [3, 3], [4, -1], [4, 1], [1, 1], [4, -1], [4, -1], [3, 3], [1, 2]]]]\n_outputs = [[3], [3]]\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_... | coding | 362 |
Solve the programming task below in a Python markdown code block.
You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.
All strings that ca... | {"inputs": ["0", "1", "2", "4", "3", "5", "9", "8"], "outputs": ["0\n", "1\n", "2\n", "4\n", "3\n", "5\n", "9\n", "8\n"]} | coding | 274 |
Solve the programming task below in a Python markdown code block.
C: Skewering
problem
One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura.
There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of... | {"inputs": ["2 1 1", "2 1 2", "4 1 2", "2 1 0", "4 1 3", "2 2 0", "0 1 2", "7 1 3"], "outputs": ["Hom\n", "Tem\n", "Tem\n", "Tem\n", "Hom\n", "Tem\n", "Tem\n", "Hom\n"]} | coding | 476 |
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"]} | coding | 359 |
Solve the programming task below in a Python markdown code block.
You are wandering in the explorer space of the 2050 Conference.
The explorer space can be viewed as an undirected weighted grid graph with size n× m. The set of vertices is \{(i, j)|1≤ i≤ n, 1≤ j≤ m\}. Two vertices (i_1,j_1) and (i_2, j_2) are connected... | {"inputs": ["2 2 3\n1\n3\n4 2\n", "2 2 4\n1\n2\n1 4\n", "2 2 4\n1\n4\n4 2\n", "2 2 4\n2\n2\n1 4\n", "2 2 6\n1\n4\n4 2\n", "2 2 4\n1\n2\n2 4\n", "2 2 6\n1\n4\n4 0\n", "2 2 4\n1\n4\n2 4\n"], "outputs": ["-1 -1\n-1 -1\n", "4 4\n4 6\n", "4 4\n10 6\n", "4 6\n4 6\n", "6 6\n12 8\n", "4 4\n6 8\n", "2 0\n8 0\n", "4 4\n6 10\n"]} | coding | 730 |
Solve the programming task below in a Python markdown code block.
In olden days finding square roots seemed to be difficult but nowadays it can be easily done using in-built functions available across many languages
.
Assume that you happen to hear the above words and you want to give a try in finding the square root... | {"inputs": ["3\n1\n5\n10000", "3\n1\n2\n10000", "3\n2\n6\n11100", "3\n4\n4\n10001", "3\n2\n1\n11101", "3\n4\n6\n11100", "3\n2\n9\n00011", "3\n2\n1\n00001"], "outputs": ["1\n2\n100\n", "1\n1\n100\n", "1\n2\n105\n", "2\n2\n100\n", "1\n1\n105\n", "2\n2\n105\n", "1\n3\n3\n", "1\n1\n1\n"]} | coding | 205 |
Solve the programming task below in a Python markdown code block.
Subodh is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch.
Suppose we have 5 branches and all of them have... | {"inputs": ["6\n5 4 4 2 2 8"], "outputs": ["6\n4\n2\n1"]} | coding | 278 |
Solve the programming task below in a Python markdown code block.
# Description:
Find the longest successive exclamation marks and question marks combination in the string. A successive exclamation marks and question marks combination must contains two part: a substring of "!" and a substring "?", they are adjacent. ... | {"functional": "_inputs = [['!!'], ['!??'], ['!?!!'], ['!!???!????'], ['!!???!?????'], ['!????!!!?'], ['!?!!??!!!?']]\n_outputs = [[''], ['!??'], ['?!!'], ['!!???'], ['!?????'], ['????!!!'], ['??!!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | coding | 280 |
Solve the programming task below in a Python markdown code block.
For 3 distinct prime integers A, B, and C (1 < A,B,C < 2^{30}), we define positive integers X, Y, and Z as:
X = A\oplus B, Y = B\oplus C, and Z = C\oplus A, where \oplus denotes the [bitwise XOR] operation.
Given only two integers X and Y and the fa... | {"inputs": ["2\n1 6\n9 15"], "outputs": ["2 3 5\n2 11 13"]} | coding | 540 |
Solve the programming task below in a Python markdown code block.
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself,... | {"inputs": ["1\n", "8\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n"], "outputs": ["8\n", "54\n", "16\n", "24\n", "27\n", "32\n", "40\n", "48\n"]} | coding | 619 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese] and [Bengali].
There is an empty bus with M seats and a total of N people, numbered from 1 to N. Everyone is currently outside the bus. You are given a sequence of Q events of the following form.
- +\ i : ... | {"inputs": ["2\n2 1 4\n+ 1\n+ 2\n- 1\n- 2\n3 2 6\n+ 2\n+ 1\n- 1\n+ 3\n- 3\n- 2", "2\n100 10 5\n+ 1\n+ 2\n- 3\n+ 3\n- 2\n6 4 4\n+ 3\n+ 2\n+ 1\n+ 4\n"], "outputs": ["Inconsistent\nConsistent", "Inconsistent\nConsistent\n"]} | coding | 616 |
Solve the programming task below in a Python markdown code block.
Chef made two laddus with sweetness X and Y respectively. Cheffina comes and sees the chef created two laddus with different sweetness (might be same). Cheffina has the magical power to make the sweetness of laddus equal. Cheffina requires 1 unit of powe... | {"inputs": ["2\n2 2\n4 6"], "outputs": ["0\n3"]} | coding | 328 |
Solve the programming task below in a Python markdown code block.
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.
Magically, all the numbers were shuffled in arbitrary order while this note was passed t... | {"inputs": ["01\n0\n", "13\n3\n", "14\n4\n", "21\n2\n", "12\n2\n", "10\n0\n", "10\n0\n", "13\n3\n"], "outputs": ["0\n", "3\n", "4\n", "2\n", "2\n", "0\n", "0", "3"]} | coding | 318 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return true if it is a power of four. Otherwise, return false.
An integer n is a power of four, if there exists an integer x such that n == 4x.
Please complete the following python code precisely... | {"functional": "def check(candidate):\n assert candidate(n = 16) == True\n assert candidate(n = 5) == False\n assert candidate(n = 1) == True\n\n\ncheck(Solution().isPowerOfFour)"} | coding | 92 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.
Please complete the following python code precisely:
```python
class Solution:
def maxSum... | {"functional": "def check(candidate):\n assert candidate(nums = [3,6,5,1,8]) == 18\n assert candidate(nums = [4]) == 0\n assert candidate(nums = [1,2,3,4,4]) == 12\n\n\ncheck(Solution().maxSumDivThree)"} | coding | 74 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice and Bob take turns playing a game, with Alice starting first.
There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and B... | {"functional": "def check(candidate):\n assert candidate(aliceValues = [1,3], bobValues = [2,1]) == 1\n assert candidate(aliceValues = [1,2], bobValues = [3,1]) == 0\n assert candidate(aliceValues = [2,4,3], bobValues = [1,6,7]) == -1\n\n\ncheck(Solution().stoneGameVI)"} | coding | 237 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
The *beauty* of a sequence of non-negative integers is computed in the following way: for each of its non-empty (not necessarily contiguous) subseque... | {"inputs": ["3\n2 2 7\n4 3 17\n3 5 13"], "outputs": ["6\n-1\n28"]} | coding | 461 |
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 clock, but it got broken today — the minute hand on Chef's clock doesn't rotate by the angle 2π/3600 each second, but by a different fixed angle x. The coordinates... | {"inputs": ["3\n4 2 1\n4 2 2\n4 2 3"], "outputs": ["2\n1000000005\n1000000003"]} | coding | 612 |
Solve the programming task below in a Python markdown code block.
Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The a... | {"inputs": ["(\n1\n1 1\n", ")\n1\n1 1\n", "(\n1\n1 1\n", ")\n1\n1 1\n", "()\n1\n1 2\n", ")(\n1\n1 2\n", ")(\n1\n1 2\n", "()\n1\n1 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "2\n", "0\n", "0\n", "2\n"]} | coding | 556 |
Solve the programming task below in a Python markdown code block.
Chef wants to gift C chocolates to Botswal on his birthday. However, he has only X chocolates with him.
The cost of 1 chocolate is Y rupees.
Find the minimum money in rupees Chef needs to spend so that he can gift C chocolates to Botswal.
------ Inp... | {"inputs": ["2\n7 5 5\n10 1 1"], "outputs": ["10\n9"]} | coding | 322 |
Solve the programming task below in a Python markdown code block.
In 17th century our Chef was a Wizard. He asked his small son "Anshu" to bring him the secret of the Magical Mountain. The boy after travelling a lot reached the Mountain.
The description of the Mountain was as follows:
- Mountain contains N magical sto... | {"inputs": ["1\n5\n1 2\n1 3\n2 4\n2 5"], "outputs": ["1 2 3 4 5"]} | coding | 475 |
Solve the programming task below in a Python markdown code block.
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
SelectionSort(A)
1 for i = 0 to A.length-1
2 mini = i
3 for j = i to A.length-1
4 if... | {"inputs": ["6\n5 2 4 6 1 0", "6\n5 6 4 4 1 3", "6\n6 2 4 6 1 0", "6\n5 6 4 4 1 2", "6\n6 2 4 6 0 0", "6\n5 6 4 3 1 2", "6\n6 2 8 6 0 0", "6\n5 6 4 2 1 2"], "outputs": ["0 1 2 4 5 6\n5\n", "1 3 4 4 5 6\n2\n", "0 1 2 4 6 6\n4\n", "1 2 4 4 5 6\n2\n", "0 0 2 4 6 6\n4\n", "1 2 3 4 5 6\n3\n", "0 0 2 6 6 8\n3\n", "1 2 2 4 5 ... | coding | 306 |
Solve the programming task below in a Python markdown code block.
You are given n strings s_1, s_2, ..., s_{n} consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation s_{a}_{i}s_{b}_{i} is saved into a new... | {"inputs": ["1\n1\n1\n1 1\n", "1\n1\n1\n1 1\n", "1\n0\n1\n1 1\n", "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n", "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 7\n", "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n", "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7\n", "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1... | coding | 538 |
Solve the programming task below in a Python markdown code block.
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most... | {"inputs": ["1 1 1 2\n", "1 2 3 1\n", "1 2 1 5\n", "2 7 8 4\n", "1 2 1 5\n", "2 7 8 4\n", "1 2 2 5\n", "2 7 8 0\n"], "outputs": ["4\n", "2\n", "20\n", "25\n", "20\n", "25\n", "23\n", "1\n"]} | coding | 344 |
Solve the programming task below in a Python markdown code block.
In this problem we are concerned with words constructed using the lowercase letters of the English alphabet - that is, a,b,c,…,z. These words need not necessarily be meaningful: any sequence of letters forms a word. For example, abbca is a word.
We say t... | {"inputs": ["11\nabacd\nbcdada\ndd\nabcd\nbcdd\nadcd\naddd\naa\nccd\nadd\nad"], "outputs": ["7"]} | coding | 620 |
Solve the programming task below in a Python markdown code block.
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in... | {"inputs": ["2\n1 1\n1 2\n", "2\n1 1\n4 4\n", "2\n1 1\n5 1\n", "2\n1 1\n1 1\n", "2\n1 1\n1 0\n", "2\n1 1\n1 3\n", "2\n1 1\n0 4\n", "2\n1 1\n5 0\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n"]} | coding | 608 |
Solve the programming task below in a Python markdown code block.
Yuki made a sugoroku so that everyone can play at the children's association event. In this sugoroku, squares are lined up in a ring, and each square has an integer of 1 or more written on it.
The player chooses a square as a starting point and places h... | {"inputs": ["3\n2 1 1", "3\n1 1 3", "3\n1 2 3", "3\n2 1 0", "3\n1 1 0", "3\n1 2 1", "3\n2 2 1", "3\n1 2 0"], "outputs": ["2\n", "1\n", "3\n", "1\n", "1\n", "2\n", "2\n", "3\n"]} | coding | 342 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k.
Return the number of non-empty subarrays in nums that have a median equal to k.
Note:
The median of an array... | {"functional": "def check(candidate):\n assert candidate(nums = [3,2,1,4,5], k = 4) == 3\n assert candidate(nums = [2,3,1], k = 3) == 1\n\n\ncheck(Solution().countSubarrays)"} | coding | 180 |
Solve the programming task below in a Python markdown code block.
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates.
There are a total of n students in those schools. Before the tournament, all students put their na... | {"inputs": ["1 1 1\n1\n1\n1\n", "1 1 1\n2\n1\n1\n", "2 1 1\n1 2\n1 1\n1\n", "2 1 1\n1 2\n1 1\n2\n", "5 1 1\n4 3 2 1 5\n1 1 1 1 1\n5\n", "5 1 1\n4 3 2 1 5\n1 1 1 1 1\n1\n", "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 2\n3\n", "7 3 1\n1 5 3 4 6 7 2\n1 1 1 2 1 2 3\n3\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n"... | coding | 737 |
Solve the programming task below in a Python markdown code block.
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), ... | {"inputs": ["1\n1 1\n", "1\n1 0\n", "1\n3 0\n", "1\n0 0\n", "1\n1 -1\n", "1\n2 -1\n", "1\n3 -1\n", "1\n0 -1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 520 |
Solve the programming task below in a Python markdown code block.
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-... | {"inputs": ["4\n2 1 3 2\n3 2 1 2\n", "4\n2 2 3 1\n3 2 1 2\n", "4\n1 2 3 4\n3 2 1 4\n", "4\n2 2 3 2\n3 2 2 2\n", "4\n1 2 3 2\n3 2 1 2\n", "2\n1 100500\n1 100500\n", "1\n800950546\n800950546\n", "1\n873725529\n873725529\n"], "outputs": ["2\n1 2\n2 3\n", "3\n1 2\n3 4\n2 3\n", "3\n2 3\n1 2\n2 3\n", "2\n1 2\n2 3\n", "3\n2 3... | coding | 498 |
Solve the programming task below in a Python markdown code block.
Penny has an array of $n$ integers, $[a_0,a_1,\ldots,a_{n-1}]$. She wants to find the number of unique multisets she can form using elements from the array such that the bitwise XOR of all the elements of the multiset is a prime number. Recall that a mul... | {"inputs": ["1 \n3 \n3511 3671 4153 \n"], "outputs": ["4\n"]} | coding | 535 |
Solve the programming task below in a Python markdown code block.
Chef has N subordinates. In order to complete a very important order he will choose exactly K of them. He can't choose less than K since it will be not enough to complete the order in time. On the other hand if he chooses more than K subordinates he can'... | {"inputs": ["3\n2 1\n3 3\n10 5"], "outputs": ["2\n1\n252"]} | coding | 221 |
Solve the programming task below in a Python markdown code block.
Tieu owns a pizza restaurant and he manages it in his own way. While in a normal restaurant, a customer is served by following the first-come, first-served rule, Tieu simply minimizes the average waiting time of his customers. So he gets to decide who i... | {"inputs": ["3\n0 3\n1 9\n2 6\n", "3\n0 3\n1 9\n2 5\n"], "outputs": ["9\n", "8\n"]} | coding | 677 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
In the magical land of Byteland, there are three kinds of citizens:
a Bit - $2\;\mathrm{ms}$ after a Bit appears, it grows up and becomes a Nibble (i.... | {"inputs": ["2\n2\n3"], "outputs": ["1 0 0\n0 1 0"]} | coding | 460 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the number of ways you can write n as the sum of consecutive positive integers.
Please complete the following python code precisely:
```python
class Solution:
def consecutiveNumbersSum... | {"functional": "def check(candidate):\n assert candidate(n = 5) == 2\n assert candidate(n = 9) == 3\n assert candidate(n = 15) == 4\n\n\ncheck(Solution().consecutiveNumbersSum)"} | coding | 70 |
Solve the programming task below in a Python markdown code block.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after s... | {"inputs": ["1\n0 0\n", "1\n8 9\n", "1\n8 17\n", "1\n16 17\n", "2\n1 2\n1 3\n", "2\n1 3\n1 6\n", "2\n1 3\n2 4\n", "2\n2 2\n1 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n"]} | coding | 431 |
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... | coding | 320 |
Solve the programming task below in a Python markdown code block.
This is the easy version of this problem. The difference between easy and hard versions is only the constraints on $a_i$ and on $n$. You can make hacks only if both versions of the problem are solved.
Burenka is the crown princess of Buryatia, and soon ... | {"inputs": ["7\n4\n5 5 5 5\n3\n1 3 2\n2\n0 0\n3\n2 5 7\n6\n1 2 3 3 2 1\n10\n27 27 34 32 2 31 23 56 52 4\n5\n1822 1799 57 23 55\n"], "outputs": ["2\n2\n0\n2\n4\n7\n4\n"]} | coding | 736 |
Solve the programming task below in a Python markdown code block.
Did you ever hear about 'crossing the bridge noodle' ? Let me tell you that it's not some kind of bridge made of noodles. It's a dish, a kind of rice noodle soup. Mr.Ping makes the best noodle soup and his son Po is eagerly waiting for the user reviews i... | {"inputs": ["2\nP 1\nP 2\n2\nP 2\nM -2\n0", "2\nP 1\nP 2\n\n2\nP 0\nM -2\n\n0", "2\nP 1\nP 4\n\n2\nP 0\nM -2\n\n0", "2\nQ 2\nP 4\n\n0\nP 0\nM -2\n\n0", "2\nP 1\nP 5\n\n2\nQ 0\nM -2\n\n0", "2\nQ 2\nP 6\n\n0\nP 0\nL -4\n\n2", "2\nQ 2\nP 5\n\n0\nP 1\nL -4\n\n2", "2\nQ 2\nP 8\n\n0\nP 1\nM -2\n\n1"], "outputs": ["1\n1", "1\... | coding | 618 |
Solve the programming task below in a Python markdown code block.
Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated).
The weight of a is defined as the maximum number ... | {"inputs": ["1 1\n1\n0 0\n", "1 1\n0\n0 0\n", "2 1\n1 1\n0 0\n", "2 1\n1 0\n0 0\n", "2 1\n2 0\n0 0\n", "2 1\n0 0\n0 0\n", "2 1\n0 1\n0 0\n", "2 1\n2 1\n0 0\n"], "outputs": ["1\n", "0\n", "2\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
Let's assume that v(n) is the largest prime number, that does not exceed n;
u(n) is the smallest prime number strictly greater than n.
Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$.
-----Input-----
The first line contains integer t (1 ≤ t ≤ 500) —... | {"inputs": ["2\n2\n3\n", "2\n2\n3\n", "1\n649580447\n", "1\n649580447\n", "1\n642996383\n", "1\n577046292\n", "1\n564149555\n", "1\n512056728\n"], "outputs": ["1/6\n7/30\n", "1/6\n7/30\n", "421954771415489597/843909545429301074\n", "421954771415489597/843909545429301074\n", "413444317687254719/826888637946494782\n", "3... | coding | 187 |
Solve the programming task below in a Python markdown code block.
Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple of 7, or... | {"inputs": ["26\n5 10\n4 10\n100 3\n123456 7\n49 7\n158854 50\n822992 101\n691238 345\n682373 49\n643378 53\n328697 62\n446656 228\n368684 130\n530193 371\n864163 325\n708578 207\n915093 485\n711860 28\n234554 366\n309089 25\n595700 393\n10 6\n9 19\n4 10\n11 2\n11 3"], "outputs": ["10\n0\n99\n123459\n49\n158850\n822948... | coding | 201 |
Solve the programming task below in a Python markdown code block.
# Description:
Replace the pair of exclamation marks and question marks to spaces(from the left to the right). A pair of exclamation marks and question marks must has the same number of "!" and "?".
That is: "!" and "?" is a pair; "!!" and "??" is ... | {"functional": "_inputs = [['!!?!!?!!?!!?!!!??!!!??!!!??'], ['??!??!??!??!???!!???!!???!!'], ['?!!?!!?!!?!!!??!!!??!!!??!!!??!!!??']]\n_outputs = [[' ? ? ?!!?!!! !!! !!! '], [' ! ! !??!??? ??? ??? '], ['? ? ? ?!!! !!! !!! !!!??!!!??']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, ... | coding | 197 |
Solve the programming task below in a Python markdown code block.
Isaac has to buy a new HackerPhone for his girlfriend Amy. He is exploring the shops in the town to compare the prices whereupon he finds a shop located on the first floor of a building, that has a unique pricing policy. There are N steps leading to the ... | {"inputs": ["3\n1 \n1\n2\n", "4\n1 \n2\n2\n2\n"], "outputs": ["2.0\n", "3.5\n"]} | coding | 416 |
Solve the programming task below in a Python markdown code block.
Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = $2$, b = $3$ changes the v... | {"inputs": ["2\n1 2 3\n5 4 100\n", "2\n1 2 3\n7 4 100\n", "2\n1 1 3\n5 4 100\n", "2\n1 1 3\n5 4 101\n", "2\n1 1 3\n5 4 111\n", "2\n1 2 3\n5 4 100\n", "16\n1 1 1\n3 4 7\n4 5 13\n456 123 7890123\n1 1 1000000000\n45 12 782595420\n1 1000000000 1000000000\n1 999999999 1000000000\n1 99999 676497416\n5 6 930234861\n8 9 881919... | coding | 364 |
Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.
You are given an array [a_1, a_2, ..., a_n].
Your goal is to f... | {"inputs": ["1\n1\n", "7\n1 2 3 3 3 2 1\n", "7\n1 2 2 3 3 2 1\n", "7\n1 2 1 3 3 2 1\n", "7\n1 2 2 3 3 4 1\n", "7\n1 2 2 3 2 2 1\n", "7\n1 2 2 5 3 2 1\n", "7\n1 2 1 3 3 4 1\n"], "outputs": ["0\n", "3\n", "5\n", "6\n", "7\n", "2\n", "4\n", "6\n"]} | coding | 431 |
Solve the programming task below in a Python markdown code block.
You are given a permutation $p_1, p_2, \ldots, p_n$.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment $1,2,\ldots, k$, in other words in the end there should... | {"inputs": ["1\n1\n", "1\n1\n", "3\n1 2 3\n", "3\n2 1 3\n", "3\n2 3 1\n", "3\n3 1 2\n", "3\n3 2 1\n", "3\n1 3 2\n"], "outputs": ["0 \n", "0 ", "0 0 0 \n", "0 1 1\n", "0 2 2\n", "0 0 2\n", "0 1 3\n", "0 1 1\n"]} | coding | 377 |
Solve the programming task below in a Python markdown code block.
A geyser has a capacity of X litres of water and a bucket has a capacity of Y litres of water.
One person requires exactly 2 buckets of water to take a bath. Find the maximum number of people that can take bath using water from one completely filled gey... | {"inputs": ["4\n10 6\n25 1\n100 10\n30 40\n"], "outputs": ["0\n12\n5\n0\n"]} | coding | 450 |
Solve the programming task below in a Python markdown code block.
Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first.
-----Input-----
First line of input contains an integer T, d... | {"inputs": ["2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2\n\n"], "outputs": ["2 2\n1 3"]} | coding | 269 |
Solve the programming task below in a Python markdown code block.
Tonight, Chef would like to hold a party for his $N$ friends.
All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at the party a... | {"inputs": ["3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3"], "outputs": ["2\n4\n0"]} | coding | 516 |
Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has sequence a consisting ... | {"inputs": ["2 2\n1 62\n", "2 2\n1 71\n", "2 2\n44 44\n", "2 2\n47 47\n", "2 2\n88 44\n", "2 2\n47 71\n", "2 2\n33 44\n", "2 2\n54 71\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 460 |
Solve the programming task below in a Python markdown code block.
Let f(A, B) be the exclusive OR of A, A+1, ..., B. Find f(A, B).
What is exclusive OR?
The bitwise exclusive OR of integers c_1, c_2, ..., c_n (let us call it y) is defined as follows:
- When y is written in base two, the digit in the 2^k's place (k \ge... | {"inputs": ["2 4\n", "0 0\n", "0 1\n", "123 456\n", "7 549755813887\n", "0 1000000000000\n", "16469429916 70896110856\n", "4917728545 146793804400\n"], "outputs": ["5\n", "0\n", "1\n", "435\n", "7\n", "1000000000000\n", "70896110856\n", "150467061584\n"]} | coding | 313 |
Solve the programming task below in a Python markdown code block.
Monocarp is the coach of the Berland State University programming teams. He decided to compose a problemset for a training session for his teams.
Monocarp has $n$ problems that none of his students have seen yet. The $i$-th problem has a topic $a_i$ (an... | {"inputs": ["2\n4\n2 4\n3 4\n2 1\n1 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n2 4\n3 4\n2 1\n2 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n2 4\n3 3\n2 2\n1 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n4 4\n3 3\n2 2\n2 3\n5\n1 5\n2 4\n3 3\n4 2\n5 1\n", "2\n4\n2 4\n3 4\n2 2\n2 3\n5\n1 5\n2 3\n3 3\n4 2\n2 1\n", "2\n4\n4 4\n3 4\n2... | coding | 522 |
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's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy... | {"inputs": ["1\n4 1\n3 4 5 1"], "outputs": ["4"]} | coding | 626 |
Solve the programming task below in a Python markdown code block.
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message... | {"inputs": ["2\na. b.\n", "4\na. A.\n", "2\na- b.\n", "8\nabc! ab.\n", "5\nabc. abcd.\n", "5\na. b. c. d.\n", "5\na. b. c- d.\n", "5\na. b/ c- d.\n"], "outputs": ["2\n", "2\n", "Impossible\n", "1\n", "2\n", "2\n", "2\n", "Impossible\n"]} | coding | 442 |
Solve the programming task below in a Python markdown code block.
# Fourier transformations are hard. Fouriest transformations are harder.
This Kata is based on the SMBC Comic on fourier transformations.
A fourier transformation on a number is one that converts the number to a base in which it has more `4`s ( `10` in... | {"functional": "_inputs = [[30], [15], [9999], [35353], [100], [1000000243], [142042158218941532125212890], [2679388715912901287113185885289513476], [640614569414659959863091616350016384446719891887887380], [2579111107964987025047536361483312385374008248282655401675211033926782006920415224913494809688581314878892733564... | coding | 442 |
Solve the programming task below in a Python markdown code block.
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts share... | {"inputs": ["1 1\n+ 1\n", "2 1\n- 2\n", "2 1\n+ 1\n", "2 1\n+ 2\n", "20 1\n- 16\n", "2 2\n- 1\n+ 1\n", "6 2\n+ 1\n- 2\n", "6 2\n+ 1\n- 4\n"], "outputs": ["1\n1 \n", "2\n1 2 \n", "2\n1 2 \n", "2\n1 2 \n", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \n", "2\n1 2 \n", "4\n3 4 5 6 \n", "4\n2 3 5 6 \n"]} | coding | 613 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.
Please complete the following python code precisely:
```python
class Solution:
def largestUniq... | {"functional": "def check(candidate):\n assert candidate([5,7,3,9,4,9,8,3,1]) == 8\n assert candidate([9,9,8,8]) == -1\n\n\ncheck(Solution().largestUniqueNumber)"} | coding | 74 |
Solve the programming task below in a Python markdown code block.
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I'll gi... | {"inputs": ["1\n6\n", "1\n0\n", "1\n2\n", "1\n1\n", "1\n1\n", "1\n6\n", "1\n2\n", "1\n0\n"], "outputs": ["BitLGM\n", "BitAryo\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitAryo\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
Dio Brando has set a goal for himself of becoming the richest and the most powerful being on earth.To achieve his goals he will do anything using either manipulation,seduction or plain violence.
Only one guy stands between his goal of conquering earth ,... | {"inputs": ["6\nabcdfgh\nurdrdrav\njojojojoj\nbbbbaaa\ncddfsccs\ntttttttttttt"], "outputs": ["1234678\n2118418418122\n1015\n21\n46193\n20"]} | coding | 532 |
Solve the programming task below in a Python markdown code block.
You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$.
The following actions are allowed: Token movement. To move the token from vertex $u$ to vertex $v$ if there is an edge... | {"inputs": ["2 1\n2 1\n", "2 1\n2 1\n", "4 3\n2 1\n2 3\n4 3\n", "4 3\n2 1\n2 3\n4 3\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "4 4\n1 2\n2 1\n3 4\n4 1\n", "4 4\n2 2\n2 1\n3 4\n3 1\n", "4 3\n1 2\n3 2\n3 4\n4 2\n"], "outputs": ["2\n", "2\n", "10\n", "10\n", "2\n", "2\n", "5\n", "6\n"]} | coding | 512 |
Solve the programming task below in a Python markdown code block.
Chef has an array A of length N.
Let f(i) denote the sum A_{1} + A_{2} + \dots + A_{i} \, and let g(i) denote the sum A_{i} + A_{i + 1} + \dots + A_{N}.
Chef creates another array B of length N such that B_{i} = f(i) + g(i) for all 1 ≤ i ≤ N.
Now, Ch... | {"inputs": ["4\n1\n6\n3\n7 8 9\n4\n13 15 13 14\n2\n25 20\n"], "outputs": ["3 \n1 2 3 \n2 4 2 3 \n10 5 \n"]} | coding | 678 |
Solve the programming task below in a Python markdown code block.
## The galactic games have begun!
It's the galactic games! Beings of all worlds come together to compete in several interesting sports, like nroogring, fredling and buzzing (the beefolks love the last one). However, there's also the traditional marathon... | {"functional": "_inputs = [[10], [100], [1000], [10000], [16], [20], [200], [1000000], [50000000], [50000000000000000000000000000000000000000]]\n_outputs = [[23], [2318], [233168], [23331668], [60], [78], [9168], [233333166668], [583333291666668], [58333333333333333333333333333333333333329166666666666666666666666666666... | coding | 379 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
There is a garland — a cyclic rope with red and green flowers on it in some order. The sequence of flower colours is described by a string $s$; since... | {"inputs": ["3\nRG\nRRGG\nRR"], "outputs": ["yes\nyes\nno"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
Chef loves to play with iron (Fe) and magnets (Ma). He took a row of $N$ cells (numbered $1$ through $N$) and placed some objects in some of these cells. You are given a string $S$ with length $N$ describing them; for each valid $i$, the $i$-th character... | {"inputs": ["2\n4 5\nI::M\n9 10\nMIM_XII:M"], "outputs": ["1\n2"]} | coding | 757 |
Solve the programming task below in a Python markdown code block.
You are a given a tree of N vertices. The i-th vertex has two things assigned to it — a value A_{i} and a range [L_{i}, R_{i}]. It is guaranteed that L_{i} ≤ A_{i} ≤ R_{i}.
You perform the following operation exactly once:
Pick a (possibly empty) subset... | {"inputs": ["2\n3\n1 1 1\n2 3 3\n3 3 3\n1 2\n1 3\n4\n3 3 4\n1 3 5\n2 2 2\n2 2 2\n1 2\n2 3\n2 4\n"], "outputs": ["3\n1"]} | coding | 717 |
Solve the programming task below in a Python markdown code block.
A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.
You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.
-----Constraints--... | {"inputs": ["2 3 4", "1 4 4", "7 9 6", "4 3 4", "1 4 8", "7 4 6", "4 5 4", "0 4 8"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n"]} | coding | 162 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is n... | {"functional": "def check(candidate):\n assert candidate(equation = \"x+5-3+x=6+x-2\") == \"x=2\"\n assert candidate(equation = \"x=x\") == \"Infinite solutions\"\n assert candidate(equation = \"2x=x\") == \"x=0\"\n\n\ncheck(Solution().solveEquation)"} | coding | 144 |
Solve the programming task below in a Python markdown code block.
Alexandra has a paper strip with n numbers on it. Let's call them a_{i} from left to right.
Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:
Each piece should contain at least l numbers.
The ... | {"inputs": ["1 0 1\n0\n", "1 0 1\n0\n", "1 0 1\n0\n", "1 100 2\n42\n", "1 100 2\n42\n", "1 100 2\n14\n", "1 100 2\n40\n", "1 0 1\n-98876039\n"], "outputs": ["1\n", "1\n", "1", "-1\n", "-1", "-1\n", "-1\n", "1\n"]} | coding | 338 |
Solve the programming task below in a Python markdown code block.
Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.
A game is played by N players, n... | {"inputs": ["6 1 4\n3\n1\n3\n2", "6 3 4\n3\n1\n3\n4", "6 5 4\n3\n0\n3\n2", "8 1 4\n3\n1\n0\n2", "6 3 4\n6\n1\n3\n1", "8 1 1\n4\n1\n0\n2", "8 5 3\n3\n0\n4\n2", "9 1 0\n6\n1\n3\n4"], "outputs": ["No\nNo\nNo\nNo\nNo\nNo\n", "No\nNo\nYes\nNo\nNo\nNo\n", "Yes\nYes\nYes\nYes\nYes\nYes\n", "No\nNo\nNo\nNo\nNo\nNo\nNo\nNo\n", ... | coding | 565 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a ... | {"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = \"abaedcd\") == [2,1,1,1,1,1,1]\n assert candidate(n = 4, edges = [[0,1],[1,2],[0,3]], labels = \"bbbb\") == [4,2,1,1]\n assert candidate(n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = \"... | coding | 232 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shor... | {"inputs": ["2\n1\n2", "2\n1\n3", "2\n2\n3", "2\n2\n5", "2\n2\n2", "2\n2\n1", "2\n4\n5", "2\n4\n1"], "outputs": ["1\n3", "1\n4\n", "3\n4\n", "3\n6\n", "3\n3\n", "3\n1\n", "7\n6\n", "7\n1\n"]} | coding | 384 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:
Suppose this list is answer = [a1, a2, a3, ... , an], then the ... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 1) == [1, 2, 3]\n assert candidate(n = 3, k = 2) == [1, 3, 2]\n\n\ncheck(Solution().constructArray)"} | coding | 162 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting of exactly $n$ characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.
Your task is to replace minimum number of characters in this string with other characters to obtain a... | {"inputs": ["3\n121\n", "3\n111\n", "3\n002\n", "3\n000\n", "3\n001\n", "3\n022\n", "3\n211\n", "3\n020\n"], "outputs": ["021\n", "012\n", "012\n", "012\n", "021\n", "012\n", "201\n", "021\n"]} | coding | 419 |
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 true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.
A leaf is a node with no children.
Please... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([5,4,8,11,None,13,4,7,2,None,None,None,1]), targetSum = 22) == True\n assert candidate(root = tree_node([1,2,3]), targetSum = 5) == False\n assert candidate(root = tree_node([]), targetSum = 0) == False\n\n\ncheck(Solution().hasPathSum)"... | coding | 154 |
Solve the programming task below in a Python markdown code block.
Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post offic... | {"inputs": ["1\n1\n1\n", "1\n0\n0\n", "1\n2\n2\n", "1\n3\n3\n", "1\n4\n4\n", "3\n3 3 3\n3 2 4\n", "4\n0 7 2 3\n8 1 0 3\n", "4\n1 7 2 3\n9 1 0 3\n"], "outputs": ["1\n1 \n", "1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "3\n1 2 3 \n", "2\n2 4 ", "2\n2 4 "]} | coding | 738 |
Solve the programming task below in a Python markdown code block.
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row.
The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise.
Snuke wants to maximize the total happiness of the camels. Find th... | {"inputs": ["3\n2\n1 5 10\n0 15 5\n3\n2 93 78\n1 71 59\n3 57 96\n19\n19 23 16\n9 90 26\n12 85 70\n19 67 78\n1 16 16\n18 48 28\n5 4 24\n12 97 97\n4 57 87\n8 91 74\n18 100 76\n7 31 46\n9 100 5\n3 76 73\n6 84 93\n1 6 84\n11 75 94\n19 15 3\n12 11 34", "3\n2\n1 5 10\n2 15 5\n3\n2 93 78\n1 71 59\n3 57 96\n19\n19 23 16\n9 90 ... | coding | 520 |
Solve the programming task below in a Python markdown code block.
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a... | {"inputs": ["1\nR\n", "1\nR\n", "2\nDU\n", "2\nDU\n", "2\nUD\n", "4\nDLUU\n", "4\nRRDR\n", "4\nRRDR\n"], "outputs": ["0\n", "0", "1\n", "1", "1\n", "0\n", "0\n", "0"]} | coding | 293 |
Solve the programming task below in a Python markdown code block.
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum... | {"inputs": ["2\n", "1\n", "3\n", "1\n", "3\n", "2\n", "1+1\n", "1+2\n"], "outputs": ["2\n", "1\n", "3\n", "1\n", "3\n", "2\n", "1+1\n", "1+2\n"]} | coding | 306 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.
As the answer can be very large, return it modulo 109 + 7.
Please co... | {"functional": "def check(candidate):\n assert candidate(arr = [1,1,2,2,3,3,4,4,5,5], target = 8) == 20\n assert candidate(arr = [1,1,2,2,2,2], target = 5) == 12\n\n\ncheck(Solution().threeSumMulti)"} | coding | 115 |
Solve the programming task below in a Python markdown code block.
Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:
- For any integer j (1 \leq j \leq i), P_i \leq P_j.
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
... | {"inputs": ["1\n0", "1\n1", "1\n1\n", "1\n-1", "1\n-2", "1\n-4", "4\n4 3 2 1", "4\n4 3 2 1\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "4", "4\n"]} | coding | 260 |
Solve the programming task below in a Python markdown code block.
You are given two strings of equal length $s$ and $t$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose two adjacent characters in any string and assign the v... | {"inputs": ["3\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n", "3\nxabb\naabx\nteohnccup\ntechnocup\na\nz\n", "3\nbcbw\nxaaa\ntdohncbup\npvconhcet\nb\nz\n", "3\nxabb\naabx\ntdohnccup\ntechnocup\na\nz\n", "3\nxabb\nxbaa\ntdohnccup\ntechnocup\na\nz\n", "3\nxacb\nxbaa\ntdohnccup\ntechnocup\na\nz\n", "3\nxabb\naabx\ntechnncup\... | coding | 577 |
Solve the programming task below in a Python markdown code block.
Create a program to determine the positional relationship between a triangle and a circle on a plane. All target figures shall include boundaries. The triangle is given the position of three vertices, and the circle is given the position of the center an... | {"inputs": ["4 0\n3 1\n3 3\n3 3\n1\n4 3\n8 2\n4 12\n8 9\n5\n0 0\n52 2\n8 5\n2 2\n5\n3 7\n23 2\n4 9\n37 1\n0\n0 0", "2 0\n3 1\n3 3\n3 3\n1\n4 3\n16 2\n4 12\n8 9\n5\n5 0\n10 2\n8 5\n7 2\n5\n3 7\n23 2\n16 9\n37 1\n0\n0 0", "2 0\n3 1\n3 3\n3 3\n1\n4 3\n16 2\n4 12\n8 9\n5\n5 0\n10 2\n8 5\n7 2\n0\n3 7\n23 2\n16 9\n37 1\n0\n0... | coding | 393 |
Solve the programming task below in a Python markdown code block.
problem
There are fine icicles under the eaves of JOI's house in Canada. Because of this, JOI decided to investigate the icicles.
There are N (2 ≤ N ≤ 100000 = 105) icicles under the eaves of JOI's house. These icicles are aligned and i cm (1 ≤ i ≤ N) ... | {"inputs": ["4 6\n7\n2\n3\n5", "4 6\n4\n1\n3\n5", "1 6\n4\n2\n3\n1", "4 5\n4\n2\n3\n1", "1 6\n3\n2\n3\n1", "1 6\n2\n2\n3\n1", "4 9\n7\n2\n3\n5", "1 6\n1\n0\n1\n1"], "outputs": ["8\n", "9\n", "2\n", "6\n", "3\n", "4\n", "17\n", "5\n"]} | coding | 687 |
Solve the programming task below in a Python markdown code block.
At the start of each season, every player in a football team is assigned their own unique squad number. Due to superstition or their history certain numbers are more desirable than others.
Write a function generateNumber() that takes two arguments, an a... | {"functional": "_inputs = [[[1, 2, 3, 4, 6, 9, 10, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 38, 47, 56, 65, 69, 74, 83, 92], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 18, 23, 69], 18], [[1, 2, 3, 4, 6, 9, 10, 15, 69], 34], [[1, ... | coding | 235 |
Solve the programming task below in a Python markdown code block.
Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network as... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n8\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 481 |
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Ada has an array of N crayons, some crayons are pointing upwards and some downwards.
Ada thinks that an array of crayons is beautiful if all the crayons are pointing in the ... | {"inputs": ["1\nUUDDDUUU"], "outputs": ["1"]} | coding | 281 |
Solve the programming task below in a Python markdown code block.
To pass the series of gates guarded by the owls, Kenneth needs to present them each with a highly realistic portrait of one. Unfortunately, he is absolutely rubbish at drawing, and needs some code to return a brand new portrait with a moment's notice.
... | {"functional": "_inputs = [['xwe'], ['kuawd6r8q27y87t93r76352475437'], ['t6ggggggggWw'], ['xweWXo']]\n_outputs = [[\"XW''0v0''WX\"], [\"UAW8Y8T''0v0''T8Y8WAU\"], [\"TWW''0v0''WWT\"], [\"XWWXO''0v0''OXWWX\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | coding | 250 |
Solve the programming task below in a Python markdown code block.
There are N cities numbered 1 to N, connected by M railroads.
You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket.
The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins a... | {"inputs": ["2 1 1\n1 2 1 1\n1 1000000000\n1 1", "2 1 0\n1 2 1 1\n1 1000000100\n1 1", "2 1 0\n1 2 1 1\n1 1000000000\n1 1", "2 1 0\n1 2 1 1\n1 1000000000\n1 1\n", "2 1 1\n1 2 2 1\n1 1000000000\n-1 0", "2 1 1\n1 2 -1 2\n0 1000000000\n0 2", "2 1 0\n1 2 2 1\n1 1000000000\n-1 0", "2 1 0\n1 2 2 1\n1 1000010000\n-1 0"], "outp... | coding | 730 |
Solve the programming task below in a Python markdown code block.
Problem statement
Jota knows only the characters from `a` to` z` and the addition symbol `+`. Jota has an older sister, Tachiko. In addition to that, Tatsuko knows multiplication `*`, parentheses `(`, `)`, and integers (numbers) between `1` and` 9`. How... | {"inputs": ["5\nb+a+a", "5\nb+b+b", "5\na+a+b", "5\na+b+b", "5\nb+b+a", "5\nc+a+a", "5\nb+a+b", "5\nc+a+b"], "outputs": ["5\n", "3\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n"]} | coding | 617 |
Solve the programming task below in a Python markdown code block.
Mehta is a very rich guy. He has $N$ types of coins, and each type of coin is available in an unlimited supply.
So Mehta goes to a supermarket to buy monthly groceries. There he sees that every item has a unique price, that is, no two items have the s... | {"inputs": ["4\n2\n3\n4\n5\n3\n1 10\n2 20\n3 7\n"], "outputs": ["8\n14\n4\n"]} | coding | 628 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.