problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,2],[2,3],[5],[0],[5],[],[]]) == [2,4,5,6]\n assert candidate(graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]) == [4]\n\n\ncheck(Solution().eventualSafeNodes)"} | coding | 177 |
Solve the programming task below in a Python markdown code block.
You are a *khm*mad*khm* scientist and you decided to play with electron distribution among atom's shells.
You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons.
---... | {"functional": "_inputs = [[1], [10], [11], [22], [23], [47], [50], [52], [60], [61]]\n_outputs = [[[1]], [[2, 8]], [[2, 8, 1]], [[2, 8, 12]], [[2, 8, 13]], [[2, 8, 18, 19]], [[2, 8, 18, 22]], [[2, 8, 18, 24]], [[2, 8, 18, 32]], [[2, 8, 18, 32, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, floa... | coding | 265 |
Solve the programming task below in a Python markdown code block.
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of wo... | {"functional": "_inputs = [['AWUBBWUBC'], ['AWUBWUBWUBBWUBWUBWUBC'], ['WUBAWUBBWUBCWUB'], ['RWUBWUBWUBLWUB'], ['WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB'], ['WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB'], ['QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH'], ['WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTW... | coding | 404 |
Solve the programming task below in a Python markdown code block.
Given a board of `NxN`, distributed with tiles labeled `0` to `N² - 1`(inclusive):
A solved grid will have the tiles in order of label, left to right, top to bottom.
Return `true` if the board state is currently solved, and `false` if the board state i... | {"functional": "_inputs = [[[[1, 0], [3, 2]]], [[[1, 0, 4], [3, 2, 7], [8, 5, 6]]], [[[6, 7, 8], [0, 1, 2], [3, 4, 5]]]]\n_outputs = [[False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\... | coding | 173 |
Solve the programming task below in a Python markdown code block.
Chef has two integers A and B. In one operation he can choose any integer d, and make one of the following two moves :
Add d to A and subtract d from B.
Add d to B and subtract d from A.
Chef is allowed to make as many operations as he wants. Can he mak... | {"inputs": ["2\n3 3\n1 2\n"], "outputs": ["Yes\nNo\n"]} | coding | 294 |
Solve the programming task below in a Python markdown code block.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditio... | {"inputs": ["3\n4 2 3\n", "4\n5 4 2 1", "4\n5 2 2 1", "4\n8 2 2 1", "4\n8 2 1 1", "4\n6 4 2 1", "4\n5 4 3 1", "4\n6 2 2 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n"]} | coding | 252 |
Solve the programming task below in a Python markdown code block.
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle ... | {"inputs": ["1 0\n", "2 0\n", "6 0\n", "50 0\n", "49 0\n", "49 0\n", "50 0\n", "6 1\n4 1\n"], "outputs": ["YES\n1\n1 1\n", "YES\n2\n1 2\n1 2\n", "YES\n6\n1 2\n1 3\n2 4\n3 5\n4 6\n5 6\n", "YES\n50\n1 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n2... | coding | 491 |
Solve the programming task below in a Python markdown code block.
You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010...
Calculate the numb... | {"inputs": ["1\n1 1\n0\n", "1\n1 0\n1\n", "1\n1 0\n1\n", "1\n1 1\n0\n", "1\n1 -1\n1\n", "1\n2 2\n00\n", "1\n2 2\n00\n", "1\n1 -1\n1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 551 |
Solve the programming task below in a Python markdown code block.
# Bubblesort Algorithm
## Overview
The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.):
```python
[9, 7, 5, 3, ... | {"functional": "_inputs = [[[9, 7, 5, 3, 1, 2, 4, 6, 8]], [[1, 2]], [[2, 1]], [[1, 3]], [[3, 1]], [[24, 57]], [[89, 36]], [[1, 2, 3]], [[2, 4, 1]], [[17, 5, 11]], [[25, 16, 9]], [[103, 87, 113]], [[1032, 3192, 2864]], [[1, 2, 3, 4]], [[2, 3, 4, 1]], [[3, 4, 1, 2]], [[4, 1, 2, 3]], [[7, 5, 3, 1]], [[5, 3, 7, 7]], [[3, 1... | coding | 387 |
Solve the programming task below in a Python markdown code block.
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them.
-----Input---... | {"inputs": ["3\n0 1 1\n1 0 4\n1 4 0\n", "3\n0 1 1\n1 0 1\n1 1 0\n", "3\n0 1 1\n1 0 1\n1 1 0\n", "3\n0 1 1\n1 0 8\n1 4 0\n", "3\n0 1 1\n1 0 4\n1 4 0\n", "3\n0 72 17\n72 0 8\n17 8 0\n", "3\n0 99 73\n99 0 8\n73 8 0\n", "3\n0 99 73\n99 0 8\n73 8 0\n"], "outputs": ["2\n", "1\n", "1", "2\n", "2", "25\n", "81\n", "81"]} | coding | 289 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Vietnamese], and [Russian] as well.
Chef loves Chess and has thus invented a new piece named "Disabled King".
Let's denote the cell at the intersection of the i-th column from the left and j-th row from the top b... | {"inputs": ["2\n2\n3\n"], "outputs": ["2\n2\n"]} | coding | 478 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Consider a function that implements an algorithm similar to Binary Search. The function has two input parameters: sequence is a sequence of integers, and target is an integer value. The purpose of the function is to f... | {"functional": "def check(candidate):\n assert candidate(nums = [7]) == 1\n assert candidate(nums = [-1,5,2]) == 1\n\n\ncheck(Solution().binarySearchableNumbers)"} | coding | 264 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.
In one step, you can delete exactly one character in either string.
Please complete the following pyth... | {"functional": "def check(candidate):\n assert candidate(word1 = \"leetcode\", word2 = \"etco\") == 4\n\n\ncheck(Solution().minDistance)"} | coding | 93 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string s, and two integers num1 and num2. num1 and num2 are coprime numbers.
A ratio substring is a substring of s where the ratio between the number of 0's and the number of 1's in the substrin... | {"functional": "def check(candidate):\n assert candidate(s = \"0110011\", num1 = 1, num2 = 2) == 4\n assert candidate(s = \"10101\", num1 = 3, num2 = 1) == 0\n\n\ncheck(Solution().fixedRatio)"} | coding | 235 |
Solve the programming task below in a Python markdown code block.
Your task is to create function```isDivideBy``` (or ```is_divide_by```) to check if an integer number is divisible by each out of two arguments.
A few cases:
```
(-12, 2, -6) -> true
(-12, 2, -5) -> false
(45, 1, 6) -> false
(45, 5, 15) -> ... | {"functional": "_inputs = [[8, 2, 4], [12, -3, 4], [8, 3, 4], [48, 2, -5], [-100, -25, 10], [10000, 5, -3], [4, 4, 2], [5, 2, 3], [-96, 25, 17], [33, 1, 33]]\n_outputs = [[True], [True], [False], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | coding | 174 |
Solve the programming task below in a Python markdown code block.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the ... | {"inputs": ["1 1\n1 1\n", "2 1\n2 2\n", "9 1\n1 1\n", "1 1\n1 1\n", "2 1\n2 2\n", "9 1\n1 1\n", "2 1\n2 3\n", "4 2\n1 4\n2 4\n"], "outputs": ["1\n0\n", "1\n0 0\n", "1\n0 0 0 0 0 0 0 0 0\n", "1\n0 ", "1\n0 0 ", "1\n0 0 0 0 0 0 0 0 0 ", "2\n0 1\n", "3\n0 1 2 0\n"]} | coding | 541 |
Solve the programming task below in a Python markdown code block.
There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).
For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.
We say a set of choices ... | {"inputs": ["1\n0\n", "1\n1\n", "3\n1 0 1", "3\n1 1 0", "3\n0 0 0", "3\n0 0 0", "3\n1 1 0", "3\n1 0 1"], "outputs": ["0\n", "1\n1\n", "1\n3\n", "1\n2\n", "0\n\n", "0\n\n", "1\n2\n", "1\n3\n"]} | coding | 474 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays of equal length target and arr. In one step, you can select any non-empty subarray of arr and reverse it. You are allowed to make any number of steps.
Return true if you can make arr e... | {"functional": "def check(candidate):\n assert candidate(target = [1,2,3,4], arr = [2,4,1,3]) == True\n assert candidate(target = [7], arr = [7]) == True\n assert candidate(target = [3,7,9], arr = [3,7,11]) == False\n\n\ncheck(Solution().canBeEqual)"} | coding | 110 |
Solve the programming task below in a Python markdown code block.
You receive the name of a city as a string, and you need to return a string that shows how many times each letter shows up in the string by using an asterisk (`*`).
For example:
```
"Chicago" --> "c:**,h:*,i:*,a:*,g:*,o:*"
```
As you can see, the le... | {"functional": "_inputs = [['Chicago'], ['Bangkok'], ['Las Vegas'], ['Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch']]\n_outputs = [['c:**,h:*,i:*,a:*,g:*,o:*'], ['b:*,a:*,n:*,g:*,k:**,o:*'], ['l:*,a:**,s:**,v:*,e:*,g:*'], ['l:***********,a:***,n:****,f:*,i:***,r:****,p:*,w:****,g:*******,y:*****,o:******,... | coding | 263 |
Solve the programming task below in a Python markdown code block.
Create a combat function that takes the player's current health and the amount of damage recieved, and returns the player's new health.
Health can't be less than 0.
Also feel free to reuse/extend the following starter code:
```python
def combat(health, d... | {"functional": "_inputs = [[100, 5], [83, 16], [20, 30]]\n_outputs = [[95], [67], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return... | coding | 71 |
Solve the programming task below in a Python markdown code block.
Here you have to do some mathematical operations on a "dirty string". This kata checks some basics, it's not too difficult.
__So what to do?__
Input: String which consists of two positive numbers (doubles) and exactly one operator like `+, -, * or /` ... | {"functional": "_inputs = [[';$%\u00a7fsdfsd235??df/sdfgf5gh.000kk0000'], ['sdfsd23454sdf*2342'], ['fsdfsd235???34.4554s4234df-sdfgf2g3h4j442'], ['fsdfsd234.4554s4234df+sf234442'], ['a1a2b3c.c0c/a1a0b.cc00c']]\n_outputs = [['47'], ['54929268'], ['-210908'], ['234676'], ['12']]\nimport math\ndef _deep_eq(a, b, tol=1e-5)... | coding | 245 |
Solve the programming task below in a Python markdown code block.
There is an integer array $\boldsymbol{d}$ which does not contain more than two elements of the same value. How many distinct ascending triples ($d[i]<d[j]<d[k],i<j<k$) are present?
Input format
The first line contains an integer, $N$, denoting the n... | {"inputs": ["6\n1 1 2 2 3 4\n"], "outputs": ["4\n"]} | coding | 267 |
Solve the programming task below in a Python markdown code block.
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color c_{i}. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n6\n", "1\n9\n", "2\n1 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 424 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing the number of nodes in a connected undirected graph containing exactly one cycle. The nodes are numbered from 0 to n - 1 (inclusive).
You are also given a 2D integer arr... | {"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[1,2],[2,4],[4,3],[3,1],[0,1],[5,2],[6,5]]) == [1,0,0,0,0,1,2]\n assert candidate(n = 9, edges = [[0,1],[1,2],[0,2],[2,6],[6,7],[6,8],[0,3],[3,4],[3,5]]) == [0,0,0,1,2,2,1,2,2]\n\n\ncheck(Solution().distanceToCycle)"} | coding | 194 |
Solve the programming task below in a Python markdown code block.
You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.
Write the program which finds the number of points in the intersection of two given set... | {"inputs": ["2 2 1\n1 2 0\n", "1 0 0\n0 1 0\n", "1 1 0\n2 2 1\n", "1 1 2\n0 1 0\n", "0 0 0\n0 0 1\n", "0 1 0\n1 0 1\n", "1 0 1\n0 0 1\n", "4 6 1\n2 3 1\n"], "outputs": ["1", "1", "0", "1", "0", "1", "0", "0"]} | coding | 202 |
Solve the programming task below in a Python markdown code block.
Chef has an array A of length N.
In one operation, Chef can choose any two distinct indices i, j (1 ≤ i, j ≤ N, i \neq j) and either change A_{i} to A_{j} or change A_{j} to A_{i}.
Find the minimum number of operations required to make all the elements... | {"inputs": ["4\n3\n1 2 3\n4\n5 5 5 5\n4\n2 2 1 1\n3\n1 1 2\n"], "outputs": ["2\n0\n2\n1\n"]} | coding | 590 |
Solve the programming task below in a Python markdown code block.
Given an integer a as input, print the value a + a^2 + a^3.
-----Constraints-----
- 1 \leq a \leq 10
- a is an integer.
-----Input-----
Input is given from Standard Input in the following format:
a
-----Output-----
Print the value a + a^2 + a^3 as a... | {"inputs": ["1", "0", "3", "4", "6", "7", "5", "9"], "outputs": ["3\n", "0\n", "39\n", "84\n", "258\n", "399\n", "155\n", "819\n"]} | coding | 169 |
Solve the programming task below in a Python markdown code block.
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into $n$ sub-tracks. You are given an array $a$ where $a... | {"inputs": ["3\n3\n1 2 6\n4\n2 1 1 0\n10\n0 2 5 23 4 2 4 5 7 8\n", "3\n3\n1 2 8\n4\n2 1 1 0\n10\n0 2 5 23 4 2 4 5 7 8\n", "3\n3\n1 2 8\n4\n2 1 1 0\n10\n0 2 5 23 4 2 4 5 1 8\n", "3\n3\n1 2 8\n4\n2 1 1 0\n10\n0 2 5 23 4 4 5 5 2 8\n", "3\n3\n1 2 8\n4\n3 1 1 0\n10\n0 2 5 28 4 4 5 5 2 8\n", "3\n3\n1 2 8\n4\n3 1 1 1\n10\n0 2... | coding | 492 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true:
perm[i] is divi... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 2\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().countArrangement)"} | coding | 127 |
Solve the programming task below in a Python markdown code block.
You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:
- The string does not contain characters other than A, C, G and T.
- The string does not contain AGC as a substring.
- The conditi... | {"inputs": ["5", "6", "8", "9", "7", "6", "5", "4"], "outputs": ["865\n", "3247\n", "45719\n", "171531\n", "12185\n", "3247\n", "865\n", "230"]} | coding | 281 |
Solve the programming task below in a Python markdown code block.
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Nold... | {"inputs": ["2 0\n", "4 7\n", "9 0\n", "2 9\n", "3 7\n", "8 0\n", "3 4\n", "3 0\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n"]} | coding | 334 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is a private detective. He was asked to investigate a case of murder in the city of Frangton.
Chef arrived in Frangton to find out that the mafia was involved in the cas... | {"inputs": ["6\n0 1 1 2 2 3"], "outputs": ["4 5 6"]} | coding | 455 |
Solve the programming task below in a Python markdown code block.
How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other? The knights have to be placed on different squares. A knight can move two squares horizontally and one square vertically, or two s... | {"inputs": ["3\n2 2\n2 3\n4 5", "3\n2 2\n2 3\n2 5", "3\n2 2\n2 1\n4 5", "3\n4 2\n2 3\n2 5", "3\n4 2\n2 6\n2 5", "3\n2 2\n2 3\n5 5", "3\n2 2\n2 3\n2 6", "3\n2 2\n2 1\n4 6"], "outputs": ["12\n26\n312", "12\n26\n78\n", "12\n2\n312\n", "48\n26\n78\n", "48\n116\n78\n", "12\n26\n504\n", "12\n26\n116\n", "12\n2\n464\n"]} | coding | 209 |
Solve the programming task below in a Python markdown code block.
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer $p$ (which may be positive, negative, or zero). To combine their tastes, they invented $p$-binary numbers... | {"inputs": ["1 1\n", "1 0\n", "5 2\n", "9 8\n", "3 2\n", "2 1\n", "9 4\n", "1 0\n"], "outputs": ["-1\n", "1\n", "-1\n", "1\n", "1\n", "1\n", "-1\n", "1\n"]} | coding | 670 |
Solve the programming task below in a Python markdown code block.
In a class of N students, a class test was held. The i^{th} student scored A_{i} marks. It is also known that the scores of all students were distinct.
A student passes the test if their score is strictly greater than the passing mark.
Given that exact... | {"inputs": ["3\n2 2\n5 1\n4 1\n5 1 7 4\n4 3\n15 70 100 31\n"], "outputs": ["0\n6\n30\n"]} | coding | 486 |
Solve the programming task below in a Python markdown code block.
Codefortia is a small island country located somewhere in the West Pacific. It consists of $n$ settlements connected by $m$ bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be equal... | {"inputs": ["2 1 1 2\n2 1 1\n", "2 1 1 2\n2 1 1\n", "2 1 1 4\n2 1 1\n", "2 1 185269 10000000\n1 2 10000000\n", "2 1 9999999 10000000\n1 2 10000000\n", "2 1 9999999 10000000\n1 2 10000000\n", "2 1 12099651 10000000\n1 2 10000000\n", "3 2 509529 96762\n1 2 509529\n3 2 509529\n"], "outputs": ["0 1\n", "0 1\n", "0 1 ", "0 ... | coding | 751 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]) == [1,5]\n assert candidate(arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764]) == []\n\n\ncheck(Solution().arraysIntersection)"} | coding | 99 |
Solve the programming task below in a Python markdown code block.
Given is an undirected graph G consisting of N vertices numbered 1 through N and M edges numbered 1 through M.
Edge i connects Vertex a_i and Vertex b_i bidirectionally.
G is said to be a good graph when both of the conditions below are satisfied. It is ... | {"inputs": ["1\n100000 0\n", "3\n3 0\n6 2\n1 2\n2 3\n15 10\n12 14\n8 3\n10 1\n14 6\n12 6\n1 9\n13 1\n2 5\n3 9\n7 2\n"], "outputs": ["First\n", "First\nSecond\nFirst\n"]} | coding | 609 |
Solve the programming task below in a Python markdown code block.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
- For each ... | {"inputs": ["2\n0 0", "2\n0 1", "2\n1 1", "2\n1 1", "2\n0 1", "2\n0 0", "2\n1 0", "2\n1 0\n"], "outputs": ["0 0\n", "0 1\n", "1 0\n", "1 0\n", "0 1\n", "0 0\n", "1 1", "1 1\n"]} | coding | 380 |
Solve the programming task below in a Python markdown code block.
You are given an array a of length n. We define f_{a} the following way:
Initially f_{a} = 0, M = 1; for every 2 ≤ i ≤ n if a_{M} < a_{i} then we set f_{a} = f_{a} + a_{M} and then set M = i.
Calculate the sum of f_{a} over all n! permutations of t... | {"inputs": ["2\n1 3\n", "2\n1 6\n", "2\n1 9\n", "2\n1 3\n", "3\n1 1 2\n", "3\n1 2 2\n", "3\n1 2 4\n", "3\n1 1 4\n"], "outputs": ["1", "1\n", "1\n", "1\n", "4", "2\n", "8\n", "4\n"]} | coding | 450 |
Solve the programming task below in a Python markdown code block.
This kata is an extension of "Combinations in a Set Using Boxes":https://www.codewars.com/kata/5b5f7f7607a266914200007c
The goal for this kata is to get all the possible combinations (or distributions) (with no empty boxes) of a certain number of balls,... | {"functional": "_inputs = [[4], [3], [2], [20]]\n_outputs = [[[15, 7, 2]], [[5, 3, 2]], [[2, 1, 2]], [[51724158235372, 15170932662679, 8]]]\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,... | coding | 569 |
Solve the programming task below in a Python markdown code block.
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] con... | {"inputs": ["3\n1 2 3\n2\n1 2\n2 3\n", "3\n1 2 3\n2\n1 2\n2 6\n", "3\n1 2 3\n2\n1 2\n1 3\n", "3\n1 2 3\n2\n1 2\n2 5\n", "3\n1 2 3\n2\n1 3\n2 6\n", "3\n1 2 3\n2\n1 2\n2 3\n", "3\n2 1 3\n3\n2 3\n1 1\n1 3\n", "3\n2 1 3\n3\n2 3\n1 1\n1 3\n"], "outputs": ["odd\neven\n", "odd\nodd\n", "odd\neven\n", "odd\nodd\n", "odd\nodd\n... | coding | 690 |
Solve the programming task below in a Python markdown code block.
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
Input
The input is a sequence of datasets. The end of the i... | {"inputs": ["2 2\n2 8\n0 0", "4 1\n2 7\n0 0", "6 2\n7 8\n0 0", "3 3\n2 1\n0 0", "5 1\n2 7\n0 0", "4 4\n6 4\n0 0", "4 1\n3 8\n0 0", "5 1\n1 7\n0 0"], "outputs": ["Monday\nSunday\n", "Thursday\nSaturday\n", "Wednesday\nThursday\n", "Wednesday\nSunday\n", "Saturday\nSaturday\n", "Sunday\nFriday\n", "Thursday\nMonday\n", "... | coding | 212 |
Solve the programming task below in a Python markdown code block.
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to co... | {"inputs": ["1\n2\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n1\n", "1\n7\n", "1\n3\n", "1\n6\n"], "outputs": ["98\n", "98\n", "9998\n", "99988\n", "8\n", "9999988\n", "998\n", "999988\n"]} | coding | 675 |
Solve the programming task below in a Python markdown code block.
This is a spin off of my first [kata](http://www.codewars.com/kata/56bc28ad5bdaeb48760009b0). You are given a list of character sequences as a comma separated string. Write a function which returns another string containing all the character sequences ex... | {"functional": "_inputs = [[''], ['1'], ['1, 3'], ['1,2,3'], ['1,2,3,4']]\n_outputs = [[None], [None], [None], ['2'], ['2 3']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple... | coding | 143 |
Solve the programming task below in a Python markdown code block.
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi.
You want to find a subset of items to put such that:
* The total value of the items is as large as possible.
* The items have combined weight at most W, that... | {"inputs": ["2 20\n5 9\n4 0", "2 20\n5 28\n4 8", "2 20\n5 14\n4 8", "2 20\n5 14\n5 8", "2 20\n5 28\n1 8", "2 20\n5 9\n4 10", "2 20\n5 14\n4 10", "2 20\n5 28\n1 10"], "outputs": ["9\n", "4\n", "5\n", "5\n", "1\n", "9", "5\n", "1\n"]} | coding | 256 |
Solve the programming task below in a Python markdown code block.
### Background
We **all** know about "balancing parentheses" (plus brackets, braces and chevrons) and even balancing characters that are identical.
Read that last sentence again, I balanced different characters and identical characters twice and you ... | {"functional": "_inputs = [['(Sensei says yes!)', '()'], ['(Sensei says no!', '()'], ['(Sensei [says] yes!)', '()[]'], ['(Sensei [says) no!]', '()[]'], ['Sensei says -yes-!', '--'], ['Sensei -says no!', '--'], ['Hello Mother can you hear me?', '()'], ['(Hello Mother can you hear me?)', '()'], ['(Hello Mother can you he... | coding | 351 |
Solve the programming task below in a Python markdown code block.
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has a_{i} apples. This tree has a special property: the lengths of all paths from the root to any leaf have th... | {"inputs": ["3\n2 2 3\n1 1\n", "3\n1 2 3\n1 1\n", "3\n1 1 3\n1 1\n", "3\n2 2 3\n1 2\n", "3\n2 0 3\n1 2\n", "3\n2 0 1\n1 2\n", "3\n1 2 3\n1 1\n", "3\n2 2 3\n1 1\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]} | coding | 739 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sereja has an array A that contains n integers: A_{1}, A_{2}, ..., A_{n}.
Sereja also has an array B that contains n integers B_{1}, B_{2}, ..., B_{n}.
In a single step Sereja can choose two i... | {"inputs": ["1\n5\n2 1 3 0 3\n2 2 0 1 0"], "outputs": ["1"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
Treeland is a country with $n$ cities and $n-1$ roads. There is exactly one path between any two cities.
The ruler of Treeland wants to implement a self-driving bus system and asks tree-loving Alex to plan the bus routes. Alex decides that each route ... | {"inputs": ["3\n1 3\n3 2\n"], "outputs": ["5\n"]} | coding | 636 |
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... | coding | 334 |
Solve the programming task below in a Python markdown code block.
# Explanation
It's your first day in the robot factory and your supervisor thinks that you should start with an easy task. So you are responsible for purchasing raw materials needed to produce the robots.
A complete robot weights `50` kilogram. Iron is... | {"functional": "_inputs = [[[10], 90], [[20, 10], 55], [[0], 90], [[0, 0, 0], 90], [[10, 0], 90], [[0, 10], 90], [[10, 0, 0, 10], 81], [[0, 10, 0, 10], 81], [[0, 10, 10, 0], 81], [[10, 20, 30, 40, 50, 60, 70, 80, 90], 25], [[90, 80, 70, 60, 50, 40, 30, 20, 10], 20], [[10, 0, 30, 0, 50, 0, 70, 0, 90], 25], [[22, 33, 44,... | coding | 339 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers.
You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$.
Your task is to calculate the maximum possible length of the strictly increasing contiguous ... | {"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 1\n", "2\n7 6\n", "2\n2 2\n", "2\n2 1\n", "2\n1 1\n", "2\n2 2\n"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "1", "1", "1"]} | coding | 400 |
Solve the programming task below in a Python markdown code block.
You are given the array $a$ consisting of $n$ positive (greater than zero) integers.
In one move, you can choose two indices $i$ and $j$ ($i \ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \le 1$) and ... | {"inputs": ["1\n1\n23\n", "1\n1\n46\n", "1\n1\n114\n", "1\n1\n157\n", "1\n1\n305\n", "1\n1\n292\n", "1\n1\n430\n", "2\n3\n1 2 2\n4\n5 5 5 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\nYES\n"]} | coding | 544 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given positive integers n and target.
An array nums is beautiful if it meets the following conditions:
nums.length == n.
nums consists of pairwise distinct positive integers.
There doesn't exist two distinct ... | {"functional": "def check(candidate):\n assert candidate(n = 2, target = 3) == 4\n assert candidate(n = 3, target = 3) == 8\n assert candidate(n = 1, target = 1) == 1\n\n\ncheck(Solution().minimumPossibleSum)"} | coding | 141 |
Solve the programming task below in a Python markdown code block.
In a bizarre game of chess ,knight was so drunk, that instead of his usual move he started walking straight. In every move Knight jumps on 2n steps forward (n is number of block that he had travelled so far from starting) but after that he has to take ei... | {"inputs": ["2\n17\n10"], "outputs": ["2111\n0"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
Pete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun.
They decide to have a competition. 3 rounds, 2 shots each. Winner is the one with the most hits.
Some of the clays have something attached to create ... | {"functional": "_inputs = [[[[{'P1': 'XX', 'P2': 'XO'}, True], [{'P1': 'OX', 'P2': 'OO'}, False], [{'P1': 'XX', 'P2': 'OX'}, True]]], [[[{'P1': 'XX', 'P2': 'XO'}, False], [{'P1': 'OX', 'P2': 'XX'}, False], [{'P1': 'OO', 'P2': 'XX'}, True]]], [[[{'P1': 'OO', 'P2': 'XX'}, False], [{'P1': 'OO', 'P2': 'XX'}, False], [{'P1'... | coding | 312 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n matrix grid where each cell is either a wall 'W', an enemy 'E' or empty '0', return the maximum enemies you can kill using one bomb. You can only place the bomb in an empty cell.
The bomb kills all the ... | {"functional": "def check(candidate):\n assert candidate(grid = [[\"0\",\"E\",\"0\",\"0\"],[\"E\",\"0\",\"W\",\"E\"],[\"0\",\"E\",\"0\",\"0\"]]) == 3\n assert candidate(grid = [[\"W\",\"W\",\"W\"],[\"0\",\"0\",\"0\"],[\"E\",\"E\",\"E\"]]) == 1\n\n\ncheck(Solution().maxKilledEnemies)"} | coding | 130 |
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, where nums[i] represents the score of the ith student. You are also given an integer k.
Pick the scores of any k students from the array so that the difference between the... | {"functional": "def check(candidate):\n assert candidate(nums = [90], k = 1) == 0\n assert candidate(nums = [9,4,1,7], k = 2) == 2\n\n\ncheck(Solution().minimumDifference)"} | coding | 117 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $2$) or determine that there is no such subset.
Both the given array and required subset may contain e... | {"inputs": ["1\n2\n1 1\n", "1\n2\n1 1\n", "1\n3\n1 1\n", "1\n3\n1 2\n", "1\n3\n0 2\n", "1\n3\n0 3\n", "1\n3\n0 1\n", "1\n4\n1 2\n"], "outputs": ["2\n1 2\n", "2\n1 2\n", "2\n1 2\n", "1\n2\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n2\n"]} | coding | 427 |
Solve the programming task below in a Python markdown code block.
You wish to buy video games from the famous online video game store Mist.
Usually, all games are sold at the same price, $\boldsymbol{p}$ dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a ... | {"inputs": ["20 3 6 80\n", "20 3 6 85\n"], "outputs": ["6\n", "7\n"]} | coding | 677 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string, message, and a positive integer, limit.
You must split message into one or more parts based on limit. Each resulting part should have the suffix "<a/b>", where "b" is to be replaced with the to... | {"functional": "def check(candidate):\n assert candidate(message = \"this is really a very awesome message\", limit = 9) == [\"thi<1/14>\",\"s i<2/14>\",\"s r<3/14>\",\"eal<4/14>\",\"ly <5/14>\",\"a v<6/14>\",\"ery<7/14>\",\" aw<8/14>\",\"eso<9/14>\",\"me<10/14>\",\" m<11/14>\",\"es<12/14>\",\"sa<13/14>\",\"ge<14/14... | coding | 232 |
Solve the programming task below in a Python markdown code block.
The code provided is supposed replace all the dots `.` in the specified String `str` with dashes `-`
But it's not working properly.
# Task
Fix the bug so we can all go home early.
# Notes
String `str` will never be null.
Also feel free to reuse/exte... | {"functional": "_inputs = [[''], ['no dots'], ['one.two.three'], ['........']]\n_outputs = [[''], ['no dots'], ['one-two-three'], ['--------']]\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 isinstanc... | coding | 90 |
Solve the programming task below in a Python markdown code block.
You will be given an array of numbers.
For each number in the array you will need to create an object.
The object key will be the number, as a string. The value will be the corresponding character code, as a string.
Return an array of the resulting o... | {"functional": "_inputs = [[[118, 117, 120]], [[101, 121, 110, 113, 113, 103]], [[118, 103, 110, 109, 104, 106]], [[107, 99, 110, 107, 118, 106, 112, 102]], [[100, 100, 116, 105, 117, 121]]]\n_outputs = [[[{'118': 'v'}, {'117': 'u'}, {'120': 'x'}]], [[{'101': 'e'}, {'121': 'y'}, {'110': 'n'}, {'113': 'q'}, {'113': 'q'}... | coding | 116 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. You are given an ascending array nums consisting of three-digit integers representing a binary tree with... | {"functional": "def check(candidate):\n assert candidate(nums = [113, 215, 221]) == 12\n assert candidate(nums = [113, 221]) == 4\n\n\ncheck(Solution().pathSum)"} | coding | 203 |
Solve the programming task below in a Python markdown code block.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be s... | {"inputs": ["3 3\n39 4 1", "4 1\n5 4 0 1", "3 1\n5 4 0 1", "3 2\n39 19 1", "3 2\n39 14 1", "3 2\n39 18 1", "3 1\n39 18 1", "3 1\n39 16 1"], "outputs": ["No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | coding | 229 |
Solve the programming task below in a Python markdown code block.
We define subsequence as any subset of an array. We define a subarray as a contiguous subsequence in an array.
Given an array, find the maximum possible sum among:
all nonempty subarrays.
all nonempty subsequences.
Print the two values as space-s... | {"inputs": ["1\n5\n-2 -3 -1 -4 -6\n", "2\n4\n1 2 3 4\n6\n2 -1 2 3 4 -5\n"], "outputs": ["-1 -1\n", "10 10\n10 11\n"]} | coding | 568 |
Solve the programming task below in a Python markdown code block.
# Introduction
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. The letters called airstrike to help them in war -... | {"functional": "_inputs = [['z'], ['z*dq*mw*pb*s'], ['zdqmwpbs'], ['zz*zzs'], ['sz**z**zs'], ['z*z*z*zs'], ['*wwwwww*z*']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], [\"Let's fight again!\"], ['Right side wins!'], ['Left side wins!'], ['Left side wins!'], ['Left side wins!']]\nimport math\ndef _deep_e... | coding | 336 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and an integer value.
In one operation, you can add or subtract value from any element of nums.
For example, if nums = [1,2,3] and value = 2, you can choose to subtract va... | {"functional": "def check(candidate):\n assert candidate(nums = [1,-10,7,13,6,8], value = 5) == 4\n assert candidate(nums = [1,-10,7,13,6,8], value = 7) == 2\n\n\ncheck(Solution().findSmallestInteger)"} | coding | 197 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtrans... | {"inputs": ["5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 0\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 1\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n", "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n"... | coding | 671 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums and divisors.
The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
Return the integer divisors[i] with the maximum divis... | {"functional": "def check(candidate):\n assert candidate(nums = [4,7,9,3,9], divisors = [5,2,3]) == 3\n assert candidate(nums = [20,14,21,10], divisors = [5,7,5]) == 5\n assert candidate(nums = [12], divisors = [10,16]) == 10\n\n\ncheck(Solution().maxDivScore)"} | coding | 120 |
Solve the programming task below in a Python markdown code block.
Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties.
Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so you deci... | {"inputs": ["3\n1 2\n0 4\n-1 1\n"], "outputs": ["4\n2\n0\n"]} | coding | 402 |
Solve the programming task below in a Python markdown code block.
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards.
A deck is called sorted if the front values are in increasing order and t... | {"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n2 1\n", "2\n1 2\n3 4\n", "2\n2 1\n3 4\n", "2\n1 2\n3 4\n", "3\n1 2\n3 6\n4 5\n", "3\n3 5\n4 1\n2 6\n"], "outputs": ["0\n", "0\n", "0\n", "-1\n", "-1\n", "\n-1\n", "-1\n", "0\n"]} | coding | 486 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
While vacationing in Egypt, Chef found a recipe of an ancient dish. The receipt is a sequence of hieroglyphs written on a magic paper - it survived for thousands of years! Th... | {"inputs": ["3\n3 3\n1 2\n2 3\n1 3\n3 2\n1 2\n1 3\n5 4\n1 3\n2 3\n3 4\n2 5"], "outputs": ["1\n2\n2"]} | coding | 660 |
Solve the programming task below in a Python markdown code block.
Jack really likes his number five: the trick here is that you have to multiply each number by 5 raised to the number of digits of each numbers, so, for example:
```python
multiply(3)==15
multiply(10)==250
multiply(200)==25000
multiply(0)==0
multiply(-3)=... | {"functional": "_inputs = [[10], [5], [200], [0], [-2]]\n_outputs = [[250], [25], [25000], [0], [-10]]\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) !... | coding | 116 |
Solve the programming task below in a Python markdown code block.
A string is binary, if it consists only of characters "0" and "1".
String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01"... | {"inputs": ["1\n0\n", "2\n1\n", "1\n1\n", "0\n1\n", "2\n0\n", "0\n0\n", "0\n00\n", "1\n00\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "0\n", "1\n", "3\n", "0\n"]} | coding | 376 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).
You want to choose an integer... | {"functional": "def check(candidate):\n assert candidate(s = \"abcacb\", p = \"ab\", removable = [3,1,0]) == 2\n assert candidate(s = \"abcbddddd\", p = \"abcd\", removable = [3,2,1,4,5,6]) == 1\n assert candidate(s = \"abcab\", p = \"abc\", removable = [0,1,2,3,4]) == 0\n\n\ncheck(Solution().maximumRemovals)"... | coding | 240 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a string and two indexes (`a` and `b`). Your task is to reverse the portion of that string between those two indices inclusive.
~~~if-not:fortran
```
solve("codewars",1,5) = "cawedors" -- elements at index 1 to 5 inclusi... | {"functional": "_inputs = [['codewars', 1, 5], ['codingIsFun', 2, 100], ['FunctionalProgramming', 2, 15], ['abcefghijklmnopqrstuvwxyz', 0, 20], ['abcefghijklmnopqrstuvwxyz', 5, 20]]\n_outputs = [['cawedors'], ['conuFsIgnid'], ['FuargorPlanoitcnmming'], ['vutsrqponmlkjihgfecbawxyz'], ['abcefvutsrqponmlkjihgwxyz']]\nimpo... | coding | 417 |
Solve the programming task below in a Python markdown code block.
Snuke is interested in strings that satisfy the following conditions:
* The length of the string is at least N.
* The first N characters equal to the string s.
* The last N characters equal to the string t.
Find the length of the shortest string that... | {"inputs": ["1\na\n{", "1\n`\nz", "1\n`\n{", "1\n`\n|", "1\n`\n}", "1\n`\n~", "1\n_\n~", "1\n_\n\u007f"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | coding | 176 |
Solve the programming task below in a Python markdown code block.
Chef played an interesting game yesterday. This game is played with two variables $X$ and $Y$; initially, $X = Y = 0$. Chef may make an arbitrary number of moves (including zero). In each move, he must perform the following process:
- Choose any positive... | {"inputs": ["3\n3\n8\n9"], "outputs": ["3\n5\n6"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
Compare two strings by comparing the sum of their values (ASCII character code).
* For comparing treat all letters as UpperCase
* `null/NULL/Nil/None` should be treated as empty strings
* If the string contains other characters than letters, treat the w... | {"functional": "_inputs = [['AD', 'BC'], ['AD', 'DD'], ['gf', 'FG'], ['Ad', 'DD'], ['zz1', ''], ['ZzZz', 'ffPFF'], ['kl', 'lz'], [None, ''], ['!!', '7476'], ['##', '1176']]\n_outputs = [[True], [False], [True], [False], [True], [True], [False], [True], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | coding | 204 |
Solve the programming task below in a Python markdown code block.
Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); w... | {"inputs": ["3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 8 4 6 2", "3\n1 6 7 9 5 4 8 3 2", "3\n2 4 7 9 5 3 8 6 1", "3\n1 3 7 9 4 8 5 6 2", "3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 4 8 6 2", "4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1", "3"]} | coding | 627 |
Solve the programming task below in a Python markdown code block.
Amer cabs has released a scheme through which a user gets a free drive when he shares a reference code with another Amer app user. Given N number of app users, output total number of free drives gained by all of them. Two same users cannot share referenc... | {"inputs": ["340\n5277\n9302\n7274\n3\n5968\n1327\n255\n27\n5665\n8104\n138\n4051\n4168\n507\n7773\n2688\n3497\n4074\n1403\n3599\n2007\n7621\n3124\n1195\n7245\n1979\n3365\n6607\n4816\n9336\n3620\n1557\n3404\n5451\n3739\n2504\n1845\n5533\n8298\n2893\n7814\n2505\n9785\n4709\n7880\n6262\n5135\n2088\n9309\n7259\n9993\n325\... | coding | 208 |
Solve the programming task below in a Python markdown code block.
itertools.combinations(iterable, r)
This tool returns the $\textbf{r}$ length subsequences of elements from the input iterable.
Combinations are emitted in lexicographic sorted order. So, if the input iterable is sorted, the combination tuples will be... | {"inputs": ["HACK 2\n"], "outputs": ["A\nC\nH\nK\nAC\nAH\nAK\nCH\nCK\nHK\n"]} | coding | 393 |
Solve the programming task below in a Python markdown code block.
Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one lette... | {"functional": "_inputs = [['Something', 'Home'], ['Something', 'Fun'], ['Something', ''], ['', 'Something'], ['BANANA', 'banana'], ['test', 'lllt'], ['', ''], ['1234567', '541265'], ['supercalifragilisticexpialidocious', 'SoundOfItIsAtrocious'], ['LoremipsumdolorsitametconsecteturadipiscingelitAeneannonaliquetligulaut... | coding | 277 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game.
They start with a positive integer $n$ and take alternating turns doing operations on it. Each turn a player can subtract from $n$ one of its divisors that isn't $1$ or $n$. The player who cannot make a move on his/her ... | {"inputs": ["4\n1\n4\n12\n69\n"], "outputs": ["Bob\nAlice\nAlice\nBob\n"]} | coding | 363 |
Solve the programming task below in a Python markdown code block.
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determ... | {"inputs": ["5\n", "1\n", "2\n", "3\n", "4\n", "3\n", "1\n", "4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 254 |
Solve the programming task below in a Python markdown code block.
A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows.
There is a grid-like field of vertical h squares x horizontal w squares, and each block has at most one block. Each block... | {"inputs": ["4 6 3\n......\n..Y...\n...Y..\nRRYRYY", "4 6 1\n......\n...Y..\n/..Z..\nYRRRYY", "4 6 3\n......\n...Y..\n...Y..\nRRYRZ.", "4 6 3\n......\n...Y..\n/..Y..\nRRYRYY", "4 6 3\n......\n...Y..\n...Y..\n.RYRYR", "4 6 3\n......\n...Y..\n...Z..\nRRYRZ.", "4 6 3\n......\n...Y..\n/..Z..\nRRYRYY", "4 6 3\n....-.\n...Y.... | coding | 456 |
Solve the programming task below in a Python markdown code block.
For a given polygon g and target points t, print "2" if g contains t, "1" if t is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon... | {"inputs": ["4\n0 0\n3 1\n2 3\n0 3\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 1\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 3\n3\n2 0\n0 2\n0 2", "4\n0 0\n3 1\n4 3\n0 3\n3\n2 0\n0 3\n0 2", "4\n0 0\n2 1\n2 2\n0 3\n3\n2 1\n0 1\n3 2", "4\n1 0\n3 0\n2 3\n0 3\n3\n2 0\n0 0\n0 4", "4\n0 1\n3 1\n6 3\n0 3\n3\n2 0\n0 5\n0 2", "4\n0 0... | coding | 390 |
Solve the programming task below in a Python markdown code block.
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, ... | {"inputs": ["1\n", ",\n", "0\n", ",,\n", "1,\n", ",1\n", "2,\n", ",2\n"], "outputs": ["1\n", ",\n", "0\n", ", ,\n", "1,\n", ", 1\n", "2,\n", ", 2\n"]} | coding | 498 |
Solve the programming task below in a Python markdown code block.
Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit.
Vasya has $n$ problems to choose from. They are numbered from $1$ to $n$. The difficulty of the $i$-th probl... | {"inputs": ["1 10\n1 13\n", "1 10\n1 13\n", "1 16\n1 13\n", "1 235\n15 210\n", "1 235\n15 210\n", "1 235\n23 210\n", "1 235\n23 340\n", "3 5\n1 8\n2 19\n3 11\n"], "outputs": ["0\n", " 0\n", "3\n", "25\n", " ... | coding | 519 |
Solve the programming task below in a Python markdown code block.
There are $n$ players sitting at the card table. Each player has a favorite number. The favorite number of the $j$-th player is $f_j$.
There are $k \cdot n$ cards on the table. Each card contains a single integer: the $i$-th card contains number $c_i$. ... | {"inputs": ["1 1\n1\n2\n1\n", "1 1\n1\n1\n1\n", "1 1\n1\n2\n1\n", "1 1\n1\n1\n1\n", "1 1\n1\n4\n1\n", "1 1\n1\n7\n1\n", "1 1\n1\n7\n2\n", "1 1\n1\n7\n3\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 759 |
Solve the programming task below in a Python markdown code block.
Monk was asked to answer some queries in an interview. He is given an empty array A. Queries are of 4 types:-
1. 1 X - Add number X to the array A.
2. 2 X - Remove a single instance of number X from the array A. If not possible, print "-1" without the qu... | {"inputs": ["10\n1 5\n3\n3\n3\n1 4\n1 1\n1 8\n3\n1 6\n4\n", "100\n1 5\n1 22393\n2 22393\n4\n1 28040\n1 9505\n1 22027\n3\n1 2173\n4\n1 16189\n1 15918\n1 2896\n4\n4\n3\n4\n1 6654\n1 8716\n3\n4\n2 1472\n3\n4\n4\n1 2463\n2 2463\n2 19805\n4\n4\n4\n1 30479\n1 12892\n3\n3\n2 1\n4\n1 17656\n2 26370\n3\n2 28040\n3\n4\n4\n2 6263... | coding | 319 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the ith query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments.
A segment i... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]) == [14,7,2,2,0]\n assert candidate(nums = [3,2,11,1], removeQueries = [3,2,1,0]) == [16,5,3,0]\n\n\ncheck(Solution().maximumSegmentSum)"} | coding | 164 |
Solve the programming task below in a Python markdown code block.
A product-sum number is a natural number N which can be expressed as both the product and the sum of the same set of numbers.
N = a1 × a2 × ... × ak = a1 + a2 + ... + ak
For example, 6 = 1 × 2 × 3 = 1 + 2 + 3.
For a given set of size, k, we shall call... | {"functional": "_inputs = [[3], [6], [12], [2]]\n_outputs = [[10], [30], [61], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fa... | coding | 401 |
Solve the programming task below in a Python markdown code block.
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1... | {"inputs": ["2\n2 3\n", "2\n2 3\n", "2\n4 3\n", "2\n1 3\n", "2\n4 1\n", "2\n1 6\n", "2\n7 1\n", "2\n1 1\n"], "outputs": ["5\n", "5\n", "7\n", "3\n", "3\n", "3\n", "3\n", "2\n"]} | coding | 538 |
Solve the programming task below in a Python markdown code block.
This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that t... | {"inputs": ["3 4 3 5 3 6 2 1\n", "1 6 5 5 5 8 3 1\n", "2 5 3 5 6 9 2 1\n", "1 7 3 5 3 6 2 1\n", "1 7 5 3 3 9 2 1\n", "2 4 5 4 5 7 3 2\n", "1 7 5 5 5 5 2 2\n", "1 4 6 7 3 5 1 3\n"], "outputs": ["2\n", "8\n", "3\n", "6\n", "9\n", "1\n", "2\n", "1\n"]} | coding | 415 |
Solve the programming task below in a Python markdown code block.
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball re... | {"inputs": ["2\n1 2\n2 2", "2\n2 1\n2 2", "2\n1 2\n2 4", "2\n1 1\n2 2", "3\n1 4\n3 6\n7 8", "3\n1 4\n4 6\n8 8", "3\n1 4\n4 6\n7 8", "3\n1 4\n4 6\n11 8"], "outputs": ["1\n", "1\n", "1\n", "1", "2\n", "2\n", "1", "2\n"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program.
Program is very simple, Given two integers A and B, write a program to add these two numbers.
-----Input... | {"inputs": ["3\n1 2\n100 200\n10 40"], "outputs": ["3\n300\n50"]} | coding | 187 |
Solve the programming task below in a Python markdown code block.
Babidi has summoned Majin Vegeta. He orders him to kill Supreme Kai. But Vegeta wants to get out of his control.
Babidi has laid out a trap. Vegeta is standing at the $nth$ level of mind control. In order to defeat Babidi's trap, he needs to reach $mth$... | {"inputs": ["2\n3 7\n1 1023"], "outputs": ["5\n2177"]} | coding | 429 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.