task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively.
He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to th... | {"inputs": ["1\n1\n1\n2\n", "1\n1\n1\n2\n", "1\n2\n1\n2\n", "1\n2\n1\n0\n", "1\n5\n2\n3 2\n", "2\n1 1\n1\n1\n", "1\n5\n2\n5 5\n", "1\n2\n2\n2 3\n"], "outputs": ["-1\n", "-1\n", "1\n", "-1\n", "1\n", "-1\n", "-1\n", "-1\n"]} | 573 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Given two integers $n$ and $\textbf{r}$. In how many ways can $\textbf{r}$ items be chosen from $n$ items?
Input Format
The first line contains the number of test cases $\mathbf{T}$. Each of the next $\mathbf{T}$ lines contains two integers $n$ and $\t... | {"inputs": ["4\n2 1\n4 0\n5 2\n10 3\n"], "outputs": ["2\n1\n10\n120\n"]} | 201 | 40 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and some number of black pawns 'p'. Empty squares are represented by '.'.
... | {"functional": "def check(candidate):\n assert candidate([[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"R\",\".\",\".\",\".\",\"p\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"... | 206 | 589 |
coding | Solve the programming task below in a Python markdown code block.
Elon Musk has succesfully built an automated staircase from Earth to Mars. Many people want to go to Mars, but that's not possible due to limited capacity of the staircase and logistics involved. Hence, Elon asks interested candidates to solve a tough ch... | {"inputs": ["2\n10 2 \n12 1\n"], "outputs": ["63\n10\n"]} | 383 | 29 |
coding | Solve the programming task below in a Python markdown code block.
There are N integers written on a blackboard. The i-th integer is A_i.
Takahashi will repeatedly perform the following operation on these numbers:
* Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are o... | {"inputs": ["3\n2 2 3", "3\n2 2 6", "3\n2 2 7", "3\n1 2 7", "3\n1 0 7", "3\n1 2 3", "3\n1 0 13", "3\n1 0 19"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES", "YES\n", "YES\n"]} | 243 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.
Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k ... | {"inputs": ["1 1\n2\n0\n", "1 1\n2\n0\n", "1 1\n2\n1\n", "4 4\n1122\n2\n", "4 4\n1122\n2\n", "4 4\n1049\n2\n", "4 4\n1384\n2\n", "4 4\n2661\n2\n"], "outputs": ["4\n", "4\n", "5\n", "8\n", "8\n", "9\n", "7\n", "3\n"]} | 656 | 133 |
coding | Solve the programming task below in a Python markdown code block.
# How much is the fish! (- Scooter )
The ocean is full of colorful fishes. We as programmers want to know the hexadecimal value of these fishes.
## Task
Take all hexadecimal valid characters (a,b,c,d,e,f) of the given name and XOR them. Return the resul... | {"functional": "_inputs = [['pufferfish'], ['puffers'], ['balloonfish'], ['blowfish'], ['bubblefish'], ['globefish'], ['swellfish'], ['toadfish'], ['toadies'], ['honey toads'], ['sugar toads'], ['sea squab'], [''], ['Aeneus corydoras'], ['African glass catfish'], ['African lungfish'], ['Aholehole'], ['Airbreathing catf... | 145 | 485 |
coding | Solve the programming task below in a Python markdown code block.
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders what town he w... | {"inputs": ["4 9\n3 2 4 1", "4 0\n3 2 4 1", "4 0\n3 2 1 1", "4 0\n3 0 4 1", "4 0\n3 1 4 1", "4 5\n3 2 4 1", "4 5\n3 2 4 1\n", "4 16\n3 2 4 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "4", "4\n", "3\n"]} | 296 | 143 |
coding | Solve the programming task below in a Python markdown code block.
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.
Suppose you decided to sell packs with $a$ cans in a pack with a discount and some cu... | {"inputs": ["3\n3 4\n1 2\n120 150\n", "3\n3 4\n1 2\n120 150\n", "1\n000000101 821042\n", "1\n000000101 321987\n", "1\n000001101 321987\n", "1\n10485760 20971520\n", "1\n20971520 41943040\n", "1\n10485760 20971520\n"], "outputs": ["YES\nNO\nYES\n", "YES\nNO\nYES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 612 | 215 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an input string s, reverse the order of the words.
A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.
Return a string of the words in reverse order c... | {"functional": "def check(candidate):\n assert candidate(s = \"the sky is blue\") == \"blue is sky the\"\n assert candidate(s = \" \u00a0hello world \u00a0\") == \"world hello\"\n assert candidate(s = \"a good \u00a0 example\") == \"example good a\"\n\n\ncheck(Solution().reverseWords)"} | 136 | 88 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of length n where s[i] is either:
'D' means decreasing, or
'I' means increasing.
A permutation perm of n + 1 integers of all the integers in the range [0, n] is called a valid permutation if... | {"functional": "def check(candidate):\n assert candidate(s = \"DID\") == 5\n\n\ncheck(Solution().numPermsDISequence)"} | 176 | 35 |
coding | Solve the programming task below in a Python markdown code block.
Watson gives Sherlock an array $\mbox{A}$ of $N$ elements and two arrays $\mbox{B}$ and $\mbox{C}$, of $\mbox{M}$ elements each. Then he asks Sherlock to perform the following program:
for i = 1 to M do
for j = 1 to N do
if j % B[i] == 0 the... | {"inputs": ["4 3\n1 2 3 4\n1 2 3\n13 29 71\n"], "outputs": ["13 754 2769 1508\n"]} | 369 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game on a binary string S of length N.
Alice and Bob alternate turns, with Alice going first. On their turn, the current player must choose any index 1 ≤ i < |S| such that S_{i} \neq S_{i+1} and erase either S_{i} or S_{i+1} ... | {"inputs": ["3\n4\n1111\n3\n110\n4\n1010\n"], "outputs": ["Bob\nAlice\nBob"]} | 466 | 37 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
English description is not available for the problem. Please switch to Chinese.
Please complete the following python code precisely:
```python
class Solution:
def fraction(self, cont: List[int]) -> List[int]:
... | {"functional": "def check(candidate):\n assert candidate(cont = [3, 2, 0, 2]) == [13, 4]\n assert candidate(cont = [0, 0, 3]) == [3, 1]\n\n\ncheck(Solution().fraction)"} | 63 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals di... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4], difference = 1) == 4\n assert candidate(arr = [1,3,5,7], difference = 1) == 1\n assert candidate(arr = [1,5,7,8,5,3,4,2,1], difference = -2) == 4\n\n\ncheck(Solution().longestSubsequence)"} | 119 | 100 |
coding | Solve the programming task below in a Python markdown code block.
Janmansh has to submit 3 assignments for Chingari before 10 pm and he starts to do the assignments at X pm. Each assignment takes him 1 hour to complete. Can you tell whether he'll be able to complete all assignments on time or not?
------ Input Format ... | {"inputs": ["2\n7\n9\n"], "outputs": ["Yes\nNo\n"]} | 278 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Create an OR function, without use of the 'or' keyword, that takes an list of boolean values and runs OR against all of them.
Assume there will be between 1 and 6 variables, and return None for an empty list.
Also feel free to reuse/extend the following... | {"functional": "_inputs = [[[]], [[False, False, False, False, False, False]], [[False, False, False, False, False, True]], [[False, False, False, False, True, False]], [[False, False, False, False, True, True]], [[False, False, False, True, False, False]], [[False, False, False, True, False, True]], [[False, False, Fa... | 84 | 1,943 |
coding | Solve the programming task below in a Python markdown code block.
In Byteland they have a very strange monetary system.
Each Bytelandian gold coin has an integer number written on it. A coin n
can be exchanged in a bank into three coins: n/2, n/3 and n/4.
But these numbers are all rounded down (the banks have to make ... | {"inputs": ["12\n1", "12\n0", "12\n3", "12\n4", "12\n5", "12\n7", "12\n9", "12\n6"], "outputs": ["13\n1\n", "13\n0\n", "13\n3\n", "13\n4\n", "13\n5\n", "13\n7\n", "13\n9\n", "13\n6\n"]} | 350 | 110 |
coding | Solve the programming task below in a Python markdown code block.
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coin... | {"inputs": ["12 1 5", "17 1 5", "17 2 5", "57 7 14", "57 1 14", "27 1 14", "12 1 14", "64 17 92"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "No\n"]} | 219 | 108 |
coding | Solve the programming task below in a Python markdown code block.
During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed.
The collection of porcelain is arranged neatly on n shelves. Within each shelf the items are placed in one row, so th... | {"inputs": ["1 1\n1 100\n", "1 3\n4 4 5 1 2\n", "1 3\n4 4 5 0 2\n", "1 3\n4 4 3 1 2\n", "3 2\n1 10\n1 2\n1 5\n", "3 2\n1 13\n1 2\n1 5\n", "3 2\n1 14\n1 2\n1 5\n", "3 2\n1 13\n1 2\n1 10\n"], "outputs": ["100\n", "11\n", "11\n", "9\n", "15\n", "18\n", "19\n", "23\n"]} | 448 | 183 |
coding | Solve the programming task below in a Python markdown code block.
Rushitote went to a programming contest to distribute apples and oranges to the contestants.
He has N apples and M oranges, which need to be divided equally amongst the contestants. Find the maximum possible number of contestants such that:
Every cont... | {"inputs": ["3\n1 5\n2 4\n4 6"], "outputs": ["1\n2\n2"]} | 396 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on.
During their move, the player can choose any number (not less than one) of... | {"inputs": ["5\n01111001\n0000\n111111\n101010101\n011011110111\n", "5\n01111101\n0000\n111111\n101010101\n011011110111\n", "5\n01111101\n0000\n111111\n101010101\n011001110111\n", "5\n01111101\n0000\n111111\n101010101\n011001111111\n", "5\n11111101\n0000\n111111\n101010101\n011001111111\n", "5\n11111101\n0000\n111111\n... | 512 | 486 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:
Choosing any x with 0 < x < n and n... | {"functional": "def check(candidate):\n assert candidate(n = 2) == True\n assert candidate(n = 3) == False\n\n\ncheck(Solution().divisorGame)"} | 151 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Chef played an interesting game yesterday. This game is played with two variables $X$ and $Y$; initially, $X = Y = 0$. Chef may make an arbitrary number of moves (including zero). In each move, he must perform the following process:
- Choose any positive... | {"inputs": ["3\n3\n8\n9"], "outputs": ["3\n5\n6"]} | 342 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Consider the array $a$ composed of all the integers in the range $[l, r]$. For example, if $l = 3$ and $r = 7$, then $a = [3, 4, 5, 6, 7]$.
Given $l$, $r$, and $k$, is it possible for $\gcd(a)$ to be greater than $1$ after doing the following operation ... | {"inputs": ["1\n1 1000000000 999999999\n", "9\n1 1 0\n3 5 1\n13 13 0\n4 4 0\n3 7 4\n4 10 3\n2 4 0\n1 7 3\n1 5 3\n"], "outputs": ["YES\n", "NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\n"]} | 587 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:
Every adjacent pair of words differs by a single letter.
... | {"functional": "def check(candidate):\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]) == 5\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]) == 0\n\n\ncheck(Solution().ladderLeng... | 180 | 95 |
coding | Solve the programming task below in a Python markdown code block.
You probably know the 42 number as "The answer to life, the universe and everything" according to Douglas Adams' "The Hitchhiker's Guide to the Galaxy". For Freud, the answer was quite different.
In the society he lived in, people-women in particular- h... | {"functional": "_inputs = [['test'], ['sexy sex'], ['This is a test'], ['This is a longer test'], [\"You're becoming a true freudian expert\"]]\n_outputs = [['sex'], ['sex sex'], ['sex sex sex sex'], ['sex sex sex sex sex'], ['sex sex sex sex sex sex']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, ... | 254 | 209 |
coding | Solve the programming task below in a Python markdown code block.
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only ge... | {"inputs": ["5\n5 4 3 2 1 2 3 4 5\n", "0\n1 1 1 1 1 1 1 1 1\n", "5\n5 4 3 2 1 4 3 4 5\n", "0\n1 1 1 1 1 1 1 1 1\n", "5\n5 4 3 2 1 2 3 4 5\n", "50\n5 3 10 2 2 4 3 6 5\n", "50\n5 3 10 2 2 4 3 6 5\n", "50\n5 3 10 2 2 5 3 6 5\n"], "outputs": ["55555\n", "-1\n", "55555\n", "-1\n", "55555\n", "5555555555555555555555555\n", "... | 311 | 304 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you wa... | {"functional": "def check(candidate):\n assert candidate(numCourses = 2, prerequisites = [[1,0]]) == True\n assert candidate(numCourses = 2, prerequisites = [[1,0],[0,1]]) == False\n\n\ncheck(Solution().canFinish)"} | 151 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?
Each... | {"inputs": ["8 5\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n"], "outputs": ["2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 511 | 86 |
coding | Solve the programming task below in a Python markdown code block.
It's John's birthday; he has brought some candies in distribute among N of his friends. Being a good friend, he decided to distribute all of his candies equally among his friend and he don't want to keep any for himself. He left the task of distributing ... | {"inputs": ["3\n4\n7 8 6 4\n6\n7 3 10 2 3 8\n1\n10"], "outputs": ["4\n10\n0"]} | 465 | 47 |
coding | Solve the programming task below in a Python markdown code block.
Chef's current rating is X, and he wants to improve it. It is generally recommended that a person with rating X should solve problems whose difficulty lies in the range [X, X+200], i.e, problems whose difficulty is at least X and at most X+200.
You find... | {"inputs": ["5\n1300 1500\n1201 1402\n300 4000\n723 805\n1330 512\n"], "outputs": ["YES\nNO\nNO\nYES\nNO\n"]} | 667 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon.
Alice wants the rope to be colorful. She does not want two consecutive balloons to be o... | {"functional": "def check(candidate):\n assert candidate(colors = \"abaac\", neededTime = [1,2,3,4,5]) == 3\n assert candidate(colors = \"abc\", neededTime = [1,2,3]) == 0\n assert candidate(colors = \"aabaa\", neededTime = [1,2,3,4,1]) == 2\n\n\ncheck(Solution().minCost)"} | 174 | 95 |
coding | Solve the programming task below in a Python markdown code block.
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the ... | {"inputs": ["1 1\n1 1\n", "2 1\n2 2\n", "9 1\n1 1\n", "1 1\n1 1\n", "2 1\n2 2\n", "9 1\n1 1\n", "2 1\n2 3\n", "4 2\n1 4\n2 4\n"], "outputs": ["1\n0\n", "1\n0 0\n", "1\n0 0 0 0 0 0 0 0 0\n", "1\n0 ", "1\n0 0 ", "1\n0 0 0 0 0 0 0 0 0 ", "2\n0 1\n", "3\n0 1 2 0\n"]} | 541 | 179 |
coding | Solve the programming task below in a Python markdown code block.
# Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an *array/list [] of integers* , **_Find_** **_The maximum difference_** ... | {"functional": "_inputs = [[[13, 10, 2, 9, 5]], [[13, 3, 5]], [[24, 299, 131, 14, 26, 25]], [[-3, -27, -4, -2]], [[-7, -42, -809, -14, -12]], [[12, -5, -7, 0, 290]], [[-54, 37, 0, 64, -15, 640, 0]], [[130, 30, 50]], [[1, 1, 1]], [[-1, -1, -1]]]\n_outputs = [[4], [8], [168], [23], [767], [278], [576], [80], [0], [0]]\ni... | 657 | 354 |
coding | Solve the programming task below in a Python markdown code block.
Consider the following game:
There are two players, First and Second, sitting in front of a pile of $n$ stones. First always plays first.
There is a set, $\mbox{S}$, of $m$ distinct integers defined as $S=\{s_0,s_1,\ldots,s_{m-1}\}$.
The players move in... | {"inputs": ["15 3\n5 2 3\n"], "outputs": ["Second\n"]} | 471 | 23 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing the game of Nim with $n$ piles of stones with sizes $p_0,p_1,\ldots,p_{n-1}$. If Alice plays first, she loses if and only if the 'xor sum' (or 'Nim sum') of the piles is zero, i.e., $p_0\oplus p_1\oplus...\oplus p_{n-1}=0$.
Sin... | {"inputs": ["3\n1 2 3\n", "10\n10 10 1 1 1 1 1 10 10 10\n"], "outputs": ["4\n", "321616\n"]} | 467 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Given is an undirected graph G consisting of N vertices numbered 1 through N and M edges numbered 1 through M.
Edge i connects Vertex a_i and Vertex b_i bidirectionally.
G is said to be a good graph when both of the conditions below are satisfied. It is ... | {"inputs": ["1\n100000 0\n", "3\n3 0\n6 2\n1 2\n2 3\n15 10\n12 14\n8 3\n10 1\n14 6\n12 6\n1 9\n13 1\n2 5\n3 9\n7 2\n"], "outputs": ["First\n", "First\nSecond\nFirst\n"]} | 609 | 103 |
coding | Solve the programming task below in a Python markdown code block.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characte... | {"inputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "20\n", "10\n", "12\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "20\n", "01\n", "12\n"]} | 495 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his pro... | {"inputs": ["2\n-3 0 000 29\n-2 -100 18 100\n0\n-100 -20 -13 -280\n20 100 100 2\n0", "2\n-3 1 100 34\n-5 -100 18 100\n0\n-100 -20 -13 -284\n20 100 100 3\n0", "2\n-100 0 100 43\n-20 -100 18 100\n0\n-100 -4 -9 -284\n20 100 100 3\n0", "2\n-100 0 101 43\n-20 -100 18 100\n0\n-100 -4 -9 -284\n20 100 100 3\n0", "2\n-100 0 101... | 585 | 533 |
coding | Solve the programming task below in a Python markdown code block.
Some country is populated by wizards. They want to organize a demonstration.
There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't... | {"inputs": ["1 1 1\n", "1 0 1\n", "3 1 69\n", "67 1 3\n", "2 1 69\n", "67 2 6\n", "67 2 9\n", "67 2 3\n"], "outputs": ["0\n", "1\n", "2\n", "2\n", "1\n", "3\n", "5\n", "1\n"]} | 505 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. Chef wants you to handle $Q$ queries. There are two types of queries:
1 L R X: for each $i$ ($L ≤ i ≤ R$), add $(... | {"inputs": ["5 4\n1 10 3 6 5\n1 1 3 5\n2 3\n1 4 5 7\n2 5"], "outputs": ["52\n69"]} | 527 | 53 |
coding | Solve the programming task below in a Python markdown code block.
Chef has two integers A and B (A ≤ B).
Chef can choose any non-negative integer X and add them to both A and B. Find whether it is possible to make A a [divisor] of B.
------ Input Format ------
- The first line of input will contain a single intege... | {"inputs": ["3\n3 6\n4 14\n9 10\n"], "outputs": ["YES\nYES\nNO\n"]} | 346 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatu... | {"inputs": ["2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "2\n8 2\n", "2\n4 2\n", "2\n16 2\n", "3\n2 5 8\n", "3\n2 4 8\n"], "outputs": ["3\n", "3", "2\n", "-4\n", "0\n", "-12\n", "11\n", "8\n"]} | 610 | 108 |
coding | Solve the programming task below in a Python markdown code block.
There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the second one i... | {"inputs": ["1 6\n2\n", "1 6\n7\n", "1 6\n3\n", "1 6\n4\n", "1 7\n2\n", "1 6\n2\n", "1 6\n7\n", "1 24\n10\n"], "outputs": ["11\n", "14\n", "11\n", "14\n", "14\n", " 11\n", " 14\n", "161\n"]} | 553 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has 3 bags that she wants to take on a flight. They weigh A, B, and C kgs respectively. She wants to check-in exactly two of these bags and carry the rem... | {"inputs": ["3\n1 1 1 15 5\n8 7 6 15 5\n8 5 7 15 6"], "outputs": ["YES\nNO\nYES"]} | 505 | 49 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Chef wants to prepare a Cook-Off contest with 5 problems chosen from a set of N problems. He has marked the difficulty of each problem within a range identified by one of th... | {"inputs": ["3\n5\neasy\nmedium\nmedium-hard\nsimple\ncakewalk\n7\nsimple\nsimple\nmedium\nmedium\neasy-medium\ncakewalk\neasy\n7\ncakewalk\nsimple\neasy\neasy-medium\nmedium\nmedium-hard\nhard"], "outputs": ["Yes\nNo\nYes"]} | 576 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,3,1],[1,5,1],[4,2,1]]) == 7\n assert candidate(grid = [[1,2,3],[4,5,6]]) == 12\n\n\ncheck(Solution().minPathSum)"} | 100 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
"It's totally fun to play troublemakers ― totally." - Lee Pace
Sakshi had a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbere... | {"inputs": ["1\n2 2 3\n1 1\n1 2\n2 1"], "outputs": ["2"]} | 749 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.
You should assign labels to all vertices in such a way that:
Labels form a valid pe... | {"inputs": ["2 1\n2 1\n", "2 1\n2 1\n", "3 3\n1 2\n1 3\n3 2\n", "3 3\n1 2\n1 3\n3 2\n", "5 4\n3 1\n2 1\n2 3\n4 5\n", "5 4\n3 1\n2 1\n2 5\n4 5\n", "5 4\n3 1\n2 1\n2 3\n4 5\n", "4 5\n3 1\n4 1\n2 3\n3 4\n2 4\n"], "outputs": ["2 1 \n", "2 1\n", "1 3 2 \n", "1 3 2\n", "3 1 2 4 5 \n", "3 1 2 4 5\n", "3 1 2 4 5\n", "4 1 2 3 \... | 333 | 232 |
coding | Solve the programming task below in a Python markdown code block.
A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: wi... | {"inputs": ["7\n", "5\n", "9\n", "8\n", "8\n", "2\n", "6\n", "4\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n"]} | 159 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.
Please complete the following python code precisely:
```python
class So... | {"functional": "def check(candidate):\n assert candidate(intervals = [[0,30],[5,10],[15,20]]) == 2\n assert candidate(intervals = [[7,10],[2,4]]) == 1\n\n\ncheck(Solution().minMeetingRooms)"} | 79 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Consider a linear function f(x) = Ax + B. Let's define g^{(0)}(x) = x and g^{(}n)(x) = f(g^{(}n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g^{(}n)(x) modulo 10^9 + 7.
-----Input-----
The only line contains four in... | {"inputs": ["3 4 1 1\n", "3 4 2 1\n", "3 4 3 1\n", "1 1 1 1\n", "1 1 1 1\n", "3 3 2 1\n", "3 5 2 1\n", "3 4 4 1\n"], "outputs": ["7\n", "25\n", "79\n", "2\n", "2\n", "21\n", "29\n", "241\n"]} | 272 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
Naveej is from a tribe that speaks some weird language - their alphabet consists of N distinct characters.
He has an array A = [A_{1}, A_{2}, \dots, A_{N}], where A_{i... | {"inputs": ["2\n1\n4\n3\n4 3 1\n"], "outputs": ["0\n1\n"]} | 679 | 28 |
coding | Solve the programming task below in a Python markdown code block.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size x_{i} × y_{i}. Each impression must be parallel to the sides of the... | {"inputs": ["2 2 2\n1 2\n2 1\n", "2 1 1\n1 1\n1 1\n", "2 1 2\n1 1\n1 1\n", "1 100 50\n4 20\n", "2 2 4\n3 1\n2 2\n", "2 2 4\n2 3\n2 1\n", "2 4 2\n1 2\n2 3\n", "2 1 4\n1 2\n1 2\n"], "outputs": ["4\n", "0\n", "2\n", "0\n", "0\n", "8\n", "8\n", "4\n"]} | 422 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Let's introduce some definitions that will be needed later.
Let $prime(x)$ be the set of prime divisors of $x$. For example, $prime(140) = \{ 2, 5, 7 \}$, $prime(169) = \{ 13 \}$.
Let $g(x, p)$ be the maximum possible integer $p^k$ where $k$ is an inte... | {"inputs": ["2 1\n", "2 1\n", "10 2\n", "16 2\n", "15 2\n", "10 2\n", "9 188\n", "9 188\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "954137859\n", "954137859\n"]} | 677 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string.
Return the lexicographically smallest string you could have after applying the mentione... | {"functional": "def check(candidate):\n assert candidate(s = \"cba\", k = 1) == \"acb\"\n assert candidate(s = \"baaca\", k = 3) == \"aaabc\"\n\n\ncheck(Solution().orderlyQueue)"} | 103 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Count the pairs of length-N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions:
- A_i \neq B_i, for every i such that 1\leq i\leq N.
- A_i \neq... | {"inputs": ["1 2", "2 6", "0 2", "2 4", "1 4", "3 4", "1 1", "1 6"], "outputs": ["2\n", "630\n", "1\n", "84\n", "12\n", "264\n", "0\n", "30\n"]} | 279 | 85 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.
Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Element... | {"functional": "def check(candidate):\n assert candidate(arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]) == [2,2,2,1,4,3,3,9,6,7,19]\n assert candidate(arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6]) == [22,28,8,6,17,44]\n\n\ncheck(Solution().relativeSortArray)"} | 131 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hangin... | {"inputs": ["3 1\nabc\naec\nbc\na?c\n", "3 1\nabc\naec\nbc\nac?\n", "3 1\nacb\naec\nbb\nac?\n", "3 1\nabc\naec\nbb\nac?\n", "1 1\nacb\naec\nbb\nac?\n", "1 1\nacb\naec\nbc\nac?\n", "1 1\nacb\naec\nbc\na?c\n", "3 1\nabc\naec\nac\nc?a\n"], "outputs": ["2\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 474 | 160 |
coding | Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got... | {"inputs": ["21000\nSWISS TO LAUNCH NEW SERIES OF MONEY MARKET PAPER\nZURICH, April 9 - The Swiss Federal Government will launch\na new series of three month money market certificates totalling\naround 150 mln Swiss francs, the National Bank said.\nSubscriptions close April 14 and payment date is April 16.\nThe last se... | 497 | 1,158 |
coding | Solve the programming task below in a Python markdown code block.
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you n... | {"inputs": ["2 100\n13 78\n", "4 1\n1 2 3 4\n", "4 1\n1 2 1 2\n", "4 4\n1 2 6 7\n", "4 1\n1 2 3 4\n", "4 4\n1 2 6 7\n", "4 1\n1 2 1 2\n", "2 100\n13 78\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n"]} | 581 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "4 1\n1 2 2 1\n", "4 2\n1 2 3 1\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 1\n", "4 1\n1 2 2 1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | 667 | 138 |
coding | Solve the programming task below in a Python markdown code block.
Chef Palin, as his name suggests, is always very interested in palindromic strings. Recently, he made a pretty interesting discovery on palindromes and that made him feel really Lucky. He came across something known as Lucky Palindromes. He defines a str... | {"inputs": ["3\nlaubcdkey\nluckycodechef\naaaaaaaa", "3\nlaubcdkey\nlubkycodechef\naaaaaaaa", "3\nlaubcdkey\nyubklcodechef\naaaaaaaa", "3\nlatbcdkfy\nfeicedocljbux\naaaaaaba", "3\nytkdadfbl\ntobjlcedechwf\naabaaaba", "3\nytkdadfbl\ntobjlcfdechwf\naabaaaba", "3\nytkdadlbf\ntobjlcfdechwf\naabaaaca", "3\nytjdadlbf\nfwmcee... | 351 | 331 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rooted tree consisting of $n$ vertices numbered from $1$ to $n$. The root is vertex $1$. There is also a string $s$ denoting the color of each vertex: if $s_i = {B}$, then vertex $i$ is black, and if $s_i = {W}$, then vertex $i$ is white.... | {"inputs": ["3\n7\n1 1 2 3 3 5\nWBBWWBW\n2\n1\nBW\n8\n1 2 3 4 5 6 7\nBWBWBWBW\n"], "outputs": ["2\n1\n4\n"]} | 729 | 65 |
coding | Solve the programming task below in a Python markdown code block.
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give a... | {"inputs": ["5\n", "9\n", "2\n", "1\n", "3\n", "4\n", "6\n", "7\n"], "outputs": ["2\n1 4 \n", "3\n1 2 6 \n", "1\n2 \n", "1\n1 \n", "2\n1 2 \n", "2\n1 3 \n", "3\n1 2 3 \n", "3\n1 2 4 \n"]} | 198 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Niwango has N cards, numbered 1,2,\ldots,N. He will now arrange these cards in a row.
Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answ... | {"inputs": ["2\n2 1", "4\n2 3 4 0", "4\n4 3 4 1", "4\n2 3 2 1", "4\n3 5 2 1", "4\n2 3 5 0", "4\n2 3 4 1", "13\n1 3 3 0 9 4 9 2 4 6 12 8 8"], "outputs": ["-1", "1 3 2 4\n", "1 2 4 3\n", "1 3 4 2\n", "1 2 3 4\n", "1 3 2 4\n", "1 3 2 4", "1 2 4 3 5 6 7 8 9 10 11 13 12\n"]} | 380 | 205 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums of size n and a positive integer k.
We call an index i in the range k <= i < n - k good if the following conditions are satisfied:
The k elements that are just before the ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,1,1,3,4,1], k = 2) == [2,3]\n assert candidate(nums = [2,1,1,2], k = 2) == []\n\n\ncheck(Solution().goodIndices)"} | 142 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Let's consider a rectangular table R consisting of N rows and M columns. Rows are enumerated from 1 to N from top to bottom. Columns are enumerated from 1 to M from left to right. Each element of R is a non-negative integer. R is called steady if the su... | {"inputs": ["3\n1 1\n2 2\n2 3"], "outputs": ["2\n25\n273"]} | 399 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He w... | {"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n2 3 1\n", "3\n1 2 3\n", "3\n1 3 2\n", "3\n2 1 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]} | 375 | 110 |
coding | Solve the programming task below in a Python markdown code block.
What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example:
```
'abba' & 'baab' == true
'abba' & 'bbaa' == true
'abba' & 'abbba' == false
'abba' & 'abca' == false
```
Write a function that will ... | {"functional": "_inputs = [['abba', ['aabb', 'abcd', 'bbaa', 'dada']], ['racer', ['crazer', 'carer', 'racar', 'caers', 'racer']], ['a', ['a', 'b', 'c', 'd']], ['ab', ['cc', 'ac', 'bc', 'cd', 'ab', 'ba', 'racar', 'caers', 'racer']], ['abba', ['a', 'b', 'c', 'd', 'aabb', 'bbaa', 'abab', 'baba', 'baab', 'abcd', 'abbba', '... | 257 | 371 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums of size n. You are asked to solve n queries for each integer i in the range 0 <= i < n.
To solve the ith query:
Find the minimum value in each possible subarray of size i + 1 of th... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,4]) == [4,2,1,0]\n assert candidate(nums = [10,20,50,10]) == [50,20,10,10]\n\n\ncheck(Solution().findMaximums)"} | 163 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.
Create the maximum number of length k <= m + n fr... | {"functional": "def check(candidate):\n assert candidate(nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5) == [9,8,6,5,3]\n assert candidate(nums1 = [6,7], nums2 = [6,0,4], k = 5) == [6,7,6,0,4]\n assert candidate(nums1 = [3,9], nums2 = [8,9], k = 3) == [9,8,9]\n\n\ncheck(Solution().maxNumber)"} | 141 | 140 |
coding | Solve the programming task below in a Python markdown code block.
Maki is a house cat. One day she fortunately came at a wonderful-looking dried fish. Since she felt not hungry on that day, she put it up in her bed. However there was a problem; a rat was living in her house, and he was watching for a chance to steal he... | {"inputs": ["3\n0 0 100 101\n77 100 50\n110 010 18\n42 80 50\n4\n1 0 110 110\n8 22 50\n25 50 58\n9 154 65\n806 205 50\n0", "3\n0 1 100 101\n60 100 50\n110 010 18\n42 80 50\n4\n1 0 010 100\n8 21 50\n25 50 58\n50 150 65\n409 205 50\n0", "3\n0 0 100 101\n77 100 90\n110 110 18\n42 80 6\n4\n1 0 110 010\n8 22 50\n25 50 58\n1... | 616 | 845 |
coding | Solve the programming task below in a Python markdown code block.
Yuki made a sugoroku so that everyone can play at the children's association event. In this sugoroku, squares are lined up in a ring, and each square has an integer of 1 or more written on it.
The player chooses a square as a starting point and places h... | {"inputs": ["3\n2 1 1", "3\n1 1 3", "3\n1 2 3", "3\n2 1 0", "3\n1 1 0", "3\n1 2 1", "3\n2 2 1", "3\n1 2 0"], "outputs": ["2\n", "1\n", "3\n", "1\n", "1\n", "2\n", "2\n", "3\n"]} | 342 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
In Chefland, the speed of light is $c\ \mathrm{m}/\mathrm{s}$, and acceleration due to gravity is $g\ \mathrm{m}/\mathrm{s}^2$.
Find the smallest height (in... | {"inputs": ["3\n7 1400\n5 1000\n10 1000"], "outputs": ["140000\n100000\n50000"]} | 445 | 52 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order.
If a folder[i] is located within another folder[j], it is called a sub-folder... | {"functional": "def check(candidate):\n assert candidate(folder = [\"/a\",\"/a/b\",\"/c/d\",\"/c/d/e\",\"/c/f\"]) == [\"/a\",\"/c/d\",\"/c/f\"]\n assert candidate(folder = [\"/a\",\"/a/b/c\",\"/a/b/d\"]) == [\"/a\"]\n\n\ncheck(Solution().removeSubfolders)"} | 196 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Ronny the robot is watching someone perform the Cups and Balls magic trick. The magician has one ball and three cups, he shows Ronny which cup he hides the ball under (b), he then mixes all the cups around by performing multiple two-cup switches (arr). R... | {"functional": "_inputs = [[2, [[1, 2]]], [1, [[2, 3], [1, 2], [1, 2]]], [2, [[1, 3], [1, 2], [2, 1], [2, 3]]]]\n_outputs = [[1], [1], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a,... | 332 | 220 |
coding | Solve the programming task below in a Python markdown code block.
For the human eye, primary colours are red, green, and blue.
Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and... | {"inputs": ["4\n1 0 1\n3 3 0\n1 1 1\n0 0 0\n"], "outputs": ["2\n3\n3\n0"]} | 512 | 43 |
coding | Solve the programming task below in a Python markdown code block.
A sequence of integers is called a wonderful sequence if all the integers in it are positive and it is a strictly increasing sequence.
Given a sequence of integers, you have to make it a wonderful sequence. For that you can change any element you want, ... | {"inputs": ["3\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8", "4\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8\n4\n2 2 2 2"], "outputs": ["0\n2\n1", "0\n2\n1\n3"]} | 300 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies.
Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie!
Given $N$ and $B$, help Chef... | {"inputs": ["1\n3 2", "1\n11 2"], "outputs": ["2", "6"]} | 371 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Treeland is a country with $n$ cities and $n-1$ roads. There is exactly one path between any two cities.
The ruler of Treeland wants to implement a self-driving bus system and asks tree-loving Alex to plan the bus routes. Alex decides that each route ... | {"inputs": ["3\n1 3\n3 2\n"], "outputs": ["5\n"]} | 636 | 22 |
coding | Solve the programming task below in a Python markdown code block.
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of ... | {"inputs": ["1 1\n!\n", "1 1\n!\n", "2 2\nR1\n", "2 1\nR1\n", "2 1\nOA\n", "2 2\nGW\n", "2 1\nOA\n", "2 2\nGW\n"], "outputs": ["PRINT !\n", "PRINT !\n", "PRINT 1\nLEFT\nPRINT R\n", "PRINT R\nRIGHT\nPRINT 1\n", "PRINT O\nRIGHT\nPRINT A\n", "PRINT W\nLEFT\nPRINT G\n", "PRINT O\nRIGHT\nPRINT A\n", "PRINT W\nLEFT\nPRINT G\... | 691 | 146 |
coding | Solve the programming task below in a Python markdown code block.
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the... | {"inputs": ["1 3\n", "1 2\n", "3 2\n", "3 1\n", "6 3\n", "2 3\n", "3 4\n", "2 1\n"], "outputs": ["1\n1 3 1 1\n1 1\n1 2\n1 3\n1 1\n", "0\n1 1\n1 2\n1 1\n", "0\n1 1\n2 1\n3 1\n3 2\n2 2\n1 2\n1 1\n", "1\n3 1 1 1\n1 1\n2 1\n3 1\n1 1\n", "0\n1 1\n1 2\n1 3\n2 3\n2 2\n3 2\n3 3\n4 3\n4 2\n5 2\n5 3\n6 3\n6 2\n6 1\n5 1\n4 1\n3 1... | 606 | 342 |
coding | Solve the programming task below in a Python markdown code block.
There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i.
Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ... | {"inputs": ["4\n1 2\n1 3\n2 4", "4\n1 2\n2 3\n2 4", "4\n1 2\n2 3\n1 4", "4\n1 2\n4 3\n2 4", "4\n1 2\n4 3\n1 4", "4\n1 2\n1 3\n3 4", "4\n1 3\n2 3\n2 4", "4\n1 2\n2 4\n3 4"], "outputs": ["6\n", "2\n", "6\n", "6\n", "6\n", "6\n", "6\n", "6\n"]} | 503 | 158 |
coding | Solve the programming task below in a Python markdown code block.
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, ... | {"inputs": ["4 3\n1 1\n2 2\n3 4\n", "3 3\n1 3\n1 1\n2 2\n", "6 3\n1 6\n1 3\n4 6\n", "3 3\n1 1\n2 3\n2 3\n", "5 3\n5 5\n1 3\n3 5\n", "3 3\n1 3\n1 2\n2 3\n", "5 3\n1 3\n2 3\n4 5\n", "3 3\n1 3\n2 3\n3 3\n"], "outputs": ["2\n", "3\n", "6\n", "2\n", "3\n", "3\n", "3\n", "3\n"]} | 340 | 182 |
coding | Solve the programming task below in a Python markdown code block.
A strongness of an even number is the number of times we can successively divide by 2 until we reach an odd number starting with an even number n.
For example, if n = 12, then
* 12 / 2 = 6
* 6 / 2 = 3
So we divided successively 2 times and we reached 3... | {"functional": "_inputs = [[1, 2], [5, 10], [48, 56], [129, 193], [2, 3], [4, 6], [3, 310], [33, 40], [456445, 678860], [324243, 897653214], [1151592177, 2129680158], [2085422641, 2128923730], [1082012216, 1876572332], [1806570867, 2067832928], [206346325, 1289058842]]\n_outputs = [[2], [8], [48], [192], [2], [4], [256... | 394 | 472 |
coding | Solve the programming task below in a Python markdown code block.
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exam... | {"inputs": ["1\n2 1\n", "1\n2 2\n", "2\n4 2\n4 1\n", "2\n3 2\n3 2\n", "2\n5 2\n5 1\n", "2\n3 1\n3 2\n", "2\n2 2\n4 1\n", "2\n3 2\n3 1\n"], "outputs": ["1", "2\n", "2", "2", "2", "2", "4\n", "2\n"]} | 602 | 121 |
coding | Solve the programming task below in a Python markdown code block.
This kata is inspired on the problem #50 of the Project Euler.
The prime ``` 41``` is the result of the sum of many consecutive primes.
In fact, ``` 2 + 3 + 5 + 7 + 11 + 13 = 41 , (6 addens) ```
Furthermore, the prime ``` 41``` is the prime belo... | {"functional": "_inputs = [[100], [200], [500], [1000]]\n_outputs = [[[41]], [[197]], [[499]], [[953]]]\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) ... | 405 | 191 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Imagine you have a special keyboard with the following keys:
A: Print one 'A' on the screen.
Ctrl-A: Select the whole screen.
Ctrl-C: Copy selection to buffer.
Ctrl-V: Print buffer on screen appending it after what h... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 7) == 9\n\n\ncheck(Solution().maxA)"} | 129 | 43 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and you want to perform operations on x such that ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,12], start = 2, goal = 12) == 2\n assert candidate(nums = [3,5,7], start = 0, goal = -4) == 2\n assert candidate(nums = [2,8,16], start = 0, goal = 1) == -1\n\n\ncheck(Solution().minimumOperations)"} | 252 | 100 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).
For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 +... | {"functional": "def check(candidate):\n assert candidate(nums1 = [5,3,4,2], nums2 = [4,2,2,5]) == 40\n assert candidate(nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]) == 65\n\n\ncheck(Solution().minProductSum)"} | 184 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You have been given a String S. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes).
Input Format
The first and only line of input contains the String S. The Stri... | {"inputs": ["eovbgggijqjdsdhjyojeaujcdyyyxtpjlllowjyarfhxjxwkxpranhtlucoklahtokmqyozlrwhldozgbgpalkqlcsiowyeslusn", "sqfopldohhwnbhhpnbxiwzvkybggkgtftvvaqpejznlxluatcppctaulxlnzjepqavvtftgkggbykvzwixbnphhbnwhhodlpofqs", "fnjzxnxnjplfwzowfdrhrvhegkmoncbkembjoudteqchjwqfzlofyflkmxnooasxulwofjzknthqqxgshvwxdvhdnlzjzdjdiif... | 135 | 256 |
coding | Solve the programming task below in a Python markdown code block.
You are given n integers a_1, a_2, …, a_n and an integer k. Find the maximum value of i ⋅ j - k ⋅ (a_i | a_j) over all pairs (i, j) of integers with 1 ≤ i < j ≤ n. Here, | is the [bitwise OR operator](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
... | {"inputs": ["1\n2 1\n2 2\n", "1\n2 1\n2 0\n", "1\n2 1\n0 0\n", "1\n2 1\n2 1\n", "1\n2 2\n2 2\n", "1\n2 1\n1 0\n", "1\n2 2\n2 1\n", "1\n2 2\n0 0\n"], "outputs": ["0\n", "0\n", "2\n", "-1\n", "-2\n", "1\n", "-4\n", "2\n"]} | 546 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words, return the smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them.
You may assume that no str... | {"functional": "def check(candidate):\n assert candidate(words = [\"alex\",\"loves\",\"leetcode\"]) == \"alexlovesleetcode\"\n assert candidate(words = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]) == \"gctaagttcatgcatc\"\n\n\ncheck(Solution().shortestSuperstring)"} | 103 | 81 |
coding | Solve the programming task below in a Python markdown code block.
The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation.
Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$.
... | {"inputs": ["6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 1 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 2 1\n6\n2 4 1 3 3 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5... | 743 | 882 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to write function which takes string and list of delimiters as an input and returns list of strings/characters after splitting given string.
Example:
```python
multiple_split('Hi, how are you?', [' ']) => ['Hi,', 'how', 'are', 'you?']
multi... | {"functional": "_inputs = [['Hi everybody!', [' ', '!']], ['(1+2)*6-3^9', ['+', '-', '(', ')', '^', '*']], ['Solve_this|kata-very\\\\quickly!', ['!', '|', '\\\\', '_', '-']], ['', []], [''], ['some strange string'], ['1_2_3_huhuh_hahaha', ['_']], ['((1+2))*(6-3)^9', ['+', '-', '(', ')', '^', '*']], ['(((1+2)-(3)))', ['... | 149 | 358 |
coding | Solve the programming task below in a Python markdown code block.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that th... | {"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n1 3\n", "1\n0 3\n", "1\n0 1\n", "1\n0 2\n", "1\n0 6\n", "1\n1 6\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 1\n", "0 1\n", "1 1\n"]} | 382 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Given the names and grades for each student in a class of $N$ students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the second lowest grade, order their na... | {"inputs": ["5\nHarry\n37.21\nBerry\n37.21\nTina\n37.2\nAkriti\n41\nHarsh\n39\n"], "outputs": ["Berry\nHarry\n"]} | 487 | 53 |
coding | Solve the programming task below in a Python markdown code block.
You are given non-negative integers A, B and C.
Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X?
As a reminder, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line of input ... | {"inputs": ["5\n2 5 7\n2 3 13\n7 0 7\n2 7 6\n1 6 6\n"], "outputs": ["YES\nNO\nYES\nYES\nYES\n"]} | 354 | 53 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.