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.
Problem statement
Given the string $ S $. Find the number of all anagrams in $ S $ that are palindromic.
An anagram of the string $ X $ is an anagram of $ Y $, which means that $ X $ is equal to $ Y $, or that the rearranged characters of $ X $ are equ... | {"inputs": ["ac", "cc", "bc", "cb", "ca", "db", "bd", "be"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 271 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.
Return the number of '*'... | {"functional": "def check(candidate):\n assert candidate(s = \"l|*e*et|c**o|*de|\") == 2\n assert candidate(s = \"iamprogrammer\") == 0\n assert candidate(s = \"yo|uar|e**|b|e***au|tifu|l\") == 5\n\n\ncheck(Solution().countAsterisks)"} | 131 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Sereja has an n × m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of t... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "0 1 1\n1\n", "1 1 1\n0\n", "2 2 1\n1 1\n1 0\n", "2 2 1\n1 1\n1 0\n", "2 2 1\n1 0\n1 0\n", "8 1 4\n0\n0\n0\n1\n0\n1\n1\n0\n"], "outputs": ["0\n", "0", "0\n", "0\n", "1\n", "1", "0\n", "0\n"]} | 481 | 148 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are painting a fence of n posts with k different colors. You must paint the posts following these rules:
Every post must be painted exactly one color.
There cannot be three or more consecutive posts with the same... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 2) == 6\n assert candidate(n = 1, k = 1) == 1\n assert candidate(n = 7, k = 2) == 42\n\n\ncheck(Solution().numWays)"} | 115 | 72 |
coding | Solve the programming task below in a Python markdown code block.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane.
Each of the next n lines contains two real coordinates x_{i} and y_{i} of the $i^{\text{th}}$ point, specified with exactly 2 fractional digits... | {"inputs": ["1\n1.00 1.01\n", "1\n0.00 0.01\n", "1\n0.00 0.01\n", "1\n1.00 1.01\n", "1\n792.52 879.16\n", "1\n792.52 879.16\n", "1\n1000.00 999.99\n", "1\n1000.00 999.99\n"], "outputs": ["6.010\n", "5.010\n", "5.010", "6.010", "884.160\n", "884.160", "1004.990\n", "1004.990"]} | 655 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef's son Chefu found some matches in the kitchen and he immediately starting playing with them.
The first thing Chefu wanted to do was to calculate the re... | {"inputs": ["3\n123 234\n10101 1010\n4 4"], "outputs": ["13\n10\n7"]} | 386 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef invited N of his friends in his birthday party. All the friends are numbered from 1 to N. Some of the friends might know each other. You are given this information by M ... | {"inputs": ["3\n3 2\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4\n6 7\n1 2\n1 3\n2 3\n2 4\n4 5\n4 6\n5 6"], "outputs": ["YES\nNO\nYES"]} | 652 | 76 |
coding | Solve the programming task below in a Python markdown code block.
The game of Berland poker is played with a deck of $n$ cards, $m$ of which are jokers. $k$ players play this game ($n$ is divisible by $k$).
At the beginning of the game, each player takes $\frac{n}{k}$ cards from the deck (so each card is taken by exac... | {"inputs": ["1\n49 7 7\n", "1\n49 7 7\n", "1\n48 7 4\n", "1\n48 3 6\n", "1\n49 9 7\n", "1\n48 0 6\n", "1\n71 9 7\n", "1\n48 1 4\n"], "outputs": ["7\n", "7\n", "7\n", "3\n", "6\n", "0\n", "9\n", "1\n"]} | 637 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:
Each element p[i][j] is calculated as the produ... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,2],[3,4]]) == [[24,12],[8,6]]\n assert candidate(grid = [[12345],[2],[1]]) == [[2],[0],[0]]\n\n\ncheck(Solution().constructProductMatrix)"} | 146 | 74 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, you are initially positioned at the first index of the array.
In one step you can jump from index i to index:
i + 1 where: i + 1 < arr.length.
i - 1 where: i - 1 >= 0.
j where: arr[i] ... | {"functional": "def check(candidate):\n assert candidate(arr = [100,-23,-23,404,100,23,23,23,3,404]) == 3\n assert candidate(arr = [7]) == 0\n assert candidate(arr = [7,6,9,6,9,6,9,7]) == 1\n\n\ncheck(Solution().minJumps)"} | 156 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game. They are given an array $A$ of length $N$. The array consists of integers. They are building a sequence together. In the beginning, the sequence is empty. In one turn a player can remove a number from the left or right s... | {"inputs": ["1\n5\n", "1\n2\n", "1\n3\n", "1\n1\n", "1\n0\n", "1\n4\n", "1\n8\n", "1\n6\n"], "outputs": ["Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n", "Alice\n"]} | 299 | 86 |
coding | Solve the programming task below in a Python markdown code block.
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) c... | {"inputs": ["7 9 3 1 8\n", "8 7 1 8 7\n", "7 7 7 8 8\n", "8 8 8 2 2\n", "8 8 2 2 2\n", "1 1 1 1 1\n", "8 1 8 8 8\n", "1 1 1 8 1\n"], "outputs": ["28\n", "15\n", "16\n", "4\n", "6\n", "2\n", "9\n", "9\n"]} | 487 | 137 |
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. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.
Return the minimum number of moves to make every value in nums unique.
The test cases ar... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,2]) == 1\n assert candidate(nums = [3,2,1,2,1,7]) == 6\n\n\ncheck(Solution().minIncrementForUnique)"} | 117 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Tracy loves Donuts. She purchased a lots of Donuts for her birthday party. She learnt to calculate the area of the circle a few days back and she is fascinated to know the area of the donuts as well !! Help her finding the area of the Donuts…..
-----Inp... | {"inputs": ["2\n5\n12"], "outputs": ["78.5\n452.16"]} | 179 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XO... | {"inputs": ["9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", "9\n1\n3\n3\n4\n5\n6\n7\n8\n9\n", "9\n1\n5\n3\n4\n5\n6\n7\n8\n9\n", "9\n1\n3\n3\n2\n5\n6\n7\n8\n9\n", "9\n1\n3\n3\n2\n7\n6\n7\n8\n9\n", "9\n2\n3\n3\n2\n7\n6\n7\n8\n9\n", "9\n1\n2\n3\n4\n6\n6\n7\n8\n9\n", "9\n1\n3\n3\n4\n3\n6\n7\n8\n9\n"], "outputs": ["1\n2\n3\n4\n8\n12\n5\n... | 469 | 367 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to store some important numerical data on his personal computer. He is using a new data type that can store values only from 0 till N both inclusive. If this data type receives a value greater than N then it is cyclically converted to fit into... | {"inputs": ["5\n15 0\n15 10\n11 12\n27 37\n50 49"], "outputs": ["0\n10\n0\n9\n49"]} | 519 | 51 |
coding | Solve the programming task below in a Python markdown code block.
A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that f... | {"inputs": ["5 5 3\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 1\n.....\n.....\n.*..*\n*.*..\n....*\n", "5 5 4\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 7\n*.***\n.****\n..***\n*.***\n.**.*\n", "5 5 3\n*.***\n.****\n..***\n***.*\n.**.*\n", "5 6 1\n....*.\n...***\n....*.\n..*...\n.*.*.*\n", "5 6 1\n....*.\n...***\n...... | 589 | 319 |
coding | Solve the programming task below in a Python markdown code block.
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.
Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps... | {"inputs": ["5 1 1 5\n1 1 1\n", "5 1 1 5\n1 1 1\n", "10 1 1 10\n1 5 6\n", "10 1 1 10\n1 5 6\n", "10 1 1 10\n1 9 6\n", "10 1 1 10\n1 2 6\n", "10 1 1 10\n1 7 6\n", "2 3 2 1\n1 1 2\n2 1 2\n4 1 2\n"], "outputs": ["XRRRR\n", "XRRRR", "RRRRRRRRR\n", "RRRRRRRRR", "RRRRRRRRR\n", "XRRRRRRRRR\n", "RRRRRRRRR\n", "XXL\n"]} | 719 | 212 |
coding | Solve the programming task below in a Python markdown code block.
A certain business maintains a list of all its customers' names. The list is arranged in order of importance, with the last customer in the list being the most important. Now, he want to create a new list sorted alphabetically according to customers' las... | {"inputs": ["4\n6\na b c d\nA\nThomas a\nd d\ned edgars\nal Adams\n1\nTurnipHeadJohnson\n3\na a a a a a a a a a\nA A A A A A A A A A\nbob\n5\nBob Mackey\nMack Bobby\nbobby\nMack Mackey\nMackey", "4\n10\nAlan\naLan\nalAn\nalaN\nALan\nAlAn\nAlaN\naLAn\naLaN\nalAN\n4\nabcdefghijklmnop T\nabccefghijklmnop T\nt tt ttt tttt\... | 227 | 341 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array consisting of $n$ integers $a_1, a_2, \dots , a_n$ and an integer $x$. It is guaranteed that for every $i$, $1 \le a_i \le x$.
Let's denote a function $f(l, r)$ which erases all values such that $l \le a_i \le r$ from the array $a... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "2 3\n1 1\n", "2 3\n3 2\n", "2 3\n3 2\n", "2 3\n1 1\n", "2 4\n3 2\n", "2 20\n1 8\n"], "outputs": ["1\n", "1\n", "6\n", "5\n", "5\n", "6\n", "8\n", "210\n"]} | 461 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Create a program that takes two dates as input and outputs the number of days between the two dates.
Date 1 (y1, m1, d1) is the same as or earlier than date 2 (y2, m2, d2). Date 1 is included in the number of days, not date 2. Also, take the leap year i... | {"inputs": ["2006 3 2 522 6 3\n2006 8 1 89 11 11\n2004 1 2 362 1 2\n3334 2 1 2180 1 1\n2000 2 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "2006 9 2 522 9 2\n2006 9 1 19 11 11\n2004 1 2 2005 1 1\n1153 1 1 2006 1 1\n2000 1 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "2006 9 2 522 9 3\n2006 9 1 2006 11 11\n2004 1 2 2005 1 1\n218 1 1 2006 1 1\n20... | 356 | 1,107 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer de... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([5,1,2,3,None,6,4]), startValue = 3, destValue = 6) == \"UURL\"\n assert candidate(root = tree_node([2,1]), startValue = 2, destValue = 1) == \"L\"\n\n\ncheck(Solution().getDirections)"} | 275 | 87 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
If target is not found in the array, return [-1, -1].
You must write an algorithm with O(l... | {"functional": "def check(candidate):\n assert candidate(nums = [5,7,7,8,8,10], target = 8) == [3,4]\n assert candidate(nums = [5,7,7,8,8,10], target = 6) == [-1,-1]\n assert candidate(nums = [], target = 0) == [-1,-1]\n\n\ncheck(Solution().searchRange)"} | 109 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Given a string of words (x), you need to return an array of the words, sorted alphabetically by the final character in each.
If two words have the same last letter, they returned array should show them in the order they appeared in the given string.
Al... | {"functional": "_inputs = [['man i need a taxi up to ubud'], ['what time are we climbing up the volcano'], ['take me to semynak'], ['massage yes massage yes massage'], ['take bintang and a dance please']]\n_outputs = [[['a', 'need', 'ubud', 'i', 'taxi', 'man', 'to', 'up']], [['time', 'are', 'we', 'the', 'climbing', 'vo... | 92 | 297 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp found a rectangular table consisting of $n$ rows and $m$ columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns":
cells are numbered starting from one;
cells are numbered from left to ri... | {"inputs": ["5\n1 1 1\n2 2 3\n3 6 1\n110 100 498\n1000000 1000000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 6 1\n110 100 498\n1000000 1100000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 6 1\n110 100 507\n1000000 1000000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 6 1\n100 100 498\n1000000 1100000 1000000000000\n", "5\n1 1 1\n2 2 3\n3 ... | 654 | 734 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique.
The athletes are placed based on their scores, where the 1st... | {"functional": "def check(candidate):\n assert candidate(score = [5,4,3,2,1]) == [\"Gold Medal\",\"Silver Medal\",\"Bronze Medal\",\"4\",\"5\"]\n assert candidate(score = [10,3,8,9,4]) == [\"Gold Medal\",\"5\",\"Bronze Medal\",\"Silver Medal\",\"4\"]\n\n\ncheck(Solution().findRelativeRanks)"} | 226 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Greg has an array a = a_1, a_2, ..., a_{n} and m operations. Each operation looks as: l_{i}, r_{i}, d_{i}, (1 ≤ l_{i} ≤ r_{i} ≤ n). To apply operation i to the array means to increase all array elements with numbers l_{i}, l_{i} + 1, ..., r_{i} by value ... | {"inputs": ["1 1 1\n1\n1 1 1\n1 1\n", "1 1 1\n0\n1 1 0\n1 1\n", "1 1 1\n0\n1 1 0\n1 1\n", "1 1 1\n1\n1 1 0\n1 1\n", "1 1 1\n0\n1 1 0\n1 0\n", "1 1 1\n1\n1 1 1\n1 1\n", "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n", "3 3 3\n1 2 3\n1 2 1\n2 3 2\n2 3 4\n1 2\n1 3\n2 3\n"], "outputs": ["2\n", "0\n", "0 \n", "1\n", "0... | 604 | 260 |
coding | Solve the programming task below in a Python markdown code block.
Peter wrote on the board a strictly increasing sequence of positive integers a_1, a_2, ..., a_{n}. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore... | {"inputs": ["2\n5\n7\n", "2\n3\n7\n", "2\n6\n7\n", "2\n??\n?\n", "2\n50\n5\n", "2\n50\n5\n", "2\n25\n5\n", "2\n23\n5\n"], "outputs": ["YES\n5\n7\n", "YES\n3\n7\n", "YES\n6\n7\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 363 | 119 |
coding | Solve the programming task below in a Python markdown code block.
Let's define a function $f(x)$ ($x$ is a positive integer) as follows: write all digits of the decimal representation of $x$ backwards, then get rid of the leading zeroes. For example, $f(321) = 123$, $f(120) = 21$, $f(1000000) = 1$, $f(111) = 111$.
Let... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n6\n", "1\n5\n", "1\n8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 574 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Given a sequence of N elements, Chef defines a function F(i) (1 ≤ i ≤ N) as the median of the first i elements of the sequence.
Chef wants to get a *permutation* P of length N such that P_{i} = F(i) \forall 1 ≤ i ≤ N. Can you help Chef in achieving this... | {"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n2 1 \n3 1 2"]} | 595 | 30 |
coding | Solve the programming task below in a Python markdown code block.
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list of commands that will be given... | {"inputs": ["F\n1\n", "FT\n1\n", "TTFFF\n49\n", "FFFTFFF\n3\n", "FFFTFFF\n2\n", "FFFFTFTF\n1\n", "FTTTFTFF\n8\n", "FFFFTFTF\n0\n"], "outputs": ["0\n", "2\n", "4\n", "7\n", "6\n", "5\n", "8\n", "4\n"]} | 323 | 101 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
Return true if there is a 132 pattern in nums, othe... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == False\n assert candidate(nums = [3,1,4,2]) == True\n assert candidate(nums = [-1,3,2,0]) == True\n\n\ncheck(Solution().find132pattern)"} | 120 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef is very adventurous, so he asked Bob to give him a task.
Bob gave him a sequence of blocks with heights A_{1}, A_{2}, \ldots, A_{N}. Chef is at the first block ... | {"inputs": ["2\n5\n9 15 8 13 8\n9\n20 16 13 9 17 11 15 8 7"], "outputs": ["-1\n4"]} | 589 | 55 |
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.
Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.
-----Constraints-----
- 1 \leq N \leq 10^9
- N is an integer.
-----Input-----
Input is given from Standard Input ... | {"inputs": ["7", "2", "0", "70", "12", "16", "26", "38"], "outputs": ["4\n", "1\n", "0\n", "64\n", "9\n", "16\n", "25\n", "36\n"]} | 131 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Six friends go on a trip and are looking for accommodation. After looking for hours, they find a hotel which offers two types of rooms — double rooms and triple rooms. A double room costs Rs. X, while a triple room costs Rs. Y.
The friends can either ge... | {"inputs": ["3\n10 15\n6 8\n4 8\n"], "outputs": ["30\n16\n12\n"]} | 318 | 35 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi ... | {"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[1,2],[1,3],[4,2]], guesses = [[1,3],[0,1],[1,0],[2,4]], k = 3) == 3\n assert candidate(edges = [[0,1],[1,2],[2,3],[3,4]], guesses = [[1,0],[3,4],[2,1],[3,2]], k = 1) == 5\n\n\ncheck(Solution().rootCount)"} | 295 | 119 |
coding | Solve the programming task below in a Python markdown code block.
For each bill you pay using CRED, you earn X CRED coins.
At CodeChef store, each bag is worth 100 CRED coins.
Chef pays Y number of bills using CRED. Find the maximum number of bags he can get from the CodeChef store.
------ Input Format ------
- ... | {"inputs": ["3\n10 10\n20 4\n70 7"], "outputs": ["1\n0\n4"]} | 410 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and ... | {"inputs": ["1\n111 2 3\n", "1\n111 2 3\n", "1\n111 4 3\n", "1\n111 3 3\n", "1\n111 6 3\n", "1\n101 6 1\n", "1\n101 8 1\n", "1\n001 8 0\n"], "outputs": ["58\n", "58\n", "59\n", "58\n", "60\n", "54\n", "55\n", "4\n"]} | 642 | 141 |
coding | Solve the programming task below in a Python markdown code block.
The Tower of Hanoi problem involves 3 towers. A number of rings decreasing in size are placed on one tower. All rings must then be moved to another tower, but at no point can a larger ring be placed on a smaller ring.
Your task: Given a number of rin... | {"functional": "_inputs = [[4], [5], [10], [50]]\n_outputs = [[15], [31], [1023], [1125899906842623]]\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) !=... | 213 | 197 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.
Please complete the following python code precisely:
```... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,1,2,3,1], target = 2) == 3\n assert candidate(nums = [-6,2,5,-2,-7,-1,3], target = -2) == 10\n\n\ncheck(Solution().countPairs)"} | 99 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera... | {"inputs": ["1\n8\n", "1\n9\n", "1\n1\n", "1\n0\n", "1\n10\n", "1\n11\n", "2\n5 6\n", "2\n1 6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1", "1\n", "2", "2\n"]} | 473 | 90 |
coding | Solve the programming task below in a Python markdown code block.
You will be given a two-dimensional array with row consisting values 0 or 1.
A move consists of choosing any column or row, and toggling all the 0’s as 1’s and 1’s as 0’s.
After making the required moves, every row represents a binary number and the ... | {"inputs": ["3 4\n0 0 1 1\n1 0 1 0\n1 1 0 0"], "outputs": ["39"]} | 344 | 39 |
coding | Solve the programming task below in a Python markdown code block.
You have N cards placed in front of you on the table. The i^{th} card has the number A_{i} written on it.
In one move, you can remove any one card from the remaining cards on the table.
Find the minimum number of moves required so that all the cards ... | {"inputs": ["3\n5\n1 1 2 2 3\n4\n8 8 8 8\n6\n5 6 7 8 9 10\n"], "outputs": ["3\n0\n5\n"]} | 602 | 55 |
coding | Solve the programming task below in a Python markdown code block.
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After pr... | {"inputs": ["1 3 2 1 2 1\n", "0 0 0 0 0 0\n", "4 4 4 4 5 4\n", "2 2 2 2 2 1\n", "1 1 1 1 1 5\n", "8 1 1 3 3 0\n", "1 1 2 2 3 3\n", "1 2 2 5 2 5\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]} | 340 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Consider a table of size $n \times m$, initially fully white. Rows are numbered $1$ through $n$ from top to bottom, columns $1$ through $m$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this s... | {"inputs": ["1 1\nB\n", "1 1\nB\n", "1 1\nB\n", "1 4\nWWBW\n", "1 4\nWWBW\n", "1 4\nWWWB\n", "1 4\nBWWW\n", "1 4\nWBWW\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 3\n", "1 3\n", "1 4\n", "1 1\n", "1 2\n"]} | 295 | 123 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.
Return the sum of the three integers.
You may assume that each input would have exactl... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,2,1,-4], target = 1) == 2\n assert candidate(nums = [0,0,0], target = 1) == 0\n\n\ncheck(Solution().threeSumClosest)"} | 101 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between the occurrence of these two words in the list.
Note that word1 and word2 may be... | {"functional": "def check(candidate):\n assert candidate(wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"coding\") == 1\n assert candidate(wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"makes\") == 3\n... | 122 | 99 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n cars at given miles away from the starting mile 0, traveling to reach the mile target.
You are given two integer array position and speed, both of length n, where position[i] is the starting mile of the it... | {"functional": "def check(candidate):\n assert candidate(target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]) == 3\n\n\ncheck(Solution().carFleet)"} | 219 | 60 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of cha... | {"inputs": ["1\n9 3\nRBGGGRBBGRRBBGGGGB\n", "1\n7 2\nBGGGGBBRRGBBRGGGBR\n", "1\n18 2\nRBGGGRBBGRRBBGGGGB\n", "1\n18 2\nRBGGGRBBGRRBBGGGGB\n", "1\n18 2\nBGGGGBBRRGBBRGGGBR\n", "1\n18 3\nRBGGGRBBGRRBBGGGGB\n", "1\n18 7\nBGGGGBBRRGBBRGGGBR\n", "1\n14 2\nBGGGGBBRRGBBRGGGBR\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n"... | 575 | 200 |
coding | Solve the programming task below in a Python markdown code block.
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at... | {"inputs": ["1 1\n1\n1\n1 1\n", "1 1\n1\n1\n1 1\n", "1 1\n2\n1\n1 1\n", "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n", "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 4 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n", "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n4 5 4 2\n4 4 4 5\n6\n1 1\n2 5\n4 5\n5 5\n... | 607 | 490 |
coding | Solve the programming task below in a Python markdown code block.
You've come to your favorite store Infinitesco to buy some ice tea.
The store sells ice tea in bottles of different volumes at different costs. Specifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, ... | {"inputs": ["6 3 -1 0\n3", "5 39 -1 4\n1", "5 39 -2 4\n1", "5 39 -4 4\n1", "22 12 1 2\n2", "22 12 1 2\n3", "4 21 63 7\n10", "20 30 70 83\n3"], "outputs": ["-3\n", "-1\n", "-2\n", "-4\n", "2\n", "3\n", "35\n", "143\n"]} | 352 | 144 |
coding | Solve the programming task below in a Python markdown code block.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves a... | {"inputs": ["1\n2 3\n", "1\n2 4\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n"], "outputs": ["-1\n", "0\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n", "0\n"]} | 454 | 103 |
coding | Solve the programming task below in a Python markdown code block.
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.
The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set ... | {"inputs": ["4\n0224", "6\n123123", "19\n5546189040285140044", "19\n4753841743850076999", "19\n9039528710159876563", "19\n3616863455241776042", "19\n2785343766571511696", "19\n2922045480066417189"], "outputs": ["3", "17", "273\n", "311\n", "412\n", "322\n", "239\n", "281\n"]} | 227 | 211 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms.
One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families consisting... | {"inputs": ["5\n1 2 3 6 5 4 4 2 5 3 6 1 6 5 3 2 4 1 2 5 1 4 3 6 8 4 3 1 5 6 2 \n"], "outputs": ["8\n"]} | 419 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot.
One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to t... | {"inputs": ["1\n1\n1\n", "1\n2\n2\n", "1\n4\n4\n", "1\n0\n0\n", "1\n8\n8\n", "1\n9\n9\n", "1\n5\n5\n", "1\n11\n11\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 460 | 104 |
coding | Solve the programming task below in a Python markdown code block.
B: Periodic Sequence-
problem
Dr. Period, a professor at H University, is studying a property called the cycle that is supposed to be hidden in all things. As a generally known basic cycle, a cycle hidden in a sequence may be considered. That is, if th... | {"inputs": ["6\n1 2 3 1 1 3", "6\n1 2 3 1 0 3", "6\n2 2 3 1 0 3", "6\n2 2 3 2 0 3", "6\n4 2 3 2 0 3", "6\n4 2 3 2 0 4", "6\n4 4 3 2 0 4", "6\n7 4 3 2 0 4"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 530 | 158 |
coding | Solve the programming task below in a Python markdown code block.
*** Nova polynomial from roots***
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8... | {"functional": "_inputs = [[[4]], [[0, 0, 0, 0]], [[1, 1, 1, 1]], [[-1, 1, 2, -2]], [[]]]\n_outputs = [[[-4, 1]], [[0, 0, 0, 0, 1]], [[1, -4, 6, -4, 1]], [[4, 0, -5, 0, 1]], [[1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to... | 468 | 247 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are ... | {"inputs": ["1 1\n1\n", "1 1\n2\n", "1 2\n10\n", "2 1\n1 2\n", "2 1\n2 1\n", "2 1\n2 3\n", "2 2\n7 2\n", "2 1\n0 1\n"], "outputs": ["1 1\n", "2 2\n", "-1\n", "2 2\n", "2 2\n", "3 3\n", "2 2\n", "1 1\n"]} | 339 | 127 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers $n$, $l$, and $r$. You need to construct an array $a_1,a_2,\dots,a_n$ ($l\le a_i\le r$) such that $\gcd(i,a_i)$ are all distinct or report there's no solution.
Here $\gcd(x, y)$ denotes the greatest common divisor (GCD) of i... | {"inputs": ["1\n100000 1 99999\n", "1\n100000 50021 100000\n", "4\n5 1 5\n9 1000 2000\n10 30 35\n1 1000000000 1000000000\n"], "outputs": ["NO\n", "NO\n", "YES\n1 2 3 4 5\nYES\n1000 1000 1002 1000 1000 1002 1001 1000 1008\nNO\nYES\n1000000000\n"]} | 494 | 188 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, calculate the pivot index of this array.
The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly... | {"functional": "def check(candidate):\n assert candidate(nums = [1, 7, 3, 6, 5, 6]) == 3\n assert candidate(nums = [1, 2, 3]) == -1\n assert candidate(nums = [2, 1, -1]) == 0\n\n\ncheck(Solution().pivotIndex)"} | 155 | 82 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).
Flip operation consists of change any single bit 1 to 0 or change the b... | {"functional": "def check(candidate):\n assert candidate(a = 2, b = 6, c = 5) == 3\n assert candidate(a = 4, b = 2, c = 7) == 1\n assert candidate(a = 1, b = 2, c = 3) == 0\n\n\ncheck(Solution().minFlips)"} | 128 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Lucy loves to travel. Luckily she is a renowned computer scientist and gets to travel to international conferences using her department's budget.
Each year, Society for Exciting Computer Science Research (SECSR) organizes several conferences around the ... | {"functional": "_inputs = [[[], ['Philadelphia', 'Osaka', 'Tokyo', 'Melbourne']], [[], ['Brussels', 'Madrid', 'London']], [[], ['Sydney', 'Tokyo']], [['London', 'Berlin', 'Mexico City', 'Melbourne', 'Buenos Aires', 'Hong Kong', 'Madrid', 'Paris'], ['Berlin', 'Melbourne']], [['Beijing', 'Johannesburg', 'Sydney', 'Philad... | 311 | 519 |
coding | Solve the programming task below in a Python markdown code block.
Alice likes all the numbers which are divisible by A. Bob does not like the numbers which are divisible by B and likes all the remaining numbers. Determine the smallest number greater than or equal to N which is liked by both Alice and Bob. Output -1 if ... | {"inputs": ["3\n5 2 11\n4 3 24\n7 7 100\n"], "outputs": ["15\n28\n-1\n"]} | 352 | 43 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.
Return the kth positive integer that is missing from this array.
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(arr = [2,3,4,7,11], k = 5) == 9\n assert candidate(arr = [1,2,3,4], k = 2) == 6\n\n\ncheck(Solution().findKthPositive)"} | 86 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Dolphin is planning to generate a small amount of a certain chemical substance C.
In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b.
He does not have any stock of chemi... | {"inputs": ["0 4 6\n10 2 5", "1 -1 4\n10 3 5", "1 0 20\n8 9 10", "1 -1 4\n10 3 6", "0 1 25\n5 0 10", "0 1 25\n5 0 16", "0 2 25\n5 0 10", "0 4 10\n10 2 5"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 477 | 156 |
coding | Solve the programming task below in a Python markdown code block.
There are N bikes and M cars on the road.
Each bike has 2 tyres.
Each car has 4 tyres.
Find the total number of tyres on the road.
------ Input Format ------
- The first line will contain T - the number of test cases. Then the test cases follow.
- T... | {"inputs": ["2\n2 1\n3 0\n"], "outputs": ["8\n6\n"]} | 346 | 24 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you need to create a function that takes a 2D array/list of non-negative integer pairs and returns the sum of all the "saving" that you can have getting the [LCM](https://en.wikipedia.org/wiki/Least_common_multiple) of each couple of number ... | {"functional": "_inputs = [[[[15, 18], [4, 5], [12, 60]]], [[[1, 1], [0, 0], [13, 91]]], [[[15, 7], [4, 5], [19, 60]]], [[[20, 50], [10, 10], [50, 20]]], [[]]]\n_outputs = [[840], [1092], [0], [1890], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ... | 269 | 272 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:
Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If... | {"functional": "def check(candidate):\n assert candidate(nums = [5,1,3]) == 3\n assert candidate(nums = [1,1,1]) == 0\n assert candidate(nums = [1,1,2,2,3]) == 4\n\n\ncheck(Solution().reductionOperations)"} | 154 | 72 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rooted tree, consisting of $n$ vertices. The vertices are numbered from $1$ to $n$, the root is the vertex $1$.
You can perform the following operation at most $k$ times:
choose an edge $(v, u)$ of the tree such that $v$ is a parent of ... | {"inputs": ["5\n5 1\n1 1 2 2\n5 2\n1 1 2 2\n6 0\n1 2 3 4 5\n6 1\n1 2 3 4 5\n4 3\n1 1 1\n"], "outputs": ["2\n1\n5\n3\n1\n"]} | 491 | 84 |
coding | Solve the programming task below in a Python markdown code block.
Chef likes to solve difficult tasks. This time, he tried to solve the Big Famous Unsolvable $A+B=C$. One of his friends played a prank on Chef and randomly shuffled the bits in $A$ and $B$ (independently in each number). However, the funny thing is that ... | {"inputs": ["2\n1 2 3\n369 428 797"], "outputs": ["2\n56"]} | 555 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Sunuke-kun's dictionary contains the words s1, ..., sn, which consist of n lowercase letters. This satisfies s1 <... <sn when compared in lexicographical order. Unfortunately, some characters are faint and unreadable. Unreadable characters are represente... | {"inputs": ["3\nsnuje\n????e\neluns", "3\nsunje\n????e\neluns", "3\nsunje\n@???e\neluns", "3\nsunje\n@???e\nsnule", "3\njunse\n@???e\nsnule", "3\nesnuj\n@???e\nsnule", "3\nesnuj\n@?e??\nsnule", "3\nesnuj\n@?f??\nsnule"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 205 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its repr... | {"inputs": [".\n", "-.\n", "--\n", "..\n", ".--\n", "--.\n", ".--.\n", ".-..\n"], "outputs": ["0\n", "1\n", "2\n", "00\n", "02\n", "20\n", "020\n", "010\n"]} | 193 | 81 |
coding | Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The only difference is the constraints on $n$ and $k$. You can make hacks only if all versions of the problem are solved.
You have a string $s$, and you can do two types of operations on it:
Delete the last char... | {"inputs": ["4 5\nabcd\n", "4 11\nddcd\n", "4 11\nzzaz\n", "5 10\ndcdcd\n", "5 10\ncbcbc\n", "5 10\nbbabb\n", "8 16\ndbcadabc\n", "8 20\nccaccaca\n"], "outputs": ["aaaaa\n", "ddcddcddcdd\n", "zzazzazzazz\n", "dcdcdcdcdc\n", "cbcbcbcbcb\n", "bbabbabbab\n", "dbcadabcdbcadabc\n", "ccaccacaccaccacaccac\n"]} | 486 | 155 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sorted array $a_1, a_2, \dots, a_n$ (for each index $i > 1$ condition $a_i \ge a_{i-1}$ holds) and an integer $k$.
You are asked to divide this array into $k$ non-empty consecutive subarrays. Every element in the array should be included... | {"inputs": ["1 1\n1\n", "1 1\n4\n", "1 1\n2\n", "1 1\n1\n", "1 1\n4\n", "1 1\n2\n", "1 1\n0\n", "1 1\n20\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 531 | 103 |
coding | Solve the programming task below in a Python markdown code block.
The chef was playing with numbers and he found that natural number N can be obtained by sum various unique natural numbers, For challenging himself chef wrote one problem statement, which he decided to solve in future.
Problem statement: N can be obtaine... | {"inputs": ["2\n4 1\n38 2"], "outputs": ["2\n1"]} | 420 | 23 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You have prepared four problems. The difficulty levels of the problems are A_{1}, A_{2}, A_{3}, A_{4} respectively. A problem set comprises at least two probl... | {"inputs": ["3\n1 4 3 2\n4 5 5 5\n2 2 2 2"], "outputs": ["2\n1\n0"]} | 445 | 40 |
coding | Solve the programming task below in a Python markdown code block.
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.
Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that ... | {"inputs": ["10 1\n3 7 3 6\n0\n", "10 1\n4 3 5 2 4\n1\n", "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "4 0\n1 1 2\n1 2\n0 1", "7 2\n2 1 2\n1 1\n0 1", "4 2\n1 1 2\n1 2\n0 1", "4 2\n2 1 2\n1 1\n0 1"], "outputs": ["512\n", "512\n", "1\n", "4\n", "16\n", "32\n", "4\n", "4\n"]} | 452 | 194 |
coding | Solve the programming task below in a Python markdown code block.
Consider a pyramid made up of blocks. Each layer of the pyramid is a rectangle of blocks, and the dimensions of these rectangles increment as you descend the pyramid. So, if a layer is a `3x6` rectangle of blocks, then the next layer will be a `4x7` rect... | {"functional": "_inputs = [[1, 1, 2], [2, 4, 3], [1, 10, 10], [20, 30, 40]]\n_outputs = [[5], [47], [880], [83540]]\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 ... | 385 | 208 |
coding | Solve the programming task below in a Python markdown code block.
Recall that string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly zero or all) characters. For example, for the string $a$="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow... | {"inputs": ["v\n", "o\n", "o\n", "v\n", "n\n", "u\n", "p\n", "t\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 473 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Tonight, Chef would like to hold a party for his $N$ friends.
All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at the party a... | {"inputs": ["3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3"], "outputs": ["2\n4\n0"]} | 516 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible b... | {"inputs": ["84 36\n1\n18 32\n", "48 4\n2\n8 100\n9 59\n", "48 4\n2\n8 100\n8 59\n", "48 72\n2\n8 29\n29 37\n", "48 72\n2\n8 29\n15 37\n", "48 72\n2\n8 58\n15 37\n", "48 72\n2\n8 98\n15 37\n", "48 72\n2\n8 192\n9 37\n"], "outputs": ["-1\n", "-1\n-1\n", "-1\n-1\n", "24\n-1\n", "24\n24\n", "24\n24\n", "24\n24\n", "24\n24... | 329 | 226 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has N cards. The i-th of these cards has an integer A_i written on it.
Takahashi will choose an integer K, and then repeat the following operation some number of times:
- Choose exactly K cards such that the integers written on them are all di... | {"inputs": ["3\n2 2 2", "3\n2 2 1", "3\n2 1 2", "3\n2 1 2\n", "4\n1 3 1 3", "4\n1 3 3 2", "4\n2 3 2 2", "4\n2 3 4 1"], "outputs": ["3\n0\n0\n", "3\n1\n0\n", "3\n1\n0", "3\n1\n0\n", "4\n2\n0\n0\n", "4\n2\n1\n0\n", "4\n1\n0\n0\n", "4\n2\n1\n1\n"]} | 325 | 158 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Your task is to sort the characters in a string according to the following rules:
```
- Rule1: English alphabets are arranged from A to Z, case insensitive.
ie. "Type" --> "epTy"
- Rule2: If the uppercase and lowercase of an English alphabet ex... | {"functional": "_inputs = [['a'], ['cba'], ['Cba'], ['cCBbAa'], ['!'], ['c b a'], ['-c--b--a-'], ['cbaCcC'], ['Codewars'], [' MkWD{RB=//k-^ J@,xH Vfi uAz+$ kV _[ }a!}%pSBwn !kKB (b q PQF +}wS .kfU r wFNEs#NsR UVMdG']]\n_outputs = [['a'], ['abc'], ['abC'], ['AaBbcC'], ['!'], ['a b c'], ['-a--b--c-'], ['abcCcC'], ['aCd... | 338 | 359 |
coding | Solve the programming task below in a Python markdown code block.
`This kata is the first of the ADFGX Ciphers, the harder version can be found `here.
The ADFGX Cipher is a pretty well-known Cryptographic tool, and is essentially a modified Polybius Square.
Rather than having numbers as coordinates on the table, it h... | {"functional": "_inputs = [['helloworld', 'bchigklnmoqprstuvwxyzadef']]\n_outputs = [['AFXGDDDDDXGFDXFFDDXF']]\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 ... | 629 | 181 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp has come up with a new game to play with you. He calls it "A missing bigram".
A bigram of a word is a sequence of two adjacent letters in it.
For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".
The game goes as... | {"inputs": ["4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa ab ab\n3\naa\n5\nbb ab bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ba bb\n", "4\n7\nab bb ba aa ba\n7\nab ba aa bb ba\n3\naa\... | 711 | 368 |
coding | Solve the programming task below in a Python markdown code block.
A programming competition site AtCode provides algorithmic problems.
Each problem is allocated a score based on its difficulty.
Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.
These p_1 + … +... | {"inputs": ["1 100\n1 100\n", "2 431\n3 500\n5 800", "2 110\n3 500\n5 800", "2 431\n3 896\n5 800", "2 400\n3 500\n5 800", "2 700\n3 500\n5 800", "2 700\n3 500\n5 800\n", "2 400\n3 500\n5 800\n"], "outputs": ["1\n", "3\n", "1\n", "3\n", "2", "3", "3\n", "2\n"]} | 575 | 185 |
coding | Solve the programming task below in a Python markdown code block.
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v_1 meters per second, and in the end it is v_2 meters per second. We know that this section of the route took exactly t seconds to pa... | {"inputs": ["5 6\n4 2\n", "1 1\n5 1\n", "1 1\n5 2\n", "1 1\n2 1\n", "1 2\n2 1\n", "1 5\n3 2\n", "2 1\n2 2\n", "1 1\n3 5\n"], "outputs": ["26", "9", "13", "2", "3", "9", "3", "8"]} | 457 | 112 |
coding | Solve the programming task below in a Python markdown code block.
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If... | {"inputs": ["3\n0\n2\n1", "3\n0\n1\n0", "3\n0\n0\n0", "3\n0\n2\n2", "3\n0\n1\n2", "3\n0\n2\n0", "3\n1\n1\n0", "3\n1\n0\n0"], "outputs": ["-1\n", "1\n", "0\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]} | 297 | 111 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle... | {"functional": "def check(candidate):\n assert candidate(s = \"**|**|***|\", queries = [[2,5],[5,9]]) == [2,3]\n assert candidate(s = \"***|**|*****|**||**|*\", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]) == [9,0,0,0,0]\n\n\ncheck(Solution().platesBetweenCandles)"} | 272 | 112 |
coding | Solve the programming task below in a Python markdown code block.
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is as... | {"inputs": ["3 3\n", "7 4\n", "2 8\n", "4 4\n", "8 8\n", "2 2\n", "6 1\n", "4 5\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | 531 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
You are given an array of N integers. Find the *minimum* number of integers you need to delete from the array such that the absolute difference between each pair of intege... | {"inputs": ["3\n2\n1 2\n5\n2 5 1 2 2\n4\n1 2 1 2"], "outputs": ["0\n2\n2"]} | 423 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a... | {"inputs": ["1\n0\n0\n", "1\n0\n0\n", "1\n1000000000\n0\n", "1\n1000000000\n0\n", "2\n7 91\n2\n1 2\n2 1\n", "2\n6 91\n2\n1 2\n2 1\n", "2\n7 91\n2\n1 2\n2 1\n", "3\n1 2 3\n3\n1 2\n2 3\n3 2\n"], "outputs": ["0 1\n", "0 1\n", "1000000000 1\n", "1000000000 1\n", "7 1\n", "6 1\n", "7 1\n", "3 1\n"]} | 656 | 203 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.
It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[... | {"functional": "def check(candidate):\n assert candidate(encoded = [3,1]) == [1,2,3]\n assert candidate(encoded = [6,5,4,6]) == [2,4,1,5,3]\n\n\ncheck(Solution().decode)"} | 145 | 64 |
coding | Solve the programming task below in a Python markdown code block.
-----General Statement:-----
Given the actual high and low temperatures for the day and the normal high and low temperatures for that day, calculate the average difference from normal.
-----Input:-----
The first line of the data set for this problem is ... | {"inputs": ["3\n75 45 78 40\n50 32 45 30\n56 48 62 45"], "outputs": ["1.0 DEGREE(S) ABOVE NORMAL\n3.5 DEGREE(S) ABOVE NORMAL\n1.5 DEGREE(S) BELOW NORMAL"]} | 320 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to buy a new laptop. However, he is confused about which laptop to buy out of 10 different laptops. He asks his N friends for their recommendation. The i^{th} friend recommends the Chef to buy the {A_{i}}^{th} laptop (1 ≤ A_{i} ≤ 10).
Chef w... | {"inputs": ["4\n5\n4 4 4 2 1\n7\n1 2 3 4 5 6 6\n6\n2 2 3 3 10 8\n4\n7 7 8 8\n"], "outputs": ["4\n6\nCONFUSED\nCONFUSED\n"]} | 515 | 75 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A, consisting of N integers and an array B, consisting of M integers.
The subsequence of A is the array that can be obtained by picking the elements at the arbitrary sorted set of positions from A.
Your task is to count the number ... | {"inputs": ["4 2\n7 7 7 7\n3 4\n\n", "5 3\n1 5 2 4 7\n7 9 6\n\n"], "outputs": ["6", "4"]} | 698 | 54 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
Given a balanced string s, split it into some number of substrings such that:
Each substring is balanced.
Return the maximum number o... | {"functional": "def check(candidate):\n assert candidate(s = \"RLRRLLRLRL\") == 4\n assert candidate(s = \"RLRRRLLRLL\") == 2\n assert candidate(s = \"LLLLRRRR\") == 1\n\n\ncheck(Solution().balancedStringSplit)"} | 101 | 67 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integers m and n, which represent the dimensions of a matrix.
You are also given the head of a linked list of integers.
Generate an m x n matrix that contains the integers in the linked list presente... | {"functional": "def check(candidate):\n assert candidate(m = 3, n = 5, head = list_node([3,0,2,6,8,1,7,9,4,2,5,5,0])) == [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]\n assert candidate(m = 1, n = 4, head = list_node([0,1,2])) == [[0,1,2,-1]]\n\n\ncheck(Solution().spiralMatrix)"} | 178 | 134 |
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 costs where costs[i] is the cost of hiring the ith worker.
You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:
... | {"functional": "def check(candidate):\n assert candidate(costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4) == 11\n assert candidate(costs = [1,2,4,1], k = 3, candidates = 3) == 4\n\n\ncheck(Solution().totalCost)"} | 308 | 93 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.