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.
Read problems statements in Mandarin Chinese and Russian.
Chef wants to split a team of new chef into two teams to play a game. In order to make the split, he first designates two team captains who take alternate turns selecting players for their teams... | {"inputs": ["4\n1 1 1 1 1\n2 1 1 1 1\n3 1 2 3 4\n4 2 3 4 1"], "outputs": ["1\n2\n763\n74896"]} | coding | 582 |
Solve the programming task below in a Python markdown code block.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many sup... | {"inputs": ["1 1\n0\n", "1 1\n0\n", "2 1\n0 0\n", "2 1\n0 1\n", "2 1\n1 0\n", "2 1\n1 1\n", "2 2\n0 0\n", "2 2\n0 1\n"], "outputs": ["0\n", "0", "1\n", "0\n", "2\n", "1\n", "1\n", "2\n"]} | coding | 413 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] represents the strength of the jth potion.
You are ... | {"functional": "def check(candidate):\n assert candidate(spells = [5,1,3], potions = [1,2,3,4,5], success = 7) == [4,0,3]\n assert candidate(spells = [3,1,2], potions = [8,5,8], success = 16) == [2,0,2]\n\n\ncheck(Solution().successfulPairs)"} | coding | 155 |
Solve the programming task below in a Python markdown code block.
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
-----Input-----
The first line of input contains T - number of test cases.
Each of the n... | {"inputs": ["3\n1 2 0 3\n1 2 4 -1\n1 2 3 4"], "outputs": ["Yes\nYes\nNo"]} | coding | 237 |
Solve the programming task below in a Python markdown code block.
Rani and Nandu decide to play a number game. Both play alternately, Rani playing the first move.
In each of their moves, they can subtract a maximum of k and a minimum of 1 from n i.e. each of them must subtract from n, any natural number less than or... | {"inputs": ["151\n329 257\n705 487\n768 697\n217 104\n969 371\n430 316\n588 276\n609 496\n9 5\n290 222\n333 100\n741 626\n817 489\n235 7\n623 179\n490 253\n623 456\n841 344\n861 786\n984 656\n441 46\n734 237\n501 249\n609 19\n745 41\n905 459\n542 66\n689 39\n830 758\n781 521\n468 283\n197 26\n828 14\n714 621\n81 81\n89... | coding | 453 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of integers $a_1, a_2, ..., a_N$. An element ak is said to be an average element if there are indices $i, j$ (with $i \neq j$) such that $a_k = \frac{a_i + a_j}{2}$.
In the sequence
371022171537102217153 \quad 7 \quad 10 \quad 2... | {"inputs": ["5\n3\n7\n10\n3\n18", "5\n3\n8\n11\n17\n30", "6\n3\n7\n10\n17\n22\n15"], "outputs": ["2", "0", "1"]} | coding | 688 |
Solve the programming task below in a Python markdown code block.
Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms.
One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families consisting... | {"inputs": ["5\n1 2 3 6 5 4 4 2 5 3 6 1 6 5 3 2 4 1 2 5 1 4 3 6 8 4 3 1 5 6 2 \n"], "outputs": ["8\n"]} | coding | 419 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.
Please complete the following python code precisely:
```python
class Solution:
def coun... | {"functional": "def check(candidate):\n assert candidate(words1 = [\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"], words2 = [\"amazing\",\"leetcode\",\"is\"]) == 2\n assert candidate(words1 = [\"b\",\"bb\",\"bbb\"], words2 = [\"a\",\"aa\",\"aaa\"]) == 0\n assert candidate(words1 = [\"a\",\"ab\"], words2 = [\"a... | coding | 82 |
Solve the programming task below in a Python markdown code block.
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Eac... | {"inputs": ["1\n1\n", "1\n2\n", "3\n1\n2\n4\n", "3\n1\n3\n4\n", "3\n1\n3\n5\n", "3\n1\n6\n5\n", "3\n1\n6\n9\n", "3\n1\n11\n9\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | coding | 257 |
Solve the programming task below in a Python markdown code block.
Given the schedule of Chef for 30 days (A binary string of length 30 where '0' denotes that Chef was on leave and '1' denotes Chef was working on that day). Chef gets X- Rs for every day he worked. As working continuously for a long time is hectic so Com... | {"inputs": ["3\n6 3\n111100110101100000101100011111\n8 2\n111010111101001010100100111101\n5 6\n011101010100101000001101000010"], "outputs": ["117\n152\n78"]} | coding | 624 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi],[Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
One day, Saeed was teaching a string compression algorithm. This algorithm finds all maximal substrings which contains only one character repeated one... | {"inputs": ["3\nbbbbbbbbbbaa\nc\naaaaaaaaaabcdefgh"], "outputs": ["YES\nNO\nNO"]} | coding | 498 |
Solve the programming task below in a Python markdown code block.
Berland year consists of $m$ months with $d$ days each. Months are numbered from $1$ to $m$. Berland week consists of $w$ days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than $w$ day... | {"inputs": ["5\n6 5 2\n8 2 12\n2 30 6\n4 2 1\n2663549 214779 659567\n", "5\n6 5 2\n8 2 12\n12 30 6\n4 2 1\n2663549 214779 659567\n", "5\n6 7 4\n8 9 3\n12 11 3\n0 1 1\n7341628 25065973 296620\n", "5\n6 7 4\n8 9 3\n12 11 3\n0 1 1\n7341628 21556586 296620\n", "5\n6 5 2\n8 2 12\n0 30 6\n2 2 1\n2663549 10298779 625324\n", "... | coding | 385 |
Solve the programming task below in a Python markdown code block.
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems.
The boy h... | {"inputs": ["1\n1 2\n88\n", "1\n1 2\n88\n", "1\n1 3\n88\n", "1\n1 2\n70\n", "1\n1 5\n88\n", "1\n1 3\n103\n", "1\n1 3\n198\n", "1\n1 1\n103\n"], "outputs": ["140130951\n", "140130951\n", "772681989\n", "270016253\n", "467137716\n", "923126036\n", "792924246\n", "1\n"]} | coding | 613 |
Solve the programming task below in a Python markdown code block.
You are given a tree with N nodes with every node being colored. A color is represented by an integer ranging from 1 to 10^{9}. Can you find the number of distinct colors available in a subtree rooted at the node s?
Input Format
The first line contai... | {"inputs": ["4 2 1\n1 2\n2 4\n2 3\n10\n20\n20\n30\n1\n2\n"], "outputs": ["3\n2\n"]} | coding | 372 |
Solve the programming task below in a Python markdown code block.
Rick wants a faster way to get the product of the largest pair in an array. Your task is to create a performant solution to find the product of the largest two integers in a unique array of positive numbers. All inputs will be valid.
Passing [2, 6, 3] sh... | {"functional": "_inputs = [[[56, 335, 195, 443, 6, 494, 252]], [[154, 428, 455, 346]], [[39, 135, 47, 275, 37, 108, 265, 457, 2, 133, 316, 330, 153, 253, 321, 411]], [[136, 376, 10, 146, 105, 63, 234]], [[354, 463, 165, 62, 472, 53, 347, 293, 252, 378, 420, 398, 255, 89]], [[346, 446, 26, 425, 432, 349, 123, 269, 285, ... | coding | 229 |
Solve the programming task below in a Python markdown code block.
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of... | {"inputs": ["1 1 1\n1\n", "1 2 1\n1\n", "1 2 1\n1\n", "1 1 1\n1\n", "1 2 1\n2\n", "1 1 1\n2\n", "1 2 2\n2\n", "1 2 2\n4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 551 |
Solve the programming task below in a Python markdown code block.
The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than... | {"inputs": ["5 2 7 4\n0 1\n1 2\n0 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n0 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n1 2\n", "5 2 10 4\n0 1\n1 1\n1 4\n0 2\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 2\n", "5 2 10 4\n1 1\n1 1\n1 4\n0 1\n", "7 2 10 4\n1 1\n1 1\n1 4\n0 1\n", "7 3 17 4\n1 1\n1 1\n1 4\n0 1\n"], "outputs": ["4 1\n5 1\n4 1\n5 1\n", ... | coding | 699 |
Solve the programming task below in a Python markdown code block.
Accepts a string from the user and print the reverse string as the output without using any built-in function.
-----Input:-----
Each testcase contains of a single line of input, a string.
-----Output:-----
For each testcase, output in a single line ans... | {"inputs": ["1\nTracy"], "outputs": ["ycarT"]} | coding | 89 |
Solve the programming task below in a Python markdown code block.
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has ... | {"inputs": ["1 1 2\n3 1\n", "1 1 2\n3 1\n", "1 1 3\n3 1\n", "4 1 2\n2 1\n", "4 1 4\n2 1\n", "4 1 2\n10 1\n", "20 1 5\n8 4\n", "20 1 5\n8 4\n"], "outputs": ["5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "4\nHEAL\nSTRIKE\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE... | coding | 737 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.
Please complete the following py... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 987\n assert candidate(n = 1) == 9\n\n\ncheck(Solution().largestPalindrome)"} | coding | 91 |
Solve the programming task below in a Python markdown code block.
For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}.
Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.
Find the maximum possible value of M_1 + M_2 + \cdots + M_N.
-----Constraints-----
... | {"inputs": ["3", "4", "6", "0", "8", "9", "7", "2"], "outputs": ["3\n", "6\n", "15\n", "0\n", "28\n", "36\n", "21\n", "1"]} | coding | 217 |
Solve the programming task below in a Python markdown code block.
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. During the $k$... | {"inputs": ["1\n2\n", "1\n2\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n7\n", "2\n2 3\n", "2\n2 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]} | coding | 377 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'.
Return the lexicographically smallest string that starts at a leaf of this tree and ends at... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([0,1,2,3,4,3,4])) == \"dba\"\n assert candidate(root = tree_node([25,1,3,1,3,0,2])) == \"adz\"\n assert candidate(root = tree_node([2,2,1,None,1,0,None,0])) == \"abc\"\n\n\ncheck(Solution().smallestFromLeaf)"} | coding | 201 |
Solve the programming task below in a Python markdown code block.
Problem
Neat lives on the world line for a total of 360 days until the 30th of every month for 1 year and 12 months. In that world, N consecutive holidays with the same schedule were applied to people all over the world every year. Consecutive holidays ... | {"inputs": ["1\n1 1 1 1", "1\n1 2 1 1", "1\n1 1 359 1", "2\n4 3 5 0\n1 1 5 294", "2\n4 3 5 0\n1 1 5 262", "2\n3 4 5 7\n2 2 5 253", "2\n4 5 5 0\n4 7 1 457", "2\n4 3 5 0\n1 2 1 294"], "outputs": ["0\n", "0\n", "0", "116\n", "84\n", "75\n", "277\n", "114\n"]} | coding | 596 |
Solve the programming task below in a Python markdown code block.
Watson gives four 3-dimensional points to Sherlock and asks him if they all lie in the same plane. Your task here is to help Sherlock.
Input Format
First line contains T, the number of testcases.
Each test case consists of four lines. Each line c... | {"inputs": ["1\n1 2 0\n2 3 0\n4 0 0\n0 0 0\n"], "outputs": ["YES\n"]} | coding | 213 |
Solve the programming task below in a Python markdown code block.
Create a function xMasTree(height) that returns a christmas tree of the correct height. The height is passed through to the function and the function should return a list containing each line of the tree.
```
xMasTree(5) should return : ['____#____', '_... | {"functional": "_inputs = [[3], [7], [2], [4], [6]]\n_outputs = [[['__#__', '_###_', '#####', '__#__', '__#__']], [['______#______', '_____###_____', '____#####____', '___#######___', '__#########__', '_###########_', '#############', '______#______', '______#______']], [['_#_', '###', '_#_', '_#_']], [['___#___', '__#... | coding | 334 |
Solve the programming task below in a Python markdown code block.
In a country called Chef Land, there was a lot of monetary fraud, so Chefu, the head of the country, decided to choose new denominations of the local currency ― all even-valued coins up to an integer $N$ should exist. After a few days, a citizen complain... | {"inputs": ["4\n2 2\n1 14\n30 10\n31 4"], "outputs": ["1\n1\n3\n9"]} | coding | 439 |
Solve the programming task below in a Python markdown code block.
There was a test in your class and you passed it. Congratulations!
But you're an ambitious person. You want to know if you're better than the average student in your class.
You receive an array with your peers' test scores. Now calculate the average and... | {"functional": "_inputs = [[[2, 3], 5], [[100, 40, 34, 57, 29, 72, 57, 88], 75], [[12, 23, 34, 45, 56, 67, 78, 89, 90], 69]]\n_outputs = [[True], [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)... | coding | 195 |
Solve the programming task below in a Python markdown code block.
Chef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly $15$ players: $2$ goalkeepers, $5$ defenders, $5$ midfielders and $3$ forwards. Chef has already bought $13$ players; he is only missing one d... | {"inputs": ["2\n4 90\n3 8 6 5\n0 1 1 0\n4 90\n5 7 6 5\n0 1 1 0"], "outputs": ["yes\nno"]} | coding | 589 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, you start with an initial positive value startValue.
In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).
Return the minimum ... | {"functional": "def check(candidate):\n assert candidate(nums = [-3,2,-3,4,2]) == 5\n assert candidate(nums = [1,2]) == 1\n assert candidate(nums = [1,-2,-3]) == 5\n\n\ncheck(Solution().minStartValue)"} | coding | 116 |
Solve the programming task below in a Python markdown code block.
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you deci... | {"inputs": ["10000\n1225 3150\n5000 40\n0 0\n5000 1050\n5000 3980\n5000 210\n5000 443\n5000 5000\n0 0\n5075 2100\n5000 2494\n5000 2100\n29170\n100000 110000\n100000 100000\n100000 100100\n100000 101000\n100000 100000\n100000 101000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 000000\n100000 70831... | coding | 629 |
Solve the programming task below in a Python markdown code block.
There is a group of N friends who wish to enroll in a course together. The course has a maximum capacity of M students that can register for it. If there are K other students who have already enrolled in the course, determine if it will still be possible... | {"inputs": ["3\n2 50 27\n5 40 38\n100 100 0\n"], "outputs": ["Yes\nNo\nYes\n"]} | coding | 360 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are:
Players take turns placing characters into empty squares ' '.
The first player A always places 'X' characters, while the sec... | {"functional": "def check(candidate):\n assert candidate(moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]) == \"A\"\n assert candidate(moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]) == \"B\"\n assert candidate(moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]) == \"Draw\"\n assert candidate(moves = [[0... | coding | 290 |
Solve the programming task below in a Python markdown code block.
Polycarp has an integer $n$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times:
Reverse the prefix of length $l$ (in other words, $l$ leftmost digits) of $n$. So, the leftmost digit is swapp... | {"inputs": ["1\n99\n", "1\n21328\n", "1\n87454\n", "1\n77778\n", "1\n77774\n", "1\n841419\n", "1\n77771449\n", "4\n3876\n387\n4489\n3\n"], "outputs": ["-1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "2\n", "0\n2\n1\n-1\n"]} | coding | 676 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
A sentence can be shuffled by appending the 1-index... | {"functional": "def check(candidate):\n assert candidate(s = \"is2 sentence4 This1 a3\") == \"This is a sentence\"\n assert candidate(s = \"Myself2 Me1 I4 and3\") == \"Me Myself and I\"\n\n\ncheck(Solution().sortSentence)"} | coding | 160 |
Solve the programming task below in a Python markdown code block.
# Task
Mobius function - an important function in number theory. For each given n, it only has 3 values:
```
0 -- if n divisible by square of a prime. Such as: 4, 8, 9
1 -- if n not divisible by any square of a prime
and have even number of p... | {"functional": "_inputs = [[10], [9], [8], [100000000001], [7], [5]]\n_outputs = [[1], [0], [0], [0], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ... | coding | 191 |
Solve the programming task below in a Python markdown code block.
# Story
You and a group of friends are earning some extra money in the school holidays by re-painting the numbers on people's letterboxes for a small fee.
Since there are 10 of you in the group each person just concentrates on painting one digit! For e... | {"functional": "_inputs = [[125, 132], [1001, 1001]]\n_outputs = [[[1, 9, 6, 3, 0, 1, 1, 1, 1, 1]], [[2, 2, 0, 0, 0, 0, 0, 0, 0, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list... | coding | 445 |
Solve the programming task below in a Python markdown code block.
Write a function which reduces fractions to their simplest form! Fractions will be presented as an array/tuple (depending on the language), and the reduced fraction must be returned as an array/tuple:
```
input: [numerator, denominator]
output: [newN... | {"functional": "_inputs = [[[60, 20]], [[80, 120]], [[4, 2]], [[45, 120]], [[1000, 1]], [[1, 1]], [[10956590, 13611876]], [[35884747, 5576447]], [[24622321, 24473455]], [[4255316, 11425973]]]\n_outputs = [[[3, 1]], [[2, 3]], [[2, 1]], [[3, 8]], [[1000, 1]], [[1, 1]], [[30605, 38022]], [[76841, 11941]], [[42673, 42415]]... | coding | 143 |
Solve the programming task below in a Python markdown code block.
This is the hard version of the problem. The only difference is that in this version $n \leq 200000$. You can make hacks only if both versions of the problem are solved.
There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on ... | {"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n5\n", "1\n7\n"], "outputs": ["1", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 366 |
Solve the programming task below in a Python markdown code block.
Bob is preparing to pass IQ test. The most frequent task in this test is `to find out which one of the given numbers differs from the others`. Bob observed that one number usually differs from the others in **evenness**. Help Bob — to check his answers, ... | {"functional": "_inputs = [['2 4 7 8 10'], ['1 2 2'], ['88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46'], ['100 99 100'], ['5 3 2'], ['43 28 1 91'], ['20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36'], ['79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9... | coding | 221 |
Solve the programming task below in a Python markdown code block.
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and... | {"inputs": ["6 6 5 8 9\n", "1 1 1 1 1\n", "1 2 3 4 5\n", "1 3 3 5 3\n", "1 2 2 3 5\n", "2 4 3 7 3\n", "2 4 1 2 5\n", "4 6 6 8 9\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 338 |
Solve the programming task below in a Python markdown code block.
A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input
The first line contai... | {"inputs": ["0 2 3\n", "2 5 4\n", "4 5 4\n", "0 2 2\n", "0 2 4\n", "2 5 3\n", "0 -1 -2\n", "-1 1 -2\n"], "outputs": ["-1\n\n", "8 -4", "4 -4", "0 -1", "0 -2", "6 -3\n", "0 -2\n", "0 2\n"]} | coding | 166 |
Solve the programming task below in a Python markdown code block.
You will be given an array which lists the current inventory of stock in your store and another array which lists the new inventory being delivered to your store today.
Your task is to write a function that returns the updated list of your current inven... | {"functional": "_inputs = [[[], []]]\n_outputs = [[[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_dee... | coding | 242 |
Solve the programming task below in a Python markdown code block.
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. ... | {"inputs": ["A\n", "U\n", "B\n", "T\n", "UB\n", "WU\n", "UC\n", "XU\n"], "outputs": ["A\n", "U\n", "B \n", "T \n", "UB\n", "WU\n", "UC \n", "XU \n"]} | coding | 537 |
Solve the programming task below in a Python markdown code block.
You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet th... | {"inputs": ["2 6\n", "1 5\n", "3 6\n", "2 5\n", "2 7\n", "4 4\n", "5 7\n", "2 2\n"], "outputs": ["6\n", "2\n", "9\n", "5\n", "7\n", "8\n", "17\n", "2\n"]} | coding | 204 |
Solve the programming task below in a Python markdown code block.
Some integral numbers are odd. All are more odd, or less odd, than others.
Even numbers satisfy `n = 2m` ( with `m` also integral ) and we will ( completely arbitrarily ) think of odd numbers as `n = 2m + 1`.
Now, some odd numbers can be more odd than... | {"functional": "_inputs = [[[1, 2]], [[1, 3]], [[1, 5]], [[0]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]], [[-42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5,... | coding | 265 |
Solve the programming task below in a Python markdown code block.
Given are positive integers N and K.
Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in ex... | {"inputs": ["3 6", "1 0", "1 2", "6 6", "0 2", "5 6", "7 6", "0 1"], "outputs": ["-1\n", "0 1 2\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 311 |
Solve the programming task below in a Python markdown code block.
Your task is to write a function which counts the number of squares contained in an ASCII art picture.
The input pictures contain rectangles---some of them squares---drawn with the characters `-`, `|`, and `+`, where `-` and `|` are used to represent ho... | {"functional": "_inputs = [[['+--+ +----+', '| | | | +-+', '| | +----+ | |', '+--+ +-+']], [['+-----+', '| |', '+-----+']], [['+---+', '| |', '| +-+-+', '| | | |', '+-+-+ |', ' | |', ' +---+']], [['+-+-+', '| | |', '+-+-+', '| | |', '+-+-+']], [['+---+', '| |', '| |', '| |', '| ... | coding | 431 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:
It is ().
It can be written as AB (A concatenated with B), where A and B are valid pa... | {"functional": "def check(candidate):\n assert candidate(s = \"))()))\", locked = \"010100\") == True\n assert candidate(s = \"()()\", locked = \"0000\") == True\n assert candidate(s = \")\", locked = \"0\") == False\n\n\ncheck(Solution().canBeValid)"} | coding | 212 |
Solve the programming task below in a Python markdown code block.
Chef Ada has a matrix with $N$ rows (numbered $1$ through $N$ from top to bottom) and $N$ columns (numbered $1$ through $N$ from left to right) containing all integers between $1$ and $N^2$ inclusive. For each valid $i$ and $j$, let's denote the cell in ... | {"inputs": ["1\n4\n1 2 9 13\n5 6 10 14\n3 7 11 15\n4 8 12 16"], "outputs": ["2"]} | coding | 678 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their lengths. The lengths should not have leading zeros.
For example, a string such as "substitution" could be abbreviate... | {"functional": "def check(candidate):\n assert candidate(word = \"internationalization\", abbr = \"i12iz4n\") == True\n assert candidate(word = \"apple\", abbr = \"a2e\") == False\n\n\ncheck(Solution().validWordAbbreviation)"} | coding | 253 |
Solve the programming task below in a Python markdown code block.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, onl... | {"inputs": ["1\n1\n", "1\n3\n", "1\n0\n", "1\n2\n", "1\n5\n", "1\n4\n", "1\n13\n", "1\n-1\n"], "outputs": ["1\n", "3\n", "0\n", "2 ", "5 ", "4 ", "13\n", "-1\n"]} | coding | 466 |
Solve the programming task below in a Python markdown code block.
You are given two strings $s$ and $t$ both of length $2$ and both consisting only of characters 'a', 'b' and 'c'.
Possible examples of strings $s$ and $t$: "ab", "ca", "bb".
You have to find a string $res$ consisting of $3n$ characters, $n$ characters ... | {"inputs": ["2\nab\nbc\n", "3\naa\nbc\n", "1\ncb\nac\n", "1\nab\ncb\n", "3\nbb\ncb\n", "4\naa\nbb\n", "4\naa\nbc\n", "4\nbc\nca\n"], "outputs": ["YES\nacbacb\n", "YES\nacbacbacb\n", "YES\nabc\n", "YES\nbac\n", "YES\nabcabcabc\n", "YES\nabcabcabcabc\n", "YES\nacbacbacbacb\n", "YES\nacbacbacbacb\n"]} | coding | 478 |
Solve the programming task below in a Python markdown code block.
You are given array of integers, your task will be to count all pairs in that array and return their count.
**Notes:**
* Array can be empty or contain only one value; in this case return `0`
* If there are more pairs of a certain number, count each... | {"functional": "_inputs = [[[1, 2, 2, 20, 6, 20, 2, 6, 2]], [[1000, 1000]], [[]], [[54]]]\n_outputs = [[4], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\... | coding | 271 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A car travels from a starting position to a destination which is target miles east of the starting position.
There are gas stations along the way. The gas stations are represented as an array stations where stations[i... | {"functional": "def check(candidate):\n assert candidate(target = 1, startFuel = 1, stations = []) == 0\n assert candidate(target = 100, startFuel = 1, stations = [[10,100]]) == -1\n assert candidate(target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]) == 2\n\n\ncheck(Solution().minRefue... | coding | 266 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains ... | {"inputs": ["1 6\n5\n", "1 6\n6\n", "1 6\n5\n", "1 47\n0\n", "1 47\n0\n", "1 47\n1\n", "1 47\n2\n", "2 47\n1 0\n"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]} | coding | 370 |
Solve the programming task below in a Python markdown code block.
# Task
Given an array `arr`, find the rank of the element at the ith position.
The `rank` of the arr[i] is a value equal to the number of elements `less than or equal to` arr[i] standing before arr[i], plus the number of elements `less than` arr[i] st... | {"functional": "_inputs = [[[2, 1, 2, 1, 2], 2], [[2, 1, 2, 2, 2], 2], [[3, 2, 3, 4, 1], 0], [[3, 2, 3, 4, 1], 1], [[3, 2, 3, 4, 1], 2]]\n_outputs = [[3], [2], [2], [1], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol,... | coding | 304 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.
Each number in candidates may only be used once ... | {"functional": "def check(candidate):\n assert candidate(candidates = [10,1,2,7,6,1,5], target = 8) == [\n[1,1,6],\n[1,2,5],\n[1,7],\n[2,6]\n]\n assert candidate(candidates = [2,5,2,1,2], target = 5) == [\n[1,2,2],\n[5]\n]\n\n\ncheck(Solution().combinationSum2)"} | coding | 112 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.
Ple... | {"functional": "def check(candidate):\n assert candidate(nums = [8,2,4,7], limit = 4) == 2 \n assert candidate(nums = [10,1,2,4,7,2], limit = 5) == 4 \n assert candidate(nums = [4,2,2,2,4,4,2,2], limit = 0) == 3\n\n\ncheck(Solution().longestSubarray)"} | coding | 95 |
Solve the programming task below in a Python markdown code block.
Mr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct charac... | {"inputs": ["2\n3 1\n3 2\n"], "outputs": ["2.0\n4.0"]} | coding | 615 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the number of trailing zeroes in n!.
Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1.
Please complete the following python code precisely:
```python
class Solution:
def trailing... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 0\n assert candidate(n = 5) == 1\n assert candidate(n = 0) == 0\n\n\ncheck(Solution().trailingZeroes)"} | coding | 95 |
Solve the programming task below in a Python markdown code block.
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have go... | {"inputs": ["05:50\n05:44\n", "00:00\n01:00\n", "00:01\n00:00\n", "23:59\n23:59\n", "23:44\n23:55\n", "00:00\n13:12\n", "12:00\n23:59\n", "12:44\n12:44\n"], "outputs": ["00:06\n", "23:00\n", "00:01\n", "00:00\n", "23:49\n", "10:48\n", "12:01\n", "00:00\n"]} | coding | 355 |
Solve the programming task below in a Python markdown code block.
When provided with a String, capitalize all vowels
For example:
Input : "Hello World!"
Output : "HEllO WOrld!"
Note: Y is not a vowel in this kata.
Also feel free to reuse/extend the following starter code:
```python
def swap(st):
``` | {"functional": "_inputs = [['HelloWorld!'], ['Sunday'], ['Codewars'], ['Monday'], ['Friday'], ['abracadabra']]\n_outputs = [['HEllOWOrld!'], ['SUndAy'], ['COdEwArs'], ['MOndAy'], ['FrIdAy'], ['AbrAcAdAbrA']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | coding | 73 |
Solve the programming task below in a Python markdown code block.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if ... | {"inputs": ["4\n3 5 5 1", "4\n3 3 4 1", "4\n3 5 6 1", "4\n4 3 4 1", "4\n3 5 0 1", "4\n4 1 4 1", "4\n3 5 0 0", "4\n2 1 4 1"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n"]} | coding | 235 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Two strings $A$ and $B$ are *equivalent* (denoted by $A \sim B$) if they have the same lengths and $A$ can be transformed into $B$ by performing the ... | {"inputs": ["10\n00000\n10001\n10101\n01111\n11001\n01101\n10110\n10010\n10111\n11001"], "outputs": ["5\n11\n8\n9\n12\n10\n10\n11\n11\n12"]} | coding | 480 |
Solve the programming task below in a Python markdown code block.
Real stupidity beats artificial intelligence every time.
— Terry Pratchett, Hogfather, Discworld
You are given a string $s$ of length $n$ and a number $k$. Let's denote by $rev(s)$ the reversed string $s$ (i.e. $rev(s) = s_n s_{n-1} ... s_1$). You can ... | {"inputs": ["1\n2 1\nab\n", "1\n3 1\naab\n", "1\n3 1\nabc\n", "1\n4 1\nabcd\n", "1\n4 2\nabca\n", "4\n3 2\naab\n3 3\naab\n7 1\nabacaba\n2 0\nab\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n2\n1\n1\n"]} | coding | 523 |
Solve the programming task below in a Python markdown code block.
## Task
Given an array of strings, reverse them and their order in such way that their length stays the same as the length of the original inputs.
### Example:
```
Input: {"I", "like", "big", "butts", "and", "I", "cannot", "lie!"}
Output: {"!", "eilt"... | {"functional": "_inputs = [[['I', 'like', 'big', 'butts', 'and', 'I', 'cannot', 'lie!']], [['?kn', 'ipnr', 'utotst', 'ra', 'tsn', 'iksr', 'uo', 'yer', 'ofebta', 'eote', 'vahu', 'oyodpm', 'ir', 'hsyn', 'amwoH']]]\n_outputs = [[['!', 'eilt', 'onn', 'acIdn', 'ast', 't', 'ubgibe', 'kilI']], [['How', 'many', 'shrimp', 'do',... | coding | 134 |
Solve the programming task below in a Python markdown code block.
Decades have passed since the beginning of AtCoder Beginner Contest.
The contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?
In the end, the lab... | {"inputs": ["8", "7", "2", "3", "4", "1", "0", "5"], "outputs": ["ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n", "ABC\n"]} | coding | 254 |
Solve the programming task below in a Python markdown code block.
Implement `String#whitespace?(str)` (Ruby), `String.prototype.whitespace(str)` (JavaScript), `String::whitespace(str)` (CoffeeScript), or `whitespace(str)` (Python), which should return `true/True` if given object consists exclusively of zero or more whi... | {"functional": "_inputs = [[''], [' '], ['\\n\\r\\n\\r'], ['a'], ['w\\n'], ['\\t'], [' a\\n'], ['\\t \\n\\r\\n '], ['\\n\\r\\n\\r '], ['\\n\\r\\n\\r 3']]\n_outputs = [[True], [True], [True], [False], [False], [True], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, fl... | coding | 102 |
Solve the programming task below in a Python markdown code block.
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
There are $n$ boxes in front of you. For each $\boldsymbol{i}$, box $\boldsymbol{i}$ contains $r[i]$ red balls, $g[i]$ green balls, and $b[i]$ blu... | {"inputs": ["3\n1 1 1\n1 1 1\n1 1 1\n"], "outputs": ["6\n"]} | coding | 449 |
Solve the programming task below in a Python markdown code block.
Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to n. Each student i (1 ≤ i ≤ n) has a bes... | {"inputs": ["1\n1\n1\n", "2\n1 2\n1 2\n", "2\n1 2\n2 1\n", "3\n1 2 3\n2 1 3\n", "3\n2 3 1\n1 2 3\n", "3\n1 2 3\n1 2 3\n", "4\n1 2 3 4\n2 1 4 3\n", "4\n2 1 4 3\n3 4 2 1\n"], "outputs": ["1 ", "1 2 ", "2 1 ", "2 1 3 ", "3 1 2 ", "1 2 3 ", "2 1 4 3 ", "4 3 1 2 "]} | coding | 602 |
Solve the programming task below in a Python markdown code block.
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the di... | {"inputs": ["04:50\n", "02:17\n", "12:14\n", "03:44\n", "00:17\n", "15:51\n", "23:31\n", "07:56\n"], "outputs": ["05:50\n", "02:20\n", "12:21\n", "04:40\n", "01:10\n", "20:02\n", "23:32\n", "10:01\n"]} | coding | 320 |
Solve the programming task below in a Python markdown code block.
For a given two numbers your mission is to derive a function that evaluates whether two given numbers are **abundant**, **deficient** or **perfect** and whether together they are **amicable**.
### Abundant Numbers
An abundant number or excessive numbe... | {"functional": "_inputs = [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [139815, 122265], [496, 28], [8128, 8128]]\n_outputs = [['abundant deficient amicable'], ['abundant abundant not amicable'], ['abundant deficient amicable'], ['deficient abundant not amicab... | coding | 741 |
Solve the programming task below in a Python markdown code block.
To decide which is the strongest among Rock, Paper, and Scissors, we will hold an RPS tournament.
There are 2^k players in this tournament, numbered 0 through 2^k-1. Each player has his/her favorite hand, which he/she will use in every match.
A string s ... | {"inputs": ["1 1\nP\n", "1 1\nR\n", "1 1\nS\n", "3 2\nRPS\n", "1 100\nS\n", "11 1\nRPSSPRSPPRS\n", "15 87\nRPPRPRRRPPSPRPP\n", "19 2\nSSSPRPRPSSRPPSRRSRR\n"], "outputs": ["P\n", "R\n", "S\n", "P\n", "S\n", "P\n", "S\n", "S\n"]} | coding | 656 |
Solve the programming task below in a Python markdown code block.
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.
Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
-----Constraints-----
- x and y are inte... | {"inputs": ["2 8", "1 4", "2 3", "4 3", "7 3", "7 6", "7 4", "7 5"], "outputs": ["No\n", "No\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n"]} | coding | 140 |
Solve the programming task below in a Python markdown code block.
You are given a string of words (x), for each word within the string you need to turn the word 'inside out'. By this I mean the internal letters will move out, and the external letters move toward the centre.
If the word is even length, all letters wil... | {"functional": "_inputs = [['man i need a taxi up to ubud'], ['what time are we climbing up the volcano'], ['take me to semynak'], ['massage yes massage yes massage'], ['take bintang and a dance please']]\n_outputs = [['man i ende a atix up to budu'], ['hwta item are we milcgnib up the lovcona'], ['atek me to mesykan']... | coding | 142 |
Solve the programming task below in a Python markdown code block.
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following... | {"inputs": ["1\n2\n0\n", "1\n3\n0\n", "1\n6\n0\n", "1\n10\n0\n", "1\n13\n0\n", "2\n10 5\n0\n", "2\n11 5\n0\n", "2\n14 5\n0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n"]} | coding | 463 |
Solve the programming task below in a Python markdown code block.
Given an array of ones and zeroes, convert the equivalent binary value to an integer.
Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`.
Examples:
```
Testing: [0, 0, 0, 1] ==> 1
Testing: [0, 0, 1, 0] ==> 2
Testing: [0, ... | {"functional": "_inputs = [[[0, 0, 0, 1]], [[0, 0, 1, 0]], [[1, 1, 1, 1]], [[0, 1, 1, 0]]]\n_outputs = [[1], [2], [15], [6]]\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 | 255 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Under the grammar given below, strings can represent a set of lowercase words. Let R(expr) denote the set of words the expression represents.
The grammar can best be understood through simple examples:
Single letters... | {"functional": "def check(candidate):\n assert candidate(expression = \"{a,b}{c,{d,e}}\") == [\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]\n assert candidate(expression = \"{{a,z},a{b,c},{ab,z}}\") == [\"a\",\"ab\",\"ac\",\"z\"]\n\n\ncheck(Solution().braceExpansionII)"} | coding | 438 |
Solve the programming task below in a Python markdown code block.
Kevin is noticing his space run out! Write a function that removes the spaces from the values and returns an array showing the space decreasing.
For example, running this function on the array ['i', 'have','no','space'] would produce ['i','ihave','ihaven... | {"functional": "_inputs = [[['kevin', 'has', 'no', 'space']], [['this', 'cheese', 'has', 'no', 'holes']]]\n_outputs = [[['kevin', 'kevinhas', 'kevinhasno', 'kevinhasnospace']], [['this', 'thischeese', 'thischeesehas', 'thischeesehasno', 'thischeesehasnoholes']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins... | coding | 97 |
Solve the programming task below in a Python markdown code block.
There are $n$ points $1,2,\ldots,n$, each point $i$ has a number $a_i$ on it. You're playing a game on them. Initially, you are at point $1$. When you are at point $i$, take following steps:
If $1\le i\le n$, go to $i+a_i$,
Otherwise, the game ends.
B... | {"inputs": ["9\n1\n0\n2\n-1 0\n2\n1 -1\n2\n1 1\n3\n-1 -2 -1\n3\n1 -2 -1\n4\n-1 4 -2 1\n5\n1 1 1 1 -4\n5\n1 1 1 1 1\n"], "outputs": ["2\n8\n6\n7\n20\n17\n34\n30\n40\n"]} | coding | 663 |
Solve the programming task below in a Python markdown code block.
You are given an array consisting of $n$ integers $a_1, a_2, \dots , a_n$ and an integer $x$. It is guaranteed that for every $i$, $1 \le a_i \le x$.
Let's denote a function $f(l, r)$ which erases all values such that $l \le a_i \le r$ from the array $a... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "2 3\n1 1\n", "2 3\n3 2\n", "2 3\n3 2\n", "2 3\n1 1\n", "2 4\n3 2\n", "2 20\n1 8\n"], "outputs": ["1\n", "1\n", "6\n", "5\n", "5\n", "6\n", "8\n", "210\n"]} | coding | 461 |
Solve the programming task below in a Python markdown code block.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s_1s_2...s_{|}s| (where |s| is the length of string s) is string s_{l}s_{l} + 1...s... | {"inputs": ["a\n00000000000000000000000000\n0\n", "a\n00000000000000000000000000\n0\n", "a\n00000000000000000100000000\n0\n", "aaaa\n00000000000000000000000000\n0\n", "aaaa\n00000000000000000000000000\n0\n", "aaaa\n10000000000000000000000000\n0\n", "ababab\n01000000000000000000000000\n1\n", "aaaaaa\n0000000000000000000... | coding | 529 |
Solve the programming task below in a Python markdown code block.
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms:... | {"inputs": ["5 3\n96 98 95 000 20", "5 3\n96 98 95 100 20", "3 1\n1001 869120 1001", "3 2\n1011 869120 1001", "5 0\n96 98 162 100 39", "3 2\n0011 869120 1001", "3 0\n1101 681697 1001", "3 2\n1001 869120 1001"], "outputs": ["No\nNo\n", "Yes\nNo", "Yes\nNo\n", "No\n", "No\nNo\nNo\nNo\nNo\n", "Yes\n", "No\nNo\nNo\n", "No"... | coding | 426 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`.
For example:
```
solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit s... | {"functional": "_inputs = [[79320], [99004], [99088], [99737], [29652], [100], [48], [521], [1], [2], [3], [39188], [5], [10], [1000], [10000], [999999999992], [59195], [19930], [110], [1199], [120], [18], [2090], [72694]]\n_outputs = [[78999], [98999], [98999], [98999], [28999], [99], [48], [499], [1], [2], [3], [3899... | coding | 177 |
Solve the programming task below in a Python markdown code block.
An array A of size N is called *good* if the following conditions hold:
For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].)
JJ has an array A of size N. He wants ... | {"inputs": ["3\n5\n1 2 3 4 4\n3\n0 0 0\n6\n2 3 5 7 11 13\n"], "outputs": ["2\n3\n0\n"]} | coding | 590 |
Solve the programming task below in a Python markdown code block.
$2^n$ teams participate in a playoff tournament. The tournament consists of $2^n - 1$ games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team $1$ plays against team $2$, team $3$ plays against team $4$,... | {"inputs": ["1\n1\n", "1\n0\n", "2\n01\n", "2\n00\n", "2\n11\n", "3\n101\n", "3\n000\n", "3\n010\n"], "outputs": ["2 ", "1 ", "2 3 ", "1 ", "4 ", "4 5 6 7 ", "1 ", "2 3 4 5 "]} | coding | 574 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of length $n$, which consists only of the first $k$ letters of the Latin alphabet. All letters in string $s$ are uppercase.
A subsequence of string $s$ is a string that can be derived from $s$ by deleting some of its symbols w... | {"inputs": ["1 5\nA\n", "1 1\nA\n", "1 4\nD\n", "1 4\nD\n", "1 1\nA\n", "1 5\nA\n", "1 7\nA\n", "1 4\nC\n"], "outputs": ["0", "1", "0", "0\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 383 |
Solve the programming task below in a Python markdown code block.
Does the card fit in a snack? (Are Cards Snacks?)
square1001 You have $ N $ cards.
Each of these cards has an integer written on it, and the integer on the $ i $ th card is $ A_i $.
square1001 Your random number today is $ K $. square1001 You want to ... | {"inputs": ["7 9\n8 6 9 1 2", "5 9\n8 6 9 1 0", "7 9\n8 6 7 1 2", "7 9\n8 6 1 1 1", "7 9\n8 6 8 0 3", "7 9\n8 6 1 2 1", "7 9\n8 6 8 1 3", "6 9\n8 6 1 2 1"], "outputs": ["2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n"]} | coding | 559 |
Solve the programming task below in a Python markdown code block.
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate o... | {"inputs": ["1\n2\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 408 |
Solve the programming task below in a Python markdown code block.
Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins ... | {"inputs": ["2 1 1 1\n", "7 4 1 6\n", "4 4 2 2\n", "5 2 2 3\n", "5 3 2 1\n", "5 4 3 2\n", "1 1 1 1\n", "7 4 1 4\n"], "outputs": ["2", "-1", "1", "-1", "1", "-1", "-1", "-1"]} | coding | 410 |
Solve the programming task below in a Python markdown code block.
A permutation is a sequence of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as p_{i}. We'll call number n the size of permutation p_1, p_2, ..., p... | {"inputs": ["1\n", "2\n", "4\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["-1\n", "2 1 \n", "2 1 4 3 \n", "-1\n", "-1\n", "2 1 4 3 6 5 \n", "-1\n", "2 1 4 3 6 5 8 7 \n"]} | coding | 290 |
Solve the programming task below in a Python markdown code block.
You are given an integer a that consists of n digits. You are also given a sequence of digits s of length m. The digit in position j (1 ≤ j ≤ m) of sequence s means that you can choose an arbitrary position i (1 ≤ i ≤ n) in a and replace the digit in the... | {"inputs": ["1\n2\n", "1\n0\n", "1\n3\n", "1\n1\n", "1\n5\n", "1\n4\n", "87\n9\n", "31\n4\n"], "outputs": ["2\n", "1\n", "3", "1", "5", "4", "97\n", "41\n"]} | coding | 280 |
Solve the programming task below in a Python markdown code block.
Write a function that takes a list comprised of other lists of integers and returns the sum of all numbers that appear in two or more lists in the input list. Now that might have sounded confusing, it isn't:
```python
repeat_sum([[1, 2, 3],[2, 8, 9],[7,... | {"functional": "_inputs = [[[[1, 2, 3], [2, 8, 9], [7, 123, 8]]], [[[1], [2], [3, 4, 4, 4], [123456789]]], [[[1, 8, 8], [8, 8, 8], [8, 8, 8, 1]]], [[[1]]]]\n_outputs = [[10], [0], [9], [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, ... | coding | 208 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and... | {"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6]) == 6\n assert candidate(edges = [[0,1]], bob = 1, amount = [-7280,2350]) == -7280\n\n\ncheck(Solution().mostProfitablePath)"} | coding | 409 |
Solve the programming task below in a Python markdown code block.
Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.
Lily decides to share a contiguous segment of the bar selected such that:
The length of the segment matches Ron's birth month, and,
The sum of the in... | {"inputs": ["1\n4\n4 1\n", "5\n1 2 1 3 2\n3 2\n", "6\n1 1 1 1 1 1\n3 2\n"], "outputs": ["1\n", "2\n", "0\n"]} | coding | 620 |
Solve the programming task below in a Python markdown code block.
A format for expressing an ordered list of integers is to use a comma separated list of either
* individual integers
* or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. The range includes ... | {"functional": "_inputs = [[[-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]], [[-3, -2, -1, 2, 10, 15, 16, 18, 19, 20]], [[1, 2, 3, 4, 5]]]\n_outputs = [['-6,-3-1,3-5,7-11,14,15,17-20'], ['-3--1,2,10,15,16,18-20'], ['1-5']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float... | coding | 379 |
Solve the programming task below in a Python markdown code block.
# Task
The year of `2013` is the first year after the old `1987` with only distinct digits.
Now your task is to solve the following problem: given a `year` number, find the minimum year number which is strictly larger than the given one and has only d... | {"functional": "_inputs = [[1987], [2013]]\n_outputs = [[2013], [2014]]\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 ... | coding | 161 |
Solve the programming task below in a Python markdown code block.
You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.
You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.
You can perform this operation at most once.
How many dif... | {"inputs": ["aatu", "ttaa", "utab", "utaa", "tata", "uuaa", "atta", "aauu"], "outputs": ["6\n", "5\n", "7\n", "6\n", "5\n", "5\n", "5\n", "5\n"]} | coding | 189 |
Solve the programming task below in a Python markdown code block.
Staircase detail
This is a staircase of size $n=4$:
#
##
###
####
Its base and height are both equal to $n$. It is drawn using # symbols and spaces. The last line is not preceded by any spaces.
Write a program that prints a staircase of size ... | {"inputs": ["6 \n"], "outputs": [" #\n ##\n ###\n ####\n #####\n######\n"]} | coding | 236 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.