task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
There are N boxes arranged in a circle. The i-th box contains A_i stones.
Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:
* Select one box. Let the box be the i-th box. Then, fo... | {"inputs": ["4\n2 2 3 1", "4\n2 2 3 2", "4\n2 1 3 2", "4\n4 1 3 2", "4\n4 1 3 0", "4\n4 1 3 1", "4\n4 1 6 2", "4\n0 1 9 6"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 268 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Remember the movie with David Bowie: 'The Labyrinth'?
You can remember your childhood here: https://www.youtube.com/watch?v=2dgmgub8mHw
In this scene the girl is faced with two 'Knights" and two doors. One door leads the castle where the Goblin King an... | {"functional": "_inputs = [[True], [False], ['4+2==5'], ['2+2==4'], ['not True and False or False or False'], ['3 is 3'], ['True'], ['not True'], ['2+2==5'], ['4+1==5'], ['4 is 3'], ['9+2==3'], ['105+30076==30181'], ['3 is 3 is 3 is 9'], ['False'], ['\"orange\" is not \"red\"'], ['4 is \"blue\"'], ['True is not False']... | 376 | 399 |
coding | Solve the programming task below in a Python markdown code block.
Given few numbers, you need to print out the digits that are not being used.
Example:
```python
unused_digits(12, 34, 56, 78) # "09"
unused_digits(2015, 8, 26) # "3479"
```
Note:
- Result string should be sorted
- The test case won't pass Integer wit... | {"functional": "_inputs = [[12, 34, 56, 78], [2015, 8, 26], [276, 575], [643], [864, 896, 744], [364, 500, 715, 730], [93, 10, 11, 40], [1, 11, 111, 1111, 11111], [9, 87, 654, 3210]]\n_outputs = [['09'], ['3479'], ['013489'], ['0125789'], ['01235'], ['289'], ['25678'], ['023456789'], ['']]\nimport math\ndef _deep_eq(a,... | 125 | 346 |
coding | Solve the programming task below in a Python markdown code block.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borr... | {"inputs": ["1 2 1\n", "1 1 1\n", "1 5 6\n", "1 5 6\n", "1 2 1\n", "1 1 1\n", "1 0 1\n", "3 0 4\n"], "outputs": ["0", "0", "16", "16\n", "0\n", "0\n", "1\n", "30\n"]} | 202 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with $6$ places after the decimal.
Note: This challenge introduces precision problems. The te... | {"inputs": ["6 \n-4 3 -9 0 4 1\n"], "outputs": ["0.500000\n0.333333\n0.166667\n"]} | 556 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Two players (numbered $\mbox{1}$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows:
Player $\mbox{1}$ always moves first.
Initially there are $N$ towers of various heights.
The players move in alternating turns. In each... | {"inputs": ["2\n2 \n1 2\n3 \n1 2 3\n"], "outputs": ["1\n2\n"]} | 534 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of anoth... | {"inputs": ["a\nz\n", "y\ny\n", "z\nz\n", "a\nz\n", "z\na\n", "z\nz\n", "y\ny\n", "z\na\n"], "outputs": ["1\na z\n", "0\n", "0\n", "1\na z\n", "1\nz a\n", "0\n", "0\n", "1\nz a\n"]} | 422 | 98 |
coding | Solve the programming task below in a Python markdown code block.
A (1-indexed) binary string S of length N is called a *xor palindrome* if the value of S_{i} \oplus S_{(N + 1 - i)} is the same for all 1 ≤ i ≤ N.
For example, 0, 1111 and 0101 are xor palindromes, while 1110 and 110101 are not.
You are given a binary ... | {"inputs": ["4\n2\n00\n4\n0011\n3\n001\n4\n0001\n"], "outputs": ["YES\nYES\nYES\nNO\n"]} | 665 | 45 |
coding | Solve the programming task below in a Python markdown code block.
This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a se... | {"inputs": ["1\n7\n2\n7 9\n", "1\n6\n2\n7 9\n", "1\n6\n2\n7 16\n", "2\n6 10\n3\n6 3 3\n", "2\n1 10\n3\n6 3 3\n", "2\n2 10\n3\n6 3 3\n", "2\n5 2\n4\n8 8 0 4\n", "2\n5 2\n4\n8 8 0 8\n"], "outputs": ["1\n7 \n", "0\n\n", "0\n\n", "1\n6 \n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]} | 382 | 174 |
coding | Solve the programming task below in a Python markdown code block.
# Story&Task
There are three parties in parliament. The "Conservative Party", the "Reformist Party", and a group of independants.
You are a member of the “Conservative Party” and you party is trying to pass a bill. The “Reformist Party” is trying to b... | {"functional": "_inputs = [[8, 3, 3], [13, 4, 7], [7, 4, 3], [11, 4, 1], [11, 5, 1], [11, 6, 1], [11, 4, 4], [11, 5, 4], [11, 5, 5], [11, 4, 6], [11, 4, 5], [15, 9, 3], [16, 7, 8], [16, 8, 7], [16, 1, 8]]\n_outputs = [[2], [-1], [0], [2], [1], [0], [2], [1], [1], [-1], [2], [0], [-1], [1], [-1]]\nimport math\ndef _deep... | 657 | 342 |
coding | Solve the programming task below in a Python markdown code block.
*This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)*
##Object
Find the last number between 1 and `n` (inclusive) that survives the elimination process
####How It Works
Start with the first number on the left then ... | {"functional": "_inputs = [[9], [10], [100], [1000], [50000]]\n_outputs = [[6], [8], [54], [510], [22358]]\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(... | 324 | 197 |
coding | Solve the programming task below in a Python markdown code block.
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
-----Input-----
A single line contains a n... | {"inputs": ["a\n", "A\n", "z\n", "P\n", "z\n", "a\n", "P\n", "A\n"], "outputs": ["A\n", "A\n", "Z\n", "P\n", "Z\n", "A\n", "P\n", "A\n"]} | 124 | 70 |
coding | Solve the programming task below in a Python markdown code block.
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
TABLE ::= <table>ROWS</table... | {"inputs": ["<table><tr><td></td></tr></table>\n", "<\nt\na\nble><tr><td></td>\n</\ntr>\n</\nt\nab\nle>\n", "<table><tr><td><table><tr><td></td></tr></table></td></tr></table>\n", "<table><tr><td></td></tr></table>\n", "<table><tr><td><table><tr><td><table><tr><td></td></tr></table><... | 706 | 378 |
coding | Solve the programming task below in a Python markdown code block.
This contest, AtCoder Beginner Contest, is abbreviated as ABC.
When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.
What is the abbreviation for the N-th round of ABC? Write ... | {"inputs": ["7", "3", "4", "8", "9", "0", "1", "2"], "outputs": ["ABC7\n", "ABC3\n", "ABC4\n", "ABC8\n", "ABC9\n", "ABC0\n", "ABC1\n", "ABC2\n"]} | 161 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record.
You are given a list of strings operations, where operations[i] is the ith operation you... | {"functional": "def check(candidate):\n assert candidate(ops = [\"5\",\"2\",\"C\",\"D\",\"+\"]) == 30\n assert candidate(ops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]) == 27\n assert candidate(ops = [\"1\"]) == 1\n\n\ncheck(Solution().calPoints)"} | 210 | 87 |
coding | Solve the programming task below in a Python markdown code block.
An array A of length N is said to be *pseudo-sorted* if it can be made non-decreasing after performing the following operation at most once.
Choose an i such that 1 ≤ i ≤ N-1 and swap A_{i} and A_{i+1}
Given an array A, determine if it is *pseudo-sorted... | {"inputs": ["3\n5\n3 5 7 8 9\n4\n1 3 2 3\n3\n3 2 1\n"], "outputs": ["YES\nYES\nNO\n"]} | 442 | 48 |
coding | Solve the programming task below in a Python markdown code block.
There are N gems. The value of the i-th gem is V_i.
You will choose some of these gems, possibly all or none, and get them.
However, you need to pay a cost of C_i to get the i-th gem.
Let X be the sum of the values of the gems obtained, and Y be the sum ... | {"inputs": ["1\n1\n45", "1\n15\n0", "1\n56\n2", "1\n1\n50", "1\n1\n50\n", "1\n6\n-10", "1\n28\n-1", "1\n111\n2"], "outputs": ["0\n", "15\n", "54\n", "0", "0\n", "16\n", "29\n", "109\n"]} | 262 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}.
Let X_{i} denote the [bitwise AND] of all elem... | {"inputs": ["2\n2 2\n2 3\n"], "outputs": ["3\n12"]} | 611 | 24 |
coding | 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 whose length is a power of 2.
Apply the following algorithm on nums:
Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer arr... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,2,4,8,2,2]) == 1\n assert candidate(nums = [3]) == 3\n\n\ncheck(Solution().minMaxGame)"} | 231 | 58 |
coding | Solve the programming task below in a Python markdown code block.
# Description:
Find the longest successive exclamation marks and question marks combination in the string. A successive exclamation marks and question marks combination must contains two part: a substring of "!" and a substring "?", they are adjacent. ... | {"functional": "_inputs = [['!!'], ['!??'], ['!?!!'], ['!!???!????'], ['!!???!?????'], ['!????!!!?'], ['!?!!??!!!?']]\n_outputs = [[''], ['!??'], ['?!!'], ['!!???'], ['!?????'], ['????!!!'], ['??!!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | 280 | 211 |
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 head, in which each node contains an integer value.
Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.
Return the linked ... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([18,6,10,3])), list_node([18,6,6,2,10,1,3]))\n assert is_same_list(candidate(head = list_node([7])), list_node([7]))\n\n\ncheck(Solution().insertGreatestCommonDivisors)"} | 161 | 85 |
coding | Solve the programming task below in a Python markdown code block.
We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite qua... | {"inputs": ["21 3 64", "21 0 64", "4 767 636", "7 770 636", "5 936 910", "15 90 456", "8 18 2018", "28 90 542"], "outputs": ["3\n", "0\n", "4\n", "7\n", "5\n", "15\n", "24\n", "28\n"]} | 308 | 125 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.
Please complete the following python code precisely:
```python
class Solution:
def findDiagonalOrder(self, mat: Li... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,2,3],[4,5,6],[7,8,9]]) == [1,2,4,7,5,3,6,8,9]\n assert candidate(mat = [[1,2],[3,4]]) == [1,2,3,4]\n\n\ncheck(Solution().findDiagonalOrder)"} | 75 | 91 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A containing N integers. Find if it is possible to choose exactly M elements from the array such that the MEX of the chosen elements is exactly K.
Recall that the *MEX* of an array is the smallest non-negative integer that does no... | {"inputs": ["6\n5 4 2\n0 1 3 0 3\n2 1 2\n0 1\n3 3 3\n0 1 2\n4 3 3\n2 0 4 3\n5 4 2\n0 2 1 2 5\n6 5 2\n0 1 0 2 0 3\n"], "outputs": ["YES\nNO\nYES\nNO\nNO\nYES\n"]} | 635 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.
At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th specta... | {"inputs": ["5 3 5\n", "3 2 4\n", "6 1 4\n", "2 2 3\n", "5 4 6\n", "2 1 2\n", "2 2 2\n", "5 5 6\n"], "outputs": ["3\n", "1\n", "1\n", "1\n", "3\n", "1\n", "2\n", "4\n"]} | 666 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Alice, Bob and Charlie are bidding for an artifact at an auction.
Alice bids A rupees, Bob bids B rupees, and Charlie bids C rupees (where A, B, and C are distinct).
According to the rules of the auction, the person who bids the highest amount will w... | {"inputs": ["4\n200 100 400\n155 1000 566\n736 234 470\n124 67 2\n"], "outputs": ["Charlie\nBob\nAlice\nAlice\n"]} | 392 | 66 |
coding | Solve the programming task below in a Python markdown code block.
How much bigger is a 16-inch pizza compared to an 8-inch pizza? A more pragmatic question is: How many 8-inch pizzas "fit" in a 16-incher?
The answer, as it turns out, is exactly four 8-inch pizzas. For sizes that don't correspond to a round number of 8... | {"functional": "_inputs = [[16], [12], [8], [6], [0]]\n_outputs = [['pizzas: 4, slices: 0'], ['pizzas: 2, slices: 2'], ['pizzas: 1, slices: 0'], ['pizzas: 0, slices: 4'], ['pizzas: 0, slices: 0']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | 254 | 228 |
coding | Solve the programming task below in a Python markdown code block.
In this kata the function returns an array/list like the one passed to it but with its nth element removed (with `0 <= n <= array/list.length - 1`). The function is already written for you and the basic tests pass, but random tests fail. Your task is to ... | {"functional": "_inputs = [[[9, 7, 6, 9], 0]]\n_outputs = [[[7, 6, 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_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | 201 | 173 |
coding | Solve the programming task below in a Python markdown code block.
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array st... | {"inputs": ["1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n1000\n", "1\n1001\n", "1\n0001\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 346 | 95 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well.
You are given a positive integer N. You have to print exactly N + 1 positive integers
satisfying the following conditions:
Exactly one value should appear twice, all the remai... | {"inputs": ["2\n3\n4\n"], "outputs": ["1 2 2 3\n1 2 3 3 7"]} | 371 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this cou... | {"inputs": ["5 3 2\n", "5 4 2\n", "2 0 2\n", "2 1 2\n", "2 2 2\n", "3 2 2\n", "3 3 2\n", "2 2 2\n"], "outputs": ["3\n", "6\n", "0\n", "1\n", "4\n", "2\n", "5\n", "4\n"]} | 552 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Your dad doesn't really *get* punctuation, and he's always putting extra commas in when he posts. You can tolerate the run-on sentences, as he does actually talk like that, but those extra commas have to go!
Write a function called ```dadFilter``` that ... | {"functional": "_inputs = [['all this,,,, used to be trees,,,,,,'], ['Listen,,,, kid,,,,,,'], ['Luke,,,,,,,,, I am your father,,,,,,,,, '], [\"i,, don't believe this round earth,,, show me evadence!!\"], [\"Dead or alive,,,, you're coming with me,,, \"]]\n_outputs = [['all this, used to be trees'], ['Listen, kid'], ... | 119 | 267 |
coding | Solve the programming task below in a Python markdown code block.
IIST is thinking of acquiring some land nearby to build its new state of the art labs. The land it has chosen incidentaly has some abandoned college buildings which IIST wants to use. The administration decide the value of the building based on the amoun... | {"inputs": ["2\n6\n0 0 8 3\n1 4 3 2\n2 1 7 1\n4 1 2 3\n3 5 4 6\n2 3 9 8\n3\n3 0 10 2\n5 5 20 25\n7 -3 30 32"], "outputs": ["2 4 5\n3.16\n2\n15.00"]} | 494 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Bengali] and [Vietnamese] as well.
Ghayeeth is a math teacher. He likes playing games, so he invented a new game which he wants to play against his student Siroj. The rules of the game are as follows:
Initially, Ghayeeth writes... | {"inputs": ["2\n3\n7 9 11\n2\n13 15"], "outputs": ["Ghayeeth\nSiroj"]} | 450 | 36 |
coding | Solve the programming task below in a Python markdown code block.
There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked... | {"inputs": ["3\n0 0 1\n0 0 1\n1 1 0\n", "3\n0 0 0\n0 0 1\n0 1 0\n", "3\n0 0 1\n0 0 1\n1 1 0\n", "3\n0 0 0\n0 0 1\n0 1 0\n", "4\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 1 1 0\n", "4\n0 0 0 1\n0 0 0 0\n0 0 0 1\n1 0 1 0\n", "4\n0 0 1 0\n0 0 0 1\n1 0 0 0\n0 1 0 0\n", "4\n0 0 1 0\n0 0 0 1\n1 0 0 0\n0 1 0 0\n"], "outputs": ["1\n", "0\n... | 458 | 271 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integers, num and t. A number is achievable if it can become equal to num after applying the following operation:
Increase or decrease the number by 1, and simultaneously increase or decrease num by 1.
Ret... | {"functional": "def check(candidate):\n assert candidate(num = 4, t = 1) == 6\n assert candidate(num = 3, t = 2) == 7\n\n\ncheck(Solution().theMaximumAchievableX)"} | 112 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
During a fight with the Joker, Batman's eyes lose the capability to distinguish between some pairs of colors.
Each color has an integer ID from 1 to N. There... | {"inputs": ["3\n2 2 2\n1 2\n1 1\n2 1\n2 2 4\n1 1\n1 2\n1 2 2 1\n3 2 3\n2 1 3\n1 2\n1 3 1"], "outputs": ["2\n3\n1"]} | 612 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved pro... | {"inputs": ["3\n3 4 2\n", "3\n3 4 3\n", "3\n2 4 3\n", "3\n2 4 6\n", "3\n2 2 6\n", "3\n2 2 7\n", "3\n2 4 7\n", "3\n0 4 8\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n"]} | 516 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.
Please complete the following python code precisely:
```python
# Definition for ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([4,2,6,1,3])) == 1\n assert candidate(root = tree_node([1,0,48,None,None,12,49])) == 1\n\n\ncheck(Solution().minDiffInBST)"} | 129 | 70 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$.
Your problem is to find such pair of indices $i, j$ ($1 \le i < j \le n$) that $lcm(a_i, a_j)$ is minimum possible.
$lcm(x, y)$ is the least common multiple of $x$ and $y$ (m... | {"inputs": ["2\n1 1\n", "2\n7 2\n", "2\n6 7\n", "2\n4 4\n", "2\n8 8\n", "2\n6 5\n", "2\n8 8\n", "2\n6 5\n"], "outputs": ["1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n"]} | 349 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).
Return the indices of people whose list of favorite companies is not a subset of any... | {"functional": "def check(candidate):\n assert candidate(favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"google\",\"microsoft\"],[\"google\",\"facebook\"],[\"google\"],[\"amazon\"]]) == [0,1,4] \n assert candidate(favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"leetcode\",\"amazon\"]... | 108 | 137 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of water. If it rains over a lake that is full of water, there will be a... | {"functional": "def check(candidate):\n assert candidate(rains = [1,2,3,4]) == [-1,-1,-1,-1]\n assert candidate(rains = [1,2,0,0,2,1]) == [-1,-1,2,1,-1,-1]\n assert candidate(rains = [1,2,0,1,2]) == []\n\n\ncheck(Solution().avoidFlood)"} | 263 | 101 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].
Return the... | {"functional": "def check(candidate):\n assert candidate(nums = [8,1,2,2,3]) == [4,0,1,1,3]\n assert candidate(nums = [6,5,4,8]) == [2,1,0,3]\n assert candidate(nums = [7,7,7,7]) == [0,0,0,0]\n\n\ncheck(Solution().smallerNumbersThanCurrent)"} | 114 | 101 |
coding | Solve the programming task below in a Python markdown code block.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples o... | {"inputs": ["6 5 2 1", "9 5 2 1", "0 5 2 1", "6 3 2 1", "12 5 2 1", "-1 5 2 1", "-1 0 2 0", "-1 0 1 0"], "outputs": ["0\n", "3\n", "-6\n", "2", "6\n", "-7\n", "-3\n", "-2\n"]} | 438 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Your job is to return the volume of a cup when given the diameter of the top, the diameter of the bottom and the height.
You know that there is a steady gradient from the top to the bottom.
You want to return the volume rounded to 2 decimal places.
Ex... | {"functional": "_inputs = [[1, 1, 1], [10, 8, 10], [1000, 1000, 1000], [13.123, 123.12, 1], [5, 12, 31]]\n_outputs = [[0.79], [638.79], [785398163.4], [4436.57], [1858.51]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, a... | 230 | 262 |
coding | Solve the programming task below in a Python markdown code block.
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the l... | {"inputs": ["5 5 3\n", "5 7 2\n", "2 2 1\n", "3 5 1\n", "3 6 1\n", "1 5 3\n", "5 4 2\n", "2 2 2\n"], "outputs": ["0\n", "15\n", "0\n", "6\n", "10\n", "0\n", "0\n", "0\n"]} | 401 | 104 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. The result may be large, so ... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 4\n assert candidate(n = 5) == 13\n\n\ncheck(Solution().waysToStep)"} | 117 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:
1. + ai — add non-negative integer ai to the mul... | {"inputs": ["4\n+ 200\n+ 15\n- 200\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n", "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011\n", "10\n+ 2\n- 2\n+ 778\n+ 2\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011\n", "10\n+ 2\n- 2\n+ 778\n+ 0\n+ 4\n- 4\n+ 0\n+ 617\n? 001\n? 011\n", "10\n+ 2\n- 2\n+ 778\n+ 1\n+ 4\n- 4\n+ 1\n+ 6... | 756 | 419 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of positive integers a_1, a_2, ..., a_{n}.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of el... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n2 1 1\n", "3\n2 1 1\n", "4\n3 2 1 1\n", "4\n3 2 1 1\n", "6\n5 2 1 1 2 2\n", "6\n5 3 1 1 2 2\n"], "outputs": ["1\n2 ", "1\n2\n", "1\n3 ", "1\n3\n", "1\n4 ", "1\n4\n", "2\n5 4 ", "3\n5 4 2\n"]} | 683 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p_1, p_2, ..., p_{n}], where p_{i} denotes the n... | {"inputs": ["5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n5 4 3 2 1\n1 5 3\n1 5 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n5 4 3 2 1\n1 5 4\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n3 4 4\n2 5 3\n", "5 5\n5 4 6 2 1\n1 5 4\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "5 5\n8 4 3 2 1\n1 5 3\n1 3 1\n2 ... | 686 | 470 |
coding | Solve the programming task below in a Python markdown code block.
Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string valu... | {"functional": "_inputs = [[['one', 'two', 'three', 'four']], [['one']], [['one', '', 'three']], [['', '', 'three']], [['one', 'two', '']], [[]], [None], [['']]]\n_outputs = [['one, two, three and four'], ['one'], ['one and three'], ['three'], ['one and two'], [''], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5... | 237 | 224 |
coding | Solve the programming task below in a Python markdown code block.
Let's call beauty of an array $b_1, b_2, \ldots, b_n$ ($n > 1$) — $\min\limits_{1 \leq i < j \leq n} |b_i - b_j|$.
You're given an array $a_1, a_2, \ldots a_n$ and a number $k$. Calculate the sum of beauty over all subsequences of the array of length e... | {"inputs": ["3 2\n4 4 4\n", "3 2\n4 4 4\n", "3 3\n1 4 0\n", "3 2\n8 4 4\n", "3 3\n4 4 4\n", "3 3\n4 4 7\n", "3 3\n4 4 0\n", "3 5\n1 4 0\n"], "outputs": ["0", "0\n", "1\n", "8\n", "0\n", "0\n", "0\n", "0\n"]} | 465 | 133 |
coding | Solve the programming task below in a Python markdown code block.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclus... | {"inputs": ["1\n2 0", "1\n1 0", "1\n1 1", "1\n4 0", "1\n8 0", "1\n7 0", "1\n7 1", "1\n0 30"], "outputs": ["-1\n", "0\n", "1\n", "-3\n", "-7\n", "-6\n", "-5\n", "31\n"]} | 236 | 97 |
coding | Solve the programming task below in a Python markdown code block.
# Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an **_array of integers_** , **_Find the minimum sum_** which is obtained... | {"functional": "_inputs = [[[5, 4, 2, 3]], [[12, 6, 10, 26, 3, 24]], [[9, 2, 8, 7, 5, 4, 0, 6]]]\n_outputs = [[22], [342], [74]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tup... | 492 | 219 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:
Remove the first character of a string s and give it to the robot. The ... | {"functional": "def check(candidate):\n assert candidate(s = \"zza\") == \"azz\"\n assert candidate(s = \"bac\") == \"abc\"\n assert candidate(s = \"bdda\") == \"addb\"\n\n\ncheck(Solution().robotWithString)"} | 143 | 60 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$, and an integer $x$. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was $[3, 6, ... | {"inputs": ["1\n1 1\n1\n", "1\n1 1\n1\n", "1\n1 1\n0\n", "1\n1 171\n1\n", "1\n1 1234\n1\n", "1\n1 1234\n1\n", "2\n3 3\n3 6 9\n3 3\n6 4 11\n", "1\n4 2\n2 2655 6548 2082\n"], "outputs": ["1 1\n", "1 1\n", "0 0\n", "1 1\n", "1 1\n", "1 1\n", "6 6\n7 8\n", "5644 5644\n"]} | 627 | 182 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.
Answers within 10-5 of the actual answer will be considered accepted.
Please c... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]) == 2.00000\n assert candidate(arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]) == 4.00000\n assert candidate(arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]) == 4... | 94 | 559 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array restaurants where restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.
The veganFriendly filter will be either true (meaning you ... | {"functional": "def check(candidate):\n assert candidate(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10) == [3,1,5] \n assert candidate(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganF... | 227 | 301 |
coding | Solve the programming task below in a Python markdown code block.
Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is h_{i}. Liss wants to eat all nuts.
Now Liss is on the root of the tree with ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n", "1\n5\n", "1\n8\n"], "outputs": ["2\n", "2\n", "3\n", "4\n", "5\n", "7\n", "6\n", "9\n"]} | 336 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Ichigo is on his way to save Rukia. Unfortunately, when Ichigo was busy fighting Renji, Kenpachi Zaraki had gone to the Dangai(the same place where Ichigo got his final Getsuga Tenshou) to train. Now, he has a Bankai called Tensa Quantum Computer and he ... | {"inputs": ["4\n1 1\n4 1\n4 -3\n1729 -786\n"], "outputs": ["0\n2\n6\n3170\n"]} | 732 | 44 |
coding | Solve the programming task below in a Python markdown code block.
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of electio... | {"inputs": ["1 1\n0\n", "1 1\n0\n", "2 1\n0 0\n", "2 1\n0 0\n", "1 3\n5\n3\n2\n", "3 1\n1 2 3\n", "3 1\n0 0 0\n", "3 1\n1 2 3\n"], "outputs": ["1", "1\n", "1", "1\n", "1", "3", "1", "3\n"]} | 569 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Naman owns a very famous Ice Cream parlour in Pune. He has a wide range of flavours with different pricing.
Every flavour costs ₹ X per gram and quantity of each flavour in the parlour is indefinite. Now, Naman has
received an order for a party where... | {"inputs": ["2\n5\n4 6 8 1 10\n10 3\n2\n1 2\n1 2"], "outputs": ["18\nNot Possible"]} | 390 | 44 |
coding | Solve the programming task below in a Python markdown code block.
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be... | {"inputs": ["3 1\nerase 0\nerase 0\nerase -2147483648\n", "3 1\nerase -1\nerase 0\nerase -2147483648\n", "3 1\nerase -1\nerase 0\nerase -2666718247\n", "6 10\nalloc 6\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n", "6 4\nalloc 5\nalloc 3\nerase 2\nalloc 18\ndefragment\nalloc 6\n", "6 6\nalloc 5\nalloc 3\nerase 1\na... | 704 | 373 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ children, numbered $1,2,\ldots,n$, sitting around a circle in a clockwise manner. The ${i}$th child has a piece of paper with the number $a_i$ written on it. They play the following game:
In the ${1}$st round, the child numbered ${i}$ incr... | {"inputs": ["2\n5 1\n10 20 30 40 50\n3 4\n1 2 1\n"], "outputs": ["80 20 30 40 50\n10 60 30 40 50\n10 20 90 40 50\n10 20 30 120 50\n10 20 30 40 100\n\n23 7 12\n11 21 6\n7 13 24\n"]} | 575 | 143 |
coding | Solve the programming task below in a Python markdown code block.
The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:
- 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)
- T_i = A (T_i is the i-th character of T from the beginning.)
- T_j = B
- T_k =... | {"inputs": ["ABC\n", "AAA\n", "ACB\n", "???\n", "?C?\n", "?BC\n", "??AC", "A??C"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "8"]} | 505 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Yesterday Chef had a great party and doesn't remember the way he celebreated it. But he found a strange paper in his kitchen containing n digits (lets give them indices from 1 to n and name the... | {"inputs": ["10 3\n0324152397\n1\n4\n7", "10 3\n0324152397\n1\n6\n7", "10 1\n0324152397\n1\n6\n7", "10 2\n0324152397\n1\n6\n7", "10 3\n0324152397\n2\n4\n7", "10 2\n0324152397\n1\n7\n7", "10 3\n0324152397\n1\n3\n7", "10 3\n0324152397\n3\n1\n7"], "outputs": ["0\n7\n9", "0\n15\n9\n", "0\n", "0\n15\n", "3\n7\n9\n", "0\n9\n... | 572 | 247 |
coding | Solve the programming task below in a Python markdown code block.
There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N).
For each k = 1,2,\dots,N, find the answer to the following question:
Rng i... | {"inputs": ["4\n2 4\n1 3\n3 1\n4 2", "4\n2 4\n1 3\n3 2\n4 1", "4\n1 4\n2 3\n3 2\n4 1", "4\n1 4\n2 2\n3 1\n4 3", "4\n2 4\n1 2\n3 1\n4 3", "4\n2 4\n1 3\n3 1\n4 2", "4\n2 4\n1 3\n3 2\n4 1", "4\n1 4\n3 3\n2 1\n4 2"], "outputs": ["2\n2\n2\n2\n", "2\n2\n1\n1\n", "1\n1\n1\n1\n", "1\n3\n3\n3\n", "4\n4\n4\n4\n", "2\n2\n2\n2\n",... | 401 | 238 |
coding | Solve the programming task below in a Python markdown code block.
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array.
For example:
```python
solution([1,2,3,10,5]) # should return [1,2,3,5,10]
solution(No... | {"functional": "_inputs = [[[1, 2, 3, 10, 5]], [None], [[]], [[20, 2, 10]], [[2, 20, 10]]]\n_outputs = [[[1, 2, 3, 5, 10]], [[]], [[]], [[2, 10, 20]], [[2, 10, 20]]]\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=... | 162 | 232 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array A of size N and an integer M, such that 1 ≤ A_{i} ≤ M for every 1 ≤ i ≤ N.
The *distance* of an array B from array A is defined as:
d(A, B) = \sum_{i=1}^N |A_{i} - B_{i}|
Chef wants an array B of size N, such that 1 ≤ B_{i} ≤ M and t... | {"inputs": ["4\n2 6\n3 5\n4 1\n1 1 1 1\n5 7\n2 3 4 5 6\n7 24\n23 7 6 16 12 4 24\n"], "outputs": ["7\n0\n21\n127\n"]} | 632 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array consisting of N + K - 1 integers. The array contains only the first N positive odd numbers. Each number appears exactly once, except for one number which appears exactly K times. The sum of integers in Chef's array is equal to S.
For e... | {"inputs": ["3\n3 2 14\n5 4 28\n2 3 10\n"], "outputs": ["5\n1\n3\n"]} | 434 | 39 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.
In other words, if the number of positive integers in nums is pos an... | {"functional": "def check(candidate):\n assert candidate(nums = [-2,-1,-1,1,2,3]) == 3\n assert candidate(nums = [-3,-2,-1,0,0,1,2]) == 3\n assert candidate(nums = [5,20,66,1314]) == 4\n\n\ncheck(Solution().maximumCount)"} | 117 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exac... | {"inputs": ["1 1 5\n1\n", "1 1 1\n0\n", "1 1 1\n1\n", "1 1 2\n1\n", "1 1 0\n1\n", "1 1 2\n0\n", "1 1 5\n1\n", "1 1 1\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0", "0"]} | 537 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color t_{i}.
For a fixed interval (set of consecutive elements) of ba... | {"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n2 1\n", "2\n2 2\n", "3\n1 1 1\n", "3\n2 1 1\n", "3\n1 1 1\n"], "outputs": ["1 \n", "1 ", "2 1 \n", "2 1 ", "0 3\n", "6 0 0 \n", "5 1 0\n", "6 0 0 "]} | 412 | 123 |
coding | Solve the programming task below in a Python markdown code block.
Tom is very fond of adding values , so what he does whenever he gets a value he adds all its digits and forms a new value and checks it whether it has become a single digit or not and if it does not even becomes a single digit he apply the operation agai... | {"inputs": ["72\n147\n1009\n994\n5564\n9999\n1547\n18894\n1475\n5554\n8457\n32254\n14562\n18995\n5624\n65412\n1235\n2356\n1113\n1555\n4631\n8641\n2945\n8466\n3214\n4412\n6594\n3120\n55\n964\n1584\n6645\n3472\n12\n6642\n34454\n4851\n6524\n6314\n7516\n9547\n8714\n8214\n6425\n7132\n5621\n1203\n2350\n563\n1223\n4584\n6424\... | 242 | 516 |
coding | Solve the programming task below in a Python markdown code block.
Iahub got lost in a very big desert. The desert can be represented as a n × n square matrix, where each cell is a zone of the desert. The cell (i, j) represents the cell at row i and column j (1 ≤ i, j ≤ n). Iahub can go from one cell (i, j) only down or... | {"inputs": ["2 1\n1 2\n", "2 1\n2 2\n", "2 1\n2 2\n", "2 1\n2 2\n", "2 1\n1 2\n", "12 1\n7 4\n", "12 1\n7 4\n", "12 1\n12 4\n"], "outputs": ["2\n", "-1\n", "-1\n", "-1\n", "2\n", "22\n", "22\n", "22\n"]} | 507 | 125 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.
Your task is... | {"functional": "def check(candidate):\n assert candidate(s = \"egcfe\") == \"efcfe\"\n assert candidate(s = \"abcd\") == \"abba\"\n assert candidate(s = \"seven\") == \"neven\"\n\n\ncheck(Solution().makeSmallestPalindrome)"} | 184 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Given $N *M$ matrix containing elements either $1$ or $0$ and string S of length $N+M-1$ containing characters $0$ or $1$. Your task is to make all the paths from top left corner to the bottom right corner of the matrix same as the given string .You c... | {"inputs": ["2\n3 3\n1 0 1\n0 1 1\n1 1 0\n10111\n10 5\n3 3\n0 0 1\n0 1 1\n0 1 1\n00011\n2 9"], "outputs": ["5\n4"]} | 511 | 79 |
coding | Solve the programming task below in a Python markdown code block.
Given a set of N integer points on the Cartesian plane. Your task is to find an integer point satisfying its sum of distances to N given points (S) is minimum.
------ Input ------
There are several test cases (fifteen at most), each formed as follows:... | {"inputs": ["3\n1 1\n2 2\n3 3\n5\n1 4\n2 3\n5 2\n3 5\n4 1\n0\n"], "outputs": ["2.828427\n9.640986"]} | 232 | 65 |
coding | Solve the programming task below in a Python markdown code block.
You will be given two ASCII strings, `a` and `b`. Your task is write a function to determine which one of these strings is "worth" more, and return it.
A string's worth is determined by the sum of its ASCII codepoint indexes. So, for example, the string... | {"functional": "_inputs = [['AaBbCcXxYyZz0189', 'KkLlMmNnOoPp4567'], ['ABcd', '0123'], ['!\"?$%^&*()', \"{}[]@~'#:;\"], ['ABCD', 'DCBA']]\n_outputs = [['KkLlMmNnOoPp4567'], ['ABcd'], [\"{}[]@~'#:;\"], ['ABCD']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n re... | 166 | 257 |
coding | Solve the programming task below in a Python markdown code block.
During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome.
Recall that a number is called a palindrom... | {"inputs": ["1\n3\n100\n", "1\n3\n109\n", "3\n2\n99\n4\n1023\n3\n385\n"], "outputs": ["899\n", "890\n", "12\n8976\n614\n"]} | 490 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can ... | {"inputs": ["1\n0\n1\n1\n0\n", "3\n1 0 0\n0 0 0\n0 0 0\n0 0 0\n", "5\n0 1 0 1 0\n1 1 0 0 1\n1 0 1 0 1\n0 0 1 1 0\n", "7\n1 0 0 1 1 0 1\n1 0 0 0 1 1 1\n1 1 1 0 0 1 0\n0 1 1 1 0 0 0\n", "7\n0 0 1 0 1 0 1\n0 0 0 0 0 0 1\n0 1 0 1 0 1 0\n1 0 0 0 0 0 0\n", "7\n0 0 0 0 0 0 0\n1 0 0 0 0 0 0\n0 0 0 0 0 1 0\n0 0 0 0 0 0 0\n", "7... | 602 | 422 |
coding | Solve the programming task below in a Python markdown code block.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of... | {"inputs": ["6\n", "8\n", "4\n", "9\n", "3\n", "5\n", "7\n", "1\n"], "outputs": ["83\n", "155\n", "35\n", "198\n", "20\n", "56\n", "116\n", "4\n"]} | 390 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Chef had an array A of length N such that 1 ≤ A_{i} ≤ N for all 1 ≤ i ≤ N. Chef constructed another binary array B of length N in the following manner:
B_{i} = 1 if the frequency of element i in A is *odd*.
B_{i} = 0 if the frequency of element i in A is... | {"inputs": ["3\n4\n0 1 0 1\n5\n1 1 1 1 0\n6\n1 1 1 1 1 1\n"], "outputs": ["YES\nNO\nYES\n"]} | 569 | 54 |
coding | Solve the programming task below in a Python markdown code block.
The activity of a panipuri seller is "making a panipuri and putting it on the palte of his customer".
$N$ customers are eating panipuri, Given an array $A$ of length $N$, $i^{th}$ customer takes $A_i$ seconds to eat a panipuri.
The Speed of Pani... | {"inputs": ["2\n4\n2 4 6 3\n5\n2 3 4 6 5"], "outputs": ["2\n3"]} | 702 | 36 |
coding | Solve the programming task below in a Python markdown code block.
There are S sheep and W wolves.
If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.
If the wolves will attack the sheep, print unsafe; otherwise, print safe.
-----Constraints-----
- 1 \leq S \leq 100
- ... | {"inputs": ["1 5", "1 6", "0 6", "0 7", "0 8", "0 1", "0 0", "1 0"], "outputs": ["unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "unsafe\n", "safe\n"]} | 168 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.
The cost of the substring is the sum of the values of each character in the substring. The cost of... | {"functional": "def check(candidate):\n assert candidate(s = \"adaa\", chars = \"d\", vals = [-1000]) == 2\n assert candidate(s = \"abc\", chars = \"abc\", vals = [-1,-1,-1]) == 0\n\n\ncheck(Solution().maximumCostSubstring)"} | 224 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.
-----Constraints-----
- S and T are strings consisting of lowercase English letters.
- ... | {"inputs": ["c a\n", "oder atb", "redo atb", "redp atb", "redp bta", "redo bta", "redo bat", "redo b`t"], "outputs": ["ac\n", "atboder\n", "atbredo\n", "atbredp\n", "btaredp\n", "btaredo\n", "batredo\n", "b`tredo\n"]} | 145 | 92 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.
Please complete the following python code precis... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,2,1], nums2 = [2,2]) == [2]\n assert candidate(nums1 = [4,9,5], nums2 = [9,4,9,8,4]) == [9,4]\n\n\ncheck(Solution().intersection)"} | 90 | 80 |
coding | Solve the programming task below in a Python markdown code block.
In ChefLand, there is a mountain range consisting of $N$ hills (numbered $1$ through $N$) in a straight line. Let's denote the height of the $i$-th hill from the left by $h_i$.
Ada is working on the water supply system of ChefLand. On some of the hills, ... | {"inputs": ["1\n6\n4 16 32 6 8 2\n"], "outputs": ["2 "]} | 517 | 31 |
coding | Solve the programming task below in a Python markdown code block.
# Do you ever wish you could talk like Siegfried of KAOS ?
## YES, of course you do!
https://en.wikipedia.org/wiki/Get_Smart
# Task
Write the function ```siegfried``` to replace the letters of a given sentence.
Apply the rules using the course not... | {"functional": "_inputs = [[1, 'City civilians'], [1, 'Centre receiver'], [1, 'Chatanooga choo choo crashed'], [1, 'Capital city cats chew cheese'], [2, 'Photo of 5 pheasants with graphs'], [3, 'Meet me at the same place at noon'], [3, 'The time is now'], [3, 'Be quite quiet'], [3, 'Aardvarks are nice most of the time'... | 389 | 618 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings,write a method to decide if one is a permutation of the other.
Please complete the following python code precisely:
```python
class Solution:
def CheckPermutation(self, s1: str, s2: str) -> bool:... | {"functional": "def check(candidate):\n assert candidate(s1 = \"abc\", s2 = \"bca\") == True\n assert candidate(s1 = \"abc\", s2 = \"bad\") == False\n\n\ncheck(Solution().CheckPermutation)"} | 71 | 57 |
coding | Solve the programming task below in a Python markdown code block.
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. I... | {"inputs": ["3\n1 5\n2 6\n4 7\n", "3\n1 5\n2 6\n3 7\n", "3\n1 5\n2 6\n3 12\n", "3\n3 9\n20 30\n1 3\n", "3\n3 9\n20 30\n0 3\n", "3\n3 9\n20 55\n0 3\n", "3\n3 13\n20 55\n0 3\n", "3\n3 10\n20 30\n0 3\n"], "outputs": ["0\n\n", "0\n", "0\n\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n", "3\n1 2 3\n"]} | 394 | 211 |
coding | Solve the programming task below in a Python markdown code block.
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed ... | {"inputs": ["11\n", "85\n", "21\n", "99\n", "21\n", "99\n", "11\n", "85\n"], "outputs": ["-1\n", "58\n", "12\n", "-1\n", "12\n", "-1\n", "-1\n", "58\n"]} | 360 | 83 |
coding | Solve the programming task below in a Python markdown code block.
AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.
-----Constraints-----
- 1 ≤ a,b ≤ 10000
- a and b are integers.
-----Input-----
Input is given from Standard Input in the following forma... | {"inputs": ["4 4", "2 4", "3 0", "0 0", "0 1", "0 2", "1 2", "1 1"], "outputs": ["Even\n", "Even\n", "Even\n", "Even\n", "Even\n", "Even\n", "Even\n", "Odd\n"]} | 133 | 78 |
coding | Solve the programming task below in a Python markdown code block.
While Alice was drinking sugarcane juice, she started wondering about the following facts:
The juicer sells each glass of sugarcane juice for 50 coins.
He spends 20\% of his total income on buying sugarcane.
He spends 20\% of his total income on buying s... | {"inputs": ["4\n2\n4\n5\n10\n"], "outputs": ["30\n60\n75\n150\n"]} | 624 | 34 |
coding | Solve the programming task below in a Python markdown code block.
It's a Pokemon battle! Your task is to calculate the damage that a particular move would do using the following formula (not the actual one from the game):
Where:
* attack = your attack power
* defense = the opponent's defense
* effectiveness = the eff... | {"functional": "_inputs = [['fire', 'water', 100, 100], ['grass', 'water', 100, 100], ['electric', 'fire', 100, 100], ['grass', 'electric', 57, 19], ['grass', 'water', 40, 40], ['grass', 'fire', 35, 5], ['fire', 'electric', 10, 2]]\n_outputs = [[25], [100], [50], [150], [100], [175], [250]]\nimport math\ndef _deep_eq(a... | 334 | 284 |
coding | Solve the programming task below in a Python markdown code block.
## Description
Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required:
```if X[i] > X[j] then X[i] = X[i] - X[j]```
When no more transformations are possible, retu... | {"functional": "_inputs = [[[6, 9, 21]], [[9]], [[30, 12]], [[11, 22]], [[1, 21, 55]], [[4, 16, 24]], [[3, 13, 23, 7, 83]], [[60, 12, 96, 48, 60, 24, 72, 36, 72, 72, 48]], [[71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71]]]\n_outputs = [[9], [9], [12], [22], [3], [12], [5], [132], [923]]\nimport math\ndef _deep_eq(... | 403 | 346 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 109 + 7.
Please complete the following python code precisely:
```python... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 1\n assert candidate(n = 3) == 27\n assert candidate(n = 12) == 505379714\n\n\ncheck(Solution().concatenatedBinary)"} | 84 | 67 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rooted tree of $2^n - 1$ vertices. Every vertex of this tree has either $0$ children, or $2$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children is the left one, and t... | {"inputs": ["2\nBAA\n", "2\nABA\n", "2\nAAB\n", "2\nAAA\n", "2\nBBB\n", "2\nBBB\n", "2\nAAB\n", "2\nBBB\n"], "outputs": ["1\n", "2\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 593 | 92 |
coding | Solve the programming task below in a Python markdown code block.
You get an array of numbers, return the sum of all of the positives ones.
Example `[1,-4,7,12]` => `1 + 7 + 12 = 20`
Note: if there is nothing to sum, the sum is default to `0`.
Also feel free to reuse/extend the following starter code:
```python
def p... | {"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, -2, 3, 4, 5]], [[-1, 2, 3, 4, -5]], [[]], [[-1, -2, -3, -4, -5]]]\n_outputs = [[15], [13], [9], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ... | 95 | 230 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.