task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Transpose means is to interchange rows and columns of a two-dimensional array matrix.
[A^(T)]ij=[A]ji
ie:
Formally, the i th row, j th column element of AT is the j th row, i th column element of A:
Example :
```
[[1,2,3],[4,5,6]].transpose() //sho... | {"functional": "_inputs = [[[]], [[[1]]], [[[0, 1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3, 4, 5, 6]]], [[[1], [2], [3], [4], [5], [6]]], [[['a', 'b', 'c'], ['d', 'e', 'f']]], [[[True, False, True], [False, True, False]]], [[[]]], [[[], [], [], [], [], []]]]\n_outputs = [[[]], [[[1]]], [[[0], [1]]], [[[1, 4], [2, 5], [... | 175 | 378 |
coding | Solve the programming task below in a Python markdown code block.
Let $n$ be a fixed integer.
A permutation is a bijection from the set $\{1,2,\ldots,n\}$ to itself.
A cycle of length ${k}$ ($k\geq2$) is a permutation $\mbox{f}$ where different integers exist $i_1,\ldots,i_k$ such that $f(i_1)=i_2,f(i_2)=i_3,...,f(... | {"inputs": ["1\n3 2\n2 2\n"], "outputs": ["6\n"]} | 528 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Given a string `s` of uppercase letters, your task is to determine how many strings `t` (also uppercase) with length equal to that of `s` satisfy the followng conditions:
* `t` is lexicographical larger than `s`, and
* when you write both `s` and `t` in... | {"functional": "_inputs = [['XYZ'], ['ABC'], ['ABCD'], ['ZAZ'], ['XYZA']]\n_outputs = [[5], [16174], [402230], [25], [34480]]\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)... | 200 | 195 |
coding | Solve the programming task below in a Python markdown code block.
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
A number is called a smart number if it has an odd number of factors. Given some numbers, find whether they are smart numbers or not.
Debug the g... | {"inputs": ["4\n1\n2\n7\n169\n"], "outputs": ["YES\nNO\nNO\nYES\n"]} | 395 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given a sequence A_{1}, A_{2}, ..., A_{N} and Q queries. In each query, you are given two parameters L and R; you have to find the smallest integer X such that 0 ≤ X ... | {"inputs": ["5 3\n20 11 18 2 13\n1 3\n3 5\n2 4"], "outputs": ["2147483629\n2147483645\n2147483645"]} | 417 | 71 |
coding | Solve the programming task below in a Python markdown code block.
According to a recent survey, Biryani is the most ordered food. Chef wants to learn how to make world-class Biryani from a MasterChef. Chef will be required to attend the MasterChef's classes for X weeks, and the cost of classes per week is Y coins. What... | {"inputs": ["4\n1 10\n1 15\n2 10\n2 15"], "outputs": ["10\n15\n20\n30\n"]} | 453 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two mult... | {"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n1 4\n", "2\n1 100\n", "3\n2 1 2\n", "3\n1 1 1\n", "3\n2 2 2\n", "3\n2 1 4\n"], "outputs": ["YES\nAA\n", "YES\nAB", "YES\nAB\n", "YES\nAB", "NO\n", "YES\nAAA\n", "YES\nAAA\n", "NO\n"]} | 373 | 122 |
coding | Solve the programming task below in a Python markdown code block.
There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.
Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cran... | {"inputs": ["2 2", "6 8", "3 2", "3 1", "6 3", "5 1", "3 3", "5 2"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 238 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a sorted integer array nums and three integers a, b and c, apply a quadratic function of the form f(x) = ax2 + bx + c to each element nums[i] in the array, and return the array in a sorted order.
Please comple... | {"functional": "def check(candidate):\n assert candidate(nums = [-4,-2,2,4], a = 1, b = 3, c = 5) == [3,9,15,33]\n assert candidate(nums = [-4,-2,2,4], a = -1, b = 3, c = 5) == [-23,-5,1,7]\n\n\ncheck(Solution().sortTransformedArray)"} | 114 | 104 |
coding | Solve the programming task below in a Python markdown code block.
ZCO is approaching, and you want to be well prepared!
There are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \le i \le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. You know ... | {"inputs": ["2\n5 4 10\n10 24 30 19 40\n5 4 16\n7 16 35 10 15"], "outputs": ["2\n4"]} | 594 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Flatland is a country with a number of cities, some of which have space stations. Cities are numbered consecutively and each has a road of $1km$ length connecting it to the next city. It is not a circular route, so the first city doesn't connect with t... | {"inputs": ["5 2\n0 4\n", "6 6\n0 1 2 4 3 5\n"], "outputs": ["2\n", "0\n"]} | 660 | 42 |
coding | Solve the programming task below in a Python markdown code block.
You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$.
Write a program which prints:
* "2" if $B$ is in $A$,
* "-2" if $A$ is in $B$,
* "1" if circu... | {"inputs": ["2\n0.0 0.0 5.0 0.0 0.0 4.0\n0.0 0.0 2.0 4.1 0.0 2.0", "2\n0.0 0.0 5.0 0.0 0.0 4.0\n0.0 0.0 2.0 4.1 0.0 2.4515674947137622", "2\n0.0 0.0 5.0 0.0 1.5542884595470625 4.0\n0.0 0.0 2.0 4.1 0.0 2.4515674947137622", "2\n0.0 0.0 5.0 0.0 0.5752470256734817 4.0\n0.0 0.0 2.0 4.1 0.0 2.4515674947137622", "2\n0.0 0.0 5... | 304 | 748 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optim... | {"inputs": ["1 0\n", "8 7\n", "9 0\n", "20 1\n", "10 1\n", "59 3\n", "16 1\n", "10 0\n"], "outputs": ["1\n", "8\n", "9\n", "19\n", "9\n", "59\n", "16\n", "10\n"]} | 347 | 95 |
coding | Solve the programming task below in a Python markdown code block.
Make a program that filters a list of strings and returns a list with only your friends name in it.
If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours! Otherwise, you can be sure he's not...
Ex: Input = ["Ryan", ... | {"functional": "_inputs = [[['Ryan', 'Kieran', 'Mark']], [['Ryan', 'Jimmy', '123', '4', 'Cool Man']], [['Jimm', 'Cari', 'aret', 'truehdnviegkwgvke', 'sixtyiscooooool']], [['Love', 'Your', 'Face', '1']], [['Hell', 'Is', 'a', 'badd', 'word']], [['Issa', 'Issac', 'Issacs', 'ISISS']], [['Robot', 'Your', 'MOMOMOMO']], [['Yo... | 132 | 378 |
coding | Solve the programming task below in a Python markdown code block.
Given an array $a$ of length $n$ and an integer $k$, you are tasked to find any two numbers $l$ and $r$ ($l \leq r$) such that:
For each $x$ $(l \leq x \leq r)$, $x$ appears in $a$ at least $k$ times (i.e. $k$ or more array elements are equal to $x$).
... | {"inputs": ["1\n1 1\n114514\n", "4\n7 2\n11 11 12 13 13 14 14\n5 1\n6 3 5 2 1\n6 4\n4 3 4 3 3 4\n14 2\n1 1 2 2 2 3 3 3 3 4 4 4 4 4\n"], "outputs": ["114514 114514\n", "13 14\n1 3\n-1\n1 4\n"]} | 679 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evenin... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "2\n1 3\n", "2\n1 2\n", "2\n3 4\n", "2\n2 3\n", "2\n6 7\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 405 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.
The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let'... | {"inputs": ["2 1\n1 2\n5 6\n1\n", "2 1\n1 1\n100 100\n5\n", "2 2\n11 14\n15 18\n2 9\n", "2 2\n11 14\n17 18\n2 9\n", "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n", "3 2\n1 5\n6 12\n14 100000000000\n10000000000 4\n", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 10 6 2 6 9 5\n", "5 9\n1 2\n3 3\n5 7\n11 13\n14 20\n2 3 4 20 6 2 6 9 5... | 685 | 316 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a string and your task will be to return the length of the longest prefix that is also a suffix. A prefix is the start of a string while the suffix is the end of a string. For instance, the prefixes of the string `"abcd"`... | {"functional": "_inputs = [['abcd'], ['abcda'], ['abcdabc'], ['abcabc'], ['abcabca'], ['abcdabcc'], ['aaaaa'], ['aaaa'], ['aaa'], ['aa'], ['a'], ['acbacc']]\n_outputs = [[0], [1], [3], [3], [1], [0], [2], [2], [1], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ... | 278 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters ... | {"inputs": ["z\n0\n", "y\n0\n", "x\n0\n", "ababa\n1\nba\n", "abbba\n1\nba\n", "ababa\n1\nab\n", "nllnrlrnll\n1\nrl\n", "llnrlrnlln\n1\nrl\n"], "outputs": ["0\n", "0\n", "0\n", "2\n", "2\n", "2\n", "1\n", "1\n"]} | 556 | 109 |
coding | Solve the programming task below in a Python markdown code block.
Print all the integers that satisfies the following in ascending order:
- Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
-----Constraints-----
- 1 \leq A \leq B \leq 10^9
... | {"inputs": ["3 4 2", "1 4 4", "0 0 3", "1 1 4", "6 8 3", "3 6 2", "0 8 3", "1 4 1"], "outputs": ["3\n4\n", "1\n2\n3\n4\n", "0\n", "1\n", "6\n7\n8\n", "3\n4\n5\n6\n", "0\n1\n2\n6\n7\n8\n", "1\n4\n"]} | 225 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Problem
Alice and Bob are competing in the 50m dash.
However, in this world, the higher the AOJ rate is, the better, so the higher the AOJ rate wins.
If there is no AOJ rate on either side, there is no comparison, so there is no choice but to compete in... | {"inputs": ["18 9 0 1", "18 9 0 0", "30 9 0 0", "45 9 0 0", "63 9 0 0", "63 2 0 0", "63 4 0 0", "82 4 0 0"], "outputs": ["Bob\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n"]} | 410 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the charact... | {"inputs": ["1\n2\n00\n10"], "outputs": ["2"]} | 578 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Alice, Bob and Charlie are playing Card Game for Three, as below:
- At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearran... | {"inputs": ["caa\naccc\nca", "aac\naccc\nca", "caa\naccc\nac", "aac\naccb\nca", "caa\naccb\nca", "caa\naccb\nba", "caa\nacbc\nba", "caa\nacbc\naa"], "outputs": ["A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n"]} | 493 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Everybody knows the classic ["half your age plus seven"](https://en.wikipedia.org/wiki/Age_disparity_in_sexual_relationships#The_.22half-your-age-plus-seven.22_rule) dating rule that a lot of people follow (including myself). It's the 'recommended' age r... | {"functional": "_inputs = [[17], [40], [15], [35], [10], [53], [19], [12], [7], [33]]\n_outputs = [['15-20'], ['27-66'], ['14-16'], ['24-56'], ['9-11'], ['33-92'], ['16-24'], ['10-13'], ['6-7'], ['23-52']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ... | 277 | 255 |
coding | Solve the programming task below in a Python markdown code block.
Vasya plays the Geometry Horse.
The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value.
There are n types of geometric f... | {"inputs": ["1\n1 1000\n1\n2\n", "1\n1 1000\n1\n1\n", "1\n1 1100\n1\n2\n", "1\n4 10\n2\n3 6\n", "1\n9 10\n2\n3 6\n", "1\n4 10\n2\n1 6\n", "1\n9 10\n2\n2 6\n", "1\n4 10\n2\n2 6\n"], "outputs": ["1000\n", "1000\n", "1100\n", "50\n", "180\n", "70\n", "190\n", "60\n"]} | 596 | 174 |
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 | Solve the programming task below in a Python markdown code block.
Kuznecov likes art, poetry, and music. And strings consisting of lowercase English letters.
Recently, Kuznecov has found two strings, $a$ and $b$, of lengths $n$ and $m$ respectively. They consist of lowercase English letters and no character is contain... | {"inputs": ["1\n5 1 5\naaaaa\nx\n", "3\n6 4 2\naaaaaa\nbbbb\n5 9 3\ncaaca\nbedededeb\n7 7 1\nnoskill\nwxhtzdy\n"], "outputs": ["aaaaa\n", "aabaabaa\naaabbcc\ndihktlwlxnyoz\n"]} | 681 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Here your task is to Create a (nice) Christmas Tree.
You don't have to check errors or incorrect input values, every thing is ok without bad tricks, only one int parameter as input and a string to return;-)...
So what to do?First three easy examples:
``... | {"functional": "_inputs = [[5], [10], [8], [2]]\n_outputs = [[' *\\r\\n ***\\r\\n*****\\r\\n ###'], [' *\\r\\n ***\\r\\n *****\\r\\n ***\\r\\n *****\\r\\n *******\\r\\n *****\\r\\n *******\\r\\n*********\\r\\n ###'], [' *\\r\\n ***\\r\\n *****\\r\\n ***\\r\\n *****\\r\\n*******\\r\\n ###'], ['']]\nimp... | 314 | 279 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[ro... | {"functional": "def check(candidate):\n assert candidate(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]) == [1,0]\n assert candidate(n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]) == [1,1]\n assert candidate(n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]) == [1,1,0]\n\n\ncheck(Solut... | 298 | 138 |
coding | Solve the programming task below in a Python markdown code block.
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy t... | {"inputs": ["01-01-2014\n", "29-02-2013-02-2013-29-02-2013\n", "29-02-2013-03-2013-29-02-2013\n", "29-02-3013-02-2013-29-02-2013\n", "30-12-201429-15-208830-12-2014\n", "29-02-201329-02-201321-12-2013\n", "120110201311-10-20151201102013\n", "31-12-201331-11-201331-11-2013\n"], "outputs": ["01-01-2014\n", "13-02-2013\n"... | 516 | 351 |
coding | Solve the programming task below in a Python markdown code block.
One day, $n$ people ($n$ is an even number) met on a plaza and made two round dances, each round dance consists of exactly $\frac{n}{2}$ people. Your task is to find the number of ways $n$ people can make two round dances if each round dance consists of ... | {"inputs": ["2\n", "4\n", "8\n", "6\n", "6\n", "2\n", "4\n", "8\n"], "outputs": ["1\n", "3\n", "1260\n", "40\n", "40\n", "1\n", "3\n", "1260\n"]} | 461 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Athenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception.
His song consists of $n$ notes, whic... | {"inputs": ["5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\n", "5\n6\n1 2 2 2 5 6\n2\n2 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\n", "5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 3\n", "5\n6\n1 2 2 4 5 6\n2\n2 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 2 2 2 2\n", "5\n6\n1 2 2 4 5 6\n2\n2 4\n6\n1... | 640 | 550 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer, $N$. Your task is to print an alphabet rangoli of size $N$.
(Rangoli is a form of Indian folk art based on creation of patterns.)
Different sizes of alphabet rangoli are shown below:
#size 3
----c----
--c-b-c--
c-b-a-b-c
--c-... | {"inputs": ["5\n"], "outputs": ["--------e--------\n------e-d-e------\n----e-d-c-d-e----\n--e-d-c-b-c-d-e--\ne-d-c-b-a-b-c-d-e\n--e-d-c-b-c-d-e--\n----e-d-c-d-e----\n------e-d-e------\n--------e--------\n"]} | 567 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).
You are given an integer $n$. You need to find two integers $l$ and $r$ such that $-10^{18} \le l < r \le 10^{18}$ and $l ... | {"inputs": ["7\n2\n4\n7\n3\n111\n6\n56293238153\n", "7\n1\n2\n6\n2\n101\n2\n390536414718\n", "7\n1\n2\n6\n2\n001\n2\n390536414718\n", "7\n1\n2\n6\n2\n001\n2\n133532318784\n", "7\n1\n2\n4\n2\n001\n2\n133532318784\n", "7\n1\n2\n8\n2\n001\n2\n133532318784\n", "7\n1\n2\n8\n4\n001\n2\n133532318784\n", "7\n2\n2\n8\n4\n001\n2... | 507 | 718 |
coding | Solve the programming task below in a Python markdown code block.
There are several (or no) spiders, butterflies, and dragonflies.
In this kata, a spider has eight legs. A dragonfly or a butterfly has six legs. A __dragonfly__ has __two__ pairs of wings, while a __butterfly__ has __one__ pair of wings. __I am not sur... | {"functional": "_inputs = [[3, 20, 3]]\n_outputs = [[[1, 1, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return... | 314 | 168 |
coding | Solve the programming task below in a Python markdown code block.
inner
The inner tool returns the inner product of two arrays.
import numpy
A = numpy.array([0, 1])
B = numpy.array([3, 4])
print numpy.inner(A, B) #Output : 4
outer
The outer tool returns the outer product of two arrays.
import numpy
A ... | {"inputs": ["0 1\n2 3\n"], "outputs": ["3\n[[0 0]\n [2 3]]\n"]} | 239 | 33 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.
Please complete the following python code precisely:
```python
class Solution:
def dayOfYear... | {"functional": "def check(candidate):\n assert candidate(date = \"2019-01-09\") == 9\n assert candidate(date = \"2019-02-10\") == 41\n\n\ncheck(Solution().dayOfYear)"} | 71 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden loo... | {"inputs": ["0 0 0 1\n", "0 0 1 1\n", "0 0 1 2\n", "0 1 2 3\n", "0 1 0 0\n", "1 1 0 0\n", "0 0 1 0\n", "1 0 0 1\n"], "outputs": ["1 0 1 1\n", "0 1 1 0\n", "-1\n", "0 3 2 1\n", "1 1 1 0\n", "1 0 0 1\n", "0 1 1 1\n", "1 1 0 0\n"]} | 385 | 160 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the maximum number of occurrences of any substring under the following rules:
The number of unique characters in the substring must be less than or equal to maxLetters.
The substring size mus... | {"functional": "def check(candidate):\n assert candidate(s = \"aababcaab\", maxLetters = 2, minSize = 3, maxSize = 4) == 2\n assert candidate(s = \"aaaa\", maxLetters = 1, minSize = 3, maxSize = 3) == 2\n assert candidate(s = \"aabcabcab\", maxLetters = 2, minSize = 2, maxSize = 3) == 3\n assert candidate(s... | 110 | 142 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] t... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,1,1,2]) == [5,0,3,4,0]\n assert candidate(nums = [0,5,3]) == [0,0,0]\n\n\ncheck(Solution().distance)"} | 121 | 68 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef wants to give a gift to Chefina to celebrate their anniversary. Of course, he has a sequence $a_{1}, a_{2}, \ldots, a_{N}$ ready for this occasi... | {"inputs": ["1\n4\n2 3 4 5"], "outputs": ["3"]} | 531 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Santa has $n$ candies and he wants to gift them to $k$ kids. He wants to divide as many candies as possible between all $k$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the ... | {"inputs": ["1\n49845 2\n", "1\n96290 2\n", "1\n51548 1\n", "1\n25702 1\n", "1\n25113 1\n", "1\n49777 3\n", "1\n38068 2\n", "1\n49845 1\n"], "outputs": ["49845\n", "96290\n", "51548\n", "25702\n", "25113\n", "49777\n", "38068\n", "49845\n"]} | 700 | 166 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $n$.
Find any pair of integers $(x,y)$ ($1\leq x,y\leq n$) such that $x^y\cdot y+y^x\cdot x = n$.
-----Input-----
The first line contains a single integer $t$ ($1\leq t\leq 10^4$) — the number of test cases.
Each test case c... | {"inputs": ["5\n3\n7\n42\n31250\n20732790\n"], "outputs": ["-1\n-1\n1 21\n1 15625\n1 10366395\n"]} | 317 | 64 |
coding | Solve the programming task below in a Python markdown code block.
M-kun is a brilliant air traffic controller.
On the display of his radar, there are N airplanes numbered 1, 2, ..., N, all flying at the same altitude.
Each of the airplanes flies at a constant speed of 0.1 per second in a constant direction. The curren... | {"inputs": ["2\n10 -1 U\n3 0 D", "2\n10 -1 U\n2 0 D", "2\n20 1 U\n11 47 D", "2\n20 1 U\n11 37 D", "2\n20 0 U\n11 37 D", "2\n20 0 U\n12 37 D", "2\n20 0 U\n12 70 D", "2\n10 0 U\n3 103 D"], "outputs": ["SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n"]} | 574 | 162 |
coding | Solve the programming task below in a Python markdown code block.
M-kun is a student in Aoki High School, where a year is divided into N terms.
There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:
* For the first through (K-1)-th terms:... | {"inputs": ["5 3\n96 98 95 000 20", "5 3\n96 98 95 100 20", "3 1\n1001 869120 1001", "3 2\n1011 869120 1001", "5 0\n96 98 162 100 39", "3 2\n0011 869120 1001", "3 0\n1101 681697 1001", "3 2\n1001 869120 1001"], "outputs": ["No\nNo\n", "Yes\nNo", "Yes\nNo\n", "No\n", "No\nNo\nNo\nNo\nNo\n", "Yes\n", "No\nNo\nNo\n", "No"... | 426 | 228 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue... | {"inputs": ["1 1 10\n10\nR\n", "1 1 10\n10\nR\n", "1 1 20\n10\nR\n", "2 1 15\n5 6\nRG\n", "2 1 10\n5 5\nRG\n", "2 1 10\n5 6\nRR\n", "2 1 10\n5 5\nRG\n", "2 1 10\n5 6\nRR\n"], "outputs": ["0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 715 | 155 |
coding | Solve the programming task below in a Python markdown code block.
For her next karate demonstration, Ada will break some bricks.
Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $W_1, W_2, W_3$.
Ada's strength is $S$. Whenever she hits a stack of bricks, consider the large... | {"inputs": ["3\n3 1 2 2\n2 1 1 1\n3 2 2 1"], "outputs": ["2\n2\n2"]} | 541 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Recently Johnny have learned bogosort sorting algorithm. He thought that it is too ineffective. So he decided to improve it. As you may know this algorithm shuffles the sequence randomly until it is sorted. Johnny decided that we don't need to shuffle th... | {"inputs": ["3\n2\n3\n7", "3\n4\n7\n3", "3\n2\n2\n8", "3\n3\n3\n7", "3\n4\n6\n8", "3\n3\n3\n5", "3\n4\n3\n5", "3\n2\n6\n7"], "outputs": ["2\n10/3\n8810/693\n", "5\n8810/693\n10/3\n", "2\n2\n439331/27027\n", "10/3\n10/3\n8810/693\n", "5\n1826/189\n439331/27027\n", "10/3\n10/3\n149/21\n", "5\n10/3\n149/21\n", "2\n1826/18... | 380 | 237 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.
Please complete the following python code precisely:
```python
# Defini... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,1,4,None,2]), k = 1) == 1\n assert candidate(root = tree_node([5,3,6,2,4,None,None,1]), k = 3) == 3\n\n\ncheck(Solution().kthSmallest)"} | 142 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D array of axis-aligned rectangles. Each rectangle[i] = [xi1, yi1, xi2, yi2] denotes the ith rectangle where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinate... | {"functional": "def check(candidate):\n assert candidate(rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]]) == 6\n assert candidate(rectangles = [[0,0,1000000000,1000000000]]) == 49\n\n\ncheck(Solution().rectangleArea)"} | 168 | 92 |
coding | Solve the programming task below in a Python markdown code block.
The ugliness of a sequence of size N is defined as the number of pairs of neighboring elements which are not equal to each other. Formally, the ugliness of a sequence increase by 1 if for a value of i, 2 ≤ i ≤ N, the following condition holds true:
A_{i}... | {"inputs": ["2\n8 2\n1 2 1 2 2 2 1 2\n8 3\n1 2 2 1 1 1 2 3"], "outputs": ["0 0\n1 1 3\n"]} | 700 | 61 |
coding | Solve the programming task below in a Python markdown code block.
"I'm a fan of anything that tries to replace actual human contact." - Sheldon.
After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact.
He found k$k$ integers n1,n2...nk$n_1,n_2...n_k$ . Also ... | {"inputs": ["1\n1\n5"], "outputs": ["2"]} | 497 | 16 |
coding | Solve the programming task below in a Python markdown code block.
The cows have just learned what a primitive root is! Given a prime p, a primitive root $\operatorname{mod} p$ is an integer x (1 ≤ x < p) such that none of integers x - 1, x^2 - 1, ..., x^{p} - 2 - 1 are divisible by p, but x^{p} - 1 - 1 is.
Unfortunat... | {"inputs": ["3\n", "5\n", "7\n", "2\n", "2\n", "7\n", "5\n", "3\n"], "outputs": ["1\n", "2\n", "2\n", "1\n", "1", "2", "2", "1"]} | 251 | 66 |
coding | Solve the programming task below in a Python markdown code block.
For an array of non-negative integers $a$ of size $n$, we construct another array $d$ as follows: $d_1 = a_1$, $d_i = |a_i - a_{i - 1}|$ for $2 \le i \le n$.
Your task is to restore the array $a$ from a given array $d$, or to report that there are multi... | {"inputs": ["1\n2\n5 5\n", "1\n2\n1 1\n", "1\n2\n3 3\n", "1\n2\n2 2\n", "1\n2\n4 4\n", "1\n2\n7 7\n", "1\n2\n2 3\n", "1\n2\n6 6\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2 5\n", "-1\n"]} | 373 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not... | {"inputs": ["1 1\n", "8 9\n", "9 9\n", "5 4\n", "8 9\n", "1 1\n", "9 9\n", "5 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 318 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You are the Dungeon Master for a public DnD game at your local comic shop and recently you've had some trouble keeping your players' info neat and organized so you've decided to write a bit of code to help keep them sorted!
The goal of this code is to c... | {"functional": "_inputs = [['a, 5'], ['jane, 801, dave, 123'], ['Amelia, 8165254325, Jessie, 9187162345, Marcus Kaine, 8018273245'], [''], [None]]\n_outputs = [[[{'player': 'a', 'contact': 5}]], [[{'player': 'jane', 'contact': 801}, {'player': 'dave', 'contact': 123}]], [[{'player': 'Amelia', 'contact': 8165254325}, {'... | 421 | 341 |
coding | Solve the programming task below in a Python markdown code block.
BerPhone X is almost ready for release with n applications being preinstalled on the phone. A category of an application characterizes a genre or a theme of this application (like "game", "business", or "education"). The categories are given as integers ... | {"inputs": ["3\n11\n1 5 1 3 1 5 1 1 1 1 5\n6\n1 2 2 2 2 1\n5\n4 3 3 1 2\n", "3\n11\n1 5 1 3 1 2 1 1 1 1 5\n6\n1 2 2 2 4 1\n5\n4 3 3 1 2\n", "3\n11\n1 5 1 3 2 2 1 1 1 1 5\n6\n1 2 2 2 4 2\n5\n4 3 3 1 2\n", "3\n11\n1 5 1 2 2 2 1 1 1 1 5\n6\n1 2 2 2 4 2\n5\n4 3 3 1 2\n", "3\n11\n2 5 1 5 1 5 1 1 1 1 5\n6\n1 2 2 2 2 1\n5\n4 ... | 522 | 510 |
coding | Solve the programming task below in a Python markdown code block.
There is a string s of length 3 or greater. No two neighboring characters in s are equal.
Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:
* Remove one of the c... | {"inputs": ["abb", "aaa", "baa", "bba", "aa`", "aab", "`aa", "bca"], "outputs": ["First\n", "Second\n", "First\n", "First\n", "First\n", "First\n", "First\n", "First\n"]} | 224 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of... | {"inputs": ["6\n", "8\n", "4\n", "9\n", "3\n", "5\n", "7\n", "1\n"], "outputs": ["83\n", "155\n", "35\n", "198\n", "20\n", "56\n", "116\n", "4\n"]} | 390 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensio... | {"inputs": ["5 1 5 2 5\n", "4 0 3 1 4\n", "5 4 0 5 1\n", "6 6 0 2 6\n", "5 4 0 5 2\n", "6 6 0 1 6\n", "2 0 1 2 0\n", "2 0 0 1 0\n"], "outputs": ["1\n", "2\n", "2\n", "10\n", "3\n", "11\n", "3\n", "1\n"]} | 316 | 136 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.
The closest is defined as the absolute difference minimize... | {"functional": "def check(candidate):\n assert candidate(n = \"123\") == \"121\"\n assert candidate(n = \"1\") == \"0\"\n\n\ncheck(Solution().nearestPalindromic)"} | 96 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At sc... | {"inputs": ["2\n5 2 3\n6 4 5\n", "2\n5 3 4\n9 4 4\n", "2\n5 2 3\n9 4 7\n", "2\n5 2 3\n1 4 7\n", "2\n5 2 4\n9 4 4\n", "2\n5 2 4\n1 4 7\n", "2\n5 4 4\n1 4 7\n", "2\n5 3 4\n9 4 5\n"], "outputs": ["Yes\nNo\n", "No\nNo\n", "Yes\nYes\n", "Yes\nNo\n", "Yes\nNo\n", "Yes\nNo\n", "No\nNo\n", "No\nYes\n"]} | 694 | 182 |
coding | Solve the programming task below in a Python markdown code block.
# Covfefe
Your are given a string. You must replace the word(s) `coverage` by `covfefe`, however, if you don't find the word `coverage` in the string, you must add `covfefe` at the end of the string with a leading space.
For the languages where the st... | {"functional": "_inputs = [['coverage'], ['coverage coverage'], ['nothing'], ['double space '], ['covfefe']]\n_outputs = [['covfefe'], ['covfefe covfefe'], ['nothing covfefe'], ['double space covfefe'], ['covfefe covfefe']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float... | 126 | 205 |
coding | Solve the programming task below in a Python markdown code block.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.
You want to... | {"inputs": ["1", "0", "0\n", "1\n", "010", "100", "101", "011"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n"]} | 203 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody g... | {"inputs": ["3 2 1 1\n", "2 4 2 2\n", "1 1 1 1\n", "4 5 2 3\n", "9 7 4 7\n", "5 5 3 2\n", "4 5 2 3\n", "9 7 4 7\n"], "outputs": ["3\n2 1\n3 1\n3 2\n", "0\n", "0\n", "1\n4 3\n", "2\n8 7\n9 7\n", "6\n3 2\n4 2\n4 3\n5 2\n5 3\n5 4\n", "1\n4 3\n", "2\n8 7\n9 7\n"]} | 464 | 178 |
coding | Solve the programming task below in a Python markdown code block.
Vasily the bear has got a sequence of positive integers a_1, a_2, ..., a_{n}. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum.
The beauty of the written out numbers b_1, ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n315\n", "1\n284\n", "1\n535\n", "1\n785\n", "1\n805\n", "1\n6360\n"], "outputs": ["1\n1\n", "1\n1 ", "1\n315\n", "1\n284\n", "1\n535\n", "1\n785\n", "1\n805\n", "1\n6360\n"]} | 497 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
Let's focus on the students. They are indexed with integer... | {"inputs": ["1\n1\n1\n", "1\n2\n1\n", "1\n2\n2\n", "1\n2\n0\n", "1\n3\n0\n", "1\n5\n1\n", "1\n5\n0\n", "1\n4\n0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 538 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Chef would like go shopping to buy ingredients for his special dish. The local grocery store has some special discount offers. If you want to buy some set of ingredients you will pay for all ingredients except the cheapest one. Chef would like to spend a... | {"inputs": ["1\n4\n1 2 3 4\n3\n2 1 2\n2 3 4\n3 1 2 3"], "outputs": ["6"]} | 441 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Description
Lets imagine a yoga classroom as a Square 2D Array of Integers ```classroom```, with each integer representing a person, and the value representing their skill level.
```
classroom = [
[3,2,1,3],
[1,3,2,1],
... | {"functional": "_inputs = [[[[0, 0], [0, 0]], [1, 1, 0, 1, 2, 3, 0, 1, 5]], [[], [1, 3, 4]], [[[0, 0], [0, 0]], []], [[], []]]\n_outputs = [[8], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n... | 365 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.
-----Input-----
The only line contains two integers n and k (1 ≤ n, k ≤ 10^9).
-----Output-----
Print the smal... | {"inputs": ["5 3\n", "1 1\n", "8 8\n", "8 8\n", "1 1\n", "1 2\n", "4 3\n", "2 2\n"], "outputs": ["6\n", "2\n", "16\n", "16", "2", "2\n", "6\n", "4\n"]} | 129 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2.
Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.
Please complete the following python code pre... | {"functional": "def check(candidate):\n assert candidate(n = 5) == 2\n assert candidate(n = 10) == 4\n\n\ncheck(Solution().countTriples)"} | 102 | 45 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $x$ and $y$ (it is guaranteed that $x > y$). You may choose any prime integer $p$ and subtract it any number of times from $x$. Is it possible to make $x$ equal to $y$?
Recall that a prime number is a positive integer that has... | {"inputs": ["1\n51 50\n", "1\n52 51\n", "1\n54 53\n", "1\n90 80\n", "1\n90 80\n", "1\n51 50\n", "1\n54 53\n", "1\n52 51\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | 461 | 118 |
coding | Solve the programming task below in a Python markdown code block.
You are given a positive decimal number x.
Your task is to convert it to the "simple exponential notation".
Let x = a·10^{b}, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" ... | {"inputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "16\n", ".1\n", "1.\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "1.6E1\n", "1E-1\n", "1\n"]} | 247 | 79 |
coding | Solve the programming task below in a Python markdown code block.
Determine the total number of digits in the integer (`n>=0`) given as input to the function. For example, 9 is a single digit, 66 has 2 digits and 128685 has 6 digits. Be careful to avoid overflows/underflows.
All inputs will be valid.
Also feel free to... | {"functional": "_inputs = [[5], [12345], [9876543210]]\n_outputs = [[1], [5], [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) != len(b): return Fa... | 101 | 179 |
coding | Solve the programming task below in a Python markdown code block.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the $n$ piles with stones numbered from $1$ to $n$.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was $x_1, x... | {"inputs": ["1\n3\n2\n", "1\n1\n5\n", "1\n6\n1\n", "1\n1\n1\n", "1\n0\n0\n", "1\n7\n3\n", "1\n2\n1\n", "1\n0\n0\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | 622 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integ... | {"functional": "def check(candidate):\n assert candidate(intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]) == [3,3,1,4]\n assert candidate(intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]) == [2,-1,4,6]\n\n\ncheck(Solution().minInterval)"} | 179 | 113 |
coding | Solve the programming task below in a Python markdown code block.
Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "6\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "3\n", "4\n", "5\n", "4"]} | 337 | 69 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings s and t, your goal is to convert s into t in k moves or less.
During the ith (1 <= i <= k) move you can:
Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen... | {"functional": "def check(candidate):\n assert candidate(s = \"input\", t = \"ouput\", k = 9) == True\n assert candidate(s = \"abc\", t = \"bcd\", k = 10) == False\n assert candidate(s = \"aab\", t = \"bbb\", k = 27) == True\n\n\ncheck(Solution().canConvertString)"} | 250 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
Given an integer n, return true if n is an ugly number.
Please complete the following python code precisely:
```python
class Solut... | {"functional": "def check(candidate):\n assert candidate(n = 6) == True\n assert candidate(n = 1) == True\n assert candidate(n = 14) == False\n\n\ncheck(Solution().isUgly)"} | 85 | 54 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return all root-to-leaf paths in any order.
A leaf is a node with no children.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# c... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,5])) == [\"1->2->5\",\"1->3\"]\n assert candidate(root = tree_node([1])) == [\"1\"]\n\n\ncheck(Solution().binaryTreePaths)"} | 130 | 69 |
coding | Solve the programming task below in a Python markdown code block.
Dima worked all day and wrote down on a long paper strip his favorite number $n$ consisting of $l$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip ... | {"inputs": ["2\n55\n", "2\n87\n", "2\n74\n", "2\n41\n", "2\n66\n", "2\n24\n", "3\n101\n", "3\n101\n"], "outputs": ["10\n", "15\n", "11\n", "5\n", "12\n", "6\n", "11\n", "11\n"]} | 414 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Given a matrix you need to find the submatrix with the largest number of elements, where the GCD (Greatest Common Divisor) of its elements is greater than one. A submatrix of the matrix is a sub-section composed of contiguous rows and columns of the orig... | {"inputs": ["3 3\n2 6 8\n4 8 3\n6 9 4\n"], "outputs": ["4\n"]} | 198 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Monocarp is a little boy who lives in Byteland and he loves programming.
Recently, he found a permutation of length $n$. He has to come up with a mystic permutation. It has to be a new permutation such that it differs from the old one in each position.
... | {"inputs": ["4\n3\n1 2 3\n5\n2 3 4 5 1\n4\n2 3 1 4\n1\n1\n"], "outputs": ["2 3 1\n1 2 3 4 5\n1 2 4 3\n-1\n"]} | 683 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lin... | {"inputs": ["6\n4 4 2 5 2 3\n", "6\n4 4 2 5 2 6\n", "6\n4 4 2 5 2 3\n", "6\n4 4 2 5 2 11\n", "9\n5 1 3 1 5 2 4 2 5\n", "9\n5 1 3 2 5 2 4 2 5\n", "9\n5 1 3 2 5 2 4 3 5\n", "9\n5 1 3 1 5 2 4 2 5\n"], "outputs": ["14\n", "17\n", "14\n", "22\n", "9\n", "8\n", "5\n", "9\n"]} | 558 | 195 |
coding | Solve the programming task below in a Python markdown code block.
Currently, people's entertainment is limited to programming contests. The activity of the entertainment club of a junior high school to which she belongs is to plan and run a programming contest. Her job is not to create problems. It's a behind-the-scene... | {"inputs": ["1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 0\n3 0 0 3 0 0\n3 1 0 1 3 1\n1 2 0 2 0 1\n0 0 1 1 0 3\n1 0 0 1 1 0\n0 0 0 0 0 0", "1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 0\n3 0 0 0 0 0\n3 1 0 1 3 1\n1 2 0 2 0 1\n0 0 1 1 0 3\n1 0 0 1 1 0\n0 0 0 0 0 0", "1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 1\n2 0 0 3 0 0\n3 1 0 1 3 1\n1 2 ... | 625 | 1,022 |
coding | Solve the programming task below in a Python markdown code block.
Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who loo... | {"inputs": ["2\n3 0\n3\n0 1 1\n1\n1000\n0", "2\n3 2\n3\n0 1 1\n1\n0000\n0", "2\n1 0\n3\n0 1 1\n1\n1000\n0", "2\n2 0\n3\n0 1 1\n0\n1100\n0", "2\n1 0\n3\n0 1 1\n0\n1100\n0", "2\n3 2\n3\n0 0 1\n1\n1000\n0", "2\n6 4\n3\n0 1 2\n1\n0000\n0", "2\n0 4\n3\n0 1 2\n1\n0000\n0"], "outputs": ["2\nNA\n2\n", "3\nNA\nNA\n", "NA\nNA\n2... | 397 | 258 |
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.
There are N integers, A_1, A_2, ..., A_N, written on the blackboard.
You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.
Find the maximum possible ... | {"inputs": ["3\n7 6 7", "3\n4 8 7", "3\n4 2 5", "3\n7 6 8", "3\n7 6 8\n", "3\n4 6 9\n", "3\n9 28 18", "3\n9 28 30"], "outputs": ["7\n", "4\n", "2\n", "2", "2\n", "3\n", "9\n", "3\n"]} | 234 | 115 |
coding | Solve the programming task below in a Python markdown code block.
The marmots need to prepare k problems for HC^2 over n days. Each problem, once prepared, also has to be printed.
The preparation of a problem on day i (at most one per day) costs a_{i} CHF, and the printing of a problem on day i (also at most one per d... | {"inputs": ["1 1\n96\n86\n", "1 1\n96\n86\n", "1 1\n71\n86\n", "1 1\n50\n86\n", "1 1\n126\n86\n", "8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 1\n", "8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 0\n", "8 4\n3 3 7 9 9 4 6 8\n2 5 9 4 3 8 9 0\n"], "outputs": ["182", "182\n", "157\n", "136\n", "212\n", "32", "31\n", "26\n"]} | 489 | 224 |
coding | Solve the programming task below in a Python markdown code block.
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1... | {"inputs": ["3 8 3\n0 2\n3 2\n6 1", "2 8 3\n0 1\n3 2\n6 1", "3 8 3\n1 2\n3 2\n6 1", "1 8 3\n1 2\n3 2\n6 1", "1 8 0\n1 2\n3 4\n6 1", "1 8 1\n1 2\n3 4\n6 1", "2 8 3\n1 1\n3 2\n6 1", "1 5 3\n1 2\n6 2\n6 1"], "outputs": ["0\n1\n5\n", "0\n3\n", "0\n1\n6\n", "6\n", "1\n", "0\n", "0\n4\n", "3\n"]} | 416 | 202 |
coding | Solve the programming task below in a Python markdown code block.
a is an array of n positive integers, all of which are not greater than n.
You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap ... | {"inputs": ["3\n1 1 1\n3\n1 1\n2 1\n1 1\n", "3\n1 1 1\n3\n2 1\n2 1\n1 1\n", "3\n2 1 1\n3\n1 1\n2 1\n1 1\n", "3\n1 1 2\n3\n2 1\n2 1\n1 1\n", "3\n1 1 1\n3\n2 2\n2 1\n1 1\n", "3\n1 1 0\n3\n2 1\n2 1\n1 1\n", "3\n1 1 1\n3\n1 1\n2 1\n3 1\n", "10\n3 5 4 3 7 8 6 7 2 3\n10\n4 5\n2 10\n4 3\n9 9\n9 2\n5 1\n6 4\n1 1\n5 6\n6 4\n"],... | 280 | 321 |
coding | Solve the programming task below in a Python markdown code block.
I've got a crazy mental illness.
I dislike numbers a lot. But it's a little complicated:
The number I'm afraid of depends on which day of the week it is...
This is a concrete description of my mental illness:
Monday --> 12
Tuesday --> numbers gr... | {"functional": "_inputs = [['Monday', 13], ['Monday', 12], ['Tuesday', 0], ['Tuesday', 100], ['Tuesday', 95], ['Wednesday', 35], ['Wednesday', 34], ['Thursday', 2], ['Thursday', 0], ['Friday', 5], ['Friday', 4], ['Saturday', 55], ['Saturday', 56], ['Sunday', 55], ['Sunday', 666], ['Sunday', -666]]\n_outputs = [[False],... | 182 | 308 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.
Create the maximum number of length k <= m + n fr... | {"functional": "def check(candidate):\n assert candidate(nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5) == [9,8,6,5,3]\n assert candidate(nums1 = [6,7], nums2 = [6,0,4], k = 5) == [6,7,6,0,4]\n assert candidate(nums1 = [3,9], nums2 = [8,9], k = 3) == [9,8,9]\n\n\ncheck(Solution().maxNumber)"} | 141 | 140 |
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 given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.
Throughout moveFrom.length steps, y... | {"functional": "def check(candidate):\n assert candidate(nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]) == [5,6,8,9]\n assert candidate(nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]) == [2]\n\n\ncheck(Solution().relocateMarbles)"} | 181 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Every positive integer number, that is not prime, may be decomposed in prime factors. For example the prime factors of 20, are:
```
2, 2, and 5, because: 20 = 2 . 2 . 5
```
The first prime factor (the smallest one) of ```20``` is ```2``` and the last on... | {"functional": "_inputs = [[10, 100], [10, 200], [15, 150], [501, 1000], [501, 5000]]\n_outputs = [[[21, 25, 63]], [[21, 25, 63, 105, 125, 147, 189]], [[26, 52, 78, 104, 130]], [[998]], [[998, 1996, 2994, 3992, 4990]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 604 | 299 |
coding | Solve the programming task below in a Python markdown code block.
Challenge:
Given two null-terminated strings in the arguments "string" and "prefix", determine if "string" starts with the "prefix" string. Return 1 (or any other "truthy" value) if true, 0 if false.
Example:
```
startsWith("hello world!", "hello"); // ... | {"functional": "_inputs = [['hello world!', 'hello'], ['hello world!', 'HELLO'], ['nowai', 'nowaisir'], ['', ''], ['abc', ''], ['', 'abc']]\n_outputs = [[True], [False], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma... | 278 | 203 |
coding | Solve the programming task below in a Python markdown code block.
# Task
John and Alice have an appointment today.
In the morning, John starts from (`0,0`) and goes to the place (`a,b`) where he is dating. Unfortunately, John had no sense of direction at all, so he moved 1 step in a random direction(up, down, left o... | {"functional": "_inputs = [[3, 3, 6], [4, 5, 10], [-5, -5, 10], [-5, -5, 8], [10, -10, 10]]\n_outputs = [[True], [False], [True], [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)\n if isins... | 582 | 216 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
Choose two different indices i and j (1≤ i,j≤ N);
Change A_{i} and A_{j} to A_{i} \oplus A_{j}. Here \oplus represents the [bitwise XOR] operat... | {"inputs": ["4\n5\n11011\n7\n0111010\n1\n1\n4\n1100"], "outputs": ["0\n1\n0\n1"]} | 619 | 47 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inc... | {"functional": "def check(candidate):\n assert candidate(timeSeries = [1,4], duration = 2) == 4\n assert candidate(timeSeries = [1,2], duration = 2) == 3\n\n\ncheck(Solution().findPoisonedDuration)"} | 188 | 62 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.