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.
Sorry folks,, admin has no time to create a story for this problem...
You have two integers n and m and you have to print value of factorial(n)%m.
OUTPUT
a single integer containing answer of problem.
Input
23 14567
NOTE You do not need to create a p... | {"inputs": ["23 14567"], "outputs": ["12404"]} | coding | 118 |
Solve the programming task below in a Python markdown code block.
Did you know that the yummy golden triangle was introduced in India as early as 13th century ? By the way, I'm referring to the popular South Asian snack, Samosa. I guess its hard to code while thinking of Samosa, especially if you are very hungry now ; ... | {"inputs": ["1\n2\n10 20 34 55\n4\n7 5\n2 4\n21 6\n7 2", "1\n2\n12 20 34 55\n4\n7 5\n2 4\n21 6\n7 2", "1\n2\n12 20 34 55\n2\n7 5\n2 4\n21 6\n7 2", "1\n2\n12 20 34 55\n1\n7 5\n2 4\n21 6\n7 2", "1\n2\n10 20 34 55\n4\n7 14\n7 4\n14 6\n7 2", "1\n2\n10 20 34 55\n4\n7 14\n7 4\n21 6\n7 2", "1\n2\n10 20 34 55\n4\n7 14\n2 4\n21... | coding | 631 |
Solve the programming task below in a Python markdown code block.
Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in all the n w... | {"inputs": ["1\n4\ngrace graceful disgraceful gracefully"], "outputs": ["grace"]} | coding | 240 |
Solve the programming task below in a Python markdown code block.
Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
Input
The in... | {"inputs": ["1 2 3 4 5 6\n2 -1 -2 0 -1 -5", "1 2 3 4 5 6\n2 -1 -2 0 -1 -4", "1 2 3 4 6 4\n2 -1 -4 -1 0 -5", "1 2 3 3 5 6\n2 -1 -2 0 -1 -4", "1 2 3 4 0 4\n2 -1 -4 -1 0 -5", "2 1 3 5 5 4\n4 -1 -4 -1 0 -5", "1 2 3 3 5 6\n2 -1 -2 -1 0 -4", "2 1 1 5 5 4\n4 -1 -4 -1 0 -5"], "outputs": ["-1.000 2.000\n1.500 5.000\n", "-1.000 ... | coding | 282 |
Solve the programming task below in a Python markdown code block.
The Quark Codejam's number QC(n, m) represents the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:
{1, 2, 3} ∪ {4}, {1, 2, 4} ∪ {3}, {1, 3, 4} ∪ {2}, {2... | {"inputs": ["1\n4 2"], "outputs": ["1"]} | coding | 393 |
Solve the programming task below in a Python markdown code block.
We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N.
Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of... | {"inputs": ["1\nx 1\n", "2\nabc 1\nab 0", "2\nabc 1\nba 0", "2\nabc 2\nab 0", "2\nabc 2\nba 0", "2\nbac 2\nba 0", "2\nbac 2\nab 0", "2\ncab 2\nab 0"], "outputs": ["1\n", "-1\n", "1\n", "-1\n", "2\n", "-1\n", "2\n", "-1\n"]} | coding | 399 |
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 nums of length n.
You can perform the following operation as many times as you want:
Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[... | {"functional": "def check(candidate):\n assert candidate(nums = [4,9,6,10]) == True\n assert candidate(nums = [6,8,11,12]) == True\n assert candidate(nums = [5,8,3]) == False\n\n\ncheck(Solution().primeSubOperation)"} | coding | 143 |
Solve the programming task below in a Python markdown code block.
Write a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "*", or "/", the function will return the result of the corresponding mathematical function on ... | {"functional": "_inputs = [[3.2, '+', 8], [3.2, '-', 8], [3.2, '/', 8], [3.2, '*', 8], [-3, '+', 0], [-3, '-', 0], [-2, '/', -2], [-3, '*', 0], [-3, '/', 0], [-3, 'w', 0], [-3, 'w', 1]]\n_outputs = [[11.2], [-4.8], [0.4], [25.6], [-3], [-3], [1], [0], [None], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\... | coding | 153 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position $3$ and ends in position $6$), but "aa" or "d" ... | {"inputs": ["2\nba\n", "2\naa\n", "2\nba\n", "2\naa\n", "2\nab\n", "2\nb`\n", "2\nb_\n", "2\nac\n"], "outputs": ["YES\n1 2\n", "NO\n", "YES\n1 2\n", "NO\n", "NO\n", "YES\n1 2\n", "YES\n1 2\n", "NO\n"]} | coding | 547 |
Solve the programming task below in a Python markdown code block.
Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer n and array a, consisting of ten integers, indexed by n... | {"inputs": ["6\n2 2 2 0 0 0 0 0 0 0\n", "4\n1 1 2 0 0 0 0 0 0 0\n", "8\n1 0 1 0 1 1 2 2 0 0\n", "6\n0 1 0 1 1 0 0 0 1 0\n", "6\n1 1 0 1 2 1 0 0 0 0\n", "7\n0 0 2 2 1 0 1 0 0 0\n", "6\n1 1 1 1 1 1 0 0 0 0\n", "4\n0 0 1 0 1 0 0 0 1 1\n"], "outputs": ["60\n", "9\n", "8820\n", "23160\n", "300\n", "9660\n", "600\n", "24\n"]... | coding | 399 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have some apples and a basket that can carry up to 5000 units of weight.
Given an integer array weight where weight[i] is the weight of the ith apple, return the maximum number of apples you can put in the basket.... | {"functional": "def check(candidate):\n assert candidate(weight = [100,200,150,1000]) == 4\n assert candidate(weight = [900,950,800,1000,700,800]) == 5\n\n\ncheck(Solution().maxNumberOfApples)"} | coding | 101 |
Solve the programming task below in a Python markdown code block.
###Story
Sometimes we are faced with problems when we have a big nested dictionary with which it's hard to work. Now, we need to solve this problem by writing a function that will flatten a given dictionary.
###Info
Python dictionaries are a convenient ... | {"functional": "_inputs = [[{'key': 'value'}], [{'key': {'deeper': {'more': {'enough': 'value'}}}}], [{'empty': {}}], [{'additional': {'place': {'cell': '2', 'zone': '1'}}, 'job': 'scout', 'name': {'last': 'Drone', 'first': 'One'}, 'recent': {}}], [{'job': {'1': 'scout', '2': 'worker', '3': 'writer', '4': 'reader', '5'... | coding | 461 |
Solve the programming task below in a Python markdown code block.
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds.
Po... | {"inputs": ["1 1 1\n1\n1\n", "3 3 3\n2 2 4\n1 1 3\n", "3 3 3\n2 2 4\n1 1 1\n", "3 3 3\n2 2 4\n1 1 2\n", "3 3 3\n2 2 2\n1 1 3\n", "5 4 5\n1 2 2 3 4\n1 3 4 5\n", "5 5 10\n8 2 8 5 9\n9 1 7 5 1\n", "5 5 10\n8 2 8 5 1\n9 1 7 5 1\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 478 |
Solve the programming task below in a Python markdown code block.
This is the easy version of this problem. The only difference between easy and hard versions is the constraints on $k$ and $m$ (in this version $k=2$ and $m=3$). Also, in this version of the problem, you DON'T NEED to output the answer by modulo.
You ar... | {"inputs": ["2\n2\n2 2\n1\n1\n", "2\n2\n2 2\n1\n1\n", "2\n2\n2 1\n1\n1\n", "3\n1\n1\n1\n1\n1\n1\n", "3\n1\n1\n1\n1\n1\n1\n", "2\n5\n1 1 1 1 1\n4\n1 1 1 1\n", "2\n5\n1 1 1 1 1\n4\n1 1 1 1\n", "2\n5\n1 1 2 1 1\n4\n1 1 1 1\n"], "outputs": ["0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n0\n", "0\n0\n0\n", "10\n4\n", "10\n4\n", "10\n... | coding | 589 |
Solve the programming task below in a Python markdown code block.
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in ... | {"inputs": ["1 1\n5\n", "3 1\n1 1 1\n", "2 2\n97 197\n", "2 1\n97 197\n", "2 2\n193 193\n", "4 2\n0 2 1 2\n", "4 2\n0 2 2 2\n", "4 2\n1 2 1 2\n"], "outputs": [" 1\n", " 6\n", " ... | coding | 616 |
Solve the programming task below in a Python markdown code block.
We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.
Snuke's objective is to permute the element in a so that the following condition is satisfied:
- For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a mult... | {"inputs": ["2\n0 0", "2\n1 1", "2\n1 1\n", "3\n0 4 1", "3\n0 1 1", "3\n0 0 0", "3\n0 0 1", "3\n0 1 0"], "outputs": ["Yes\n", "No", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | coding | 226 |
Solve the programming task below in a Python markdown code block.
Determine the total number of digits in the integer (`n>=0`) given as input to the function. For example, 9 is a single digit, 66 has 2 digits and 128685 has 6 digits. Be careful to avoid overflows/underflows.
All inputs will be valid.
Also feel free to... | {"functional": "_inputs = [[5], [12345], [9876543210]]\n_outputs = [[1], [5], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fa... | coding | 101 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes problems related to numbers a lot. He is generally quite good at solving these kinds of problems, but today he got stuck at one number theory problem, and so he ask... | {"inputs": ["6", "9939"], "outputs": ["1", "4"]} | coding | 495 |
Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's ... | {"inputs": ["4\n", "1\n", "9\n", "7\n", "5\n", "2\n", "0\n", "73\n"], "outputs": ["47\n", "47\n", "47\n", "47\n", "47", "47", "47", "74\n"]} | coding | 240 |
Solve the programming task below in a Python markdown code block.
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?
Every one of them has an integer sequences a and b of l... | {"inputs": ["3\n3 3 3\n1 1 1\n", "3\n1 1 1\n2 2 2\n", "3\n1 1 1\n2 2 2\n", "3\n1 2 0\n2 2 2\n", "3\n1 1 0\n2 2 2\n", "3\n3 3 6\n1 1 1\n", "3\n3 2 6\n1 1 1\n", "3\n0 2 0\n2 2 2\n"], "outputs": ["0\n", "0\n", "0", "4\n", "0\n", "0\n", "0\n", "4\n"]} | coding | 556 |
Solve the programming task below in a Python markdown code block.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
- Attack: Fennec chooses one monster. That monster's health will decrease by 1.
- Special Move: Fennec chooses one monster. That monster... | {"inputs": ["3 1\n0 1 5", "3 0\n0 1 5", "3 1\n4 1 6", "3 1\n4 1 5", "3 1\n4 1 5\n", "8 8\n7 9 3 2 3 8 4 6", "8 0\n4 9 5 2 3 6 5 6", "8 1\n4 9 5 2 3 6 5 6"], "outputs": ["1\n", "6\n", "5\n", "5", "5\n", "0\n", "40\n", "31\n"]} | coding | 320 |
Solve the programming task below in a Python markdown code block.
Polycarp took $n$ videos, the duration of the $i$-th video is $a_i$ seconds. The videos are listed in the chronological order, i.e. the $1$-st video is the earliest, the $2$-nd video is the next, ..., the $n$-th video is the last.
Now Polycarp wants to ... | {"inputs": ["1 1\n3\n", "1 1\n3\n", "1 1\n5\n", "1 1\n8\n", "1 1\n2\n", "1 1\n1\n", "1 1\n10\n", "1 1\n14\n"], "outputs": ["Yes\n1 ", "Yes\n1 \n", "Yes\n1\n", "Yes\n1\n", "Yes\n1\n", "Yes\n1\n", "Yes\n1\n", "Yes\n1\n"]} | coding | 667 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings words. Each element of words consists of two lowercase English letters.
Create the longest possible palindrome by selecting some elements from words and concatenating them in any orde... | {"functional": "def check(candidate):\n assert candidate(words = [\"lc\",\"cl\",\"gg\"]) == 6\n assert candidate(words = [\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"]) == 8\n assert candidate(words = [\"cc\",\"ll\",\"xx\"]) == 2\n\n\ncheck(Solution().longestPalindrome)"} | coding | 134 |
Solve the programming task below in a Python markdown code block.
You are given the `length` and `width` of a 4-sided polygon. The polygon can either be a rectangle or a square.
If it is a square, return its area. If it is a rectangle, return its perimeter.
```
area_or_perimeter(6, 10) --> 32
area_or_perimeter(4, 4) ... | {"functional": "_inputs = [[4, 4], [6, 10]]\n_outputs = [[16], [32]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n re... | coding | 158 |
Solve the programming task below in a Python markdown code block.
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of cand... | {"inputs": ["1 2 3 4\n", "1 1 2 3\n", "7 3 6 3\n", "1 2 3 3\n", "1 2 2 7\n", "3 1 1 1\n", "2 3 3 4\n", "1 1 4 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | coding | 283 |
Solve the programming task below in a Python markdown code block.
You have an array $a_1, a_2, \dots, a_n$.
Let's call some subarray $a_l, a_{l + 1}, \dots , a_r$ of this array a subpermutation if it contains all integers from $1$ to $r-l+1$ exactly once. For example, array $a = [2, 2, 1, 3, 2, 3, 1]$ contains $6$ su... | {"inputs": ["5\n1 1 2 1 2\n", "5\n1 1 2 1 2\n", "8\n2 4 1 3 4 2 1 2\n", "8\n2 4 1 3 4 3 1 2\n", "8\n2 7 1 3 4 3 1 2\n", "8\n2 8 2 3 4 3 1 2\n", "8\n2 8 1 3 4 6 1 2\n", "8\n2 4 1 3 4 6 2 2\n"], "outputs": ["6\n", "6\n", "7\n", "6\n", "5\n", "4\n", "3\n", "2\n"]} | coding | 480 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], quantity = [2]) == False\n assert candidate(nums = [1,2,3,3], quantity = [2]) == True\n assert candidate(nums = [1,1,2,2], quantity = [2,2]) == True\n\n\ncheck(Solution().canDistribute)"} | coding | 160 |
Solve the programming task below in a Python markdown code block.
In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progressio... | {"functional": "_inputs = [[[1, 1, 3, 5, 6, 5]], [[2, 1, 2]], [[1, 2, 3]], [[1, 1, 10]], [[24, 21, 14, 10]], [[3, 2, 1, 1, 1]], [[1, 3, 6, 9, 12]], [[0, 0, 0, 0, 0]], [[5, 4, 3, 2, 1, 1]], [[1, 2, 1]], [[1, 2, 3, 1, 1]], [[1, 3, 6, 8, 10]], [[5, 6, 5, 3, 1, 1]]]\n_outputs = [[4], [1], [0], [-1], [3], [4], [1], [0], [1]... | coding | 327 |
Solve the programming task below in a Python markdown code block.
We’ve all seen katas that ask for conversion from snake-case to camel-case, from camel-case to snake-case, or from camel-case to kebab-case — the possibilities are endless.
But if we don’t know the case our inputs are in, these are not very helpful.
##... | {"functional": "_inputs = [['hello-world'], ['hello-to-the-world'], ['hello_world'], ['hello_to_the_world'], ['helloWorld'], ['helloToTheWorld'], ['hello-World'], ['hello-To-The-World'], ['good-Night'], ['he--llo'], ['good-night'], ['good_night'], ['goodNight'], ['hello_World'], ['hello_To_The_World'], ['he_lloWorld'],... | coding | 557 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.
Return true if and only if we can do this so that the resulting number is a power ... | {"functional": "def check(candidate):\n assert candidate(n = 1) == True\n assert candidate(n = 10) == False\n\n\ncheck(Solution().reorderedPowerOf2)"} | coding | 99 |
Solve the programming task below in a Python markdown code block.
Let's play Fairy Chess!
You have an $n\times n$ chessboard. An $\boldsymbol{\mathrm{~S~}}$-leaper is a chess piece which can move from some square $(x_0,y_0)$ to some square $(x_{1},y_{1})$ if $abs(x_0-x_1)+abs(y_0-y_1)\leq s$; however, its movements ar... | {"inputs": ["3\n4 1 1\n....\n.L..\n.P..\n....\n3 2 1\n...\n...\n..L\n4 3 2\n....\n...L\n..P.\nP...\n"], "outputs": ["4\n11\n385\n"]} | coding | 714 |
Solve the programming task below in a Python markdown code block.
In 2937, DISCO creates a new universe called DISCOSMOS to celebrate its 1000-th anniversary.
DISCOSMOS can be described as an H \times W grid. Let (i, j) (1 \leq i \leq H, 1 \leq j \leq W) denote the square at the i-th row from the top and the j-th colu... | {"inputs": ["2 2 1", "7 48 1110", "3 29 1101", "5 48 1110", "3 22 1101", "5 70 1110", "3 35 1101", "11 6 1111"], "outputs": ["9", "404785941\n", "582975580\n", "220543434\n", "899722747\n", "284885353\n", "133144039\n", "533072736\n"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
### Task
King Arthur and his knights are having a New Years party. Last year Lancelot was jealous of Arthur, because Arthur had a date and Lancelot did not, and they started a duel.
To prevent this from happening again, Arthur wants to make sure that ... | {"functional": "_inputs = [[[1, -1, 1]], [[-1, -1, -1]], [[1, -1]], [[1, 1, 1]], [[]]]\n_outputs = [[True], [False], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance... | coding | 241 |
Solve the programming task below in a Python markdown code block.
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a... | {"inputs": ["3 2 3\n1 2\n0 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n1 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n2 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n2 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 2\n3 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 3\n4 9\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 2\n4 9\n1 2 2\n1 3 2"], "ou... | coding | 324 |
Solve the programming task below in a Python markdown code block.
Consider the set of all nonnegative integers: ${0, 1, 2, \dots}$. Given two integers $a$ and $b$ ($1 \le a, b \le 10^4$). We paint all the numbers in increasing number first we paint $0$, then we paint $1$, then $2$ and so on.
Each number is painted whi... | {"inputs": ["1\n9 1\n", "1\n9 2\n", "1\n17 1\n", "1\n29 1\n", "1\n29 2\n", "1\n29 3\n", "1\n48 3\n", "1\n48 6\n"], "outputs": ["Finite\n", "Finite\n", "Finite\n", "Finite\n", "Finite\n", "Finite\n", "Infinite\n", "Infinite\n"]} | coding | 644 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.
Return the minimum number of s... | {"functional": "def check(candidate):\n assert candidate(s = \"abacaba\") == 4\n assert candidate(s = \"ssssss\") == 6\n\n\ncheck(Solution().partitionString)"} | coding | 111 |
Solve the programming task below in a Python markdown code block.
Implement a function which behaves like the uniq command in UNIX.
It takes as input a sequence and returns a sequence in which all duplicate elements following each other have been reduced to one instance.
Example:
```
["a", "a", "b", "b", "c", "a", "... | {"functional": "_inputs = [[['a', 'a', 'b', 'b', 'c', 'a', 'b', 'c', 'c']], [['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']], [[]], [['foo']], [['bar']], [['']], [[None, 'a', 'a']]]\n_outputs = [[['a', 'b', 'c', 'a', 'b', 'c']], [['a', 'b', 'c']], [[]], [['foo']], [['bar']], [['']], [[None, 'a']]]\nimport math\ndef _dee... | coding | 121 |
Solve the programming task below in a Python markdown code block.
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all... | {"inputs": ["2 2\n3 3\n", "2 2\n3 2\n", "2 3\n1 2\n", "4 2\n1 1 3 4\n", "4 2\n1 2 3 4\n", "5 2\n2 4 1 1 3\n", "5 2\n2 4 1 1 1\n", "5 3\n5 5 7 5 1\n"], "outputs": ["6\n", "4\n", "0\n", "6\n", "8\n", "8\n", "6\n", "20\n"]} | coding | 583 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters.
A string X is called a good string when the following conditions are all met:
* Let L be the length of X. L is divisible by both ... | {"inputs": ["3 2\nacq\nae", "1 2\nacq\nae", "4 1\nabq\nae", "1 1\n`br\n`e", "5 2\naar\nae", "5 1\nacp\nae", "5 3\naar\nae", "7 2\n`ar\n`e"], "outputs": ["6\n", "2\n", "4\n", "1\n", "10\n", "5\n", "15\n", "14\n"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
The brothers Hiroshi and Kenjiro came to Lake Inawashiro for fishing. The two decided to score as follows and compete with the total score of the fish they caught.
* One char is a point
* One yamame trout b points
* Add c points for every 10 chars
* Add... | {"inputs": ["9 1\n3 1\n1 2 5 5", "5 1\n4 1\n1 2 5 5", "9 1\n3 1\n1 2 5 3", "5 1\n4 1\n1 2 5 1", "9 2\n3 1\n1 2 5 3", "5 1\n4 1\n1 2 5 0", "9 2\n2 1\n1 2 5 3", "5 1\n4 1\n1 0 5 0"], "outputs": ["hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n", "hiroshi\n"]} | coding | 430 |
Solve the programming task below in a Python markdown code block.
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each ot... | {"inputs": ["1 5 4 3 2\n", "6 0 0 2 8\n", "5 8 2 1 3\n", "2 0 0 1 3\n", "1 5 6 2 1\n", "5 0 0 6 7\n", "6 0 1 6 7\n", "3 5 1 1 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | coding | 591 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.
Return an array of all the ... | {"functional": "def check(candidate):\n assert candidate(text = \"alice is a good girl she is a good student\", first = \"a\", second = \"good\") == [\"girl\",\"student\"]\n assert candidate(text = \"we will we will rock you\", first = \"we\", second = \"will\") == [\"we\",\"rock\"]\n\n\ncheck(Solution().findOcur... | coding | 109 |
Solve the programming task below in a Python markdown code block.
Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some impo... | {"inputs": ["1\n", "7\n", "3\n", "8\n", "2\n", "5\n", "9\n", "4\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n"]} | coding | 545 |
Solve the programming task below in a Python markdown code block.
On March 14, the day of the number $\pi$ is celebrated all over the world. This is a very important mathematical constant equal to the ratio of the circumference of a circle to its diameter.
Polycarp was told at school that the number $\pi$ is irrationa... | {"inputs": ["1\n1\n", "1\n3\n", "1\n0\n", "1\n00\n", "1\n31\n", "2\n0\n0\n", "1\n3444\n", "3\n8\n5\n8\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "2\n", "0\n0\n", "1\n", "0\n0\n0\n"]} | coding | 446 |
Solve the programming task below in a Python markdown code block.
Given an array (arr) as an argument complete the function `countSmileys` that should return the total number of smiling faces.
Rules for a smiling face:
- Each smiley face must contain a valid pair of eyes. Eyes can be marked as `:` or `;`
- A smiley ... | {"functional": "_inputs = [[[]], [[':D', ':~)', ';~D', ':)']], [[':)', ':(', ':D', ':O', ':;']], [[';]', ':[', ';*', ':$', ';-D']]]\n_outputs = [[0], [4], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=t... | coding | 312 |
Solve the programming task below in a Python markdown code block.
# Task
Given some sticks by an array `V` of positive integers, where V[i] represents the length of the sticks, find the number of ways we can choose three of them to form a triangle.
# Example
For `V = [2, 3, 7, 4]`, the result should be `1`.
There ... | {"functional": "_inputs = [[[2, 3, 7, 4]], [[5, 6, 7, 8]], [[2, 2, 2, 2]], [[1, 2, 5]], [[1, 2, 3, 10, 20, 30, 4]], [[1, 2, 3]]]\n_outputs = [[1], [4], [4], [0], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab... | coding | 249 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are par... | {"functional": "def check(candidate):\n assert candidate(rec1 = [0,0,2,2], rec2 = [1,1,3,3]) == True\n assert candidate(rec1 = [0,0,1,1], rec2 = [1,0,2,1]) == False\n assert candidate(rec1 = [0,0,1,1], rec2 = [2,2,3,3]) == False\n\n\ncheck(Solution().isRectangleOverlap)"} | coding | 188 |
Solve the programming task below in a Python markdown code block.
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes... | {"inputs": ["4\n4\n0 0 0 1\n2\n1 1\n6\n1 2 3 4 5 6\n4\n2 28 3 22\n"], "outputs": ["1\n0\n4\n3\n"]} | coding | 747 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.
Return any possible rearrangement of s or return "" if not possible.
Please complete the following python code pr... | {"functional": "def check(candidate):\n assert candidate(s = \"aab\") == \"aba\"\n assert candidate(s = \"aaab\") == \"\"\n\n\ncheck(Solution().reorganizeString)"} | coding | 85 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the ith tire can finish its xth successive lap in fi * ri(x-1) seconds.
For example, if fi = 3 and ri = 2, then the tire would... | {"functional": "def check(candidate):\n assert candidate(tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4) == 21\n assert candidate(tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5) == 25\n\n\ncheck(Solution().minimumFinishTime)"} | coding | 248 |
Solve the programming task below in a Python markdown code block.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, nu... | {"inputs": ["1\n0\n0\n", "1\n1\n0\n", "1\n1\n1\n", "1\n0\n1\n", "1\n0\n2\n", "1\n0\n4\n", "1\n0\n3\n", "1\n0\n-1\n"], "outputs": ["0\n", "1\n1\n", "0\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]} | coding | 477 |
Solve the programming task below in a Python markdown code block.
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertic... | {"inputs": ["1\n0 1", "1\n1 1", "2\n0 3 2", "2\n0 1 1", "2\n0 2 2", "2\n0 3 1", "2\n-1 3 2", "2\n-2 3 2"], "outputs": ["2\n", "-1", "-1\n", "4\n", "-1\n", "-1", "7\n", "8\n"]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Gritukan likes to take cyclic trips around the world. There are $N$ countries numbered $1$ through $N$ in the world. Before starting his travels, Gritukan chooses a permutati... | {"inputs": ["2\n6\n1 1 1 1 1 1\n6\n6 6 6 6 6 6"], "outputs": ["1\n120"]} | coding | 595 |
Solve the programming task below in a Python markdown code block.
You are given a binary string S.
In one operation, you can pick an index i (1≤ i < |S|) and swap the characters S_{i} and S_{(i+1)}.
Find the minimum number of operations required, such that, the decimal representation of the final binary string is di... | {"inputs": ["3\n0000\n111\n11001"], "outputs": ["0\n-1\n1"]} | coding | 451 |
Solve the programming task below in a Python markdown code block.
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuf... | {"inputs": ["3\nnoe\n", "3\nnoe\n", "3\none\n", "3\neon\n", "3\nneo\n", "3\neno\n", "3\noen\n", "4\nezor\n"], "outputs": ["1 \n", "1\n", "1 ", "1 ", "1 ", "1 ", "1 ", "0 \n"]} | coding | 312 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of integers $a_1, a_2, \dots, a_n$. You need to paint elements in colors, so that: If we consider any color, all elements of this color must be divisible by the minimal element of this color. The number of used colors must be ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n100\n", "2\n1 1\n", "2\n1 2\n", "1\n100\n", "2\n1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 674 |
Solve the programming task below in a Python markdown code block.
Your task is to write a program which reads an expression and evaluates it.
* The expression consists of numerical values, operators and parentheses, and the ends with '='.
* The operators includes +, - , *, / where respectively represents, addition, su... | {"inputs": ["2\n4-2*3=\n8*(4+4+3)=", "2\n4-2*3=\n8*(4+4+2)=", "2\n4-3*3=\n4*(8+4+3)=", "2\n4-1*3=\n4*(8+4+3)=", "2\n4-1+3=\n4*(8+4+3)=", "2\n4-2+3=\n4*(8+4+3)=", "2\n5-1+3=\n4*(8+4+3)=", "2\n3-1*3=\n4*(8+4+3)="], "outputs": ["-2\n88\n", "-2\n80\n", "-5\n60\n", "1\n60\n", "6\n60\n", "5\n60\n", "7\n60\n", "0\n60\n"]} | coding | 250 |
Solve the programming task below in a Python markdown code block.
You are given a $sorted$ list $A$ of size $N$.You have to make a new list $B$ such that $B[i]$ is equal to the number of elements $strictly$ $greater$ than $A[i]$ in the list $A$.
Print the $new$ $list$.
------ Input ------
The first line consists o... | {"inputs": ["2\n4\n1 2 4 4\n5\n1 2 2 2 2"], "outputs": ["3 2 0 0\n4 0 0 0 0"]} | coding | 535 |
Solve the programming task below in a Python markdown code block.
It's the academic year's end, fateful moment of your school report.
The averages must be calculated. All the students come to you and entreat you to calculate their average for them.
Easy ! You just need to write a script.
Return the average of the give... | {"functional": "_inputs = [[[2, 2, 2, 2]], [[1, 5, 87, 45, 8, 8]], [[2, 5, 13, 20, 16, 16, 10]], [[1, 2, 15, 15, 17, 11, 12, 17, 17, 14, 13, 15, 6, 11, 8, 7]]]\n_outputs = [[2], [25], [11], [11]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo... | coding | 107 |
Solve the programming task below in a Python markdown code block.
Sunita has lots of tasks pending and she has no time to complete. She needs your help and wants you complete the task.
You are given a list of integers and two values $N$ and $K$ $-$ the size of array of integers and the numbers of partitions to be made... | {"inputs": ["1\n4 2\n5 6 3 2"], "outputs": ["6"]} | coding | 340 |
Solve the programming task below in a Python markdown code block.
Mark and Jane are very happy after having their first child. Their son loves toys, so Mark wants to buy some. There are a number of different toys lying in front of him, tagged with their prices. Mark has only a certain amount to spend, and he wants to ... | {"inputs": ["7 50\n1 12 5 111 200 1000 10\n"], "outputs": ["4\n"]} | coding | 420 |
Solve the programming task below in a Python markdown code block.
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another o... | {"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n1 1\n", "2\n2 2\n", "2\n2 4\n", "2\n1 4\n", "2\n4 3\n", "2\n8 3\n"], "outputs": ["3", "2", "2\n", "4\n", "6\n", "5\n", "7\n", "11\n"]} | coding | 614 |
Solve the programming task below in a Python markdown code block.
We have three stones at points (0, 0), (1,0), and (0,1) on a two-dimensional plane.
These three stones are said to form an L when they satisfy the following conditions:
- Each of the stones is at integer coordinates.
- Each of the stones is adjacent to... | {"inputs": ["1\n3 2 2 2 2 1\n", "10\n0 0 1 0 0 1\n1 0 0 1 1 1\n2 -1 1 -1 1 0\n1 -2 2 -1 1 -1\n-1 2 0 2 -1 3\n-1 -2 -2 -2 -2 -3\n-2 4 -3 3 -2 3\n3 1 4 2 4 1\n-4 2 -4 3 -3 3\n5 4 5 3 4 4\n"], "outputs": ["4\n", "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n"]} | coding | 587 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.
A grid is said to be valid if all the cells above the main diagonal are zeros.
Return the minimum number of steps nee... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,0,1],[1,1,0],[1,0,0]]) == 3\n assert candidate(grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]) == -1\n assert candidate(grid = [[1,0,0],[1,1,0],[1,1,1]]) == 0\n\n\ncheck(Solution().minSwaps)"} | coding | 143 |
Solve the programming task below in a Python markdown code block.
This contest, AtCoder Beginner Contest, is abbreviated as ABC.
When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.
What is the abbreviation for the N-th round of ABC? Write ... | {"inputs": ["7", "3", "4", "8", "9", "0", "1", "2"], "outputs": ["ABC7\n", "ABC3\n", "ABC4\n", "ABC8\n", "ABC9\n", "ABC0\n", "ABC1\n", "ABC2\n"]} | coding | 161 |
Solve the programming task below in a Python markdown code block.
Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size $n \times m$ cells on a map (rows of grid are numbered from $1$ to $n$ from north to south, and columns are numbered from $... | {"inputs": ["3 4 3 3\n4 4 0 5\n", "1 1 1 1\n1 3 4 7\n", "1 1 1 1\n1 3 4 7\n", "3 4 3 3\n4 4 0 5\n", "3 4 2 1\n1 2 3 59\n", "3 4 2 1\n2 2 3 59\n", "3 4 2 1\n2 4 3 59\n", "3 4 2 1\n2 4 0 59\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "111\n", "153\n", "44\n", "172\n"]} | coding | 751 |
Solve the programming task below in a Python markdown code block.
During the hypnosis session, Nicholas suddenly remembered a positive integer $n$, which doesn't contain zeros in decimal notation.
Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so t... | {"inputs": ["1\n1\n9\n", "1\n1\n1\n", "1\n1\n8\n", "1\n1\n4\n", "1\n1\n6\n", "1\n2\n77\n", "1\n2\n77\n", "1\n2\n83\n"], "outputs": ["1\n9\n", "1\n1\n", "1\n8\n", "1\n4\n", "1\n6\n", "2\n77\n", "2\n77\n", "1\n8\n"]} | coding | 630 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line.
You are given a 0-indexed integer array tickets of length n wh... | {"functional": "def check(candidate):\n assert candidate(tickets = [2,3,2], k = 2) == 6\n assert candidate(tickets = [5,1,1,1], k = 0) == 8\n\n\ncheck(Solution().timeRequiredToBuy)"} | coding | 216 |
Solve the programming task below in a Python markdown code block.
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of n next days. The number of seconds that Luba has to spend worki... | {"inputs": ["1 1\n86399\n", "1 1\n86399\n", "2 2\n86400 86398\n", "2 86400\n0 86400\n", "2 86400\n1 86399\n", "2 86400\n1 86399\n", "2 86400\n0 86399\n", "2 86400\n0 48332\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "1\n", "1\n"]} | coding | 294 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well.
You are given the height $H$ (in metres) and mass $M$ (in kilograms) of Chef. The Body Mass Index (BMI) of a person is computed as $\frac{M}{H^{2}}$.
Report t... | {"inputs": ["3\n72 2\n80 2\n120 2"], "outputs": ["1\n2\n4"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor o... | {"inputs": ["9\n", "8\n", "4\n", "2\n", "5\n", "3\n", "7\n", "1\n"], "outputs": ["2", "1\n4", "2", "1\n0", "1\n0", "1\n0", "1\n0\n", "1\n0"]} | coding | 418 |
Solve the programming task below in a Python markdown code block.
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set o... | {"inputs": ["1\n2\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n7\n"], "outputs": ["1\n", "-1\n", "-1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 227 |
Solve the programming task below in a Python markdown code block.
# Task
Let's consider a table consisting of `n` rows and `n` columns. The cell located at the intersection of the i-th row and the j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer `... | {"functional": "_inputs = [[5, 5], [10, 5], [6, 12], [6, 169], [100000, 1000000000]]\n_outputs = [[2], [2], [4], [0], [16]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):... | coding | 489 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclu... | {"functional": "def check(candidate):\n assert candidate(nums = [1,0,2,1,3]) == [3,3,2,2,1]\n assert candidate(nums = [1,2]) == [2,1]\n\n\ncheck(Solution().smallestSubarrays)"} | coding | 229 |
Solve the programming task below in a Python markdown code block.
Chef has a nice complete binary tree in his garden. Complete means that each node has exactly two sons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way:
- Let's call the nodes' level a number of nodes that occur ... | {"inputs": ["4\nrll\nrll\nr\nlllr", "4\nlrl\nrll\nr\nrlll", "4\nlrl\nrll\nr\nllrl", "4\nrll\nllr\nr\nlllr", "4\nrll\nrll\nr\nllrl", "4\nrll\nllr\nr\nrlll", "4\nllr\nllr\nr\nrlll", "4\nllr\nrll\nr\nrlll"], "outputs": ["14\n14\n4\n13\n", "10\n14\n4\n27\n", "10\n14\n4\n15\n", "14\n8\n4\n13\n", "14\n14\n4\n15\n", "14\n8\n4... | coding | 538 |
Solve the programming task below in a Python markdown code block.
Given an array of integers and a target sum, determine the sum nearest to but not exceeding the target that can be created. To create the sum, use any element of your array zero or more times.
For example, if $arr=[2,3,4]$ and your target sum is $10$, ... | {"inputs": ["2\n3 12\n1 6 9\n5 9\n3 4 4 4 8\n"], "outputs": ["12\n9\n"]} | coding | 425 |
Solve the programming task below in a Python markdown code block.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\operatorname{d... | {"inputs": ["1 1\n", "2 2\n", "4 1\n", "4 2\n", "4 3\n", "4 4\n", "3 4\n", "2 4\n"], "outputs": ["0\n", "8\n", "0\n", "24\n", "102\n", "264\n", "162\n", "84\n"]} | coding | 348 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Chef is stuck at the following problem. Help him solve it!
Chef has a sequence of integers $A_{1}, A_{2}, \dots, A_{N}$. He should find the number of... | {"inputs": ["1\n5\n2 4 8 1 3"], "outputs": ["3"]} | coding | 433 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.
Return true if it is po... | {"functional": "def check(candidate):\n assert candidate(s1 = \"bank\", s2 = \"kanb\") == True\n assert candidate(s1 = \"attack\", s2 = \"defend\") == False\n assert candidate(s1 = \"kelb\", s2 = \"kelb\") == True\n assert candidate(s1 = \"abcd\", s2 = \"dcba\") == False\n\n\ncheck(Solution().areAlmostEqual... | coding | 124 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
As we all know, Binomial Coefficient C(n, r) is defined by the
following formula.
Also define S(n) as follows.
Note that n will be provided to you as an input parameter.
Since S(n) can be ... | {"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["2\n4\n2\n4\n8"]} | coding | 258 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
Chef has bought a new robot, which will be used for delivering dishes to his customers. He started testing the robot by letting it move on a line.
Initially... | {"inputs": ["2\n6 10\nRRLLLL\n2 0\nLL"], "outputs": ["5\n3"]} | coding | 497 |
Solve the programming task below in a Python markdown code block.
Write
```python
remove(text, what)
```
that takes in a string ```str```(```text``` in Python) and an object/hash/dict/Dictionary ```what``` and returns a string with the chars removed in ```what```.
For example:
```python
remove('this is a string',{'t':1... | {"functional": "_inputs = [['this is a string', {'t': 1, 'i': 2}], ['hello world', {'x': 5, 'i': 2}], ['apples and bananas', {'a': 50, 'n': 1}], ['a', {'a': 1, 'n': 1}], ['codewars', {'c': 5, 'o': 1, 'd': 1, 'e': 1, 'w': 1, 'z': 1, 'a': 1, 'r': 1, 's': 1}]]\n_outputs = [['hs s a string'], ['hello world'], ['pples d bnn... | coding | 222 |
Solve the programming task below in a Python markdown code block.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. E... | {"inputs": ["3\nhaneda\noookayama\nssu\n2\nazusa\nazishirabe\n2\nsnuke\nsnake\n4\nhaneda\nhonda\nhanamaki\nhawaii\n0", "3\nhaneda\noookayama\ntsv\n2\nazusa\nazishirabe\n2\nrnuke\nsnake\n4\nhaneda\nhonda\nhanamaki\nhawbii\n0", "3\nhaneda\noookayama\ntsv\n2\nazvsa\nazishirabe\n2\nrnuke\nsnake\n4\nhaneda\nhonda\nhanamaki\... | coding | 553 |
Solve the programming task below in a Python markdown code block.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Pe... | {"inputs": ["4\n", "6\n", "1\n", "1\n", "2\n", "3\n", "5\n", "8\n"], "outputs": ["3\n2 4 3 \n", "4\n2 4 3 5 \n", "0\n\n", "0\n", "1\n2 ", "2\n2 3 ", "4\n2 4 3 5 ", "6\n2 4 8 3 5 7 "]} | coding | 413 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese] and [Bengali].
Given n (n is even), determine the number of black cells in an n \times n chessboard.
------ Input Format ------
The only line of the input contains a single integer n.
------ Output Form... | {"inputs": ["8"], "outputs": ["32"]} | coding | 168 |
Solve the programming task below in a Python markdown code block.
Ken loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.
G consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.
First, Ken stands on Vertex S. He wants to reac... | {"inputs": ["3 0\n1 2", "6 0\n1 2", "2 0\n1 2", "2 0\n1 2\n", "3 3\n1 2\n2 3\n2 1\n1 2", "3 1\n1 1\n3 3\n3 1\n1 2", "3 3\n1 1\n2 3\n3 1\n1 2", "3 3\n1 2\n2 1\n2 1\n1 2"], "outputs": ["-1\n", "-1\n", "-1", "-1\n", "1\n", "0\n", "-1\n", "1\n"]} | coding | 514 |
Solve the programming task below in a Python markdown code block.
You are given an unsorted permutation P of size N. An operation is defined as:
Swap P_{i} and P_{i+K} for any i in the range [1,N-K].
Find the maximum value of K, such that, the permutation P can be sorted by applying any finite number of operations.
... | {"inputs": ["3\n4\n4 2 3 1\n5\n1 4 3 2 5\n2\n2 1\n"], "outputs": ["3\n2\n1\n"]} | coding | 473 |
Solve the programming task below in a Python markdown code block.
You are given $n$ permutations $a_1, a_2, \dots, a_n$, each of length $m$. Recall that a permutation of length $m$ is a sequence of $m$ distinct integers from $1$ to $m$.
Let the beauty of a permutation $p_1, p_2, \dots, p_m$ be the largest $k$ such tha... | {"inputs": ["1\n3 10\n1 2 3 4 7 9 8 5 6 10\n6 8 9 4 2 5 7 3 1 10\n1 2 3 4 8 10 5 7 6 9\n", "3\n3 4\n2 4 1 3\n1 2 4 3\n2 1 3 4\n2 2\n1 2\n2 1\n8 10\n3 4 9 6 10 2 7 8 1 5\n3 9 1 8 5 7 4 10 2 6\n3 10 1 7 5 9 6 4 2 8\n1 2 3 4 8 6 10 7 9 5\n1 2 3 4 10 6 8 5 7 9\n9 6 1 2 10 4 7 8 3 5\n7 9 3 2 5 6 4 8 1 10\n9 4 3 7 5 6 1 10 8... | coding | 676 |
Solve the programming task below in a Python markdown code block.
You are a skier (marked below by the `X`). You have made it to the Olympics! Well done.
```
\_\_\_X\_
\*\*\*\*\*\
\*\*\*\*\*\*\
\*\*\*\*\*\*\*\
\*\*\*\*\*\*\*\*\
\*\*\*\*\*\*\*\*\*\\.\_\_\_\_/
```
Your job in this kata is to calculate the maximum speed... | {"functional": "_inputs = [[['*']], [['*', '**', '***']], [['*', '**', '***', '****', '*****', '******']], [['*', '**', '***', '****', '*****', '******', '*******', '********']]]\n_outputs = [[\"1.35 metres: He's crap!\"], [\"12.15 metres: He's ok!\"], [\"48.60 metres: He's flying!\"], ['86.40 metres: Gold!!']]\nimport... | coding | 449 |
Solve the programming task below in a Python markdown code block.
There are N children, numbered 1, 2, \ldots, N.
They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over.
Find the number... | {"inputs": ["1 10\n3", "1 10\n9", "1 10\n17", "2 0\n0 0", "3 4\n1 2 3", "4 100000\n101000 100000 100000 100000", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000"], "outputs": ["0\n", "0", "1\n", "1", "5", "665683269\n", "744244119\n", "741473440\n"]} | coding | 324 |
Solve the programming task below in a Python markdown code block.
You are given a sequence $A_1, A_2, \ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$.
Chef is a curious person, so he wants to know the maximum star value i... | {"inputs": ["1\n7\n8 1 28 4 2 6 7"], "outputs": ["3"]} | coding | 383 |
Solve the programming task below in a Python markdown code block.
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some... | {"inputs": ["2\n0 0\n0 0\n", "2\n0 0\n0 0\n", "2\n0 0\n0 1\n", "2\n1 0\n0 1\n", "2\n1 0\n0 0\n", "2\n0 1\n0 1\n", "2\n1 0\n1 0\n", "2\n0 1\n1 1\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "1\n", "0\n", "0\n", "1\n"]} | coding | 621 |
Solve the programming task below in a Python markdown code block.
Fans of The Wire will appreciate this one.
For those that haven't seen the show, the Barksdale Organization has a simple method for encoding telephone numbers exchanged via pagers: "Jump to the other side of the 5 on the keypad, and swap 5's and 0's."
... | {"functional": "_inputs = [['4103432323'], ['4103438970'], ['4104305768'], ['4102204351'], ['4107056043']]\n_outputs = [['6957678787'], ['6957672135'], ['6956750342'], ['6958856709'], ['6953504567']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | coding | 279 |
Solve the programming task below in a Python markdown code block.
Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one ... | {"inputs": ["1\n", "0\n", "2\n", "55\n", "99\n", "93\n", "13\n", "84\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
Pushpa has entered Chefland and wants to establish Pushpa-Raj here too.
Chefland has N towers where the height of the i^{th} tower is H_{i}. To establish Pushpa-Raj, Pushpa does the following:
Initially, Pushpa chooses any tower i (1≤ i ≤ N) and lands ... | {"inputs": ["2\n4\n1 2 1 3\n1\n2"], "outputs": ["3\n2"]} | coding | 557 |
Solve the programming task below in a Python markdown code block.
Chef has a binary string S. He can modify it by choosing any subsequence of length 3 from it and deleting the first and last character of the subsequence.
For example, if S = \textcolor{red}{11}01\textcolor{red}{0}1, Chef can choose the subsequence mark... | {"inputs": ["4\n101\n1010\n0000\n0001\n"], "outputs": ["101\n11\n0000\n01\n"]} | coding | 519 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well.
You have been appointed as the designer for your school's computer network.
In total, there are N computers in the class, and M computer-to-computer connections need to be ... | {"inputs": ["2\n10 1\n5 5"], "outputs": ["-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1"]} | coding | 545 |
Solve the programming task below in a Python markdown code block.
You've had a baby.
Well done. Nice isn't it? Life destroying... but in a good way.
Part of your new routine is lying awake at night worrying that you've either lost the baby... or that you have more than 1!
Given a string of words (x), you need to cal... | {"functional": "_inputs = [['baby'], ['abby'], ['baby baby baby'], ['Why the hell are there so many babies?!'], ['Anyone remember life before babies?'], ['Happy babies boom ba by?'], ['b a b y'], [''], ['none here']]\n_outputs = [[1], [1], [3], [1], [1], [2], [1], [\"Where's the baby?!\"], [\"Where's the baby?!\"]]\nim... | coding | 227 |
Solve the programming task below in a Python markdown code block.
Your job is to write a function that takes a string and a maximum number of characters per line and then inserts line breaks as necessary so that no line in the resulting string is longer than the specified limit.
If possible, line breaks should not spl... | {"functional": "_inputs = [['test', 7], ['hello world', 7], ['a lot of words for a single line', 10], ['this is a test', 4], ['a longword', 6], ['areallylongword', 6], ['aa', 3], ['aaa', 3], ['aaaa', 3], ['a a', 3], ['a aa', 3], ['a aaa', 3], ['a aaaa', 3], ['a aaaaa', 3], ['a a a', 3], ['a aa a', 3], ['a aaa a', 3], [... | coding | 349 |
Solve the programming task below in a Python markdown code block.
Our football team finished the championship.
The result of each match look like "x:y". Results of all matches are recorded in the collection.
For example:
```["3:1", "2:2", "0:1", ...]```
Write a function that takes such collection and counts the point... | {"functional": "_inputs = [[['1:0', '2:0', '3:0', '4:0', '2:1', '3:1', '4:1', '3:2', '4:2', '4:3']], [['1:1', '2:2', '3:3', '4:4', '2:2', '3:3', '4:4', '3:3', '4:4', '4:4']], [['0:1', '0:2', '0:3', '0:4', '1:2', '1:3', '1:4', '2:3', '2:4', '3:4']], [['1:0', '2:0', '3:0', '4:0', '2:1', '1:3', '1:4', '2:3', '2:4', '3:4']... | coding | 169 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.