task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Alice gave Bob 3 integers N, K, and S. Help Bob find an S-good sequence.
A sequence B of length N is called S-good if the following conditions are met:
B_{i} \in \{-1, 0, 1\} for each 1 ≤ i ≤ N
\sum_{i=1}^N B_{i}\cdot K^{i-1} = S
If there are multiple ... | {"inputs": ["3\n4 2 15\n3 6 36\n5 5 7"], "outputs": ["1 1 1 1\n0 0 1\n-2"]} | 497 | 47 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.
if no such substring exists, return 0.
Pl... | {"functional": "def check(candidate):\n assert candidate(s = \"aaabb\", k = 3) == 3\n assert candidate(s = \"ababbc\", k = 2) == 5\n\n\ncheck(Solution().longestSubstring)"} | 97 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he dre... | {"inputs": ["1\n1\n", "1\n5\n", "1\n5\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n4\n", "1\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 350 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Sakuzyo - Imprinting
A.R.C. Markland-N is a tall building with $n$ floors numbered from $1$ to $n$. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr, and he'... | {"inputs": ["1\n10 1 1\n1\n", "1\n10 1 1\n1\n", "1\n10 9 2\n8 2\n", "1\n10 9 2\n8 2\n", "1\n110 8 1\n32\n", "1\n100 32 1\n32\n", "1\n100 32 1\n32\n", "1\n100 55 1\n32\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]} | 660 | 157 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of reverse pairs in the array.
A reverse pair is a pair (i, j) where:
0 <= i < j < nums.length and
nums[i] > 2 * nums[j].
Please complete the following python code pr... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,3,1]) == 2\n assert candidate(nums = [2,4,3,5,1]) == 3\n\n\ncheck(Solution().reversePairs)"} | 97 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Santa Claus has received letters from $n$ different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the $i$-th kid asked Santa to give them one of $k_i$ different items as a present. Some items could h... | {"inputs": ["2\n2 2 1\n1 1\n", "2\n2 4 1\n1 1\n", "2\n2 8 1\n1 2\n", "2\n2 8 1\n1 1\n", "2\n2 3 1\n1 1\n", "2\n2 4 1\n1 2\n", "2\n2 4 1\n1 4\n", "2\n2 5 1\n1 1\n"], "outputs": ["124780545\n", "124780545\n", "499122177\n", "124780545\n", "124780545\n", "499122177\n", "124780545\n", "124780545\n"]} | 688 | 214 |
coding | Solve the programming task below in a Python markdown code block.
In the city of Saint Petersburg, a day lasts for $2^{100}$ minutes. From the main station of Saint Petersburg, a train departs after $1$ minute, $4$ minutes, $16$ minutes, and so on; in other words, the train departs at time $4^k$ for each integer $k \ge... | {"inputs": ["0\n", "1\n", "1\n", "0\n", "11\n", "11\n", "101\n", "110\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "2\n", "2\n"]} | 385 | 76 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.
A sequence $a$ ... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 1\n", "1\n998\n", "1\n998\n", "2\n1 1\n", "2\n2 1\n", "2\n2 2\n"], "outputs": ["1", "1", "1", "-1", "-1", "1", "1\n", "2\n"]} | 388 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master.... | {"inputs": ["2\n5 4\n8 6", "2\n5 2\n5 3", "2\n9 6\n5 7", "2\n9 7\n8 3", "2\n9 7\n1 9", "2\n6 7\n8 7", "2\n6 7\n5 9", "2\n3 7\n4 6"], "outputs": ["2\n3\n", "1\n2\n", "4\n5\n", "4\n2\n", "4\n1\n", "6\n3\n", "6\n5\n", "3\n4\n"]} | 471 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Alice (uniformly and independently) randomly picks two integers a, b from the range [1,10^{4}], and writes down the values of a + b, a - b, a \cdot b and \lfloor \frac{a}{b} \rfloor (integer division) in some random order. Unfortunately, she forgot the v... | {"inputs": ["2\n-1 72 0 17\n1 4 5 6"], "outputs": ["8 9\n-1 -1"]} | 563 | 38 |
coding | Solve the programming task below in a Python markdown code block.
$Riggi$ is a spy of $KBI$ and he is on a secret mission, he is spying an Underworld Don $Anit$.
$Riggi$ is spying him since 5 years and he is not able to find any evidence against $Anit$.
$KBI$ told $Riggi$ they will send him a code string in a spe... | {"inputs": ["3+xy-bb3+yx-", "3+xy-bb3+xy-"], "outputs": ["Return", "Continue"]} | 467 | 33 |
coding | Solve the programming task below in a Python markdown code block.
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by... | {"inputs": ["1\n2\n", "1\n3\n", "1\n1\n", "1\n4\n", "2\n2 1\n", "2\n4 2\n", "2\n4 1\n", "2\n1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n"]} | 343 | 94 |
coding | Solve the programming task below in a Python markdown code block.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing... | {"inputs": ["3 2 3", "5 4 1", "0 2 3", "8 4 1", "0 0 3", "8 4 2", "3 3 3", "5 4 2"], "outputs": ["1 2\n", "2 6\n", "0 1\n", "4 8\n", "0 0\n", "8 4\n", "1 3", "5 3"]} | 276 | 108 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Android devices have a special lock screen with a 3 x 3 grid of dots. Users can set an "unlock pattern" by connecting the dots in a specific sequence, forming a series of joined line segments where each segment's endp... | {"functional": "def check(candidate):\n assert candidate(m = 1, n = 1) == 9\n assert candidate(m = 1, n = 2) == 65\n\n\ncheck(Solution().numberOfPatterns)"} | 517 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Given an `x` and `y` find the smallest and greatest numbers **above** and **below** a given `n` that are divisible by both `x` and `y`.
### Examples
```python
greatest(2, 3, 20) => 18 # 18 is the greatest number under 20 that is divisible by both 2 an... | {"functional": "_inputs = [[2, 3, 20], [13, 17, 100], [10, 100, 100], [1000000007, 1000000009, 10000000000000000000]]\n_outputs = [[18], [0], [0], [9000000144000000567]]\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_... | 423 | 262 |
coding | Solve the programming task below in a Python markdown code block.
# Definition
**_Jumping number_** is the number that *All adjacent digits in it differ by 1*.
____
# Task
**_Given_** a number, **_Find if it is Jumping or not_** .
____
# Warm-up (Highly recommended)
# [Playing With Numbers Series](https://www.co... | {"functional": "_inputs = [[1], [7], [9], [23], [32], [79], [98], [987654322]]\n_outputs = [['Jumping!!'], ['Jumping!!'], ['Jumping!!'], ['Jumping!!'], ['Jumping!!'], ['Not!!'], ['Jumping!!'], ['Not!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma... | 602 | 223 |
coding | Solve the programming task below in a Python markdown code block.
Given an array A of n non-negative integers. Find the number of ways to partition/divide the array into subarrays, such that mex in each subarray is not more than k. For example, mex of the arrays [1, 2] will be 0, and that of [0, 2] will be 1, and that... | {"inputs": ["3 1\n0 1 2\n\n", "10 3\n0 1 2 3 4 0 1 2 5 3\n\n"], "outputs": ["2", "379"]} | 403 | 55 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin, Russian and Vietnamese as well.
There are N sets of integers from 1 to K both inclusive. Find out number of pairs of sets whose union contains all the K elements.
------ Input ------
The first line contains an i... | {"inputs": ["3\n2 2\n1 1\n1 1\n3 2\n2 1 2\n2 1 2\n2 1 2\n3 4\n3 1 2 3\n4 1 2 3 4\n3 2 3 4"], "outputs": ["0\n3\n3"]} | 429 | 80 |
coding | Solve the programming task below in a Python markdown code block.
You have a playlist consisting of $n$ songs. The $i$-th song is characterized by two numbers $t_i$ and $b_i$ — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied b... | {"inputs": ["2 1\n1 2\n2 1\n", "2 1\n1 2\n2 1\n", "2 2\n1 2\n2 1\n", "2 1\n1 2\n0 1\n", "2 1\n2 2\n2 1\n", "2 2\n100 100\n100 100\n", "2 2\n100 100\n100 100\n", "2 2\n100 100\n000 100\n"], "outputs": ["2\n", "2", "3\n", "2\n", "4\n", "20000\n", "20000", "10000\n"]} | 456 | 184 |
coding | Solve the programming task below in a Python markdown code block.
Pete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun.
They decide to have a competition. 3 rounds, 2 shots each. Winner is the one with the most hits.
Some of the clays have something attached to create ... | {"functional": "_inputs = [[[[{'P1': 'XX', 'P2': 'XO'}, True], [{'P1': 'OX', 'P2': 'OO'}, False], [{'P1': 'XX', 'P2': 'OX'}, True]]], [[[{'P1': 'XX', 'P2': 'XO'}, False], [{'P1': 'OX', 'P2': 'XX'}, False], [{'P1': 'OO', 'P2': 'XX'}, True]]], [[[{'P1': 'OO', 'P2': 'XX'}, False], [{'P1': 'OO', 'P2': 'XX'}, False], [{'P1'... | 312 | 425 |
coding | Solve the programming task below in a Python markdown code block.
It is an interesting exercise to write a program to print out all permutations of $1, 2, …, n$. However, since there are $6227020800$ permutations of $1, 2, …, 13$, it is unlikely that we would ever run this program on an input of size more than $10$.
Ho... | {"inputs": ["3 2\n3 1 2\n2 3 1\n"], "outputs": ["3 2 1\n3 1 2 "]} | 483 | 38 |
coding | Solve the programming task below in a Python markdown code block.
John is developing a system to report fuel usage but needs help with the coding.
First, he needs you to write a function that, given the actual consumption (in l/100 km) and remaining amount of petrol (in l), will give you how many kilometers you'll be ... | {"functional": "_inputs = [[10, 60], [8, 0], [6.4, 54], [9.3, 87.3], [11.7, 63.4]]\n_outputs = [[600], [0], [843.75], [938.71], [541.88]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (... | 269 | 228 |
coding | Solve the programming task below in a Python markdown code block.
# Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an **_array of integers_** , **_Find the minimum sum_** which is obtained... | {"functional": "_inputs = [[[5, 4, 2, 3]], [[12, 6, 10, 26, 3, 24]], [[9, 2, 8, 7, 5, 4, 0, 6]]]\n_outputs = [[22], [342], [74]]\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, tup... | 492 | 219 |
coding | Solve the programming task below in a Python markdown code block.
Bob has a string $s$ consisting of lowercase English letters. He defines $s'$ to be the string after removing all "a" characters from $s$ (keeping all other characters in the same order). He then generates a new string $t$ by concatenating $s$ and $s'$. ... | {"inputs": ["a\n", "b\n", "a\n", "b\n", "`\n", "c\n", "_\n", "^\n"], "outputs": ["a\n", ":(\n", "a", ":(", ":(\n", ":(\n", ":(\n", ":(\n"]} | 364 | 72 |
coding | Solve the programming task below in a Python markdown code block.
The "Western calendar" is a concept imported from the West, but in Japan there is a concept called the Japanese calendar, which identifies the "era name" by adding a year as a method of expressing the year on the calendar. For example, this year is 2016 ... | {"inputs": ["4 2", "3 1", "2 0", "3 2", "4 1", "1 0", "3 0", "4 0"], "outputs": ["1990\n", "1926\n", "1911\n", "1927\n", "1989\n", "1867\n", "1925\n", "1988\n"]} | 629 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n.
The sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])2 for each 0 <= i < n.
You a... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0) == 579\n assert candidate(nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1) == 43\n\n\ncheck(Solution().minSumSquareDiff)"} | 229 | 115 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Leonid is developing new programming language. The key feature of his language is fast multiplication and raising to a power operations. He is asking you to help with the following task.
You ha... | {"inputs": ["2\n1000 2**3*3**1\n100000 11**2*2**4", "2\n1000 2**3*3**1\n100000 4**2*2**11", "2\n1001 2**3*2**1\n100000 4**2*2**11", "2\n1000 2**3*3**1\n101000 11**2*2**4", "2\n1001 1**3*3**2\n100000 4**2*2**11", "2\n1001 1**3*3**2\n100000 4**2*2**01", "2\n1001 1**3*3**1\n110000 11**2*2**4", "2\n1100 2**3*3**1\n110000 4... | 422 | 339 |
coding | Solve the programming task below in a Python markdown code block.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has ... | {"inputs": ["1\n0 0\n", "1\n0 0\n", "1\n0 1\n", "1\n0 2\n", "1\n-1 2\n", "1\n-1 0\n", "1\n-1 1\n", "1\n-2 1\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]} | 278 | 106 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:
lower[i] = arr[i] - ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,10,6,4,8,12]) == [3,7,11]\n assert candidate(nums = [1,1,3,3]) == [2,2]\n assert candidate(nums = [5,435]) == [220]\n\n\ncheck(Solution().recoverArray)"} | 238 | 89 |
coding | Solve the programming task below in a Python markdown code block.
Write
```python
function repeating_fractions(numerator, denominator)
```
that given two numbers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part has repeated digits, replace those digi... | {"functional": "_inputs = [[0, 1], [18018018, 80000000000], [1, 1], [1, 2], [1, 3], [1554, 70]]\n_outputs = [['0.0'], ['0.(0)(2)5(2)5(2)5'], ['1.0'], ['0.5'], ['0.(3)'], ['22.2']]\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... | 171 | 252 |
coding | Solve the programming task below in a Python markdown code block.
For "x", determine how many positive integers less than or equal to "x" are odd but not prime. Assume "x" is an integer between 1 and 10000.
Example: 5 has three odd numbers (1,3,5) and only the number 1 is not prime, so the answer is 1
Example: 10 has... | {"functional": "_inputs = [[5], [10], [99]]\n_outputs = [[1], [2], [26]]\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 ... | 146 | 171 |
coding | Solve the programming task below in a Python markdown code block.
Some time ago, Chef bought X stocks at the cost of Rs. Y each. Today, Chef is going to sell all these X stocks at Rs. Z each. What is Chef's total profit after he sells them?
Chef's profit equals the total amount he received by selling the stocks, minus... | {"inputs": ["3\n2 5 20\n3 1 2\n4 5 6"], "outputs": ["30\n3\n4\n"]} | 590 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-... | {"inputs": ["5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n", "5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1010000000\n1\n1\n", "5\n10\n0011111111\n4\n0101\n8\n11001101\n10\n1010000000\n1\n1\n", "5\n10\n0001111110\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n", "5\n10\n0001111110\n4\n0101\n8\n11001101... | 728 | 624 |
coding | Solve the programming task below in a Python markdown code block.
problem
JOI took six subjects: physics, chemistry, biology, earth science, history, and geography. Each test was scored on a 100-point scale.
JOI chooses 3 subjects from 4 subjects of physics, chemistry, biology, and earth science, and 1 subject from 2... | {"inputs": ["100\n0\n3\n2\n0\n-4", "100\n4\n41\n96\n1\n0", "100\n4\n68\n96\n1\n0", "100\n0\n55\n30\n0\n0", "100\n0\n55\n41\n0\n0", "100\n0\n34\n41\n0\n0", "100\n2\n50\n41\n0\n0", "100\n2\n50\n4\n-1\n0"], "outputs": ["105\n", "238\n", "265\n", "185\n", "196\n", "175\n", "191\n", "154\n"]} | 614 | 189 |
coding | Solve the programming task below in a Python markdown code block.
Decompose a number `num` into an array (tuple in Haskell, array of arrays `long[][]` in C# or Java) of the form `[[k1,k2,k3...], r]`, `([k1,k2,k3...], r)` in Haskell, `[[k1,k2,k3...], [r]]` in C# or Java) such that:
1. each kn is more than one
2. eack ... | {"functional": "_inputs = [[0], [4], [9], [25], [8330475], [9819938], [8331299], [8328441]]\n_outputs = [[[[], 0]], [[[2], 0]], [[[3], 1]], [[[4, 2], 0]], [[[22, 13, 10, 8, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 0]], [[[23, 12, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 0]]... | 555 | 555 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads an integer and prints sum of its digits.
Input
The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.
The input ends with a line includi... | {"inputs": ["123\n1\n1001\n0", "123\n4\n1100\n0", "123\n1\n1101\n0", "123\n1\n1000\n0", "123\n0\n1000\n0", "123\n2\n1101\n0", "123\n4\n1101\n0", "123\n3\n1101\n0"], "outputs": ["6\n1\n2\n", "6\n4\n2\n", "6\n1\n3\n", "6\n1\n1\n", "6\n", "6\n2\n3\n", "6\n4\n3\n", "6\n3\n3\n"]} | 124 | 178 |
coding | Solve the programming task below in a Python markdown code block.
Your task is very simple. Given an input string s, case\_sensitive(s), check whether all letters are lowercase or not. Return True/False and a list of all the entries that are not lowercase in order of their appearance in s.
For example, case\_sensitive... | {"functional": "_inputs = [['asd'], ['cellS'], ['z'], ['']]\n_outputs = [[[True, []]], [[False, ['S']]], [[True, []]], [[True, []]]]\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,... | 150 | 182 |
coding | Solve the programming task below in a Python markdown code block.
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond i... | {"inputs": ["W\n", "Q\n", "A\n", "W\n", "Q\n", "A\n", "V\n", "R\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 290 | 70 |
coding | Solve the programming task below in a Python markdown code block.
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the cur... | {"inputs": ["5 2 3\n", "8 2 4\n", "1 2 3\n", "1 3 4\n", "1 1 1\n", "1 2 5\n", "1 3 8\n", "1 3 5\n"], "outputs": ["20 15\n", "35 32\n", "0 3\n", "0 4\n", "0 1\n", "0 5\n", "0 8\n", "0 5\n"]} | 410 | 122 |
coding | Solve the programming task below in a Python markdown code block.
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Input
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is ... | {"inputs": ["2 1\n1 2 1\n", "3 1\n1 2 1\n", "2 1\n1 2 0\n", "2 1\n1 1 1\n", "3 1\n2 2 1\n", "3 3\n1 2 1\n1 3 2\n2 3 1\n", "3 3\n1 2 1\n1 3 2\n2 3 0\n", "3 3\n1 2 1\n1 3 2\n1 3 1\n"], "outputs": ["1 2\n", "-1\n", "1 2\n", "-1\n", "-1\n", "1 3\n", "1 2 3\n", "1 3\n"]} | 299 | 182 |
coding | Solve the programming task below in a Python markdown code block.
**This Kata is intended as a small challenge for my students**
Create a function, called ``removeVowels`` (or ``remove_vowels``), that takes a string argument and returns that same string with all vowels removed (vowels are "a", "e", "i", "o", "u").
Als... | {"functional": "_inputs = [['drake'], ['scholarstem'], ['codewars'], ['high fives!'], [''], ['i'], ['b']]\n_outputs = [['drk'], ['schlrstm'], ['cdwrs'], ['hgh fvs!'], [''], [''], ['b']]\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, r... | 103 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s.
Note... | {"inputs": ["3\n3\n6\n8"], "outputs": ["2\n5\n8"]} | 272 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Taro's Shopping
Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to ... | {"inputs": ["3 45\n20 20 30\n6 10\n1 2 5 8 4 11\n7 000\n11 34 8 47 59 29 70\n4 100\n80 70 62 50\n4 8\n0 5 10 16\n0 0", "3 45\n0 20 30\n6 10\n2 2 5 8 1 11\n7 100\n22 34 33 94 59 29 70\n4 100\n8 70 80 18\n4 20\n10 5 10 16\n0 0", "3 45\n2 20 30\n6 10\n1 2 5 8 4 11\n7 100\n11 34 83 47 59 29 70\n4 100\n80 70 62 50\n4 20\n1 ... | 649 | 903 |
coding | Solve the programming task below in a Python markdown code block.
In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of $n$ students doing yet another trick.
Let's assume that all these students are numbered from $1$ to $n$. ... | {"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n2 1\n", "3\n2 3 2\n", "3\n1 2 3\n", "3\n2 3 1\n", "3\n2 3 1\n"], "outputs": ["1 \n", "1\n", "1 2 \n", "1 2\n", "2 2 3 \n", "1 2 3 \n", "1 2 3 \n", "1 2 3\n"]} | 603 | 131 |
coding | Solve the programming task below in a Python markdown code block.
Create a program that calculates and outputs the surface distance by inputting the north latitude and east longitude of two cities on the earth. However, the earth is a sphere with a radius of 6,378.1 km, and the surface distance between two points is th... | {"inputs": ["35.68 139.77 51.15 359.82\n1.37 103.92 41.78 272.25\n51.15 359.82 -34.58 301.52\n-1 -1 -1 -1", "35.68 139.77 51.15 360.3067312023825\n1.37 103.92 41.78 272.25\n51.15 359.82 -34.58 301.52\n-1 -1 -1 -1", "35.68 139.77 51.15 359.82\n1.37 103.92 41.78 272.25\n51.15 359.82 -34.03920544232073 301.52\n-1 -1 -1 -1... | 513 | 973 |
coding | Solve the programming task below in a Python markdown code block.
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages... | {"inputs": ["1\n0\n", "2\n1\n0\n", "2\n1\n2\n", "2\n0\n1\n", "2\n1\n1\n", "2\n0\n0\n", "2\n0\n2\n", "2\n2\n0\n"], "outputs": ["Exemplary pages.\n", "Unrecoverable configuration.\n", "Unrecoverable configuration.\n", "Unrecoverable configuration.\n", "Exemplary pages.\n", "Exemplary pages.\n", "1 ml. from cup #1 to cup ... | 567 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to ... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "2\n1 1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "2\n"]} | 572 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.
```python
move_zeros([False,1,0,1,2,0,1,3,"a"]) # returns[False,1,1,2,1,3,"a",0,0]
```
Also feel free to reuse/extend the following... | {"functional": "_inputs = [[[1, 2, 0, 1, 0, 1, 0, 3, 0, 1]], [[9, 0.0, 0, 9, 1, 2, 0, 1, 0, 1, 0.0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [['a', 0, 0, 'b', 'c', 'd', 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [['a', 0, 0, 'b', None, 'c', 'd', 0, 1, False, 0, 1, 0, 3, [], 0, 1, 9, 0, 0, {}, 0, 0, 9]], [[0, 1, None, 2, False, 1,... | 106 | 662 |
coding | Solve the programming task below in a Python markdown code block.
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch.
There are n m... | {"inputs": ["2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4"], "outputs": ["1\n2"]} | 409 | 42 |
coding | Solve the programming task below in a Python markdown code block.
My friend John likes to go to the cinema. He can choose between system A and system B.
```
System A : he buys a ticket (15 dollars) every time
System B : he buys a card (500 dollars) and a first ticket for 0.90 times the ticket price,
then for each addi... | {"functional": "_inputs = [[500, 15, 0.9], [100, 10, 0.95], [0, 10, 0.95], [250, 20, 0.9], [500, 20, 0.9], [2500, 20, 0.9]]\n_outputs = [[43], [24], [2], [21], [34], [135]]\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, a... | 443 | 256 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.
The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)
Assuming that nothing other than the interest affects Takahashi'... | {"inputs": ["121", "888", "435", "684", "394", "124", "143", "110"], "outputs": ["21\n", "271\n", "193\n", "243\n", "182\n", "24\n", "43\n", "10\n"]} | 238 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A happy string is a string that:
consists only of letters of the set ['a', 'b', 'c'].
s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).
For example, strings "abc", "ac", "b" and "abc... | {"functional": "def check(candidate):\n assert candidate(n = 1, k = 3) == \"c\"\n assert candidate(n = 1, k = 4) == \"\"\n assert candidate(n = 3, k = 9) == \"cab\"\n assert candidate(n = 2, k = 7) == \"\"\n assert candidate(n = 10, k = 100) == \"abacbabacb\"\n\n\ncheck(Solution().getHappyString)"} | 204 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible... | {"inputs": ["6 2\n4 6 3 2 5 1"], "outputs": ["1 2 3 4 5 6"]} | 436 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that
* s(a) ≥ n,
* s(b) ≥ n,
* s(a + b) ≤ m.
Input
The only line of input contain two integers n ... | {"inputs": ["4 1\n", "1 1\n", "9 1\n", "4 3\n", "3 1\n", "2 1\n", "7 1\n", "4 2\n"], "outputs": ["1111\n8889", "1\n9", "111111111\n888888889", "1111\n8889", "111\n889", "11\n89", "1111111\n8888889", "1111\n8889"]} | 244 | 146 |
coding | Solve the programming task below in a Python markdown code block.
I'm sure you're familiar with factorials – that is, the product of an integer and all the integers below it.
For example, `5! = 120`, as `5 * 4 * 3 * 2 * 1 = 120`
Your challenge is to create a function that takes any number and returns the number that... | {"functional": "_inputs = [[120], [3628800], [150]]\n_outputs = [['5!'], ['10!'], ['None']]\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): r... | 204 | 180 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A of length N.
Determine the count of subarrays of A which contain their length as an element.
Formally, count the number of pairs (L, R) (1≤ L≤ R≤ N) such that: (R-L+1) \in \{A_{L}, A_{L+1}, \ldots, A_{R}\}.
------ Input Format... | {"inputs": ["3\n3\n1 2 1\n5\n2 3 1 3 5\n10\n10 7 4 4 2 9 2 1 9 3\n"], "outputs": ["4\n6\n15\n"]} | 430 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Problem
There are $ N $ streetlights on a two-dimensional square of $ W \ times H $.
Gaccho wants to start with $ (1,1) $ and go to $ (W, H) $.
Gaccho is afraid of dark places, so he only wants to walk in the squares that are brightened by the streetlig... | {"inputs": ["8 6 1\n6 5", "8 6 1\n6 8", "1 1 1\n1 1", "8 10 1\n6 6", "24 4 1\n6 2", "8 10 1\n6 8", "10 3 1\n6 2", "8 10 1\n6 5"], "outputs": ["9\n", "12\n", "0", "10\n", "20\n", "12\n", "6\n", "9\n"]} | 571 | 134 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string $s$.
Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring.
The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a... | {"inputs": ["2\n0\n", "1\n1\n", "5\n1\n", "1\n0\n", "5\n1\n", "1\n0\n", "1\n1\n", "2\n0\n"], "outputs": ["3", "1", "31", "1", "31\n", "1\n", "1\n", "3\n"]} | 415 | 84 |
coding | Solve the programming task below in a Python markdown code block.
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word... | {"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "2 0\n1 3\n", "2 1\n1 100\n", "2 1\n1 100\n", "2 1\n2 100\n", "2 0\n1 100\n"], "outputs": ["2", "2\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]} | 566 | 124 |
coding | Solve the programming task below in a Python markdown code block.
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record a... | {"inputs": ["L\n", "R\n", "RR\n", "DL\n", "LD\n", "UL\n", "DDR\n", "ULD\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "BUG\n"]} | 463 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length a_{i}.
Mishka can put a box i into another box j if the following conditions are met:
i-th box is not put into another box; j-th box doesn't contain any other... | {"inputs": ["1\n1\n", "1\n9\n", "1\n5\n", "1\n2\n", "1\n2\n", "1\n1\n", "1\n5\n", "1\n9\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 334 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose ... | {"inputs": ["6\n4\n1024 512 8 512\n1\n2048\n3\n32 512 2\n2\n4096 1\n1\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n", "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n", "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n1\n2048 2 2048 2048 2048 2048 20... | 720 | 877 |
coding | Solve the programming task below in a Python markdown code block.
Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem:
Given an array A of non-negative integers, how many pairs of indices i and... | {"inputs": ["2\n3\n3 4 5\n4\n1 1 1 1", "2\n3\n3 8 5\n4\n1 1 1 1", "2\n3\n1 4 5\n4\n1 1 1 1", "2\n3\n1 3 0\n4\n1 1 2 1", "2\n3\n2 5 2\n4\n1 0 1 1", "2\n3\n1 1 3\n4\n0 2 6 1", "2\n3\n6 4 5\n4\n1 1 1 1", "2\n3\n3 8 5\n4\n1 1 0 1"], "outputs": ["3\n0", "3\n0\n", "1\n0\n", "0\n0\n", "2\n0\n", "0\n1\n", "3\n0\n", "3\n0\n"]} | 322 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.
Help Kurt find the maximum possible product of digits among all integers from $1$ to $n$.
-----Input-----... | {"inputs": ["7\n", "1\n", "9\n", "2\n", "3\n", "4\n", "1\n", "9\n"], "outputs": ["7\n", "1\n", "9\n", "2\n", "3\n", "4\n", "1", "9"]} | 267 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at th... | {"functional": "def check(candidate):\n assert candidate(logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5) == [0,2,0,0,0]\n assert candidate(logs = [[1,1],[2,2],[2,3]], k = 4) == [1,1,0,0]\n\n\ncheck(Solution().findingUsersActiveMinutes)"} | 231 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Chef is given two integers N, S.
Consider an array A of size N such that A[i]=i for every 1 ≤ i ≤ N.
You are required to find any position x(1≤ x ≤ N) such that :
(A[1]+A[2]+...A[x-1]) + (A[x+1]+A[x+2]+...A[N]) = S
If there are multiple such position... | {"inputs": ["3\n4 8\n5 10\n2 3\n"], "outputs": ["2\n5\n-1\n"]} | 313 | 32 |
coding | Solve the programming task below in a Python markdown code block.
The Chef has been hunting for a machine developed to change numbers in a rather peculiar manner. This machine has a fixed number c associated with it and a changing number X.
In a single step, the Chef can do the following:
First, choose any positive i... | {"inputs": ["3\n1 5\n10 1\n20 4"], "outputs": ["1\n1\n20"]} | 442 | 31 |
coding | Solve the programming task below in a Python markdown code block.
# Feynman's squares
Richard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing.
Recently, an old farmer found some papers and ... | {"functional": "_inputs = [[1], [2], [3], [5], [8], [15]]\n_outputs = [[1], [5], [14], [55], [204], [1240]]\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... | 273 | 193 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers $n$, $l$, and $r$. You need to construct an array $a_1,a_2,\dots,a_n$ ($l\le a_i\le r$) such that $\gcd(i,a_i)$ are all distinct or report there's no solution.
Here $\gcd(x, y)$ denotes the greatest common divisor (GCD) of i... | {"inputs": ["1\n100000 1 99999\n", "1\n100000 50021 100000\n", "4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000\n"], "outputs": ["NO\n", "NO\n", "YES\n1 2 3 4 5\nYES\n1000 1000 1002 1000 1000 1002 1001 1000 1008\nNO\nYES\n1000000000\n"]} | 494 | 188 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. fruits is already sorted b... | {"functional": "def check(candidate):\n assert candidate(fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4) == 9\n assert candidate(fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4) == 14\n assert candidate(fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2) == 0\n\n\ncheck(Solution().maxTot... | 216 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Problem
Taro decided to watch one movie every day at a nearby movie theater during the summer vacation. (Taro has 31 days of summer vacation from August 1st to August 31st.)
The theater is set to show n movies during the summer vacation. Each movie is ... | {"inputs": ["4\n1 31\n2 4\n2 3\n3 3", "4\n1 31\n2 2\n2 1\n3 3", "4\n1 31\n2 2\n2 3\n3 5", "4\n1 31\n2 4\n2 3\n1 3", "4\n1 31\n2 2\n2 3\n4 5", "4\n1 31\n2 2\n2 0\n3 3", "4\n1 31\n2 8\n2 3\n1 3", "4\n1 31\n2 8\n2 3\n1 1"], "outputs": ["1750\n", "1700\n", "1750\n", "1750\n", "1750\n", "1700\n", "1750\n", "1750\n"]} | 377 | 222 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from... | {"functional": "def check(candidate):\n assert candidate(arr = [1,-2,0,3]) == 4\n assert candidate(arr = [1,-2,-2,3]) == 3\n assert candidate(arr = [-1,-1,-1,-1]) == -1\n\n\ncheck(Solution().maximumSum)"} | 133 | 73 |
coding | Solve the programming task below in a Python markdown code block.
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with ... | {"inputs": ["bbbbbb\nbb\n", "aaaaa\naaa\n", "bbbbbb\nbb\n", "aaaaa\naaa\n", "bbbbbb\nbc\n", "aabaa\naaa\n", "bbbbba\nbc\n", "aabaa\naab\n"], "outputs": ["3", "1", "3", "1", "0\n", "0\n", "0\n", "1\n"]} | 469 | 90 |
coding | Solve the programming task below in a Python markdown code block.
There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.
Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i an... | {"inputs": ["3\n2 0 4", "3\n2 0 6", "3\n2 0 0", "3\n0 0 6", "3\n2 1 5", "3\n2 2 4", "3\n2 2 4\n", "5\n3 8 1 5 5"], "outputs": ["6 -2 2\n", "8 -4 4\n", "2 2 -2\n", "6 -6 6\n", "6 -2 4\n", "4 0 4", "4 0 4\n", "-4 10 6 -4 14\n"]} | 493 | 152 |
coding | Solve the programming task below in a Python markdown code block.
Chang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to demonstrat... | {"inputs": ["4 4"], "outputs": ["1"]} | 284 | 14 |
coding | Solve the programming task below in a Python markdown code block.
As we know, Danny has a huge army and each time she wins a battle the size of her army is increased. Missandei, her advisor and Handmaiden, keeps the log of each battle and the amount and strength of soldiers won in a battle.
Now, Danny has some questi... | {"inputs": ["5 3\n2 3 1 6 5\n1 2 3 4 5\n2 3\n1 1\n1 5"], "outputs": ["9\n2\n60"]} | 481 | 51 |
coding | Solve the programming task below in a Python markdown code block.
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him.
You are given a tree with $N$ vertices nu... | {"inputs": ["2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7"], "outputs": ["YES\n1 2 3 4\nNO"]} | 593 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.
Pasha didn't like his present ver... | {"inputs": ["abcdef\n1\n2\n", "abcdef\n1\n1\n", "abdcef\n1\n2\n", "abcdef\n1\n2\n", "vwxyz\n2\n2 2\n", "vwwyz\n2\n2 2\n", "vwwyz\n2\n2 1\n", "vwxyz\n2\n2 2\n"], "outputs": ["aedcbf\n", "fedcba\n", "aecdbf\n", "aedcbf\n", "vwxyz\n", "vwwyz\n", "zwwyv\n", "vwxyz\n"]} | 365 | 131 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We are given an array asteroids of integers representing asteroids in a row.
For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning l... | {"functional": "def check(candidate):\n assert candidate(asteroids = [5,10,-5]) == [5,10]\n assert candidate(asteroids = [8,-8]) == []\n assert candidate(asteroids = [10,2,-5]) == [10]\n\n\ncheck(Solution().asteroidCollision)"} | 141 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is consider... | {"inputs": ["000000\n", "123456\n", "111000\n", "120111\n", "999999\n", "199880\n", "899889\n", "899888\n"], "outputs": ["0\n", "2\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n"]} | 276 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A string is good if there are no repeated characters.
Given a string s, return the number of good substrings of length three in s.
Note that if there are multiple occurrences of the same substring, every oc... | {"functional": "def check(candidate):\n assert candidate(s = \"xyzzaz\") == 1\n assert candidate(s = \"aababcabc\") == 4\n\n\ncheck(Solution().countGoodSubstrings)"} | 114 | 49 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string expression representing a Lisp-like expression to return the integer value of.
The syntax for these expressions is given as follows.
An expression is either an integer, let expression, add expr... | {"functional": "def check(candidate):\n assert candidate(expression = \"(let x 2 (mult x (let x 3 y 4 (add x y))))\") == 14\n assert candidate(expression = \"(let x 3 x 2 x)\") == 2\n assert candidate(expression = \"(let x 1 y 2 x (add x y) (add x y))\") == 5\n\n\ncheck(Solution().evaluate)"} | 445 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Zombies have placed themselves at every junction in Bucharest. Each junction 'i' initially has a presence of ai number of zombies. Every timestep, each zombie randomly chooses one of its neighboring junctions and walks towards it. Each neighboring juncti... | {"inputs": ["1\n10 18 100\n0 8\n0 5\n1 2\n1 5\n2 8\n2 4\n2 5\n2 6\n3 5\n4 8\n4 6\n4 7\n5 8\n5 9\n6 8\n6 9\n7 9\n8 9\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"], "outputs": ["2 2 1 1 1\n"]} | 451 | 124 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.
A query word queries[i] matches pattern if you can inse... | {"functional": "def check(candidate):\n assert candidate(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FB\") == [True,False,True,True,False]\n assert candidate(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FoBa... | 126 | 142 |
coding | Solve the programming task below in a Python markdown code block.
You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.
Write the program which finds the number of points in the intersection of two given set... | {"inputs": ["2 2 1\n1 2 0\n", "1 0 0\n0 1 0\n", "1 1 0\n2 2 1\n", "1 1 2\n0 1 0\n", "0 0 0\n0 0 1\n", "0 1 0\n1 0 1\n", "1 0 1\n0 0 1\n", "4 6 1\n2 3 1\n"], "outputs": ["1", "1", "0", "1", "0", "1", "0", "0"]} | 202 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:
the upper half of matrix c (rows with numbers from 1 to x)... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 2\n0 1\n", "1 2\n0 1\n", "1 2\n1 1\n", "1 2\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 457 | 110 |
coding | Solve the programming task below in a Python markdown code block.
problem
JOI, who has been suffering from his winter vacation homework every time, decided to do his homework systematically this time. Homework is a national language and math drill, with a national language drill on page A and a math drill on page B.
... | {"inputs": ["20\n2\n6\n3\n1", "20\n4\n0\n6\n1", "20\n8\n9\n7\n1", "20\n4\n6\n3\n1", "20\n4\n6\n6\n1", "20\n1\n4\n6\n6", "20\n4\n0\n6\n2", "20\n1\n4\n6\n2"], "outputs": ["14\n", "19\n", "11\n", "14\n", "14\n", "19\n", "19\n", "18\n"]} | 386 | 142 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers $a$, $b$, and $c$. Determine if one of them is the sum of the other two.
-----Input-----
The first line contains a single integer $t$ ($1 \leq t \leq 9261$) — the number of test cases.
The description of each test case co... | {"inputs": ["1\n14 5 14\n", "1\n19 18 16\n", "7\n1 4 3\n2 5 8\n9 11 20\n0 0 0\n20 20 20\n4 12 3\n15 7 8\n", "12\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "19\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10\n19 8 10... | 307 | 791 |
coding | Solve the programming task below in a Python markdown code block.
Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".
Maxim was very boring to sit in class, so the teacher came up with a task for him: o... | {"inputs": ["4\nZCTH\n", "4\nNPGT\n", "4\nAZTG\n", "4\nYCTG\n", "4\nANTG\n", "4\nOCTG\n", "4\nACHG\n", "4\nANTG\n"], "outputs": ["2", "52", "3", "2", "11", "12", "12", "11\n"]} | 536 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya encountered a tree w... | {"inputs": ["2\n1 2 7\n", "2\n1 2 3\n", "2\n1 2 10\n", "2\n2 1 1000000000\n", "2\n2 1 1010000000\n", "2\n2 1 1000000001\n", "4\n1 2 4\n3 1 2\n1 4 7\n", "4\n1 2 4\n1 3 47\n1 4 7447\n"], "outputs": ["0", "0", "0", "0", "0", "0", "16", "24"]} | 638 | 168 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of unique palindromes of length three that are a subsequence of s.
Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.
A palindr... | {"functional": "def check(candidate):\n assert candidate(s = \"aabca\") == 3\n assert candidate(s = \"adc\") == 0\n assert candidate(s = \"bbcbaba\") == 4\n\n\ncheck(Solution().countPalindromicSubsequence)"} | 161 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime ... | {"inputs": ["10\n3\n5", "10\n3\n9", "10\n3\n2", "10\n6\n2", "10\n1\n5", "10\n1\n2", "10\n2\n2", "10\n3\n4"], "outputs": ["4\n2\n3\n", "4\n2\n4\n", "4\n2\n1\n", "4\n3\n1\n", "4\n0\n3\n", "4\n0\n1\n", "4\n1\n1\n", "4\n2\n2\n"]} | 159 | 134 |
coding | Solve the programming task below in a Python markdown code block.
For a square matrix of integers of size $n \times n$, let's define its beauty as follows: for each pair of side-adjacent elements $x$ and $y$, write out the number $|x-y|$, and then find the number of different numbers among them.
For example, for the m... | {"inputs": ["2\n2\n3\n"], "outputs": ["4 1\n2 3\n9 1 8\n3 7 2\n6 4 5\n"]} | 401 | 42 |
coding | Solve the programming task below in a Python markdown code block.
There is an array of $n$ integers. There are also $2$ disjoint sets, $\mbox{A}$ and $\mbox{B}$, each containing $m$ integers. You like all the integers in set $\mbox{A}$ and dislike all the integers in set $\mbox{B}$. Your initial happiness is $\mbox{o}$... | {"inputs": ["3 2\n1 5 3\n3 1\n5 7\n"], "outputs": ["1\n"]} | 446 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals, not just the two that bise... | {"functional": "def check(candidate):\n assert candidate(4) == [[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\n\n\ncheck(Solution().solveNQueens)"} | 125 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A of length N containing the elements -1 and 1 only. Determine if it is possible to rearrange the array A in such a way that A_{i} is not the geometric mean of A_{i-1} and A_{i+1}, for all i such that 2 ≤ i ≤ N-1.
Y is said to be ... | {"inputs": ["3\n5\n1 1 1 -1 -1\n3\n1 1 1\n6\n1 -1 -1 -1 -1 1\n"], "outputs": ["Yes\nNo\nYes\n"]} | 478 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all blac... | {"inputs": ["1 1\nW\n", "1 1\nW\n", "1 1\nB\n", "1 1\nB\n", "1 1\nW\n", "1 2\nBB\n", "1 2\nWW\n", "1 2\nWB\n"], "outputs": ["1\n", "1\n", "0\n", "0", "1", "-1\n", "1\n", "0\n"]} | 436 | 100 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:
- Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, ... | {"inputs": ["3\n3", "3\n4", "3\n2", "3\n8", "3\n6", "1\n1\n", "6\n1\n", "3\n74"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "1\n", "6\n", "3\n"]} | 576 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Introduction
Mr. Safety loves numeric locks and his Nokia 3310. He locked almost everything in his house. He is so smart and he doesn't need to remember the combinations. He has an algorithm to generate new passcodes on his Nokia cell phone.
Task
... | {"functional": "_inputs = [['Nokia'], ['Valut'], ['toilet'], ['waterheater'], ['birdhouse']]\n_outputs = [['66542'], ['82588'], ['864538'], ['92837432837'], ['247346873']]\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... | 226 | 215 |
coding | Solve the programming task below in a Python markdown code block.
It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. ... | {"inputs": ["5 1\n3 5\n", "6 1\n6 2\n", "4 1\n4 2\n", "7 1\n4 7\n", "9 1\n6 2\n", "9 1\n4 7\n", "9 1\n4 2\n", "9 1\n1 2\n"], "outputs": ["i\n", "i\n", "i\n", "i\n", "i", "i", "i", "i"]} | 369 | 114 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.