task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
The new £5 notes have been recently released in the UK and they've certainly became a sensation! Even those of us who haven't been carrying any cash around for a while, having given in to the convenience of cards, suddenly like to have some of these in t... | {"functional": "_inputs = [[2000, [500, 160, 400]], [1260, [500, 50, 100]], [3600, [1800, 350, 460, 500, 15]], [1995, [1500, 19, 44]], [10000, [1800, 500, 1200, 655, 150]], [2300, [590, 1500, 45, 655, 150]], [5300, [1190, 1010, 1045, 55, 10, 19, 55]], [2000, [500, 495, 100, 900]], [2000, [500, 496, 100, 900]], [2000, [... | 201 | 465 |
coding | Solve the programming task below in a Python markdown code block.
# A wolf in sheep's clothing
Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them.
Warn the sheep in front of the wolf that it is ab... | {"functional": "_inputs = [[['sheep', 'sheep', 'sheep', 'sheep', 'sheep', 'wolf', 'sheep', 'sheep']], [['sheep', 'wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep']], [['wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep']], [['sheep', 'wolf', 'sheep']], [['sheep', 'sheep', 'wolf']]]\n_outputs = [['Oi! Sheep n... | 328 | 348 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given a score log of a football match between two teams. Every time when one of the teams scored a goal, the name of that team was written in the score log on a separ... | {"inputs": ["2\n4\nab\nbc\nbc\nab\n3\nxxx\nyyy\nyyy"], "outputs": ["Draw\nyyy"]} | 361 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of n$n$ integers : A1,A2,...,An$ A_1, A_2,... , A_n$, find the longest size subsequence which satisfies the following property: The xor of adjacent integers in the subsequence must be non-decreasing.
-----Input:-----
- First line contains... | {"inputs": ["8\n1 200 3 0 400 4 1 7"], "outputs": ["6"]} | 275 | 32 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return true if it is a power of two. Otherwise, return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(n = 1) == True\n assert candidate(n = 16) == True\n assert candidate(n = 3) == False\n\n\ncheck(Solution().isPowerOfTwo)"} | 92 | 55 |
coding | 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... | 625 | 314 |
coding | Solve the programming task below in a Python markdown code block.
You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input
The first line contai... | {"inputs": ["1 2\n95\n", "1 2\n96\n", "1 2\n54\n", "1 3\n289\n", "1 3\n250\n", "2 1\n2\n0\n", "2 1\n2\n1\n", "3 1\n1\n2\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "1\n", "1\n"]} | 372 | 117 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
Return the length of n. If there is no such n, return -1.
Note... | {"functional": "def check(candidate):\n assert candidate(k = 1) == 1\n assert candidate(k = 2) == -1\n assert candidate(k = 3) == 3\n\n\ncheck(Solution().smallestRepunitDivByK)"} | 118 | 60 |
coding | Solve the programming task below in a Python markdown code block.
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then ... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n10\n10\n101\n101\n101\n1010\n1010\n1010\n1010"]} | 216 | 58 |
coding | Solve the programming task below in a Python markdown code block.
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i... | {"inputs": ["3\n2 3 5\n3 7 1", "3\n1 3 3\n2 2 1", "3\n1 6 5\n0 1 3", "3\n2 1 5\n3 7 1", "3\n1 6 3\n2 2 1", "3\n0 1 5\n3 7 1", "3\n1 6 3\n2 1 1", "3\n0 1 5\n3 4 1"], "outputs": ["-1\n", "2\n", "0\n", "-1\n", "2\n", "-1\n", "2\n", "-1\n"]} | 727 | 159 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].
A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal dire... | {"functional": "def check(candidate):\n assert candidate(x = 2, y = 1) == 1\n assert candidate(x = 5, y = 5) == 4\n\n\ncheck(Solution().minKnightMoves)"} | 137 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Have you heard about Megamind? Megamind and Metro Man are two aliens who came to earth. Megamind wanted to destroy the earth, while Metro Man wanted to stop him and protect mankind. After a lot of fighting, Megamind finally threw Metro Man up into the sk... | {"functional": "_inputs = [[12, 4, 3, 2], [9, 4, 2, 7], [13, 4, 3, 1], [13, 4, 3, 50], [36, 4, 3, 2], [15, 4, 3, 12], [100000, 99999, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 1, 50000, 49999], [100000, 1, 1000, 999], [17, 4, 4, 16], [23, 4, 4, 13], [1, 4, 4, 15], [22, 4, 4, 13], [16, 4, 4, 16], [20, ... | 684 | 490 |
coding | Solve the programming task below in a Python markdown code block.
N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i.
Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets... | {"inputs": ["3\n3\n6\n5", "3\n4\n1\n2", "3\n3\n1\n1", "3\n5\n1\n1", "3\n2\n1\n1", "3\n1\n2\n1", "3\n3\n3\n5", "3\n5\n1\n4"], "outputs": ["6\n", "3\n", "2\n", "4\n", "1\n", "0\n", "5\n", "5\n"]} | 457 | 110 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A, consisting of N distinct integers.
Calculate number of pairs (i,j) (1 ≤ i < j ≤ N), such that 2 \cdot (A_{i} \oplus A_{j}) = A_{i} + A_{j}, where \oplus denotes [bitwise XOR].
------ Input Format ------
- The first line con... | {"inputs": ["4\n1 2 3 6\n", "5\n4 3 9 7 1"], "outputs": ["2\n", "1"]} | 567 | 38 |
coding | Solve the programming task below in a Python markdown code block.
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.
In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y... | {"inputs": ["`a\n", "a`\n", "aa\n", "aa`\n", "a`a\n", "aaa\n", "aabba\n", "bbaab\n"], "outputs": ["1\n", "1\n", "1\n", "4\n", "3\n", "5\n", "18\n", "18\n"]} | 338 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keywo... | {"functional": "_inputs = [['Welcome home', 'secret'], ['hello', 'wednesday'], ['HELLO', 'wednesday'], ['HeLlO', 'wednesday'], ['WELCOME HOME', 'gridlocked'], ['alpha bravo charlie', 'delta'], ['Home Base', 'seven'], ['basecamp', 'covert'], ['one two three', 'rails'], ['Test', 'unbuntu']]\n_outputs = [['wticljt dljt'],... | 243 | 299 |
coding | Solve the programming task below in a Python markdown code block.
Scheduling is how the processor decides which jobs(processes) get to use the processor and for how long. This can cause a lot of problems. Like a really long process taking the entire CPU and freezing all the other processes. One solution is Shortest Job... | {"functional": "_inputs = [[[100], 0], [[3, 10, 20, 1, 2], 0], [[3, 10, 20, 1, 2], 1], [[3, 10, 10, 20, 1, 2], 1], [[3, 10, 10, 20, 1, 2], 2], [[3, 10, 20, 1, 2, 3], 5], [[3, 10, 20, 1, 2, 10, 10], 5]]\n_outputs = [[100], [6], [16], [16], [26], [9], [26]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | 437 | 323 |
coding | Solve the programming task below in a Python markdown code block.
-----Problem Statement-----
Harry Potter has one biscuit and zero rupee in his pocket. He will perform the following operations exactly $K$ times in total, in the order he likes:
- Hit his pocket, which magically increases the number of biscuits by one.
... | {"inputs": ["4 2 6"], "outputs": ["7"]} | 317 | 16 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is... | {"inputs": ["5\norrer\n2", "5\nrorre\n2", "5\norrer\n1", "5\nrerro\n1", "5\nrerro\n2", "5\nerror\n4", "5\norrer\n4", "5\nserro\n1"], "outputs": ["*rr*r\n", "*o***\n", "o****\n", "r*rr*\n", "*e***\n", "***o*\n", "***e*\n", "s****\n"]} | 188 | 116 |
coding | Solve the programming task below in a Python markdown code block.
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times.
Yo... | {"inputs": ["1 1\n14\n", "1 1\n14\n", "1 1\n32\n", "1 1\n19\n", "1 1\n36\n", "1 1\n99992\n", "1 1\n20000\n", "1 1\n99992\n"], "outputs": ["3\n", "3\n", "5\n", "0\n", "1\n", "11\n", "11\n", "11\n"]} | 495 | 122 |
coding | Solve the programming task below in a Python markdown code block.
*** No Loops Allowed ***
You will be given an array (a) and a value (x). All you need to do is check whether the provided array contains the value, without using a loop.
Array can contain numbers or strings. X can be either. Return true if the array co... | {"functional": "_inputs = [[[66, 101], 66], [[80, 117, 115, 104, 45, 85, 112, 115], 45], [['t', 'e', 's', 't'], 'e'], [['what', 'a', 'great', 'kata'], 'kat'], [[66, 'codewars', 11, 'alex loves pushups'], 'alex loves pushups'], [['come', 'on', 110, '2500', 10, '!', 7, 15], 'Come'], [[\"when's\", 'the', 'next', 'Katathon... | 166 | 395 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of AND triples.
An AND triple is a triple of indices (i, j, k) such that:
0 <= i < nums.length
0 <= j < nums.length
0 <= k < nums.length
nums[i] & nums[j] & nums[k] == 0... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 12\n assert candidate(nums = [0,0,0]) == 27\n\n\ncheck(Solution().countTriplets)"} | 125 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Valera's finally decided to go on holiday! He packed up and headed for a ski resort.
Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider t... | {"inputs": ["1\n1\n0\n", "1\n1\n0\n", "2\n1 1\n0 0\n", "2\n1 1\n0 0\n", "2\n0 1\n0 0\n", "4\n1 0 0 0\n2 3 4 2\n", "4\n1 0 0 0\n2 3 4 2\n", "5\n0 0 0 0 1\n0 1 2 3 4\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n1\n", "5\n1 2 3 4 5\n"]} | 674 | 178 |
coding | Solve the programming task below in a Python markdown code block.
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper... | {"inputs": ["3\n1 1000 1\n", "6\n3 2 1 2 3 3\n"], "outputs": ["0\n", "8\n"]} | 549 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Codeforces separates its users into $4$ divisions by their rating:
For Division 1: $1900 \leq \mathrm{rating}$
For Division 2: $1600 \leq \mathrm{rating} \leq 1899$
For Division 3: $1400 \leq \mathrm{rating} \leq 1599$
For Division 4: $\mathrm{rating... | {"inputs": ["2\n114\n514\n", "7\n-789\n1299\n1300\n1399\n1400\n1679\n2300\n"], "outputs": ["Division 4\nDivision 4\n", "Division 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1\n"]} | 460 | 97 |
coding | Solve the programming task below in a Python markdown code block.
It's IPL time and as usual RCB are finding it tough to qualify for playoffs. RCB needs a minimum of $X$ more points to qualify for playoffs in their remaining $Y$ matches. A win, tie and loss in a match will yield $2,1,0$ points respectively to a team.
... | {"inputs": ["2\n10 5\n1 5"], "outputs": ["5\n0"]} | 397 | 23 |
coding | Solve the programming task below in a Python markdown code block.
The SRA company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of... | {"inputs": ["6 4\n100 20 40 20 50 50"], "outputs": ["40"]} | 422 | 34 |
coding | Solve the programming task below in a Python markdown code block.
MoEngage has 3 decks. Each deck consists of N cards, numbered from 1 to N. He draws out 1 card from each deck randomly with each card having an equal probability of being drawn.
MoEngage drew cards numbered A and B from the decks 1 and 2 respectively. N... | {"inputs": ["3\n4 2 3\n6 2 1\n5 2 5\n"], "outputs": ["2\n1\n0\n"]} | 508 | 36 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... +... | {"functional": "def check(candidate):\n assert candidate(arr = [0,2,1,-6,6,-7,9,1,2,0,1]) == True\n assert candidate(arr = [0,2,1,-6,6,7,9,-1,2,0,1]) == False\n assert candidate(arr = [3,3,6,5,-2,2,5,1,-9,4]) == True\n\n\ncheck(Solution().canThreePartsEqualSum)"} | 155 | 113 |
coding | Solve the programming task below in a Python markdown code block.
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., ... | {"inputs": ["2 2 4 1\n2\n", "0 8 5 1\n9\n", "2 0 1 1\n2\n", "2 0 2 1\n2\n", "4 0 4 1\n0\n", "2 2 4 1\n3\n", "0 1 1 1\n0\n", "3 1 3 1\n5\n"], "outputs": ["1", "inf", "0", "inf", "1", "2", "0", "inf"]} | 701 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Ambar is a gardener and have many water jugs in his garden.
The shape of water jug is a cone placed on the top of a cylinder (the radius and height of cylinder and cone and is "r").
There is a jug for each value of "r'. "r" varies from 1 to "n" ("n" be... | {"inputs": ["100"], "outputs": ["106824622"]} | 181 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are?
Constraints
* 1 ≤ A ≤ B < 2^{60}
* A and B are integers.
Input
... | {"inputs": ["7\n8", "7\n7", "7\n9", "7\n15", "7\n20", "7\n33", "7\n10", "7\n32"], "outputs": ["3\n", "1\n", "4", "9\n", "25\n", "52\n", "6\n", "51\n"]} | 195 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it.
There are $N$ atoms numbered from $1$ to $N$. These atoms are especially quirky. Initially, each atom is in n... | {"inputs": ["4 2\n1 2 4 8\n1 5 3 5\n", "4 2\n1 2 4 8\n5 1 3 5\n", "4 2\n1 2 4 8\n5 3 1 5\n", "4 2\n1 2 4 8\n6 5 3 1\n", "4 3\n1 2 4 8\n1 5 3 5\n", "4 3\n1 2 4 8\n5 1 3 5\n", "4 3\n1 2 4 8\n5 3 1 5\n", "4 3\n1 2 4 8\n6 5 3 1\n"], "outputs": ["14\n", "14\n", "14\n", "12\n", "14\n", "14\n", "14\n", "12\n"]} | 680 | 222 |
coding | Solve the programming task below in a Python markdown code block.
Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.
Kyota Ootori has just ... | {"inputs": ["1 1\n", "5 8\n", "5 1\n", "2 2\n", "3 3\n", "9 1\n", "4 2\n", "2 1\n"], "outputs": ["1 ", "2 1 4 3 5 ", "1 2 3 4 5 ", "2 1 ", "2 1 3 ", "1 2 3 4 5 6 7 8 9 ", "1 2 4 3 ", "1 2\n"]} | 647 | 125 |
coding | Solve the programming task below in a Python markdown code block.
Petya has an array of integers $a_1, a_2, \ldots, a_n$. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it.
Petya likes to challenge himself, so he wants to sort array using only $3$-cycles. More fo... | {"inputs": ["7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 2 3\n3\n2 1 3\n3\n3 1 2\n4\n2 1 4 3\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\nYES\nYES\n"]} | 722 | 76 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A string is beautiful if:
It consists of the first k letters of the English lowercase alphabet.
It does not contain any substring of length 2 or more which is a palindrome.
You are given a beautiful string s of leng... | {"functional": "def check(candidate):\n assert candidate(s = \"abcz\", k = 26) == \"abda\"\n assert candidate(s = \"dc\", k = 4) == \"\"\n\n\ncheck(Solution().smallestBeautifulString)"} | 213 | 59 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums of size n.
Consider a non-empty subarray from nums that has the maximum possible bitwise AND.
In other words, let k be the maximum value of the bitwise AND of any subarray of nums.... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,3,2,2]) == 2\n assert candidate(nums = [1,2,3,4]) == 1\n\n\ncheck(Solution().longestSubarray)"} | 153 | 61 |
coding | Solve the programming task below in a Python markdown code block.
To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it.
One of such formats is related to citations. If you refe... | {"inputs": ["5\n1 1 3 5 6\n3\n7 8 9\n0", "5\n1 1 6 5 6\n3\n7 8 9\n0", "5\n1 1 6 4 6\n3\n7 8 9\n0", "5\n1 1 6 4 9\n3\n7 8 9\n0", "5\n1 1 2 4 9\n3\n7 8 9\n0", "5\n1 2 2 4 9\n3\n7 8 9\n0", "5\n1 2 3 5 6\n3\n3 8 9\n0", "5\n1 1 3 5 6\n3\n8 8 9\n0"], "outputs": ["1 1 3 5-6\n7-9\n", "1 1 6 5-6\n7-9\n", "1 1 6 4 6\n7-9\n", "1 ... | 432 | 320 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship... | {"functional": "def check(candidate):\n assert candidate(n = 3, relations = [[1,3],[2,3]]) == 2\n assert candidate(n = 3, relations = [[1,2],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().minimumSemesters)"} | 184 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Omkar is building a waterslide in his water park, and he needs your help to ensure that he does it as efficiently as possible.
Omkar currently has $n$ supports arranged in a line, the $i$-th of which has height $a_i$. Omkar wants to build his waterslide... | {"inputs": ["1\n1\n1\n", "1\n1\n1\n", "1\n1\n0\n", "1\n4\n6 5 5 6\n", "1\n4\n6 5 5 6\n", "1\n4\n6 5 5 7\n", "1\n4\n6 4 5 7\n", "1\n4\n6 4 9 7\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "2\n", "4\n"]} | 685 | 132 |
coding | Solve the programming task below in a Python markdown code block.
Given the number n, return a string which shows the minimum number of moves to complete the tower of Hanoi consisting of n layers.
Tower of Hanoi : https://en.wikipedia.org/wiki/Tower_of_Hanoi
Example - 2 layered Tower of Hanoi
Input: n=2
Start
[[2, ... | {"functional": "_inputs = [[2], [3]]\n_outputs = [['[[2, 1], [], []]\\n[[2], [1], []]\\n[[], [1], [2]]\\n[[], [], [2, 1]]'], ['[[3, 2, 1], [], []]\\n[[3, 2], [], [1]]\\n[[3], [2], [1]]\\n[[3], [2, 1], []]\\n[[], [2, 1], [3]]\\n[[1], [2], [3]]\\n[[1], [], [3, 2]]\\n[[], [], [3, 2, 1]]']]\nimport math\ndef _deep_eq(a, b,... | 160 | 293 |
coding | Solve the programming task below in a Python markdown code block.
You are a *khm*mad*khm* scientist and you decided to play with electron distribution among atom's shells.
You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons.
---... | {"functional": "_inputs = [[1], [10], [11], [22], [23], [47], [50], [52], [60], [61]]\n_outputs = [[[1]], [[2, 8]], [[2, 8, 1]], [[2, 8, 12]], [[2, 8, 13]], [[2, 8, 18, 19]], [[2, 8, 18, 22]], [[2, 8, 18, 24]], [[2, 8, 18, 32]], [[2, 8, 18, 32, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, floa... | 265 | 299 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an input string s, reverse the order of the words.
A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.
Return a string of the words in reverse order c... | {"functional": "def check(candidate):\n assert candidate(s = \"the sky is blue\") == \"blue is sky the\"\n assert candidate(s = \" \u00a0hello world \u00a0\") == \"world hello\"\n assert candidate(s = \"a good \u00a0 example\") == \"example good a\"\n\n\ncheck(Solution().reverseWords)"} | 136 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary... | {"inputs": ["2\n2 4\n1 5"], "outputs": ["2\n1"]} | 388 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Shil likes Round numbers very much . A number is called Round number if its non-negative and its first and last digits are same. For example 0 , 3 , 343 and 50005 are round numbers whereas 1000 is not a round number. Shil has an array A1 , A2 .. AN... | {"inputs": ["10 10\n999999999999980689 -999999999999985424 999999999999997259 -999999999999980547 999999999999980429 999999999999985309 999999999999988309 -999999999999978240 999999999999973229 -999999999999986703 \n2 9 999999999999974279\n2 3 999999999999975369\n2 3 999999999999991679\n2 5 999999999999968959\n1 1 7\n1... | 521 | 393 |
coding | Solve the programming task below in a Python markdown code block.
You are given a non-degenerate triangle (a non-degenerate triangle is a triangle with positive area). The vertices of the triangle have coordinates $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$.
You want to draw a straight line to cut the triangle into tw... | {"inputs": ["4\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n", "20\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n\n4 7\n6 8\n3 5\n\n4 5\n4 7\n6 8\n\n5 8\n1 8\n2 5\n\n3 6\n6 6\n6 3\n\n4 7\n6 8\n3 5\n\n4 5\n... | 437 | 686 |
coding | Solve the programming task below in a Python markdown code block.
Ibis is fighting with a monster.
The health of the monster is H.
Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.
The same spell can be cast multiple times. There is no way ot... | {"inputs": ["9 3\n8 3\n4 4\n2 1", "9 3\n8 3\n4 4\n4 1", "9 3\n2 3\n4 4\n1 1", "9 3\n8 3\n4 2\n2 1", "9 3\n8 3\n4 2\n2 1\n", "10000 1\n1 10000\n", "9999 2\n2 9999\n2 10000\n", "10000 2\n1 9999\n1 10000\n"], "outputs": ["4\n", "3\n", "9\n", "4", "4\n", "100000000\n", "49995000\n", "99990000\n"]} | 350 | 212 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that when given a number >= 0, returns an Array of ascending length subarrays.
```
pyramid(0) => [ ]
pyramid(1) => [ [1] ]
pyramid(2) => [ [1], [1, 1] ]
pyramid(3) => [ [1], [1, 1], [1, 1, 1] ]
```
**Note:** the subarrays should be fil... | {"functional": "_inputs = [[0], [1], [2], [3]]\n_outputs = [[[]], [[[1]]], [[[1], [1, 1]]], [[[1], [1, 1], [1, 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 ... | 134 | 196 |
coding | Solve the programming task below in a Python markdown code block.
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a_1, a_2, ..., a_{n} in the non-decreasing order. The pseu... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["-1\n", "-1\n", "3 2 1 ", "4 3 2 1 ", "5 4 3 2 1 ", "6 5 4 3 2 1 ", "7 6 5 4 3 2 1 ", "8 7 6 5 4 3 2 1 "]} | 374 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Problem
There are $ 2 $ teams, Team UKU and Team Ushi. Initially, Team UKU has $ N $ people and Team Uku has $ M $ people. Team UKU and Team Ushi decided to play a game called "U & U". "U & U" has a common score for $ 2 $ teams, and the goal is to work ... | {"inputs": ["6 5", "5 9", "7 9", "1 1", "1 2", "1 3", "2 3", "3 3"], "outputs": ["2\n", "3\n", "3\n", "2\n", "1\n", "1\n", "3\n", "2\n"]} | 574 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.
Advertisers will put up the ad only if it is possible to place all three logos on th... | {"inputs": ["5 1 2 5 5 2\n", "4 4 2 6 4 2\n", "1 3 1 3 3 1\n", "2 4 1 4 1 4\n", "7 2 7 2 7 3\n", "2 1 3 1 2 2\n", "1 2 2 4 3 2\n", "7 4 3 3 4 3\n"], "outputs": ["5\nAAAAA\nBBBBB\nBBBBB\nCCCCC\nCCCCC\n", "6\nBBBBBB\nBBBBBB\nAAAACC\nAAAACC\nAAAACC\nAAAACC\n", "3\nAAA\nBBB\nCCC\n", "4\nAAAA\nAAAA\nBBBB\nCCCC\n", "7\nAAAAA... | 535 | 262 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N. Find if it is possible to represent N as the sum of several(possibly zero) 2's and several(possibly zero) 7's.
Formally, find if there exist two integers X, Y \ (X, Y ≥ 0) such that 2 \cdot X + 7\cdot Y = N.
------ Input Fo... | {"inputs": ["4\n2\n5\n7\n11\n"], "outputs": ["YES\nNO\nYES\nYES\n"]} | 377 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Mike and Joe are fratboys that love beer and games that involve drinking. They play the following game: Mike chugs one beer, then Joe chugs 2 beers, then Mike chugs 3 beers, then Joe chugs 4 beers, and so on. Once someone can't drink what he is supposed ... | {"functional": "_inputs = [[3, 2], [4, 2], [9, 1000], [0, 1]]\n_outputs = [['Joe'], ['Mike'], ['Joe'], [\"Non-drinkers can't play\"]]\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... | 209 | 193 |
coding | Solve the programming task below in a Python markdown code block.
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingd... | {"inputs": ["7.6\n", "7.5\n", "8.3\n", "9.8\n", "0.9\n", "4.4\n", "2.6\n", "5.0\n"], "outputs": ["8", "8", "8", "GOTO Vasilisa.", "1", "4", "3", "5"]} | 652 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Write a function to split a string and convert it into an array of words. For example:
```python
"Robin Singh" ==> ["Robin", "Singh"]
"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]
```
Also feel free t... | {"functional": "_inputs = [['Robin Singh'], ['CodeWars'], ['I love arrays they are my favorite'], ['1 2 3'], ['']]\n_outputs = [[['Robin', 'Singh']], [['CodeWars']], [['I', 'love', 'arrays', 'they', 'are', 'my', 'favorite']], [['1', '2', '3']], [['']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, f... | 101 | 220 |
coding | Solve the programming task below in a Python markdown code block.
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total.
Each Kinder Surprise can be one of three types:
* it can contain a single sticker and no toy;
* it can co... | {"inputs": ["1\n5 3 2\n", "1\n5 4 2\n", "1\n5 4 4\n", "1\n5 1 4\n", "1\n3 1 4\n", "1\n7 4 4\n", "1\n6 5 2\n", "1\n1926 54 3018\n"], "outputs": ["4\n", "4\n", "2\n", "5\n", "3\n", "4\n", "5\n", "1873\n"]} | 435 | 128 |
coding | Solve the programming task below in a Python markdown code block.
You are given a list/array which contains only integers (positive and negative). Your job is to sum only the numbers that are the same and consecutive. The result should be one list.
Extra credit if you solve it in one line. You can assume there is neve... | {"functional": "_inputs = [[[1, 4, 4, 4, 0, 4, 3, 3, 1]], [[1, 1, 7, 7, 3]], [[-5, -5, 7, 7, 12, 0]], [[3, 3, 3, 3, 1]], [[2, 2, -4, 4, 5, 5, 6, 6, 6, 6, 6, 1]], [[1, 1, 1, 1, 1, 3]], [[1, -1, -2, 2, 3, -3, 4, -4]], [[0, 1, 1, 2, 2]]]\n_outputs = [[[1, 12, 0, 4, 6, 1]], [[2, 14, 3]], [[-10, 14, 12, 0]], [[12, 1]], [[4,... | 264 | 432 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a list of preferences for n friends, where n is always even.
For each person i, preferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list i... | {"functional": "def check(candidate):\n assert candidate(n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]) == 2\n assert candidate(n = 2, preferences = [[1], [0]], pairs = [[1, 0]]) == 0\n assert candidate(n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, ... | 264 | 176 |
coding | Solve the programming task below in a Python markdown code block.
For a positive integer n
* If n is even, divide by 2.
* If n is odd, multiply by 3 and add 1.
If you repeat the above operation, the result will be 1. A problem called "Colatz conjecture" is that repeating this operation for any positive integer n wi... | {"inputs": ["3\n3\n0", "3\n2\n0", "3\n9\n0", "3\n6\n0", "3\n1\n0", "3\n0\n0", "3\n4\n0", "3\n5\n0"], "outputs": ["7\n7\n", "7\n1\n", "7\n19\n", "7\n8\n", "7\n0\n", "7\n", "7\n2\n", "7\n5\n"]} | 382 | 109 |
coding | Solve the programming task below in a Python markdown code block.
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the s... | {"inputs": ["1 10 9 5\n1 2 3 4 5 6 7 8 9 1\n1 1 9 2 3\n", "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 4 5 6 7 8 9 1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 3 5 6 7 8 9 1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 3 5 6 7 6 9 1\n1 1 9 2 3\n", "10 1 9 5\n1\n... | 694 | 366 |
coding | Solve the programming task below in a Python markdown code block.
The door of Snuke's laboratory is locked with a security code.
The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
You are given the current security code S. If S is ... | {"inputs": ["44", "333", "446", "199", "110", "100", "000", "377"], "outputs": ["Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n"]} | 166 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. W... | {"inputs": ["1 1 1\n2\n", "1 2 1\n2\n", "1 1 2\n2\n", "1 2 2\n2\n", "1 0 1\n2\n", "1 0 0\n2\n", "1 1 0\n2\n", "1 4 1\n2\n"], "outputs": ["0", "0", "0", "0", "0\n", "1\n", "0\n", "0\n"]} | 501 | 114 |
coding | Solve the programming task below in a Python markdown code block.
AquaMoon has a string $a$ consisting of only $0$ and $1$. She wants to add $+$ and $-$ between all pairs of consecutive positions to make the absolute value of the resulting expression as small as possible. Can you help her?
-----Input-----
The first ... | {"inputs": ["3\n2\n11\n5\n01101\n5\n10001\n"], "outputs": ["-\n+-++\n+++-\n"]} | 367 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
Input
The input is a sequence of datasets. The end of the i... | {"inputs": ["2 2\n2 8\n0 0", "4 1\n2 7\n0 0", "6 2\n7 8\n0 0", "3 3\n2 1\n0 0", "5 1\n2 7\n0 0", "4 4\n6 4\n0 0", "4 1\n3 8\n0 0", "5 1\n1 7\n0 0"], "outputs": ["Monday\nSunday\n", "Thursday\nSaturday\n", "Wednesday\nThursday\n", "Wednesday\nSunday\n", "Saturday\nSaturday\n", "Sunday\nFriday\n", "Thursday\nMonday\n", "... | 212 | 158 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,4,3,2,5,2]), x = 3), list_node([1,2,2,4,3,5]))\n assert is_same_list(candidate(head = list_node([2,1]), x = 2), list_node([1,2]))\n\n\ncheck(Solution().partition)"} | 142 | 92 |
coding | Solve the programming task below in a Python markdown code block.
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.
For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it e... | {"inputs": ["1 0\n", "2 0\n", "3 0\n", "1 1\n", "2 1\n", "3 1\n", "4 1\n", "5 1\n"], "outputs": ["1\n", "2\n", "3\n", "10\n", "10\n", "30\n", "20\n", "10\n"]} | 251 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted ... | {"inputs": ["t\n", "N\n", "s\n", "O\n", "r\n", "P\n", "q\n", "Q\n"], "outputs": ["t", "N", "s\n", "O\n", "r\n", "P\n", "q\n", "Q\n"]} | 255 | 68 |
coding | Solve the programming task below in a Python markdown code block.
An array $b$ is good if the sum of elements of $b$ is even.
You are given an array $a$ consisting of $n$ positive integers. In one operation, you can select an index $i$ and change $a_i := \lfloor \frac{a_i}{2} \rfloor$. $^\dagger$
Find the minimum num... | {"inputs": ["1\n1\n524287\n", "4\n4\n1 1 1 1\n2\n7 4\n3\n1 2 4\n1\n15\n"], "outputs": ["19\n", "0\n2\n1\n4\n"]} | 616 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves ... | {"inputs": ["1 5\n4\n", "1 2\n1\n", "1 1\n2\n", "1 5\n1\n", "1 4\n2\n", "1 1\n1\n", "1 6\n3\n", "1 5\n5\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 592 | 102 |
coding | Solve the programming task below in a Python markdown code block.
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?
Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't ... | {"inputs": ["1\n3\n2 2 1\n", "1\n3\n2 2 0\n", "1\n3\n4 2 0\n", "1\n3\n3 2 0\n", "1\n3\n4 3 0\n", "1\n3\n0 2 0\n", "1\n3\n0 2 1\n", "1\n3\n2 2 2\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | 598 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Recall that a tree is an undirected, connected acyclic graph. We have a weighted tree, $\mathbf{T}$, with $n$ vertices; let $dist_{u,v}$ be the total sum of edge weights on the path between nodes $\mbox{u}$ and $\boldsymbol{\nu}$.
Let's consider all the... | {"inputs": ["3\n1 2 2\n1 3 1\n"], "outputs": ["3\n"]} | 527 | 26 |
coding | Solve the programming task below in a Python markdown code block.
# How much is the fish! (- Scooter )
The ocean is full of colorful fishes. We as programmers want to know the hexadecimal value of these fishes.
## Task
Take all hexadecimal valid characters (a,b,c,d,e,f) of the given name and XOR them. Return the resul... | {"functional": "_inputs = [['pufferfish'], ['puffers'], ['balloonfish'], ['blowfish'], ['bubblefish'], ['globefish'], ['swellfish'], ['toadfish'], ['toadies'], ['honey toads'], ['sugar toads'], ['sea squab'], [''], ['Aeneus corydoras'], ['African glass catfish'], ['African lungfish'], ['Aholehole'], ['Airbreathing catf... | 145 | 485 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You are given a function that should insert an asterisk (`*`) between every pair of **even digits** in the given input, and return it as a string. If the input is a sequence, concat the elements first as a string.
## Input
The input can be an... | {"functional": "_inputs = [[5312708], [9682135], [2222], [1111], [9999], ['0000'], [8], [2], [0], [[1, 4, 64, 68, 67, 23, 1]]]\n_outputs = [['531270*8'], ['96*8*2135'], ['2*2*2*2'], ['1111'], ['9999'], ['0*0*0*0'], ['8'], ['2'], ['0'], ['14*6*4*6*8*67231']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance... | 187 | 304 |
coding | Solve the programming task below in a Python markdown code block.
There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).
For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.
We say a set of choices ... | {"inputs": ["1\n0\n", "1\n1\n", "3\n1 0 1", "3\n1 1 0", "3\n0 0 0", "3\n0 0 0", "3\n1 1 0", "3\n1 0 1"], "outputs": ["0\n", "1\n1\n", "1\n3\n", "1\n2\n", "0\n\n", "0\n\n", "1\n2\n", "1\n3\n"]} | 474 | 116 |
coding | Solve the programming task below in a Python markdown code block.
You are given two arrays A and B, both of length N.
You would like to choose exactly K distinct indices i_{1},i_{2}, \ldots, i_{K} such that \min(A_{i_{1}}+A_{i_{2}}+ \ldots + A_{i_{K}}, B_{i_{1}}+B_{i_{2}}+\ldots + B_{i_{K}}) is maximized. Find this ma... | {"inputs": ["3\n5 3\n4 2 3 1 4\n3 2 5 5 1\n4 2\n1 2 3 4\n4 3 2 1\n6 3\n8 10 3 6 7 2\n4 8 4 1 1 6\n"], "outputs": ["9\n5\n18\n"]} | 553 | 92 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i:
If nums[i] is positive, move nums[... | {"functional": "def check(candidate):\n assert candidate(nums = [2,-1,1,2,2]) == True\n assert candidate(nums = [-1,2]) == False\n assert candidate(nums = [-2,1,-1,-2,-2]) == False\n\n\ncheck(Solution().circularArrayLoop)"} | 240 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
AOR Ika-chan is in a bad mood lately. Apparently, I don't like the ratio of the number of followers to the number of followers of "Ikatta". Currently, AOR Ika-chan has $ A $ followers, $ B $ followers, and a ratio of $ A: B $.
Therefo... | {"inputs": ["7 4 3", "30 7 1", "37 7 1", "35 7 1", "35 1 1", "7 26 3", "35 2 1", "19 2 2"], "outputs": ["1\n", "23\n", "30\n", "28\n", "34\n", "6\n", "33\n", "15\n"]} | 571 | 107 |
coding | Solve the programming task below in a Python markdown code block.
A `bouncy number` is a positive integer whose digits neither increase nor decrease. For example, 1235 is an increasing number, 5321 is a decreasing number, and 2351 is a bouncy number. By definition, all numbers under 100 are non-bouncy, and 101 is the f... | {"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]]\n_outputs = [[0], [0], [0], [525], [8325], [95046], [987048], [9999722967], [99999999999959940181], [99999999999999999999999999999999999999912040301674]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | 284 | 303 |
coding | Solve the programming task below in a Python markdown code block.
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains... | {"inputs": ["1\n1\n", "1\n3\n", "1\n2\n", "2\n3 2\n", "2\n2 1\n", "2\n3 1\n", "2\n1 2\n", "2\n2 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 182 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Description
Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively.
The number of roots shall be counted including the multiple roots.
Input... | {"inputs": ["2\n1 4 3 0\n-1 0 1 1", "2\n1 4 3 0\n-1 0 0 0", "2\n1 4 3 0\n-1 0 1 0", "2\n2 4 3 0\n-1 0 1 0", "2\n1 3 3 1\n-8 0 0 0", "2\n1 4 5 0\n-1 0 0 1", "2\n1 4 5 0\n-1 0 0 0", "2\n1 4 3 1\n-3 0 0 1"], "outputs": ["0 2\n1 0\n", "0 2\n0 0\n", "0 2\n1 1\n", "0 0\n1 1\n", "0 3\n0 0\n", "0 0\n1 0\n", "0 0\n0 0\n", "0 1\... | 196 | 246 |
coding | Solve the programming task below in a Python markdown code block.
Utkarsh is forced to play yet another one of Ashish's games. The game progresses turn by turn and as usual, Ashish moves first.
Consider the 2D plane. There is a token which is initially at $(0,0)$. In one move a player must increase either the $x$ coor... | {"inputs": ["5\n4 1\n4 1\n20 3\n55 4\n768 53\n", "5\n6 1\n2 2\n9 1\n58 4\n4776 53\n", "5\n2 1\n9 1\n10 3\n9 4\n33374 5\n", "5\n6 1\n3 2\n9 1\n58 4\n4776 53\n", "5\n2 1\n9 1\n13 3\n9 4\n33374 5\n", "5\n4 2\n2 1\n6 2\n58 4\n15769 7\n", "5\n4 1\n2 2\n9 1\n58 4\n12041 53\n", "5\n2 1\n9 1\n10 3\n9 4\n33374 57\n"], "outputs"... | 443 | 424 |
coding | Solve the programming task below in a Python markdown code block.
Once N boys and M girls attended a party. You are given a matrix A of N rows and M columns where Aij is 1 if the i-th boy likes the j-th girl, otherwise it will be 0. Note that it is not necessary that if a boy x likes girl y, then girl y should like boy... | {"inputs": ["2\n4 3\n111\n100\n011\n100\n0 1\n10\n1", "2\n4 3\n101\n100\n011\n100\n0 1\n10\n1", "2\n4 3\n101\n100\n001\n100\n0 1\n10\n1", "2\n4 3\n101\n100\n110\n000\n1 2\n10\n2", "2\n4 3\n101\n100\n110\n000\n0 1\n10\n0", "2\n4 3\n101\n100\n010\n100\n2 1\n10\n0", "2\n4 3\n101\n101\n100\n000\n2 1\n10\n0", "2\n4 3\n101\n... | 415 | 310 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive chara... | {"inputs": ["7 2 3", "7 1 3", "3 3 2", "3 2 2", "9 7 2", "6 2 3", "5 2 3", "9 7 3"], "outputs": ["116\n", "128\n", "4\n", "6\n", "242\n", "55\n", "25\n", "129\n"]} | 260 | 104 |
coding | Solve the programming task below in a Python markdown code block.
There were initially X million people in a town, out of which Y million people left the town and Z million people immigrated to this town.
Determine the final population of town in millions.
------ Input Format ------
- The first line of input will ... | {"inputs": ["4\n3 1 2\n2 2 2\n4 1 8\n10 1 10\n"], "outputs": ["4\n2\n11\n19\n"]} | 315 | 48 |
coding | Solve the programming task below in a Python markdown code block.
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.
He is famous across the country for his ability to foresee... | {"inputs": ["2\n1 2", "2\n2 3", "2\n2 5", "2\n4 5", "2\n2 7", "2\n7 8", "2\n2 6", "2\n3 5"], "outputs": ["2000\n", "1500\n", "2500\n", "1250\n", "3500\n", "1142\n", "3000\n", "1666\n"]} | 398 | 118 |
coding | Solve the programming task below in a Python markdown code block.
You drop a ball from a given height. After each bounce, the ball returns to some fixed proportion of its previous height. If the ball bounces to height 1 or less, we consider it to have stopped bouncing. Return the number of bounces it takes for the ball... | {"functional": "_inputs = [[2, 0.5], [4, 0.5], [10, 0.1], [100, 0.1], [9, 0.3], [30, 0.3]]\n_outputs = [[1], [2], [1], [2], [2], [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, abs_tol=tol)\n if isinstance(a, (list... | 246 | 219 |
coding | Solve the programming task below in a Python markdown code block.
Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", — Volodya said and was right for sure. And yo... | {"inputs": ["e8 e7 d8 g8\n", "b3 a8 d3 a3\n", "b2 c2 b3 b1\n", "c6 b2 g6 b4\n", "a5 c5 c3 a1\n", "d4 e5 b7 a5\n", "e8 e7 f8 h8\n", "h7 h8 c7 a8\n"], "outputs": ["CHECKMATE\n", "OTHER\n", "OTHER\n", "OTHER\n", "OTHER\n", "CHECKMATE\n", "OTHER\n", "OTHER\n"]} | 405 | 130 |
coding | Solve the programming task below in a Python markdown code block.
We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.
In how many ways can we choose three of the sticks with different lengths that can form a triangle?
That is, find the number of triples of integers (i, j, k) (1 \leq i ... | {"inputs": ["1\n1\n", "2\n1 0", "2\n0 0", "2\n0 1", "2\n3 0", "2\n3 1", "2\n2 1", "2\n2 2"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 316 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Speedcubing is the hobby involving solving a variety of twisty puzzles, the most famous being the 3x3x3 puzzle or Rubik's Cube, as quickly as possible.
In the majority of Speedcubing competitions, a Cuber solves a scrambled cube 5 times, and their resul... | {"functional": "_inputs = [[[9.5, 7.6, 11.4, 10.5, 8.1]], [[13.4, 12.3, 9.5, 11.9, 20.8]], [[28.3, 14.5, 17.3, 8.9, 10.1]]]\n_outputs = [[[9.37, 7.6]], [[12.53, 9.5]], [[13.97, 8.9]]]\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... | 302 | 268 |
coding | Solve the programming task below in a Python markdown code block.
The government has invited bids from contractors to run canteens at all railway stations. Contractors will be allowed to bid for the catering contract at more than one station. However, to avoid monopolistic price-fixing, the government has declared that... | {"inputs": ["6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4"], "outputs": ["90"]} | 517 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.
A substring is a contiguous non-empty sequence of chara... | {"functional": "def check(candidate):\n assert candidate(s = \"abcba\") == 7\n assert candidate(s = \"abacad\") == 9\n assert candidate(s = \"a\") == 1\n\n\ncheck(Solution().numberOfSubstrings)"} | 96 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp found the string $s$ and the permutation $p$. Their lengths turned out to be the same and equal to $n$.
A permutation of $n$ elements — is an array of length $n$, in which every integer from $1$ to $n$ occurs exactly once. For example, $[1, 2, ... | {"inputs": ["1\n12\nzsmlzcqpszjy\n2 3 4 5 6 7 8 9 10 11 12 1\n", "3\n5\nababa\n3 4 5 2 1\n5\nababa\n2 1 4 5 3\n10\ncodeforces\n8 6 1 7 5 2 9 3 10 4\n", "1\n26\nofnbnccxwsnaxyjwnmefjhkwmi\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1\n", "1\n78\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqq... | 653 | 497 |
coding | Solve the programming task below in a Python markdown code block.
The male gametes or sperm cells in humans and other mammals are heterogametic and contain one of two types of sex chromosomes. They are either X or Y. The female gametes or eggs however, contain only the X sex chromosome and are homogametic.
The sperm c... | {"functional": "_inputs = [['XY'], ['XX']]\n_outputs = [[\"Congratulations! You're going to have a son.\"], [\"Congratulations! You're going to have a daughter.\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=t... | 215 | 181 |
coding | Solve the programming task below in a Python markdown code block.
You are given a tree with N nodes and each has a value associated with it. You are given Q queries, each of which is either an update or a retrieval operation.
Initially all node values are zero.
The update query is of the format
a1 d1 a2 d2 A B
T... | {"inputs": ["7 2\n1 2\n1 3\n2 4\n2 6\n4 5\n6 7\n1 4\n1 1 1 1 4 6\n4 5\n2 7\n4 7\n5 3\n"], "outputs": ["1\n44\n45\n9\n"]} | 649 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist.
-----... | {"inputs": ["1\n3\n4 4 4", "1\n3\n2 5 1", "1\n3\n4 6 4", "1\n3\n4 6 0", "1\n3\n4 6 3", "1\n3\n2 2 3", "1\n3\n4 4 0", "1\n3\n7 6 3"], "outputs": ["3\n1 2 3 \n", "2\n2 3 \n", "1\n2 \n", "1\n2 \n", "1\n2 \n", "1\n3 \n", "1\n3 \n", "1\n2 \n"]} | 377 | 164 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between the ma... | {"inputs": ["3 3\n7 12 8\n", "3 3\n7 12 8\n", "4 5\n3 1 7 5\n", "4 5\n3 1 7 5\n", "5 1\n6 4 6 7 7\n", "5 1\n6 4 6 7 7\n", "5 1\n6 4 6 11 7\n", "3 10\n100 100 100\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "6\n", "0\n"]} | 411 | 160 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A pangram is a sentence where every letter of the English alphabet appears at least once.
Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.
... | {"functional": "def check(candidate):\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"leetcode\") == False\n\n\ncheck(Solution().checkIfPangram)"} | 91 | 54 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are several squares being dropped onto the X-axis of a 2D plane.
You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi t... | {"functional": "def check(candidate):\n assert candidate(positions = [[1,2],[2,3],[6,1]]) == [2,5,5]\n assert candidate(positions = [[100,100],[200,100]]) == [100,100]\n\n\ncheck(Solution().fallingSquares)"} | 229 | 83 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B,... | {"inputs": ["8 3\n0\n2\n4\n0\n5\n6\n9\n7\n4\n4", "8 3\n1\n5\n2\n3\n6\n6\n9\n8\n4\n1", "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n4\n4", "10 3\n1\n5\n4\n3\n6\n6\n9\n7\n4\n4", "10 3\n0\n1\n4\n3\n6\n6\n9\n7\n4\n4", "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n3\n4", "10 1\n0\n1\n4\n0\n5\n9\n9\n7\n8\n4", "10 3\n1\n5\n2\n0\n6\n6\n9\n8\n4\n1"], "outp... | 220 | 245 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:
s[i] == 'I' if perm[i] < perm[i + 1], and
s[i] == 'D' if perm[i] > perm[i + 1].
Given ... | {"functional": "def check(candidate):\n assert candidate(s = \"IDID\") == [0,4,1,3,2]\n assert candidate(s = \"III\") == [0,1,2,3]\n assert candidate(s = \"DDI\") == [3,2,0,1]\n\n\ncheck(Solution().diStringMatch)"} | 146 | 81 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.