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. For a given array whose element values are randomly picked from single-digit integers `0` to `9`, return an array with the same digit order but all `0`'s paired. Paring two `0`'s generates one `0` at the location of the first. Ex: ```python pair_zeros([...
{"functional": "_inputs = [[[]], [[1]], [[1, 2, 3]], [[0]], [[0, 0]], [[1, 0, 1, 0, 2, 0, 0]], [[0, 0, 0]], [[1, 0, 1, 0, 2, 0, 0, 3, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]\n_outputs = [[[]], [[1]], [[1, 2, 3]], [[0]], [[0]], [[1, 0, 1, 2, 0]], [[0, 0]], [[1, 0, 1, 2, 0,...
coding
404
Solve the programming task below in a Python markdown code block. Madoka is a very strange girl, and therefore she suddenly wondered how many pairs of integers $(a, b)$ exist, where $1 \leq a, b \leq n$, for which $\frac{\operatorname{lcm}(a, b)}{\operatorname{gcd}(a, b)} \leq 3$. In this problem, $\operatorname{gcd}(...
{"inputs": ["6\n1\n2\n3\n4\n5\n100000000\n"], "outputs": ["1\n4\n7\n10\n11\n266666666\n"]}
coding
426
Solve the programming task below in a Python markdown code block. When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his n...
{"inputs": ["maohiro", "orihoam", "anphiro", "onphira", "arihpno", "nmpgira", "sgi`pmn", "nlp`igs"], "outputs": ["mao\n", "ori\n", "anp\n", "onp\n", "ari\n", "nmp\n", "sgi\n", "nlp\n"]}
coding
150
Solve the programming task below in a Python markdown code block. There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a v...
{"inputs": ["1\n6\n", "1\n11\n", "1\n11\n", "1\n-8\n", "1\n-4\n", "1\n-3\n", "1\n10\n", "1\n20\n"], "outputs": ["6\n", "11", "11\n", "-8\n", "-4\n", "-3\n", "10\n", "20\n"]}
coding
379
Solve the programming task below in a Python markdown code block. You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input ...
{"inputs": ["5\n2 5 7\n2 3 13\n7 0 7\n2 7 6\n1 6 6\n"], "outputs": ["YES\nNO\nYES\nYES\nYES\n"]}
coding
354
Solve the programming task below in a Python markdown code block. YouKn0wWho has an integer sequence a_1, a_2, …, a_n. He will perform the following operation until the sequence becomes empty: select an index i such that 1 ≤ i ≤ |a| and a_i is not divisible by (i + 1), and erase this element from the sequence. Here |a|...
{"inputs": ["5\n3\n1 8 3\n1\n2\n2\n7 7\n10\n384836991 191890310 15674376 782177068 172478243 550654647 954291757 278929746 405393865 840594328\n8\n6 69 696 69696 687972 87299 69696969 1602686280\n", "5\n3\n1 8 3\n1\n2\n2\n7 7\n10\n384836991 191890310 15674376 892143751 172478243 550654647 954291757 278929746 405393865 ...
coding
645
Solve the programming task below in a Python markdown code block. In a New York City coffee house called Central Perk, we're introduced to six friends: chef Monica Geller, data controller Chandler Bing who lives across the hall from Monica, Chandler's roommate/actor Joey Tribbiani, Monica's brother Ross Geller, new age...
{"inputs": ["3\n42\n5\n909"], "outputs": ["YES\nNO\nYES"]}
coding
355
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 triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.   Please complete the following python code precisely: ```python ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,2,3,4]) == 3\n assert candidate(nums = [4,2,3,4]) == 4\n\n\ncheck(Solution().triangleNumber)"}
coding
79
Solve the programming task below in a Python markdown code block. Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima ...
{"inputs": ["1\n", "2\n", "3\n", "0\n", "4\n", "7\n", "1\n", "70\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
573
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you wa...
{"functional": "def check(candidate):\n assert candidate(numCourses = 2, prerequisites = [[1,0]]) == True\n assert candidate(numCourses = 2, prerequisites = [[1,0],[0,1]]) == False\n\n\ncheck(Solution().canFinish)"}
coding
151
Solve the programming task below in a Python markdown code block. Alice has learnt factorization recently. Bob doesn't think she has learnt it properly and hence he has decided to quiz her. Bob gives Alice a very large number and asks her to find out the number of factors of that number. To make it a little easier for ...
{"inputs": ["3\n3\n3 5 7\n3\n2 4 6\n2\n5 5", "3\n3\n3 5 7\n3\n2 4 3\n2\n5 5", "3\n3\n3 3 7\n3\n2 4 3\n2\n5 5", "3\n3\n3 5 7\n3\n2 4 3\n2\n5 2", "3\n3\n3 5 7\n3\n2 4 6\n2\n8 5", "3\n3\n4 3 7\n3\n2 4 3\n2\n5 5", "3\n3\n3 7 7\n3\n2 4 6\n2\n8 5", "3\n3\n3 5 7\n3\n2 4 6\n2\n7 5"], "outputs": ["8\n10\n3", "8\n8\n3\n", "6\n8\...
coding
356
Solve the programming task below in a Python markdown code block. The NumPy (Numeric Python) package helps us manipulate large arrays and matrices of numeric data. To use the NumPy module, we need to import it using: import numpy Arrays A NumPy array is a grid of values. They are similar to lists, except that ev...
{"inputs": ["1 2 3 4 -8 -10\n"], "outputs": ["[-10. -8. 4. 3. 2. 1.]\n"]}
coding
272
Solve the programming task below in a Python markdown code block. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic i...
{"inputs": ["4 4 4\n", "4 4 8\n", "1 80 7\n", "1 10 2\n", "6 19 5\n", "12 23 3\n", "2 1000 4\n", "1 124 11\n"], "outputs": ["0\n", "0\n", "3\n", "5\n", "0\n", "2\n", "0\n", "2\n"]}
coding
453
Solve the programming task below in a Python markdown code block. The town sheriff dislikes odd numbers and wants all odd numbered families out of town! In town crowds can form and individuals are often mixed with other people and families. However you can distinguish the family they belong to by the number on the shir...
{"functional": "_inputs = [[[1, 2, 3, 1, 3, 3]], [[75, 68, 75, 47, 68]], [[42, 72, 32, 4, 94, 82, 67, 67]], [[100, 100, 5, 5, 100, 50, 68, 50, 68, 50, 68, 5, 100]], [[82, 86, 71, 58, 44, 79, 50, 44, 79, 67, 82, 82, 55, 50]]]\n_outputs = [[[1, 1]], [[75, 68, 75, 68]], [[67, 67]], [[100, 100, 100, 100]], [[44, 79, 50, 44...
coding
430
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the followong problem: given array of N integers A and a number K. During a turn the maximal value over a...
{"inputs": ["4 1\n5 0 7 0", "4 1\n5 0 7 1", "4 2\n5 0 7 1", "4 2\n5 0 7 0", "4 0\n2 0 5 0", "4 1\n4 0 0 1", "4 1\n4 0 1 1", "4 1\n4 1 1 1"], "outputs": ["2 7 0 7\n", "2 7 0 6\n", "5 0 7 1\n", "5 0 7 0\n", "2 0 5 0\n", "0 4 4 3\n", "0 4 3 3\n", "0 3 3 3\n"]}
coding
263
Solve the programming task below in a Python markdown code block. Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$. Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$. Let's say string $t$ is go...
{"inputs": ["1\n1111\n", "1\n1111\n", "1\n0111\n", "1\n0011\n", "1\n0101\n", "1\n0001\n", "1\n1101\n", "1\n1001\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "0\n", "1\n", "1\n", "2\n"]}
coding
455
Solve the programming task below in a Python markdown code block. Given the number pledged for a year, current value and name of the month, return string that gives information about the challenge status: - ahead of schedule - behind schedule - on track - challenge is completed Examples: `(12, 1, "February")` - shou...
{"functional": "_inputs = [[12, 5, 'January'], [12, 1, 'February'], [12, 1, 'March'], [12, 12, 'September'], [12, 5, 'March'], [100, 5, 'March'], [100, 52, 'July'], [100, 51, 'July'], [100, 53, 'July']]\n_outputs = [['You are on track.'], ['You are on track.'], ['You are 1 behind schedule.'], ['Challenge is completed.'...
coding
276
Solve the programming task below in a Python markdown code block. Taro Aizu's company has a boss who hates being indivisible. When Taro goes out to eat with his boss, he pays by splitting the bill, but when the payment amount is not divisible by the number of participants, his boss always pays for it. One day, Taro be...
{"inputs": ["4 15000\n305\n24\n129\n500\n3 349\n9\n20\n30\n3 5016\n5\n9\n12\n0 0", "4 15000\n305\n24\n129\n949\n3 568\n9\n20\n30\n3 5016\n5\n9\n12\n0 0", "4 1512\n305\n17\n129\n129\n3 709\n6\n20\n52\n3 200909\n8\n6\n9\n0 0", "4 1512\n305\n17\n129\n129\n3 709\n6\n20\n52\n3 319036\n8\n6\n9\n0 0", "4 7955\n305\n24\n129\n1...
coding
516
Solve the programming task below in a Python markdown code block. Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division. To improve his division skills, Oleg came up with $t$ pairs of integers $p_i$ and $q_i$ and for each pair decided to find the greatest integer $x_i$, such...
{"inputs": ["1\n5 5\n", "1\n5 6\n", "1\n6 12\n", "1\n9 17\n", "1\n5 12\n", "1\n6 17\n", "1\n95775579 43432\n", "1\n95775579 67436\n"], "outputs": ["1\n", "5\n", "6\n", "9\n", "5\n", "6\n", "95775579\n", "95775579\n"]}
coding
513
Solve the programming task below in a Python markdown code block. The squirrel Chokudai has N acorns. One day, he decides to do some trades in multiple precious metal exchanges to make more acorns. His plan is as follows: 1. Get out of the nest with N acorns in his hands. 2. Go to Exchange A and do some trades. 3. Go...
{"inputs": ["23\n1 1 1\n2 2 1", "23\n1 2 1\n2 1 1", "23\n1 2 1\n2 0 1", "23\n0 2 1\n2 0 1", "23\n1 1 2\n1 1 0", "23\n1 1 1\n2 0 1", "23\n1 4 1\n2 1 1", "23\n1 1 2\n2 3 0"], "outputs": ["46\n", "92\n", "48\n", "27\n", "25\n", "47\n", "184\n", "71\n"]}
coding
451
Solve the programming task below in a Python markdown code block. You have a list of numbers from $1$ to $n$ written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are $1$-indexed). On the $i$-th step you wipe the $i$-th number (considering only remaining numbers). Yo...
{"inputs": ["1\n4271 0\n", "1\n3916 0\n", "1\n33777 1\n", "1\n33777 0\n", "1\n54843 1\n", "1\n21874 1\n", "1\n21874 2\n", "1\n42601 2\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "2\n", "2\n", "4\n", "4\n"]}
coding
355
Solve the programming task below in a Python markdown code block. Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which the dolls come in pairs. One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!! Help c...
{"inputs": ["1\n3\n1 \n2\n1", "1\n3\n2 \n2\n1", "1\n3\n0 \n2\n0", "1\n3\n1 \n4\n1", "1\n3\n1 \n8\n1", "1\n1\n7 \n6\n1", "1\n3\n2 \n1\n1", "1\n3\n0 \n1\n0"], "outputs": ["2", "1\n", "2\n", "4\n", "8\n", "7\n", "2\n", "1\n"]}
coding
258
Solve the programming task below in a Python markdown code block. There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points? Here, the Manhattan distance between two...
{"inputs": ["2\n0 1\n1 1", "2\n0 0\n1 1", "2\n0 0\n1 2", "2\n1 1\n1 1", "2\n1 1\n1 1\n", "2\n0 -1\n1 2", "2\n9 9\n0 -1", "2\n0 2\n39 0"], "outputs": ["1\n", "2\n", "3\n", "0", "0\n", "4\n", "19\n", "41\n"]}
coding
248
Solve the programming task below in a Python markdown code block. Chef wants to buy a new laptop. However, he is confused about which laptop to buy out of 10 different laptops. He asks his N friends for their recommendation. The i^{th} friend recommends the Chef to buy the {A_{i}}^{th} laptop (1 ≤ A_{i} ≤ 10). Chef w...
{"inputs": ["4\n5\n4 4 4 2 1\n7\n1 2 3 4 5 6 6\n6\n2 2 3 3 10 8\n4\n7 7 8 8\n"], "outputs": ["4\n6\nCONFUSED\nCONFUSED\n"]}
coding
515
Solve the programming task below in a Python markdown code block. Write a function which takes one parameter representing the dimensions of a checkered board. The board will always be square, so 5 means you will need a 5x5 board. The dark squares will be represented by a unicode white square, while the light squares w...
{"functional": "_inputs = [[1], [0], [-1], ['test'], [None], [[]], [2], [100], [3], [7]]\n_outputs = [[False], [False], [False], [False], [False], [False], ['\u25a1 \u25a0\\n\u25a0 \u25a1'], ['\u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \u25a1 \u25a0 \...
coding
376
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef and his little brother are playing with sticks. Initially, Chef has $N$ sticks with lengths $A_{1}, A_{2}, \dots, A_{N}$. He should give his little brother at least $K$ ...
{"inputs": ["2\n7 6\n1 2 3 1 2 2 1\n5 4\n1 2 1 2 3"], "outputs": ["2\n-1"]}
coding
605
Solve the programming task below in a Python markdown code block. Lia is fascinated by anything she considers to be a twin. She calls a pairs of positive integers, $\boldsymbol{i}$ and $j$, twins if: They are both prime. A prime number is an integer greater than $\mbox{1}$ that has no positive divisors other than $\mb...
{"inputs": ["3 13\n"], "outputs": ["3\n"]}
coding
279
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x. Return abs(i - start...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], target = 5, start = 3) == 1\n assert candidate(nums = [1], target = 1, start = 0) == 0\n assert candidate(nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0) == 0\n\n\ncheck(Solution().getMinDistance)"}
coding
123
Solve the programming task below in a Python markdown code block. There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the second one i...
{"inputs": ["1 6\n2\n", "1 6\n7\n", "1 6\n3\n", "1 6\n4\n", "1 7\n2\n", "1 6\n2\n", "1 6\n7\n", "1 24\n10\n"], "outputs": ["11\n", "14\n", "11\n", "14\n", "14\n", " 11\n", " 14\n", "161\n"]}
coding
553
Solve the programming task below in a Python markdown code block. The only difference between the easy and hard versions is that the given string $s$ in the easy version is initially a palindrome, this condition is not always true for the hard version. A palindrome is a string that reads the same left to right and rig...
{"inputs": ["2\n4\n1001\n1\n0\n"], "outputs": ["BOB\nBOB\n"]}
coding
656
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string array words. Two strings are similar if they consist of the same characters. For example, "abca" and "cba" are similar since both consist of characters 'a', 'b', and 'c'. However, "ab...
{"functional": "def check(candidate):\n assert candidate(words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]) == 2\n assert candidate(words = [\"aabb\",\"ab\",\"ba\"]) == 3\n assert candidate(words = [\"nba\",\"cba\",\"dba\"]) == 0\n\n\ncheck(Solution().similarPairs)"}
coding
163
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. Each plant needs a specific amount of ...
{"functional": "def check(candidate):\n assert candidate(plants = [2,2,3,3], capacityA = 5, capacityB = 5) == 1\n assert candidate(plants = [2,2,3,3], capacityA = 3, capacityB = 4) == 2\n assert candidate(plants = [5], capacityA = 10, capacityB = 8) == 0\n\n\ncheck(Solution().minimumRefill)"}
coding
343
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to. You have to distribute the mon...
{"functional": "def check(candidate):\n assert candidate(money = 20, children = 3) == 1\n assert candidate(money = 16, children = 2) == 2\n\n\ncheck(Solution().distMoney)"}
coding
159
Solve the programming task below in a Python markdown code block. D: Shiritori Compression problem Ebi-chan and Kana-chan did a shiritori. Ebi-chan is looking at the memo of the word that came out in Shiritori. Ebi-chan wants to remove redundant continuous subsequences from this word sequence w_1, w_2, ..., w_N unti...
{"inputs": ["7\nbanana\nta\ntomb\nbus\nsound\ndoes\nsome", "7\nananab\nta\nsomb\nbus\nsound\ndoes\nsemo", "7\nbanaoa\nta\ntomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nta\nuomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\nspund\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\...
coding
684
Solve the programming task below in a Python markdown code block. Welcome to the exciting class of Professor Manasa. In each lecture she used to play some game while teaching a new concept. Today's topic is Set Theory. For today's game, she had given a set A = {a_{1}, a_{2}, ...a_{N}} of N integers to her students and ...
{"inputs": ["3\n1 2 2\n", "4\n2 4 6 1\n"], "outputs": ["3\n", "7\n"]}
coding
656
Solve the programming task below in a Python markdown code block. A person is said to be sleep deprived if he slept strictly less than 7 hours in a day. Chef was only able to sleep X hours yesterday. Determine if he is sleep deprived or not. ------ Input Format ------ - The first line contains a single integer T — ...
{"inputs": ["3\n4\n7\n10\n"], "outputs": ["YES\nNO\nNO\n"]}
coding
265
Solve the programming task below in a Python markdown code block. We have N points numbered 1 to N arranged in a line in this order. Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The...
{"inputs": ["4 2\n1 2 2\n3 4 2", "4 2\n1 2 1\n1 4 2", "3 1\n1 3 4\n6 0 0", "4 2\n1 4 1\n3 4 2", "1 2\n2 2 2\n3 3 2", "4 2\n1 2 2\n3 4 0", "3 2\n1 2 2\n3 4 0", "3 2\n1 2 2\n6 4 0"], "outputs": ["-1\n", "2\n", "4\n", "1\n", "0\n", "-1\n", "-1\n", "-1\n"]}
coding
456
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Devu is a disastrous oracle: his predictions about various events of your life are horrifying. Instead of providing good luck, he "blesses" you with bad luck. The secret behi...
{"inputs": ["3\n2\nab\nba\n2\naa\nbb\n3\naabb\nabab\nbaab"], "outputs": ["1\n0\n2"]}
coding
525
Solve the programming task below in a Python markdown code block. This is a follow-up from my previous Kata which can be found here: http://www.codewars.com/kata/5476f4ca03810c0fc0000098 This time, for any given linear sequence, calculate the function [f(x)] and return it as a function in Javascript or Lambda/Block in...
{"functional": "_inputs = [[[1, 2, 4, 7, 11]], [[0, 1, 2, 3, 100000]], [[0, 1, 2, 100000, 4]], [[0, 1, 100000, 3, 4]], [[0, 100000, 2, 3, 4]]]\n_outputs = [['Non-linear sequence'], ['Non-linear sequence'], ['Non-linear sequence'], ['Non-linear sequence'], ['Non-linear sequence']]\nimport math\ndef _deep_eq(a, b, tol=1e...
coding
284
Solve the programming task below in a Python markdown code block. inner The inner tool returns the inner product of two arrays. import numpy A = numpy.array([0, 1]) B = numpy.array([3, 4]) print numpy.inner(A, B) #Output : 4 outer The outer tool returns the outer product of two arrays. import numpy A ...
{"inputs": ["0 1\n2 3\n"], "outputs": ["3\n[[0 0]\n [2 3]]\n"]}
coding
239
Solve the programming task below in a Python markdown code block. Simple enough this one - you will be given an array. The values in the array will either be numbers or strings, or a mix of both. You will not get an empty array, nor a sparse one. Your job is to return a single array that has first the numbers sorted i...
{"functional": "_inputs = [[[6, 2, 3, 4, 5]], [[14, 32, 3, 5, 5]], [[1, 2, 3, 4, 5]], [['Banana', 'Orange', 'Apple', 'Mango', 0, 2, 2]], [['C', 'W', 'W', 'W', 1, 2, 0]], [['Hackathon', 'Katathon', 'Code', 'CodeWars', 'Laptop', 'Macbook', 'JavaScript', 1, 5, 2]], [[66, 't', 101, 0, 1, 1]], [[78, 117, 110, 99, 104, 117, ...
coding
131
Solve the programming task below in a Python markdown code block. Here's a way to construct a list containing every positive rational number: Build a binary tree where each node is a rational and the root is `1/1`, with the following rules for creating the nodes below: * The value of the left-hand node below `a/b` is ...
{"functional": "_inputs = [[0], [3], [4], [10], [1000000000]]\n_outputs = [[[1, 1]], [[1, 3]], [[3, 2]], [[5, 2]], [[73411, 65788]]]\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
461
Solve the programming task below in a Python markdown code block. Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew ...
{"inputs": ["1\n0\n1\n", "1\n1\n0\n", "2\n0 0\n1 2\n", "2\n0 0\n2 1\n", "2\n0 1\n0 2\n", "2\n0 2\n0 1\n", "2\n1 0\n0 2\n", "3\n0 0 0\n2 3 1\n"], "outputs": ["0\n", "1\n", "0\n", "4\n", "3\n", "1\n", "3\n", "6\n"]}
coding
584
Solve the programming task below in a Python markdown code block. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in t...
{"inputs": ["1 1 1\n1\n", "1 1 1\n0\n", "1 1 1\n0\n", "1 1 1\n1\n", "2 2 1\n0 1\n1 0\n", "2 2 1\n0 1\n1 0\n", "2 2 2\n0 1\n1 0\n", "2 2 2\n0 1\n0 0\n"], "outputs": ["1 0\n", "0 0\n", "0 0", "1 0", "2 0\n", "2 0", "2 0\n", "1 0\n"]}
coding
445
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following pro...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]) == [5,8,1]\n assert candidate(grid = [[5,2,1],[1,1,2]], queries = [3]) == [0]\n\n\ncheck(Solution().maxPoints)"}
coding
215
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi],[Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. As usual, I went to work in the morning. Unfortunately, I found out that my manager bought a new machine and I have to learn to operate it. There are...
{"inputs": ["1\n3\n2 1 3"], "outputs": ["4"]}
coding
600
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n unique candies (labeled 1 through n) and k bags. You are asked to distribute all the candies into the bags such that every bag has at least one candy. There can be multiple ways to distribute the candies. ...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 2) == 3\n assert candidate(n = 4, k = 2) == 7\n assert candidate(n = 20, k = 5) == 206085257\n\n\ncheck(Solution().waysToDistribute)"}
coding
291
Solve the programming task below in a Python markdown code block. problem One day in the cold winter, JOI Taro decided to break the thin ice in the plaza and play. The square is rectangular and is divided into m sections in the east-west direction and n sections in the north-south direction, that is, m × n. In additio...
{"inputs": ["3\n3\n1 1 0\n1 0 1\n1 1 0\n5\n3\n1 1 1 0 1\n1 1 0 1 0\n1 0 0 0 1\n0\n0", "3\n3\n1 1 0\n1 0 1\n0 1 0\n5\n3\n1 1 0 0 1\n1 1 0 1 0\n1 0 0 0 1\n0\n0", "3\n3\n1 1 0\n1 0 1\n0 1 0\n5\n3\n1 1 0 0 1\n1 1 0 1 0\n1 1 1 0 1\n0\n0", "3\n3\n1 1 0\n1 0 1\n1 1 0\n5\n3\n1 0 1 0 1\n1 1 0 1 0\n1 0 0 0 1\n0\n0", "3\n3\n1 1 0...
coding
527
Solve the programming task below in a Python markdown code block. Jump is a simple one-player game: You are initially at the first cell of an array of cells containing non-negative integers; At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells. You win...
{"functional": "_inputs = [[[11, 6, 11, 0, 2, 1, 14, 3, 7, 6, 2, 1, 10, 6, 0, 0, 8, 10, 2, 12, 13, 11, 14, 6, 1, 4, 14, 3, 10, 4, 14, 2, 3, 10, 8, 13, 14, 8, 2, 13, 11, 14, 0, 1, 6, 2, 1, 6, 8, 2, 0, 12, 4, 9, 2, 6, 8, 14, 4, 14, 4, 10, 8, 7, 12, 11, 0, 3, 8, 0, 13, 9, 9, 11, 10, 13, 12, 1, 0, 10, 14, 6, 1, 11, 7, 8, 6...
coding
424
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef will have N guests in his house today. He wants to serve at least one dish to each of the N guests. Chef can make two types of dishes. He needs one fruit and one...
{"inputs": ["4\n2 1 2 1\n3 2 2 2\n4 2 6 3\n3 1 3 1\n"], "outputs": ["YES\nNO\nYES\nNO"]}
coding
412
Solve the programming task below in a Python markdown code block. Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b. Constraints * 0 < a, b ≤ 2,000,000,000 * LCM(a, b) ≤ 2,000,000,000 * The number of data sets ≤ 50 Input Input consists of several d...
{"inputs": ["13 1\n183 188468232", "13 1\n183 218395056", "13 1\n183 158763340", "13 2\n183 158763340", "11 2\n183 158763340", "8 1\n21473 188468232", "8 1\n32366 188468232", "0 8\n3041947 11770363"], "outputs": ["1 13\n3 11496562152\n", "1 13\n3 13322098416\n", "1 13\n1 29053691220\n", "1 26\n1 29053691220\n", "1 22\n...
coding
204
Solve the programming task below in a Python markdown code block. You are given $n$ words. Some words may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification. Note: Each input line end...
{"inputs": ["4\nbcdef\nabcdefg\nbcde\nbcdef\n"], "outputs": ["3\n2 1 1\n"]}
coding
284
Solve the programming task below in a Python markdown code block. You have been recruited by an unknown organization for your cipher encrypting/decrypting skills. Being new to the organization they decide to test your skills. Your first test is to write an algorithm that encrypts the given string in the following s...
{"functional": "_inputs = [['amz'], ['welcome to the organization'], ['hello'], ['my name is'], ['goodbye']]\n_outputs = [['man'], ['qibkyai ty tfi yvgmzenmteyz'], ['fibby'], ['ao zmai eu'], ['gyyjloi']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
coding
259
Solve the programming task below in a Python markdown code block. A marine themed rival site to Codewars has started. Codwars is advertising their website all over the internet using subdomains to hide or obfuscate their domain to trick people into clicking on their site. Your task is to write a function that accepts ...
{"functional": "_inputs = [['codwars.com'], ['http://codwars.com'], ['http://kcodwars.com'], ['https://www.codwars.com'], ['https://www.codwars.com/kata'], ['codewars.com.codwars.com'], ['https://www.codwars.com/kata?this=is&a=querystring'], ['https://this.is.an.unneccesarily.long.subdomain.codwars.com/katas.are.really...
coding
430
Solve the programming task below in a Python markdown code block. X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10. -----Constraints----- - 0 \leq X, A \leq 9 - All values in input are integers. -----Input----- Input is given from Standard Input in th...
{"inputs": ["0 6", "7 0", "3 0", "0 8", "0 0", "0 3", "9 0", "6 0"], "outputs": ["0\n", "10\n", "10\n", "0\n", "10\n", "0\n", "10\n", "10\n"]}
coding
149
Solve the programming task below in a Python markdown code block. There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you n...
{"inputs": ["2 100\n13 78\n", "4 1\n1 2 3 4\n", "4 1\n1 2 1 2\n", "4 4\n1 2 6 7\n", "4 1\n1 2 3 4\n", "4 4\n1 2 6 7\n", "4 1\n1 2 1 2\n", "2 100\n13 78\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n"]}
coding
581
Solve the programming task below in a Python markdown code block. Chef received an array A of N integers as a valentine's day present. He wants to maximize the length of the longest strictly increasing subsequence by choosing a subarray and adding a fixed integer X to all its elements. More formally, Chef wants to max...
{"inputs": ["3\n3\n1 2 1\n5\n1 5 8 6 9\n4\n1 2 2 1\n"], "outputs": ["3\n5\n3\n"]}
coding
598
Solve the programming task below in a Python markdown code block. You love array, don't you? You are given two integer N and M, along with an array B of length N containing pairwise distinct integers. You have to find the number of array A of length N satisfying the follow conditions: 1. 1 ≤ A_{i} ≤ M. 2. A_{i} \neq ...
{"inputs": ["2 2\n1 3", "3 4\n5 1 2"], "outputs": ["1", "14"]}
coding
594
Solve the programming task below in a Python markdown code block. A total of n depots are located on a number line. Depot i lies at the point x_i for 1 ≤ i ≤ n. You are a salesman with n bags of goods, attempting to deliver one bag to each of the n depots. You and the n bags are initially at the origin 0. You can carr...
{"inputs": ["4\n5 1\n1 1 3 4 1\n9 3\n-9 -6 -6 6 5 8 3 7 4\n5 3\n1 1 6 3 4\n4 2\n1000000000 1000000000 1000000000 1010100000\n", "4\n5 1\n1 1 3 4 1\n9 3\n-9 -18 -6 6 6 8 3 7 4\n5 3\n1 2 6 3 4\n4 2\n1000000010 1000000000 1000000000 1000000000\n", "4\n5 1\n1 1 3 4 1\n9 3\n-9 -22 -6 6 6 8 3 7 4\n5 3\n1 2 6 3 4\n4 2\n100000...
coding
670
Solve the programming task below in a Python markdown code block. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For...
{"inputs": ["b\n25", "b\n11", "b\n16", "a\n16", "a\n25", "xyz\n1", "zyx\n1", "zyx\n2"], "outputs": ["a\n", "m\n", "r\n", "q\n", "z", "xya\n", "ayx\n", "ayy\n"]}
coding
256
Solve the programming task below in a Python markdown code block. Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1). In one move, he can move from (i,j) to either (i+1,j) or (i,j+1). Given an...
{"inputs": ["5", "1", "2", "3", "6", "2\n", "83", "19"], "outputs": ["4\n", "0\n", "1\n", "2\n", "3\n", "1\n", "82\n", "18\n"]}
coding
206
Solve the programming task below in a Python markdown code block. Shik loves sorted intervals. But currently he does not have enough time to sort all the numbers. So he decided to use Almost sorted intervals. An Almost sorted interval is a consecutive subsequence in a sequence which satisfies the following property: T...
{"inputs": ["5\n3 1 2 5 4\n"], "outputs": ["8\n"]}
coding
220
Solve the programming task below in a Python markdown code block. In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage. A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following ...
{"inputs": ["8 5", "0 7", "0 5", "3 4", "4 7", "2 5", "4 8", "3 5"], "outputs": ["0\n", "64\n", "16\n", "4\n", "42\n", "15\n", "99\n", "11\n"]}
coding
452
Solve the programming task below in a Python markdown code block. Chef is teaching his class of N students at Hogwarts. He groups students with the same height together for an activity. Some of the students end up in a groups with only themselves and are saddened by this. With the help of his magic wand, Chef can incr...
{"inputs": ["4\n4\n1 2 1 2\n4\n1 2 2 2\n3\n1 1 1\n5\n1 2 3 4 5\n"], "outputs": ["0\n1\n0\n3\n"]}
coding
519
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers. All gar...
{"functional": "def check(candidate):\n assert candidate(n = 3, paths = [[1,2],[2,3],[3,1]]) == [1,2,3]\n assert candidate(n = 4, paths = [[1,2],[3,4]]) == [1,2,1,2]\n assert candidate(n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]) == [1,2,3,4]\n\n\ncheck(Solution().gardenNoAdj)"}
coding
209
Solve the programming task below in a Python markdown code block. An array is called beautiful if all the elements in the array are equal. You can transform an array using the following steps any number of times: 1. Choose two indices i and j (1 ≤ i,j ≤ n), and an integer x (1 ≤ x ≤ a_i). Let i be the source index...
{"inputs": ["3\n0 0 3\n", "3\n0 3 3\n", "3\n0 1 2\n", "3\n0 2 3\n", "3\n1 3 3\n", "3\n0 3 1\n", "3\n0 3 2\n", "3\n0 1 1\n"], "outputs": ["3", "3\n", "6\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
659
Solve the programming task below in a Python markdown code block. Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as tha...
{"inputs": ["1 2 3 2 5 6\n6 5 4 3 2 1", "1 2 3 2 5 6\n6 1 4 3 2 1", "1 2 3 2 5 6\n6 0 4 3 2 1", "1 2 3 2 5 6\n6 0 4 3 4 1", "1 2 3 2 7 6\n6 0 4 3 4 1", "1 2 3 2 7 3\n6 0 4 3 4 1", "1 2 2 2 7 6\n6 0 4 3 4 1", "1 2 2 2 7 9\n6 0 4 3 4 1"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
235
Solve the programming task below in a Python markdown code block. There is a tree with N vertices numbered 1 through N. The i-th edge connects Vertex x_i and y_i. Each vertex is painted white or black. The initial color of Vertex i is represented by a letter c_i. c_i = W represents the vertex is white; c_i = B represen...
{"inputs": ["1\nB", "1\nB\n", "5\n1 2\n0 3\n2 4\n4 5\nWBBWW", "5\n1 2\n2 3\n2 5\n4 5\nWBBWW", "5\n1 2\n1 3\n2 4\n4 5\nWBBWW", "5\n1 3\n2 3\n2 5\n4 5\nWBBWW", "5\n1 2\n1 3\n3 4\n4 5\nWBBWW", "5\n1 2\n2 3\n2 4\n4 5\nWBBWW"], "outputs": ["0", "0\n", "5\n", "5\n", "5\n", "7\n", "5\n", "5"]}
coding
435
Solve the programming task below in a Python markdown code block. You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top ...
{"inputs": ["2 3\n...\n.#.\n...", "2 3\n...\n.#.\n..-", "2 3\n/..\n.#.\n..-", "2 3\n/..\n.#.\n..,", "3 3\n...\n/#.\n...", "2 3\n...\n.#.\n..,", "3 3\n../\n/#.\n...", "3 3\n-..\n.#.\n..."], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
296
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are "it", and people who are not "it". The people who are "it" want to catch as many people as possible who are no...
{"functional": "def check(candidate):\n assert candidate(team = [0,1,0,1,0], dist = 3) == 2\n assert candidate(team = [1], dist = 1) == 0\n assert candidate(team = [0], dist = 1) == 0\n\n\ncheck(Solution().catchMaximumAmountofPeople)"}
coding
207
Solve the programming task below in a Python markdown code block. Related to MrZizoScream's Product Array kata. You might want to solve that one first :) ```if:javascript **Note:** Node 10 has now been enabled, and you can now use its BigInt capabilities if you wish, though your resulting array must still contain stri...
{"functional": "_inputs = [[[1, 1, 1]], [[0, -99, 0]], [[9, 0, -2]], [[1, 2, 3, 4]], [[2, 3, 4, 5]], [[-8, 1, 5, 13, -1]], [[3, 14, 9, 11, 11]], [[4, 7, 3, 6, 2, 11, 14, 4, 7, 5]]]\n_outputs = [[[1, 1, 1]], [[0, 0, 0]], [[0, -18, 0]], [[24, 12, 8, 6]], [[60, 40, 30, 24]], [[-65, 520, 104, 40, -520]], [[15246, 3267, 508...
coding
298
Solve the programming task below in a Python markdown code block. You're given an ancient book that unfortunately has a few pages in the wrong position, fortunately your computer has a list of every page number in order from ``1`` to ``n``. You're supplied with an array of numbers, and should return an array with each...
{"functional": "_inputs = [[[1, 2, 10, 3, 4, 5, 8, 6, 7]], [[1, 2, 3, 4, 50, 5, 6, 7, 51, 8, 40, 9]], [[1, 2, 3000, 3, 4, 5, 8, 6, 7, 8, 100, 9, 40, 10, 11, 13]], [[1, 2, 3, 4, 50, 5, 6, 7, 51, 8, 9]], [[4, 1, 2, 3, 3, 4, 26, 5, 6, 2, 7]]]\n_outputs = [[[10, 8]], [[50, 51, 40]], [[3000, 8, 100, 40, 13]], [[50, 51]], [[...
coding
171
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer k. A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray. Return the length of the longest possible ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,3,1,3], k = 3) == 3\n assert candidate(nums = [1,1,2,2,1,1], k = 2) == 4\n\n\ncheck(Solution().longestEqualSubarray)"}
coding
131
Solve the programming task below in a Python markdown code block. _Friday 13th or Black Friday is considered as unlucky day. Calculate how many unlucky days are in the given year._ Find the number of Friday 13th in the given year. __Input:__ Year as an integer. __Output:__ Number of Black Fridays in the year as an i...
{"functional": "_inputs = [[1634], [2873], [1586]]\n_outputs = [[2], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n...
coding
144
Solve the programming task below in a Python markdown code block. Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0. Let f(n) be the number of times the following operation will be done when we...
{"inputs": ["3\n111", "3\n110", "3\n101", "3\n100", "3\n001", "3\n011", "23\n00110111001011011001111", "23\n00110111001011011101111"], "outputs": ["2\n2\n1\n", "1\n1\n2\n", "1\n2\n1\n", "0\n1\n2\n", "2\n2\n0\n", "2\n1\n1", "3\n3\n2\n2\n3\n3\n2\n3\n3\n3\n2\n2\n3\n2\n2\n2\n2\n3\n2\n3\n3\n3\n2\n", "4\n4\n3\n3\n4\n3\n3\n3\...
coding
456
Solve the programming task below in a Python markdown code block. The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson. Nam created a sequence a consisting of n (1 ≤ n ...
{"inputs": ["1\n4\n", "1\n7\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n11\n", "2\n5 4\n", "2\n5 4\n"], "outputs": ["3\n", "3", "3", "3", "3", "3", "22\n", "22"]}
coding
667
Solve the programming task below in a Python markdown code block. There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: - The name of every chosen person begins with M, A, R, C or H. - There are no multiple people whose names begin with ...
{"inputs": ["1\nAAA\n", "5\nM\nA\nR\nC\nH\n", "4\nZY\nZZZ\nZ\nZZZZZZZZZZ", "4\nZY\nZZY\nZ\nZZZZZZZZZZ", "4\nZY\nYZZ\nZ\nZZZZZZZZZZ", "4\nZY\nYZZ\nY\nZZZZZZZZZZ", "4\nZY\nZYZ\nY\nZZZZZZZZZZ", "4\nZY\nZYZ\nY\nZYZZZZZZZZ"], "outputs": ["0\n", "10\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
294
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t.   Please complete the following python co...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\", t = \"abcde\") == \"e\"\n assert candidate(s = \"\", t = \"y\") == \"y\"\n\n\ncheck(Solution().findTheDifference)"}
coding
91
Solve the programming task below in a Python markdown code block. Correct this code so that it takes one argument, `x`, and returns "`x` is more than zero" if `x` is positive (and nonzero), and otherwise, returns "`x` is equal to or less than zero." In both cases, replace `x` with the actual value of `x`. Also feel fre...
{"functional": "_inputs = [[8], [1], [-2], [-1], [0]]\n_outputs = [['8 is more than zero.'], ['1 is more than zero.'], ['-2 is equal to or less than zero.'], ['-1 is equal to or less than zero.'], ['0 is equal to or less than zero.']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstanc...
coding
97
Solve the programming task below in a Python markdown code block. Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore t...
{"inputs": ["1\n100\n", "1\n200\n", "1\n200\n", "1\n100\n", "1\n200\n", "2\n100 100\n", "2\n200 200\n", "2\n100 200\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
coding
355
Solve the programming task below in a Python markdown code block. In ChefLand, human brain speed is measured in bits per second (bps). Chef has a threshold limit of X bits per second above which his calculations are prone to errors. If Chef is currently working at Y bits per second, is he prone to errors? If Chef is p...
{"inputs": ["7 9\n", "6 6\n", "53 8\n", "31 53\n"], "outputs": ["YES", "NO", "NO", "YES\n"]}
coding
413
Solve the programming task below in a Python markdown code block. You should have done Product Partitions I to do this second part. If you solved it, you should have notice that we try to obtain the multiplicative partitions with ```n ≤ 100 ```. In this kata we will have more challenging values, our ```n ≤ 10000```. ...
{"functional": "_inputs = [[36, 3], [48, 5], [37, 2], [96, 5], [96, 6]]\n_outputs = [[[8, 3, [[2, 2, 9], [2, 3, 6], [3, 3, 4]]]], [[11, 1, [2, 2, 2, 2, 3]]], [[0, 0, []]], [[18, 2, [[2, 2, 2, 2, 6], [2, 2, 2, 3, 4]]]], [[18, 1, [2, 2, 2, 2, 2, 3]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, floa...
coding
625
Solve the programming task below in a Python markdown code block. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd',...
{"inputs": ["a\n", "a\n", "w\n", "`\n", "x\n", "b\n", "y\n", "c\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
639
Solve the programming task below in a Python markdown code block. Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in ...
{"inputs": ["2 1", "3 1", "1 1", "2 0", "1 9", "1 7", "4 8", "4 1"], "outputs": ["2\n", "3\n", "1\n", "0\n", "9\n", "7\n", "8\n", "4\n"]}
coding
215
Solve the programming task below in a Python markdown code block. Let's play the game using a bag containing several cards with integers written on it. In each game, participants first declare one of their favorite number n. Then, take out an appropriate number of cards from the bag at a time, and if the sum of the num...
{"inputs": ["5\n2 28\n5 4\n5 2\n25 1\n50 2\n4\n228\n714\n100\n168\n7\n1 8\n4 10\n9 10\n17 5\n6 1\n10 15\n110 5\n3\n692\n574\n787\n0", "5\n2 28\n5 4\n5 2\n25 1\n50 2\n4\n228\n714\n100\n168\n7\n1 8\n4 10\n9 10\n17 5\n4 1\n10 15\n110 5\n3\n692\n574\n787\n0", "5\n4 28\n5 4\n5 2\n25 1\n50 2\n4\n228\n714\n100\n168\n7\n1 8\n4...
coding
484
Solve the programming task below in a Python markdown code block. Hardy wants to test Ramanujam of his Mathematical skills. So he gives him a puzzle which is described below. Puzzle: There are 100 doors, numbered 1,2,....100 .Initially all doors are closed. Now a person comes(lets call him the 1st person)he opens the ...
{"inputs": ["400012 31\n10194\n59030\n6930\n39402\n24765\n38154\n147756\n25399\n221328\n30059\n71528\n128184\n18710\n79764\n47450\n176355\n8061\n7335\n82824\n61380\n286810\n634\n7410\n153984\n2277\n46980\n12568\n18390\n173054\n20181\n184416"], "outputs": ["1252\n5968\n890\n4148\n2739\n4027\n13656\n2800\n19724\n3250\n70...
coding
594
Solve the programming task below in a Python markdown code block. In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that t...
{"inputs": ["1 0\n0", "1 2\n0", "1 1\n0", "2 4\n0 2", "2 4\n0 4", "2 6\n0 3", "2 8\n0 5", "2 9\n0 1"], "outputs": ["0\n", "2\n", "1", "6\n", "8\n", "9\n", "13\n", "10\n"]}
coding
369
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef likes sequences of integers and in particular, he likes arithmetic progressions. There are two integers $N$ and $K$. Chef wants to choose a st...
{"inputs": ["2\n2 2\n3 1"], "outputs": ["1\n6"]}
coding
499
Solve the programming task below in a Python markdown code block. Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers $n$ and $k$, count the number of arrays of length $n$ such that: all its elements are integers between $0$ and $2^k-1$ (inclusive); the bit...
{"inputs": ["1\n2 3\n", "1\n2 3\n", "1\n2 2\n", "1\n0 2\n", "1\n1 3\n", "1\n2 4\n", "1\n5 20\n", "1\n9 20\n"], "outputs": ["8\n", "8\n", "4\n", "0\n", "1\n", "16\n", "430973056\n", "953271190\n"]}
coding
321
Solve the programming task below in a Python markdown code block. Chef Shifu and Chef Po are participating in the Greatest Dumpling Fight of 2012. Of course, Masterchef Oogway has formed the rules of the fight. There is a long horizontal rope of infinite length with a center point P. Initially both Chef Shifu and Chef...
{"inputs": ["3\n2 5 0 6 0\n1 4 4 5 2\n10 12 3 1 8", "3\n2 5 0 6 0\n1 4 5 5 2\n10 12 3 1 8", "3\n2 4 0 32 0\n2 1 6 5 1\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 5 5 2\n5 12 3 1 12", "3\n2 4 0 32 0\n2 1 6 5 2\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 8 5 2\n5 12 3 1 12", "3\n2 4 3 6 7\n1 2 4 5 1\n10 12 3 9 16", "3\n2 4 0 10 0\n0 4 4 5 1\n...
coding
533
Solve the programming task below in a Python markdown code block. Snuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct. He is sorting this sequence in increasing order. With supernatural power, he can pe...
{"inputs": ["4\n2\n4\n2\n1", "4\n2\n4\n6\n1", "4\n2\n4\n2\n0", "4\n2\n4\n8\n1", "4\n2\n4\n5\n1", "4\n2\n4\n9\n1", "4\n2\n4\n3\n0", "4\n0\n4\n8\n1"], "outputs": ["1\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n"]}
coding
290
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 true if s is a k-palindrome. A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.   Please complete the following pyth...
{"functional": "def check(candidate):\n assert candidate(s = \"abcdeca\", k = 2) == True\n assert candidate(s = \"abbababa\", k = 1) == True\n\n\ncheck(Solution().isValidPalindrome)"}
coding
95
Solve the programming task below in a Python markdown code block. There is always an integer in Takahashi's mind. Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in h...
{"inputs": ["--+-", "++-+", "++++", "-+-+", "---+", "+---", "-+++", "+++-"], "outputs": ["-2\n", "2\n", "4\n", "0\n", "-2\n", "-2\n", "2\n", "2\n"]}
coding
329
Solve the programming task below in a Python markdown code block. You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second: * Select some distinct indices i_{1}, i_{2}, …, i_{k} which are between 1 and n inclusive, and add 2^{x-1} to each c...
{"inputs": ["3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -7\n", "3\n4\n1 7 6 5\n5\n1 2 1 4 5\n2\n0 -7\n", "3\n4\n1 7 0 5\n5\n1 2 1 4 5\n2\n0 -7\n", "3\n4\n1 7 0 5\n5\n1 2 1 4 5\n2\n1 -7\n", "3\n4\n1 7 6 5\n5\n1 2 6 4 5\n2\n0 -4\n", "3\n4\n1 7 6 5\n5\n1 2 5 4 5\n2\n0 -7\n", "3\n4\n1 7 6 5\n5\n1 4 1 4 5\n2\n0 -7\n", "3\n4\n1 7 1 5...
coding
529
Solve the programming task below in a Python markdown code block. There is an airplane which has n rows from front to back. There will be m people boarding this airplane. This airplane has an entrance at the very front and very back of the plane. Each person has some assigned seat. It is possible for multiple people ...
{"inputs": ["3 3\n", "1 1\n", "1 1\n", "2 1\n", "1 2\n", "3 3\n", "10 1\n", "10 1\n"], "outputs": ["128\n", "2\n", "2\n", "4\n", "0\n", "128\n", "20\n", "20\n"]}
coding
445
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer length and an array updates where updates[i] = [startIdxi, endIdxi, inci]. You have an array arr of length length with all zeros, and you have some operation to apply on arr. In the ith operat...
{"functional": "def check(candidate):\n assert candidate(length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]]) == [-2,0,3,5,3]\n\n\ncheck(Solution().getModifiedArray)"}
coding
146
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese Divyam is teaching his student Amit about palindromes. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. For example,...
{"inputs": ["2\naaa\naca"], "outputs": ["4\n2"]}
coding
392
Solve the programming task below in a Python markdown code block. You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that...
{"inputs": ["z\n", "abc\n", "bbcd\n", "abcd\n", "wxxyxxx\n", "xxxyxxx\n", "hfihihhfh\n", "hhihhhffh\n"], "outputs": ["YES\nz\n", "YES\nabc\n", "YES\ncbdb", "NO\n", "YES\nwxxxxxy", "YES\nxxxxxxy\n", "NO\n", "YES\nfhhhfhihh"]}
coding
341
Solve the programming task below in a Python markdown code block. Math hasn't always been your best subject, and these programming symbols always trip you up! I mean, does `**` mean *"Times, Times"* or *"To the power of"*? Luckily, you can create the function `expression_out()` to write out the expressions for you! ...
{"functional": "_inputs = [['1 + 3'], ['2 - 10'], ['6 ** 9'], ['5 = 5'], ['7 * 4'], ['2 / 2'], ['8 != 5']]\n_outputs = [['One Plus Three'], ['Two Minus Ten'], ['Six To The Power Of Nine'], ['Five Equals Five'], ['Seven Times Four'], ['Two Divided By Two'], ['Eight Does Not Equal Five']]\nimport math\ndef _deep_eq(a, b,...
coding
294
Solve the programming task below in a Python markdown code block. # Task You are given a positive integer `n`. We intend to make some ascending sequences according to the following rules: 1. Make a sequence of length 1: [ n ] 2. Or, insert a number to the left side of the sequence. But this number can not exceed h...
{"functional": "_inputs = [[6], [10], [1000]]\n_outputs = [[6], [14], [1981471878]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fa...
coding
534