task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).
Constraints
* 1 ≤ |V| ≤ 10,000
* 0 ≤ |E| ≤ 100,000
* 0 ≤ wi ≤ 10,000
* The graph is connected
* There are no parallel edges
* There are no s... | {"inputs": ["4 6\n0 1 2\n1 2 1\n2 3 1\n3 0 1\n0 2 1\n1 3 5", "4 6\n0 1 2\n1 2 1\n0 3 0\n3 0 1\n0 2 1\n1 3 5", "4 6\n0 1 2\n1 2 1\n2 3 1\n3 0 1\n0 2 1\n1 1 5", "4 6\n0 1 2\n1 2 1\n0 3 1\n3 0 1\n0 2 1\n1 3 5", "4 6\n0 1 2\n1 2 1\n2 0 1\n3 0 1\n0 2 1\n1 1 5", "4 6\n0 1 2\n1 2 1\n2 0 1\n3 0 1\n0 2 3\n1 3 5", "4 6\n0 1 2\n1... | 348 | 366 |
coding | Solve the programming task below in a Python markdown code block.
Problem
Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even.
Constraints
The input satisfies the following conditions.
* 1 ≤ n ≤ 1018
Input
The input is given in the fo... | {"inputs": ["4", "7", "6", "5", "0", "8", "9", "3"], "outputs": ["1\n", "8\n", "1\n", "2\n", "1\n", "1\n", "2\n", "4"]} | 127 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Petr, Nikita G. and Nikita are the most influential music critics in Saint-Petersburg. They have recently downloaded their favorite band's new album and going to listen to it. Nikita cla... | {"inputs": ["3\n1\n2\n3", "3\n1\n2\n2", "3\n1\n2\n6", "3\n2\n2\n2", "3\n1\n3\n2", "3\n1\n3\n6", "3\n1\n1\n2", "3\n1\n1\n6"], "outputs": ["1.0\n3.0\n5.5", "1.0\n3.0\n3.0\n", "1.0\n3.0\n14.7\n", "3.0\n3.0\n3.0\n", "1.0\n5.5\n3.0\n", "1.0\n5.5\n14.7\n", "1.0\n1.0\n3.0\n", "1.0\n1.0\n14.7\n"]} | 543 | 192 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.
You are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that ther... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]) == 4\n assert candidate(n = 3, edges = [[1,2],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().magnificentSets)"} | 241 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Given is a string S. Each character in S is either a digit (0, ..., 9) or ?.
Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can ... | {"inputs": ["?\n", "5\n", "3\n", "??\n", "74?", "54?", "64?", "?46"], "outputs": ["1\n", "1\n", "0\n", "8\n", "1\n", "0\n", "1\n", "1\n"]} | 217 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
There is a party going on in a club situated in some city. N gangsters will attend that party. The i-th gangster comes to the party at the beginning of S_{i} time and will leave the party... | {"inputs": ["3\n3 2\n1 3\n3 5\n4 6\n4 3\n1 8\n2 9\n3 10\n4 11\n4 3\n1 5\n4 9\n8 13\n12 17"], "outputs": ["1\n2\n0"]} | 709 | 77 |
coding | Solve the programming task below in a Python markdown code block.
For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ i... | {"inputs": ["7\n1 0\n0 1\n0 3\n0 0\n1 0\n0 7\n1 0", "7\n1 0\n0 1\n1 2\n0 0\n1 0\n0 7\n1 0", "7\n0 0\n0 2\n0 3\n0 2\n0 4\n0 3\n1 4", "7\n1 0\n0 1\n0 2\n0 0\n1 0\n1 7\n1 0", "7\n0 2\n0 2\n0 1\n0 0\n1 4\n1 3\n0 0", "7\n0 0\n1 3\n1 0\n0 0\n0 4\n1 3\n1 9", "7\n1 0\n0 2\n1 2\n0 0\n1 0\n0 7\n1 0", "7\n0 0\n0 2\n0 1\n0 0\n0 0\... | 286 | 382 |
coding | Solve the programming task below in a Python markdown code block.
During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome.
Recall that a number is called a palindrom... | {"inputs": ["1\n3\n100\n", "1\n3\n109\n", "3\n2\n99\n4\n1023\n3\n385\n"], "outputs": ["899\n", "890\n", "12\n8976\n614\n"]} | 490 | 74 |
coding | Solve the programming task below in a Python markdown code block.
The snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so.
Formally, eve... | {"inputs": ["7\n5\n1 2 3 2 1\n7\n2 3 4 5 4 3 2\n5\n1 2 3 4 3\n5\n1 3 5 3 1\n7\n1 2 3 4 3 2 1\n4\n1 2 3 2\n4\n1 2 2 1"], "outputs": ["yes\nno\nno\nno\nyes\nno\nno"]} | 710 | 112 |
coding | Solve the programming task below in a Python markdown code block.
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.
You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the c... | {"inputs": ["3\n0 5\n3 9\n7 8", "3\n0 8\n3 9\n7 8", "3\n0 8\n3 9\n9 8", "3\n1 5\n3 9\n7 8", "3\n0 8\n3 9\n16 8", "3\n0 4\n3 9\n16 8", "3\n0 4\n3 9\n3 10", "3\n0 0\n22 26\n6 0"], "outputs": ["4\n", "1\n", "1\n", "3", "1\n", "4\n", "3\n", "16\n"]} | 295 | 163 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
L... | {"inputs": ["1\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n"], "outputs": ["1\n", "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n"]} | 316 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students... | {"functional": "def check(candidate):\n assert candidate(seats = [3,1,5], students = [2,7,4]) == 4\n assert candidate(seats = [4,1,5,9], students = [1,3,2,6]) == 7\n assert candidate(seats = [2,2,6,6], students = [1,3,2,6]) == 4\n\n\ncheck(Solution().minMovesToSeat)"} | 204 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp n... | {"inputs": ["1\nz\ny\n", "1\na\nb\n", "2\nab\nba\n", "2\nab\nac\n", "2\nba\nca\n", "2\ner\nre\n", "2\nac\ncb\n", "2\nab\naa\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n"]} | 394 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions:
There will be 4 different kinds of queries:-
-
Alice gives an integer $i$ and Bob has to repor... | {"inputs": ["1\n2 2\n2\n1\n1\n1"], "outputs": ["ON"]} | 551 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table $M$ with $n$ rows and $n$ columns such that $M_{ij}=a_i \cdot a_j$ where $a_1, \dots, a_n$ is some sequence of positive integers.
Of course, the ... | {"inputs": ["3\n0 2 4\n2 0 8\n4 8 0\n", "3\n0 4 4\n4 0 4\n4 4 0\n", "3\n0 6 6\n6 0 4\n6 4 0\n", "3\n0 6 6\n6 0 9\n6 9 0\n", "3\n0 9 9\n9 0 9\n9 9 0\n", "3\n0 4 8\n4 0 8\n8 8 0\n", "3\n0 6 6\n6 0 9\n6 9 0\n", "3\n0 4 8\n4 0 8\n8 8 0\n"], "outputs": ["1 2 4 ", "2 2 2 ", "3 2 2 ", "2 3 3 ", "3 3 3 ", "2 2 4 ", "2 3 3 ", "... | 460 | 239 |
coding | Solve the programming task below in a Python markdown code block.
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
# Description:
Give you two number `m` and `n`(two positive integer, m < n), make a triangle pattern wit... | {"functional": "_inputs = [[1, 12], [1, 100]]\n_outputs = [[''], ['']]\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 ... | 313 | 167 |
coding | Solve the programming task below in a Python markdown code block.
How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a single spa... | {"inputs": ["6 2 4", "6 2 1", "6 1 1", "6 0 1", "4 0 0", "1 0 0", "2 0 0", "1 1 0"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]} | 116 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Let's define $f(x)$ for a positive integer $x$ as the length of the base-10 representation of $x$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that.
You are given two arrays $a$ and $b... | {"inputs": ["4\n1\n1\n1000\n4\n1 2 3 4\n3 1 4 2\n3\n2 9 3\n1 100 9\n10\n75019 709259 5 611271314 9024533 81871864 9 3 6 4865\n9503 2 371245467 6 7 37376159 8 364036498 52295554 169\n"], "outputs": ["2\n0\n2\n18\n"]} | 646 | 175 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.
Return the length of the lo... | {"functional": "def check(candidate):\n assert candidate(s = \"ABAB\", k = 2) == 4\n assert candidate(s = \"AABABBA\", k = 1) == 4\n\n\ncheck(Solution().characterReplacement)"} | 110 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Well met with Fibonacci bigger brother, AKA Tribonacci.
As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't g... | {"functional": "_inputs = [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]]\n_outputs = [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, 4, 7, 13, ... | 451 | 766 |
coding | Solve the programming task below in a Python markdown code block.
Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple of 7, or... | {"inputs": ["26\n5 10\n4 10\n100 3\n123456 7\n49 7\n158854 50\n822992 101\n691238 345\n682373 49\n643378 53\n328697 62\n446656 228\n368684 130\n530193 371\n864163 325\n708578 207\n915093 485\n711860 28\n234554 366\n309089 25\n595700 393\n10 6\n9 19\n4 10\n11 2\n11 3"], "outputs": ["10\n0\n99\n123459\n49\n158850\n822948... | 201 | 379 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}.
You can apply the following operation to this permutation, any number of times (possibly zero):
* Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, ... | {"inputs": ["4 4\n4 2 3 1", "4 1\n4 2 3 1", "4 2\n4 3 2 1", "4 3\n4 1 3 2", "4 2\n4 1 3 2", "4 3\n3 2 4 1", "4 3\n4 2 3 1", "4 5\n4 2 3 1"], "outputs": ["4\n2\n3\n1\n", "1\n2\n3\n4\n", "4\n3\n2\n1\n", "4\n1\n3\n2\n", "2\n1\n4\n3\n", "3\n2\n4\n1\n", "4\n2\n3\n1\n", "4\n2\n3\n1\n"]} | 306 | 190 |
coding | Solve the programming task below in a Python markdown code block.
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function $g : \{1,2, \ldots, n \} \rightarrow \{1,2, \ldots, n \}$, that for any $x \in \{1,2, \ldots, n \}$ the formula g(g(x)) = g(x... | {"inputs": ["1\n1\n", "2\n1 2\n", "2\n1 1\n", "2\n2 2\n", "2\n2 1\n", "3\n2 3 3\n", "3\n2 3 1\n", "3\n2 1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "3\n", "2\n"]} | 745 | 106 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.
The customer weirdly values the colored balls. Each colored ball's value is the number of balls of that c... | {"functional": "def check(candidate):\n assert candidate(inventory = [2,5], orders = 4) == 14\n assert candidate(inventory = [3,5], orders = 6) == 19\n assert candidate(inventory = [2,8,4,10,6], orders = 20) == 110\n assert candidate(inventory = [1000000000], orders = 1000000000) == 21\n\n\ncheck(Solution()... | 259 | 128 |
coding | Solve the programming task below in a Python markdown code block.
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by s... | {"inputs": ["1 2 3 3\nw\n", "1 2 6 3\nw\n", "1 2 6 5\nw\n", "1 3 6 5\nw\n", "1 3 3 3\nw\n", "1 3 6 3\nw\n", "4 2 3 16\nwwhw\n", "4 2 3 14\nwwhw\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n", "3\n"]} | 596 | 137 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way:
nums[0] = 0
nums[1] = 1
nums[2 * i] = nums[i] when 2 <= 2 * i <= n
nums[2 * i + 1] = nums[i] + nums[i + 1]... | {"functional": "def check(candidate):\n assert candidate(n = 7) == 3\n assert candidate(n = 2) == 1\n assert candidate(n = 3) == 2\n\n\ncheck(Solution().getMaximumGenerated)"} | 158 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Chef categorises an instagram account as *spam*, if, the *following* count of the account is more than 10 times the count of *followers*.
Given the *following* and *follower* count of an account as X and Y respectively, find whether it is a *spam* acco... | {"inputs": ["4\n1 10\n10 1\n11 1\n97 7\n"], "outputs": ["NO\nNO\nYES\nYES\n"]} | 437 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
... | {"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "2\n1 1\n", "2\n1 1\n", "2\n1 0\n", "1\n1000\n", "1\n1000\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | 284 | 98 |
coding | Solve the programming task below in a Python markdown code block.
Chef has allocated himself a budget of P rupees to buy Diwali crackers. There are only 3 types of crackers available in the market and each type of cracker can be bought any number of times.
1. Fuljhari, where each costs a rupees
2. Anar, where each cos... | {"inputs": ["3\n100 5 5 10 4 8\n16 2 2 2 1 1\n55 1 2 3 4 5"], "outputs": ["4\n4\n9"]} | 693 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Luntik has decided to try singing. He has $a$ one-minute songs, $b$ two-minute songs and $c$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert.
He wants to make the abso... | {"inputs": ["4\n1 1 1\n2 1 3\n5 5 5\n1 1 2\n", "4\n1 1 1\n2 1 3\n5 2 5\n1 1 2\n", "4\n1 2 2\n2 1 1\n3 2 5\n1 1 2\n", "4\n1 2 2\n2 2 1\n3 2 2\n1 1 2\n", "4\n1 1 2\n2 2 1\n3 2 2\n2 1 2\n", "4\n2 2 0\n4 2 1\n6 4 5\n1 1 2\n", "4\n1 1 2\n2 2 1\n4 2 2\n2 1 2\n", "4\n2 2 0\n4 2 0\n6 4 5\n1 1 2\n"], "outputs": ["0\n1\n0\n1\n",... | 398 | 310 |
coding | Solve the programming task below in a Python markdown code block.
There are just some things you can't do on television. In this case, you've just come back from having a "delicious" Barth burger and you're set to give an interview. The Barth burger has made you queezy, and you've forgotten some of the import rules of ... | {"functional": "_inputs = [['water'], ['wet'], ['wash'], [\"i don't know\"], ['slime'], ['wet water'], ['slime water'], [\"I don't know if this will work\"], [\"I don't know if this will work without watering it first.\"], [''], ['is there SLIME in that?!'], [\"i won't say anything\"], ['WaTeR?'], ['but i can say sludg... | 414 | 381 |
coding | Solve the programming task below in a Python markdown code block.
Problem
Den, the phone number of Ukunikia Co., Ltd., enters a very long phone number into the phone every day.
One day, too tired, Den came up with a surprising idea.
"Isn't it even a little easier if you rearrange the arrangement of the buttons on the ... | {"inputs": ["10\n1598114589", "10\n2555486547", "10\n2722382398", "10\n2713182985", "10\n4333783596", "10\n1859787539", "10\n1888971773", "10\n6843843631"], "outputs": ["142\n853\n967\n", "123\n659\n847\n", "139\n428\n576\n", "317\n482\n659\n", "124\n783\n695\n", "124\n853\n796\n", "173\n892\n456\n", "125\n347\n689\n"]... | 478 | 238 |
coding | Solve the programming task below in a Python markdown code block.
We have A apples and P pieces of apple.
We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.
Find the maximum number of apple pies we can make with what we have now.
-----Constraints-----
- A... | {"inputs": ["2 3", "1 1", "2 6", "0 0", "0 6", "2 5", "5 0", "1 3"], "outputs": ["4\n", "2\n", "6\n", "0\n", "3\n", "5\n", "7\n", "3"]} | 185 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Little chief has his own restaurant in the city. There are N workers there. Each worker has his own salary. The salary of the i-th worker equals to W_{i} (i = 1, 2, ..., N). Once, chief decided to equalize all workers, that is, he wants to make salaries ... | {"inputs": ["2\n3\n1 4 3\n2\n7 2", "2\n3\n1 0 3\n2\n8 2", "2\n3\n1 4 3\n2\n42 7", "2\n3\n1 4 3\n2\n47 7", "2\n3\n1 4 3\n2\n20 7", "2\n3\n1 4 3\n2\n20 8", "2\n3\n1 0 2\n2\n1 17", "2\n3\n1 4 3\n2\n20 2"], "outputs": ["5\n5\n", "4\n6\n", "5\n35\n", "5\n40\n", "5\n13\n", "5\n12\n", "3\n16\n", "5\n18\n"]} | 485 | 202 |
coding | Solve the programming task below in a Python markdown code block.
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented... | {"inputs": ["1\n2\n", "1\n2\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 506 | 96 |
coding | Solve the programming task below in a Python markdown code block.
There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.
Example
$n=7$
$ar=[1,2,1,2,1,3,2]$
There is one pair o... | {"inputs": ["9\n10 20 20 10 10 30 50 10 20"], "outputs": ["3"]} | 356 | 39 |
coding | Solve the programming task below in a Python markdown code block.
There is a street with $n$ houses in a line, numbered from $1$ to $n$. The house $i$ is initially painted in color $c_i$. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street ... | {"inputs": ["3\n10 2\n1 1 2 2 1 1 2 2 2 1\n7 1\n1 2 3 4 5 6 7\n10 3\n1 3 3 3 3 1 2 1 3 3\n", "6\n6 4\n2 1 1 1 1 2\n10 5\n1 1 1 2 2 1 2 2 1 1\n9 6\n1 2 3 1 2 3 1 2 3\n1 1\n100\n10 10\n1 100 2 99 3 98 4 97 5 96\n8 1\n50 50 50 50 50 50 50 50\n"], "outputs": ["3\n6\n2\n", "1\n1\n2\n0\n1\n0\n"]} | 624 | 235 |
coding | Solve the programming task below in a Python markdown code block.
There are 3^N people dancing in circle. We denote with 0,1,\dots, 3^{N}-1 the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person.
The people are going ... | {"inputs": ["1\nRRS", "1\nSRR", "1\nSSR", "1\nRSR", "1\nRRR", "1\nRSS", "1\nSRS", "2\nSRRRSSSSR"], "outputs": ["1 0 2 ", "2 1 0 ", "1 2 0 ", "0 2 1 ", "0 1 2 ", "1 2 0 ", "2 0 1", "4 6 5 1 3 2 7 0 8 "]} | 519 | 125 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp has prepared $n$ competitive programming problems. The topic of the $i$-th problem is $a_i$, and some problems' topics may coincide.
Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and al... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n4 1\n", "2\n5 1\n", "2\n5 0\n", "2\n1 0\n", "2\n5 -1\n"], "outputs": ["2\n", "2", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 568 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a_1, a_2, ..., a_{n} of length n, that the following condition fulfills: a_2 - a_1 = a_3 - a_2 = a_4 - a_3 = ... ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n10\n", "1\n11\n", "1\n-1\n", "1\n17\n", "1\n10\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 467 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C c... | {"inputs": ["3 5\n6\n2\n9\n7\n0", "3 5\n6\n2\n8\n7\n0", "3 5\n5\n2\n9\n7\n0", "3 5\n6\n1\n9\n6\n5", "3 5\n6\n2\n8\n5\n0", "6 5\n5\n2\n9\n7\n0", "3 5\n6\n1\n9\n6\n3", "5 5\n6\n2\n8\n7\n0"], "outputs": ["2\n0\n1\n3\n0\n", "2\n0\n2\n3\n0\n", "1\n0\n1\n3\n0\n", "2\n0\n1\n2\n1\n", "2\n0\n2\n1\n0\n", "0\n0\n2\n0\n0\n", "2\n0... | 359 | 222 |
coding | Solve the programming task below in a Python markdown code block.
Reve has two integers $n$ and $k$.
Let $p$ be a permutation$^\dagger$ of length $n$. Let $c$ be an array of length $n - k + 1$ such that $$c_i = \max(p_i, \dots, p_{i+k-1}) + \min(p_i, \dots, p_{i+k-1}).$$ Let the cost of the permutation $p$ be the maxi... | {"inputs": ["3\n5 3\n5 1\n6 6\n"], "outputs": ["5 4 1 3 2\n1 2 3 4 5\n6 5 4 3 2 1\n"]} | 615 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Congratulations! That Special Someone has given you their phone number.
But WAIT, is it a valid number?
Your task is to write a function that verifies whether a given string contains a valid British mobile (cell) phone number or not.
If valid, retur... | {"functional": "_inputs = [['07454876120'], ['0754876120'], ['0745--487-61-20'], ['+447535514555'], ['-07599-51-4555'], ['075335440555'], ['+337535512555'], ['00535514555'], ['+447+4435512555'], ['+44']]\n_outputs = [['In with a chance'], ['Plenty more fish in the sea'], ['In with a chance'], ['In with a chance'], ['In... | 279 | 361 |
coding | Solve the programming task below in a Python markdown code block.
Pirates have notorious difficulty with enunciating. They tend to blur all the letters together and scream at people.
At long last, we need a way to unscramble what these pirates are saying.
Write a function that will accept a jumble of letters as well ... | {"functional": "_inputs = [['trisf', ['first']], ['oob', ['bob', 'baobab']], ['ainstuomn', ['mountains', 'hills', 'mesa']], ['oolp', ['donkey', 'pool', 'horse', 'loop']], ['ortsp', ['sport', 'parrot', 'ports', 'matey']], ['ourf', ['one', 'two', 'three']]]\n_outputs = [[['first']], [[]], [['mountains']], [['pool', 'loop... | 174 | 261 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.
In the American keyboard:
the first row consists of the cha... | {"functional": "def check(candidate):\n assert candidate(words = [\"Hello\",\"Alaska\",\"Dad\",\"Peace\"]) == [\"Alaska\",\"Dad\"]\n assert candidate(words = [\"omk\"]) == []\n assert candidate(words = [\"adsdf\",\"sfd\"]) == [\"adsdf\",\"sfd\"]\n\n\ncheck(Solution().findWords)"} | 128 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You are given N integers A_{1}, A_{2}, \ldots, A_{N}.
You can perform the following operation any number of times:
Select any index i such that 1 ≤ i ≤ (N-1);
Subtract 1 from A_{i} and 2 from A_{i+1}.
Find the smallest possible value of |A_{1}| + |A_{... | {"inputs": ["4\n2\n2 4\n3\n1 1 1\n6\n-4 2 -4 2 -4 2\n1\n-100000000\n"], "outputs": ["0\n2\n15\n100000000\n"]} | 684 | 71 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the head of a linked list.
The nodes in the linked list are sequentially assigned to non-empty groups whose lengths form the sequence of the natural numbers (1, 2, 3, 4, ...). The length of a group is th... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([5,2,6,3,9,1,7,3,8,4])), list_node([5,6,2,3,9,1,4,8,3,7]))\n assert is_same_list(candidate(head = list_node([1,1,0,6])), list_node([1,0,1,6]))\n assert is_same_list(candidate(head = list_node([2,1])), list_node([2,1]))\n\n\n... | 259 | 133 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.
For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR... | {"functional": "def check(candidate):\n assert candidate(arr1 = [1,2,3], arr2 = [6,5]) == 0\n assert candidate(arr1 = [12], arr2 = [4]) == 4\n\n\ncheck(Solution().getXORSum)"} | 217 | 65 |
coding | Solve the programming task below in a Python markdown code block.
# Definition
A **number** is called **_Automorphic number_** if and only if *its square ends in the same digits as the number itself*.
___
# Task
**_Given_** a **number** *determine if it Automorphic or not* .
___
# Warm-up (Highly recommended)
# [P... | {"functional": "_inputs = [[1], [3], [6], [9], [25], [53], [76], [95], [625], [225]]\n_outputs = [['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!'], ['Automorphic'], ['Not!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst... | 675 | 227 |
coding | Solve the programming task below in a Python markdown code block.
The chef is having one array of natural numbers. Cheffina challenges chef that find the sum of weights all the natural numbers present in the array, but the main problem is that all numbers have not original weights. After every 6 natural numbers weight ... | {"inputs": ["1\n6\n6 7 9 11 4 16"], "outputs": ["23"]} | 302 | 29 |
coding | Solve the programming task below in a Python markdown code block.
`Description:`
Given an input array (`arr`) of positive integers, the objective is to return an output array where each index represents the amount of times an element appeared (frequency) in the input array.
More specifically, the element at each ind... | {"functional": "_inputs = [[2, 2, 4, 4, 6, 6, 9, 9, 9, 9], [3, 3, 3, 3, 2], [5, 5, 5, 5, 5], [77, 3, 40, 40, 40], [16, 7, 5, 3, 6, 23]]\n_outputs = [[[None, None, [2, 4, 6], None, [9], None, None, None, None, None, None]], [[None, [2], None, None, [3], None]], [[None, None, None, None, None, [5]]], [[None, [3, 77], Non... | 647 | 361 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.
Please complete the following python code precisely:
```python
cla... | {"functional": "def check(candidate):\n assert candidate([3, 2, 1]) == 1\n assert candidate([1, 2]) == 2\n assert candidate([2, 2, 3, 1]) == 1\n\n\ncheck(Solution().thirdMax)"} | 77 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers.
He has created a meth... | {"inputs": ["3\n3 3 1\n", "3\n3 4 1\n", "3\n6 4 1\n", "3\n6 6 1\n", "3\n2 4 1\n", "3\n4 3 2\n", "3\n2 6 1\n", "3\n6 9 1\n"], "outputs": ["12\n", "7\n", "14\n", "24\n", "10\n", "13\n", "12\n", "21\n"]} | 467 | 125 |
coding | Solve the programming task below in a Python markdown code block.
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super ... | {"inputs": ["8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\n", "8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_o... | 541 | 995 |
coding | Solve the programming task below in a Python markdown code block.
You are going to be given a string. Your job is to return that string in a certain order that I will explain below:
Let's say you start with this: `012345`
The first thing you do is reverse it:`543210`
Then you will take the string from the 1st posit... | {"functional": "_inputs = [['012'], ['012345'], ['0123456789'], ['Hello']]\n_outputs = [['201'], ['504132'], ['9081726354'], ['oHlel']]\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, (li... | 229 | 207 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has always dreamed of becoming an employee of the "Hack and Manipulate Group". Their work is simple ― attacking networks. They gave Chef the fol... | {"inputs": ["5\n5 5\n5 1\n5 2\n1 2\n2 3\n2 4\n5 6\n4 5\n4 1\n4 2\n4 3\n5 1\n5 2\n5 5\n3 4\n3 5\n3 1\n3 2\n4 2\n4 1\n3 4\n6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"], "outputs": ["1\n4\n2\n-1\n-1"]} | 653 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:
The cost of painting a digit (i + 1) is given by cost[i] (0-indexed).
The total cost used mus... | {"functional": "def check(candidate):\n assert candidate(cost = [4,3,2,5,6,7,2,5,5], target = 9) == \"7772\"\n assert candidate(cost = [7,6,5,5,5,6,8,7,8], target = 12) == \"85\"\n assert candidate(cost = [2,4,6,2,4,6,4,4,4], target = 5) == \"0\"\n assert candidate(cost = [6,10,15,40,40,40,40,40,40], target... | 148 | 174 |
coding | Solve the programming task below in a Python markdown code block.
Dr .: Peter, do you know "Yes, I have a number"?
Peter: I used to do it on TV the other day. You remember something by the number of characters in each word contained in a sentence. "Yes, I have a number", so it means "the number 3.14" and is a keyword ... | {"inputs": ["Yes I have a number\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT", "Yes I have a rebmun\nHow I wish I could calculate an unused bolor for space\nThank you\nEND OF INPUT", "Yes I have a rebmun\nHow J wish I could calculate an unused bolor for space\nThank you\nEND OF INPU... | 543 | 420 |
coding | Solve the programming task below in a Python markdown code block.
Remove the parentheses
=
In this kata you are given a string for example:
```python
"example(unwanted thing)example"
```
Your task is to remove everything inside the parentheses as well as the parentheses themselves.
The example above would return:
`... | {"functional": "_inputs = [['example(unwanted thing)example'], ['example (unwanted thing) example'], ['a (bc d)e'], ['a(b(c))'], ['hello example (words(more words) here) something'], ['(first group) (second group) (third group)']]\n_outputs = [['exampleexample'], ['example example'], ['a e'], ['a'], ['hello example s... | 132 | 233 |
coding | Solve the programming task below in a Python markdown code block.
Niwango-kun is an employee of Dwango Co., Ltd.
One day, he is asked to generate a thumbnail from a video a user submitted.
To generate a thumbnail, he needs to select a frame of the video according to the following procedure:
* Get an integer N and N in... | {"inputs": ["3\n0 2 3", "3\n0 0 3", "3\n0 0 1", "3\n1 1 3", "3\n1 0 3", "3\n0 0 2", "3\n0 1 3", "3\n0 2 5"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]} | 277 | 110 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Consider a string of lowercase Latin letters and space characters (" ").
First, rearrange the letters in each word `alphabetically`.
And then rearrange the words in ascending order of the sum of their characters' `ASCII` values.
If tw... | {"functional": "_inputs = [['batman is bruce wayne'], ['peter parker is spiderman'], ['codewars is great'], ['airplanes in the night sky']]\n_outputs = [['is bceru aenwy aabmnt'], ['is eeprt aekprr adeimnprs'], ['is aegrt acdeorsw'], ['in eht ksy ghint aaeilnprs']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if is... | 363 | 231 |
coding | Solve the programming task below in a Python markdown code block.
You need count how many valleys you will pass.
Start is always from zero level.
Every time you go down below 0 level counts as an entry of a valley, and as you go up to 0 level from valley counts as an exit of a valley.
One passed valley is equal one ... | {"functional": "_inputs = [['UFFFD'], ['DFFFD'], ['UFFFU'], ['DFFFU'], ['UFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDUFFDDUFFDDUDUDUDUDUDUUUUUUUUU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU']]\n_o... | 190 | 319 |
coding | Solve the programming task below in a Python markdown code block.
You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query:
- You are given a positive integer $X$.
- You should insert $X$ into $S$.
- For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ in... | {"inputs": ["1\n3\n4\n2\n7"], "outputs": ["0 1\n1 2\n3 4"]} | 552 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Hanuman has been a great admirer of Ram. However, there is one thing that Hanuman finds really difficult when talking to Ram. Hanuman can only understand sentences in reverse order but Ram,though an incarnation of God,is somehow unable to speak in revers... | {"inputs": ["9\nI have always been fond of you, Hanuman\nSpacelessSentence\nHello how are ou?\n.\na . gg\nt t his is a random sentence\nabcdef\nreverse me please\ntestcase 1"], "outputs": ["Hanuman you, of fond been always have I \nSpacelessSentence \nou? are how Hello \n. \ngg . a \nsentence random a is his t t \nabcd... | 216 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that takes 2 positive integers in form of a string as an input, and outputs the sum (also as a string):
If either input is an empty string, consider it as zero.
Also feel free to reuse/extend the following starter code:
```python
def s... | {"functional": "_inputs = [['4', '5'], ['34', '5'], ['9', ''], ['', '9']]\n_outputs = [['9'], ['39'], ['9'], ['9']]\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 ... | 77 | 183 |
coding | Solve the programming task below in a Python markdown code block.
Chef got his dream seat in F1 and secured a 3^{rd} place in his debut race. He now wants to know the time gap between him and the winner of the race.
You are his chief engineer and you only know the time gap between Chef and the runner up of the race, g... | {"inputs": ["4\n1 1\n2 5\n3 2\n5 6\n"], "outputs": ["2\n7\n5\n11\n"]} | 500 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Gorodetskiy is a university student. He is really good at math and really likes solving engaging math problems. In the last exam, his professor gave him really hard math problems to solve, but Gorodetskiy could not solve them and failed the exam, so the ... | {"inputs": ["2\n3\n6"], "outputs": ["2\n4\n6\n5\n7\n8\n9\n10\n12"]} | 513 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in... | {"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "2\n00\n", "2\n01\n", "2\n10\n", "2\n11\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]} | 374 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host s... | {"inputs": ["4 5 4\n4 4 5 1\n15\n9\n13\n6\n", "4 5 4\n4 4 5 1\n15\n9\n13\n6\n", "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n8\n", "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n", "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n", "1 100 20\n5\n2\n3\n4\n5\n100\n101\n102\n103\n200\n78\n... | 716 | 654 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n req... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n6 3\n9 3\n", "2\n6 3\n9 1\n", "2\n6 1\n9 1\n", "2\n6 1\n9 2\n", "2\n6 1\n5 2\n", "2\n6 1\n2 2\n"], "outputs": ["1 1\n", "1 1\n", "6 8\n9 11\n", "6 8\n9 9\n", "6 6\n9 9\n", "6 6\n9 10\n", "6 6\n1 2\n", "6 6\n2 3\n"]} | 749 | 168 |
coding | 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"]} | 359 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Alice and Bob are playing the game. Initially, there is a single rooted tree. Players take turns alternately, Alice starts.
In a single turn, Alice should choose any non-empty subset of... | {"inputs": ["3\n2\n1 2\n7\n1 3\n1 4\n4 2\n4 5\n4 6\n6 7\n1"], "outputs": ["2\n5\n1"]} | 407 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Chef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has $N$ integers with him. To stop Doof, Chef has to find an odd number which is an integer multiple of all... | {"inputs": ["2\n5\n1 2 5 4 3\n1\n7"], "outputs": ["NO\nYES"]} | 420 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = a^{p}.
-----Input-----
The first line contains the number of queries Q (1 ≤ Q ≤... | {"inputs": ["6\n1 4\n9 9\n5 7\n12 29\n83 591\n1 1000000\n", "6\n1 2\n9 9\n5 7\n12 29\n83 591\n1 1000000\n", "6\n2 2\n9 9\n5 7\n12 29\n83 591\n1 1000000\n", "6\n2 2\n9 9\n3 7\n12 29\n83 591\n1 1000000\n", "6\n2 2\n9 9\n1 7\n12 29\n83 591\n1 1000000\n", "6\n4 2\n9 9\n2 7\n12 29\n83 301\n1 1000000\n", "6\n1 4\n9 9\n5 7\n1... | 206 | 462 |
coding | Solve the programming task below in a Python markdown code block.
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Ali... | {"inputs": ["2\n1 2\n", "2\n6 2\n", "2\n4 6\n", "2\n2 6\n", "2\n8 2\n", "2\n3 6\n", "2\n7 3\n", "2\n2 1\n"], "outputs": ["Bob\n", "Alice\n", "Alice\n", "Alice\n", "Bob\n", "Bob\n", "Alice\n", "Bob\n"]} | 361 | 102 |
coding | Solve the programming task below in a Python markdown code block.
The name of our college is "Government College of Engineering and Textile Technology Berhampore". There is another college named "Government College of Engineering and Textile Technology Serampore". As the names are quite similar, those who are unaware o... | {"inputs": ["3\nGovernment clg Berhampore\nSeRaMporE textile college\nGirls college Kolkata"], "outputs": ["GCETTB\nGCETTS\nOthers"]} | 268 | 40 |
coding | Solve the programming task below in a Python markdown code block.
We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1).
Snuke will perform the following operation exactly M times:
* Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replac... | {"inputs": ["0 2", "5 7", "6 7", "3 7", "3 3", "3 6", "2 5", "5 6"], "outputs": ["0\n", "11600\n", "63008\n", "169\n", "37\n", "127\n", "6\n", "6685\n"]} | 309 | 94 |
coding | Solve the programming task below in a Python markdown code block.
problem
Given the squares of $ R * C $. Each square is either an empty square or a square with a hole. The given square meets the following conditions.
* The cells with holes are connected. (You can move a square with a hole in the cross direction to a... | {"inputs": ["3 5\n.....\n.#.#.\n.###.\n.#.#.\n.....", "3 1\n.....\n.#.#.\n.###.\n.#.#.\n.....", "2 5\n.....\n.#.#.\n.###.\n.#.#.\n.....", "4 2\n.....\n.#.#/\n.###.\n.#.#.\n.....", "0 1\n.....\n.#.#.\n.###.\n.#.#.\n.....", "4 1\n.....\n.#.#.\n.###.\n.#.#.\n.....", "0 1\n.....\n.#.#.\n.##\".\n.#.#.\n.....", "2 1\n.....\n... | 230 | 215 |
coding | Solve the programming task below in a Python markdown code block.
To participate in a prize draw each one gives his/her firstname.
Each letter of a firstname
has a value which is its rank in the English alphabet. `A` and `a` have rank `1`, `B` and `b` rank `2` and so on.
The *length* of the firstname is added to th... | {"functional": "_inputs = [['Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin', [4, 2, 1, 4, 3, 1, 2], 4], ['Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden', [1, 3, 5, 5, 3, 6], 2], ['Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth', [3, 1, 4, 4, 3, 2], 4], ['Lagon,Lily', [1, 5], 2], ['Elijah,Michael,Avery,Sophia,Samantha... | 497 | 734 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line.
You are given a 0-indexed integer array tickets of length n wh... | {"functional": "def check(candidate):\n assert candidate(tickets = [2,3,2], k = 2) == 6\n assert candidate(tickets = [5,1,1,1], k = 0) == 8\n\n\ncheck(Solution().timeRequiredToBuy)"} | 216 | 67 |
coding | Solve the programming task below in a Python markdown code block.
A and B are preparing themselves for programming contests.
The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n - 1 corridors so that you can get from any room to any other one b... | {"inputs": ["4\n1 2\n1 3\n2 4\n1\n2 3\n", "5\n1 2\n1 3\n2 5\n2 4\n1\n5 4\n", "4\n1 2\n2 3\n2 4\n2\n1 2\n1 2\n", "4\n1 3\n2 3\n2 4\n2\n1 2\n1 2\n", "4\n1 3\n2 3\n2 4\n2\n1 1\n1 2\n", "4\n1 4\n2 3\n2 4\n2\n1 1\n1 3\n", "5\n1 2\n1 3\n2 5\n2 4\n1\n5 3\n", "4\n1 4\n4 3\n2 4\n2\n1 1\n1 3\n"], "outputs": ["1\n", "3\n", "0\n0\... | 482 | 252 |
coding | Solve the programming task below in a Python markdown code block.
There are N+1 towns. The i-th town is being attacked by A_i monsters.
We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.
What is the maximum total number of monsters the heroes ca... | {"inputs": ["1\n1 1\n1\n", "2\n3 5 2\n7 5", "2\n3 5 1\n7 5", "2\n3 5 1\n0 5", "2\n2 5 1\n0 5", "2\n2 9 1\n0 5", "2\n2 9 1\n0 2", "2\n2 1 1\n0 2"], "outputs": ["1\n", "10\n", "9\n", "5\n", "5\n", "5\n", "2\n", "2\n"]} | 282 | 140 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`.
He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is ... | {"inputs": ["baa", "bba", "bab", "bbb", "abb", "abc", "cba", "bca"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | 183 | 65 |
coding | Solve the programming task below in a Python markdown code block.
Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest.
There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows about Snack... | {"inputs": ["2\n7\n2 1 1 5 5 5 5\n5\n5 1 3 2 1"], "outputs": ["2\n1"]} | 572 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Rupsa recently started to intern under Chef. He gave her N type of ingredients of varying quantity A_{1}, A_{2}, ..., A_{N} respectively to store it. But as she is lazy to arrange them she put... | {"inputs": ["2\n2\n2 2\n1\n6", "2\n2\n2 1\n1\n6", "2\n2\n2 2\n1\n8", "2\n2\n4 2\n1\n6", "2\n1\n2 1\n1\n1", "2\n3\n3 2\n1\n8", "2\n3\n4 2\n0\n1", "2\n3\n4 7\n0\n6"], "outputs": ["4\n2", "-1\n2\n", "4\n2\n", "6\n2\n", "-1\n-1\n", "5\n2\n", "6\n-1\n", "9\n2\n"]} | 469 | 159 |
coding | Solve the programming task below in a Python markdown code block.
In this kata, your task is to create a function that takes a single list as an argument and returns a flattened list. The input list will have a maximum of one level of nesting (list(s) inside of a list).
```python
# no nesting
[1, 2, 3]
# one level of... | {"functional": "_inputs = [[[1, [2, 3], 4]], [[['a', 'b'], 'c', ['d']]], [['!', '?']]]\n_outputs = [[[1, 2, 3, 4]], [['a', 'b', 'c', 'd']], [['!', '?']]]\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... | 228 | 209 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows.
1. $ X_0 = 0 $
2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $ Either.
... | {"inputs": ["4\n0 1\n4 2\n2 4\n3 4", "4\n0 1\n4 2\n2 1\n3 4", "4\n1 2\n4 2\n2 4\n3 4", "4\n1 2\n4 2\n2 4\n3 7", "4\n0 1\n4 3\n2 1\n2 4", "4\n2 2\n4 2\n2 4\n3 7", "4\n2 2\n4 2\n2 7\n3 7", "4\n2 0\n4 2\n2 7\n3 7"], "outputs": ["-16\n", "-4\n", "-12\n", "-21\n", "-5\n", "-35\n", "-56\n", "-49\n"]} | 390 | 197 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of ze... | {"inputs": ["0\n", "1\n", "1\n", "0\n", "110\n", "010\n", "100\n", "000\n"], "outputs": ["0\n", "0\n", "0", "0", "010\n", "010\n", "100\n", "000\n"]} | 690 | 84 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.
You have the following three operations permitted on a word:
Insert a character
Delete a character
Replac... | {"functional": "def check(candidate):\n assert candidate(word1 = \"horse\", word2 = \"ros\") == 3\n assert candidate(word1 = \"intention\", word2 = \"execution\") == 5\n\n\ncheck(Solution().minDistance)"} | 100 | 58 |
coding | Solve the programming task below in a Python markdown code block.
You are given a set of all integers from $l$ to $r$ inclusive, $l < r$, $(r - l + 1) \le 3 \cdot 10^5$ and $(r - l)$ is always odd.
You want to split these numbers into exactly $\frac{r - l + 1}{2}$ pairs in such a way that for each pair $(i, j)$ the gr... | {"inputs": ["1 8\n", "1 2\n", "2 3\n", "4 9\n", "3 6\n", "2 7\n", "2 7\n", "1 2\n"], "outputs": ["YES\n1 2\n3 4\n5 6\n7 8\n", "YES\n1 2\n", "YES\n2 3\n", "YES\n4 5\n6 7\n8 9\n", "YES\n3 4\n5 6\n", "YES\n2 3\n4 5\n6 7\n", "YES\n2 3\n4 5\n6 7\n", "YES\n1 2\n"]} | 344 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Given a positive integer $k$, two arrays are called $k$-similar if:
they are strictly increasing;
they have the same length;
all their elements are positive integers between $1$ and $k$ (inclusive);
they differ in exactly one position.
You are given... | {"inputs": ["1 1 4\n3\n1 1\n", "1 1 20\n3\n1 1\n", "1 1 20\n3\n1 1\n", "1 1 20\n5\n1 1\n", "1 1 39\n3\n1 1\n", "1 1 31\n2\n1 1\n", "1 1 26\n3\n1 1\n", "1 1 23\n2\n1 1\n"], "outputs": ["3\n", "19\n", "19\n", "19\n", "38\n", "30\n", "25\n", "22\n"]} | 529 | 164 |
coding | Solve the programming task below in a Python markdown code block.
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:
* the Euclidean distance between A and B is o... | {"inputs": ["0\n", "9\n", "8\n", "4\n", "7\n", "6\n", "5\n", "2\n"], "outputs": ["1\n", "48\n", "44\n", "20\n", "36\n", "32\n", "28\n", "8\n"]} | 267 | 76 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N. Let A be an N \times N grid such that A_{i, j} = i + N\cdot(j-1) for 1 ≤ i, j ≤ N. For example, if N = 4 the grid looks like:
You start at the top left corner of the grid, i.e, cell (1, 1). You would like to reach the bottom-... | {"inputs": ["4\n1 0\n2 0\n2 1\n3 1\n"], "outputs": ["No\nYes\nYes\nYes\n"]} | 592 | 36 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case.
# Input/Output
`[input]` string `s`
String of odd length consisting of English letters.... | {"functional": "_inputs = [['asdERvT'], ['oyTYbWQ'], ['bbiIRvbcW'], ['rWTmvcoRWEWQQWR']]\n_outputs = [['asdervt'], ['OYTYBWQ'], ['bbiirvbcw'], ['RWTMVCORWEWQQWR']]\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=to... | 150 | 212 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a full binary tree with the following properties:
Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.
Non-leaf nodes have either the value 2 or 3, where ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([2,1,3,None,None,0,1])) == True\n assert candidate(root = tree_node([0])) == False\n\n\ncheck(Solution().evaluateTree)"} | 263 | 55 |
coding | Solve the programming task below in a Python markdown code block.
Given the time in numerals we may convert it into words, as shown below:
$\begin{array}{l}5.00\rightarrow\:five \quad o'clock\\
5.01\rightarrow\:one\quad minute \quad past\quad five\\
5.10\rightarrow\:ten\quad minutes\quad past\quad five\\
5.15\righ... | {"inputs": ["5\n47\n", "3\n00\n", "7\n15\n"], "outputs": ["thirteen minutes to six\n", "three o' clock\n", "quarter past seven\n"]} | 445 | 48 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer n, you can apply one of the following operations:
If n is even, replace n with n / 2.
If n is odd, replace n with either n + 1 or n - 1.
Return the minimum number of operations needed for n ... | {"functional": "def check(candidate):\n assert candidate(n = 8) == 3\n assert candidate(n = 7) == 4\n assert candidate(n = 4) == 2\n\n\ncheck(Solution().integerReplacement)"} | 110 | 55 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle... | {"functional": "def check(candidate):\n assert candidate(s = \"**|**|***|\", queries = [[2,5],[5,9]]) == [2,3]\n assert candidate(s = \"***|**|*****|**||**|*\", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]) == [9,0,0,0,0]\n\n\ncheck(Solution().platesBetweenCandles)"} | 272 | 112 |
coding | Solve the programming task below in a Python markdown code block.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved pro... | {"inputs": ["3\n3 5 4\n", "3\n6 5 4\n", "3\n6 5 8\n", "3\n6 5 6\n", "3\n4 5 6\n", "3\n4 0 6\n", "3\n4 0 7\n", "3\n7 0 7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 561 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today.
Your function should return `True` or `False` based on the following criteria.
* You should take a... | {"functional": "_inputs = [['sunny', 0.4], ['rainy', 0.0], ['cloudy', 0.2]]\n_outputs = [[False], [True], [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, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ... | 202 | 187 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.