problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x_0, y_0) of a ... | {"inputs": ["1 2 1 1\nR\n", "2 1 1 1\nD\n", "2 1 1 1\nD\n", "1 2 1 1\nR\n", "1 2 1 2\nLR\n", "2 1 2 1\nUD\n", "1 2 1 2\nLR\n", "2 1 2 1\nUD\n"], "outputs": ["1 1\n", "1 1\n", "1 1 ", "1 1 ", "1 1 0\n", "1 1 0\n", "1 1 0 ", "1 1 0 "]} | coding | 678 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Ada has two matrices $A$ and $B$, each with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$).
Ada may perform the foll... | {"inputs": ["1\n3\n1 2 3\n4 5 6\n7 8 9\n1 2 7\n4 5 8\n3 6 9"], "outputs": ["Yes"]} | coding | 571 |
Solve the programming task below in a Python markdown code block.
You will be given an array of positive integers. The array should be sorted by the amount of distinct perfect squares and reversed, that can be generated from each number permuting its digits.
E.g.: ```arr = [715, 112, 136, 169, 144]```
```
Number P... | {"functional": "_inputs = [[[715, 112, 136, 169, 144]], [[234, 61, 16, 441, 144, 728]]]\n_outputs = [[[169, 144, 112, 136, 715]], [[144, 441, 16, 61, 234, 728]]]\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 | 585 |
Solve the programming task below in a Python markdown code block.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish... | {"inputs": ["1\n1\n", "1\n17\n", "2\n1 2\n", "1\n500\n", "1\n987\n", "1\n585\n", "1\n435\n", "1\n474\n"], "outputs": ["1\n", "17\n", "1\n", "500\n", "987\n", "585\n", "435\n", "474\n"]} | coding | 577 |
Solve the programming task below in a Python markdown code block.
Your task is to remove all duplicate words from a string, leaving only single (first) words entries.
Example:
Input:
'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'
Output:
'alpha beta gamma delta'
Also feel free to... | {"functional": "_inputs = [['alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'], ['my cat is my cat fat']]\n_outputs = [['alpha beta gamma delta'], ['my cat is fat']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isc... | coding | 84 |
Solve the programming task below in a Python markdown code block.
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendsh... | {"inputs": ["3 3\n4 5\n0 17\n9 11\n", "1 1000000000\n15 1\n", "1 1000000000\n19 8\n", "1 1000000000\n15 12\n", "3 3\n4 15\n0 17\n9 11\n", "3 3\n4 15\n0 17\n9 11\n", "1 1000000000\n15 12\n", "3 3\n4 15\n0 17\n6 11\n"], "outputs": ["17\n", "1\n", "8\n", "12\n", "17\n", "17", "12", "26\n"]} | coding | 432 |
Solve the programming task below in a Python markdown code block.
You are given an array of integers $b_1, b_2, \ldots, b_n$.
An array $a_1, a_2, \ldots, a_n$ of integers is hybrid if for each $i$ ($1 \leq i \leq n$) at least one of these conditions is true:
$b_i = a_i$, or
$b_i = \sum_{j=1}^{i} a_j$.
Find the numb... | {"inputs": ["4\n3\n2 0 1\n4\n1 2 2 4\n10\n2 0 1 0 1 2 -6 0 -2 -2\n4\n0 0 0 1\n", "4\n3\n2 0 1\n4\n1 2 2 4\n10\n2 0 1 0 0 2 -6 0 -2 -2\n4\n0 0 0 2\n", "4\n3\n1 -2 1\n4\n1 2 3 4\n10\n2 -1 1 -2 2 3 -5 0 2 0\n4\n0 0 1 2\n", "4\n3\n1 -1 1\n4\n1 2 3 6\n10\n2 -1 1 -2 2 3 -5 0 2 0\n4\n0 0 1 2\n", "4\n3\n1 -2 1\n4\n1 2 3 4\n10\... | coding | 606 |
Solve the programming task below in a Python markdown code block.
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a... | {"inputs": ["1\n", "6\n", "8\n", "9\n", "2\n", "4\n", "7\n", "96\n"], "outputs": ["17 17\n", "34 57\n", "40 73\n", "41 81\n", "22 25\n", "28 41\n", "47 65\n", "144 777\n"]} | coding | 728 |
Solve the programming task below in a Python markdown code block.
You have two arrays A and B of size N and M respectively. You have to merge both the arrays to form a new array C of size N + M (the relative order of elements in the original arrays A and B should not change in the array C).
For e.g. if A = [{\color{bl... | {"inputs": ["2\n3 2\n6 4 5\n1 3\n2 3\n1 3\n2 2 4\n"], "outputs": ["4\n5\n"]} | coding | 715 |
Solve the programming task below in a Python markdown code block.
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers fr... | {"inputs": ["2 1 1\n1\n1\n", "3 1 1\n2\n1\n", "3 1 1\n2\n1\n", "2 1 1\n1\n1\n", "3 1 1\n2\n0\n", "3 1 0\n2\n0\n", "2 1 2\n1\n1 2\n", "3 1 2\n2\n1 1\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2\n", "2\n"]} | coding | 644 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the... | {"functional": "def check(candidate):\n assert candidate(triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]) == True\n assert candidate(triplets = [[1,3,4],[2,5,8]], target = [2,5,8]) == True\n assert candidate(triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]) == True\n assert candidate(tr... | coding | 287 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums of n integers, and an integer k.
The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i... | {"functional": "def check(candidate):\n assert candidate(nums = [7,4,3,9,1,8,5,2,6], k = 3) == [-1,-1,-1,5,4,4,-1,-1,-1]\n assert candidate(nums = [100000], k = 0) == [100000]\n assert candidate(nums = [8], k = 100000) == [-1]\n\n\ncheck(Solution().getAverages)"} | coding | 257 |
Solve the programming task below in a Python markdown code block.
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has ... | {"inputs": ["8 6 4 5\n", "8 6 4 6\n", "4 2 1 4\n", "1 1 1 1\n", "3 1 1 1\n", "4 2 1 6\n", "5 5 4 4\n", "3 2 1 1\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n"]} | coding | 524 |
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 two integers x and y. In one operation, you must choose an index i such that 0 <= i < nums.length and perform the following:
Decrement nums[i] by x.
Decrement values b... | {"functional": "def check(candidate):\n assert candidate(nums = [3,4,1,7,6], x = 4, y = 2) == 3\n assert candidate(nums = [1,2,1], x = 2, y = 1) == 1\n\n\ncheck(Solution().minOperations)"} | coding | 139 |
Solve the programming task below in a Python markdown code block.
You are given an array a. Some element of this array a_{i} is a local minimum iff it is strictly less than both of its neighbours (that is, a_{i} < a_{i} - 1 and a_{i} < a_{i} + 1). Also the element can be called local maximum iff it is strictly greater ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n0\n", "1\n4\n", "1\n3\n", "1\n8\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 296 |
Solve the programming task below in a Python markdown code block.
A boy PCK is playing with N electric metronomes. The i-th metronome is set to tick every t_i seconds. He started all of them simultaneously.
He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from t... | {"inputs": ["2\n8\n2", "2\n8\n4", "2\n4\n4", "2\n8\n6", "2\n4\n1", "2\n4\n0", "2\n10\n4", "2\n10\n6"], "outputs": ["0\n", "0\n", "0\n", "2\n", "0\n", "1\n", "1\n", "4\n"]} | coding | 305 |
Solve the programming task below in a Python markdown code block.
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. ... | {"inputs": ["1\n0\n", "1\n1\n", "1\n9\n", "1\n0\n", "1\n1\n", "1\n9\n", "1\n2\n", "1\n4\n"], "outputs": ["0", "1", "9", "0\n", "1", "9", "2\n", "4\n"]} | coding | 488 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7.
A subsequence of a string is obtained by deleting zero or more ch... | {"functional": "def check(candidate):\n assert candidate(s = 'bccb') == 6\n assert candidate(s = 'abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba') == 104860361\n\n\ncheck(Solution().countPalindromicSubsequences)"} | coding | 156 |
Solve the programming task below in a Python markdown code block.
Number is a palindrome if it is equal to the number with digits in reversed order.
For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes.
Write a method `palindrome_chain_length` which takes a positive number and returns th... | {"functional": "_inputs = [[87], [1], [88], [89], [10]]\n_outputs = [[4], [0], [0], [24], [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)... | coding | 291 |
Solve the programming task below in a Python markdown code block.
Byteland is a beautiful land known because of its beautiful trees.
Misha has found a binary tree with $n$ vertices, numbered from $1$ to $n$. A binary tree is an acyclic connected bidirectional graph containing $n$ vertices and $n - 1$ edges. Each verte... | {"inputs": ["4\n2\n1 2\n4\n1 2\n2 3\n2 4\n7\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n15\n1 2\n2 3\n3 4\n4 5\n4 6\n3 7\n2 8\n1 9\n9 10\n9 11\n10 12\n10 13\n11 14\n11 15\n"], "outputs": ["0\n2\n2\n10\n"]} | coding | 628 |
Solve the programming task below in a Python markdown code block.
Programmer Deepak has created a program which calculates magical number as 2^n * 3^n * 5^n where "n" is an integer.
Now he wants to find the magical number which is just greater than the input. Help him in finding it.
NOTE : a^b denotes a raised to po... | {"inputs": ["456"], "outputs": ["900"]} | coding | 139 |
Solve the programming task below in a Python markdown code block.
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching ... | {"inputs": ["A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "TANB\nXNCPR\n1\n15 h 6 r\n9 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 27 r\n6 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 2 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 54 r\n6 h 27 r\... | coding | 597 |
Solve the programming task below in a Python markdown code block.
A *Vampire number* is a positive integer `z` with a factorization `x * y = z` such that
- `x` and `y` have the same number of digits and
- the multiset of digits of `z` is equal to the multiset of digits of `x` and `y`.
- Additionally, to avoid triviali... | {"functional": "_inputs = [[10], [100], [155]]\n_outputs = [[105210], [336960], [939658]]\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): ret... | coding | 322 |
Solve the programming task below in a Python markdown code block.
On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coord... | {"inputs": ["2\n2 2\n3 5\n0 0\n1 1", "2\n2 2\n3 0\n0 0\n1 1", "2\n2 4\n3 0\n0 0\n1 1", "2\n2 4\n3 0\n0 0\n2 1", "2\n2 4\n6 0\n0 0\n2 1", "2\n2 4\n6 0\n0 0\n1 1", "2\n0 4\n6 0\n0 0\n1 1", "2\n0 3\n6 0\n0 0\n1 1"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 369 |
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 servers and tasks of lengths n and m respectively. servers[i] is the weight of the ith server, and tasks[j] is the time needed to process the jth... | {"functional": "def check(candidate):\n assert candidate(servers = [3,3,2], tasks = [1,2,3,2,1,2]) == [2,2,0,2,1,2]\n assert candidate(servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]) == [1,4,1,4,1,3,2]\n\n\ncheck(Solution().assignTasks)"} | coding | 342 |
Solve the programming task below in a Python markdown code block.
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length $n$, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move an... | {"inputs": ["2\n6\n**..**\n4\n**..\n", "2\n6\n**..**\n4\n**..\n", "2\n6\n**..**\n4\n..**\n", "2\n6\n**.**.\n4\n..**\n", "2\n6\n**..**\n4\n.*.*\n", "2\n6\n**.**.\n4\n*.*.\n", "2\n6\n.**.**\n4\n*..*\n", "2\n6\n**..**\n4\n*..*\n"], "outputs": ["4\n0\n", "4\n0\n", "4\n0\n", "2\n0\n", "4\n1\n", "2\n1\n", "2\n2\n", "4\n2\n"]... | coding | 486 |
Solve the programming task below in a Python markdown code block.
AtCoDeer the deer recently bought three paint cans.
The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.
Here, the color of each paint can is represented by an int... | {"inputs": ["3 2 4", "2 2 2", "3 2 0", "3 4 0", "3 7 0", "8 0 1", "3 7 1", "6 4 0"], "outputs": ["3\n", "1\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | coding | 201 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$ and an integer $k$.
In one step you can do one of the following moves: decrease $n$ by $1$; divide $n$ by $k$ if $n$ is divisible by $k$.
For example, if $n = 27$ and $k = 3$ you can do the following steps: $27 \rightar... | {"inputs": ["1\n2 99\n", "1\n2 99\n", "1\n1 75\n", "1\n2 75\n", "1\n2 52\n", "1\n1 14\n", "1\n2 60\n", "1\n99 99\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n"]} | coding | 387 |
Solve the programming task below in a Python markdown code block.
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of... | {"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n-1\n", "1\n-1\n", "1\n-2\n", "1\n100\n", "2\n0 1\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "2\n", "100\n", "1\n"]} | coding | 355 |
Solve the programming task below in a Python markdown code block.
# Kata Task
Given a list of random integers, return the Three Amigos.
These are 3 numbers that live next to each other in the list, and who have the **most** in common with each other by these rules:
* lowest statistical range
* same parity
# Notes
*... | {"functional": "_inputs = [[[1, 2, 34, 2, 1, 5, 3, 5, 7, 234, 2, 1]], [[2, 4, 6, 8, 10, 2, 2, 2, 1, 1, 1, 5, 3]], [[2, 4, 5, 3, 6, 3, 1, 56, 7, 6, 3, 12]], [[1, 3, 5]], [[1, 3, 2]], [[1, 3, 5, 7, 9, 11, 13, 15]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5]], [[-5, -4, -2, 0, 1, 2, 3, 4, 5]], [[-8, -25, 21, -7, -5]], [[8, 5, ... | coding | 338 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n binary matrix mat, return the number of submatrices that have all ones.
Please complete the following python code precisely:
```python
class Solution:
def numSubmat(self, mat: List[List[int]]) -> ... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,0,1],[1,1,0],[1,1,0]]) == 13\n assert candidate(mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]]) == 24\n\n\ncheck(Solution().numSubmat)"} | coding | 71 |
Solve the programming task below in a Python markdown code block.
You are given a Directed Acyclic Graph (DAG) with $n$ vertices and $m$ edges. Each vertex $v$ has an integer, $a_v$, associated with it and the initial value of $a_v$ is $0$ for all vertices. You must perform $\textit{q}$ queries on the DAG, where each q... | {"inputs": ["6 5 18\n1 2\n1 3\n3 4\n2 4\n5 6\n1 1 3\n3 1\n3 2\n3 3\n3 4\n1 2 2\n3 1\n3 2\n3 3\n3 4\n2 6 7\n3 5\n3 6\n2 1 3\n3 1\n3 2\n3 3\n3 4\n"], "outputs": ["3\n3\n3\n3\n3\n2\n3\n2\n0\n0\n3\n2\n3\n2\n"]} | coding | 633 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pa... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3])) == 6\n assert candidate(root = tree_node([-10,9,20,None,None,15,7])) == 42\n\n\ncheck(Solution().maxPathSum)"} | coding | 189 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend fo... | {"functional": "def check(candidate):\n assert candidate(n = 5, k = 2) == [4,5]\n assert candidate(n = 4, k = 4) == [2,3,4]\n\n\ncheck(Solution().circularGameLosers)"} | coding | 331 |
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 the preorder traversal of its nodes' values.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,None,2,3])) == [1,2,3]\n assert candidate(root = tree_node([])) == []\n assert candidate(root = tree_node([1])) == [1]\n assert candidate(root = tree_node([1,2])) == [1,2]\n assert candidate(root = tree_node([1,None,2])) == [1,2... | coding | 119 |
Solve the programming task below in a Python markdown code block.
As you know, the girl Dora is always looking for something. This time she was given a permutation, and she wants to find such a subsegment of it that none of the elements at its ends is either the minimum or the maximum of the entire subsegment. More for... | {"inputs": ["4\n3\n1 2 3\n4\n2 1 4 3\n7\n1 3 2 4 6 5 7\n6\n2 3 6 5 4 1\n"], "outputs": ["-1\n1 4\n2 6\n-1\n"]} | coding | 755 |
Solve the programming task below in a Python markdown code block.
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), th... | {"inputs": ["6\n", "7\n", "4\n", "5\n", "3\n", "8\n", "9\n", "1\n"], "outputs": ["6 1 2 3 4 5\n", "7 1 2 3 4 5 6\n", "4 1 2 3\n", "5 1 2 3 4\n", "3 1 2\n", "8 1 2 3 4 5 6 7 ", "9 1 2 3 4 5 6 7 8 ", "1\n"]} | coding | 286 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary tree root and an integer target, delete all the leaf nodes with value target.
Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,2,3,2,None,2,4]), target = 2), tree_node([1,None,3,None,4]))\n assert is_same_tree(candidate(root = tree_node([1,3,3,3,2]), target = 3), tree_node([1,3,None,None,2]))\n assert is_same_tree(candidate(root = tree_node([1,2,... | coding | 168 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is repeated at least twice, you perform the following operation:
you choose the index $i$ ($1 \le i \le |s|$) such that the c... | {"inputs": ["6\ncodeforces\naezakmi\nabacaba\nconvexhull\nswflldjgpaxs\nmyneeocktxpqjpz\n", "6\nsecrofedoc\naezakmi\nabacaba\nconvexhull\nswflldjgpaxs\nmyneeocktxpqjpz\n", "6\nsecrofedoc\naezakmi\nabacaba\nconvexhull\nswflldagpjxs\nmyneeocktxpqjpz\n", "6\ncodeforces\naezakmi\nabacabb\nconvexhull\nswflldjgpaxs\nmyneeock... | coding | 612 |
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"... | coding | 516 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings of the same length words.
In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i].
Two strings words[i] and words[j] are speci... | {"functional": "def check(candidate):\n assert candidate(words = [\"abcd\",\"cdab\",\"cbad\",\"xyzz\",\"zzxy\",\"zzyx\"]) == 3\n assert candidate(words = [\"abc\",\"acb\",\"bac\",\"bca\",\"cab\",\"cba\"]) == 3\n\n\ncheck(Solution().numSpecialEquivGroups)"} | coding | 243 |
Solve the programming task below in a Python markdown code block.
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $h$, and there is a moving platform on each height $x$ from $1$ to $h$.
Each platform is either hidde... | {"inputs": ["1\n3 2\n3 2\n", "1\n3 2\n3 2\n", "1\n3 2\n3 1\n", "1\n6 2\n6 2\n", "1\n6 2\n6 1\n", "1\n6 2\n6 3\n", "4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1\n", "4\n1 1\n1\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n1\n2\n0\n", "0\n0\n1\n2\n... | coding | 674 |
Solve the programming task below in a Python markdown code block.
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
-----Input-----
The first line of the input contains integer n (1 ≤ n ≤ ... | {"inputs": ["1\n0 0\n", "1\n6 6\n", "1\n0 0\n", "1\n6 6\n", "1\n9 6\n", "1\n-1 0\n", "1\n18 6\n", "1\n0 -1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 176 |
Solve the programming task below in a Python markdown code block.
Gigi is a clever monkey, living in the zoo, his teacher (animal keeper) recently taught him some knowledge of "0".
In Gigi's eyes, "0" is a character contains some circle(maybe one, maybe two).
So, a is a "0",b is a "0",6 is also a "0",and 8 have two "... | {"functional": "_inputs = [[''], ['0'], ['0oO0oO'], ['1234567890'], ['abcdefghijklmnopqrstuvwxyz'], ['()'], ['E'], ['aA'], ['BRA'], ['%%']]\n_outputs = [[0], [1], [6], [5], [8], [1], [0], [1], [3], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return mat... | coding | 224 |
Solve the programming task below in a Python markdown code block.
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, y_{i}).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every poi... | {"inputs": ["4\n1 0 3 0\n", "4\n1 0 1 4\n", "4\n0 0 4 0\n", "4\n0 0 1 3\n", "4\n1 3 4 4\n", "4\n2 2 4 5\n", "4\n1 3 3 6\n", "4\n1 3 4 4\n"], "outputs": ["No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n"]} | coding | 424 |
Solve the programming task below in a Python markdown code block.
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.
A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alte... | {"inputs": ["7\n", "2\n", "5\n", "8\n", "9\n", "6\n", "1\n", "3\n"], "outputs": ["53", "3", "19", "87", "142", "32", "1", "6"]} | coding | 386 |
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 the length of the diameter of the tree.
The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through th... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5])) == 3\n assert candidate(root = tree_node([1,2])) == 1\n\n\ncheck(Solution().diameterOfBinaryTree)"} | coding | 170 |
Solve the programming task below in a Python markdown code block.
# Convert Improper Fraction to Mixed Number
You will need to convert an [improper fraction](https://www.mathplacementreview.com/arithmetic/fractions.php#improper-fractions) to a [mixed number](https://www.mathplacementreview.com/arithmetic/fractions.php... | {"functional": "_inputs = [['18/11'], ['13/5'], ['75/10']]\n_outputs = [['1 7/11'], ['2 3/5'], ['7 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(... | coding | 183 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).
A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,-1,8,4]) == 3\n assert candidate(nums = [1,-1,4]) == 2\n assert candidate(nums = [2,5]) == -1\n assert candidate(nums = [1]) == 0\n\n\ncheck(Solution().findMiddleIndex)"} | coding | 191 |
Solve the programming task below in a Python markdown code block.
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a_1, a_2, ..., a_{m} of length m, consisting of integers from 1 to n, not necessaril... | {"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "3 1\n1 1 2\n2\n", "2 2\n1 1\n1 2\n", "2 2\n1 1\n1 2\n", "3 1\n1 1 2\n2\n", "3 1\n1 1 2\n3\n", "3 2\n1 1 3\n1 2\n"], "outputs": ["Possible\n1 \n", "Possible\n1 \n", "Possible\n3 \n", "Impossible\n", "Impossible\n", "Possible\n3 \n", "Impossible\n", "Impossible\n"]} | coding | 572 |
Solve the programming task below in a Python markdown code block.
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximi... | {"inputs": ["1 0\n0\n", "1 0\n0\n", "1 0\n1\n", "1 1\n0\n", "1 1\n1\n", "1 0\n0\n", "1 0\n1\n", "1 1\n0\n"], "outputs": ["0\n0\n", "0\n0\n", "1\n1\n", "1\n1\n", "1\n1\n", "0\n0 ", "1\n1 ", "1\n1 "]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
The only difference between the easy and the hard versions is constraints.
A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are... | {"inputs": ["1 2\nu\n", "1 5\nw\n", "1 5\nw\n", "1 2\nu\n", "1 1\ns\n", "1 6\nn\n", "1 10\ns\n", "1 25\no\n"], "outputs": ["1\n", "-1\n", "-1\n", "1\n", "0\n", "-1\n", "-1\n", "-1\n"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Form... | {"inputs": ["3\n2 1\n3 0\n9 100\n"], "outputs": ["6\n42\n260610\n"]} | coding | 393 |
Solve the programming task below in a Python markdown code block.
Snuke built an online judge to hold a programming contest.
When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-chara... | {"inputs": ["XW", "XV", "VX", "YW", "WY", "VY", "YV", "YU"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 207 |
Solve the programming task below in a Python markdown code block.
While playing yet another strategy game, Mans has recruited $n$ Swedish heroes, whose powers which can be represented as an array $a$.
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something... | {"inputs": ["1\n8\n", "1\n11\n", "1\n11\n", "1\n22\n", "1\n15\n", "2\n86 5\n", "2\n86 5\n", "2\n86 8\n"], "outputs": ["8\n", "11\n", "11", "22\n", "15\n", "-91\n", "-91", "-94\n"]} | coding | 415 |
Solve the programming task below in a Python markdown code block.
# Task
Your task is to find the smallest number which is evenly divided by all numbers between `m` and `n` (both inclusive).
# Example
For `m = 1, n = 2`, the output should be `2`.
For `m = 2, n = 3`, the output should be `6`.
For `m = 3, n = 2... | {"functional": "_inputs = [[1, 2], [1, 5], [5, 1], [1, 10], [2, 3], [3, 5], [10, 20], [1, 25], [24, 25]]\n_outputs = [[2], [60], [60], [2520], [6], [60], [232792560], [26771144400], [600]]\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... | coding | 208 |
Solve the programming task below in a Python markdown code block.
#Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
... | {"functional": "_inputs = [['a'], ['z'], ['aaa'], ['aaab'], ['foo']]\n_outputs = [[1], [26], [1], [2], [3759]]\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 ... | coding | 154 |
Solve the programming task below in a Python markdown code block.
Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:
- Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).
- The number of matchsticks used to form digits 1, 2,... | {"inputs": ["6965 1\n3\n", "1685 1\n3\n", "4 7\n4 4 7", "9 6\n7 5 6", "5 7\n7 3 6", "8 6\n7 5 6", "5 7\n5 3 6", "15 4\n5 4 6"], "outputs": ["33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333... | coding | 350 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid.
The rules of tic-tac-toe are... | {"functional": "def check(candidate):\n assert candidate(board = [\"O X\",\" XO\",\"X O\"]) == \"X\"\n assert candidate(board = [\"OOX\",\"XXO\",\"OXO\"]) == \"Draw\"\n assert candidate(board = [\"OOX\",\"XXO\",\"OX \"]) == \"Pending\"\n\n\ncheck(Solution().tictactoe)"} | coding | 253 |
Solve the programming task below in a Python markdown code block.
Dexter, being irritated by DD, gave her a lucrative game to play to keep her busy.
There are $N$ bags numbered $1$ to $N$. The $i_{th}$ bag contains $A_i$ coins. The bags are placed in a circular order such that the $N_{th}$ bag is adjacent to the $1^{st... | {"inputs": ["1\n5 3\n8 6 9 4 10"], "outputs": ["24"]} | coding | 389 |
Solve the programming task below in a Python markdown code block.
Write a function that takes a number or a string and gives back the number of **permutations without repetitions** that can generated using all of its element.; more on permutations [here](https://en.wikipedia.org/wiki/Permutation).
For example, startin... | {"functional": "_inputs = [[2], [25], [342], [1397], [76853], ['a'], ['ab'], ['abc'], [737], [66666]]\n_outputs = [[1], [2], [6], [24], [120], [1], [2], [6], [3], [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_to... | coding | 185 |
Solve the programming task below in a Python markdown code block.
You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
#Examples:
~~~if-not:bf
```
Kata.getMiddle(... | {"functional": "_inputs = [['test'], ['testing'], ['middle'], ['A'], ['of']]\n_outputs = [['es'], ['t'], ['dd'], ['A'], ['of']]\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, tupl... | coding | 300 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer num. You can swap two digits at most once to get the maximum valued number.
Return the maximum valued number you can get.
Please complete the following python code precisely:
```python
class... | {"functional": "def check(candidate):\n assert candidate(num = 2736) == 7236\n assert candidate(num = 9973) == 9973\n\n\ncheck(Solution().maximumSwap)"} | coding | 78 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string text. You can swap two of the characters in the text.
Return the length of the longest substring with repeated characters.
Please complete the following python code precisely:
```python
class ... | {"functional": "def check(candidate):\n assert candidate(text = \"ababa\") == 3\n assert candidate(text = \"aaabaaa\") == 6\n assert candidate(text = \"aaabbaaa\") == 4\n assert candidate(text = \"aaaaa\") == 5\n assert candidate(text = \"abcdef\") == 1\n\n\ncheck(Solution().maxRepOpt1)"} | coding | 78 |
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 of the same length present and future where present[i] is the current price of the ith stock and future[i] is the price of the ith stock a year in the future. You may buy eac... | {"functional": "def check(candidate):\n assert candidate(present = [5,4,6,2,3], future = [8,5,4,3,5], budget = 10) == 6\n assert candidate(present = [2,2,5], future = [3,4,10], budget = 6) == 5\n assert candidate(present = [3,3,12], future = [0,3,15], budget = 10) == 0\n\n\ncheck(Solution().maximumProfit)"} | coding | 138 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i].
Please complete the following python code precisely:
```python
class Solution:
... | {"functional": "def check(candidate):\n assert candidate(nums = [5,2,6,1]) == [2,1,1,0] \n assert candidate(nums = [-1]) == [0]\n assert candidate(nums = [-1,-1]) == [0,0]\n\n\ncheck(Solution().countSmaller)"} | coding | 78 |
Solve the programming task below in a Python markdown code block.
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curve... | {"inputs": ["{}\n", "{}\n", "{a}\n", "{y}\n", "{x}\n", "{z}\n", "{a}\n", "{x}\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 232 |
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 and his friend Chefu decided to go on a trip. The trip takes place over the next $N$ days (numbered 1 through $N$). There are $K$ different plac... | {"inputs": ["5\n5 3\n-1 -1 -1 -1 -1\n4 5\n1 2 3 5\n3 2\n1 -1 2\n4 2\n1 -1 -1 1\n6 4\n-1 -1 4 -1 2 -1"], "outputs": ["YES\n1 2 1 2 1\nYES\n1 2 3 5\nNO\nNO\nYES\n1 2 4 1 2 1"]} | coding | 768 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n. Each digit of n has a sign according to the following rules:
The most significant digit is assigned a positive sign.
Each other digit has an opposite sign to its adjacent digits.
... | {"functional": "def check(candidate):\n assert candidate(n = 521) == 4\n assert candidate(n = 111) == 1\n assert candidate(n = 886996) == 0\n\n\ncheck(Solution().alternateDigitSum)"} | coding | 102 |
Solve the programming task below in a Python markdown code block.
We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to... | {"inputs": ["2\n2 0\n1 2", "2\n2 1\n1 1", "2\n0 1\n1 1", "2\n0 1\n2 1", "2\n0 1\n0 1", "2\n1 1\n0 1", "2\n1 2\n0 1", "2\n1 2\n0 2"], "outputs": ["-1", "1", "0", "0", "0", "0", "0", "0"]} | coding | 489 |
Solve the programming task below in a Python markdown code block.
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number $q = \frac{\sqrt{5} + 1}{2}$, in particular that q^2 = q + 1, and she thinks it would make a good base for h... | {"inputs": ["0\n0\n", "0\n1\n", "1\n0\n", "1\n1\n", "1\n1\n", "0\n1\n", "0\n0\n", "1\n0\n"], "outputs": ["=\n", "<\n", ">\n", "=\n", "=", "<", "=", ">"]} | coding | 464 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two sparse matrices mat1 of size m x k and mat2 of size k x n, return the result of mat1 x mat2. You may assume that multiplication is always possible.
Please complete the following python code precisely:
```p... | {"functional": "def check(candidate):\n assert candidate(mat1 = [[1,0,0],[-1,0,3]], mat2 = [[7,0,0],[0,0,0],[0,0,1]]) == [[7,0,0],[-7,0,3]]\n assert candidate(mat1 = [[0]], mat2 = [[0]]) == [[0]]\n\n\ncheck(Solution().multiply)"} | coding | 97 |
Solve the programming task below in a Python markdown code block.
Peter has a sequence of integers a_1, a_2, ..., a_{n}. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (inclusive). A... | {"inputs": ["3 2\n1 1 1\n", "3 2\n2 1 1\n", "3 4\n4 3 2\n", "3 6\n5 6 5\n", "3 2\n1 0 1\n", "1 349\n348\n", "3 2\n1 0 1\n", "3 2\n2 1 1\n"], "outputs": ["4\n", "2\n", "0\n", "1\n", "2\n", "1\n", "2\n", "2\n"]} | coding | 374 |
Solve the programming task below in a Python markdown code block.
Chef likes rectangles. Among all possible rectangles, he loves rectangles that can be drawn like a grid, such that they have N rows and M columns. Grids are common in Byteland. Hence, Chef has drawn such a rectangle and plans on moving around in it.
The... | {"inputs": ["3\n2 2 2\n4 2 2\n1 5 2", "3\n2 7 2\n4 2 2\n1 9 0", "3\n2 7 2\n4 2 2\n1 9 4", "3\n2 1 2\n5 2 2\n1 5 2", "3\n2 4 2\n8 2 2\n1 9 3", "3\n1 9 2\n4 2 2\n1 9 0", "3\n2 2 2\n3 1 2\n1 8 0", "3\n2 1 2\n5 2 2\n1 5 1"], "outputs": ["1\n1\n2\n", "1\n1\n0\n", "1\n1\n4\n", "0\n1\n2\n", "1\n1\n3\n", "2\n1\n0\n", "1\n2\n0\... | coding | 702 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the maximum value of $n$.
You are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$.
The positive integer is... | {"inputs": ["1\n6\n", "1\n8\n", "1\n662\n", "1\n937\n", "1\n150\n", "1\n719\n", "1\n940\n", "1\n435\n"], "outputs": ["9\n", "9\n", "729\n", "972\n", "243\n", "729\n", "972\n", "729\n"]} | coding | 619 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Implement a function signFunc(x) that returns:
1 if x is positive.
-1 if x is negative.
0 if x is equal to 0.
You are given an integer array nums. Let product be the product of all values in the array nums.
Return s... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,-2,-3,-4,3,2,1]) == 1\n assert candidate(nums = [1,5,0,2,-3]) == 0\n assert candidate(nums = [-1,1,-1,1,-1]) == -1\n\n\ncheck(Solution().arraySign)"} | coding | 106 |
Solve the programming task below in a Python markdown code block.
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the same size a_1 and a_... | {"inputs": ["a\na\n", "a\nb\n", "a\na\n", "a\nb\n", "a\nc\n", "a\nd\n", "`\nc\n", "`\nd\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 409 |
Solve the programming task below in a Python markdown code block.
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th d... | {"inputs": ["1\n2\n", "1\n0\n", "1\n3\n", "1\n1\n", "2\n0 2\n", "2\n1 2\n", "2\n2 3\n", "2\n0 0\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "2\n"]} | coding | 686 |
Solve the programming task below in a Python markdown code block.
For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows:
* f(b,n) = n, when n < b
* f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b
Here, {\rm floor}(n / b) denotes the largest integer not exc... | {"inputs": ["87654\n9", "87654\n8", "87654\n1", "87654\n2", "87654\n3", "87654\n4", "87654\n7", "87654\n5"], "outputs": ["2\n", "3\n", "87654\n", "43827\n", "29218\n", "43826\n", "12522\n", "87650\n"]} | coding | 468 |
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 a positive integer k.
Return the length of the longest subsequence of s that makes up a binary number less than or equal to k.
Note:
The subsequence can contain leading zeroes.
The... | {"functional": "def check(candidate):\n assert candidate(s = \"1001010\", k = 5) == 5\n assert candidate(s = \"00101001\", k = 1) == 6\n\n\ncheck(Solution().longestSubsequence)"} | coding | 138 |
Solve the programming task below in a Python markdown code block.
Sherlock is given an array of $N$ integers ($A_0,A_1...A_{N-1}$ by Watson. Now Watson asks Sherlock how many different pairs of indices $\boldsymbol{i}$ and $j$ exist such that $\boldsymbol{i}$ is not equal to $j$ but $A_i$ is equal to $A_j$.
That ... | {"inputs": ["2\n3\n1 2 3\n3\n1 1 2\n"], "outputs": ["0\n2\n"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then t... | {"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["*\n*\n**\n*\n**\n***\n*\n**\n* *\n****\n*\n**\n* *\n* *\n*****"]} | coding | 197 |
Solve the programming task below in a Python markdown code block.
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.
We all know that programs often store sets of integers. For example, if we have a problem about a wei... | {"inputs": ["1\nint\n", "2\nint int\n", "1\npair iot\n", "1\npair ins\n", "1\npair int\n", "2\npair int int\n", "2\nint pair int\n", "1\nint pair pair\n"], "outputs": ["int\n", "Error occurred\n", "Error occurred\n", "Error occurred\n", "Error occurred\n", "pair<int,int>\n", "Error occurred\n", "Error occurred\n"]} | coding | 632 |
Solve the programming task below in a Python markdown code block.
Find the least common multiple (LCM) of given n integers.
Constraints
* 2 ≤ n ≤ 10
* 1 ≤ ai ≤ 1000
* Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1
Input
n
a1 a2 ... an
n is given in the first line. Then, n integers are given ... | {"inputs": ["3\n3 4 3", "3\n3 7 3", "3\n4 6 5", "3\n4 6 7", "3\n4 4 7", "3\n5 4 7", "3\n9 4 3", "3\n9 2 6"], "outputs": ["12\n", "21\n", "60\n", "84\n", "28\n", "140\n", "36\n", "18\n"]} | coding | 156 |
Solve the programming task below in a Python markdown code block.
You are given an undirected graph consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is $a_i$. Initially there are no edges in the graph.
You may add some edges to this graph, but you have to pay for them. The cost ... | {"inputs": ["1 0\n1\n", "1 0\n4\n", "1 0\n4\n", "1 0\n1\n", "1 0\n7\n", "1 0\n8\n", "1 0\n10\n", "1 0\n18\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 621 |
Solve the programming task below in a Python markdown code block.
Check Tutorial tab to know how to to solve.
The included code stub will read an integer, $n$, from STDIN.
Without using any string methods, try to print the following:
$123\cdots n$
Note that "$\bullet\bullet\bullet\bullet$" represents the cons... | {"inputs": ["3\n"], "outputs": ["123\n"]} | coding | 168 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:
If the first element has the smallest value, remove it
Otherwise, put the first ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,4,-1]) == 5\n assert candidate(nums = [1,2,4,3]) == 5\n assert candidate(nums = [1,2,3]) == 3\n\n\ncheck(Solution().countOperationsToEmptyArray)"} | coding | 116 |
Solve the programming task below in a Python markdown code block.
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started ... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n0\n", "1 0 1\n2\n", "1 2 1\n1\n", "1 0 1\n1\n", "2 5 1\n5 8\n", "2 5 1\n8 8\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "3\n", "1\n", "9\n", "10\n"]} | coding | 451 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting of brackets of two types: '(', ')', '[' and ']'.
A string is called a regular bracket sequence (RBS) if it's of one of the following types:
empty string;
'(' + RBS + ')';
'[' + RBS + ']';
RBS + RBS.
where plus... | {"inputs": ["4\n()\n()\n()\n()\n", "4\n()\n()\n()\n()\n", "4\n)(\n()\n()\n()\n", "4\n)(\n()\n((\n()\n", "4\n()\n()\n)(\n()\n", "4\n)(\n))\n()\n()\n", "4\n)(\n()\n((\n)(\n", "4\n()\n))\n()\n()\n"], "outputs": ["1\n1\n1\n1\n", "1\n1\n1\n1\n", "0\n1\n1\n1\n", "0\n1\n0\n1\n", "1\n1\n0\n1\n", "0\n0\n1\n1\n", "0\n1\n0\n0\n",... | coding | 461 |
Solve the programming task below in a Python markdown code block.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is t... | {"inputs": ["2 2\n", "3 2\n", "1 8\n", "100000 100000\n"], "outputs": ["8\n", "12\n", "0\n", "530123477\n"]} | coding | 265 |
Solve the programming task below in a Python markdown code block.
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
So given a string "super", we should return a list of [2, 4].
Some examples:
Mmmm => []
... | {"functional": "_inputs = [['mmm'], ['apple'], ['super'], ['orange'], ['grapes'], ['supercalifragilisticexpialidocious'], ['123456'], ['crIssUm'], ['Implied'], ['rIc'], ['UNDISARMED'], ['bialy'], ['stumpknocker'], ['narboonnee'], ['carlstadt'], ['ephodee'], ['spicery'], ['oftenness'], ['bewept'], ['capsized']]\n_output... | coding | 168 |
Solve the programming task below in a Python markdown code block.
problem
JOI decided to play a game with his friends. N players participate in this game. The rules for a single game are as follows:
Each player writes a favorite integer from 1 to 100 on the card and submits it. Each player gets the same score as he w... | {"inputs": ["5\n100 2 98\n100 97 5\n18 4 65\n68 1 77\n57 81 58", "5\n100 2 98\n100 97 5\n18 4 12\n68 1 77\n57 81 58", "5\n100 2 98\n100 97 5\n18 4 47\n68 1 77\n57 81 58", "5\n100 2 98\n100 97 5\n18 4 65\n68 91 77\n57 81 58", "5\n100 1 98\n100 97 68\n2 21 9\n68 99 77\n89 97 43", "5\n100 1 98\n100 97 5\n18 4 65\n68 91 77... | coding | 624 |
Solve the programming task below in a Python markdown code block.
Watson gives Sherlock an array of integers. Given the endpoints of an integer range, for all $M$ in that inclusive range, determine the minimum( abs(arr[i]-M) for all $1\leq i\leq|arr|$) ). Once that has been determined for all integers in the range, r... | {"inputs": ["3\n5 8 14\n4 9\n"], "outputs": ["4\n"]} | coding | 674 |
Solve the programming task below in a Python markdown code block.
The $\text{$gcdSum$}$ of a positive integer is the $gcd$ of that integer with its sum of digits. Formally, $\text{$gcdSum$}(x) = gcd(x, \text{ sum of digits of } x)$ for a positive integer $x$. $gcd(a, b)$ denotes the greatest common divisor of $a$ and $... | {"inputs": ["3\n6\n5\n4\n", "3\n6\n6\n4\n", "3\n6\n6\n6\n", "3\n6\n3\n6\n", "3\n6\n3\n8\n", "3\n6\n4\n8\n", "3\n4\n4\n75\n", "3\n4\n6\n75\n"], "outputs": ["6\n5\n4\n", "6\n6\n4\n", "6\n6\n6\n", "6\n3\n6\n", "6\n3\n8\n", "6\n4\n8\n", "4\n4\n75\n", "4\n6\n75\n"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
-----Input-----
A single line with a positive integer $k$ ($... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "7\n", "9\n", "7\n"], "outputs": ["19\n", "28\n", "37\n", "46\n", "55\n", "73\n", "91\n", "73"]} | coding | 151 |
Solve the programming task below in a Python markdown code block.
# Task
You are given two string `a` an `s`. Starting with an empty string we can do the following two operations:
```
append the given string a to the end of the current string.
erase one symbol of the current string.```
Your task is to find the least n... | {"functional": "_inputs = [['aba', 'abbabba'], ['aba', 'abaa'], ['aba', 'a'], ['a', 'a'], ['a', 'aaa'], ['abcdefgh', 'hgfedcba']]\n_outputs = [[9], [4], [3], [1], [3], [64]]\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, ... | coding | 388 |
Solve the programming task below in a Python markdown code block.
**This Kata is intended as a small challenge for my students**
All Star Code Challenge #23
There is a certain multiplayer game where players are assessed at the end of the game for merit. Players are ranked according to an internal scoring system that ... | {"functional": "_inputs = [[[]]]\n_outputs = [[[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.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 all(_deep_eq... | coding | 359 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix grid where grid[r][c] represents the height of ... | {"functional": "def check(candidate):\n assert candidate(grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]) == 35\n assert candidate(grid = [[0,0,0],[0,0,0],[0,0,0]]) == 0\n\n\ncheck(Solution().maxIncreaseKeepingSkyline)"} | coding | 240 |
Solve the programming task below in a Python markdown code block.
The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$-th pile contains $a_i$ haybales.
However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, B... | {"inputs": ["3\n4 5\n1 0 3 2\n2 2\n100 1\n1 8\n0\n", "3\n4 5\n1 0 1 2\n2 2\n100 1\n1 8\n0\n", "3\n4 5\n1 0 1 2\n2 2\n100 2\n1 8\n0\n", "3\n4 5\n0 0 1 2\n2 2\n100 2\n1 7\n0\n", "3\n4 5\n0 0 1 2\n2 2\n000 2\n1 7\n0\n", "3\n4 5\n1 0 3 2\n2 2\n100 0\n1 8\n0\n", "3\n4 5\n2 0 1 2\n2 2\n100 2\n1 8\n0\n", "3\n4 1\n1 0 1 2\n2 2... | coding | 670 |
Solve the programming task below in a Python markdown code block.
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only s... | {"inputs": ["2 2 2\n2 1\n1 2\n", "3 4 2\n2 2\n2 4\n", "3 4 2\n3 2\n2 4\n", "3 7 2\n3 2\n2 4\n", "2 4 2\n2 2\n2 3\n", "3 4 2\n2 2\n2 3\n", "100000 100000 2\n1 2\n2 1\n", "100 100 3\n15 7\n16 15\n15 88\n"], "outputs": ["0\n", "2", "3", "9", "1", "2\n", "0\n", "950251154"]} | coding | 461 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.