task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
You are given an array a consisting of n integers. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, ..., a_r] (1 ≤ l ≤ r ≤ n).
A subarray is considered good if every integer that occurs in this subarray occurs there exactly thrice. For examp... | {"inputs": ["9\n2 2 2 2 1 1 2 2 2\n", "9\n4 2 2 2 1 1 2 2 2\n", "9\n4 2 2 1 1 1 2 2 2\n", "9\n1 2 2 2 1 1 2 2 2\n", "10\n1 2 3 4 1 2 5 1 2 3\n", "10\n1 2 3 4 1 2 7 1 2 3\n", "10\n1 2 5 4 1 2 7 1 2 3\n", "10\n2 2 5 4 1 2 7 1 2 3\n"], "outputs": ["3\n", "2\n", "5\n", "3", "0\n", "0\n", "0\n", "0\n"]} | 355 | 225 |
coding | Solve the programming task below in a Python markdown code block.
You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and a goal, determine the minmum number of mov... | {"inputs": ["3\n.X.\n.X.\n...\n0 0 0 2\n"], "outputs": ["3\n"]} | 504 | 30 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you will have to modify a sentence so it meets the following rules:
convert every word backwards that is:
longer than 6 characters
OR
has 2 or more 'T' or 't' in it
convert every word uppercase that is:
exactly 2 characte... | {"functional": "_inputs = [['Welcome.'], ['If a man does not keep pace with his companions, perhaps it is because he hears a different drummer.'], ['As Grainier drove along in the wagon behind a wide, slow, sand-colored mare, clusters of orange butterflies exploded off the purple blackish piles of bear sign and winked ... | 275 | 519 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.
Given an integer array nums, return the length of its longest harmonious subsequence among al... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,2,5,2,3,7]) == 5\n assert candidate(nums = [1,2,3,4]) == 2\n assert candidate(nums = [1,1,1,1]) == 0\n\n\ncheck(Solution().findLHS)"} | 97 | 82 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.
In one edit you can take a word from queries, and change any letter in i... | {"functional": "def check(candidate):\n assert candidate(queries = [\"word\",\"note\",\"ants\",\"wood\"], dictionary = [\"wood\",\"joke\",\"moat\"]) == [\"word\",\"note\",\"wood\"]\n assert candidate(queries = [\"yes\"], dictionary = [\"not\"]) == []\n\n\ncheck(Solution().twoEditWords)"} | 159 | 83 |
coding | Solve the programming task below in a Python markdown code block.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they... | {"inputs": ["xx..\n.oo.\nx...\noox.\n", "x.ox\nox..\nx.o.\noo.x\n", "x..x\n..oo\no...\nx.xo\n", "o.x.\no...\n.x..\nooxx\n", ".xox\no.x.\nx.o.\n..o.\n", "o.oo\n.x.o\nx.x.\n.x..\n", ".xx.\n.xoo\n.oox\n....\n", "xxox\no.x.\nx.oo\nxo.o\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | 493 | 158 |
coding | Solve the programming task below in a Python markdown code block.
For a given polygon g, computes the area of the polygon.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon... | {"inputs": ["3\n1 0\n2 4\n-1 1", "3\n2 0\n2 2\n-1 1", "3\n3 0\n2 2\n-1 0", "3\n0 0\n2 2\n-1 1", "3\n3 0\n2 2\n-2 -1", "3\n3 0\n2 2\n-2 -2", "3\n3 0\n1 2\n-2 -2", "3\n3 0\n1 2\n-2 -4"], "outputs": ["4.5\n", "3.0\n", "4.0\n", "2.0", "5.5\n", "6.0\n", "7.0\n", "9.0\n"]} | 298 | 181 |
coding | Solve the programming task below in a Python markdown code block.
You are playing another computer game, and now you have to slay $n$ monsters. These monsters are standing in a circle, numbered clockwise from $1$ to $n$. Initially, the $i$-th monster has $a_i$ health.
You may shoot the monsters to kill them. Each shot... | {"inputs": ["1\n3\n7 4\n3 24\n5 3\n", "1\n3\n7 4\n2 24\n5 3\n", "1\n3\n7 14\n2 9\n6 3\n", "1\n3\n7 15\n2 14\n5 3\n", "1\n3\n7 15\n2 24\n5 3\n", "1\n3\n7 15\n2 22\n5 4\n", "1\n3\n7 15\n2 22\n5 3\n", "1\n3\n7 15\n2 22\n6 3\n"], "outputs": ["7\n", "6\n", "6\n", "6\n", "6\n", "5\n", "6\n", "6\n"]} | 442 | 195 |
coding | Solve the programming task below in a Python markdown code block.
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contig... | {"inputs": ["1\n1\n", "1\n2\n", "2\n1 1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 1\n", "2\n1 4\n", "2\n2 4\n"], "outputs": ["0\n", "0\n", "2\n", "0\n", "2\n", "0\n", "0\n", "0\n"]} | 487 | 98 |
coding | 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)"} | 187 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Aklank is fond of numbers which are divisible by either P1 or P2. He termed those numbers as Bakku numbers. Recently his best friend gave him a range of numbers. Now he is wondering what is the probability of finding Bakku numbers from that range of numb... | {"inputs": ["7607 9769\n10\n1 1\n1 100000\n10000 100000\n999 1000\n7607 7607\n1 7605\n9770 10000\n15005 100000\n9 12345\n100000 100000"], "outputs": ["0.000000\n0.000230\n0.000233\n0.000000\n1.000000\n0.000000\n0.000000\n0.000247\n0.000162\n0.000000"]} | 350 | 209 |
coding | Solve the programming task below in a Python markdown code block.
Abhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle.
The puzzle consists of a string S and a keywordK. Abhiram needs to find the string of position of ... | {"inputs": ["cat is the act of tac\ncat"], "outputs": ["The antidote is found in 46."]} | 269 | 29 |
coding | Solve the programming task below in a Python markdown code block.
JJ loves playing with medians. He has an array A of length N (N is odd). He wants to partition the array A into two non-empty subsets P and Q such that the value of |median(P) - median(Q)| is as small as possible. (Note that each A_{i} must belong to eit... | {"inputs": ["3\n5\n2 7 4 8 2\n3\n1 2 3\n5\n1 1 1 1 1\n"], "outputs": ["2\n1\n0"]} | 591 | 49 |
coding | Solve the programming task below in a Python markdown code block.
After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and... | {"inputs": ["1\nR\n0\n", "1\nr\n0\n", "1\nR\n0\n", "1\nr\n0\n", "1\nQ\n0\n", "1\ns\n0\n", "1\nffff\n1\nffff r\n", "1\nffff\n1\nffff r\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 4\n", "0 4\n"]} | 565 | 124 |
coding | Solve the programming task below in a Python markdown code block.
The Professor is facing the North. Tokyo is in trouble, and she is facing the South. Professor being her guardian angel wants to help her.
So, The Professor will follow some instructions, given as a string S of length N, and will turn either left or rig... | {"inputs": ["3\n12\nLRLRRRLRLLLL\n2\nLR\n4\nLRRL\n"], "outputs": ["YES\nNO\nYES\n"]} | 407 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs ... | {"inputs": ["4 4\n1 1 2 2\n", "5 2\n1 1 2 2 5\n", "10 3\n5 1 3 2 4 1 1 2 3 4\n"], "outputs": ["0\n", "1\n", "3\n"]} | 263 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.
You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix s... | {"inputs": ["3\n", "5\n", "7\n", "9\n", "5\n", "7\n", "3\n", "11\n"], "outputs": ["*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n", "****D****\n***DDD***\n**DDDDD**\n*DDDDDDD*\nDDDDDDDDD\n*DDDDDDD*\n**DDDDD**\n***DDD***\n****D****\n", "**D**\n*D... | 213 | 293 |
coding | Solve the programming task below in a Python markdown code block.
Mary loves binary strings.
Given a binary string S, she defines the *beauty* of the string as the [bitwise XOR] of decimal representations of all substrings of S.
Find the *beauty* of string S. Since the answer can be huge, print it modulo 998244353.
... | {"inputs": ["3\n2\n10\n3\n101\n4\n1111"], "outputs": ["3\n6\n12\n"]} | 765 | 36 |
coding | Solve the programming task below in a Python markdown code block.
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i.
For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows:
- Let S be the set of ... | {"inputs": ["2\n0 2", "2\n1 1", "2\n1 2", "2\n1 2\n", "2\n-1 1", "2\n-1 2", "2\n-3 0", "2\n-1 0"], "outputs": ["4\n", "2\n", "3", "3\n", "6\n", "5\n", "13\n", "7\n"]} | 534 | 99 |
coding | Solve the programming task below in a Python markdown code block.
A binary string A is called *good* if it can be sorted (in non-decreasing order) using the following operation:
Select an i (1 ≤ i ≤ |A| - 1) and swap A_{i} with A_{i + 1}.
This operation can be performed on any i at most once.
For example, A = 10110 ... | {"inputs": ["2\n4\n0011\n6\n111000\n"], "outputs": ["10\n17\n"]} | 540 | 34 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n couples sitting in 2n seats arranged in a row and want to hold hands.
The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. The couples ... | {"functional": "def check(candidate):\n assert candidate(row = [0,2,1,3]) == 1\n assert candidate(row = [3,2,0,1]) == 0\n\n\ncheck(Solution().minSwapsCouples)"} | 180 | 58 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, we will calculate the **minumum positive number that is not a possible sum** from a list of positive integers.
```
solve([1,2,8,7]) = 4 => we can get 1, 2, 3 (from 1+2), but we cannot get 4. 4 is the minimum number not possible from the l... | {"functional": "_inputs = [[[1, 2, 8, 7]], [[2, 12, 3, 1]], [[4, 2, 8, 3, 1]], [[4, 2, 7, 3, 1]], [[4, 2, 12, 3]]]\n_outputs = [[4], [7], [19], [18], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n i... | 244 | 233 |
coding | Solve the programming task below in a Python markdown code block.
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to... | {"inputs": ["1 2\n", "2 1\n", "4 6\n", "6 7\n", "4 9\n", "7 3\n", "2 7\n", "7 4\n"], "outputs": ["Equal\n", "Equal\n", "Equal\n", "Equal\n", "Dasha\n", "Masha\n", "Dasha\n", "Masha\n"]} | 615 | 90 |
coding | Solve the programming task below in a Python markdown code block.
# Task
**_Given_** *a number* , **_Return_** **_The Maximum number _** *could be formed from the digits of the number given* .
___
# Notes
* **_Only Natural numbers_** *passed to the function , numbers Contain digits [0:9] inclusive*
* **_Digit ... | {"functional": "_inputs = [[213], [7389], [63792], [566797], [1000000]]\n_outputs = [[321], [9873], [97632], [977665], [1000000]]\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, tu... | 606 | 218 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Nim is a well-known combinatorial game, based on removing stones from piles. In this problem, we'll deal with a similar game, which we'll call Dual Nim. The rules of this game... | {"inputs": ["3\n4\n1 2 4 8\n3\n2 3 3\n5\n3 3 3 3 3", "3\n4\n1 2 4 8\n3\n2 3 3\n5\n1 3 3 3 3", "3\n4\n1 2 4 2\n3\n3 3 3\n5\n1 3 2 3 3", "3\n4\n1 2 8 7\n3\n2 1 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 8\n3\n3 3 3\n5\n1 3 3 3 3", "3\n4\n1 2 4 8\n3\n3 3 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 2\n3\n3 3 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 7\n3\n2 ... | 363 | 333 |
coding | Solve the programming task below in a Python markdown code block.
Some scientists are working on protein recombination, and during their research, they have found a remarkable fact: there are 4 proteins in the protein ring that mutate after every second according to a fixed pattern. For simplicity, proteins are called ... | {"inputs": ["5 15\nAAAAD\n"], "outputs": ["DDDDA\n"]} | 583 | 22 |
coding | Solve the programming task below in a Python markdown code block.
You have to create a function which receives 3 arguments: 2 numbers, and the result of an unknown operation performed on them (also a number).
Based on those 3 values you have to return a string, that describes which operation was used to get the given ... | {"functional": "_inputs = [[1, 2, 3], [10, 5, 5], [10, 4, 40], [9, 5, 1.8]]\n_outputs = [['addition'], ['subtraction'], ['multiplication'], ['division']]\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... | 218 | 204 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two sorted arrays of distinct integers nums1 and nums2.
A valid path is defined as follows:
Choose array nums1 or nums2 to traverse (from index-0).
Traverse the current array from left to right.
If you ... | {"functional": "def check(candidate):\n assert candidate(nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]) == 30\n assert candidate(nums1 = [1,3,5,7,9], nums2 = [3,5,100]) == 109\n assert candidate(nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]) == 40\n\n\ncheck(Solution().maxSum)"} | 189 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.
So, the goal of this kata is to wite a function that encodes a single word string to pig latin.
The rules themselves are rather ea... | {"functional": "_inputs = [['Hello'], ['CCCC'], ['tes3t5'], ['ay'], [''], ['YA'], ['123'], ['ya1'], ['yaYAya'], ['YayayA']]\n_outputs = [['ellohay'], ['ccccay'], [None], ['ayway'], [None], ['ayay'], [None], [None], ['ayayayay'], ['ayayayay']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i... | 272 | 230 |
coding | Solve the programming task below in a Python markdown code block.
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of eac... | {"inputs": ["3 3\n2 2 3", "3 3\n2 2 2", "6 3\n2 2 2", "6 3\n0 2 2", "6 3\n0 3 2", "3 3\n1 2 4", "3 3\n2 2 0", "3 3\n2 2 1"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "1\n", "1\n", "1\n"]} | 287 | 126 |
coding | Solve the programming task below in a Python markdown code block.
T is playing a game with his friend, HL.
There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single sto... | {"inputs": ["1\n2\n1 6\n", "1\n2\n1 3\n", "1\n2\n1 4\n", "1\n2\n1 1\n", "1\n2\n1 8\n", "1\n2\n2 1\n", "1\n2\n2 2\n", "1\n2\n1 9\n"], "outputs": ["T\n", "T\n", "T\n", "HL\n", "T\n", "T\n", "HL\n", "T\n"]} | 393 | 118 |
coding | Solve the programming task below in a Python markdown code block.
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference ... | {"inputs": ["2+2\n", "1+2\n", "2+2\n", "45+5\n", "45+5\n", "5+55\n", "5+54\n", "55+4\n"], "outputs": ["-46\n", "-47\n", "-46\n", "0\n", "0\n", "-440\n", "-441\n", "9\n"]} | 184 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to ___find the next higher number (int) with same '1'- Bits___.
I.e. as much `1` bits as before and output next higher than input. Input is always an int in between 1 and 1<<30 (inclusive). No bad cases or special tricks...
### Some easy ... | {"functional": "_inputs = [[128], [1], [1022], [127], [1253343]]\n_outputs = [[256], [2], [1279], [191], [1253359]]\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 ... | 276 | 205 |
coding | Solve the programming task below in a Python markdown code block.
# Task
John is new to spreadsheets. He is well aware of rows and columns, but he is not comfortable with spreadsheets numbering system.
```
Spreadsheet Row Column
A1 R1C1
D5 R5C4
AA48 ... | {"functional": "_inputs = [['A1'], ['R1C1'], ['R5C4'], ['AA48'], ['BK12'], ['R12C63'], ['R85C26'], ['R31C78'], ['BZ31']]\n_outputs = [['R1C1'], ['A1'], ['D5'], ['R48C27'], ['R12C63'], ['BK12'], ['Z85'], ['BZ31'], ['R31C78']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float... | 295 | 259 |
coding | Solve the programming task below in a Python markdown code block.
A gene is represented as a string of length $n$ (where $n$ is divisible by $4$), composed of the letters $\mbox{A}$, $\mbox{C}$, $\textbf{T}$, and $\mbox{G}$.
It is considered to be steady if each of the four letters occurs exactly $\frac{n}{4}$ times. ... | {"inputs": ["8 \nGAAATAAA\n"], "outputs": ["5\n"]} | 615 | 21 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,
F(0) = 0, F(1) = 1
F(n) = F(n -... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 1\n assert candidate(n = 3) == 2\n assert candidate(n = 4) == 3\n\n\ncheck(Solution().fib)"} | 135 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
You had an array of integer numbers. You also had a beautiful operations called "Copy-Paste" which allowed you to copy any contiguous subsequence of your array and paste it in any positi... | {"inputs": ["2\n5\n1 1 1 1 1\n5\n1 2 3 1 2", "2\n5\n1 1 1 1 1\n5\n1 2 6 1 2", "2\n5\n1 0 1 1 1\n5\n1 3 3 1 2", "2\n5\n1 0 1 2 1\n5\n1 3 3 1 2", "2\n5\n1 1 1 1 1\n5\n1 2 6 0 2", "2\n5\n1 0 1 1 1\n5\n0 3 3 1 2", "2\n5\n1 0 1 2 1\n5\n1 3 3 1 3", "2\n5\n1 1 1 1 1\n5\n1 2 1 1 2"], "outputs": ["1\n3", "1\n3\n", "2\n3\n", "3\... | 502 | 269 |
coding | Solve the programming task below in a Python markdown code block.
# Introduction
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began.
# Task
Write a function that accepts `fight` str... | {"functional": "_inputs = [['z'], ['zdqmwpbs'], ['wq'], ['zzzzs'], ['wwwwww']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], ['Left side wins!'], ['Right side wins!'], ['Left side wins!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma... | 264 | 205 |
coding | Solve the programming task below in a Python markdown code block.
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are e... | {"inputs": ["1 1\n1\n", "1 4\n1\n", "1 1\n0\n", "1 6\n1\n", "1 2\n1\n", "2 1\n1 3\n", "2 8\n1 2\n", "2 6\n1 2\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0", "0", "0\n"]} | 564 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Road Runner bought a piece of land in the middle of a desert for a nominal amount. It turns out that the piece of land is now worth millions of dollars as it has an oil reserve under it. Mr. Road Runner contacts the ACME corp to set up the oil wells ... | {"inputs": ["3 4\n1 0 0 0\n1 0 0 0\n0 0 1 0\n"], "outputs": ["3 \n"]} | 688 | 42 |
coding | Solve the programming task below in a Python markdown code block.
We have a matrix of integers with m rows and n columns.
We want to calculate the total sum for the matrix:
As you can see, the name "alternating sum" of the title is due to the sign of the terms that changes from one term to its contiguous one and ... | {"functional": "_inputs = [[[[1, 2, 3], [-3, -2, 1], [3, -1, 2]]]]\n_outputs = [[8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return F... | 232 | 180 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of distinct substrings of s.
A substring of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) fro... | {"functional": "def check(candidate):\n assert candidate(s = \"aabbaba\") == 21\n assert candidate(s = \"abcdefg\") == 28\n\n\ncheck(Solution().countDistinct)"} | 100 | 48 |
coding | Solve the programming task below in a Python markdown code block.
G: Tree
problem
Given a tree consisting of N vertices. Each vertex of the tree is numbered from 1 to N. Of the N-1 edges, the i \ (= 1, 2, ..., N-1) edge connects the vertex u_i and the vertex v_i.
Write a program to find the number of K non-empty sub... | {"inputs": ["3 4\n1 2\n1 3", "3 2\n1 2\n2 3", "3 2\n2 2\n1 3", "3 1\n1 2\n2 3", "3 1\n1 2\n3 3", "1 2\n1 2\n2 3", "3 4\n1 2\n2 3", "1 1\n1 2\n2 3"], "outputs": ["0\n", "5\n", "1\n", "6\n", "3\n", "0\n", "0\n", "1\n"]} | 533 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Given two matrices A and B. Both have N rows and M columns. In the matrix A, numbers from 1 to MN have been written in row major order. Row major order numbers cells from left to right, and top to bottom. That is,
1 2 3 ... | {"inputs": ["1\n4 5", "1\n3 5", "1\n3 2", "1\n6 6", "1\n0 0", "1\n1 5", "1\n1 8", "1\n1 1"], "outputs": ["2", "3\n", "2\n", "6\n", "0\n", "5\n", "8\n", "1\n"]} | 491 | 93 |
coding | Solve the programming task below in a Python markdown code block.
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland... | {"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\... | 611 | 774 |
coding | Solve the programming task below in a Python markdown code block.
Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which the dolls come in pairs. One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!
Help c... | {"inputs": ["1\n3\n1 \n2\n1", "1\n3\n2 \n2\n1", "1\n3\n0 \n2\n0", "1\n3\n1 \n4\n1", "1\n3\n1 \n8\n1", "1\n1\n7 \n6\n1", "1\n3\n2 \n1\n1", "1\n3\n0 \n1\n0"], "outputs": ["2", "1\n", "2\n", "4\n", "8\n", "7\n", "2\n", "1\n"]} | 258 | 133 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.
For every two consecutive 0's, merge all the nodes lying... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([0,3,1,0,4,5,2,0])), list_node([4,11]))\n assert is_same_list(candidate(head = list_node([0,1,0,3,0,2,2,0])), list_node([1,3,4]))\n\n\ncheck(Solution().mergeNodes)"} | 180 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.
Raja only participates in contests and does not upsolve, but he claims that he has been upsolving. Chef wants to test if he is really improving, so h... | {"inputs": ["1\n3\n2 3 2"], "outputs": ["5"]} | 637 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor o... | {"inputs": ["9\n", "8\n", "4\n", "2\n", "5\n", "3\n", "7\n", "1\n"], "outputs": ["2", "1\n4", "2", "1\n0", "1\n0", "1\n0", "1\n0\n", "1\n0"]} | 418 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has recently got a job as a cashier at a local store. His day at work is $L$ minutes long. Vasya has already memorized $n$ regular customers, the $i$-th of which comes after $t_{i}$ minutes after the beginning of the day, and his service consumes $... | {"inputs": ["0 5 2\n", "0 1 1\n", "0 1 1\n", "0 2 1\n", "0 0 2\n", "0 0 1\n", "0 0 4\n", "0 6 2\n"], "outputs": ["2", "1", "1\n", "2\n", "0\n", "0\n", "0\n", "3\n"]} | 476 | 100 |
coding | Solve the programming task below in a Python markdown code block.
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
- For each integer j (... | {"inputs": ["1000000000 1000000001 0", "1000000000 1000001000 0", "1000000000 1001001000 0", "1000000000 1001001010 0", "1000100000 1001001010 0", "1000000000 1000000000 0", "1000000000 1000000000 0\n", "4 5 8\n1 1\n1 4\n0 5\n2 3\n3 1\n3 2\n3 4\n4 4"], "outputs": ["999999997000000002\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "100... | 436 | 519 |
coding | 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"]} | 477 | 207 |
coding | Solve the programming task below in a Python markdown code block.
Tim buy a string of length N from his friend which consist of ‘d’ and ‘u’ letters only
,but now Tim wants to sell the string at maximum cost.
The maximum cost of string is defined as the maximum length of a Substring (consecutive subsequence) consist... | {"inputs": ["4 2\nduud", "10 1\ndduddudddu"], "outputs": ["4", "6"]} | 289 | 34 |
coding | Solve the programming task below in a Python markdown code block.
You are given two positive integers $N$ and $K$, where $K \le N$. Find a sequence $A_1, A_2, \ldots, A_N$ such that:
- for each valid $i$, $A_i$ is either $i$ or $-i$
- there are exactly $K$ values of $i$ such that $1 \le i \le N$ and $A_1 + A_2 + \ldots... | {"inputs": ["1\n3 3"], "outputs": ["1 2 3"]} | 327 | 20 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character.
Return the minimum number of steps to make t an anagram of s.
An Anagram of a ... | {"functional": "def check(candidate):\n assert candidate(s = \"bab\", t = \"aba\") == 1\n assert candidate(s = \"leetcode\", t = \"practice\") == 5\n assert candidate(s = \"anagram\", t = \"mangaar\") == 0\n\n\ncheck(Solution().minSteps)"} | 120 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by cre... | {"inputs": ["3 4\n1 2 3"], "outputs": ["5"]} | 350 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:$f(p) = \sum_{i = 1}^{n} \sum_{j = i}^{n} \operatorname{min}(p_{i}, p_{i + 1}, \ldots p_{j})$
Find the lexicographically m-th permutation of length n in the se... | {"inputs": ["2 2\n", "3 2\n", "1 1\n", "3 1\n", "3 3\n", "3 4\n", "4 1\n", "4 3\n"], "outputs": ["2 1 \n", "1 3 2 \n", "1 \n", "1 2 3 \n", "2 3 1 \n", "3 2 1 \n", "1 2 3 4 \n", "1 3 4 2 \n"]} | 334 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_... | {"inputs": ["3\n4 10\n-16 2 -6 8\n3 1000\n-100000 -100000 -100000\n6 0\n2 6 -164 1 -1 -6543\n"], "outputs": ["2 4\n-1\n1 2\n"]} | 748 | 88 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.
Please complete the ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,3,2]) == 4\n assert candidate(nums = [6,2,6,5,1,2]) == 9\n\n\ncheck(Solution().arrayPairSum)"} | 109 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Comprised of a team of five incredibly brilliant women, "The ladies of ENIAC" were the first “computors” working at the University of Pennsylvania’s Moore School of Engineering (1945). Through their contributions, we gained the first software application... | {"functional": "_inputs = [['k?%35a&&/y@@@5599 m93753&$$$c$n///79u??@@%l?975$t?%5y%&$3$1!'], ['9?9?9?m335%$@a791%&$r$$$l@53$&y&n%$5@ $5577w&7e931%s$c$o%%%f351f??%!%%'], ['%&$557f953//1/$@%r%935$$a@3111$@???%n???5 $%157b%///$i%55&31@l?%&$$a%@$s5757!$$%%%%53'], ['///$%&$553791r357%??@$%u?$%@7993111@$%t$h3% 3$l$311i3%@?&c... | 189 | 531 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:
A cell containing a thief if grid[r][c] = 1
An empty cell if grid[r][c] = 0
You are initially positioned at cell (0, 0). In one move, ... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,0,0],[0,0,0],[0,0,1]]) == 0\n assert candidate(grid = [[0,0,1],[0,0,0],[0,0,0]]) == 2\n assert candidate(grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]) == 2\n\n\ncheck(Solution().maximumSafenessFactor)"} | 288 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Leonid is developing new programming language. The key feature of his language is fast multiplication and raising to a power operations. He is asking you to help with the following task.
You ha... | {"inputs": ["2\n1000 2**3*3**1\n100000 11**2*2**4", "2\n1000 2**3*3**1\n100000 4**2*2**11", "2\n1001 2**3*2**1\n100000 4**2*2**11", "2\n1000 2**3*3**1\n101000 11**2*2**4", "2\n1001 1**3*3**2\n100000 4**2*2**11", "2\n1001 1**3*3**2\n100000 4**2*2**01", "2\n1001 1**3*3**1\n110000 11**2*2**4", "2\n1100 2**3*3**1\n110000 4... | 422 | 339 |
coding | Solve the programming task below in a Python markdown code block.
A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input.
Input:... | {"inputs": ["3\nritesh\nsahil\nritesh", "5\nritesh\nritesh\nritesh\nsahil\nsahil"], "outputs": ["ritesh 2\nsahil 1", "ritesh 3\nsahil 2"]} | 252 | 63 |
coding | Solve the programming task below in a Python markdown code block.
At a break Vanya came to the class and saw an array of $n$ $k$-bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$-bit integer if $0 \leq x \leq 2^k - 1$.
Of course, Vanya was not able to resist and started changing the nu... | {"inputs": ["1 1\n1\n", "1 1\n0\n", "1 2\n3\n", "1 2\n3\n", "1 1\n1\n", "1 1\n0\n", "1 2\n4\n", "1 2\n0\n"], "outputs": ["1", "1", "1", "1", "1", "1", "1\n", "1\n"]} | 740 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Find the longest substring in alphabetical order.
Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`.
There are tests with strings up to `10 000` characters long so your code will need to be efficient.
The ... | {"functional": "_inputs = [['asd'], ['nab'], ['abcdeapbcdef'], ['asdfaaaabbbbcttavvfffffdf'], ['asdfbyfgiklag'], ['z'], ['zyba']]\n_outputs = [['as'], ['ab'], ['abcde'], ['aaaabbbbctt'], ['fgikl'], ['z'], ['z']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r... | 128 | 216 |
coding | Solve the programming task below in a Python markdown code block.
Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation.
There are $n$ photographer... | {"inputs": ["2\n2\n0 1\n0 1\n2\n0 1\n100 1\n"], "outputs": ["0.785398163397\n0.000100999899"]} | 523 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.
If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.
-----Inpu... | {"inputs": ["3 \n7\n19\n43", "3 \n7\n17\n43", "3 \n7\n33\n43", "3 \n5\n33\n43", "3 \n6\n50\n80", "3 \n8\n50\n80", "3 \n1\n67\n25", "3 \n50\n0\n25"], "outputs": ["2\n4\n6\n", "2\n3\n6\n", "2\n5\n6\n", "1\n5\n6\n", "2\n1\n4\n", "3\n1\n4\n", "1\n4\n3\n", "1\n0\n3\n"]} | 205 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The student... | {"inputs": ["1 3\n", "3 2\n", "5 0\n", "4 2\n", "6 4\n", "6 3\n", "7 3\n", "5 4\n"], "outputs": ["9\n", "8\n", "10\n", "9\n", "15\n", "14\n", "15\n", "14\n"]} | 334 | 91 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a date, return the corresponding day of the week for that date.
The input is given as three integers representing the day, month and year respectively.
Return the answer as one of the following values {"Sunday",... | {"functional": "def check(candidate):\n assert candidate(day = 31, month = 8, year = 2019) == \"Saturday\"\n assert candidate(day = 18, month = 7, year = 1999) == \"Sunday\"\n assert candidate(day = 15, month = 8, year = 1993) == \"Sunday\"\n\n\ncheck(Solution().dayOfTheWeek)"} | 120 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists ... | {"inputs": ["1\n.\n", "1\n.\n", "1\n/\n", "1\n0\n", "1\n-\n", "1\n,\n", "1\n+\n", "1\n*\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 404 | 86 |
coding | Solve the programming task below in a Python markdown code block.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 **below** the number passed in.
> Note: If ... | {"functional": "_inputs = [[10], [20], [0], [1], [200]]\n_outputs = [[23], [78], [0], [0], [9168]]\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) != le... | 161 | 186 |
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 and a positive integer k.
You can apply the following operation on the array any number of times:
Choose any subarray of size k from the array and decrease all its element... | {"functional": "def check(candidate):\n assert candidate(nums = [2,2,3,1,1,0], k = 3) == True\n assert candidate(nums = [1,3,1,1], k = 2) == False\n\n\ncheck(Solution().checkArray)"} | 134 | 67 |
coding | Solve the programming task below in a Python markdown code block.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the recta... | {"inputs": ["1\n1 1\n", "1\n0 1\n", "1\n1 1\n", "1\n14 304\n", "1\n15 304\n", "2\n0 0\n1 1\n", "1\n-188 17\n", "1\n71 -740\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "1\n", "-1\n", "-1\n"]} | 371 | 120 |
coding | Solve the programming task below in a Python markdown code block.
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) ex... | {"inputs": ["2 1\n1 2\n3\n1 2\n1 2\n2 1\n", "5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 6\n6 5\n4 3\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n5 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n3 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n1 5\n5\n1 5\n3 1\... | 674 | 438 |
coding | Solve the programming task below in a Python markdown code block.
An SNS has N users - User 1, User 2, \cdots, User N.
Between these N users, there are some relationships - M friendships and K blockships.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i.
For each i = 1, 2,... | {"inputs": ["4 4 1\n2 1\n1 3\n3 3\n3 4\n4 1", "4 4 1\n2 0\n1 3\n3 3\n3 4\n4 1", "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1", "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n", "5 7 0\n1 2\n2 3\n2 4\n0 5\n0 2\n2 4\n2 0\n2 1\n1 2\n4 1", "5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n1 3\n4 5", "5 10 0\n1 2\n1 3\n2 4\n1 5\n3 2\n2 4\n2 5\n4 3\n1 ... | 686 | 393 |
coding | Solve the programming task below in a Python markdown code block.
Chef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d on a paper. Chef wants to know whether he can shuffle these numbers so as to make some proportion? Formally, four numbers x, y, z, w are said to make a proport... | {"inputs": ["1 2 4 2"], "outputs": ["Possible"]} | 236 | 18 |
coding | Solve the programming task below in a Python markdown code block.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out... | {"inputs": ["2\n", "1\n", "3\n", "5\n", "7\n", "37\n", "19\n", "30\n"], "outputs": ["2", "1", "3\n", "5\n", "7\n", "37", "19\n", "30\n"]} | 455 | 73 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $2$) or determine that there is no such subset.
Both the given array and required subset may contain e... | {"inputs": ["1\n2\n1 1\n", "1\n2\n1 1\n", "1\n3\n1 1\n", "1\n3\n1 2\n", "1\n3\n0 2\n", "1\n3\n0 3\n", "1\n3\n0 1\n", "1\n4\n1 2\n"], "outputs": ["2\n1 2\n", "2\n1 2\n", "2\n1 2\n", "1\n2\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n2\n"]} | 427 | 140 |
coding | Solve the programming task below in a Python markdown code block.
Mr. Das is a teacher teaching for several years in a school. He is not computer savvy. Due to lockdown, now he has to take classes online. Recently he took an online exam for students of different classes. Now, he will call parents of all the students wh... | {"inputs": ["2\n3\nRahul 1345964789 47\nRupendra 1457856987 58\nPriya 1478569820 45\n2\nTanuja 4310779415 97\nAkash 3689781245 43"], "outputs": ["Priya 1478569820 45\nRahul 1345964789 47\nAkash 3689781245 43"]} | 497 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Alice buys a toy with a selling price of 100 rupees. There is a discount of x percent on the toy. Find the amount Alice needs to pay for it.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of t... | {"inputs": ["4\n5\n9\n11\n21\n"], "outputs": ["95\n91\n89\n79\n"]} | 233 | 34 |
coding | Solve the programming task below in a Python markdown code block.
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you h... | {"inputs": ["1 1\n2 1", "1 1\n2 1\n", "3 4\n4 3\n4 1\n3 2", "3 4\n4 3\n3 0\n3 4", "3 4\n4 3\n3 1\n2 4", "3 0\n4 3\n3 1\n2 4", "3 5\n4 3\n4 1\n2 2", "3 4\n4 3\n4 1\n6 2"], "outputs": ["0", "0\n", "5\n", "7\n", "8\n", "0\n", "6\n", "3\n"]} | 338 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob.
The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The... | {"inputs": ["3\n5\n3 1 3 3 4\n1 6 2 5 3\n5\n1 6 2 5 3\n3 1 3 3 4\n3\n4 1 3\n2 2 7"], "outputs": ["Alice\nBob\nDraw"]} | 710 | 74 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing tha... | {"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2) == 0.25000\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2) == 0.30000\n assert candidate(n = 3, edges = [[0,1]], succPr... | 207 | 180 |
coding | Solve the programming task below in a Python markdown code block.
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise X... | {"inputs": ["2\n1 5\n", "2\n1 0\n", "2\n0 5\n", "2\n1 1\n", "2\n1 5\n", "3\n1 2 3\n", "3\n1 1 3\n", "3\n0 1 9\n"], "outputs": ["4\n", "1\n", "4\n", "0\n", "4", "2\n", "2\n", "8\n"]} | 310 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times takes a r... | {"inputs": ["5\n2 4 5 1 3\n", "5\n4 3 5 1 2\n", "5\n4 1 5 2 3\n", "5\n2 4 5 1 3\n"], "outputs": ["Petr\n", "Petr\n", "Petr\n", "Petr\n"]} | 404 | 82 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of size $n$. Each element in this array is an integer between $1$ and $10^9$.
You can perform several operations to this array. During an operation, you can replace an element in the array with any integer between $1$ and $10^... | {"inputs": ["5\n3\n2 1 2\n4\n1 2 3 1\n5\n1 2 1 2 1\n9\n1 2 1 3 2 3 1 2 1\n9\n2 1 3 1 3 1 3 1 3\n"], "outputs": ["0\n2 1 2 \n1\n1 2 3 3 \n1\n1 2 2 2 1 \n2\n1 2 3 3 2 3 3 2 1 \n2\n2 1 3 3 3 1 3 3 3 \n"]} | 627 | 157 |
coding | Solve the programming task below in a Python markdown code block.
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a_1, a_2, ..., a_{m} of length m, consisting of integers from 1 to n, not necessaril... | {"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "3 1\n1 1 2\n2\n", "2 2\n1 1\n1 2\n", "2 2\n1 1\n1 2\n", "3 1\n1 1 2\n2\n", "3 1\n1 1 2\n3\n", "3 2\n1 1 3\n1 2\n"], "outputs": ["Possible\n1 \n", "Possible\n1 \n", "Possible\n3 \n", "Impossible\n", "Impossible\n", "Possible\n3 \n", "Impossible\n", "Impossible\n"]} | 572 | 156 |
coding | Solve the programming task below in a Python markdown code block.
----- Statement -----
You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the ... | {"inputs": ["2\n1\n2", "2\n2\n2", "2\n2\n3", "2\n3\n2", "2\n2\n5", "2\n4\n5", "2\n3\n5", "2\n5\n5"], "outputs": ["ba\ncba", "cba\ncba\n", "cba\ndcba\n", "dcba\ncba\n", "cba\nfedcba\n", "edcba\nfedcba\n", "dcba\nfedcba\n", "fedcba\nfedcba\n"]} | 161 | 121 |
coding | Solve the programming task below in a Python markdown code block.
After Derek (of district 5) discovered how to compute the greatest common divisor (gcd) of Fibonacci numbers, he now tried to answer the next obvious question: how does one compute the least common multiple (lcm) of Fibonacci numbers? Unfortunately, Dere... | {"inputs": ["5\n1\n3\n3\n6\n9\n"], "outputs": ["136\n"]} | 349 | 26 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers and an integer k.
Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of eleme... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], k = 4) == 6\n assert candidate(nums = [3,3,3], k = 4) == 0\n assert candidate(nums = [6,6], k = 2) == 2\n\n\ncheck(Solution().countPartitions)"} | 153 | 83 |
coding | Solve the programming task below in a Python markdown code block.
For a non-negative integer N, define S(N) as the sum of the odd digits of N
plus twice the sum of the even digits of N.
For example, S(5)=5, S(456)=2*4+5+2*6=25, and S(314159)=3+1+2*4+1+5+9=27.
Define D(N) as the last digit of S(N).
So D(5)=5, D(456)=5, ... | {"inputs": ["3\n2 8\n28 102\n1092 314159", "3\n2 8\n35 102\n1092 314159", "3\n2 8\n61 102\n1092 314159", "3\n0 9\n49 155\n4563 223113", "3\n2 8\n28 102\n1358 314159", "3\n2 8\n35 102\n1092 182073", "3\n2 8\n61 102\n1092 544927", "3\n0 9\n49 218\n2145 473966"], "outputs": ["35\n326\n1408814\n", "35\n302\n1408814\n", "35... | 297 | 348 |
coding | Solve the programming task below in a Python markdown code block.
------Read problems statements in Mandarin chinese
, Russian and Vietnamese as well. ------
Professor GukiZ decided to distribute all of his candies to his $N$ students (numbered $1$ through $N$). Let's denote the number of candies GukiZ gave to the $i... | {"inputs": ["2\n4 3 4 \n2 1 5\n2 2 9\n3 6"], "outputs": ["12\n9"]} | 752 | 38 |
coding | Solve the programming task below in a Python markdown code block.
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction.
A fraction in notation with base b is finite if it contains finite number of nume... | {"inputs": ["2\n9 12 10\n4 3 10\n", "2\n9 12 10\n4 6 10\n", "2\n47 23 4\n3 6 16\n", "2\n6 12 10\n4 3 10\n", "2\n25 12 10\n3 6 15\n", "2\n47 23 10\n3 6 20\n", "2\n18 12 10\n4 6 10\n", "2\n18 12 10\n5 6 10\n"], "outputs": ["Finite\nInfinite\n", "Finite\nInfinite\n", "Infinite\nFinite\n", "Finite\nInfinite\n", "Infinite\n... | 343 | 219 |
coding | Solve the programming task below in a Python markdown code block.
Given a binary number $S$ containing only of 1's and 0's, find two binary numbers $A$ and $B$ such that the sum of the number of 1's in $A$ and $B$ is minimum and $A-B=S$. If there are many such numbers, you can print any.
The binary number $S$ has some... | {"inputs": ["1110000"], "outputs": ["10000000 10000"]} | 361 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \leq B \leq C \leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A ... | {"inputs": ["1 2 3 4\n", "1 2 2 5\n", "1 2 2 3\n", "1 0 2 5\n", "1 2 2 5\n", "1 2 3 4\n", "32 89 451 476\n", "32 89 451 476\n"], "outputs": ["4\n", "3\n", "3\n", "0\n", "3", "4", "72384\n", "72384"]} | 471 | 135 |
coding | Solve the programming task below in a Python markdown code block.
For a given polygon g and target points t, print "2" if g contains t, "1" if t is on a segment of g, "0" otherwise.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon... | {"inputs": ["4\n0 0\n3 1\n2 3\n0 3\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 1\n3\n2 1\n0 2\n0 2", "4\n0 0\n3 0\n2 3\n0 3\n3\n2 0\n0 2\n0 2", "4\n0 0\n3 1\n4 3\n0 3\n3\n2 0\n0 3\n0 2", "4\n0 0\n2 1\n2 2\n0 3\n3\n2 1\n0 1\n3 2", "4\n1 0\n3 0\n2 3\n0 3\n3\n2 0\n0 0\n0 4", "4\n0 1\n3 1\n6 3\n0 3\n3\n2 0\n0 5\n0 2", "4\n0 0... | 390 | 334 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.
You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also giv... | {"functional": "def check(candidate):\n assert candidate(nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]) == 9\n assert candidate(nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]) == 0\n\n\ncheck(Solution().minimumScore)"} | 328 | 104 |
coding | Solve the programming task below in a Python markdown code block.
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, ... | {"inputs": ["1 1 1\n1\n1\n", "1 1 13\n2\n3\n", "1 1 13\n2\n2\n", "1 1 10\n5\n15\n", "1 1 10\n2\n15\n", "1 1 13\n2\n15\n", "1 1 10\n10\n10\n", "1 1 10\n10\n15\n"], "outputs": ["0", "11\n", "11\n", "15", "18\n", "15\n", "0", "10\n"]} | 494 | 151 |
coding | 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"]} | 550 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); w... | {"inputs": ["3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 8 4 6 2", "3\n1 6 7 9 5 4 8 3 2", "3\n2 4 7 9 5 3 8 6 1", "3\n1 3 7 9 4 8 5 6 2", "3\n2 3 7 9 5 4 8 6 1", "3\n1 3 7 9 5 4 8 6 2", "4\n6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1", "3"]} | 627 | 225 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.