problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
In ChefLand, there is a mountain range consisting of $N$ hills (numbered $1$ through $N$) in a straight line. Let's denote the height of the $i$-th hill from the left by $h_i$.
Ada is working on the water supply system of ChefLand. On some of the hills, ... | {"inputs": ["1\n6\n4 16 32 6 8 2\n"], "outputs": ["2 "]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
You are given an array of $n$ integers $a_1, a_2, \ldots, a_n$. After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation.
In one operation, you choose $n-1$ elements of the array and replace each o... | {"inputs": ["4\n3\n42 42 42\n5\n1 2 3 4 5\n4\n4 3 2 1\n3\n24 2 22\n"], "outputs": ["YES\nYES\nNO\nNO\n"]} | coding | 551 |
Solve the programming task below in a Python markdown code block.
Karan's company makes software that provides different features based on the version of operating system of the user.
For finding which version is more recent, Karan uses the following method:
While this function worked for OS versions 10.6, 10.7, 10.8... | {"functional": "_inputs = [['11', '10'], ['11', '11'], ['10.4.6', '10.4'], ['10.4', '10.4.8'], ['10.4', '11'], ['10.4.9', '10.5'], ['4.3.3', '4.3.3.1'], ['10.4.9', '104.9'], ['10.15', '10.12']]\n_outputs = [[True], [True], [True], [False], [False], [False], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol... | coding | 477 |
Solve the programming task below in a Python markdown code block.
# Sort an array by value and index
Your task is to sort an array of integer numbers by the product of the value and the index of the positions.
For sorting the index starts at 1, NOT at 0!
The sorting has to be ascending.
The array will never be null a... | {"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[23, 2, 3, 4, 5]], [[26, 2, 3, 4, 5]], [[9, 5, 1, 4, 3]]]\n_outputs = [[[1, 2, 3, 4, 5]], [[2, 3, 4, 23, 5]], [[2, 3, 4, 5, 26]], [[1, 9, 5, 3, 4]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo... | coding | 288 |
Solve the programming task below in a Python markdown code block.
Chef has $K$ chocolates and he wants to distribute them to $N$ people (numbered $1$ through $N$). These people are standing in a line in such a way that for each $i$ ($1 \le i \le N-1$), person $i$ and person $i+1$ are adjacent.
First, consider some way ... | {"inputs": ["1\n3\n2"], "outputs": ["2"]} | coding | 754 |
Solve the programming task below in a Python markdown code block.
Johnny has a pool in his garden. There are several islands in the pool. Some islands are connected by bridges. Any bridge can be removed. Every day Johnny removes some bridges so that there is only one way from any island to any other. In the evening he ... | {"inputs": ["1\n4\n0111\n1011\n1101\n1110\n2\n1 2\n3 4"], "outputs": ["4"]} | coding | 376 |
Solve the programming task below in a Python markdown code block.
The squarefree part of a positive integer is the largest divisor of that integer which itself has no square factors (other than 1). For example, the squareefree part of 12 is 6, since the only larger divisor is 12, and 12 has a square factor (namely, 4).... | {"functional": "_inputs = [[0], [-100], [2.5]]\n_outputs = [[None], [None], [None]]\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 Fa... | coding | 271 |
Solve the programming task below in a Python markdown code block.
There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the numbe... | {"inputs": ["3 3\n", "4 2\n", "5 5\n", "6 4\n", "1 1\n", "1 2\n", "2 1\n", "1 4\n"], "outputs": ["GBGBGB\n", "BGBGBB\n", "GBGBGBGBGB\n", "BGBGBGBGBB\n", "GB\n", "GBG\n", "BGB\n", "GBGGG\n"]} | coding | 313 |
Solve the programming task below in a Python markdown code block.
Chef has two integers X and Y. Chef wants to perform some operations to make both X and Y zero simultaneously. In one operation, Chef can either:
set X := 2 \cdot X
or set Y := 2 \cdot Y
or set X := X - 1 and Y := Y - 1
Chef is a little busy with prepar... | {"inputs": ["2\n1 2\n99999999999999999 99999999999999999"], "outputs": ["3\n99999999999999999"]} | coding | 446 |
Solve the programming task below in a Python markdown code block.
You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] containing distinct positive integers.
Let B be a [permutation] of A. Define the *value* of B to be
\sum_{i=1}^N (B_{i} \bmod{B_{i+1}})
where B_{N+1} is treated to be B_{1}.
Find the maximum *va... | {"inputs": ["2\n2\n5 13\n4\n11 5 14869010166 19007432007\n"], "outputs": ["8\n14869010184\n"]} | coding | 755 |
Solve the programming task below in a Python markdown code block.
The most dangerous cyborg Jenish is finally entrapped on a narrow bridge over a valley. The bridge is $N$ meters long. For convenience, position $i$ represents a portion of bridge between whose left border is at distance $i-1$ meters from left end and ri... | {"inputs": ["3\n4 8\n5 1 4 2\n3 4\n3 1 2\n2 7\n5 5"], "outputs": ["YES\nYES\nNO"]} | coding | 721 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid ... | {"functional": "def check(candidate):\n assert candidate(grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]) == 3\n assert candidate(grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]]) == 2\n\n\ncheck(Solution().largestMagicSquare)"} | coding | 143 |
Solve the programming task below in a Python markdown code block.
On an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers.
There are unpaved roads between every pair of points for which either the x coordinates are equal and the difference ... | {"inputs": ["2 2\n3\n6\n2\n7", "2 2\n3\n9\n2\n7", "2 2\n3\n9\n0\n7", "2 2\n3\n9\n1\n7", "2 2\n1\n8\n1\n7", "2 2\n3\n5\n2\n7", "2 2\n3\n16\n2\n7", "2 2\n3\n32\n2\n7"], "outputs": ["31\n", "35\n", "29\n", "32\n", "27\n", "29", "42\n", "58\n"]} | coding | 392 |
Solve the programming task below in a Python markdown code block.
Mathematician Shikhar has invented a new type of fibonacci series in which
fib(1)=a
fib(2)=b
fib(n)=(fib(n-1)+fib(n-2))%1000000007 for all n>2
and now help him find the nth term of this series.
Input contains 3 space separated integers a,b and n.... | {"inputs": ["2 4 35"], "outputs": ["29860704"]} | coding | 160 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist.
-----... | {"inputs": ["1\n3\n4 4 4", "1\n3\n2 5 1", "1\n3\n4 6 4", "1\n3\n4 6 0", "1\n3\n4 6 3", "1\n3\n2 2 3", "1\n3\n4 4 0", "1\n3\n7 6 3"], "outputs": ["3\n1 2 3 \n", "2\n2 3 \n", "1\n2 \n", "1\n2 \n", "1\n2 \n", "1\n3 \n", "1\n3 \n", "1\n2 \n"]} | coding | 377 |
Solve the programming task below in a Python markdown code block.
Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without reveali... | {"inputs": ["2 1\n1 2 1 3\n1 2\n", "2 1\n4 5 6 7\n4 7\n", "2 1\n1 2 1 3\n1 2\n", "2 1\n4 5 6 7\n4 7\n", "2 1\n1 4 1 3\n1 2\n", "2 1\n4 6 6 7\n4 7\n", "2 1\n3 6 6 7\n4 7\n", "2 2\n1 2 3 4\n1 5 3 4\n"], "outputs": ["1\n", "-1\n", "1", "-1", "1\n", "-1\n", "7\n", "1\n"]} | coding | 754 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.
A string is said to be palindrome if it the same string when reversed.
... | {"functional": "def check(candidate):\n assert candidate(s = \"abcbdd\") == True\n assert candidate(s = \"bcbddxy\") == False\n\n\ncheck(Solution().checkPartitioning)"} | coding | 99 |
Solve the programming task below in a Python markdown code block.
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this ... | {"inputs": ["2 1 1\n1 2 1\n2 1000000000\n", "2 1 1\n1 2 1\n2 1100000000\n", "2 1 1\n1 2 1\n2 1100000100\n", "3 2 2\n1 2 4\n2 3 4\n2 2\n3 6\n", "3 2 2\n1 3 4\n2 3 4\n2 2\n3 2\n", "3 2 2\n1 3 4\n2 3 4\n2 2\n3 6\n", "3 2 2\n1 2 100\n2 3 1\n2 1\n3 3\n", "2 2 3\n1 2 2\n2 1 3\n2 2\n2 2\n2 3\n"], "outputs": ["1", "1\n", "1\n"... | coding | 456 |
Solve the programming task below in a Python markdown code block.
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.
Consider two infinite sets of numbers. The first set consists of odd positive... | {"inputs": ["1 3\n", "1 1\n", "1 1\n", "1 3\n", "5 14\n", "1 15\n", "1 15\n", "1 28\n"], "outputs": ["7", "1", "1\n", "7\n", "105", "135", "135\n", "434\n"]} | coding | 600 |
Solve the programming task below in a Python markdown code block.
Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime ... | {"inputs": ["10\n3\n5", "10\n3\n9", "10\n3\n2", "10\n6\n2", "10\n1\n5", "10\n1\n2", "10\n2\n2", "10\n3\n4"], "outputs": ["4\n2\n3\n", "4\n2\n4\n", "4\n2\n1\n", "4\n3\n1\n", "4\n0\n3\n", "4\n0\n1\n", "4\n1\n1\n", "4\n2\n2\n"]} | coding | 159 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone.
A stone can be removed if it shares either the same row or the same column as another stone that ha... | {"functional": "def check(candidate):\n assert candidate(stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]) == 5\n assert candidate(stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]) == 3\n assert candidate(stones = [[0,0]]) == 0\n\n\ncheck(Solution().removeStones)"} | coding | 139 |
Solve the programming task below in a Python markdown code block.
You are organizing a boxing tournament, where $n$ boxers will participate ($n$ is a power of $2$), and your friend is one of them. All boxers have different strength from $1$ to $n$, and boxer $i$ wins in the match against boxer $j$ if and only if $i$ is... | {"inputs": ["4\n3 9 1 -1\n", "4\n1 -1 1 1\n", "4\n1 -1 1 1\n", "4\n3 9 0 -1\n", "4\n0 9 0 -1\n", "4\n3 9 1 -1\n", "2\n-1 1000000000\n", "2\n1000000000 -1\n"], "outputs": ["0", "1", "1\n", "0\n", "0\n", "0", "1000000000", "0"]} | coding | 665 |
Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky ... | {"inputs": ["4\n", "3\n", "8\n", "7\n", "2\n", "1\n", "5\n", "6\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 241 |
Solve the programming task below in a Python markdown code block.
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.
Then, by using a random generator they choose a random integer c... | {"inputs": ["3 1\n", "4 3\n", "5 5\n", "1 1\n", "1 1\n", "2 1\n", "2 2\n", "3 1\n"], "outputs": ["2", "2", "4", "1", "1", "2", "1", "2"]} | coding | 446 |
Solve the programming task below in a Python markdown code block.
Tenten runs a weapon shop for ninjas. Today she is willing to sell n shurikens which cost 1, 2, ..., n ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly si... | {"inputs": ["1\n+\n- 1\n", "1\n- 1\n+\n", "3\n+\n+\n+\n- 2\n- 1\n- 2\n", "3\n+\n+\n+\n- 2\n- 1\n- 3\n", "4\n+\n- 1\n+\n+\n- 4\n+\n- 2\n- 3\n", "4\n+\n+\n+\n- 3\n- 4\n+\n- 1\n- 2\n", "4\n+\n+\n+\n- 4\n- 4\n+\n- 1\n- 2\n", "4\n+\n+\n+\n- 3\n- 2\n+\n- 1\n- 2\n"], "outputs": ["YES\n1 ", "NO\n", "NO\n", "NO\n", "NO\n", "NO\... | coding | 694 |
Solve the programming task below in a Python markdown code block.
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How ... | {"inputs": ["aaba\n2\n", "ayi\n10\n", "ayi\n10\n", "ayi\n11\n", "yai\n20\n", "abaa\n2\n", "yai\n11\n", "aaab\n2\n"], "outputs": ["6\n", "12\n", "12\n", "14\n", "22\n", "6\n", "14\n", "4\n"]} | coding | 280 |
Solve the programming task below in a Python markdown code block.
Given is an integer N. Snuke will choose integers s_1, s_2, n_1, n_2, u_1, u_2, k_1, k_2, e_1, and e_2 so that all of the following six conditions will be satisfied:
* 0 \leq s_1 < s_2
* 0 \leq n_1 < n_2
* 0 \leq u_1 < u_2
* 0 \leq k_1 < k_2
* 0 \leq e_... | {"inputs": ["4\n2\n6\n1\n1001000000", "4\n0\n6\n6\n1001000000", "4\n0\n0\n9\n1001000101", "4\n1\n0\n9\n1000000101", "4\n2\n1\n9\n1001000001", "4\n6\n2\n7\n0010010100", "4\n6\n2\n5\n0010010100", "4\n4\n6\n15\n1000000000"], "outputs": ["0\n11\n0\n475432620\n", "0\n11\n11\n475432620\n", "0\n0\n1346\n301343122\n", "0\n0\n1... | coding | 453 |
Solve the programming task below in a Python markdown code block.
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N:
* If the frog is currently... | {"inputs": ["3 1\n4 8 1", "2 100\n10 9", "2 100\n7 10", "2 100\n17 9", "2 101\n3 21", "3 1\n0 20 10", "3 1\n9 20 10", "3 1\n1 20 10"], "outputs": ["11\n", "1\n", "3\n", "8\n", "18\n", "30\n", "21\n", "29\n"]} | coding | 358 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. Pair the integers $1$ to $2n$ (i.e. each integer should be in exactly one pair) so that each sum of matched pairs is consecutive and distinct.
Formally, let $(a_i, b_i)$ be the pairs that you matched. $\{a_1, b_1, a_2, b_2,... | {"inputs": ["1\n99988\n", "1\n99990\n", "1\n99992\n", "1\n99994\n", "1\n99996\n", "1\n99998\n", "1\n31704\n", "1\n100000\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 492 |
Solve the programming task below in a Python markdown code block.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display... | {"inputs": ["3\n1 2 3\n1 1 1\n", "3\n1 2 3\n1 1 1\n", "3\n1 3 3\n1 1 1\n", "3\n1 3 3\n1 0 1\n", "3\n1 0 3\n1 0 1\n", "3\n1 -1 3\n1 0 1\n", "3\n1 -1 3\n1 0 2\n", "3\n0 -1 3\n1 0 2\n"], "outputs": ["3\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 594 |
Solve the programming task below in a Python markdown code block.
Complete the function `power_of_two`/`powerOfTwo` (or equivalent, depending on your language) that determines if a given non-negative integer is a [power of two](https://en.wikipedia.org/wiki/Power_of_two). From the corresponding Wikipedia entry:
> *a ... | {"functional": "_inputs = [[0], [1], [536870912]]\n_outputs = [[False], [True], [True]]\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): retur... | coding | 344 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length N consisting of A, B and C, and an integer K which is between 1 and N (inclusive).
Print the string S after lowercasing the K-th character in it.
-----Constraints-----
- 1 ≤ N ≤ 50
- 1 ≤ K ≤ N
- S is a string of len... | {"inputs": ["1 1\nA\n", "3 2\nABC", "3 2\nACC", "3 2\nBCC", "3 2\nCBA", "3 2\nBDC", "6 2\nCCA", "3 2\nCDB"], "outputs": ["a\n", "AbC\n", "AcC\n", "BcC\n", "CbA\n", "BdC\n", "CcA\n", "CdB\n"]} | coding | 149 |
Solve the programming task below in a Python markdown code block.
There are N squares arranged in a row, numbered 1 to N from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet.
He wants to stack blocks on the squares evenly, so he will repeat the following operation... | {"inputs": ["2 2 1", "2 30 9", "2 7 26", "2 1 26", "2 2 26", "2 4 26", "2 6 26", "1 7 26"], "outputs": ["6", "225084266\n", "8192\n", "2\n", "8\n", "128\n", "2048\n", "64\n"]} | coding | 340 |
Solve the programming task below in a Python markdown code block.
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - ... | {"inputs": ["0 0\n", "1 0\n", "0 1\n", "0 6\n", "1 1\n", "0 6\n", "1 1\n", "2 1\n"], "outputs": ["0\n", "0\n", "2\n", "22\n", "1\n", "22\n", "1\n", "5\n"]} | coding | 318 |
Solve the programming task below in a Python markdown code block.
Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is display... | {"inputs": ["2\nD\nT", "2\nE\nU", "2\nF\nU", "2\nD\nS", "2\nC\nU", "2\nB\nU", "2\nD\nV", "2\nD\nR"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 375 |
Solve the programming task below in a Python markdown code block.
Takahashi is drawing a segment on grid paper.
From a certain square, a square that is x squares to the right and y squares above, is denoted as square (x, y).
When Takahashi draws a segment connecting the lower left corner of square (A, B) and the lowe... | {"inputs": ["1 2 3 4", "1 2 6 4", "6 6 3 5", "9 1 4 0", "1 0 6 4", "6 3 3 5", "1 1 3 4", "3 3 10 7"], "outputs": ["2\n", "6\n", "3\n", "5\n", "8\n", "4\n", "4", "10\n"]} | coding | 227 |
Solve the programming task below in a Python markdown code block.
Given are an integer K and integers a_1,\dots, a_K. Determine whether a sequence P satisfying below exists. If it exists, find the lexicographically smallest such sequence.
* Every term in P is an integer between 1 and K (inclusive).
* For each i=1,\dot... | {"inputs": ["3\n1 1 1", "3\n1 1 2", "3\n1 2 2", "3\n2 1 2", "3\n2 1 1", "3\n2 2 4", "3\n2 4 4", "3\n2 2 1"], "outputs": ["1 2 3 \n", "3 1 2 3 \n", "2 3 1 2 3 \n", "1 3 2 1 3 \n", "1 2 3 1 \n", "3 1 2 3 3 1 2 3 \n", "2 3 1 2 3 2 3 1 2 3 \n", "1 2 3 1 2 \n"]} | coding | 329 |
Solve the programming task below in a Python markdown code block.
It is the easy version of the problem. The only difference is that in this version $k = 3$.
You are given a positive integer $n$. Find $k$ positive integers $a_1, a_2, \ldots, a_k$, such that:
$a_1 + a_2 + \ldots + a_k = n$
$LCM(a_1, a_2, \ldots, a_k)... | {"inputs": ["3\n3 3\n8 3\n14 3\n"], "outputs": ["1 1 1\n4 2 2\n2 6 6\n"]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
In computer science and discrete mathematics, an [inversion](https://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29) is a pair of places in a sequence where the elements in these places are out of their natural order. So, if we use ascending ... | {"functional": "_inputs = [[[1, 2, 3]], [[-3, -2, -1]], [[-20, 0, 20]], [[-13, 4, 8]], [[1, 3, 2]], [[-2, -3, -1]], [[-20, 20, 0]], [[-13, 9, 8]], [[3, 6, 2]], [[3, 6, 2, 7, 3]], [[26, 32, -21, 45, 21]], [[14, 12, 17, 124, 1, -12, 21, -24]], [[]], [[25, 12, 7, 4, 2, -7, -12, -22]], [[324, 123, 36, 4, -1, -72, -123]], [... | coding | 277 |
Solve the programming task below in a Python markdown code block.
There are two groups, one of $N$ boys and the other of $N$ girls numbered from $1$ to $N$.
You are given two arrays $A$ and $B$ containing $N$ numbers each, denoting the height of boys and girls in the group.
You have to form $N$ couples, where each cou... | {"inputs": ["1\n3\n4 5 1\n2 2 2"], "outputs": ["7"]} | coding | 482 |
Solve the programming task below in a Python markdown code block.
Consider a regular polygon with N vertices labelled 1..N. In how many ways can you draw K diagonals such that no two diagonals intersect at a point strictly inside the polygon? A diagonal is a line segment joining two non adjacent vertices of the polygon... | {"inputs": ["3\n4 1\n5 2\n5 3\n"], "outputs": ["2\n5\n0\n"]} | coding | 268 |
Solve the programming task below in a Python markdown code block.
Task
======
Make a custom esolang interpreter for the language [InfiniTick](https://esolangs.org/wiki/InfiniTick). InfiniTick is a descendant of [Tick](https://esolangs.org/wiki/tick) but also very different. Unlike Tick, InfiniTick has 8 commands inste... | {"functional": "_inputs = [['\\\\h*&'], ['+-*&']]\n_outputs = [['\\x00'], ['\\x00']]\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... | coding | 466 |
Solve the programming task below in a Python markdown code block.
Little Lucy loves to arrange her flowers in patterns similar to those of a binary search tree. Her father, a computer scientist himself, takes note of this and finds out that she has N flowers. Every day she takes some of these N flowers and arranges the... | {"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["1\n4\n14\n50 \n"]} | coding | 359 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.
Given an array of numbers arr, return true if the array can be rearranged to form an arithm... | {"functional": "def check(candidate):\n assert candidate(arr = [3,5,1]) == True\n assert candidate(arr = [1,2,4]) == False\n\n\ncheck(Solution().canMakeArithmeticProgression)"} | coding | 100 |
Solve the programming task below in a Python markdown code block.
Write a program which reads an integer and prints sum of its digits.
Input
The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.
The input ends with a line includi... | {"inputs": ["123\n1\n1001\n0", "123\n4\n1100\n0", "123\n1\n1101\n0", "123\n1\n1000\n0", "123\n0\n1000\n0", "123\n2\n1101\n0", "123\n4\n1101\n0", "123\n3\n1101\n0"], "outputs": ["6\n1\n2\n", "6\n4\n2\n", "6\n1\n3\n", "6\n1\n1\n", "6\n", "6\n2\n3\n", "6\n4\n3\n", "6\n3\n3\n"]} | coding | 124 |
Solve the programming task below in a Python markdown code block.
Chef wants to host some Division-3 contests. Chef has $N$ setters who are busy creating new problems for him. The $i^{th}$ setter has made $A_i$ problems where $1 \leq i \leq N$.
A Division-3 contest should have exactly $K$ problems. Chef wants to pl... | {"inputs": ["5\n1 5 31\n4\n1 10 3\n23\n2 5 7\n20 36\n2 5 10\n19 2\n3 3 300\n1 1 1"], "outputs": ["0\n2\n7\n4\n1"]} | coding | 756 |
Solve the programming task below in a Python markdown code block.
Chef recently opened a big e-commerce website where her recipes can be bought online. It's Chef's birthday month and so she has decided to organize a big sale in which grand discounts will be provided.
In this sale, suppose a recipe should have a discoun... | {"inputs": ["2\n2\n100 5 10\n100 1 50\n3\n10 10 0\n79 79 79\n100 1 100"], "outputs": ["30.000000000\n3995.0081000"]} | coding | 739 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has an integer $N$ and he wants to generate a matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). He... | {"inputs": ["1\n2"], "outputs": ["1 2\n4 3"]} | coding | 601 |
Solve the programming task below in a Python markdown code block.
Chef has fallen in love with Cheffina, and wants to buy N gifts for her. On reaching the gift shop, Chef got to know the following two things:
The cost of each gift is 1 coin.
On the purchase of every 4^{th} gift, Chef gets the 5^{th} gift free of cost. ... | {"inputs": ["2\n5\n4"], "outputs": ["4\n4"]} | coding | 314 |
Solve the programming task below in a Python markdown code block.
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise d... | {"inputs": ["3\n1 9 3\n8 6 7\n4 2 5\n", "3\n1 5 8\n9 2 4\n3 6 7\n", "3\n1 4 7\n6 9 2\n3 8 5\n", "3\n1 6 3\n7 2 9\n4 8 5\n", "3\n1 6 3\n4 9 8\n7 2 5\n", "3\n8 6 3\n9 1 5\n2 4 7\n", "3\n1 5 2\n7 6 3\n4 8 9\n", "3\n1 4 8\n7 2 6\n5 9 3\n"], "outputs": ["12 1\n", "12 1\n", "9 1\n", "11 2\n", "9 1\n", "13 2\n", "11 0\n", "11... | coding | 632 |
Solve the programming task below in a Python markdown code block.
Maria plays college basketball and wants to go pro. Each season she maintains a record of her play. She tabulates the number of times she breaks her season record for most points and least points in a game. Points scored in the first game establish he... | {"inputs": ["9\n10 5 20 20 4 5 2 25 1\n", "10\n3 4 21 36 10 28 35 5 24 42\n"], "outputs": ["2 4\n", "4 0\n"]} | coding | 679 |
Solve the programming task below in a Python markdown code block.
Chef has $N$ dishes of different types arranged in a row: $A_1, A_2, \ldots, A_N$, where $A_i$ denotes the type of the $i^{th}$ dish. He wants to choose as many dishes as possible from the given list but while satisfying two conditions:
- He can choose ... | {"inputs": ["3\n5\n1 2 2 1 2\n6\n1 1 1 1 1 1\n8\n1 2 2 2 3 4 2 1"], "outputs": ["1\n1\n2"]} | coding | 635 |
Solve the programming task below in a Python markdown code block.
An n × n square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n × n matrices, s... | {"inputs": ["5 0 13\n", "5 0 13\n", "2 0 1000\n", "2 0 1000\n", "2 0 1010\n", "4 0 1100\n", "99 0 757\n", "2 0 1100\n"], "outputs": ["12\n", "12\n", "1\n", "1\n", "1\n", "90\n", "613\n", "1\n"]} | coding | 347 |
Solve the programming task below in a Python markdown code block.
A sophomore Computer Science student is frustrated with boring college lectures. Professor X agreed to give him some questions; if the student answers all questions correctly, then minimum attendance criteria will not apply to him.
Professor X chooses a ... | {"inputs": ["1\n6 1\n4 2 15 9 8 8\n3"], "outputs": ["2 4"]} | coding | 675 |
Solve the programming task below in a Python markdown code block.
## **Task**
You are given a positive integer (`n`), and your task is to find the largest number **less than** `n`, which can be written in the form `a**b`, where `a` can be any non-negative integer and `b` is an integer greater than or equal to `2`. Try... | {"functional": "_inputs = [[90], [6], [65], [2], [1], [81], [29], [4]]\n_outputs = [[[81, 2]], [[4, 1]], [[64, 3]], [[1, -1]], [[0, -1]], [[64, 3]], [[27, 1]], [[1, -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... | coding | 477 |
Solve the programming task below in a Python markdown code block.
After many years of research, Ikta has acquired the ability to predict the future! The time and money he spent on this research was enormous, but it's finally time to be rewarded. To get the money back, Ikta decided to start investing in stocks.
Ikta do... | {"inputs": ["1 2 5\n4\n10000", "2 2 6\n3 2\n5 4", "1 2 7\n4\n10000", "1 1 5\n6\n10000", "2 1 8\n6\n10000", "1 2 5\n6\n10000", "2 2 5\n3 2\n5 4", "2 3 5\n4 5\n6 3\n8 6"], "outputs": ["10001\n", "12\n", "10003\n", "5\n", "8\n", "5", "9", "13\n"]} | coding | 636 |
Solve the programming task below in a Python markdown code block.
Given an array A having N elements, a subarray S of A is called good if XOR(S) ≥ K, where XOR(S) denotes the [bitwise XOR] of all the elements of the subarray S.
Find the length of the smallest subarray S which is good. If there is no good subarray, pri... | {"inputs": ["3\n5 15\n1 4 2 8 1\n5 7\n1 4 2 8 1\n5 20\n1 4 2 8 1"], "outputs": ["4\n1\n-1"]} | coding | 657 |
Solve the programming task below in a Python markdown code block.
The chef was not happy with the binary number system, so he designed a new machine which is having 6 different states, i.e. in binary there is a total of 2 states as 0 and 1. Now, the chef is confused about how to correlate this machine to get an interac... | {"inputs": ["2\n3\n5"], "outputs": ["7\n37"]} | coding | 304 |
Solve the programming task below in a Python markdown code block.
# Task
You are given a string `s`. Let's call its substring a group, if all letters in it are adjacent and the same(such as `"aa","bbb","cccc"`..). Let's call the substiring with 2 or more adjacent group a big group(such as `"aabb","bbccc"`...).
Your... | {"functional": "_inputs = [['ccccoodeffffiiighhhhhhhhhhttttttts'], ['soooooldieeeeeer'], ['ccccoooooooooooooooooooooooddee'], ['wwwwaaaarrioooorrrrr'], ['gztxxxxxggggggggggggsssssssbbbbbeeeeeeehhhmmmmmmmitttttttlllllhkppppp']]\n_outputs = [[3], [0], [1], [2], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isi... | coding | 366 |
Solve the programming task below in a Python markdown code block.
Chef has two binary strings A and B, each of length N.
Chef can rearrange both the strings in any way. Find the maximum [bitwise XOR] he can achieve if he rearranges the strings optimally.
------ Input Format ------
- The first line of input will con... | {"inputs": ["4\n0011\n1011\n100\n100\n11111\n11101\n1\n0\n"], "outputs": ["1110\n110\n10000\n1\n"]} | coding | 583 |
Solve the programming task below in a Python markdown code block.
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.
Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a ca... | {"inputs": ["5 1 1\n1 0 1 1 1", "5 1 4\n0 1 6 0 2", "5 2 1\n1 1 1 1 1", "5 1 1\n1 0 1 1 0", "5 0 1\n0 0 2 1 1", "5 1 4\n1 1 6 0 2", "5 2 1\n1 1 1 1 0", "5 1 1\n1 0 1 1 2"], "outputs": ["0\n", "2\n", "0\n", "1\n", "0\n", "2\n", "1\n", "1\n"]} | coding | 407 |
Solve the programming task below in a Python markdown code block.
The MarkiT online virtual market startup wants to organize its grand opening in NIT Patna.
but they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them:
The first-year students come to cam... | {"inputs": ["1\n10\n8 10 6"], "outputs": ["2"]} | coding | 351 |
Solve the programming task below in a Python markdown code block.
Notes
Template in C
Constraints
2 ≤ the number of operands in the expression ≤ 100
1 ≤ the number of operators in the expression ≤ 99
-1 × 109 ≤ values in the stack ≤ 109
Input
An expression is given in a line. Two consequtive symbols (operand or op... | {"inputs": ["1 3 +", "0 3 +", "0 3 *", "0 5 +", "0 1 +", "6 7 *", "0 4 +", "0 0 *"], "outputs": ["4\n", "3\n", "0\n", "5\n", "1\n", "42\n", "4\n", "0\n"]} | coding | 162 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person.
The population of some year x is the number of people alive during that year. The ith ... | {"functional": "def check(candidate):\n assert candidate(logs = [[1993,1999],[2000,2010]]) == 1993\n assert candidate(logs = [[1950,1961],[1960,1971],[1970,1981]]) == 1960\n\n\ncheck(Solution().maximumPopulation)"} | coding | 149 |
Solve the programming task below in a Python markdown code block.
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are... | {"inputs": ["1 1\n", "6 2\n", "6 3\n", "6 4\n", "6 5\n", "6 6\n", "2 2\n", "6 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]} | coding | 363 |
Solve the programming task below in a Python markdown code block.
Problem C Medical Checkup
Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on.
Students are now forming a long queue, waiting for the checkup to start. Students are also numbered... | {"inputs": ["3 0\n1\n3\n3", "1 0\n1\n2\n3", "3 1\n1\n3\n3", "1 5\n5\n7\n3", "3 9\n1\n2\n0", "2 5\n6\n1\n3", "3 9\n1\n0\n0", "3 20\n1\n3\n6"], "outputs": ["1\n1\n1\n", "1\n", "2\n1\n1\n", "2\n", "10\n5\n5\n", "1\n1\n", "10\n10\n10\n", "21\n7\n3\n"]} | coding | 603 |
Solve the programming task below in a Python markdown code block.
Sho has an array $a$ consisting of $n$ integers. An operation consists of choosing two distinct indices $i$ and $j$ and removing $a_i$ and $a_j$ from the array.
For example, for the array $[2, 3, 4, 2, 5]$, Sho can choose to remove indices $1$ and $3$. ... | {"inputs": ["1\n2\n1 9\n", "4\n6\n2 2 2 3 3 3\n5\n9 1 9 9 1\n4\n15 16 16 15\n4\n10 100 1000 10000\n"], "outputs": ["2\n", "2\n1\n2\n4\n"]} | coding | 690 |
Solve the programming task below in a Python markdown code block.
Initially, two non-touching spheres of radii R1 and R2 are lying in space at rest. Both of them are then given accelerations a1 and a2 respectively at time=0. Find whether they will ever come in contact. Their initial positions are represented as (x1,y1,... | {"inputs": ["2\n1 2\n0 0 0\n-1 0 0\n4 0 0\n1 0 0\n1 2\n0 0 0\n100 0 0\n4 0 0\n0 0 0\n"], "outputs": ["NO\nYES\n"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
Given a set of N natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which Ith.
number of set come at Kth postion.Elements of every subset should be in sorted order.
The answer could be very l... | {"inputs": ["1\n3 3\n1 2\n2 1\n3 2"], "outputs": ["0\n2\n2"]} | coding | 461 |
Solve the programming task below in a Python markdown code block.
For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out... | {"inputs": ["3\n1\n5\n8"], "outputs": ["1\n4\n8"]} | coding | 309 |
Solve the programming task below in a Python markdown code block.
You are the gym teacher in the school.
There are $n$ students in the row. And there are two rivalling students among them. The first one is in position $a$, the second in position $b$. Positions are numbered from $1$ to $n$ from left to right.
Since th... | {"inputs": ["1\n5 2 3 2\n", "1\n5 2 3 2\n", "1\n7 2 3 2\n", "1\n7 0 3 2\n", "1\n7 1 3 2\n", "1\n3 1 1 2\n", "1\n5 2 1 2\n", "1\n6 1 3 2\n"], "outputs": ["3\n", "3\n", "3\n", "1\n", "2\n", "2\n", "3\n", "2\n"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
Given a string, determine if it's a valid identifier.
## Here is the syntax for valid identifiers:
* Each identifier must have at least one character.
* The first character must be picked from: alpha, underscore, or dollar sign. The first character cann... | {"functional": "_inputs = [['okay_ok1'], ['$ok'], ['___'], ['str_STR'], ['myIdentf'], ['1ok0okay'], ['!Ok'], [''], ['str-str'], ['no no']]\n_outputs = [[True], [True], [True], [True], [True], [False], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinsta... | coding | 168 |
Solve the programming task below in a Python markdown code block.
Introduction
It's been more than 20 minutes since the negligent waiter has taken your order for the house special prime tofu steak with a side of chili fries.
Out of boredom, you start fiddling around with the condiments tray. To be efficient, you want... | {"functional": "_inputs = [[0], [3], [16], [32], [49], [89], [327], [363], [366], [512], [656], [1038], [1052], [1222], [1235], [1302], [1735], [1757], [1974], [2048]]\n_outputs = [[0], [7], [171], [683], [1215], [3715], [52239], [60195], [62063], [174763], [209095], [699451], [700379], [757295], [762019], [832559], [1... | coding | 385 |
Solve the programming task below in a Python markdown code block.
_Based on [Project Euler problem 35](https://projecteuler.net/problem=35)_
A circular prime is a prime in which every circular permutation of that number is also prime. Circular permutations are created by rotating the digits of the number, for example:... | {"functional": "_inputs = [[197], [179], [971], [222], [9377], [7], [213], [35], [1]]\n_outputs = [[True], [False], [True], [False], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol... | coding | 148 |
Solve the programming task below in a Python markdown code block.
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to... | {"inputs": ["habege\necjecg\n0\n", "habege\ngcejce\n0\n", "habege\ngceice\n0\n", "habfge\ngceice\n0\n", "habfge\ngdeice\n0\n", "habfge\nedeicg\n0\n", "a\nb\n3\na b 2\na b 3\nb a 5\n", "uayd\nuxxd\n3\na x 8\nx y 13\nd c 2\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2\nb\n", "21\nuxyd\n"]} | coding | 426 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef is so good at programming that he won almost all competitions. With all the prizes, Chef bought a new house. The house looks like a grid of size N (1-indexed) which cons... | {"inputs": ["3\n1\n2\n3"], "outputs": ["2\n12\n36"]} | coding | 472 |
Solve the programming task below in a Python markdown code block.
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given... | {"inputs": ["24\n17:30\n", "12\n17:30\n", "24\n99:99\n", "12\n05:54\n", "12\n00:05\n", "24\n23:80\n", "24\n73:16\n", "12\n03:77\n"], "outputs": ["17:30\n", "07:30\n", "09:09\n", "05:54\n", "01:05\n", "23:00\n", "03:16\n", "03:07\n"]} | coding | 412 |
Solve the programming task below in a Python markdown code block.
Brave Ponta and his best friend, Brave Gonta, have come to Luida's bar in search of friends to embark on an epic adventure. There are many warriors, monks and wizards in the tavern who are itching to go on an adventure.
Gonta, who is kind-hearted, cared... | {"inputs": ["5\n1 3 3 4 5\n4\n2 3 5 7\n0", "5\n1 2 3 4 5\n4\n2 1 0 7\n0", "5\n1 2 3 5 5\n4\n2 1 0 7\n0", "5\n1 2 3 5 5\n4\n2 1 0 6\n0", "5\n0 1 3 8 1\n4\n5 4 8 7\n0", "5\n0 1 2 8 1\n4\n5 4 8 7\n0", "5\n0 1 2 8 1\n4\n5 4 5 7\n0", "5\n0 1 2 8 0\n4\n5 4 8 7\n0"], "outputs": ["0\n1\n", "1\n4\n", "0\n4\n", "0\n3\n", "3\n0\n... | coding | 367 |
Solve the programming task below in a Python markdown code block.
A non-decreasing sequence is a called a Fox sequence, iff the most frequent element in the sequence is unique.
e.g. The sequence 1, 1, 2, 3, 4 is a Fox sequence, because it follows the above definition. The most frequent element is 1. It occurs twice ... | {"inputs": ["5\n2 1 1\n2 1 3\n3 1 2\n4 4 5\n10 2 4\n"], "outputs": ["1\n3\n4\n4\n60\n"]} | coding | 476 |
Solve the programming task below in a Python markdown code block.
There are N positive integers arranged in a circle.
Now, the i-th number is A_i. Takahashi wants the i-th number to be B_i. For this objective, he will repeatedly perform the following operation:
* Choose an integer i such that 1 \leq i \leq N.
* Let a... | {"inputs": ["3\n1 1 1\n13 1 7", "3\n2 1 1\n13 5 7", "3\n2 1 1\n13 1 7", "3\n2 1 1\n13 2 7", "3\n2 1 1\n13 2 0", "3\n1 1 1\n13 2 0", "3\n1 1 1\n13 3 0", "3\n1 1 1\n13 4 0"], "outputs": ["4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 366 |
Solve the programming task below in a Python markdown code block.
In this kata you need to build a function to return either `true/True` or `false/False` if a string can be seen as the repetition of a simpler/shorter subpattern or not.
For example:
```cpp,java
hasSubpattern("a") == false; //no repeated pattern
hasSub... | {"functional": "_inputs = [['a'], ['aaaa'], ['abcd'], ['abababab'], ['ababababa'], ['123a123a123a'], ['123A123a123a'], ['abbaabbaabba'], ['abbabbabba'], ['abcdabcabcd']]\n_outputs = [[False], [True], [False], [True], [False], [True], [False], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | coding | 321 |
Solve the programming task below in a Python markdown code block.
Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.
Gregor's favorite prime number is $P$. Gregor wants to find two bases of $P$. Formally, Gregor is lo... | {"inputs": ["2\n7\n5\n", "1\n271\n", "1\n833\n", "1\n497\n", "1\n643\n", "1\n997\n", "1\n611\n", "1\n887\n"], "outputs": ["2 6\n2 4\n", "2 270\n", "2 832\n", "2 496\n", "2 642\n", "2 996\n", "2 610\n", "2 886\n"]} | coding | 367 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The array-form of an integer num is an array representing its digits in left to right order.
For example, for num = 1321, the array form is [1,3,2,1].
Given num, the array-form of an integer, and an integer k, retur... | {"functional": "def check(candidate):\n assert candidate(num = [1,2,0,0], k = 34) == [1,2,3,4]\n assert candidate(num = [2,7,4], k = 181) == [4,5,5]\n assert candidate(num = [2,1,5], k = 806) == [1,0,2,1]\n\n\ncheck(Solution().addToArrayForm)"} | coding | 124 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian] and [Mandarin Chinese].
Given the time control of a chess match as a + b, determine which format of chess out of the given 4 it belongs to.
1) Bullet if a + b < 3
2) Blitz if 3 ≤ a + b ≤ 10
3) Rapid if 11 ≤ a +... | {"inputs": ["4\n1 0\n4 1\n100 0\n20 5\n"], "outputs": ["1\n2\n4\n3"]} | coding | 319 |
Solve the programming task below in a Python markdown code block.
Jigar got a sequence of n positive integers as his birthday present! He likes consecutive subsequences whose sum is divisible by k. He asks you to write a program to count them for him.
Input Format
The first line contains T, the number of testcases. ... | {"inputs": ["2\n5 3\n1 2 3 4 1\n6 2\n1 2 1 2 1 2\n"], "outputs": ["4\n9\n"]} | coding | 350 |
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)"} | coding | 189 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums that consists of positive integers.
The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.
For example, the GCD of the seq... | {"functional": "def check(candidate):\n assert candidate(nums = [6,10,3]) == 5\n assert candidate(nums = [5,15,40,5,6]) == 7\n\n\ncheck(Solution().countDifferentSubsequenceGCDs)"} | coding | 186 |
Solve the programming task below in a Python markdown code block.
Given the string S and m queries. The i-th query is given by the two strings xi and yi.
For each query, answer the longest substring of the string S, starting with xi and ending with yi.
For the string S, | S | represents the length of S. Also, the fac... | {"inputs": ["abracadabsa\n5\nab a\na a\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na b\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na c\nb c\nac ca\nz z", "abracadabsa\n5\nab a\na c\na c\nac ca\nz z", "abracadabsa\n5\nba a\na c\na c\nac ca\nz y", "abracadabsa\n5\nba a\na c\nb c\nac ca\nz y", "abracadabsa\n2\nba a\na c\nb c\... | coding | 491 |
Solve the programming task below in a Python markdown code block.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This li... | {"inputs": ["2 2\n0\n0\n", "3 3\n0\n0\n0\n", "2 2\n1 2\n0\n", "2 2\n1 2\n1 1\n", "3 100\n0\n0\n0\n", "2 3\n1 2\n1 1\n", "3 101\n0\n0\n0\n", "3 001\n0\n0\n0\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "3\n", "1\n", "3\n", "3\n"]} | coding | 476 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Chef is judging a game called "Broken telephone". There are total N players taking part in the game. They are all sitting in a line. In the start of the game, first player is given a secret mes... | {"inputs": ["3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 1\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 3\n5\n1 3 1 1 2\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 0 1 1 1\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n9 5 5 5", "3\n7\n1 1 1 3 3 3 3\n5\n1 3 1 1 2\n4\n5 5 9 5", "3\n7\n1 2 1 3... | coding | 547 |
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... | coding | 435 |
Solve the programming task below in a Python markdown code block.
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot.
One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to t... | {"inputs": ["1\n1\n1\n", "3\n3 1 2\n1 2 3\n", "3\n3 2 1\n1 2 3\n", "5\n1 5 2 3 4\n1 2 3 4 5\n", "5\n1 2 3 4 5\n1 5 2 3 4\n", "7\n6 1 7 3 4 5 2\n6 1 7 3 4 5 2\n", "10\n5 8 1 10 3 6 2 9 7 4\n4 2 6 3 1 9 10 5 8 7\n", "10\n1 6 10 3 4 9 2 5 8 7\n7 5 1 6 10 3 4 8 9 2\n"], "outputs": ["0", "2\n", "2", "3", "1", "0", "8", "3"]... | coding | 460 |
Solve the programming task below in a Python markdown code block.
"I don't have any fancy quotes." - vijju123
Chef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word "not" are Real Fancy; quotes that do not ... | {"inputs": ["2\ni do not have any fancy quotes\nwhen nothing goes right go left"], "outputs": ["Real Fancy\nregularly fancy"]} | coding | 322 |
Solve the programming task below in a Python markdown code block.
There are N people standing in a queue from west to east.
Given is a string S of length N representing the directions of the people.
The i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R.
A per... | {"inputs": ["1 99999\nL\n", "6 2\nLRLRRL", "6 0\nLRRLRL", "6 1\nRRLLRL", "6 0\nRRLLRL", "6 0\nLRLRLR", "6 4\nLRLRRL", "6 1\nLRRLRL"], "outputs": ["0\n", "5\n", "1\n", "4\n", "2\n", "0\n", "5\n", "3\n"]} | coding | 413 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.
Please complete the following python code ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,1,1,1,1], target = 2) == 2\n assert candidate(nums = [-1,3,5,1,4,2,-9], target = 6) == 2\n assert candidate(nums = [-2,6,6,3,5,4,1,2,8], target = 10) == 3\n assert candidate(nums = [0,0,0], target = 0) == 3\n\n\ncheck(Solution().maxNonOverla... | coding | 90 |
Solve the programming task below in a Python markdown code block.
You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au.
For each vertex v, we consider the path going upwards from v to the root. Suppose that path is ... | {"inputs": ["8\n1 1 1 1 5 8 6\n1 2 3 4 5 15 70 10"], "outputs": ["1 3 4 5 6 21 96 26"]} | coding | 644 |
Solve the programming task below in a Python markdown code block.
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42.
These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764.
The sum of the squared divisors is 2500 which is 50 * 50, a square!
Given two integers m, n (1 <= m <= n) we want to find all integers
between ... | {"functional": "_inputs = [[1, 250], [42, 250], [250, 500], [300, 600], [600, 1500], [1500, 1800], [1800, 2000], [2000, 2200], [2200, 5000], [5000, 10000]]\n_outputs = [[[[1, 1], [42, 2500], [246, 84100]]], [[[42, 2500], [246, 84100]]], [[[287, 84100]]], [[]], [[[728, 722500], [1434, 2856100]]], [[[1673, 2856100]]], [[... | coding | 364 |
Solve the programming task below in a Python markdown code block.
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are n mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in on... | {"inputs": ["5\n", "6\n", "4\n", "1\n", "8\n", "7\n", "3\n", "2\n"], "outputs": ["1 5 2 4 3", "1 6 2 5 3 4 ", "1 4 2 3 ", "1", "1 8 2 7 3 6 4 5\n", "1 7 2 6 3 5 4\n", "1 3 2", "1 2 "]} | coding | 282 |
Solve the programming task below in a Python markdown code block.
In genetics a reading frame is a way to divide a sequence of nucleotides (DNA bases) into a set of consecutive non-overlapping triplets (also called codon). Each of this triplets is translated into an amino-acid during a translation process to create pro... | {"functional": "_inputs = [['AGGTGACACCGCAAGCCTTATATTAGC']]\n_outputs = [['Frame 1: AGG TGA CAC CGC AAG CCT TAT ATT AGC\\nFrame 2: A GGT GAC ACC GCA AGC CTT ATA TTA GC\\nFrame 3: AG GTG ACA CCG CAA GCC TTA TAT TAG C']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 461 |
Solve the programming task below in a Python markdown code block.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
-----Constraints-----
- 1000 ≤ N ≤ 9999
- N is an integer.
-----Input-----
Input is given fro... | {"inputs": ["860", "374", "425", "647", "317", "943", "308", "164"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | coding | 139 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.