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.
Mohit's girlfriend is playing a game with Nicky. The description of the game is as follows:
- Initially on a table Player 1 will put N gem-stones.
- Players will play alternatively, turn by turn.
- At each move a player can take at most M gem-stones (at ... | {"inputs": ["4 2"], "outputs": ["2"]} | coding | 411 |
Solve the programming task below in a Python markdown code block.
A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. Longest common subsequence (LCS) of 2 sequences is a subsequence, with maximal length, which is common ... | {"inputs": ["5 6\n1 2 3 4 1\n3 4 1 2 1 3\n"], "outputs": ["1 2 3\n"]} | coding | 549 |
Solve the programming task below in a Python markdown code block.
Joisino is about to compete in the final round of a certain programming competition.
In this contest, there are N problems, numbered 1 through N.
Joisino knows that it takes her T_i seconds to solve problem i(1β¦iβ¦N).
Also, there are M kinds of drinks off... | {"inputs": ["3\n2 1 4\n2\n1 1\n0 3", "3\n2 1 4\n2\n1 1\n0 6", "3\n2 1 4\n2\n1 0\n2 3", "3\n2 1 4\n2\n1 0\n0 3", "3\n1 1 4\n2\n1 1\n0 6", "3\n2 0 4\n2\n1 0\n0 3", "3\n1 1 0\n2\n1 1\n0 6", "3\n1 1 0\n2\n1 1\n0 8"], "outputs": ["6\n6\n", "6\n9\n", "5\n9\n", "5\n6\n", "6\n8\n", "4\n5\n", "2\n8\n", "2\n10\n"]} | coding | 477 |
Solve the programming task below in a Python markdown code block.
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
-----Input-----
... | {"inputs": ["1\n2\n", "3\n3\n", "4\n9\n", "5\n6\n", "6\n9\n", "2\n6\n", "1\n2\n", "3\n3\n"], "outputs": ["1\n", "3\n", "4\n", "5\n", "6\n", "2\n", "1\n", "3\n"]} | coding | 243 |
Solve the programming task below in a Python markdown code block.
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String a is the divisor of string b if and only if there exists a positive integer x such that if we write out str... | {"inputs": ["a\na\n", "a\nb\n", "c\nc\n", "a\nc\n", "b\nc\n", "c\nb\n", "b\nd\n", "c\nd\n"], "outputs": ["1", "0", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 280 |
Solve the programming task below in a Python markdown code block.
Platypus Perry is on a mission again. This time, Dr. Heinz Doofenshmirtz has plotted a bomb in the centre of Danville town. He wishes to rebuild the town.
We need to defuse the bomb for Perry. As always, Dr. Heinz has given perry the key combination to ... | {"inputs": ["2\n987654321 123\n120000000 22"], "outputs": ["121401\n107748\n94095\n80442\n66789\n53136\n39483\n264\n440\n0\n0\n0\n0\n0\n0"]} | coding | 345 |
Solve the programming task below in a Python markdown code block.
For a square matrix of integers of size $n \times n$, let's define its beauty as follows: for each pair of side-adjacent elements $x$ and $y$, write out the number $|x-y|$, and then find the number of different numbers among them.
For example, for the m... | {"inputs": ["2\n2\n3\n"], "outputs": ["4 1\n2 3\n9 1 8\n3 7 2\n6 4 5\n"]} | coding | 401 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the smallest prime palindrome greater than or equal to n.
An integer is prime if it has exactly two divisors: 1 and itself. Note that 1 is not a prime number.
For example, 2, 3, 5, 7, 11, a... | {"functional": "def check(candidate):\n assert candidate(n = 6) == 7\n assert candidate(n = 8) == 11\n assert candidate(n = 13) == 101\n\n\ncheck(Solution().primePalindrome)"} | coding | 187 |
Solve the programming task below in a Python markdown code block.
In this Kata, we will check if a string contains consecutive letters as they appear in the English alphabet and if each letter occurs only once.
```Haskell
Rules are: (1) the letters are adjacent in the English alphabet, and (2) each letter occurs only... | {"functional": "_inputs = [['abc'], ['abd'], ['dabc'], ['abbc']]\n_outputs = [[True], [False], [True], [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 isinstance(a, (list, tuple)):\n if... | coding | 197 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Let's call a positive integer $M$ a *beautiful number* if the following conditions are satisfied:
The decimal representation of $M$ (without leading ... | {"inputs": ["2\n1\n2"], "outputs": ["1\n34"]} | coding | 453 |
Solve the programming task below in a Python markdown code block.
"Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up."
Let's call a string balanced if all characters that occur in this string occur in it the same number of... | {"inputs": ["2\nABCB\nBBC"], "outputs": ["1\n1"]} | coding | 452 |
Solve the programming task below in a Python markdown code block.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have $n$... | {"inputs": ["1\n0\n", "1\n8\n", "1\n8\n", "1\n0\n", "1\n1\n", "1\n2\n", "8\n12345678\n", "8\n12345678\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
Did you hear about the Nibiru collision ? It is a supposed disastrous encounter between the earth and a large planetary object. Astronomers reject this idea. But why listen to other people's beliefs and opinions. We are coders above all, so what better w... | {"inputs": ["3\n0 0 R\n2\n2 0 U\n2 2 D\n1 2 U\n1\n2 0 U\n2 0 R\n1\n3 0 L", "3\n0 0 R\n2\n2 0 U\n2 2 D\n1 2 U\n1\n1 0 U\n1 0 R\n1\n3 0 L", "3\n0 0 R\n2\n1 -2 U\n2 2 D\n1 1 U\n1\n1 0 U\n0 0 R\n1\n3 0 L", "3\n0 0 R\n2\n2 -2 U\n2 2 D\n1 1 U\n1\n1 0 U\n0 0 R\n1\n3 0 L", "3\n0 0 R\n2\n1 -4 U\n1 2 D\n1 1 U\n1\n1 0 U\n0 0 R\n1... | coding | 733 |
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"]} | coding | 497 |
Solve the programming task below in a Python markdown code block.
There is a girl named ''Akansha''. She is very fond of eating chocolates but she has a weak immune system due to which she gets cold after eating chocolate during morning, evening and night and can only eat at most $x$ number of chocolate each afternoon.... | {"inputs": ["3\n3\n5\n4 1 2\n5\n2\n4 4 3 2 2\n5\n1\n4 2 3 1 1"], "outputs": ["Impossible\nPossible\nImpossible"]} | coding | 628 |
Solve the programming task below in a Python markdown code block.
You are given an array A of length N. Find the number of pairs of indices (i,j) such that
1 β€ i < j β€ N
A_{i} \cdot A_{j} > 0
------ Input Format ------
- The first line contains a single integer T - the number of test cases. Then the test cases follo... | {"inputs": ["3\n5\n1 -3 0 2 -1\n4\n-1 -1 -1 -1\n4\n0 1 2 3\n"], "outputs": ["2\n6\n3\n"]} | coding | 395 |
Solve the programming task below in a Python markdown code block.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be ... | {"inputs": ["1\n", "8\n", "6\n", "3\n", "4\n", "5\n", "2\n", "9\n"], "outputs": ["1\n", "280\n", "60\n", "6\n", "12\n", "60\n", "2\n", "504\n"]} | coding | 269 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).
For example, "Hello ... | {"functional": "def check(candidate):\n assert candidate(s = \"Hello how are you Contestant\", k = 4) == \"Hello how are you\"\n assert candidate(s = \"What is the solution to this problem\", k = 4) == \"What is the solution\"\n assert candidate(s = \"chopper is not a tanuki\", k = 5) == \"chopper is not a tan... | coding | 158 |
Solve the programming task below in a Python markdown code block.
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
A... | {"inputs": ["1\n8\n", "1\n15\n", "1\n19\n", "1\n12\n", "2\n3\n7\n", "2\n3\n4\n", "2\n3\n1\n", "2\n6\n8\n"], "outputs": ["2\n", "2\n", "3\n", "3\n", "-1\n-1\n", "-1\n1\n", "-1\n-1\n", "1\n2\n"]} | coding | 333 |
Solve the programming task below in a Python markdown code block.
C: Divisor Game
problem
tsutaj is trying to play about a few games.
In a divisor game, a natural number N of 2 or more is given first, and then the game progresses according to the following procedure.
* Declare one integer from the divisors of N oth... | {"inputs": ["2", "8", "7", "4", "5", "3", "6", "9"], "outputs": ["1 1\n", "1 3\n", "1 1\n", "1 2\n", "1 1\n", "1 1\n", "2 3\n", "1 2\n"]} | coding | 398 |
Solve the programming task below in a Python markdown code block.
Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how h... | {"inputs": [")(\n", "()\n", "()\n", "((\n", "))\n", ")(\n", "(()((\n", "())((\n"], "outputs": ["0\n", "1\n2\n1 2 \n", "1\n2\n1 2 ", "0\n", "0\n", "0", "1\n2\n1 3 \n", "1\n2\n1 3\n"]} | coding | 719 |
Solve the programming task below in a Python markdown code block.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value a_{i}. The root of the tree is node 1.
This tree has a special propert... | {"inputs": ["5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n", "5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n", "10 10\n137 197 856 768 825 894 86 174 2 326\n7 8\n4 7\n8 9\n7 10\n1 2\n2 4\n3 6\n3 5\n2 3\n1 9 624\n2 1\n2 4\n1 6 505\n1 8 467\n1 3 643\n2 1\n1 8 631\n2 1\n1 7 244\n", "... | coding | 694 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
As usual, Tom and Jerry are fighting. Tom has strength $TS$ and Jerry has strength $JS$. You are given $TS$ and your task is to find the number of po... | {"inputs": ["2\n1\n11"], "outputs": ["0\n5"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as ... | {"inputs": ["1 2 1\n0 0\nc 1 2\n", "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 2\n", "2 1 3\n1\n2\nr 1 2\ng 1 1\ng 2 1\n", "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 1\n", "1 2 3\n0 2\nc 1 2\ng 1 1\ng 1 2\n", "1 2 3\n1 2\nc 1 2\ng 1 2\ng 1 2\n", "2 3 3\n1 0 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n", "2 3 3\n1 2 4\n3 1 5\nc 2 2\nr 1 1\ng 1 3\n"], "outpu... | coding | 695 |
Solve the programming task below in a Python markdown code block.
Let's dive into the interesting topic of regular expressions! You are given some input, and you are required to check whether they are valid mobile numbers.
A valid mobile number is a ten digit number starting with a $7,8$ or $9$.
Concept
A valid ... | {"inputs": ["2\n9587456281\n1252478965\n"], "outputs": ["YES\nNO\n"]} | coding | 269 |
Solve the programming task below in a Python markdown code block.
You are given a string s of length 8 consisting solely of '0's and '1's. Assume that the characters of the string are written in a circular fashion. You need to find the number of 0-1 or 1-0 transitions that one has to make while making a single traversa... | {"inputs": ["4\n00000000\n10101010\n10000001\n10010011"], "outputs": ["uniform\nnon-uniform\nuniform\nnon-uniform"]} | coding | 338 |
Solve the programming task below in a Python markdown code block.
Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.
The game is played by two people taking turns, where Mr. Chanek takes... | {"inputs": ["2\n5\n6\n", "2\n6\n6\n", "2\n3\n6\n", "2\n4\n6\n", "2\n1\n6\n", "2\n7\n3\n", "2\n8\n3\n", "2\n5\n1\n"], "outputs": ["2\n4\n", "4\n4\n", "2\n4\n", "3\n4\n", "1\n4\n", "3\n2\n", "5\n2\n", "2\n1\n"]} | coding | 394 |
Solve the programming task below in a Python markdown code block.
There is a directed graph with N vertices numbered 1 to N and M edges.
The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge.
Additionally, there is a button on Vertex N.
We will play a game on this graph... | {"inputs": ["2 1 0\n1 2 1\n", "2 2 0\n1 2 1\n1 1 1\n", "2 2 1\n1 2 1\n2 2 1\n", "2 2 0\n1 2 1\n1 2 2\n", "2 2 1\n2 1 2\n1 2 1\n", "2 1 10\n1 2 100\n2 2 100", "2 1 13\n1 2 100\n4 2 100", "2 1 13\n1 2 101\n4 2 100"], "outputs": ["1\n", "-1\n", "0\n", "2\n", "-1\n", "90\n", "87\n", "88\n"]} | coding | 672 |
Solve the programming task below in a Python markdown code block.
While surfing in web I found interesting math problem called "Always perfect". That means if you add 1 to the product of four consecutive numbers the answer is ALWAYS a perfect square.
For example we have: 1,2,3,4 and the product will be 1X2X3X4=24. If w... | {"functional": "_inputs = [['4,5,6,7'], ['3,s,5,6'], ['11,13,14,15'], ['10,11,12,13,15'], ['10,11,12,13'], ['ad,d,q,tt,v'], ['//,;;,/,..,'], ['1,2,3,4'], ['1015,1016,1017,1018'], ['555,777,444,111'], ['20,21,22,24'], ['9,10,10,11'], ['11254,11255,11256,11258'], ['25000,25001,25002,25003'], ['2000000,2000001,2000002,200... | coding | 208 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, ... | {"inputs": ["m\nm\n", "m\nm\n", "td\nt\n", "aa\na\n", "td\nt\n", "ba\na\n", "ba\nb\n", "bb\nb\n"], "outputs": ["0\n", "0", "1\n", "1", "1", "1\n", "1\n", "1\n"]} | coding | 471 |
Solve the programming task below in a Python markdown code block.
In winter, the inhabitants of the Moscow Zoo are very bored, in particular, it concerns gorillas. You decided to entertain them and brought a permutation $p$ of length $n$ to the zoo.
A permutation of length $n$ is an array consisting of $n$ distinct in... | {"inputs": ["1\n1\n1\n", "3\n1 3 2\n2 1 3\n", "6\n1 2 3 4 5 6\n6 5 4 3 2 1\n", "7\n7 3 6 2 1 5 4\n6 7 2 5 3 1 4\n"], "outputs": ["1\n", "2\n", "11\n", "16\n"]} | coding | 715 |
Solve the programming task below in a Python markdown code block.
In Dark Souls, players level up trading souls for stats. 8 stats are upgradable this way: vitality, attunement, endurance, strength, dexterity, resistance, intelligence, and faith. Each level corresponds to adding one point to a stat of the player's choi... | {"functional": "_inputs = [['deprived', [11, 11, 11, 11, 11, 11, 11, 11]], ['pyromancer', [10, 12, 11, 12, 9, 12, 11, 8]], ['pyromancer', [16, 12, 11, 12, 9, 12, 10, 8]], ['pyromancer', [16, 12, 11, 12, 9, 12, 13, 8]], ['pyromancer', [16, 12, 11, 12, 9, 12, 13, 10]]]\n_outputs = [['Starting as a deprived, level 6 will ... | coding | 746 |
Solve the programming task below in a Python markdown code block.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 Γ n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the fi... | {"inputs": ["2\n><\n5 5\n", "2\n>>\n1 1\n", "2\n><\n1 2\n", "2\n<>\n5 5\n", "2\n?>\n1 1\n", "2\n<>\n1 2\n", "2\n<>\n4 5\n", "2\n?>\n2 1\n"], "outputs": ["FINITE", "FINITE", "FINITE", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n", "FINITE\n"]} | coding | 347 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef is very adventurous, so he asked Bob to give him a task.
Bob gave him a sequence of blocks with heights A_{1}, A_{2}, \ldots, A_{N}. Chef is at the first block ... | {"inputs": ["2\n5\n9 15 8 13 8\n9\n20 16 13 9 17 11 15 8 7"], "outputs": ["-1\n4"]} | coding | 589 |
Solve the programming task below in a Python markdown code block.
Given an array of integers and a positive integer $\boldsymbol{\mbox{k}}$, determine the number of $(i,j)$ pairs where $i<j$ and $ar[i]$ + $ar[j]$ is divisible by $\boldsymbol{\mbox{k}}$.
Example
$ar=[1,2,3,4,5,6]$
$k=5$
Three pairs meet the ... | {"inputs": ["6 3\n1 3 2 6 1 2\n"], "outputs": [" 5\n"]} | coding | 462 |
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": ["3\n2\n3\n4"], "outputs": ["12\n21\n123\n231\n312\n1234\n2341\n3412\n4123"]} | coding | 212 |
Solve the programming task below in a Python markdown code block.
The new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some continuous discussion, they came up with a schedule s, w... | {"inputs": ["10\n10100\n", "10\n11100\n", "11111111\n1\n", "11000000\n0\n", "10100110\n1\n", "11000000\n1\n", "101101\n010\n", "101101\n000\n"], "outputs": ["10\n", "10\n", "11111111\n", "00000011\n", "11110000\n", "11000000\n", "010111\n", "001111\n"]} | coding | 546 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The value of an alphanumeric string can be defined as:
The numeric representation of the string in base 10, if it comprises of digits only.
The length of the string, otherwise.
Given an array strs of alphanumeric st... | {"functional": "def check(candidate):\n assert candidate(strs = [\"alic3\",\"bob\",\"3\",\"4\",\"00000\"]) == 5\n assert candidate(strs = [\"1\",\"01\",\"001\",\"0001\"]) == 1\n\n\ncheck(Solution().maximumValue)"} | coding | 104 |
Solve the programming task below in a Python markdown code block.
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S palindromi... | {"inputs": ["f\n", "zz\n", "ax\n", "za\n", "ddr\n", "ntt\n", "lol\n", "xxx\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n"]} | coding | 173 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are givenΒ an integer nΒ which is the length of a 0-indexed array nums, and a 0-indexed 2D-array ranges, which is a list of sub-ranges of numsΒ (sub-ranges may overlap).
Each row ranges[i] has exactly 2 cells:
range... | {"functional": "def check(candidate):\n assert candidate(n = 10, ranges = [[3,5],[7,8]]) == [[0,2],[6,6],[9,9]]\n assert candidate(n = 3, ranges = [[0,2]]) == []\n assert candidate(n = 7, ranges = [[2,4],[0,3]]) == [[5,6]]\n\n\ncheck(Solution().findMaximalUncoveredRanges)"} | coding | 264 |
Solve the programming task below in a Python markdown code block.
*Based on this Numberphile video: https://www.youtube.com/watch?v=Wim9WJeDTHQ*
---
Multiply all the digits of a nonnegative integer `n` by each other, repeating with the product until a single digit is obtained. The number of steps required is known as... | {"functional": "_inputs = [[1234567890], [123456789], [12345678], [1234567], [123456], [12345], [2379], [777], [25], [277777788888899], [3778888999]]\n_outputs = [[[0]], [[362880, 0]], [[40320, 0]], [[5040, 0]], [[720, 0]], [[120, 0]], [[378, 168, 48, 32, 6]], [[343, 36, 18, 8]], [[10, 0]], [[4996238671872, 438939648, ... | coding | 404 |
Solve the programming task below in a Python markdown code block.
Some languages like Chinese, Japanese, and Thai do not have spaces between words. However, most natural languages processing tasks like part-of-speech tagging require texts that have segmented words. A simple and reasonably effective algorithm to segment... | {"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 | 732 |
Solve the programming task below in a Python markdown code block.
Watson gives a circle and a triangle in a 2-dimensional plane to Sherlock. Sherlock has to tell if they intersect/touch each other.
The circle is centered at $(x_c,y_c)$ and has radius $\mbox{R}$.
Input Format
The first line contains $\mathbf{T}$... | {"inputs": ["2\n0 0 10\n10 0\n15 0\n15 5\n0 0 10\n0 0\n5 0\n5 5\n"], "outputs": ["YES\nNO\n"]} | coding | 337 |
Solve the programming task below in a Python markdown code block.
Chef is given a binary string S of length N.
In one operation, Chef has to choose exactly K indices and flip their values.
Chef can perform the above operation any number of times. Find the number of distinct binary strings Chef can obtain.
Since the ... | {"inputs": ["2\n4 1\n0010\n2 2\n00\n"], "outputs": ["16\n2\n"]} | coding | 393 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] =... | {"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5) == 13\n assert candidate(n = 2, edges = [[1,2]], time = 3, change = 2) == 11\n\n\ncheck(Solution().secondMinimum)"} | coding | 341 |
Solve the programming task below in a Python markdown code block.
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster?
----... | {"inputs": ["0 74\n57", "0 668\n57", "0 668\n84", "1 668\n57", "0 599\n84", "-1 864\n7", "0 823\n57", "-1 74\n57"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 226 |
Solve the programming task below in a Python markdown code block.
Petya has an array of integers $a_1, a_2, \ldots, a_n$. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it.
Petya likes to challenge himself, so he wants to sort array using only $3$-cycles. More fo... | {"inputs": ["7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 2 3\n3\n2 1 3\n3\n3 1 2\n4\n2 1 4 3\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\nYES\nYES\n"]} | coding | 722 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:
word contains the first letter of puzzle.
For each letter in word, that letter is in puzzle.
For example, if th... | {"functional": "def check(candidate):\n assert candidate(\nwords = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], \npuzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]) == [1,1,3,2,4,0]\n\n\ncheck(Solution().findNumOfValidWords)"} | coding | 190 |
Solve the programming task below in a Python markdown code block.
Your job is to build a function which determines whether or not there are double characters in a string (including whitespace characters). For example ```aa```, ``!!`` or ``` ```.
You want the function to return true if the string contains double cha... | {"functional": "_inputs = [['abca'], ['aabc'], ['a 11 c d'], ['AabBcC'], ['a b c'], ['a b c d e f g h i h k'], ['2020'], [\"a!@\u20ac\u00a3#$%^&*()_-+=}]{[|':;?/>.<,~\"]]\n_outputs = [[False], [True], [True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, f... | coding | 260 |
Solve the programming task below in a Python markdown code block.
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices w... | {"inputs": ["5\n1\n3\n3\n4\n100", "5\n1\n2\n3\n4\n110", "5\n1\n2\n1\n4\n110", "5\n1\n4\n1\n4\n110", "5\n1\n2\n3\n4\n101", "5\n1\n3\n3\n4\n110", "5\n1\n2\n3\n4\n111", "5\n1\n2\n2\n4\n110"], "outputs": ["26\n728\n728\n1404\n508533804\n", "26\n52\n728\n1404\n316452997\n", "26\n52\n26\n1404\n316452997\n", "26\n1404\n26\n14... | coding | 504 |
Solve the programming task below in a Python markdown code block.
You are given three positive integers $a$, $b$, $c$ ($a < b < c$). You have to find three positive integers $x$, $y$, $z$ such that:
$$x mod y = a,$$ $$y mod z = b,$$ $$z mod x = c.$$
Here $p mod q$ denotes the remainder from dividing $p$ by $q$. It is... | {"inputs": ["1\n1 2 2002\n", "1\n1 2 1000000\n", "1\n1 2 100000000\n", "4\n1 3 4\n127 234 421\n2 7 8\n59 94 388\n"], "outputs": ["2005 2004 2002\n", "1000003 1000002 1000000\n", "100000003 100000002 100000000\n", "8 7 4\n782 655 421\n17 15 8\n541 482 388\n"]} | coding | 413 |
Solve the programming task below in a Python markdown code block.
You have a tree of $n$ vertices. You are going to convert this tree into $n$ rubber bands on infinitely large plane. Conversion rule follows:
For every pair of vertices $a$ and $b$, rubber bands $a$ and $b$ should intersect if and only if there is an ed... | {"inputs": ["3\n1 3\n2 3\n", "3\n1 3\n2 3\n", "3\n1 2\n2 3\n", "4\n1 2\n2 3\n3 4\n", "4\n1 2\n2 4\n3 4\n", "4\n1 3\n2 4\n3 4\n", "4\n1 2\n1 4\n3 4\n", "4\n1 4\n2 4\n3 4\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n"]} | coding | 559 |
Solve the programming task below in a Python markdown code block.
Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(123) = 1 + 2 + 3 = 6.
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
Given an intege... | {"inputs": ["7", "5", "8", "2", "6", "4", "1", "3"], "outputs": ["1\n2\n3\n4\n5\n6\n7\n", "1\n2\n3\n4\n5\n", "1\n2\n3\n4\n5\n6\n7\n8\n", "1\n2\n", "1\n2\n3\n4\n5\n6\n", "1\n2\n3\n4\n", "1\n", "1\n2\n3\n"]} | coding | 211 |
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 zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).
Β
Please complete the following p... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == [[3],[20,9],[15,7]]\n assert candidate(root = tree_node([1])) == [[1]]\n assert candidate(root = tree_node([])) == []\n\n\ncheck(Solution().zigzagLevelOrder)"} | coding | 146 |
Solve the programming task below in a Python markdown code block.
M-kun has the following three cards:
* A red card with the integer A.
* A green card with the integer B.
* A blue card with the integer C.
He is a genius magician who can do the following operation at most K times:
* Choose one of the three cards an... | {"inputs": ["7 4 4\n3", "4 2 5\n3", "7 4 4\n5", "4 2 5\n6", "7 2 4\n5", "4 2 3\n6", "7 2 4\n9", "1 2 3\n6"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | coding | 249 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall.... | {"functional": "def check(candidate):\n assert candidate(maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]) == True\n assert candidate(maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]) == False\n asse... | coding | 191 |
Solve the programming task below in a Python markdown code block.
There is a new prodigy in town and he has challenged people to a game. They have to give him an integer N and he will immediately respond with a number which has more than N factors.
What the prodigy really does is to do some complex calculations in his ... | {"inputs": ["3\n3\n5\n12345678"], "outputs": ["win 6\nwin 12\nlose"]} | coding | 308 |
Solve the programming task below in a Python markdown code block.
Tashizan Hikizan (Calculation Training)
square1001 You gave E869120 two numbers, $ A $ and $ B $, as birthday presents.
E869120 You decided to use these two numbers for calculation training.
Specifically, E869120 does the following for these numbers e... | {"inputs": ["3\n4 4", "3\n4 3", "3\n5 3", "3\n9 3", "3\n7 3", "3\n0 3", "3\n0 5", "3\n0 6"], "outputs": ["-4 4\n", "-3 4\n", "-3 5\n", "-3 9\n", "-3 7\n", "-3 0\n", "-5 0\n", "-6 0\n"]} | coding | 439 |
Solve the programming task below in a Python markdown code block.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
-----Constrain... | {"inputs": ["1 2 5 4", "2 0 1 3", "0 3 8 6", "0 3 8 5", "2 2 3 4", "4 2 0 4", "4 3 4 3", "6 1 1 7"], "outputs": ["0\n", "1\n", "-3\n", "-2\n", "2\n", "4\n", "3\n", "6\n"]} | coding | 219 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will create a function that converts a string with letters and numbers to the inverse of that string (with regards to Alpha and Numeric characters). So, e.g. the letter `a` will become `1` and number `1` will become `a`; `z` will become... | {"functional": "_inputs = [['25abcd26'], ['18zyz14'], ['a1b2c3d4'], ['5a8p17'], ['w6aa4ct24m5'], ['17dh'], ['25gj8sk6r17'], ['18zzz14'], ['y17kg5et11'], ['abcdefghijklmnopqrstuvwxyz'], ['1a2b3c4d5e6f7g8h9i10j11k12l13m14n15o16p17q18r19s20t21u22v23w24x25y26z'], ['h15q4pc6yw23nmx19y'], ['p16k11o25x7m6m20ct9'], ['nv15u19d5... | coding | 257 |
Solve the programming task below in a Python markdown code block.
A country decides to build a palace.
In this country, the average temperature of a point at an elevation of x meters is T-x \times 0.006 degrees Celsius.
There are N places proposed for the place. The elevation of Place i is H_i meters.
Among them, Princ... | {"inputs": ["2\n12 5\n1000 2000\n", "3\n21 -11\n81234 94124 52141\n"], "outputs": ["1\n", "3\n"]} | coding | 343 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sereja is playing a game called Winner Eats Sandwich with his friends. There are N persons in total, including Sereja. Sereja is allotted the number 1, while his friends are allotted numbers fro... | {"inputs": ["2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000", "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n0.5000 0.5000 0.5000\n0.5000 0.5000 0.5000 ", "2\n2 2\n1.0000 1.0000\n0.0000 0.0000\n2 3\n1.2649803683768097 0.5000 0.5000\n0.5000 0.5000 0.5000", "2\n2 2\n1.0000 1.7642945663... | coding | 565 |
Solve the programming task below in a Python markdown code block.
Count the number of labeled strongly connected digraphs with the given number of vertices.
Input Format
The first line contains $\mathbf{T}$, the number of queries.
Following are $\mathbf{T}$ lines. Each line contains one integer $N$, denoting the... | {"inputs": ["5\n1\n2\n3\n4\n1000\n"], "outputs": ["1\n1\n18\n1606\n871606913\n"]} | coding | 199 |
Solve the programming task below in a Python markdown code block.
There are three cells on an infinite 2-dimensional grid, labeled $A$, $B$, and $F$. Find the length of the shortest path from $A$ to $B$ if:
in one move you can go to any of the four adjacent cells sharing a side;
visiting the cell $F$ is forbidden (it... | {"inputs": ["7\n\n1 2\n3 3\n2 2\n\n2 5\n0 0\n2 3\n\n0000 16\n1010 1\n1010 1000\n\n1 10\n0 10\n2 10\n\n3 8\n8 2\n3 7\n\n2 0\n2 1\n1 1\n\n1 578\n1 6\n0 1\n", "7\n\n1 2\n3 3\n2 2\n\n2 5\n0 0\n2 3\n\n0000 16\n1010 1\n1010 1000\n\n1 10\n0 17\n2 10\n\n3 8\n8 2\n3 7\n\n2 0\n2 1\n1 1\n\n1 578\n1 6\n0 1\n", "7\n\n1 2\n3 3\n2 2\... | coding | 516 |
Solve the programming task below in a Python markdown code block.
Raj is suffering from shot term memory loss so he is unable to remember his laptop password but he has a list of some string and the only thing that he remember about his password is alphanumeric and also that all the characters are unique.
Given a lis... | {"inputs": ["absdbads\nasdjenfef\ntyerbet\nabc564"], "outputs": ["Invalid\nInvalid\nInvalid\nValid"]} | coding | 168 |
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots a_n$. Count the number of pairs of indices $1 \leq i, j \leq n$ such that $a_i < i < a_j < j$.
-----Input-----
The first line contains an integer $t$ ($1 \leq t \leq 1000$) β the number of test cases.
The first... | {"inputs": ["5\n8\n1 1 2 3 8 2 1 4\n2\n1 2\n10\n0 2 1 6 3 4 1 2 8 3\n2\n1 1000000000\n3\n0 1000000000 2\n"], "outputs": ["3\n0\n10\n0\n1\n"]} | coding | 550 |
Solve the programming task below in a Python markdown code block.
As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.
Snuke, an employee, would like to play with this sequence.
Specifically, he would like to repeat the fo... | {"inputs": ["3\n5 2 8", "3\n5 3 8", "3\n5 2 7", "3\n3 3 8", "3\n5 2 4", "3\n5 2 4\n", "3\n3 3 11", "3\n3 5 11"], "outputs": ["4\n", "3\n", "1\n", "3\n", "3", "3\n", "0\n", "0\n"]} | coding | 436 |
Solve the programming task below in a Python markdown code block.
You are given two integer arrays a and b of length n.
You can reverse at most one subarray (continuous subsegment) of the array a.
Your task is to reverse such a subarray that the sum β_{i=1}^n a_i β
b_i is maximized.
Input
The first line contains o... | {"inputs": ["1\n1\n1\n", "1\n2\n1\n", "1\n2\n0\n", "2\n13 37\n0 4\n", "2\n13 71\n0 4\n", "2\n13 37\n2 4\n", "3\n0 2 5\n5 45 22\n", "3\n0 2 5\n5 69 22\n"], "outputs": ["1\n", "2\n", "0\n", "148\n", "284\n", "\n174\n", "269\n", "389\n"]} | coding | 476 |
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots, a_n$. You can perform the following operation any number of times: Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair). Replace them by one element with value $... | {"inputs": ["1\n1000\n", "1\n1000\n", "3\n1 3 5\n", "3\n2 3 5\n", "3\n2 3 1\n", "3\n1 3 5\n", "5\n4 3 2 2 3\n", "5\n4 3 2 3 3\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "2\n", "4\n"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
Cheesy Cheeseman just got a new monitor! He is happy with it, but he just discovered that his old desktop wallpaper no longer fits. He wants to find a new wallpaper, but does not know which size wallpaper he should be looking for, and alas, he just threw... | {"functional": "_inputs = [[1024, '4:3'], [1280, '16:9'], [3840, '32:9'], [1600, '4:3'], [1280, '5:4'], [2160, '3:2'], [1920, '16:9'], [5120, '32:9']]\n_outputs = [['1024x768'], ['1280x720'], ['3840x1080'], ['1600x1200'], ['1280x1024'], ['2160x1440'], ['1920x1080'], ['5120x1440']]\nimport math\ndef _deep_eq(a, b, tol=1... | coding | 167 |
Solve the programming task below in a Python markdown code block.
You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$.
You want to find a subset of items to put such that:
* The total value of the items is as large as possible.
* The items have com... | {"inputs": ["2 100\n1 1 100\n2 1 50", "4 8\n4 3 2\n2 1 1\n1 2 4\n2 2 2", "4 8\n4 3 2\n2 1 1\n1 2 1\n3 2 2", "4 8\n4 3 2\n0 1 1\n1 2 4\n2 3 2", "4 8\n4 3 2\n2 2 1\n1 2 4\n3 2 3", "4 8\n6 3 2\n2 3 1\n1 2 4\n3 2 3", "4 8\n8 3 2\n2 1 1\n1 2 4\n3 2 2", "4 8\n0 3 2\n0 1 1\n1 2 4\n2 3 1"], "outputs": ["150", "10\n", "12\n", "... | coding | 472 |
Solve the programming task below in a Python markdown code block.
There are $N$ villages numbered $1$ to $N$. The villages are connected through bi-directional paths in between them. The whole network is in the form of a tree.
Each village has only $1$ fighter but they help each other in times of crisis by sending the... | {"inputs": ["2\n5\n1 2\n1 3\n2 4\n3 5\n3\n1 2\n2 3"], "outputs": ["1 2\n2 1"]} | coding | 523 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes problems on geometry a lot. Please help him to solve one such problem.
Find all possible triangles with integer sides which has the radius of inscribed circle (al... | {"inputs": ["2"], "outputs": ["5\n5 12 13\n6 8 10\n6 25 29\n7 15 20\n9 10 17"]} | coding | 393 |
Solve the programming task below in a Python markdown code block.
# Task
Christmas is coming. In the [previous kata](https://www.codewars.com/kata/5a405ba4e1ce0e1d7800012e), we build a custom Christmas tree with the specified characters and the specified height.
Now, we are interested in the center of the Christmas t... | {"functional": "_inputs = [[''], ['a'], ['ab'], ['abc'], ['abab'], ['abcde'], ['aaaaaaaaaaaaaa'], ['abaabaaab'], ['dbdbebedbddbedededeeddbbdeddbeddeebdeddeebbbb'], ['vttussvutvuvvtustsvsvtvu']]\n_outputs = [[''], ['a'], ['a'], ['aba'], ['a'], ['aecea'], ['a'], ['aba'], ['deededebddeebeddeddeddbddeddeddebeeddbededeed'],... | coding | 593 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The ith recipe has the name recipes[i], and you can create it if you have all the needed ingredie... | {"functional": "def check(candidate):\n assert candidate(recipes = [\"bread\"], ingredients = [[\"yeast\",\"flour\"]], supplies = [\"yeast\",\"flour\",\"corn\"]) == [\"bread\"]\n assert candidate(recipes = [\"bread\",\"sandwich\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"]], supplies = [\"yeast\",... | coding | 198 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
There are n chocolates, and you are given an array of n numbers where the i-th number A_{i} is the flavour type of the i-th chocolate. Sebrina wants to eat as many differe... | {"inputs": ["3\n2 1\n1 2\n4 2\n1 1 1 1\n5 3\n50 50 50 100 100"], "outputs": ["1\n1\n2"]} | coding | 553 |
Solve the programming task below in a Python markdown code block.
Hands that shed innocent blood!
There are n guilty people in a line, the i-th of them holds a claw with length L_{i}. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person ... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n", "2\n0 0\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]} | coding | 291 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a numeric string num, representing a very large palindrome.
Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty str... | {"functional": "def check(candidate):\n assert candidate(num = \"1221\") == \"2112\"\n assert candidate(num = \"32123\") == \"\"\n assert candidate(num = \"45544554\") == \"54455445\"\n\n\ncheck(Solution().nextPalindrome)"} | coding | 103 |
Solve the programming task below in a Python markdown code block.
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting ... | {"inputs": ["1\n0\n1\n1 1 1\n", "1\n0\n1\n1 1 1\n", "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "5\n00010\n5\n5 3 1\n2 1 2\n4 1 1\n3 1 3\n2 1 3\n", "5\n11010\n5\n2 1 4\n3 5 1\n4 2 1\n4 5 1\n2 4 2\n"], "outputs": ["Ye... | coding | 714 |
Solve the programming task below in a Python markdown code block.
There are $n$ benches in the Berland Central park. It is known that $a_i$ people are currently sitting on the $i$-th bench. Another $m$ people are coming to the park and each of them is going to have a seat on some bench out of $n$ available.
Let $k$ be... | {"inputs": ["1\n10\n5\n", "1\n10\n2\n", "1\n10\n5\n", "2\n1\n5\n1\n", "2\n1\n5\n1\n", "2\n2\n5\n1\n", "2\n1\n10\n1\n", "2\n1\n10\n1\n"], "outputs": ["15 15\n", "12 12\n", "15 15\n", "5 6\n", "5 6\n", "5 7\n", "10 11\n", "10 11\n"]} | coding | 494 |
Solve the programming task below in a Python markdown code block.
There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services me... | {"inputs": ["4\n1 2 3 4\n2\n2 3\n2 2\n", "4\n1 2 3 4\n2\n2 1\n2 2\n", "4\n1 2 3 0\n2\n2 3\n2 2\n", "4\n0 3 3 4\n2\n2 1\n2 2\n", "4\n1 0 2 4\n2\n2 1\n2 2\n", "4\n1 0 3 0\n2\n2 0\n2 2\n", "4\n1 0 2 5\n2\n2 1\n2 2\n", "4\n1 0 2 2\n2\n2 1\n2 2\n"], "outputs": ["3 3 3 4 ", "2 2 3 4\n", "3 3 3 3\n", "2 3 3 4\n", "2 2 2 4\n",... | coding | 618 |
Solve the programming task below in a Python markdown code block.
You'll be given an array A of N integers as input. For each element of the array A[i], print A[i]-1.
Input:
There will be N+1 iines of input each consisting of a single integer.
Integer in first line denotes N
For the following N lines the integer in i... | {"inputs": ["9\n1\n2\n3\n4\n5\n6\n7\n8\n9"], "outputs": ["0\n1\n2\n3\n4\n5\n6\n7\n8"]} | coding | 145 |
Solve the programming task below in a Python markdown code block.
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he... | {"inputs": ["1\n1\n", "2\n1 2\n", "2\n2 1\n", "3\n3 2 1\n", "3\n1 2 3\n", "3\n3 1 2\n", "3\n1 3 2\n", "3\n2 3 1\n"], "outputs": ["0", "0", "1", "2", "0", "1", "1", "1"]} | coding | 276 |
Solve the programming task below in a Python markdown code block.
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.
Some examples of beautiful numbers: ... | {"inputs": ["3\n", "1\n", "6\n", "9\n", "2\n", "5\n", "1\n", "5\n"], "outputs": ["1\n", "1\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 268 |
Solve the programming task below in a Python markdown code block.
A first-year student, came to your college. Being a good senior, you must tell him if it is possible to go from College Main Gate to Hostel for him.
The college can be visualized on a 2D-plane. Suppose the College Main Gate is situated at origin i.e. at... | {"inputs": ["4\n1 2 1\n3 -5 2\n-9 -6 3\n-18 12 5\n"], "outputs": ["YES\nNO\nYES\nNO"]} | coding | 622 |
Solve the programming task below in a Python markdown code block.
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that rem... | {"inputs": ["0\n", "1\n", "0\n", "1\n", "100\n", "000\n", "000\n", "101\n"], "outputs": ["no", "no", "no\n", "no\n", "no", "no", "no\n", "no\n"]} | coding | 228 |
Solve the programming task below in a Python markdown code block.
Timur has a stairway with $n$ steps. The $i$-th step is $a_i$ meters higher than its predecessor. The first step is $a_1$ meters higher than the ground, and the ground starts at $0$ meters.
The stairs for the first test case.
Timur has $q$ questions, e... | {"inputs": ["3\n4 5\n1 2 1 5\n1 2 4 9 10\n2 2\n1 1\n0 1\n3 1\n1000000000 1000000000 1000000000\n1000000000\n", "11\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n1 1\n666\n666\n"], "outputs": ["1 4 4 9 9 \n0 2 \n3000... | coding | 734 |
Solve the programming task below in a Python markdown code block.
You are given an array A of size N. In one operation, you can do the following:
Select indices i and j (i\neq j) and set A_{i} = A_{j}.
Find the minimum number of operations required to make all elements of the array equal.
------ Input Format ------... | {"inputs": ["3\n3\n1 2 3\n4\n2 2 3 1\n4\n3 1 2 4\n"], "outputs": ["2\n2\n3\n"]} | coding | 634 |
Solve the programming task below in a Python markdown code block.
We have an integer sequence A, whose length is N.
Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the... | {"inputs": ["5\n0 0 2 0 8", "5\n0 0 3 0 8", "5\n0 0 3 1 8", "5\n1 0 6 -2 5", "5\n1 0 8 -2 5", "5\n2 0 8 -2 5", "5\n2 0 8 -2 9", "5\n2 0 2 -2 5"], "outputs": ["4\n", "4\n", "3\n", "1\n", "1\n", "1\n", "1\n", "3\n"]} | coding | 241 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$.
Your task is to reorder... | {"inputs": ["1\n5\n3 1 2 4 5\n2 4 5 1 3"], "outputs": ["3 1 2 4 5"]} | coding | 557 |
Solve the programming task below in a Python markdown code block.
For two permutations p and q of the integers from 1 through N, let f(p,q) be the permutation that satisfies the following:
* The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.
You... | {"inputs": ["3 1\n1 2 3\n3 2 1", "3 6\n1 2 3\n3 2 1", "3 9\n2 1 3\n3 2 1", "3 4\n1 2 3\n3 2 1", "3 2\n1 2 3\n3 2 1", "3 9\n1 2 3\n3 2 1", "3 8\n1 2 3\n3 2 1", "3 7\n1 2 3\n3 2 1"], "outputs": ["1 2 3", "3 2 1", "2 3 1", "1 2 3", "3 2 1", "3 2 1", "3 2 1", "1 2 3"]} | coding | 433 |
Solve the programming task below in a Python markdown code block.
The country of Berland initially has N isolated cities, the i-th city has a significance of A_{i}. The President of Berland wants to connect all the cities. He can construct a bidirectional road of length L (L > 0) from city X to city Y if (A_{X} \& A_{Y... | {"inputs": ["2\n4\n4 4 4 4\n3\n2 4 6"], "outputs": ["12\n6\n"]} | coding | 721 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white.
You are also given an integer carpetLen, the length of a single carpet that ca... | {"functional": "def check(candidate):\n assert candidate(tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10) == 9\n assert candidate(tiles = [[10,11],[1,1]], carpetLen = 2) == 2\n\n\ncheck(Solution().maximumWhiteTiles)"} | coding | 128 |
Solve the programming task below in a Python markdown code block.
In mathematics, a matrix (plural matrices) is a rectangular array of numbers. Matrices have many applications in programming, from performing transformations in 2D space to machine learning.
One of the most useful operations to perform on matrices is m... | {"functional": "_inputs = [[[[2, -2], [5, 3]], [[-1, 4], [7, -6]]], [[[1]], [[3]]], [[[1, 2], [3, 4]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[7, 3], [2, 5], [6, 8], [9, 0]], [[7, 4, 9], [8, 1, 5]]], [[[1, 0.5], [-0.5, 1]], [[5, 0.25], [2, 0.5]]]]\n_outputs = [[[[-16, 20], [16, 2]]], [[[3]]], [-1], [[[73, 31, 78], [54, ... | coding | 405 |
Solve the programming task below in a Python markdown code block.
AquaMoon has a string $a$ consisting of only $0$ and $1$. She wants to add $+$ and $-$ between all pairs of consecutive positions to make the absolute value of the resulting expression as small as possible. Can you help her?
-----Input-----
The first ... | {"inputs": ["3\n2\n11\n5\n01101\n5\n10001\n"], "outputs": ["-\n+-++\n+++-\n"]} | coding | 367 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:
Every element less than pivot appears before every element greater than pivot.
Every... | {"functional": "def check(candidate):\n assert candidate(nums = [9,12,5,10,14,3,10], pivot = 10) == [9,5,3,10,10,12,14]\n assert candidate(nums = [-3,4,3,2], pivot = 2) == [-3,2,4,3]\n\n\ncheck(Solution().pivotArray)"} | coding | 223 |
Solve the programming task below in a Python markdown code block.
Check Tutorial tab to know how to solve.
Task
Given an integer, $n$, perform the following conditional actions:
If $n$ is odd, print Weird
If $n$ is even and in the inclusive range of $2$ to $5$, print Not Weird
If $n$ is even and in the inclusive ... | {"inputs": ["3\n", "24\n"], "outputs": ["Weird\n", "Not Weird\n"]} | coding | 252 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.
Β
Please complete the following python code precisely:
```python
class So... | {"functional": "def check(candidate):\n assert candidate(height = [0,1,0,2,1,0,1,3,2,1,2,1]) == 6\n assert candidate(height = [4,2,0,3,2,5]) == 9\n\n\ncheck(Solution().trap)"} | coding | 76 |
Solve the programming task below in a Python markdown code block.
Consider a sequence made up of the consecutive prime numbers. This infinite sequence would start with:
```python
"2357111317192329313741434753596167717379..."
```
You will be given two numbers: `a` and `b`, and your task will be to return `b` elements ... | {"functional": "_inputs = [[2, 2], [10, 5], [10, 3], [20, 9], [30, 12], [40, 8], [50, 6], [10000, 5], [20000, 5]]\n_outputs = [['57'], ['19232'], ['192'], ['414347535'], ['616771737983'], ['83899710'], ['031071'], ['02192'], ['09334']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstan... | coding | 235 |
Solve the programming task below in a Python markdown code block.
We have N+1 integers: 10^{100}, 10^{100}+1, ..., 10^{100}+N.
We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7).
-----Constraints-----
- 1 \leq N \leq 2\times 10^5
- 1 \leq ... | {"inputs": ["3 1", "1 1", "3 4", "6 1", "2 1", "6 2", "4 3", "4 1"], "outputs": ["14\n", "3\n", "1\n", "63\n", "7\n", "56\n", "13\n", "25\n"]} | coding | 620 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.