task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Mohit(Ex GenSec ) is the most active member of the roasting club who loves giving tasks to other members. One day he observed that none of the members were paying attention to the online classes, so he decided to have some fun and overcome the boring lec... | {"inputs": ["5 4\n7\n12\n10\n1"], "outputs": ["17\n22\n20\n20"]} | 346 | 34 |
coding | Solve the programming task below in a Python markdown code block.
A number `n` is called `prime happy` if there is at least one prime less than `n` and the `sum of all primes less than n` is evenly divisible by `n`. Write `isPrimeHappy(n)` which returns `true` if `n` is `prime happy` else `false`.
Also feel free to reu... | {"functional": "_inputs = [[5], [8], [25], [32], [2], [0]]\n_outputs = [[True], [False], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\... | 102 | 188 |
coding | Solve the programming task below in a Python markdown code block.
You are given $4n$ sticks, the length of the $i$-th stick is $a_i$.
You have to create $n$ rectangles, each rectangle will consist of exactly $4$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length an... | {"inputs": ["1\n2\n3 3 4 4 4 4 6 6\n", "1\n2\n3 3 4 4 4 4 6 6\n", "1\n2\n3 3 4 4 4 4 6 4\n", "1\n2\n3 3 4 4 8 4 6 6\n", "1\n2\n3 3 6 4 4 4 6 4\n", "1\n2\n3 3 6 4 4 7 6 4\n", "1\n2\n6 3 6 4 4 7 6 4\n", "1\n2\n3 3 4 4 4 4 1 6\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 470 | 214 |
coding | Solve the programming task below in a Python markdown code block.
Given is a rooted tree with N vertices numbered 1 to N.
The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.
Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.... | {"inputs": ["4 3\n1 2\n4 3\n1 4\n2 7\n1 000\n3 1", "4 3\n1 2\n2 3\n2 4\n2 4\n2 100\n3 1", "2 3\n1 2\n2 4\n1 4\n1 6\n2 100\n1 1", "4 3\n1 2\n2 3\n2 4\n2 4\n2 100\n3 0", "4 3\n1 2\n2 3\n2 4\n2 4\n2 110\n3 0", "2 3\n1 2\n2 4\n1 4\n1 3\n2 100\n1 1", "4 3\n1 2\n2 3\n2 4\n2 4\n2 101\n3 1", "4 3\n1 2\n4 3\n1 4\n2 2\n2 000\n3 ... | 640 | 353 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.
The bowling game consists of n turns, and the number of p... | {"functional": "def check(candidate):\n assert candidate(player1 = [4,10,7,9], player2 = [6,5,2,3]) == 1\n assert candidate(player1 = [3,5,7,6], player2 = [8,10,10,2]) == 2\n assert candidate(player1 = [2,3], player2 = [4,1]) == 0\n\n\ncheck(Solution().isWinner)"} | 235 | 107 |
coding | Solve the programming task below in a Python markdown code block.
The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that ther... | {"inputs": ["3 3 5\n", "2 4 4\n", "1 1 1\n", "8 7 5\n", "8 7 5\n", "1 1 1\n", "3 4 5\n", "3 4 3\n"], "outputs": ["18\n3 6\n", "16\n4 4\n", "6\n1 6\n", "48\n8 6\n", "48\n8 6\n", "6\n1 6\n", "20\n4 5\n", "18\n6 3\n"]} | 278 | 140 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.
The algorithm for myAtoi(string s) is as follows:
Whitespace: Ignore any leading whitespace (" ").
Signedness: Determine th... | {"functional": "def check(candidate):\n assert candidate(s = \"42\") == 42\n assert candidate(s = \" -042\") == -42\n assert candidate(s = \"1337c0d3\") == 1337\n assert candidate(s = \"0-1\") == 0\n assert candidate(s = \"words and 987\") == 0\n\n\ncheck(Solution().myAtoi)"} | 244 | 103 |
coding | 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... | 142 | 307 |
coding | Solve the programming task below in a Python markdown code block.
Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)
Here, the price before tax must be a... | {"inputs": ["1 2", "1 1", "0 1", "2 3", "3 4", "7 8", "3 3", "5 6"], "outputs": ["20\n", "13\n", "10\n", "30\n", "40\n", "88\n", "38\n", "63\n"]} | 351 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a_{1}, a_{2}, \ldots, a_{n}$. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct.
In other words, at most one time you can choose two integers $l$ and $r$ ($1 \leq l \leq r \leq n$) ... | {"inputs": ["2\n2 1\n", "2\n2 1\n", "2\n3 1\n", "2\n6 1\n", "3\n1 2 3\n", "3\n1 2 1\n", "3\n1 2 0\n", "3\n1 2 3\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "1\n", "0\n", "0"]} | 412 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering.
Write a function which takes a list of strings and returns each line prepended by the correct number.
The numbering starts at 1. The format is `n:... | {"functional": "_inputs = [[[]], [['a', 'b', 'c']], [['', '', '', '', '']], [['', 'b', '', '', '']]]\n_outputs = [[[]], [['1: a', '2: b', '3: c']], [['1: ', '2: ', '3: ', '4: ', '5: ']], [['1: ', '2: b', '3: ', '4: ', '5: ']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, flo... | 138 | 237 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a garden of n flowers, and each flower has an integer beauty value. The flowers are arranged in a line. You are given an integer array flowers of size n and each flowers[i] represents the beauty of the ith fl... | {"functional": "def check(candidate):\n assert candidate(flowers = [1,2,3,1,2]) == 8\n assert candidate(flowers = [100,1,1,-3,1]) == 3\n assert candidate(flowers = [-1,-2,0,-1]) == -2\n\n\ncheck(Solution().maximumBeauty)"} | 203 | 82 |
coding | Solve the programming task below in a Python markdown code block.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the... | {"inputs": ["2\n2 1", "2\n2 0", "2\n4 0", "2\n3 1", "2\n3 1\n", "2\n2 -1", "2\n4 -1", "2\n5 -2"], "outputs": ["1\n", "2\n", "4\n", "2", "2\n", "3\n", "5\n", "7\n"]} | 269 | 94 |
coding | Solve the programming task below in a Python markdown code block.
There were initially X million people in a town, out of which Y million people left the town and Z million people immigrated to this town.
Determine the final population of town in millions.
------ Input Format ------
- The first line of input will ... | {"inputs": ["4\n3 1 2\n2 2 2\n4 1 8\n10 1 10\n"], "outputs": ["4\n2\n11\n19\n"]} | 315 | 48 |
coding | Solve the programming task below in a Python markdown code block.
D: The Diversity of Prime Factorization
Problem
Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in O ($ \ log $ M) time! But unfortunately, the machine could display only digits and white spaces.
In gener... | {"inputs": ["3\n2 3 6", "3\n3 2 3", "3\n2 5 3", "3\n2 2 3", "3\n3 2 6", "3\n4 2 6", "3\n2 2 0", "3\n4 2 2"], "outputs": ["1\n", "0\n", "2\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 628 | 110 |
coding | Solve the programming task below in a Python markdown code block.
After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simp... | {"inputs": ["4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\n2 2 2 2\n1 1 1 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\... | 654 | 699 |
coding | Solve the programming task below in a Python markdown code block.
"I don't have any fancy quotes." - vijju123
Chef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word "not" are Real Fancy; quotes that do not ... | {"inputs": ["2\ni do not have any fancy quotes\nwhen nothing goes right go left"], "outputs": ["Real Fancy\nregularly fancy"]} | 322 | 32 |
coding | Solve the programming task below in a Python markdown code block.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and... | {"inputs": ["3\n3 1 1\n", "3\n3 0 1\n", "3\n0 2 3\n", "3\n1 0 3\n", "3\n3 0 2\n", "3\n0 0 3\n", "3\n1 0 2\n", "3\n3 2 1\n"], "outputs": ["2\n", "3\n", "0\n", "1\n", "3\n", "0\n", "1\n", "2\n"]} | 491 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Given an array $A$ of length $N$.
We have to find the $maximum$ sum of elements of the subarray between $two$ nearest occurrences of $same$ elements (excluding both).
If both the elements are $even$ then the total number of $even$ elements in that subarr... | {"inputs": ["1\n10\n1 2 3 2 1 5 1 2 8 2"], "outputs": ["7"]} | 360 | 35 |
coding | Solve the programming task below in a Python markdown code block.
There are a number of plants in a garden. Each of the plants has been treated with some amount of pesticide. After each day, if any plant has more pesticide than the plant on its left, being weaker than the left one, it dies.
You are given the initial... | {"inputs": ["7\n6 5 8 4 7 10 9\n"], "outputs": ["2\n"]} | 560 | 29 |
coding | 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 the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of t... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,0,2]), low = 1, high = 2), tree_node([1,None,2]))\n assert is_same_tree(candidate(root = tree_node([3,0,4,None,2,None,None,1]), low = 1, high = 3), tree_node([3,2,None,1]))\n\n\ncheck(Solution().trimBST)"} | 209 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.
You must implement a solution with a linear runtime complexity and... | {"functional": "def check(candidate):\n assert candidate(nums = [2,2,3,2]) == 3\n assert candidate(nums = [0,1,0,1,0,1,99]) == 99\n\n\ncheck(Solution().singleNumber)"} | 97 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Grapes of Coderpur are very famous. Devu went to the market and saw that there were N people selling grapes. He didn’t like it because things were not very structured. So, he gave a task to Dhi... | {"inputs": ["2\n2 1\n8 1\n3 7\n2 4 7", "2\n2 2\n3 8\n3 7\n8 16 7", "2\n2 1\n5 8\n3 7\n8 16 7", "2\n2 2\n5 8\n2 7\n7 16 7", "2\n2 2\n5 8\n3 7\n8 11 7", "2\n2 2\n5 1\n2 7\n8 16 7", "2\n2 2\n5 8\n2 7\n8 21 7", "2\n2 3\n5 8\n3 7\n8 11 7"], "outputs": ["0\n8\n", "1\n3\n", "0\n3\n", "1\n2\n", "1\n4\n", "2\n3\n", "1\n1\n", "2... | 537 | 229 |
coding | Solve the programming task below in a Python markdown code block.
I’m planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming.
I wish to enj... | {"inputs": ["5 2\n5 5 6 5", "100 3\n1 3 3", "5 2\n3 5 6 5", "000 3\n1 3 3", "5 2\n3 7 6 5", "010 3\n1 3 3", "010 3\n1 3 5", "5 4\n5 5 6 5"], "outputs": ["2\n", "1\n", "2\n", "7\n", "2\n", "1\n", "1\n", "4"]} | 390 | 141 |
coding | Solve the programming task below in a Python markdown code block.
any()
This expression returns True if any element of the iterable is true.
If the iterable is empty, it will return False.
Code
>>> any([1>0,1==0,1<0])
True
>>> any([1<0,2<1,3<2])
False
all()
This expression returns True if all of the elements of... | {"inputs": ["5\n12 9 61 5 14\n"], "outputs": ["True\n"]} | 337 | 27 |
coding | Solve the programming task below in a Python markdown code block.
You recently received a bag of chocolate sticks for Halloween. To prevent you from compulsively eating all the chocolate sticks in one go, your dietician devises the following fun game.
In each move, you choose one of the sticks from your bag. Then, you... | {"inputs": ["1\n6\n", "3\n1 7 24\n"], "outputs": ["10\n", "55\n"]} | 507 | 33 |
coding | Solve the programming task below in a Python markdown code block.
I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. I'll appreciate for your help.
P.S. Each array includes only integer numbers. Output is a number too.
Also feel free to reuse/extend the following st... | {"functional": "_inputs = [[[1, 2, 3], [4, 5, 6]], [[-1, -2, -3], [-4, -5, -6]], [[0, 0, 0], [4, 5, 6]], [[100, 200, 300], [400, 500, 600]]]\n_outputs = [[21], [-21], [15], [2100]]\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_to... | 86 | 252 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a positive integer $n$ ordinary if in the decimal notation all its digits are the same. For example, $1$, $2$ and $99$ are ordinary numbers, but $719$ and $2021$ are not ordinary numbers.
For a given number $n$, find the number of ordinary nu... | {"inputs": ["1\n2\n", "1\n5\n", "1\n6\n", "1\n3\n", "1\n4\n", "1\n1\n", "1\n8\n", "1\n28\n"], "outputs": ["2\n", "5\n", "6\n", "3\n", "4\n", "1\n", "8\n", "11\n"]} | 219 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a_1, a_2, ..., a_{k}. We say that this sequence occ... | {"inputs": ["11 4 1\n11\n", "11 10 1\n11\n", "11 10 1\n11\n", "5 5 5\n1 1 1 1 1\n", "5 5 5\n1 1 1 1 1\n", "5 5 5\n1 1 2 1 1\n", "5 2 5\n1 1 2 1 1\n", "5 2 5\n2 1 2 1 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | 446 | 166 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,
If isLefti == 1, then ch... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]), tree_node([50,20,80,15,17,19]))\n assert is_same_tree(candidate(descriptions = [[1,2,1],[2,3,0],[3,4,1]]), tree_node([1,2,None,None,3,4]))\n\n\ncheck(Solution().createBinaryTr... | 213 | 138 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting of lowercase Latin letters. Every letter appears in it no more than twice.
Your task is to rearrange the letters in the string in such a way that for each pair of letters that appear exactly twice, the distance bet... | {"inputs": ["1\nf\n", "1\nabdogaber\n", "3\noelhl\nabcdcba\nac\n"], "outputs": ["f\n", "aabbdegor\n", "ehllo\naabbccd\nac\n"]} | 468 | 56 |
coding | Solve the programming task below in a Python markdown code block.
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the... | {"inputs": ["C>A\nC<B\nB>A\n", "C<B\nB<A\nC>A\n", "C<B\nB>A\nA<C\n", "A>C\nC>B\nB<A\n", "C<B\nC<A\nB<A\n", "A>B\nC>B\nA<C\n", "A>C\nC<B\nB>A\n", "B>A\nC<A\nC>B\n"], "outputs": ["ACB\n", "Impossible\n", "ACB\n", "BCA\n", "CBA\n", "BAC\n", "CAB\n", "Impossible\n"]} | 294 | 132 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).
For example, "Hello ... | {"functional": "def check(candidate):\n assert candidate(s = \"Hello how are you Contestant\", k = 4) == \"Hello how are you\"\n assert candidate(s = \"What is the solution to this problem\", k = 4) == \"What is the solution\"\n assert candidate(s = \"chopper is not a tanuki\", k = 5) == \"chopper is not a tan... | 158 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Recently, Chef's College Examination has concluded. He was enrolled in $3$ courses and he scored $A, B, C$ in them, respectively. To pass the semester, he must score at le... | {"inputs": ["5\n1 1 1 300 2 2 2\n3 2 2 6 2 2 2\n2 3 2 6 2 2 2\n2 2 3 6 2 2 2\n100 100 100 300 100 100 100"], "outputs": ["NO\nNO\nNO\nNO\nYES"]} | 644 | 106 |
coding | Solve the programming task below in a Python markdown code block.
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letter... | {"inputs": ["1\nu\n", "1\nu\n", "1\nt\n", "1\ns\n", "7\na a b a a a b\n", "2\nxnnlpp jpymdh\n", "7\na a b a a a b\n", "2\nxnnlpp jpymdh\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "9\n", "13\n", "9\n", "13\n"]} | 666 | 112 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,2,5,3,None,9])) == [1,3,9]\n assert candidate(root = tree_node([1,2,3])) == [1,3]\n\n\ncheck(Solution().largestValues)"} | 127 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Consider a regular polygon with N vertices labelled 1..N. In how many ways can you draw K diagonals such that no two diagonals intersect at a point strictly inside the polygon? A diagonal is a line segment joining two non adjacent vertices of the polygon... | {"inputs": ["3\n4 1\n5 2\n5 3\n"], "outputs": ["2\n5\n0\n"]} | 268 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are ... | {"inputs": ["5\n0\n0\n0", "5\n0\n1\n0", "5\n1\n1\n0", "5\n2\n1\n0", "5\n0\n0\n1", "5\n0\n0\n2", "5\n0\n1\n2", "5\n1\n1\n2"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 290 | 110 |
coding | Solve the programming task below in a Python markdown code block.
A left rotation operation on an array of size $n$ shifts each of the array's elements $1$ unit to the left. Given an integer, $\boldsymbol{d}$, rotate the array that many steps left and return the result.
Example
$\boldsymbol{d}=2$
$arr=[1,2,3,4,5... | {"inputs": ["5 4\n1 2 3 4 5\n"], "outputs": ["5 1 2 3 4\n"]} | 379 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. A... | {"inputs": ["4\na\n", "4\nb\n", "4\nb\n", "4\na\n", "4\nc\n", "4\n`\n", "4\nd\n", "4\n_\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 642 | 86 |
coding | Solve the programming task below in a Python markdown code block.
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:
- Consider writing a number on each vertex in the tree in the following manner:
- First, write 1 on V... | {"inputs": ["2\n2 1", "2\n1 2", "2\n1 2\n", "3\n2 3\n1 3", "3\n1 2\n2 3", "3\n1 2\n1 3", "3\n1 2\n1 3\n", "5\n1 2\n1 3\n3 4\n3 5"], "outputs": ["1\n1\n", "1\n1", "1\n1\n", "1\n1\n2\n", "1\n2\n1\n", "2\n1\n1", "2\n1\n1\n", "8\n2\n12\n3\n3\n"]} | 387 | 153 |
coding | Solve the programming task below in a Python markdown code block.
You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$.
The following actions are allowed: Token movement. To move the token from vertex $u$ to vertex $v$ if there is an edge... | {"inputs": ["2 1\n2 1\n", "2 1\n2 1\n", "4 3\n2 1\n2 3\n4 3\n", "4 3\n2 1\n2 3\n4 3\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "4 4\n1 2\n2 1\n3 4\n4 1\n", "4 4\n2 2\n2 1\n3 4\n3 1\n", "4 3\n1 2\n3 2\n3 4\n4 2\n"], "outputs": ["2\n", "2\n", "10\n", "10\n", "2\n", "2\n", "5\n", "6\n"]} | 512 | 184 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
A new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :)
However, due... | {"inputs": ["2\n1\n2", "2\n1\n4", "2\n1\n8", "2\n1\n0", "2\n0\n0", "2\n1\n6", "2\n1\n1", "2\n2\n0"], "outputs": ["1\n3", "1\n15\n", "1\n255\n", "1\n0\n", "0\n0\n", "1\n63\n", "1\n1\n", "3\n0\n"]} | 533 | 113 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and... | {"inputs": ["1\n1\nk\n", "1\n1\nk\n", "1\n1\nj\n", "1\n1\ni\n", "1\n1\nh\n", "1\n3\nraq\n", "1\n3\nraq\n", "1\n3\nbab\n"], "outputs": ["k\n1\n", "k\n1\n", "j\n1\n", "i\n1\n", "h\n1\n", "aqr\n2\n", "aqr\n2\n", "abb\n2\n"]} | 748 | 120 |
coding | Solve the programming task below in a Python markdown code block.
A Narcissistic Number is a number of length n in which the sum of its digits to the power of n is equal to the original number. If this seems confusing, refer to the example below.
Ex: 153, where n = 3 (number of digits in 153)
1^(3) + 5^(3) + 3^(3) = 1... | {"functional": "_inputs = [[153], [370], [371], [407], [1634], [8208], [9474], [54748], [92727], [93084], [548834], [1741725], [4210818], [9800817], [9926315], [24678050], [88593477], [146511208], [472335975], [534494836], [912985153], [4679307774], [115132219018763992565095597973971522401]]\n_outputs = [[True], [True]... | 159 | 440 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a string and your task will be to return the length of the longest prefix that is also a suffix. A prefix is the start of a string while the suffix is the end of a string. For instance, the prefixes of the string `"abcd"`... | {"functional": "_inputs = [['abcd'], ['abcda'], ['abcdabc'], ['abcabc'], ['abcabca'], ['abcdabcc'], ['aaaaa'], ['aaaa'], ['aaa'], ['aa'], ['a'], ['acbacc']]\n_outputs = [[0], [1], [3], [3], [1], [0], [2], [2], [1], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ... | 278 | 229 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a strange printer with the following two special properties:
The printer can only print a sequence of the same character each time.
At each turn, the printer can print new characters starting from and ending... | {"functional": "def check(candidate):\n assert candidate(s = \"aaabbb\") == 2\n assert candidate(s = \"aba\") == 2\n\n\ncheck(Solution().strangePrinter)"} | 116 | 46 |
coding | Solve the programming task below in a Python markdown code block.
A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A chair number will be drawn from a... | {"inputs": ["2\n5 2 1\n5 2 2\n", "2\n7 19 2\n3 7 3\n"], "outputs": ["2\n3\n", "6\n3\n"]} | 722 | 51 |
coding | Solve the programming task below in a Python markdown code block.
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, ev... | {"inputs": ["1 0\n2\n3\n", "1 0\n2\n0\n", "1 0\n0\n0\n", "1 0\n2\n3\n", "2 0\n2 3\n3 3\n", "2 0\n2 3\n3 3\n", "2 0\n1 3\n3 3\n", "2 0\n1 3\n0 3\n"], "outputs": ["3 ", "0\n", "0\n", "3\n", "3 3 ", "3 3\n", "3 3\n", "0 3\n"]} | 588 | 140 |
coding | Solve the programming task below in a Python markdown code block.
Given are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.
- There exists a non-ne... | {"inputs": ["aba\naaaab", "aba\naa`ab", "`ba\naa`ab", "`ab\naa`ab", "ab`\naa`ab", "ab`\naa`ac", "ac`\naa`ac", "`ca\naa`ac"], "outputs": ["0", "0", "0", "0", "0", "0", "0", "0"]} | 468 | 88 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.
The company requires each employee to work for at least target hours.
You are given a 0-index... | {"functional": "def check(candidate):\n assert candidate(hours = [0,1,2,3,4], target = 2) == 3\n assert candidate(hours = [5,1,4,2,2], target = 6) == 0\n\n\ncheck(Solution().numberOfEmployeesWhoMetTarget)"} | 140 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Morning desert sun horizon
Rise above the sands of time...
Fates Warning, "Exodus"
After crossing the Windswept Wastes, Ori has finally reached the Windtorn Ruins to find the Heart of the Forest! However, the ancient repository containing this pricele... | {"inputs": ["1\n10\ngepardotop\n", "1\n10\ngepardotpp\n", "1\n10\npptodrapeg\n", "1\n10\npotodrapeg\n", "1\n10\negpardotpp\n", "1\n10\nppotdsaoeg\n", "1\n10\ngtpardoeop\n", "1\n10\nptpodrapeg\n"], "outputs": ["27\n", "27\n", "26\n", "18\n", "36\n", "17\n", "24\n", "19\n"]} | 697 | 144 |
coding | Solve the programming task below in a Python markdown code block.
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertic... | {"inputs": ["1\n0 1", "1\n1 1", "2\n0 3 2", "2\n0 1 1", "2\n0 2 2", "2\n0 3 1", "2\n-1 3 2", "2\n-2 3 2"], "outputs": ["2\n", "-1", "-1\n", "4\n", "-1\n", "-1", "7\n", "8\n"]} | 306 | 106 |
coding | Solve the programming task below in a Python markdown code block.
Mehta is a very lazy boy. He always sleeps in Maths class. One day his teacher catches him sleeping and tells him that she would mark him absent for the whole semester. While she pretends to be strict, she is actually very kind-hearted. So she wants to g... | {"inputs": ["4\n2\n8\n36\n900\n"], "outputs": ["0\n1/3\n1/8\n3/26\n"]} | 535 | 38 |
coding | Solve the programming task below in a Python markdown code block.
.task {
background: #fff;
color: #333;
padding: 25px;
box-sizing: border-box;
font-family: Comfortaa, sans-serif !important;
position: relative;
}
.task code, .task_code {
display: inline-block;
padding: 0;
border-radius: 2px;
margin:... | {"functional": "_inputs = [[10]]\n_outputs = [[3]]\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_eq(... | 606 | 157 |
coding | Solve the programming task below in a Python markdown code block.
B: Twins
One twin was angry that it was not well known which of them was the older brother and which was the younger brother.
Create a program that outputs "square1001" when "ani" is entered and "e869120" when "otouto" is entered.
input
You will be g... | {"inputs": ["ani"], "outputs": ["square1001"]} | 187 | 16 |
coding | Solve the programming task below in a Python markdown code block.
You're given a string $\mbox{S}$ of $N$ characters. It's known that the string consists of lowercase Latin letters. The string is generated randomly. That means that every symbol is chosen randomly and independently from others from the set {'a', 'b', ..... | {"inputs": ["4 4 \naaab\n1 a\n2 b\n3 c\n4 d\n"], "outputs": ["7\n7\n9\n10\n"]} | 712 | 38 |
coding | Solve the programming task below in a Python markdown code block.
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many sup... | {"inputs": ["1 1\n0\n", "1 1\n0\n", "2 1\n0 0\n", "2 1\n0 1\n", "2 1\n1 0\n", "2 1\n1 1\n", "2 2\n0 0\n", "2 2\n0 1\n"], "outputs": ["0\n", "0", "1\n", "0\n", "2\n", "1\n", "1\n", "2\n"]} | 413 | 113 |
coding | Solve the programming task below in a Python markdown code block.
Here you will create the classic [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal%27s_triangle).
Your function will be passed the depth of the triangle and you code has to return the corresponding pascal triangle up to that depth.
The triangle s... | {"functional": "_inputs = [[1], [5], [10]]\n_outputs = [[[[1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84... | 236 | 397 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums consisting of n positive integers.
The array nums is called alternating if:
nums[i - 2] == nums[i], where 2 <= i <= n - 1.
nums[i - 1] != nums[i], where 1 <= i <= n - 1.
In one o... | {"functional": "def check(candidate):\n assert candidate(nums = [3,1,3,2,4,3]) == 3\n assert candidate(nums = [1,2,2,2,2]) == 2\n\n\ncheck(Solution().minimumOperations)"} | 147 | 61 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that :
p[0] = start
p[i] and p[i+1] differ by only one bit in their binary representation.
p[0] and p[2^n -1] must also ... | {"functional": "def check(candidate):\n assert candidate(n = 2, start = 3) == [3,2,0,1]\n assert candidate(n = 3, start = 2) == [2,6,7,5,4,0,1,3]\n\n\ncheck(Solution().circularPermutation)"} | 139 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Chandrima likes the XOR operation very much and keeps finding and solving related problems. One day she comes across a problem and gets stuck on it, which makes her sad. You being her friend decide to help her out by writing a code for the same.
Consid... | {"inputs": ["3\n1 2 3\n", "3\n1 3 4\n"], "outputs": ["7\n", "0\n"]} | 388 | 34 |
coding | Solve the programming task below in a Python markdown code block.
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.
The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.
An edge whose removal disconnects the graph is called a brid... | {"inputs": ["3 2\n1 2\n1 3\n2 3", "3 0\n2 2\n1 3\n3 3", "6 1\n2 1\n1 1\n1 3", "3 2\n2 2\n1 3\n2 3", "3 2\n2 1\n1 3\n2 3", "3 2\n2 2\n1 3\n3 3", "3 2\n1 2\n1 3\n2 1", "3 2\n2 2\n1 3\n1 3"], "outputs": ["2\n", "0\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 369 | 174 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer 0-indexed array nums.
A subset of the array nums is square-free if the product of its elements is a square-free integer.
A square-free integer is an integer that is divisible by no squ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,4,4,5]) == 3\n assert candidate(nums = [1]) == 1\n\n\ncheck(Solution().squareFreeSubsets)"} | 181 | 51 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times.
Return the minimum integer you can obtain al... | {"functional": "def check(candidate):\n assert candidate(num = \"4321\", k = 4) == \"1342\"\n assert candidate(num = \"100\", k = 1) == \"010\"\n assert candidate(num = \"36789\", k = 1000) == \"36789\"\n assert candidate(num = \"22\", k = 22) == \"22\"\n assert candidate(num = \"9438957234785635408\", k... | 99 | 170 |
coding | Solve the programming task below in a Python markdown code block.
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be... | {"inputs": ["a\n", "y\n", "e\n", "e\n", "y\n", "d\n", "x\n", "c\n"], "outputs": ["51\n", "51\n", "51\n", "51\n", "51\n", "51\n", "51\n", "51\n"]} | 299 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Prior to having fancy iPhones, teenagers would wear out their thumbs sending SMS
messages on candybar-shaped feature phones with 3x4 numeric keypads.
------- ------- -------
| | | ABC | | DEF |
| 1 | | 2 | | 3 |
------- -------... | {"functional": "_inputs = [['LOL'], ['HOW R U'], ['WHERE DO U WANT 2 MEET L8R'], ['lol'], ['0'], ['ZER0'], ['1'], ['IS NE1 OUT THERE'], ['#'], ['#codewars #rocks']]\n_outputs = [[9], [13], [47], [9], [2], [11], [1], [31], [1], [36]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(... | 536 | 236 |
coding | Solve the programming task below in a Python markdown code block.
Given an array containing only zeros and ones, find the index of the zero that, if converted to one, will make the longest sequence of ones.
For instance, given the array:
```
[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1]
```
replacing the... | {"functional": "_inputs = [[[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1]], [[1, 1, 0, 1, 1, 0, 1, 1]], [[1, 1, 1, 0, 1, 1, 0, 1, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]], [[1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1]], [[0, 0, 0, 0, 0, 1]], [[0, 0, 0, 0, 1, 0]], [[1, 0, 0, 0, 0, 0]], [[0, 1, 0, 0, 0, 0]]]\n_outputs ... | 312 | 424 |
coding | Solve the programming task below in a Python markdown code block.
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?
Chef has a unusual way of forming a triangle using gold coins, which is described as follows... | {"inputs": ["3\n3\n5\n7"], "outputs": ["2\n2\n3"]} | 391 | 22 |
coding | Solve the programming task below in a Python markdown code block.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He dec... | {"inputs": ["1\n2\nab\ncd\n", "1\n2\nab\ncc\n", "1\n2\nab\ncc\n", "1\n2\nab\ncd\n", "1\n2\nba\ncc\n", "1\n2\nba\ncb\n", "1\n2\nab\ncb\n", "1\n2\naa\ncb\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 455 | 123 |
coding | Solve the programming task below in a Python markdown code block.
Dio Brando has set a goal for himself of becoming the richest and the most powerful being on earth.To achieve his goals he will do anything using either manipulation,seduction or plain violence.
Only one guy stands between his goal of conquering earth ,... | {"inputs": ["6\nabcdfgh\nurdrdrav\njojojojoj\nbbbbaaa\ncddfsccs\ntttttttttttt"], "outputs": ["1234678\n2118418418122\n1015\n21\n46193\n20"]} | 532 | 82 |
coding | Solve the programming task below in a Python markdown code block.
A country decides to build a palace.
In this country, the average temperature of a point at an elevation of x meters is T-x \times 0.006 degrees Celsius.
There are N places proposed for the place. The elevation of Place i is H_i meters.
Among them, Princ... | {"inputs": ["2\n12 5\n1000 2000\n", "3\n21 -11\n81234 94124 52141\n"], "outputs": ["1\n", "3\n"]} | 343 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Xsquare get bored playing with the arrays all the time. So,he decided to buy a new character set to play with. Xsquare's character set contains only lower case alphabets more specifically characters from 'a' to 'z' (both inclusive). Xsquare was playing w... | {"inputs": ["10\n2\n15\n6\n5\n12\n1\n7\n9\n17\n2\n", "100\n72713\n11616\n48480\n17711\n50866\n26101\n28904\n49492\n7702\n63553\n51227\n85076\n47354\n60383\n31428\n41015\n53638\n55936\n71827\n73915\n43513\n84974\n6824\n49391\n92128\n36466\n95630\n27232\n7280\n39065\n15934\n75448\n72679\n83217\n54753\n73285\n67220\n2965\... | 458 | 1,693 |
coding | Solve the programming task below in a Python markdown code block.
We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.
Shift each character of S by N in alphabetical order (see below), and print the resulting string.
We assume that A follows Z. For example, shifting A by... | {"inputs": ["13\nA\n", "0\nYBCXAZ", "2\nABDXYZ", "0\nYBBXAZ", "2\nZYXDBA", "0\nYABXAZ", "2\nZXXDBA", "0\nZAXBAY"], "outputs": ["N\n", "YBCXAZ\n", "CDFZAB\n", "YBBXAZ\n", "BAZFDC\n", "YABXAZ\n", "BZZFDC\n", "ZAXBAY\n"]} | 205 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that returns an array containing the first `l` digits from the `n`th diagonal of [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal's_triangle).
`n = 0` should generate the first diagonal of the triangle (the 'ones'). The first n... | {"functional": "_inputs = [[0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [10, 0], [100, 6]]\n_outputs = [[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 3, 6, 10, 15, 21, 28, 36, 45, 55]], [[1, 4, 10, 20, 35, 56, 84, 120, 165, 220]], [[1, 5, 15, 35, 70, 126, 210, 330, 495, 715]], [[]], [[1, 101... | 138 | 425 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $n$.
Your task is to find two positive (greater than $0$) integers $a$ and $b$ such that $a+b=n$ and the least common multiple (LCM) of $a$ and $b$ is the minimum among all possible values of $a$ and $b$. If there are multiple a... | {"inputs": ["4\n2\n9\n5\n10\n"], "outputs": ["1 1\n3 6\n1 4\n5 5\n"]} | 578 | 37 |
coding | Solve the programming task below in a Python markdown code block.
You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \... | {"inputs": ["1\n1 3\n2 1 1\n", "1\n1 5\n1 2 4 3 3\n", "1\n1 5\n1 3 2 2 4\n", "1\n1 7\n1 2 4 3 3 3 5\n", "1\n2 4\n2 1 1 1\n2 2 2 1\n", "5\n2 3\n1 2 3\n1 1 1\n2 2\n4 1\n2 3\n2 2\n2 1\n1 1\n2 3\n6 2 1\n5 4 3\n2 1\n1\n2\n", "4\n1 10\n1 2 3 2 2 2 2 2 3 3\n1 10\n1 2 3 3 3 3 3 2 3 3\n1 10\n1 2 3 3 3 3 2 2 3 3\n1 5\n1 4 3 2 5\... | 590 | 331 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.
Please complete the following python c... | {"functional": "def check(candidate):\n assert candidate(words = [\"abcw\",\"baz\",\"foo\",\"bar\",\"xtfn\",\"abcdef\"]) == 16 \n assert candidate(words = [\"a\",\"ab\",\"abc\",\"d\",\"cd\",\"bcd\",\"abcd\"]) == 4 \n assert candidate(words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]) == 0 \n\n\ncheck(Solution().maxProdu... | 89 | 95 |
coding | Solve the programming task below in a Python markdown code block.
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can... | {"inputs": ["1 1\n1\n1\n", "1 1\n4\n6\n", "1 1\n1\n1\n", "1 1\n4\n6\n", "1 1\n8\n6\n", "1 1\n7\n0\n", "1 1\n5\n0\n", "1 1\n9\n6\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 595 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to change the string s into string f during these q days, because it looks... | {"inputs": ["1\n4 1\n0011\n0011\n1 4\n", "1\n4 1\n0011\n0111\n1 4\n", "1\n4 1\n0011\n0011\n4 4\n", "1\n4 1\n0011\n0110\n1 4\n", "1\n4 1\n0011\n0011\n2 4\n", "1\n4 1\n0011\n0100\n1 4\n", "1\n4 1\n0011\n0100\n2 4\n", "1\n4 1\n0011\n0001\n4 4\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"... | 676 | 214 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$.
You are also given a set of distinct positions $p_1, p_2, \dots, p_m$, where $1 \le p_i < n$. The position $p_i$ means that you can swap elements $a[p_i]$ and $a[p_i + 1]$. You can apply this operation any numbe... | {"inputs": ["1\n3 1\n3 1 1\n1\n", "1\n3 1\n3 1 1\n1\n", "1\n3 1\n3 2 1\n1\n", "1\n4 2\n4 4 1 2\n2 1\n", "1\n4 2\n4 4 1 2\n2 1\n", "1\n4 2\n4 3 1 2\n2 1\n", "1\n4 2\n6 3 1 2\n2 1\n", "1\n4 1\n4 4 1 2\n2 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 723 | 186 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an integer N. He repeats the following operation until N becomes 1.
- Chef chooses an integer X such that X > 1 and X is a divisor of N and then divides N by X (the new value of N becomes N/X). If X is even, Chef gets A points otherwise he gets... | {"inputs": ["4\n10 2 3\n15 5 -2\n12 2 3\n8 -1 0\n"], "outputs": ["5\n-2\n7\n-1\n"]} | 350 | 49 |
coding | Solve the programming task below in a Python markdown code block.
A tuple of positive integers (a, b, c) is said to be a *bad tuple* if a, b, c are distinct, a divides b, and b divides c. For example, (1, 2, 4) and (7, 21, 42) are bad tuples while (1, 2, 3) and (2, 4, 4) are not.
Chef has the N integers from 1 to N wi... | {"inputs": ["2\n", "4\n"], "outputs": ["4\n", "14\n"]} | 371 | 23 |
coding | Solve the programming task below in a Python markdown code block.
You just took a contract with the Jedi council. They need you to write a function, `greet_jedi()`, which takes two arguments (a first name and a last name), works out the corresponding *Jedi name*, and returns a string greeting the Jedi.
A person's *Jed... | {"functional": "_inputs = [['Beyonce', 'Knowles'], ['Chris', 'Angelico'], ['grae', 'drake']]\n_outputs = [['Greetings, master KnoBe'], ['Greetings, master AngCh'], ['Greetings, master DraGr']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(... | 270 | 196 |
coding | Solve the programming task below in a Python markdown code block.
Petya has an array of integers a_1, a_2, …, a_n. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it.
Petya likes to challenge himself, so he wants to sort array using only 3-cycles. More formally, i... | {"inputs": ["7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 3 3\n3\n2 1 3\n3\n3 1 2\n4\n2 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 3 3\n3\n2 1 2\n3\n3 1 1\n4\n2 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 2 3\n3\n2 1 3\n3\n3 2 1\n4\n2 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 3 3\n3\n2 1 2\n3\n3 2 1\n4\n4 1 4 3\n", "7\n1\n1\n2\n2 2\n2\n2 2... | 629 | 566 |
coding | Solve the programming task below in a Python markdown code block.
You have a string s = s_1s_2...s_{|}s|, where |s| is the length of string s, and s_{i} its i-th character.
Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string s_{i}s_{i} + 1...s_{j}. The prefix of string s... | {"inputs": ["A\n", "A\n", "AB\n", "ZZ\n", "ZZ\n", "AB\n", "BA\n", "AA\n"], "outputs": ["1\n1 1\n", "1\n1 1\n", "1\n2 1\n", "2\n1 2\n2 1\n", "2\n1 2\n2 1\n", "1\n2 1\n", "1\n2 1\n", "2\n1 2\n2 1\n"]} | 403 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.
In the city in which Alice and Bob live, the first metro line is being built. This metro line contains $n$ stations numbered... | {"inputs": ["2 2\n1 1\n0 0\n", "2 2\n1 0\n1 0\n", "2 2\n0 0\n0 0\n", "2 2\n0 0\n0 0\n", "2 2\n1 0\n1 0\n", "2 2\n1 1\n0 0\n", "2 2\n1 0\n2 0\n", "2 2\n1 1\n0 1\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n"]} | 737 | 150 |
coding | Solve the programming task below in a Python markdown code block.
In some other world, today is December D-th.
Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.
-----Constraints-----
- 22 \leq D \leq 25
- D is an integer.
-----... | {"inputs": ["4", "8", "6", "0", "1", "2", "3", "7"], "outputs": ["Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve\n", "Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve\n", "Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Ev... | 130 | 231 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.
A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the b... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]) == 3\n assert candidate(grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]) == 0\n\n\ncheck(Solution().numEnclaves)"} | 130 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of n last pro... | {"inputs": ["1\na\n", "1\nb\n", "1\nz\n", "1\nz\n", "1\na\n", "1\nb\n", "1\ny\n", "2\nhk\nobsp\n"], "outputs": ["b\n", "a\n", "a\n", "a\n", "b\n", "a\n", "a\n", "a\n"]} | 551 | 89 |
coding | Solve the programming task below in a Python markdown code block.
Petya and Vasya are competing with each other in a new interesting game as they always do.
At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to s... | {"inputs": ["1 3\n", "6 7\n", "1 1\n", "6 8\n", "5 5\n", "1 8\n", "3 3\n", "5 9\n"], "outputs": ["YES\n3\n1\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n8\n1\n", "NO\n", "NO\n"]} | 352 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is teaching his students about properties of integers. Today he is teaching them about numbers which are squares of some number, e.g. 1, 4, 9, 16, 25 etc. These numbers ... | {"inputs": ["3\n3\n2 2 2\n3\n1 2 2\n3\n2 4 6"], "outputs": ["0\n1\n2"]} | 624 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
You are given an array A of N elements. You can do the following operations on that array:
Remove the leftmost element of the array, with index l, for the cost A_{l}. Thi... | {"inputs": ["3\n5 2 7\n9 10 11 12 13\n5 0 7\n9 9 9 9 9\n5 2 7\n9 1 2 3 10\n"], "outputs": ["23\n45\n13\n"]} | 664 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious ... | {"inputs": ["1\n7\n0\n", "1\n10\n0\n", "1\n10\n0\n", "1\n14\n0\n", "1\n11\n0\n", "1\n16\n0\n", "1\n50\n1\n1 2\n", "1\n100\n1\n1 1\n"], "outputs": ["7\n", "10\n", "10\n", "14\n", "11\n", "16\n", "0\n", "0\n"]} | 510 | 123 |
coding | Solve the programming task below in a Python markdown code block.
Sherlock is given $2$ square tiles, initially both of whose sides have length $\boldsymbol{l}$ placed in an $x-y$ plane. Initially, the bottom left corners of each square are at the origin and their sides are parallel to the axes.
At $t=0$, both squa... | {"inputs": ["10 1 2\n2\n50\n100\n"], "outputs": ["4.1421\n0.0000\n"]} | 514 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Daisy loves playing games with words. Recently, she has been playing the following Deletive Editing word game with Daniel.
Daisy picks a word, for example, "DETERMINED". On each game turn, Daniel calls out a letter, for example, 'E', and Daisy removes t... | {"inputs": ["10\nGK GK\nF F\nH D\nZQ QZ\nC C\nFN NF\nS S\nC C\nEM C\nXO C\n", "6\nDETERMINED TRME\nDETERMINED TERM\nPSEUDOPSEUDOHYPOPARATHYROIDISM PEPA\nDEINSTITUTIONALIZATION DONATION\nCONTEST CODE\nSOLUTION SOLUTION\n"], "outputs": ["YES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\n", "YES\nNO\nNO\nYES\nNO\nYES\n"]} | 485 | 132 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern ... | {"inputs": ["2 1\na\nb\n1\n", "2 1\na\nb\n2\n", "2 1\na\nb\n1\n", "2 1\na\nb\n2\n", "2 1\na\nc\n1\n", "2 1\nb\nc\n1\n", "2 1\naa\nb\n1\n", "2 1\naa\nb\n2\n"], "outputs": ["Yes\na\n", "Yes\nb\n", "Yes\na\n", "Yes\nb\n", "Yes\na\n", "Yes\nb\n", "Yes\naa\n", "Yes\nb\n"]} | 580 | 150 |
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.
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems.
The boy h... | {"inputs": ["1\n1 2\n88\n", "1\n1 3\n88\n", "1\n1 3\n129\n", "1\n1 2\n148\n", "1\n17 2\n0 17 22 21 5 7 5 24 10 8 8 6 1 8 3 0 0\n", "1\n17 2\n0 17 22 20 5 7 5 24 10 8 8 6 1 8 3 0 0\n", "1\n17 2\n0 17 22 21 5 7 13 12 10 8 8 6 1 8 3 0 0\n", "1\n17 2\n0 17 22 21 5 7 13 24 10 8 8 6 1 8 3 0 0\n"], "outputs": ["140130951\n", ... | 564 | 337 |
coding | Solve the programming task below in a Python markdown code block.
The objective is to disambiguate two given names: the original with another
This kata is slightly more evolved than the previous one: [Author Disambiguation: to the point!](https://www.codewars.com/kata/580a429e1cb4028481000019).
The function ```could_... | {"functional": "_inputs = [['Carlos Ray Norris', 'Carlos Ray Norris'], ['Carlos Ray Norris', 'Carlos Ray'], ['Carlos Ray Norris', 'Ray Norris'], ['Carlos Ray Norris', 'Carlos Norris'], ['Carlos Ray Norris', 'Norris'], ['Carlos Ray Norris', 'Carlos'], ['Carlos Ray Norris', 'Norris Carlos'], ['Carlos Ray Norris', 'carlos... | 536 | 438 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.