problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected graph with n nodes, numbered from 0 to n - 1.
You are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges ... | {"functional": "def check(candidate):\n assert candidate(scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]) == 24\n assert candidate(scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]) == -1\n\n\ncheck(Solution().maximumScore)"} | coding | 217 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
You then do the following steps:
If original is found in nums, multiply... | {"functional": "def check(candidate):\n assert candidate(nums = [5,3,6,1,12], original = 3) == 24\n assert candidate(nums = [2,7,9], original = 4) == 4\n\n\ncheck(Solution().findFinalValue)"} | coding | 142 |
Solve the programming task below in a Python markdown code block.
# Task
* **_Given_** *three integers* `a` ,`b` ,`c`, **_return_** *the **_largest number_** obtained after inserting the following operators and brackets*: `+`, `*`, `()`
* In other words , **_try every combination of a,b,c with [*+()] , and return the ... | {"functional": "_inputs = [[2, 1, 2], [2, 1, 1], [1, 1, 1], [1, 2, 3], [1, 3, 1], [2, 2, 2], [5, 1, 3], [3, 5, 7], [5, 6, 1], [1, 6, 1], [2, 6, 1], [6, 7, 1], [2, 10, 3], [1, 8, 3], [9, 7, 2], [1, 1, 10], [9, 1, 1], [10, 5, 6], [1, 10, 1]]\n_outputs = [[6], [4], [3], [9], [5], [8], [20], [105], [35], [8], [14], [48], [... | coding | 697 |
Solve the programming task below in a Python markdown code block.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised ... | {"inputs": ["1 2\n1\n1 1\n1 1\n", "1 1\n1000000000\n1 1\n", "1 1\n1010000000\n1 1\n", "1 1\n1010000010\n1 1\n", "1 1\n1010010000\n1 1\n", "1 1\n1010100010\n1 1\n", "7 2\n3 1 2 2 6 3 7\n1 7\n3 4\n", "7 2\n3 1 2 2 3 3 4\n1 7\n3 4\n"], "outputs": ["1\n1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n1\n", "3\n1\n"]} | coding | 316 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.
For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "... | {"functional": "def check(candidate):\n assert candidate(s = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]]) == \"bobistwoyearsold\"\n assert candidate(s = \"hi(name)\", knowledge = [[\"a\",\"b\"]]) == \"hi?\"\n assert candidate(s = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]]... | coding | 257 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A complex number can be represented as a string on the form "real+imaginaryi" where:
real is the real part and is an integer in the range [-100, 100].
imaginary is the imaginary part and is an integer in the range [-... | {"functional": "def check(candidate):\n assert candidate(num1 = \"1+1i\", num2 = \"1+1i\") == \"0+2i\"\n assert candidate(num1 = \"1+-1i\", num2 = \"1+-1i\") == \"0+-2i\"\n\n\ncheck(Solution().complexNumberMultiply)"} | coding | 151 |
Solve the programming task below in a Python markdown code block.
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the ... | {"inputs": ["2 1\n2 2\n", "2 2\n5 4\n", "2 1\n1 5\n", "2 1\n3 1\n", "2 1\n1 3\n", "2 1\n3 1\n", "2 2\n5 4\n", "2 1\n1 5\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n"]} | coding | 359 |
Solve the programming task below in a Python markdown code block.
There are N bags of biscuits. The i-th bag contains A_i biscuits.
Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.
He would like to select bags so that the total numb... | {"inputs": ["1 1\n67", "1 1\n42", "1 1\n50", "2 0\n1 1", "2 0\n1 3", "3 1\n1 1 1", "3 0\n1 1 1", "45 1\n6 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 8 25 9 89 45 41 16 3 11 61 8 167 72 62 67 42 26 36 66 4 87 59 91 4 24 4"], "outputs": ["1\n", "0\n", "0", "2\n", "2", "4\n", "4", "17592186044416\n"]} | coding | 388 |
Solve the programming task below in a Python markdown code block.
It started as a discussion with a friend, who didn't fully grasp some way of setting defaults, but I thought the idea was cool enough for a beginner kata: binary `OR` each matching element of two given arrays (or lists, if you do it in Python; vectors in... | {"functional": "_inputs = [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [1, 2]], [[1, 0], [1, 2, 3]], [[1, 0, 3], [1, 2, 3], 3]]\n_outputs = [[[1, 2, 3]], [[5, 7, 7]], [[1, 2, 3]], [[1, 2, 3]], [[1, 2, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\... | coding | 275 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Please complete the following python code precisely:
```python
class Solution:
def... | {"functional": "def check(candidate):\n assert candidate(n = 5) == True\n assert candidate(n = 7) == False\n assert candidate(n = 11) == False\n\n\ncheck(Solution().hasAlternatingBits)"} | coding | 73 |
Solve the programming task below in a Python markdown code block.
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell his plots. The speciality of his land is that it ... | {"inputs": ["2\n9 4\n2 2", "2\n9 4\n2 3", "2\n5 4\n2 3", "2\n8 4\n2 3", "2\n4 1\n2 3", "2\n8 5\n4 1", "2\n9 8\n2 1", "2\n9 3\n2 2"], "outputs": ["36\n1\n", "36\n6\n", "20\n6\n", "2\n6\n", "4\n6\n", "40\n4\n", "72\n2\n", "3\n1\n"]} | coding | 348 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared i... | {"functional": "def check(candidate):\n assert candidate(nums = [2,2,1,1,5,3,3,5]) == 7\n assert candidate(nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]) == 13\n\n\ncheck(Solution().maxEqualFreq)"} | coding | 128 |
Solve the programming task below in a Python markdown code block.
The Spelling Bee bees are back...
# How many bees are in the beehive?
* bees can be facing UP, DOWN, LEFT, RIGHT, and now also _diagonally_ up/down/left/right
* bees can share parts of other bees
## Examples
Ex1
```
bee.bee
.e..e..
.b..eeb
```... | {"functional": "_inputs = [[None]]\n_outputs = [[0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_e... | coding | 145 |
Solve the programming task below in a Python markdown code block.
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or l... | {"inputs": ["1\n1\n", "1\n1\n", "1\n65\n", "1\n-1\n", "1\n-1\n", "1\n65\n", "1\n-2\n", "1\n45\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 631 |
Solve the programming task below in a Python markdown code block.
Raj loves to listen to songs in his free time. It’s his birthday tomorrow and his friend Neelansh wants his gift to be the most unique. Being great at making music, he decides to produce a song for him. However, Raj likes songs according to their beauty.... | {"inputs": ["2\n8\n1 2 3 4 5 6 7 8\n16\n1 2 1 2 3 3 4 4 5 5 6 6 7 8 7 8"], "outputs": ["1\n2"]} | coding | 396 |
Solve the programming task below in a Python markdown code block.
Consider a linear function f(x) = Ax + B. Let's define g^{(0)}(x) = x and g^{(}n)(x) = f(g^{(}n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g^{(}n)(x) modulo 10^9 + 7.
-----Input-----
The only line contains four in... | {"inputs": ["3 4 1 1\n", "3 4 2 1\n", "3 4 3 1\n", "1 1 1 1\n", "1 1 1 1\n", "3 3 2 1\n", "3 5 2 1\n", "3 4 4 1\n"], "outputs": ["7\n", "25\n", "79\n", "2\n", "2\n", "21\n", "29\n", "241\n"]} | coding | 272 |
Solve the programming task below in a Python markdown code block.
Chef is taking a tough examination. The question paper consists of N objective problems and each problem has 4 options A, B, C, and D, out of which, exactly one option is correct.
Since Chef did not study for the exam, he does not know the answer to any... | {"inputs": ["2\n5\n0 0 5 0\n10\n7 1 1 1\n"], "outputs": ["5\n7\n"]} | coding | 539 |
Solve the programming task below in a Python markdown code block.
Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an.
Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formal... | {"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n51\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer $N$.
Your task is to print a palindromic triangle of size $N$.
For example, a palindromic triangle of size $5$ is:
1
121
12321
1234321
123454321
You can't take more than two lines. The first line (a for-statement... | {"inputs": ["5\n"], "outputs": ["1\n121\n12321\n1234321\n123454321\n"]} | coding | 245 |
Solve the programming task below in a Python markdown code block.
You are given $n$ strings $s_1, s_2, \ldots, s_n$ consisting of lowercase Latin letters.
In one operation you can remove a character from a string $s_i$ and insert it to an arbitrary position in a string $s_j$ ($j$ may be equal to $i$). You may perform ... | {"inputs": ["1\n2\nz\ny\n", "1\n2\na\ne\n", "1\n2\nz\ny\n", "1\n2\na\ne\n", "1\n1\nz\ny\n", "1\n2\nxx\nz\n", "1\n2\naa\nb\n", "1\n2\naa\na\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | coding | 421 |
Solve the programming task below in a Python markdown code block.
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hangin... | {"inputs": ["3 1\nabc\naec\nbc\na?c\n", "3 1\nabc\naec\nbc\nac?\n", "3 1\nacb\naec\nbb\nac?\n", "3 1\nabc\naec\nbb\nac?\n", "1 1\nacb\naec\nbb\nac?\n", "1 1\nacb\naec\nbc\nac?\n", "1 1\nacb\naec\nbc\na?c\n", "3 1\nabc\naec\nac\nc?a\n"], "outputs": ["2\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 474 |
Solve the programming task below in a Python markdown code block.
There's an array A consisting of N non-zero integers A1..N. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive).
For each x from 1 to N, com... | {"inputs": ["3\n4\n1 2 3 4\n4\n1 -5 1 -5\n6\n-5 -1 -1 2 -2 -3"], "outputs": ["1 1 1 1\n4 3 2 1\n1 1 3 2 1 1"]} | coding | 369 |
Solve the programming task below in a Python markdown code block.
Serena is interested in only red and yellow roses. She is arranging flowers in some fashion to be presented at her friend's birthday. Her friend loves only red and yellow roses(but mostly red ones). The flowers can be arranged only in the following three... | {"inputs": ["47\nRRYRRY\nRRRR\nYYRWBR\nR\nRY\nRRY\nW\nYRY\nRGGGGGGGGG\nRYYRYYRYY\nRYYY\nRR\nRYRYRYRYR\nRRRRGRRR\nRRYRRYRYY\nYYY\nBBBB\nRRRYYY\nRRRRY\nYRRRR\nRRYYRYYYR\nRYYYRYYYR\nRYYBYYRYY\nRRRRRRRRR\nRYYYYYYYY\nYYYYYYYYY\nRYRYYRYYR\nYYR\nRP\nRYYYY\nRRYYY\nRYY\nRYRYYRY\nRYRYYY\nRYRYY\nY\nRRYY\nRYRRRRYYY\nRYYRYYRY\nRYRY... | coding | 337 |
Solve the programming task below in a Python markdown code block.
AtCoder Mart sells 1000000 of each of the six items below:
* Riceballs, priced at 100 yen (the currency of Japan) each
* Sandwiches, priced at 101 yen each
* Cookies, priced at 102 yen each
* Cakes, priced at 103 yen each
* Candies, priced at 104 yen ea... | {"inputs": ["0", "3", "4", "8", "7", "5", "2", "1"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 235 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Jem couldn't even finish half of the homework exercises in "Advanced topics in algorithm" class. The teacher is really upset and gives him one final problem to solve - if he ... | {"inputs": ["3\n2\n3 4\n4\n1 5 3 4\n6\n2 4 6 7 8 10"], "outputs": ["3\n-1\n7"]} | coding | 535 |
Solve the programming task below in a Python markdown code block.
This follows from Game of Thrones - I.
Now that the king knows how to find out whether a given word has an anagram which is a palindrome or not, he encounters another challenge. He realizes that there can be more than one palindrome anagrams for a given... | {"inputs": ["aaabbbb\n", "cdcdcdcdeeeef\n"], "outputs": ["3 \n", "90\n"]} | coding | 287 |
Solve the programming task below in a Python markdown code block.
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`.
So he has decided to make a program that puts the single space he omitted.
You are given a string s with 1... | {"inputs": ["ETAUDARGTSOP", "AACDEFGHIJKL", "COCEFESTIVAL", "POSTGRADUATF", "ALCDEFGHIJKA", "COCEFESTIV@L", "POSTGRAUDATF", "AKJIHGFEDCLA"], "outputs": ["ETAU DARGTSOP\n", "AACD EFGHIJKL\n", "COCE FESTIVAL\n", "POST GRADUATF\n", "ALCD EFGHIJKA\n", "COCE FESTIV@L\n", "POST GRAUDATF\n", "AKJI HGFEDCLA\n"]} | coding | 221 |
Solve the programming task below in a Python markdown code block.
Implement a function which
creates a **[radix tree](https://en.wikipedia.org/wiki/Radix_tree)** (a space-optimized trie [prefix tree])
in which each node that is the only child is merged with its parent [unless a word from the input ends there])
from ... | {"functional": "_inputs = [[''], ['abc', 'def', 'ghi', 'jklm', 'nop'], ['ape', 'apple'], ['ape', 'appendix', 'apel'], ['ape', 'apple', 'applet', 'appendix'], ['romane', 'romanus', 'romulus'], ['test', 'tester', 'testers'], ['test', 'tester', 'testers', 'tester'], ['testers', 'tester', 'test']]\n_outputs = [[{}], [{'abc... | coding | 353 |
Solve the programming task below in a Python markdown code block.
__Definition:__ According to Wikipedia, a [complete binary tree](https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees) is a binary tree _"where every level, except possibly the last, is completely filled, and all nodes in the last level are as... | {"functional": "_inputs = [[[1]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\n_outputs = [[[1]], [[4, 2, 6, 1, 3, 5]], [[7, 4, 9, 2, 6, 8, 10, 1, 3, 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, rel_tol=tol, abs_to... | coding | 571 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings current and correct representing two 24-hour times.
24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and... | {"functional": "def check(candidate):\n assert candidate(current = \"02:30\", correct = \"04:35\") == 3\n assert candidate(current = \"11:00\", correct = \"11:01\") == 1\n\n\ncheck(Solution().convertTime)"} | coding | 178 |
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Alice and Bob are playing a game. Alice initially has the number A and Bob has the number B. There are a total of N turns in the game, and Alice and Bob alternatively take tu... | {"inputs": ["3\n1 2 1\n3 2 3\n3 7 2"], "outputs": ["1\n3\n2"]} | coding | 726 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an n x n integer matrix. You can do the following operation any number of times:
Choose any two adjacent elements of matrix and multiply each of them by -1.
Two elements are considered adjacent if and ... | {"functional": "def check(candidate):\n assert candidate(matrix = [[1,-1],[-1,1]]) == 4\n assert candidate(matrix = [[1,2,3],[-1,-2,-3],[1,2,3]]) == 16\n\n\ncheck(Solution().maxMatrixSum)"} | coding | 130 |
Solve the programming task below in a Python markdown code block.
Utkarsh is forced to play yet another game with Ashish.
In this game there are N piles, i^{th} pile contains A_{i} stones. Utkarsh moves first.
In Utkarsh's turn, Ashish chooses a pile (which contains at least 1 stone), then Utkarsh removes any non-zer... | {"inputs": ["3\n1\n10\n4\n1 1 1 1\n3\n3 3 1\n"], "outputs": ["Utkarsh\nAshish\nAshish\n"]} | coding | 488 |
Solve the programming task below in a Python markdown code block.
Write a program which reads a list of student test scores and evaluates the performance for each student.
The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examinati... | {"inputs": ["34 10 1\n30 42 0\n1 1 1\n-1 -1 -1", "40 53 -1\n0 7 -1\n0 1 -1\n-1 -1 -1", "73 6 -1\n16 30 0\n1 2 -1\n-1 -1 -1", "92 64 0\n16 30 -1\n0 2 0\n-1 -1 -1", "40 53 -1\n0 7 -1\n0 1 -2\n-1 -1 -1", "92 64 0\n16 30 -1\n1 2 0\n-1 -1 -1", "40 53 -1\n0 58 -1\n0 1 0\n-1 -1 -1", "40 53 -2\n0 7 -1\n0 1 -1\n-1 -1 -1"], "out... | coding | 444 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.
A subtree of a binary tree tree is a tree that co... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,4,5,1,2]), subRoot = tree_node([4,1,2])) == True\n assert candidate(root = tree_node([3,4,5,1,2,None,None,None,None,0]), subRoot = tree_node([4,1,2])) == False\n\n\ncheck(Solution().isSubtree)"} | coding | 181 |
Solve the programming task below in a Python markdown code block.
Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.
Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his s... | {"inputs": ["1 2\nab\n", "1 3\nab\n", "1 3\nab\n", "1 0\nab\n", "0 2\nab\n", "1 1\nab\n", "1 1\naa\n", "1 2\nab\n"], "outputs": ["Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n"]} | coding | 341 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$).
Let's sort $p$ in non-decreasing... | {"inputs": ["1\n1 4\n", "1\n2 5\n", "1\n2 5\n", "1\n3 5\n", "1\n1 6\n", "1\n4 5\n", "1\n1 9\n", "1\n1 7\n"], "outputs": ["6", "6", "6\n", "4\n", "10\n", "2\n", "16\n", "12\n"]} | coding | 753 |
Solve the programming task below in a Python markdown code block.
You are Dastan, the great Prince of Persia!
After searching long for the mysterious 'Sands of Time', you have finally arrived at the gates of the city that hosts the ancient temple of the gods. However, the gate is locked and it can only be opened with a... | {"inputs": ["3\n5 3\nH T T H T\n7 4\nH H T T T H H\n6 1\nT H T H T T"], "outputs": ["1\n2\n2"]} | coding | 487 |
Solve the programming task below in a Python markdown code block.
## Description
Your job is to create a simple password validation function, as seen on many websites.
The rules for a valid password are as follows:
- There needs to be at least 1 uppercase letter.
- There needs to be at least 1 lowercase letter.
- The... | {"functional": "_inputs = [['Abcd1234'], ['Abcd123'], ['abcd1234'], ['AbcdefGhijKlmnopQRsTuvwxyZ1234567890'], ['ABCD1234'], ['Ab1!@#$%^&*()-_+={}[]|\\\\:;?/>.<,'], ['!@#$%^&*()-_+={}[]|\\\\:;?/>.<,'], [''], [' aA1----'], ['4aA1----']]\n_outputs = [[True], [False], [False], [True], [False], [True], [False], [False], [Tr... | coding | 168 |
Solve the programming task below in a Python markdown code block.
There are $n$ seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from $1$ to $n$ from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take b... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "1 0\n1\n", "1 0\n0\n", "1 2\n1\n", "5 314\n0 310 942 628 0\n", "5 314\n0 310 942 628 1\n", "5 314\n1 310 942 628 1\n"], "outputs": ["2 \n", "2 ", "1\n", "0\n", "3\n", "314 628 1256 942 1570 \n", "314 628 1256 942 1570\n", "315 629 1257 943 1571\n"]} | coding | 700 |
Solve the programming task below in a Python markdown code block.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer a_{i} — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginn... | {"inputs": ["1 4 1\n1\n", "1 4 1\n1\n", "2 2 2\n1 3\n", "2 3 1\n1 2\n", "2 3 1\n1 2\n", "2 2 2\n2 3\n", "2 2 2\n1 3\n", "3 3 2\n3 5 1\n"], "outputs": ["1\n", "1\n", "0\n", "2\n", "2\n", "1\n", "0\n", "1\n"]} | coding | 496 |
Solve the programming task below in a Python markdown code block.
E-training
Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training.
As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6.
Multiples of 2 were $ A $, multiples o... | {"inputs": ["6 5 2 1", "9 5 2 1", "0 5 2 1", "6 3 2 1", "12 5 2 1", "-1 5 2 1", "-1 0 2 0", "-1 0 1 0"], "outputs": ["0\n", "3\n", "-6\n", "2", "6\n", "-7\n", "-3\n", "-2\n"]} | coding | 438 |
Solve the programming task below in a Python markdown code block.
Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in... | {"inputs": ["1\n3\n2\n3\n76\n116\n0", "1\n2\n4\n3\n76\n324\n0", "1\n1\n2\n0\n76\n116\n0", "1\n1\n1\n3\n333\n54\n0", "1\n2\n6\n1\n347\n31\n0", "1\n2\n4\n3\n76\n1250\n0", "1\n2\n3\n3\n76\n1250\n0", "1\n3\n3\n3\n76\n1250\n0"], "outputs": ["1\n3\n2\n3\n10\n14\n", "1\n2\n2\n3\n10\n18\n", "1\n1\n2\n", "1\n1\n1\n3\n21\n10\n",... | coding | 707 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.
Create the maximum number of length k <= m + n fr... | {"functional": "def check(candidate):\n assert candidate(nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5) == [9,8,6,5,3]\n assert candidate(nums1 = [6,7], nums2 = [6,0,4], k = 5) == [6,7,6,0,4]\n assert candidate(nums1 = [3,9], nums2 = [8,9], k = 3) == [9,8,9]\n\n\ncheck(Solution().maxNumber)"} | coding | 141 |
Solve the programming task below in a Python markdown code block.
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be w_{i}, then 0 < w_1 ≤ w_2 ≤ ... ≤ w_{k} ho... | {"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "3 3 3\n2 2 2\n1 1 3\n", "3 3 3\n2 2 2\n0 1 3\n", "3 3 3\n0 2 2\n0 1 3\n", "3 3 3\n2 2 2\n1 1 3\n", "5 4 5\n1 2 2 3 4\n1 3 4 5\n", "5 4 5\n1 2 2 3 4\n1 3 4 5\n"], "outputs": ["NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 498 |
Solve the programming task below in a Python markdown code block.
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis.
Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i.
Similarly, among the lines parallel to the y... | {"inputs": ["3 3\n1 3 4\n1 3 9", "3 3\n1 3 4\n0 3 9", "3 3\n1 3 4\n1 3 7", "3 3\n1 3 8\n0 3 9", "3 3\n0 3 4\n1 3 6", "3 3\n1 3 4\n0 3 3", "3 3\n1 3 3\n0 3 3", "3 3\n1 1 5\n0 2 3"], "outputs": ["96\n", "108\n", "72\n", "252\n", "80\n", "36\n", "24\n", "48\n"]} | coding | 394 |
Solve the programming task below in a Python markdown code block.
Share price
===========
You spent all your saved money to buy some shares.
You bought it for `invested`, and want to know how much it's worth, but all the info you can quickly get are just the change the shares price made in percentages.
Your task:
--... | {"functional": "_inputs = [[100, []], [100, [-50, 50]], [100, [-50, 100]], [100, [-20, 30]], [1000, [0, 2, 3, 6]]]\n_outputs = [['100.00'], ['75.00'], ['100.00'], ['104.00'], ['1113.64']]\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,... | coding | 194 |
Solve the programming task below in a Python markdown code block.
# Let's play Psychic
A box contains green, red, and blue balls. The total number of balls is given by `n` (`0 < n < 50`).
Each ball has a mass that depends on the ball color. Green balls weigh `5kg`, red balls weigh `4kg`, and blue balls weigh `3kg`.
... | {"functional": "_inputs = [[3, 12], [40, 180], [30, 130], [32, 148], [18, 80], [18, 74], [50, 180], [50, 172]]\n_outputs = [[[[0, 3, 0], [1, 1, 1]]], [[[20, 20, 0], [21, 18, 1], [22, 16, 2], [23, 14, 3], [24, 12, 4], [25, 10, 5], [26, 8, 6], [27, 6, 7], [28, 4, 8], [29, 2, 9], [30, 0, 10]]], [[[10, 20, 0], [11, 18, 1],... | coding | 318 |
Solve the programming task below in a Python markdown code block.
You are given a sequence $A_1, A_2, \ldots, A_N$. For each $k$ ($1 \le k \le N$), let's define a function $f(k)$ in the following way:
- Consider a sequence $B_1, B_2, \ldots, B_N$, which is created by setting $A_k = 0$. Formally, $B_k = 0$ and $B_i = A_... | {"inputs": ["2\n6\n1 2 1 1 3 1\n3\n4 1 4"], "outputs": ["6\n2"]} | coding | 368 |
Solve the programming task below in a Python markdown code block.
You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
-----Input-----
The first line contains posit... | {"inputs": ["2\n3 3\n", "2\n3 3\n", "3\n5 6 5\n", "3\n2 1 1\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n2 1 1\n", "3\n1 1 2\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 225 |
Solve the programming task below in a Python markdown code block.
You are given an integer $N$. Consider set $S=\{0,\:1,\ldots,\:2^N-1\}$. How many subsets $A\subset S$ with $\bigoplus_{x\in A}x=0$ ($\theta$ denotes xor operation) are there?
Print your answer modulo $(10^9+7)$.
Note that the xorsum of an empty set... | {"inputs": ["2\n1\n2\n"], "outputs": ["2\n4\n"]} | coding | 302 |
Solve the programming task below in a Python markdown code block.
You have two strings $s_1$ and $s_2$ of length $n$, consisting of lowercase English letters. You can perform the following operation any (possibly zero) number of times:
Choose a positive integer $1 \leq k \leq n$.
Swap the prefix of the string $s_1$ a... | {"inputs": ["7\n3\ncbc\naba\n5\nabcaa\ncbabb\n5\nabcaa\ncbabz\n1\na\na\n1\na\nb\n6\nabadaa\nadaaba\n8\nabcabdaa\nadabcaba\n"], "outputs": ["YES\nYES\nNO\nYES\nNO\nNO\nYES\n"]} | coding | 724 |
Solve the programming task below in a Python markdown code block.
Gru wanted to upgrade the quality of his minions' despicableness through his new base, The Volcano. Dave, desperately wanting the Minion of the Year award, rushed to The Volcano only to find out that he needs to solve a series of questions before he can ... | {"inputs": ["2\n7 2\n1 1 1 5\n7 8 8 7\n11 5\n1 1 1 1\n0 1 2 3\n3 2 1 0\n9 8 7 6\n0 0 1 1\n"], "outputs": ["7\nwala\n2\n1\nwala\n33\n0\n"]} | coding | 644 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.
Please complete the following python code precisely:
```python
# Defini... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([3,1,4,None,2]), k = 1) == 1\n assert candidate(root = tree_node([5,3,6,2,4,None,None,1]), k = 3) == 3\n\n\ncheck(Solution().kthSmallest)"} | coding | 142 |
Solve the programming task below in a Python markdown code block.
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the $n$ days of summer. On the $i$-th day, $a_i$ ... | {"inputs": ["1 0 0\n7\n", "1 0 1\n7\n", "1 0 0\n10\n", "1 0 0\n10\n", "1 0 1\n10\n", "2 1 0\n2 1\n", "2 0 1\n2 1\n", "2 2 2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | coding | 628 |
Solve the programming task below in a Python markdown code block.
Given is a permutation P of \{1, 2, \ldots, N\}.
For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R.
Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}.
-----Constraints-----
- 2... | {"inputs": ["2\n1 2\n", "3\n1 3 2", "3\n3 1 2", "3\n3 2 1", "3\n2 1 3", "3\n1 2 3", "3\n1 3 2", "3\n1 2 3"], "outputs": ["1\n", "5\n", "4\n", "5\n", "4\n", "5\n", "5\n", "5\n"]} | coding | 302 |
Solve the programming task below in a Python markdown code block.
MoEngage has 3 decks. Each deck consists of N cards, numbered from 1 to N. He draws out 1 card from each deck randomly with each card having an equal probability of being drawn.
MoEngage drew cards numbered A and B from the decks 1 and 2 respectively. N... | {"inputs": ["3\n4 2 3\n6 2 1\n5 2 5\n"], "outputs": ["2\n1\n0\n"]} | coding | 508 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it a palindrome.
Return the length of the maximum length awesome substring of s.
... | {"functional": "def check(candidate):\n assert candidate(s = \"3242415\") == 5\n assert candidate(s = \"12345678\") == 1\n assert candidate(s = \"213123\") == 6\n assert candidate(s = \"00\") == 2\n\n\ncheck(Solution().longestAwesome)"} | coding | 93 |
Solve the programming task below in a Python markdown code block.
Many years ago, Roman numbers were defined by only `4` digits: `I, V, X, L`, which represented `1, 5, 10, 50`. These were the only digits used. The value of a sequence was simply the sum of digits in it. For instance:
```
IV = VI = 6
IX = XI = 11
XXL = L... | {"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [10], [10000000]]\n_outputs = [[4], [10], [20], [35], [56], [83], [244], [489999753]]\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... | coding | 322 |
Solve the programming task below in a Python markdown code block.
We have a long seat of width X centimeters.
There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would like to seat as many people as possible, but they are all very shy, and... | {"inputs": ["8 3 1", "8 3 3", "4 0 1", "12 3 2", "8 0 11", "17 4 0", "-1 0 1", "13 3 1"], "outputs": ["1\n", "0\n", "3\n", "2\n", "-1\n", "4\n", "-2\n", "3"]} | coding | 203 |
Solve the programming task below in a Python markdown code block.
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know... | {"inputs": ["1\n1\n", "1\n4\n", "1\n1\n", "1\n4\n", "1\n2\n", "2\n1 1\n", "2\n2 3\n", "2\n1 4\n"], "outputs": ["-1\n", "0\n", "-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 424 |
Solve the programming task below in a Python markdown code block.
Doremy has $n$ buckets of paint which is represented by an array $a$ of length $n$. Bucket $i$ contains paint with color $a_i$.
Let $c(l,r)$ be the number of distinct elements in the subarray $[a_l,a_{l+1},\ldots,a_r]$. Choose $2$ integers $l$ and $r$ s... | {"inputs": ["7\n5\n1 3 2 2 4\n5\n1 2 3 4 5\n4\n2 1 2 1\n3\n2 3 3\n2\n2 2\n1\n1\n9\n9 8 5 2 1 1 2 3 3\n"], "outputs": ["1 5\n1 5\n1 4\n1 3\n1 2\n1 1\n1 9\n"]} | coding | 693 |
Solve the programming task below in a Python markdown code block.
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the n inte... | {"inputs": ["1\n1\n", "1\n4\n", "1\n4\n", "1\n1\n", "1\n5\n", "1\n2\n", "1\n9\n", "1\n3\n"], "outputs": ["0", "4", "4", "0", "0\n", "2\n", "0\n", "0\n"]} | coding | 300 |
Solve the programming task below in a Python markdown code block.
The task is simply stated. Given an integer n (3 < n < 10^(9)), find the length of the smallest list of [*perfect squares*](https://en.wikipedia.org/wiki/Square_number) which add up to n. Come up with the best algorithm you can; you'll need it!
Examples... | {"functional": "_inputs = [[15], [16], [17], [18], [19], [2017], [1008], [3456], [4000], [12321], [661915703], [999887641], [999950886], [999951173], [999998999]]\n_outputs = [[4], [1], [2], [2], [3], [2], [4], [3], [2], [1], [4], [1], [3], [2], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, flo... | coding | 457 |
Solve the programming task below in a Python markdown code block.
Chef has the binary representation S of a number X with him. He can modify the number by applying the following operation exactly once:
Make X := X \oplus \lfloor \frac{X}{2^{Y}} \rfloor, where (1 ≤ Y ≤ |S|) and \oplus denotes the [bitwise XOR operation]... | {"inputs": ["4\n2\n10\n2\n11\n3\n101\n3\n110\n"], "outputs": ["2\n1\n2\n1\n"]} | coding | 684 |
Solve the programming task below in a Python markdown code block.
You have been given a String S. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes).
Input Format
The first and only line of input contains the String S. The Stri... | {"inputs": ["eovbgggijqjdsdhjyojeaujcdyyyxtpjlllowjyarfhxjxwkxpranhtlucoklahtokmqyozlrwhldozgbgpalkqlcsiowyeslusn", "sqfopldohhwnbhhpnbxiwzvkybggkgtftvvaqpejznlxluatcppctaulxlnzjepqavvtftgkggbykvzwixbnphhbnwhhodlpofqs", "fnjzxnxnjplfwzowfdrhrvhegkmoncbkembjoudteqchjwqfzlofyflkmxnooasxulwofjzknthqqxgshvwxdvhdnlzjzdjdiif... | coding | 135 |
Solve the programming task below in a Python markdown code block.
Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimiz... | {"inputs": ["7\n3\n10\n100\n300\n200\n1000\n20\n30\n", "10\n4\n1\n2\n3\n4\n10\n20\n30\n40\n100\n200\n"], "outputs": ["40\n", "10\n"]} | coding | 681 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Vietnamese], and [Russian] as well.
Chef has an array A of length N.
Since Chef's favorite number is 3, he wants to make all numbers in the array a multiple of 3.
Chef can do the following operation:
Select any ... | {"inputs": ["3\n3\n1 2 3\n4\n6 3 9 12\n2\n4 3\n"], "outputs": ["1\n0\n-1\n"]} | coding | 455 |
Solve the programming task below in a Python markdown code block.
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:
- Choose two among A, B and C, then increase both by 1.
- ... | {"inputs": ["2 5 4\n", "2 6 3\n", "0 0 0\n", "0 0 1\n", "0 0 50\n", "31 41 5\n", "0 50 50\n", "0 49 49\n"], "outputs": ["2\n", "5\n", "0\n", "1\n", "50\n", "23\n", "25\n", "26\n"]} | coding | 259 |
Solve the programming task below in a Python markdown code block.
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middl... | {"inputs": ["1\n2\n", "1\n1\n", "1\n3\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n8\n", "1\n2\n"], "outputs": ["1/2\n", "0/1\n", "1/4\n", "1/4", "0/1", "3/8\n", "43/128\n", "1/2"]} | coding | 605 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game on a binary string S of length N.
Alice and Bob alternate turns, with Alice going first. On their turn, the current player must choose any index 1 ≤ i < |S| such that S_{i} \neq S_{i+1} and erase either S_{i} or S_{i+1} ... | {"inputs": ["3\n4\n1111\n3\n110\n4\n1010\n"], "outputs": ["Bob\nAlice\nBob"]} | coding | 466 |
Solve the programming task below in a Python markdown code block.
The score of an array $v_1,v_2,\ldots,v_n$ is defined as the number of indices $i$ ($1 \le i \le n$) such that $v_1+v_2+\ldots+v_i = 0$.
You are given an array $a_1,a_2,\ldots,a_n$ of length $n$. You can perform the following operation multiple times:
... | {"inputs": ["5\n5\n2 0 1 -1 0\n3\n1000000000 1000000000 0\n4\n0 0 0 0\n8\n3 0 2 -10 10 -30 30 0\n9\n1 0 0 1 -1 0 1 0 -1\n"], "outputs": ["3\n1\n4\n4\n5\n"]} | coding | 642 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s consisting only of characters a, b and c.
Return the number of substrings containing at least one occurrence of all these characters a, b and c.
Please complete the following python code precisely:
... | {"functional": "def check(candidate):\n assert candidate(s = \"abcabc\") == 10\n assert candidate(s = \"aaacb\") == 3\n assert candidate(s = \"abc\") == 1\n\n\ncheck(Solution().numberOfSubstrings)"} | coding | 86 |
Solve the programming task below in a Python markdown code block.
This is the performance edition of [this kata](https://www.codewars.com/kata/ulam-sequences). If you didn't do it yet, you should begin there.
---
The Ulam sequence U is defined by `u0=u`, `u1=v`, with the general term `u_n` for `n>2` given by the leas... | {"functional": "_inputs = [[1, 2, 5], [3, 4, 5], [5, 6, 8]]\n_outputs = [[[1, 2, 3, 4, 6]], [[3, 4, 7, 10, 11]], [[5, 6, 11, 16, 17, 21, 23, 26]]]\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 isinst... | coding | 638 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Mike likes strings. He is also interested in algorithms. A few days ago he discovered for himself a very nice problem:
You are given an AB-string S. You need to count the number of subs... | {"inputs": ["ABBCABA", "ABABBBA", "@BABBBA", "@BABCBA", "AB@BCAB", "BCABACB", "ABCBACB", "ABACBBA"], "outputs": ["2\n", "0\n", "1\n", "3\n", "4\n", "6\n", "5\n", "2\n"]} | coding | 361 |
Solve the programming task below in a Python markdown code block.
-----Input-----
The input contains a single integer a (1 ≤ a ≤ 64).
-----Output-----
Output a single integer.
-----Examples-----
Input
2
Output
1
Input
4
Output
2
Input
27
Output
5
Input
42
Output
6 | {"inputs": ["2\n", "4\n", "1\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n", "5\n"]} | coding | 76 |
Solve the programming task below in a Python markdown code block.
Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid,
B potions of blue liquid, and G potions of green liquid.
-
The red liquid potions have liquid amounts given ... | {"inputs": ["3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n2\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8", "3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n3\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8", "3\n1 1 1 1\n1\n4\n5\n1 1 1 1\n3\n4\n6\n3 2 2 2\n2 2 3\n2 7\n6 8", "3\n1 1 1 1\n1\n4\n5\n1 1 1 2\n3\n4\n6\n3 2 2 2\n2 2 3\n2 7\n6 8", "3\n2 1 1 1\n1\n4\n5\n1 1 1 2\n3\n4\n6\n... | coding | 591 |
Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K.
a has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal... | {"inputs": ["1 4\n1", "1 2\n0", "1 6\n1", "1 2\n1", "3 5\n7\n5\n7", "3 6\n7\n5\n7", "3 6\n7\n5\n10", "3 6\n7\n5\n12"], "outputs": ["0\n", "0\n", "0\n", "0", "6\n", "5", "5\n", "5\n"]} | coding | 265 |
Solve the programming task below in a Python markdown code block.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane.
Each of the next n lines contains two real coordinates x_{i} and y_{i} of the $i^{\text{th}}$ point, specified with exactly 2 fractional digits... | {"inputs": ["1\n1.00 1.01\n", "1\n0.00 0.01\n", "1\n0.00 0.01\n", "1\n1.00 1.01\n", "1\n792.52 879.16\n", "1\n792.52 879.16\n", "1\n1000.00 999.99\n", "1\n1000.00 999.99\n"], "outputs": ["6.010\n", "5.010\n", "5.010", "6.010", "884.160\n", "884.160", "1004.990\n", "1004.990"]} | coding | 655 |
Solve the programming task below in a Python markdown code block.
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you h... | {"inputs": ["1 1\n2 1", "1 1\n2 1\n", "3 4\n4 3\n4 1\n3 2", "3 4\n4 3\n3 0\n3 4", "3 4\n4 3\n3 1\n2 4", "3 0\n4 3\n3 1\n2 4", "3 5\n4 3\n4 1\n2 2", "3 4\n4 3\n4 1\n6 2"], "outputs": ["0", "0\n", "5\n", "7\n", "8\n", "0\n", "6\n", "3\n"]} | coding | 338 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums of length n, and an integer array queries of length m.
Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that ... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,2,1], queries = [3,10,21]) == [2,3,4]\n assert candidate(nums = [2,3,4,5], queries = [1]) == [0]\n\n\ncheck(Solution().answerQueries)"} | coding | 143 |
Solve the programming task below in a Python markdown code block.
Create a function that takes a positive integer and returns the next bigger number that can be formed by rearranging its digits. For example:
```
12 ==> 21
513 ==> 531
2017 ==> 2071
```
If the digits can't be rearranged to form a bigger number, return ... | {"functional": "_inputs = [[12], [513], [2017], [414], [144], [123456789], [1234567890], [9876543210], [9999999999], [59884848459853]]\n_outputs = [[21], [531], [2071], [441], [414], [123456798], [1234567908], [-1], [-1], [59884848483559]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin... | coding | 142 |
Solve the programming task below in a Python markdown code block.
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct.
Niwango was doing some work while playing this playlist. (That is, all the s... | {"inputs": ["1\nabcde 0000\nabcde", "1\nabcde 1000\nabcde", "3\ndwango 2\nsixth 5\nprelims 4\ndwango", "3\ndwango 2\nsixth 5\nprelims 7\ndwango", "3\ndwango 2\nsixth 0\nprelims 7\ndwango", "3\ndwango 2\nshxth 5\nsmilerp 1\ndwango", "3\ndwango 2\nshxth 10\nsmilerp 7\ndwango", "3\ndwango 2\nsixth 5\nprelims 25\ndwango"],... | coding | 516 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian
Chef is sitting in a very boring lecture, waiting for it to end. He has recently asked his friend about the time, and instead of the straightforward answer, his friend, being an absolute jerk, ... | {"inputs": ["2\n0\n7", "2\n2\n6", "2\n1\n2", "2\n2\n5", "2\n0\n9", "2\n1\n3", "2\n2\n4", "2\n1\n9"], "outputs": ["00:00\n05:26\n06:34\n", "03:16\n08:44\n02:12\n09:48\n", "04:22\n07:38\n03:16\n08:44\n", "03:16\n08:44\n02:10\n09:50\n", "00:00\n03:18\n08:42\n", "04:22\n07:38\n01:06\n10:54\n", "03:16\n08:44\n05:28\n06:32\n... | coding | 471 |
Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $k$.
Your task is to construct such a string $s$ of length $n$ that for each $i$ from $1$ to $k$ there is at least one $i$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and ... | {"inputs": ["3\n7 3\n4 4\n6 2\n", "3\n7 3\n4 4\n6 2\n", "3\n3 3\n4 4\n6 2\n", "3\n7 3\n4 2\n6 2\n", "3\n7 2\n4 4\n6 2\n", "3\n7 3\n4 2\n5 2\n", "3\n7 3\n4 2\n5 1\n", "3\n7 3\n4 4\n5 1\n"], "outputs": ["abcabca\nabcd\nababab\n", "abcabca\nabcd\nababab\n", "abc\nabcd\nababab\n", "abcabca\nabab\nababab\n", "abababa\nabcd\... | coding | 462 |
Solve the programming task below in a Python markdown code block.
-----Problem-----
Suppose there is a circle. There are N Juice shops on that circle. Juice shops are numbered 0 to N-1 (both inclusive). You have two pieces of information corresponding to each of the juice shop:
(1) the amount of Juice that a particula... | {"inputs": ["3\n1 5\n10 3\n3 4"], "outputs": ["1"]} | coding | 328 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the lon... | {"functional": "def check(candidate):\n assert candidate(s = \"abpcplea\", dictionary = [\"ale\",\"apple\",\"monkey\",\"plea\"]) == \"apple\"\n assert candidate(s = \"abpcplea\", dictionary = [\"a\",\"b\",\"c\"]) == \"a\"\n\n\ncheck(Solution().findLongestWord)"} | coding | 117 |
Solve the programming task below in a Python markdown code block.
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.
Iahu... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "4\n1 1 1 4\n", "4\n1 1 1 3\n", "4\n1 1 1 3\n"], "outputs": ["YES", "YES\n", "NO", "NO\n", "NO\n", "YES", "NO", "NO\n"]} | coding | 327 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
Please complete the following python code precisely:
```python
class Solution... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,1]) == True\n assert candidate(nums = [1,2,3,4]) == False\n assert candidate(nums = [1,1,1,3,3,4,3,2,4,2]) == True\n\n\ncheck(Solution().containsDuplicate)"} | coding | 76 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.
Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a b... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]) == [1,-1,-1,-1,-1]\n assert candidate(grid = [[-1]]) == [-1]\n assert candidate(grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]) == [0,1,2,3,4... | coding | 275 |
Solve the programming task below in a Python markdown code block.
Chefland is a grid with N$N$ rows and M$M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them.
For each d$d$ between 1$1$ and N+M−2$N+M-2$... | {"inputs": ["1\n3 4\n0011\n0000\n0100"], "outputs": ["1 0 1 1 0"]} | coding | 461 |
Solve the programming task below in a Python markdown code block.
Complete the function to determine the number of bits required to convert integer `A` to integer `B` (where `A` and `B` >= 0)
The upper limit for `A` and `B` is 2^(16), `int.MaxValue` or similar.
For example, you can change 31 to 14 by flipping the 4th... | {"functional": "_inputs = [[31, 14], [7, 17], [31, 0], [0, 0], [127681, 127681], [312312312, 5645657], [43, 2009989843]]\n_outputs = [[2], [3], [5], [0], [0], [13], [17]]\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 | 204 |
Solve the programming task below in a Python markdown code block.
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is... | {"inputs": ["1\n6\n1 0 -3 1 0 1\n", "1\n6\n5 -5 -3 1 1 1\n", "1\n6\n5 -6 -3 2 1 1\n", "1\n6\n5 -4 -4 1 1 1\n", "1\n6\n5 -6 -4 2 2 1\n", "1\n6\n6 -5 -3 1 0 1\n", "1\n6\n3 -6 -4 4 2 1\n", "1\n6\n6 -4 -3 1 0 0\n"], "outputs": ["2\n", "3\n", "4\n", "3\n", "5\n", "2\n", "7\n", "1\n"]} | coding | 596 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following re... | {"functional": "def check(candidate):\n assert candidate(area = 4) == [2,2]\n assert candidate(area = 37) == [37,1]\n assert candidate(area = 122122) == [427,286]\n\n\ncheck(Solution().constructRectangle)"} | coding | 174 |
Solve the programming task below in a Python markdown code block.
You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (a_{j}, b_{j}).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one ca... | {"inputs": ["1 1\n1\n1 1\n", "1 1\n1\n1 1\n", "3 1\n1 3 2\n1 2\n", "3 1\n3 2 1\n1 2\n", "3 1\n2 3 1\n1 1\n", "3 1\n3 2 1\n1 2\n", "3 1\n1 3 2\n1 2\n", "3 1\n2 3 1\n1 1\n"], "outputs": ["1\n", "1 \n", "3 1 2\n", "3 2 1\n", "2 3 1\n", "3 2 1 \n", "3 1 2 \n", "2 3 1 \n"]} | coding | 374 |
Solve the programming task below in a Python markdown code block.
Santa Claus has received letters from $n$ different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the $i$-th kid asked Santa to give them one of $k_i$ different items as a present. Some items could h... | {"inputs": ["2\n2 2 1\n1 1\n", "2\n2 4 1\n1 1\n", "2\n2 8 1\n1 2\n", "2\n2 8 1\n1 1\n", "2\n2 3 1\n1 1\n", "2\n2 4 1\n1 2\n", "2\n2 4 1\n1 4\n", "2\n2 5 1\n1 1\n"], "outputs": ["124780545\n", "124780545\n", "499122177\n", "124780545\n", "124780545\n", "499122177\n", "124780545\n", "124780545\n"]} | coding | 688 |
Solve the programming task below in a Python markdown code block.
Some time ago Lesha found an entertaining string $s$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.
Lesha chooses an arbitrary (possibly zero)... | {"inputs": ["g\n", "g\n", "h\n", "tt\n", "go\n", "tt\n", "go\n", "ut\n"], "outputs": ["1 g\n", "1 g\n", "1 h\n", "0 \n1 t\n", "2 go\n1 o\n", "0 \n1 t\n", "2 go\n1 o\n", "2 ut\n1 t\n"]} | coding | 690 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:
1 <= pivot < n
nums[0] + nums[1] + ... + nums[pivot - 1] == ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,-1,2], k = 3) == 1\n assert candidate(nums = [0,0,0], k = 1) == 2\n assert candidate(nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33) == 4\n\n\ncheck(Solution().waysToPartition)"} | coding | 184 |
Solve the programming task below in a Python markdown code block.
Chef appeared for an exam consisting of 3 sections. Each section is worth 100 marks.
Chef scored A marks in Section 1, B marks in section 2, and C marks in section 3.
Chef passes the exam if both of the following conditions satisfy:
Total score of Che... | {"inputs": ["5\n9 100 100\n30 40 50\n30 20 40\n0 98 8\n90 80 80\n"], "outputs": ["FAIL\nPASS\nFAIL\nFAIL\nPASS\n"]} | coding | 481 |
Solve the programming task below in a Python markdown code block.
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.
Examples:
Non-string inputs should be converted to strings.
Return an array... | {"functional": "_inputs = [[['bat', 'tab', 'cat']], [['dog', 'cow', 'tap', 'god', 'pat']], [['abcd', 'dcba', 'lls', 's', 'sssll']], [[]], [['adgdfsh', 'wertewry', 'zxcbxcb', 'efveyn']], [[5, 2, 'abc', True, [False]]], [[5777, 'dog', 'god', True, 75]]]\n_outputs = [[[[0, 1], [1, 0]]], [[[0, 3], [2, 4], [3, 0], [4, 2]]],... | coding | 123 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.