task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Write a function to calculate compound tax using the following table:
For $10 and under, the tax rate should be 10%.
For $20 and under, the tax rate on the first $10 is %10, and the tax on the rest is 7%.
For $30 and under, the tax rate on the first $10... | {"functional": "_inputs = [[1], [10], [11], [15], [18], [21], [26], [30], [30.49], [35], [100], [1000000], [0], [-3], [None], ['monkey'], [[]], [{}]]\n_outputs = [[0.1], [1], [1.07], [1.35], [1.56], [1.75], [2], [2.2], [2.21], [2.35], [4.3], [30001.3], [0], [0], [0], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=... | 251 | 307 |
coding | Solve the programming task below in a Python markdown code block.
Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI.
JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be investigated, ... | {"inputs": ["6\n2 8\n1 9\n1 4\n6 2\n6 2\n6 9", "6\n2 8\n1 9\n1 5\n6 2\n6 2\n6 9", "6\n2 0\n0 9\n2 4\n8 0\n6 2\n6 9", "6\n2 8\n2 9\n1 5\n6 2\n6 2\n6 9", "6\n2 0\n0 9\n2 4\n0 0\n6 2\n6 9", "6\n2 8\n5 9\n2 4\n10 4\n6 1\n6 5", "6\n2 8\n5 9\n2 4\n10 4\n6 2\n6 5", "6\n2 8\n5 9\n2 4\n10 4\n6 2\n6 9"], "outputs": ["4\n", "4\n"... | 529 | 257 |
coding | Solve the programming task below in a Python markdown code block.
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the compe... | {"inputs": ["1 0\n0\n", "1 5\n0\n", "1 7\n7\n", "1 0\n0\n", "1 7\n7\n", "1 5\n0\n", "1 7\n1\n", "1 2\n7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 443 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin and Russian. Translations in Vietnamese to be uploaded soon.
You are given an integer N. Consider a vector a of length N^{2} accessible via 0-based indexing.
Let's call the following transformation a TVT-transformati... | {"inputs": ["2\n1\n2"], "outputs": ["YES\n1\nYES\n1 1 1 -1"]} | 341 | 28 |
coding | Solve the programming task below in a Python markdown code block.
A and B are brothers and like playing with marbles.Their mother buys them N marbles to play with.The preciousness of each marble is a natural number from 1 to N and no two marbles have same preciousness.
Since A and B are good at maths they want to divid... | {"inputs": ["2\n5 7\n1 2"], "outputs": ["Yes\nNo"]} | 413 | 22 |
coding | Solve the programming task below in a Python markdown code block.
You are playing a very popular computer game. The next level consists of $n$ consecutive locations, numbered from $1$ to $n$, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the... | {"inputs": ["3\n2\n1 1\n5\n1 0 1 0 1\n4\n1 0 1 1\n"], "outputs": ["0\n4\n2\n"]} | 576 | 46 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the maximum length of a subarray that sums to k. If there is not one, return 0 instead.
Please complete the following python code precisely:
```python
class Solut... | {"functional": "def check(candidate):\n assert candidate(nums = [1,-1,5,-2,3], k = 3) == 4\n assert candidate(nums = [-2,-1,2,1], k = 1) == 2\n\n\ncheck(Solution().maxSubArrayLen)"} | 88 | 69 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.
The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2... | {"functional": "def check(candidate):\n assert candidate(ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2) == 45\n assert candidate(ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2) == 16\n\n\ncheck(Solution().computeArea)"} | 166 | 131 |
coding | Solve the programming task below in a Python markdown code block.
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on... | {"inputs": ["2 4\n2 3", "5 5\n2 2", "4 2\n2 1", "4 5\n2 2", "4 0\n2 1", "7 5\n2 2", "4 0\n0 1", "7 5\n1 2"], "outputs": ["0\n", "9\n", "2\n", "6\n", "-2\n", "15\n", "-4\n", "18\n"]} | 212 | 112 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].
Given two sentences sentence1 and sentence2 each ... | {"functional": "def check(candidate):\n assert candidate(sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"fine\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]) == True\n assert candidate(sentence1 = [\"great\"], sentence2 = [\"great\"], si... | 253 | 139 |
coding | Solve the programming task below in a Python markdown code block.
Given a word w, rearrange the letters of w to construct another word s in such a way that s is lexicographic-ally greater than w. In case of multiple possible answers, find the lexicographic-ally smallest one.
Input Format
The first line of input conta... | {"inputs": ["5\nab\nbb\nhefg\ndhck\ndkhc"], "outputs": ["ba\nno answer\nhegf\ndhkc\nhcdk"]} | 339 | 41 |
coding | Solve the programming task below in a Python markdown code block.
JJ found a balanced parenthesis sequence. He does not like balanced parentheses so he will make the parenthesis sequence unbalanced by swapping adjacent characters in the sequence.
JJ is lazy and wants to know minimum number of adjacent swaps required ... | {"inputs": ["4\n()\n(())\n()()\n((()))(())\n"], "outputs": ["1\n2\n1\n2\n"]} | 343 | 35 |
coding | Solve the programming task below in a Python markdown code block.
You are a coach of a group consisting of $n$ students. The $i$-th student has programming skill $a_i$. All students have distinct programming skills. You want to divide them into teams in such a way that: No two students $i$ and $j$ such that $|a_i - a_... | {"inputs": ["1\n1\n100\n", "1\n1\n100\n", "1\n2\n1 5\n", "1\n1\n101\n", "1\n1\n111\n", "1\n2\n1 8\n", "1\n1\n011\n", "1\n1\n010\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 578 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $n$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.
The pieces of sushi are of two types: ei... | {"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 1 2\n", "3\n2 1 1\n", "3\n1 1 2\n", "3\n2 1 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 596 | 110 |
coding | Solve the programming task below in a Python markdown code block.
You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability.
A Good Rectangle is defined as one where all squares lying on the inner border are of the same color.
What is the... | {"inputs": ["1 3 1"], "outputs": ["6"]} | 162 | 16 |
coding | Solve the programming task below in a Python markdown code block.
Akash is stuck in a N \times N grid, where N is odd. The rows of the grid are numbered 1 to N from top to bottom, and the columns are numbered 1 to N from left to right. The cell at the intersection of the i-th row and j-th column will be denoted (i, j).... | {"inputs": ["2\n3 2 1\n5 3 1"], "outputs": ["1\n0\n"]} | 669 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Mathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a
pangram. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters ... | {"inputs": ["2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nabcdefghijklmopqrstuvwz\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nthequickbrownfoxjumpsoverthelazydog"], "outputs": ["63\n0"]} | 581 | 172 |
coding | Solve the programming task below in a Python markdown code block.
Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time.
The m... | {"inputs": ["5\n0 1\n1 1\n2 1\n1 3\n4 6"], "outputs": ["0\n1\n4\n5\n46"]} | 742 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Your friend Сhef has prepared a rectangular cake for you. Both of you want to divide the cake among yourselves. Your friend is generous enough to let you choose your share first. You have... | {"inputs": ["2\n1 1 18 7\n8 20 32 6\n0 1 8 17\n22 1 90 8", "2\n1 1 18 7\n8 20 32 6\n0 1 8 17\n22 0 90 8", "2\n1 1 18 7\n2 20 32 6\n0 1 8 17\n22 0 90 8", "2\n1 1 18 7\n0 20 32 6\n0 1 8 17\n22 0 90 8", "2\n1 1 18 7\n0 20 32 6\n0 1 8 17\n22 0 90 2", "2\n0 2 7 1\n3 8 8 20\n1 0 20 20\n16 11 39 30", "2\n0 2 7 1\n3 8 8 20\n2 ... | 563 | 415 |
coding | Solve the programming task below in a Python markdown code block.
Chef is teaching his class of N students at Hogwarts. He groups students with the same height together for an activity. Some of the students end up in a groups with only themselves and are saddened by this.
With the help of his magic wand, Chef can incr... | {"inputs": ["4\n4\n1 2 1 2\n4\n1 2 2 2\n3\n1 1 1\n5\n1 2 3 4 5\n"], "outputs": ["0\n1\n0\n3\n"]} | 519 | 60 |
coding | Solve the programming task below in a Python markdown code block.
The Chef has bought $N$ boxes of Tiles. The number of tiles present in $i^{th}$ box is $i$ ($i $ varies from $1$ to $N$) . The Chef has two houses with $N$ rooms each, whose floors is a square with area $(i*i)$ ,i varies from $(1....N)$. He... | {"inputs": ["1\n16"], "outputs": ["4"]} | 362 | 15 |
coding | Solve the programming task below in a Python markdown code block.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about... | {"inputs": ["5 4 3\n", "6 8 2\n", "0 0 1\n", "0 1 1\n", "1 0 1\n", "9 7 5\n", "4 4 8\n", "0 0 1\n"], "outputs": ["3 1\n", "7 0\n", "0 0\n", "1 0\n", "1 0\n", "3 1\n", "1 4\n", "0 0\n"]} | 639 | 118 |
coding | Solve the programming task below in a Python markdown code block.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i.
Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or gr... | {"inputs": ["3 6\n1 7 3", "3 6\n1 5 2", "3 7\n1 5 0", "3 6\n1 7 2", "3 6\n1 5 0", "3 7\n0 5 0", "2 7\n0 6 0", "2 7\n0 3 0"], "outputs": ["2\n", "0\n", "3\n", "2\n", "1\n", "3\n", "2\n", "2\n"]} | 418 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on ... | {"inputs": ["1\n3\n1 3\n2 5\n6 9", "1\n3\n1 3\n0 5\n6 9", "1\n3\n1 3\n2 5\n1 6", "1\n3\n1 3\n2 5\n6 6", "1\n3\n0 3\n0 5\n6 9", "1\n3\n0 3\n1 5\n6 9", "1\n3\n1 3\n2 2\n6 9", "1\n3\n0 3\n0 5\n5 9"], "outputs": ["2", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 428 | 173 |
coding | Solve the programming task below in a Python markdown code block.
There is an empty grid (all cells are colored white) of N rows and M columns.
Chef can fill each cell with either RED or GREEN color.
Chef defines a *valid* path as a path of cells starting from (1,1) and ending at (N,M), where, Chef moves either righ... | {"inputs": ["3\n1 1\n1 2\n2 3\n"], "outputs": ["0\n2\n72\n"]} | 498 | 31 |
coding | Solve the programming task below in a Python markdown code block.
Consider the set of all nonnegative integers: ${0, 1, 2, \dots}$. Given two integers $a$ and $b$ ($1 \le a, b \le 10^4$). We paint all the numbers in increasing number first we paint $0$, then we paint $1$, then $2$ and so on.
Each number is painted whi... | {"inputs": ["1\n9 1\n", "1\n9 2\n", "1\n17 1\n", "1\n29 1\n", "1\n29 2\n", "1\n29 3\n", "1\n48 3\n", "1\n48 6\n"], "outputs": ["Finite\n", "Finite\n", "Finite\n", "Finite\n", "Finite\n", "Finite\n", "Infinite\n", "Infinite\n"]} | 644 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Templat... | {"inputs": ["5\ninsert A\ninsert U\ninsert C\nfind G\nfind A", "5\ninsert B\ninsert T\ninsert C\nfind G\nfind A", "5\ninsert A\ninsert U\ninsert F\nfind F\nfind B", "5\ninsert A\ninsert U\ninsert D\nfind G\nfind A", "5\ninsert A\ninsert T\ninsert C\nfind G\nfind @", "5\ninsert A\ninsert U\ninsert D\nfind G\nfind B", "5... | 249 | 199 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers.
You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$.
Your task is to calculate the maximum possible length of the strictly increasing contiguous ... | {"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 1\n", "2\n7 6\n", "2\n2 2\n", "2\n2 1\n", "2\n1 1\n", "2\n2 2\n"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "1", "1", "1"]} | 400 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?
There are $n$ students living in a building, and for... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "1 2\n1\n", "1 1000\n19\n", "1 1000\n548\n", "1 1000\n548\n", "1 1000\n892\n", "1 1000\n406\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 717 | 126 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour.
Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's p... | {"inputs": ["4\n1 2 3 4\n1 2\n2 3\n2 4\n", "4\n1 2 3 4\n1 2\n2 3\n1 4\n", "4\n2 2 3 4\n1 2\n2 3\n2 4\n", "4\n1 2 3 4\n1 2\n1 3\n1 4\n", "4\n3 2 3 4\n1 2\n2 3\n2 4\n", "4\n1 2 3 4\n1 2\n1 3\n2 4\n", "4\n1 2 1 4\n1 2\n1 3\n2 4\n", "4\n1 2 1 4\n1 2\n1 3\n1 4\n"], "outputs": ["10 9 3 4\n", "10 5 3 4\n", "2 9 3 4\n", "10 2 ... | 422 | 282 |
coding | Solve the programming task below in a Python markdown code block.
The weight of a sequence is defined as the number of unordered pairs of indexes $(i,j)$ (here $i \lt j$) with same value ($a_{i} = a_{j}$). For example, the weight of sequence $a = [1, 1, 2, 2, 1]$ is $4$. The set of unordered pairs of indexes with same ... | {"inputs": ["2\n4\n1 2 1 1\n4\n1 2 3 4\n", "2\n4\n1 2 2 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 1\n4\n1 2 3 4\n", "2\n4\n2 2 1 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 1\n4\n1 3 3 4\n", "2\n4\n1 2 2 1\n4\n1 4 3 4\n", "2\n4\n2 2 4 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 2\n4\n1 3 3 4\n"], "outputs": ["6\n0\n", "5\n0\n", "9\n0\n", "6\n0\n", "9\n4\n... | 587 | 247 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.
It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[... | {"functional": "def check(candidate):\n assert candidate(encoded = [3,1]) == [1,2,3]\n assert candidate(encoded = [6,5,4,6]) == [2,4,1,5,3]\n\n\ncheck(Solution().decode)"} | 145 | 64 |
coding | Solve the programming task below in a Python markdown code block.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to increase creativity by drawing pictures. Let's draw a pattern well using a square stamp.
I want t... | {"inputs": ["1\n2 3\nRRGG\nGGRB\nBRRR\nBRRR", "1\n2 1\nRRGG\nGGRB\nBRRR\nBRRR", "1\n2 1\nGGRR\nGGRB\nBRRR\nBRRR", "1\n1 1\nGGRR\nGGRB\nBRRR\nBRRR", "1\n2 3\nRRGG\nGGRB\nBRRR\nRRBR", "1\n2 1\nRRGG\nGGRB\nRRRB\nBRRR", "1\n2 4\nRRGG\nGGRB\nBRRR\nRRRB", "1\n4 1\nGRGR\nGGRB\nRRRB\nBRRR"], "outputs": ["6\n", "12\n", "9\n", "... | 551 | 214 |
coding | Solve the programming task below in a Python markdown code block.
## Task:
You have to write a function `pattern` which returns the following Pattern (See Pattern & Examples) upto `n` number of rows.
* Note: `Returning` the pattern is not the same as `Printing` the pattern.
### Rules/Note:
* If `n < 1` then it shoul... | {"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['21\\n2'], ['54321\\n5432\\n543\\n54\\n5'], [''], ['']]\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, t... | 448 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Everlasting Sa-Ga, a new, hot and very popular role-playing game, is out on October 19, 2008. Fans have been looking forward to a new title of Everlasting Sa-Ga.
Little Jimmy is in trouble. He is a seven-year-old boy, and he obtained the Everlasting Sa-... | {"inputs": ["4 3\n8 20\n0 0", "8 3\n8 20\n0 0", "4 3\n6 20\n0 0", "6 3\n8 20\n0 0", "6 6\n8 20\n0 0", "9 30\n7 6\n0 0", "4 6\n8 20\n0 0", "6 3\n8 26\n0 0"], "outputs": ["b\nb\n", "b\nb\n", "b\nb\n", "b\nb\n", "b\nb\n", "a\na\n", "a\nb\n", "b\nb\n"]} | 560 | 166 |
coding | Solve the programming task below in a Python markdown code block.
A permutation p of size n is the sequence p_1, p_2, ..., p_{n}, consisting of n distinct integers, each of them is from 1 to n (1 ≤ p_{i} ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition p_{p}_{i} = n ... | {"inputs": ["1\n", "2\n", "4\n", "5\n", "3\n", "6\n", "7\n", "8\n"], "outputs": ["1 \n", "-1\n", "2 4 1 3 \n", "2 5 3 1 4 \n", "-1\n", "-1\n", "-1\n", "2 8 4 6 3 5 1 7 \n"]} | 259 | 102 |
coding | Solve the programming task below in a Python markdown code block.
You'll be given an array A of N integers as input. For each element of the array A[i], print A[i]-1.
Input:
There will be N+1 iines of input each consisting of a single integer.
Integer in first line denotes N
For the following N lines the integer in i... | {"inputs": ["9\n1\n2\n3\n4\n5\n6\n7\n8\n9"], "outputs": ["0\n1\n2\n3\n4\n5\n6\n7\n8"]} | 145 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the ph... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "1\n2 7\n", "1\n0 1\n", "1\n5 10\n", "1\n2 10\n", "1\n5 10\n"], "outputs": ["1\n", "1\n", "1\n", "14\n", "0\n", "50\n", "20\n", "50\n"]} | 418 | 109 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $a$ and $m$. Calculate the number of integers $x$ such that $0 \le x < m$ and $\gcd(a, m) = \gcd(a + x, m)$.
Note: $\gcd(a, b)$ is the greatest common divisor of $a$ and $b$.
-----Input-----
The first line contains the sing... | {"inputs": ["3\n4 9\n5 10\n42 9999999967\n", "3\n4 5\n5 10\n42 9999999967\n", "3\n4 5\n8 10\n42 9999999967\n", "3\n4 9\n5 10\n42 9999999967\n", "3\n4 14\n5 10\n42 9999999967\n", "3\n4 27\n5 10\n42 9999999967\n", "3\n4 45\n5 10\n42 9999999967\n", "3\n4 75\n5 10\n42 9999999967\n"], "outputs": ["6\n1\n9999999966\n", "4\n1... | 282 | 365 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
Each digit is represented with number of '1' characters equal to the value of that digit... | {"inputs": ["1\n1\n", "1\n1\n", "2\n10\n", "2\n10\n", "3\n111\n", "3\n100\n", "3\n100\n", "3\n110\n"], "outputs": ["1\n", "1\n", "10\n", "10\n", "3\n", "100\n", "100\n", "20\n"]} | 245 | 103 |
coding | Solve the programming task below in a Python markdown code block.
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believ... | {"inputs": ["1 1\n4\n4\n", "1 1\n4\n4\n", "1 2\n1\n1 0\n", "1 2\n2\n1 2\n", "1 2\n2\n1 2\n", "1 2\n1\n1 0\n", "6 1\n4 2 7 3 1 8\n9\n", "1 6\n3\n6 8 2 4 5 3\n"], "outputs": ["4\n", "4\n", "1\n", "2\n", "2\n", "1\n", "\n", "3\n"]} | 484 | 145 |
coding | Solve the programming task below in a Python markdown code block.
You are given a positive integer $N$. Print a numerical triangle of height $N-1$ like the one below:
1
22
333
4444
55555
......
Can you do it using only arithmetic operations, a single for loop and print statement?
Use no more than two lines. The ... | {"inputs": ["5\n"], "outputs": ["1\n22\n333\n4444\n"]} | 191 | 26 |
coding | Solve the programming task below in a Python markdown code block.
It's the fourth quater of the Super Bowl and your team is down by 4 points. You're 10 yards away from the endzone, if your team doesn't score a touchdown in the next four plays you lose. On a previous play, you were injured and rushed to the hospital. Yo... | {"functional": "_inputs = [[[[8, 'pass'], [5, 'sack'], [3, 'sack'], [5, 'run']]], [[[12, 'pass'], [], [], []]], [[[2, 'run'], [5, 'pass'], [3, 'sack'], [8, 'pass']]], [[[5, 'pass'], [6, 'turnover'], [], []]], [[[5, 'pass'], [5, 'pass'], [10, 'sack'], [10, 'run']]], [[[5, 'pass'], [5, 'run'], [1, 'run'], []]], [[[6, 'ru... | 435 | 590 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The appeal of a string is the number of distinct characters found in the string.
For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.
Given a string s, return the total ap... | {"functional": "def check(candidate):\n assert candidate(s = \"abbca\") == 28\n assert candidate(s = \"code\") == 20\n\n\ncheck(Solution().appealSum)"} | 122 | 47 |
coding | Solve the programming task below in a Python markdown code block.
A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $5$ players in one team for each match). There are $N$ candidate players in the competition that will be trained by Pak Chane... | {"inputs": ["1 2\n1\n", "1 2\n2\n", "1 2\n3\n", "2 4\n1 2\n", "2 3\n1 2\n", "3 8\n3 2 1\n", "4 3\n2 2 5 2\n", "4 13\n3 2 1 3\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "2\n", "0\n"]} | 533 | 123 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a number and your task will be to rearrange the number so that it is divisible by `25`, but without leading zeros. Return the minimum number of digit moves that are needed to make this possible. If impossible, return `-1` ... | {"functional": "_inputs = [[50], [25], [52], [57], [75], [100], [521], [1], [5071], [705], [1241367], [50011117], [1002], [50011111112], [2057], [50001111312], [500111117], [64954713879], [71255535569], [72046951686], [68151901446], [3848363615], [75733989998], [87364011400], [2992127830], [98262144757], [81737102196],... | 109 | 651 |
coding | Solve the programming task below in a Python markdown code block.
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).
The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.
You, a magical girl... | {"inputs": ["3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n4 9", "3 3 3\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 1", "3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n8 9", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8\n", "4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 1\n2 2"... | 578 | 290 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I.
* insert $k$: Insert a node containing $k$ as key into $T$.
* find $k$: Report whether $T$ has a node containin... | {"inputs": ["10\ninsert 30\ninsert 88\ninsert 3\ninsert 2\ninsert 20\nfind 12\ninsert 1\ninsert 24\nfind 2\nprint", "10\ninsert 30\ninsert 88\ninsert 3\ninsert 2\ninsert 20\nfind 12\ninsert 1\ninsert 24\nfind 16\nprint", "10\ninsert 30\ninsert 88\ninsert 12\ninsert 2\ninsert 20\nfind 8\ninsert 1\ninsert 24\nfind 16\npr... | 413 | 749 |
coding | Solve the programming task below in a Python markdown code block.
Xorgon is an extremely delicious treat formed by the sequence $S$ of binary integers $s_1, s_2,..,s_N$. A really interesting property found in a Xorgon is that the xor of all elements in any contiguous subsequence of length $K$ in $S$ will result in $1$.... | {"inputs": ["7 5\n1 0 0 1 1 1 1"], "outputs": ["1"]} | 375 | 28 |
coding | Solve the programming task below in a Python markdown code block.
There is a grid, consisting of $2$ rows and $m$ columns. The rows are numbered from $1$ to $2$ from top to bottom. The columns are numbered from $1$ to $m$ from left to right.
The robot starts in a cell $(1, 1)$. In one second, it can perform either of ... | {"inputs": ["4\n3\n0 0 1\n4 3 2\n5\n0 4 8 12 16\n2 6 10 14 18\n4\n0 10 10 10\n10 10 10 10\n2\n0 0\n0 0\n"], "outputs": ["5\n19\n17\n3\n"]} | 574 | 98 |
coding | Solve the programming task below in a Python markdown code block.
Find the second-to-last element of a list.
Example:
```python
penultimate([1,2,3,4]) # => 3
penultimate(["Python is dynamic"]) # => 'i'
(courtesy of [haskell.org](http://www.haskell.org/haskellwiki/99_questions/1_to_10))
```
Also feel free to... | {"functional": "_inputs = [[[1, 2, 3, 4]], ['hello']]\n_outputs = [[3], ['l']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n... | 109 | 170 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.
In one operation, you can pick an index ... | {"functional": "def check(candidate):\n assert candidate(target = \"10111\") == 3\n assert candidate(target = \"101\") == 3\n assert candidate(target = \"00000\") == 0\n\n\ncheck(Solution().minFlips)"} | 154 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.
In one move, we may choose two adjacent nodes and move one coi... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,0,0])) == 2\n assert candidate(root = tree_node([0,3,0])) == 3\n\n\ncheck(Solution().distributeCoins)"} | 185 | 56 |
coding | Solve the programming task below in a Python markdown code block.
The [Ones' Complement](https://en.wikipedia.org/wiki/Ones%27_complement) of a binary number is the number obtained by swapping all the 0s for 1s and all the 1s for 0s. For example:
```
onesComplement(1001) = 0110
onesComplement(1001) = 0110
```
For any... | {"functional": "_inputs = [['0'], ['1'], ['01'], ['10'], ['1101']]\n_outputs = [['1'], ['0'], ['10'], ['01'], ['0010']]\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 ... | 149 | 190 |
coding | Solve the programming task below in a Python markdown code block.
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: 'U': go up, (x, y) → (x, y... | {"inputs": ["0 0\nD\n", "0 1\nD\n", "0 1\nD\n", "0 0\nD\n", "2 2\nRU\n", "1 2\nRU\n", "0 -1\nU\n", "-1 0\nR\n"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n"]} | 465 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of n integers arr.
The interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|... | {"functional": "def check(candidate):\n assert candidate(arr = [2,1,3,1,2,3,3]) == [4,2,7,2,4,4,5]\n assert candidate(arr = [10,5,10,10]) == [5,0,3,4]\n\n\ncheck(Solution().getDistances)"} | 145 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Doremy is asked to test $n$ contests. Contest $i$ can only be tested on day $i$. The difficulty of contest $i$ is $a_i$. Initially, Doremy's IQ is $q$. On day $i$ Doremy will choose whether to test contest $i$ or not. She can only test a contest if her c... | {"inputs": ["5\n1 1\n1\n2 1\n1 2\n3 1\n1 2 1\n4 2\n1 4 3 1\n5 2\n5 1 2 4 3\n", "2\n10 999999999\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n5 1000000000\n1000000000 1 2 3 4\n"], "outputs": ["1\n11\n101\n1011\n01111\n", "1111111111\n11111\n"]} | 609 | 260 |
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.
For an array $B$, while it has more than one element, you can apply an operation on it - you choose any two elements $x,y$ (they may be the same val... | {"inputs": ["10 \n0 1 2 3 4 5 6 7 8 9"], "outputs": ["160"]} | 580 | 37 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in wi... | {"functional": "def check(candidate):\n assert candidate(box = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 6\n assert candidate(box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]]) == 10\n\n\ncheck(Solution().pileBox)"} | 148 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
- There exists a non-negative integer... | {"inputs": ["2 46\n6 10", "2 85\n6 10", "2 50\n4 10", "2 62\n6 10", "2 50\n6 10", "2 50\n6 10\n", "2 46\n10 10", "2 12\n10 10"], "outputs": ["2\n", "3\n", "0\n", "2\n", "2", "2\n", "5\n", "1\n"]} | 354 | 128 |
coding | Solve the programming task below in a Python markdown code block.
For a given sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, find a specific value $k$ given as a query.
Constraints
* $1 \leq n \leq 100,000$
* $1 \leq q \leq 200,000$
* $0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,... | {"inputs": ["4\n1 2 2 4\n3\n2\n3\n6", "4\n1 1 2 4\n3\n0\n3\n8", "4\n0 1 2 6\n3\n0\n3\n6", "4\n1 2 1 4\n2\n0\n3\n8", "4\n0 1 2 7\n1\n0\n5\n3", "4\n0 2 3 4\n3\n2\n3\n4", "4\n0 2 2 1\n3\n4\n3\n0", "4\n1 1 1 4\n2\n0\n1\n8"], "outputs": ["1\n0\n0\n", "0\n0\n0\n", "1\n0\n1\n", "0\n0\n", "1\n", "1\n1\n1\n", "0\n0\n1\n", "0\n1... | 335 | 214 |
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 | Solve the programming task below in a Python markdown code block.
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls).
... | {"inputs": ["A\n", "B\n", "C\n", "D\n", "@\n", "E\n", "F\n", "G\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 424 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.
If the town judge exists, then:
The town judge trusts nobody.
Everybody (except for the town ju... | {"functional": "def check(candidate):\n assert candidate(n = 2, trust = [[1,2]]) == 2\n assert candidate(n = 3, trust = [[1,3],[2,3]]) == 3\n assert candidate(n = 3, trust = [[1,3],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().findJudge)"} | 195 | 88 |
coding | Solve the programming task below in a Python markdown code block.
We have N non-negative integers: A_1, A_2, ..., A_N.
Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.
Let the beauty of the painting be the \mbox{XOR} of the integers painted in red, plus the \mbox... | {"inputs": ["3\n5 6 5", "3\n4 6 5", "3\n4 8 5", "3\n4 8 9", "3\n4 8 4", "3\n5 8 5", "3\n0 6 5", "3\n8 8 9"], "outputs": ["8\n", "7\n", "17\n", "21\n", "16\n", "18\n", "11\n", "9\n"]} | 452 | 115 |
coding | Solve the programming task below in a Python markdown code block.
*“You won’t get caught if you hide behind someone.”*
Sang-Woo advises Gi-Hun to hide behind someone to avoid getting shot.
Gi-Hun follows Sang-Woo's advice and hides behind Ali, who saved his life earlier. Gi-Hun and Ali both have the same height, K. M... | {"inputs": ["3\n4 10\n2 13 4 16\n5 8\n9 3 8 8 4\n4 6\n1 2 3 4"], "outputs": ["2\n1\n0"]} | 679 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applicati... | {"inputs": ["300000 1\n1 86053\n", "300000 1\n2 86053\n", "300000 1\n1 300000\n", "300000 1\n1 300000\n", "3 4\n1 3\n1 1\n1 2\n2 3\n", "4 4\n1 3\n1 1\n1 2\n2 3\n", "4 4\n1 3\n2 1\n1 2\n2 3\n", "4 4\n1 1\n2 1\n1 2\n2 3\n"], "outputs": ["1\n", "0\n", "1\n", "1\n\n", "1\n2\n3\n2\n", "1\n2\n3\n2\n", "1\n1\n2\n1\n", "1\n0\n... | 648 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Salve, mi amice.
Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus.
Rp:
I Aqua Fortis
I Aqua Regia
II Amalgama
VII Minium
IV Vitriol
Misce ... | {"inputs": ["0 0 0 0 0\n", "1 1 2 7 4\n", "1 0 2 7 4\n", "1 1 2 6 4\n", "1 1 1 7 4\n", "1 2 2 7 4\n", "1 1 3 7 4\n", "1 1 2 6 4\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]} | 196 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The set [1, 2, 3, ..., n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
"123"
"132"
"213"
"231"
"312"
"321"
Given n an... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 3) == \"213\"\n assert candidate(n = 4, k = 9) == \"2314\"\n assert candidate(n = 3, k = 1) == \"123\"\n\n\ncheck(Solution().getPermutation)"} | 140 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Recently, Chef visited his doctor. The doctor advised Chef to drink at least 2000 ml of water each day.
Chef drank X ml of water today. Determine if Chef followed the doctor's advice or not.
------ Input Format ------
- The first line contains a sin... | {"inputs": ["3\n2999\n1450\n2000\n"], "outputs": ["YES\nNO\nYES\n"]} | 356 | 33 |
coding | Solve the programming task below in a Python markdown code block.
A function receives a certain numbers of integers ```n1, n2, n3 ..., np```(all positive and different from 0) and a factor ```k, k > 0```
The function rearranges the numbers ```n1, n2, ..., np``` in such order that generates the minimum number concatena... | {"functional": "_inputs = [[4, 32, 3, 34, 7, 12], [10, 32, 3, 34, 7, 12]]\n_outputs = [['Rearrangement: 12, 3, 34, 7, 32 generates: 12334732 divisible by 4'], ['There is no possible rearrangement']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.is... | 477 | 239 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, we are going to see how a Hash (or Map or dict) can be used to keep track of characters in a string.
Consider two strings `"aabcdefg"` and `"fbd"`. How many characters do we have to remove from the first string to get the second string? ... | {"functional": "_inputs = [['xyz', 'yxz'], ['abcxyz', 'ayxz'], ['abcdexyz', 'yxz'], ['xyz', 'yxxz'], ['abdegfg', 'ffdb'], ['aabcdefg', 'fbd']]\n_outputs = [[0], [2], [5], [0], [0], [5]]\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, r... | 202 | 216 |
coding | Solve the programming task below in a Python markdown code block.
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1... | {"inputs": ["2\n-1 0 1\n", "2\n-1 -1 1\n", "2\n50 54 50\n", "2\n50 50 50\n", "3\n-1 1 1 1 1\n", "3\n-2 3 4 5 6\n", "3\n-2 3 0 5 6\n", "2\n-1 -112 -1\n"], "outputs": ["2\n", "3\n", "154\n", "150\n", "5\n", "20\n", "16\n", "112\n"]} | 287 | 152 |
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 | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui and vi. There exists a unique path between each pair of ci... | {"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[1,2],[2,3],[2,4]]) == [3,4,0]\n assert candidate(n = 2, edges = [[1,2]]) == [1]\n assert candidate(n = 3, edges = [[1,2],[2,3]]) == [2,1]\n\n\ncheck(Solution().countSubgraphsForEachDiameter)"} | 272 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable.
For each i=2,3,...,2K, find the following value modulo 998244353:
- The number of combinations of N sides shown by the dice such that ... | {"inputs": ["3 6", "1 5", "2 3", "5 3", "5 5", "3 5", "4 8", "6 6"], "outputs": ["13\n13\n4\n13\n13\n", "0\n", "2\n2\n2\n", "30\n30\n25\n25\n20\n25\n25\n30\n30\n", "91\n91\n61\n61\n36\n61\n61\n91\n91\n", "11\n11\n4\n11\n11\n", "81\n81\n32\n32\n32\n81\n81\n", "336\n336\n231\n231\n146\n146\n146\n231\n231\n336\n336\n"]} | 420 | 217 |
coding | Solve the programming task below in a Python markdown code block.
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registr... | {"inputs": ["1\nn\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\no\n", "1\np\n", "2\nu\nu\n", "2\nv\nu\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\nu1\n", "OK\nOK\n"]} | 378 | 95 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.
For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.
Gi... | {"functional": "def check(candidate):\n assert candidate(nums = [4,2,5,3]) == 7\n assert candidate(nums = [5,6,7,8]) == 8\n assert candidate(nums = [6,2,1,2,4,5]) == 10\n\n\ncheck(Solution().maxAlternatingSum)"} | 222 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$.
Chef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i<j<k≤N$1 \leq i < j < k \leq N$ and P$P$ in the following expression contains an odd number of ones in its binar... | {"inputs": ["1\n4\n1 1 2 3"], "outputs": ["1"]} | 532 | 22 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rooted tree of $2^n - 1$ vertices. Every vertex of this tree has either $0$ children, or $2$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children is the left one, and t... | {"inputs": ["2\nBAA\n", "2\nABA\n", "2\nAAB\n", "2\nAAA\n", "2\nBBB\n", "2\nBBB\n", "2\nAAB\n", "2\nBBB\n"], "outputs": ["1\n", "2\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 593 | 92 |
coding | Solve the programming task below in a Python markdown code block.
You have to create a method "compoundArray" which should take as input two int arrays of different length and return one int array with numbers of both arrays shuffled one by one.
```Example:
Input - {1,2,3,4,5,6} and {9,8,7,6}
Output - {1,9,2,8,3,7,4... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6], [9, 8, 7, 6]], [[0, 1, 2], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [[11, 12], [21, 22, 23, 24]], [[2147483647, 2147483646, 2147483645, 2147483644, 2147483643], [9]], [[214, 215, 216, 217, 218], []], [[], [214, 215, 219, 217, 218]], [[], []]]\n_outputs = [[[1, 9, 2, 8, 3, 7, 4, 6... | 128 | 571 |
coding | Solve the programming task below in a Python markdown code block.
A: A-Z Cat / A-Z Cat
story
Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. It's so cute. Aizu Nyan was asked by her friend Joy to take care of her cat. It is a... | {"inputs": ["AOZUNYANPERIPERO", "OREQIRMQEAYNUYOA", "OREPIREPNAYNUZOA", "OREPIRNPEAYNUZOA", "OREQIRNPEAYNUZOA", "OREQIRMPEAYNUZOA", "AOZUNYAEPMRIQERO", "OREQIRMQEAYNUZOA"], "outputs": ["AZ\n", "-1\n", "AZ\n", "AZ\n", "AZ\n", "AZ\n", "AZ\n", "AZ\n"]} | 585 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Two tortoises named ***A*** and ***B*** must run a race. ***A*** starts with an average speed of ```720 feet per hour```.
Young ***B*** knows she runs faster than ***A***, and furthermore has not finished her cabbage.
When she starts, at last, she can s... | {"functional": "_inputs = [[720, 850, 70], [80, 91, 37], [80, 100, 40], [720, 850, 37], [720, 850, 370], [120, 850, 37], [820, 850, 550], [820, 81, 550]]\n_outputs = [[[0, 32, 18]], [[3, 21, 49]], [[2, 0, 0]], [[0, 17, 4]], [[2, 50, 46]], [[0, 3, 2]], [[18, 20, 0]], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n... | 509 | 334 |
coding | Solve the programming task below in a Python markdown code block.
Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B.
The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on ... | {"inputs": ["2\n3\n5", "2\n3\n6", "2\n3\n4", "2\n6\n4", "2\n6\n5", "2\n6\n6", "2\n9\n6", "2\n0\n6"], "outputs": ["9\n", "10\n", "8\n", "11\n", "12\n", "13\n", "16\n", "7\n"]} | 340 | 99 |
coding | Solve the programming task below in a Python markdown code block.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish... | {"inputs": ["1\n1\n", "1\n17\n", "2\n1 2\n", "1\n500\n", "1\n987\n", "1\n585\n", "1\n435\n", "1\n474\n"], "outputs": ["1\n", "17\n", "1\n", "500\n", "987\n", "585\n", "435\n", "474\n"]} | 577 | 110 |
coding | Solve the programming task below in a Python markdown code block.
There is a building with 2N floors, numbered 1, 2, \ldots, 2N from bottom to top.
The elevator in this building moved from Floor 1 to Floor 2N just once.
On the way, N persons got on and off the elevator. Each person i (1 \leq i \leq N) got on at Floor A... | {"inputs": ["1\n1 2\n", "1\n1 2\n", "2\n1 4\n2 3\n", "2\n4 1\n2 4\n", "2\n3 -1\n-1 2\n", "3\n3 6\n1 -1\n1 -1\n", "3\n1 4\n-1 6\n-1 6\n", "3\n1 -1\n-1 4\n-1 6\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n"]} | 506 | 143 |
coding | Solve the programming task below in a Python markdown code block.
Write a function that outputs the transpose of a matrix - a new matrix
where the columns and rows of the original are swapped.
For example, the transpose of:
| 1 2 3 |
| 4 5 6 |
is
| 1 4 |
| 2 5 |
| 3 6 |
The input to your func... | {"functional": "_inputs = [[[[1]]], [[[1, 2, 3]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]]]]\n_outputs = [[[[1]]], [[[1], [2], [3]]], [[[1, 4, 7], [2, 5, 8], [3, 6, 9]]], [[[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-... | 147 | 326 |
coding | Solve the programming task below in a Python markdown code block.
You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (x_{i}, y_{i}). We know that no two bombs are at the same point and that no bomb is at point w... | {"inputs": ["2\n1 0\n1 0\n", "2\n1 1\n1 0\n", "2\n2 1\n0 -1\n", "2\n2 1\n1 -1\n", "2\n2 2\n1 -1\n", "2\n2 0\n1 -1\n", "2\n3 0\n1 -1\n", "2\n1 0\n1 -1\n"], "outputs": ["8\n1 1 R\n2\n1 1 L\n3\n1 1 R\n2\n1 1 L\n3\n", "10\n1 1 R\n2\n1 1 L\n3\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n", "10\n1 1 D\n2\n1 1 U\n3\n1 2 R\n1 1 U\n2\n1 ... | 745 | 455 |
coding | Solve the programming task below in a Python markdown code block.
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and lon... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 535 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in ... | {"inputs": ["1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3"], "outputs": ["10"]} | 400 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$.
Your task is to reorder... | {"inputs": ["1\n5\n3 1 2 4 5\n2 4 5 1 3"], "outputs": ["3 1 2 4 5"]} | 557 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese here
------ Problem Statement ------
As we know, Fibonacci Number is defined as
F_{n}=n if n ≤ 1
F_{n}=F_{n-1}+F_{n-2}, otherwise
Now this problem is quite simple: you are given one prime number P a... | {"inputs": ["4\n0 11\n16 19\n18 19\n4 19"], "outputs": ["0\n14\n16\n-1"]} | 436 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absol... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n1\n", "1 1\n0\n", "1 4\n-3\n", "1 1\n-1\n", "1 4\n-3\n", "1 1\n-1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | 395 | 106 |
coding | Solve the programming task below in a Python markdown code block.
Given a sequence of items and a specific item in that sequence, return the item immediately following the item specified. If the item occurs more than once in a sequence, return the item after the first occurence. This should work for a sequence of any t... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8], 3], [['a', 'b', 'c'], 'd'], [['a', 'b', 'c'], 'c'], ['testing', 't'], ['Hello!', 'o'], ['Hello!', '!'], ['Hello!', 'x']]\n_outputs = [[4], [None], [None], ['e'], ['!'], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins... | 180 | 243 |
coding | Solve the programming task below in a Python markdown code block.
G --Derangement / Derangement
Story
Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a crush on C... | {"inputs": ["5\n2 1 3 5 4", "5\n2 1 0 5 4", "5\n4 1 0 5 4", "5\n4 1 0 5 6", "5\n4 0 0 5 6", "5\n4 0 0 0 3", "5\n4 0 1 0 3", "5\n7 0 1 0 3"], "outputs": ["4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 526 | 142 |
coding | Solve the programming task below in a Python markdown code block.
You've got a string $S$ consisting of $n$ lowercase English letters from your friend. It turned out that this is a number written in poman numerals. The poman numeral system is long forgotten. All that's left is the algorithm to transform number from pom... | {"inputs": ["2 -1\nba\n", "3 1\nabc\n", "3 3\nabc\n", "3 5\nabc\n", "3 7\nabc\n", "3 0\ncaa\n", "3 -7\nabc\n", "3 -3\nabc\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 598 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Write a function called `LCS` that accepts two sequences and returns the longest subsequence common to the passed in sequences.
### Subsequence
A subsequence is different from a substring. The terms of a subsequence need not be consecutive terms of the ... | {"functional": "_inputs = [['a', 'b'], ['a', 'a'], ['abc', 'ac'], ['abcdef', 'abc'], ['abcdef', 'acf'], ['anothertest', 'notatest'], ['132535365', '123456789'], ['finaltest', 'zzzfinallyzzz']]\n_outputs = [[''], ['a'], ['ac'], ['abc'], ['acf'], ['nottest'], ['12356'], ['final']]\nimport math\ndef _deep_eq(a, b, tol=1e-... | 424 | 249 |
coding | Solve the programming task below in a Python markdown code block.
Chef loves to play with iron (Fe) and magnets (Ma). He took a row of $N$ cells (numbered $1$ through $N$) and placed some objects in some of these cells. You are given a string $S$ with length $N$ describing them; for each valid $i$, the $i$-th character... | {"inputs": ["2\n4 5\nI::M\n9 10\nMIM_XII:M"], "outputs": ["1\n2"]} | 757 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tai... | {"inputs": ["3 3\n", "3 4\n", "5 3\n", "9 9\n", "3 5\n", "3 6\n", "7 3\n", "7 4\n"], "outputs": ["###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n", "#####\n....#\n#####\n", "######\n.....#\n######\n... | 302 | 192 |
coding | Solve the programming task below in a Python markdown code block.
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consistin... | {"inputs": ["a\nab\n1\na\n", "a\na\n1\nab\n", "b\naa\n1\na\n", "c\na\n1\nab\n", "a\na\n1\nab\n", "b\naa\n1\na\n", "c\na\n1\nab\n", "a\nab\n1\na\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 678 | 118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.