problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
Chef is a big fan of Coldplay. Every Sunday, he will drive to a park taking M minutes to reach there, and during the ride he will play a single song on a loop. Today, he has got the latest song which is in total S minutes long. He is interested to know h... | {"inputs": ["3\n10 5\n10 6\n9 10"], "outputs": ["2\n1\n0"]} | coding | 358 |
Solve the programming task below in a Python markdown code block.
Write a program to take a character (C) as input and check whether the given character is a vowel or a consonant.
NOTE:-
Vowels are 'A', 'E', 'I', 'O', 'U'. Rest all alphabets are called consonants.
------ Input Format ------
- First line will contai... | {"inputs": ["Z\n"], "outputs": ["Consonant"]} | coding | 157 |
Solve the programming task below in a Python markdown code block.
Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string contained in the input string (actually each input line) with another string β. More precisely, it proceeds as follows.
1. Within the input... | {"inputs": ["2\na bb\nb aa\na\nbbbbbbbb\n1\na aa\na\naaaaa\n3\nab aab\nabc aadc\nad dee\nabc\ndeeeeeeeec\n10\na abc\nb bai\nc acf\nd bed\ne abh\nf fag\ng abe\nh bag\ni aaj\nj bbb\na\nabaceaabe\n0", "2\na bb\nb aa\nb\nbbbbbbbb\n1\nb aa\na\naaaaa\n3\nab aab\nabc aadc\nad dee\nabc\ndeeeeeeeec\n10\na abc\nb bai\nc acf\nd b... | coding | 624 |
Solve the programming task below in a Python markdown code block.
Assume we take a number `x` and perform any one of the following operations:
```Pearl
a) Divide x by 3 (if it is divisible by 3), or
b) Multiply x by 2
```
After each operation, we write down the result. If we start with `9`, we can get a sequence such a... | {"functional": "_inputs = [[[1, 3]], [[4, 2]], [[12, 3, 9, 4, 6, 8]], [[4, 8, 6, 3, 12, 9]], [[558, 744, 1488, 279, 2232, 1116]], [[9, 1, 3]], [[3000, 9000]], [[4, 1, 2]], [[10, 5]]]\n_outputs = [[[3, 1]], [[2, 4]], [[9, 3, 6, 12, 4, 8]], [[9, 3, 6, 12, 4, 8]], [[279, 558, 1116, 2232, 744, 1488]], [[9, 3, 1]], [[9000, ... | coding | 246 |
Solve the programming task below in a Python markdown code block.
In this kata you have to correctly return who is the "survivor", ie: the last element of a Josephus permutation.
Basically you have to assume that n people are put into a circle and that they are eliminated in steps of k elements, like this:
```
joseph... | {"functional": "_inputs = [[7, 3], [11, 19], [40, 3], [14, 2], [100, 1], [1, 300], [2, 300], [5, 300], [7, 300], [300, 300]]\n_outputs = [[4], [10], [28], [13], [100], [1], [1], [1], [7], [265]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclos... | coding | 346 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part.
Note that the partition is done so that after concatenating all the parts in or... | {"functional": "def check(candidate):\n assert candidate(s = \"ababcbacadefegdehijhklij\") == [9,7,8]\n assert candidate(s = \"eccbbbbdec\") == [10]\n\n\ncheck(Solution().partitionLabels)"} | coding | 114 |
Solve the programming task below in a Python markdown code block.
Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resulting set.... | {"inputs": ["3\n0 0\n2 2\n3 3", "3\n0 0\n2 2\n3 3", "5\n0 0\n100 100\n200 200\n100 0\n0 100", "5\n0 0\n100 100\n200 200\n100 0\n0 100"], "outputs": ["2", "2", "0", "0"]} | coding | 320 |
Solve the programming task below in a Python markdown code block.
You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.
-----Constraints-----
- 1\leq A\leq B\leq 10^{18}
- 1\leq C,D\leq 10^9
- All values in input are intege... | {"inputs": ["4 5 2 3", "1 5 2 3", "1 5 2 6", "1 4 8 8", "4 9 2 3", "4 9 2 3\n", "1 1 1 1\n", "2 40 8 8"], "outputs": ["1\n", "2\n", "3\n", "4\n", "2", "2\n", "0\n", "34\n"]} | coding | 170 |
Solve the programming task below in a Python markdown code block.
You were strolling outside the restaurant at the end of the universe. On a metaspiral path you stumble upon a weird device which takes a three-digit number as input and processes it. The Hitchhiker's guide to the galaxy explains that it processes the inp... | {"inputs": ["1\n123 5"], "outputs": ["27"]} | coding | 376 |
Solve the programming task below in a Python markdown code block.
Transpose
We can generate the transposition of an array using the tool numpy.transpose.
It will not affect the original array, but it will create a new array.
import numpy
my_array = numpy.array([[1,2,3],
[4,5,6]])
print nu... | {"inputs": ["2 2\n1 2\n3 4\n"], "outputs": ["[[1 3]\n [2 4]]\n[1 2 3 4]\n"]} | coding | 302 |
Solve the programming task below in a Python markdown code block.
You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such tha... | {"inputs": ["? - ? = 2\n", "? - ? = 1\n", "? = 1000010\n", "? = 1010010\n", "? = 1100000\n", "? = 1000011\n", "? = 1010011\n", "? = 1010001\n"], "outputs": ["Impossible", "Impossible\n", "Possible\n1000010 = 1000010", "Possible\n1010010 = 1010010", "Possible\n1100000 = 1100000", "Possible\n1000011 = 1000011", "Possible... | coding | 296 |
Solve the programming task below in a Python markdown code block.
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implem... | {"inputs": ["1\n1 0 0\n", "1\n1 1 1\n", "1\n0 0 0\n", "1\n1 1 0\n", "1\n0 1 0\n", "1\n1 0 1\n", "2\n1 0 0\n1 1 1\n", "2\n1 0 1\n1 1 1\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "2\n"]} | coding | 406 |
Solve the programming task below in a Python markdown code block.
------ Problem Statement ------
Past
In the year of 2048, the Virtual Reality Massively Multiplayer Online Role-Playing Game (VRMMORPG), Code Art Online (CAO), is released. With the Chef Gear, a virtual reality helmet that stimulates the user's five s... | {"inputs": ["2\n5 5\n^^^^^\n^^^^^\n^^^^#\n^^^^^\n^^^^^\n5 7\n^^#^^^^\n^^#^#^#\n#^^^^^^\n^^#^^#^\n^^^^^^^", "2\n5 5\n^^^^^\n^^^^^\n^^^]#\n^^^^^\n^^^^^\n5 7\n^^#^^^^\n^^#^#^#\n#^^^^^^\n^^#^^#^\n^^^^^^^", "2\n5 1\n^^^^^\n^^^^^\n^^^^#\n^^^^^\n^]^^^\n5 7\n^^#^^^_\n^^###^^\n#^^^^^^\n^^#^^#^\n^^^^^^^", "2\n5 1\n^^^^^\n^^^^^\n... | coding | 656 |
Solve the programming task below in a Python markdown code block.
# Introduction
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began.
# Task
Write a function that accepts `fight` str... | {"functional": "_inputs = [['z'], ['zdqmwpbs'], ['wq'], ['zzzzs'], ['wwwwww']]\n_outputs = [['Right side wins!'], [\"Let's fight again!\"], ['Left side wins!'], ['Right side wins!'], ['Left side wins!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma... | coding | 264 |
Solve the programming task below in a Python markdown code block.
A [perfect power](https://en.wikipedia.org/wiki/Perfect_power) is a classification of positive integers:
> In mathematics, a **perfect power** is a positive integer that can be expressed as an integer power of another positive integer. More formally, n ... | {"functional": "_inputs = [[4], [9], [5]]\n_outputs = [[[2, 2]], [[3, 2]], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fal... | coding | 289 |
Solve the programming task below in a Python markdown code block.
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
-----Constraints-----
- 2≤K≤2500
- 0≤S≤3K
- K and... | {"inputs": ["2 2\n", "5 15\n", "1050 0\n", "148 35\n", "602 293\n", "446 491\n", "2500 3750\n", "2500 7500\n"], "outputs": ["6\n", "1\n", "1\n", "666\n", "43365\n", "118173\n", "4691251\n", "1\n"]} | coding | 260 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string num of length n consisting of digits.
Return true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.
Please complete the fo... | {"functional": "def check(candidate):\n assert candidate(num = \"1210\") == True\n assert candidate(num = \"030\") == False\n\n\ncheck(Solution().digitCount)"} | coding | 96 |
Solve the programming task below in a Python markdown code block.
Write a function which takes a number and returns the corresponding ASCII char for that value.
Example:
~~~if-not:java,racket
```
get_char(65) # => 'A'
```
~~~
~~~if:java
~~~
~~~if:racket
~~~
For ASCII table, you can refer to http://www.asciitable.co... | {"functional": "_inputs = [[65], [33], [34], [35], [36], [37], [38]]\n_outputs = [['A'], ['!'], ['\"'], ['#'], ['$'], ['%'], ['&']]\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, ... | coding | 112 |
Solve the programming task below in a Python markdown code block.
You're laying out a rad pixel art mural to paint on your living room wall in homage to [Paul Robertson](http://68.media.tumblr.com/0f55f7f3789a354cfcda7c2a64f501d1/tumblr_o7eq3biK9s1qhccbco1_500.png), your favorite pixel artist.
You want your work to be... | {"functional": "_inputs = [[4050, 27], [4066, 27], [10000, 20], [10005, 20]]\n_outputs = [[True], [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)):... | coding | 524 |
Solve the programming task below in a Python markdown code block.
You are given an integer n. Find any string s of length n consisting only of English lowercase letters such that each non-empty substring of s occurs in s an odd number of times. If there are multiple such strings, output any. It can be shown that such s... | {"inputs": ["1\n5\n", "1\n8\n", "1\n6\n", "1\n3\n", "1\n7\n", "1\n9\n", "1\n4\n", "1\n94\n"], "outputs": ["aabca\n", "aaaabaaa\n", "aaabaa\n", "abc\n", "aaabcaa\n", "aaaabcaaa\n", "aaba\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"]} | coding | 346 |
Solve the programming task below in a Python markdown code block.
Chef loves cooking. Also, he is very hygienic. Hence, Chef grows his own vegetables in his mini kitchen garden. He has $M$ lanes in which he grows vegetables. The $ith$ lane has $Ai$ vegetables growing in it.
Vegetables in $ith$ lane become edible on d... | {"inputs": ["2 4\n1 6\n2 5", "3 3\n1 4\n6 2\n5 3"], "outputs": ["11", "9"]} | coding | 662 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 of length n.
The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).
For exampl... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2], nums2 = [2,3]) == 2\n assert candidate(nums1 = [1,0,3], nums2 = [5,3,4]) == 8\n\n\ncheck(Solution().minimumXORSum)"} | coding | 214 |
Solve the programming task below in a Python markdown code block.
Complete the function that accepts a string parameter, and reverses each word in the string. **All** spaces in the string should be retained.
## Examples
```
"This is an example!" ==> "sihT si na !elpmaxe"
"double spaces" ==> "elbuod secaps"
```
... | {"functional": "_inputs = [['The quick brown fox jumps over the lazy dog.'], ['apple'], ['a b c d'], ['double spaced words'], ['stressed desserts'], ['hello hello']]\n_outputs = [['ehT kciuq nworb xof spmuj revo eht yzal .god'], ['elppa'], ['a b c d'], ['elbuod decaps sdrow'], ['desserts stressed'], ['olleh olleh']... | coding | 102 |
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 (BST), return the minimum difference between the values of any two different nodes in the tree.
Please complete the following python code precisely:
```python
# Definition for ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([4,2,6,1,3])) == 1\n assert candidate(root = tree_node([1,0,48,None,None,12,49])) == 1\n\n\ncheck(Solution().minDiffInBST)"} | coding | 129 |
Solve the programming task below in a Python markdown code block.
We define f(x)=\begin{cases} f(x \oplus reverse(x))+1 & \text{if } x \neq 0 \\ 0 & \text{otherwise} \end{cases}
Here, \oplus denotes the [bitwise XOR operation] and reverse is a function that takes a postive integer, reverses its binary representation... | {"inputs": ["8\n1\n2\n3\n5\n8\n13\n21\n34\n"], "outputs": ["1\n4\n10\n58\n578\n20098\n5236738\n24641495\n"]} | coding | 673 |
Solve the programming task below in a Python markdown code block.
There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains a_{i} balls, all of which have color i. You have to write a program that will divide all balls into sets such that: each ball belongs to exactly one of... | {"inputs": ["1\n1\n", "1\n1\n", "2\n2 7\n", "2\n9 6\n", "2\n9 6\n", "2\n9 1\n", "2\n2 3\n", "2\n3 5\n"], "outputs": ["1\n", "1\n", "4\n", "5\n", "5\n", "6\n", "2\n", "3\n"]} | coding | 294 |
Solve the programming task below in a Python markdown code block.
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of... | {"inputs": ["2 1\n2 1\n", "1 0\n1000", "1 1\n1001", "0 1\n1011", "1 1\n1010", "1 1\n1000", "1 1\n1000\n", "-1 1\n0111"], "outputs": ["1\n", "0\n", "1001\n", "1011\n", "1010\n", "1000", "1000\n", "111\n"]} | coding | 301 |
Solve the programming task below in a Python markdown code block.
Chef is now a corporate person. He has to attend office regularly. But chef does not want to go to office, rather he wants to stay home and discover different recipes and cook them.
In the office where chef works, has two guards who count how many times... | {"inputs": ["1\n19 17"], "outputs": ["19 36"]} | coding | 336 |
Solve the programming task below in a Python markdown code block.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The i... | {"inputs": ["5 3\n2\n5\n0\n5\n3\n0 0", "5 1\n0\n0\n0\n3\n1\n0 0", "5 3\n2\n5\n0\n8\n0\n0 0", "5 3\n2\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n2\n8\n0\n0 0", "5 3\n2\n5\n-4\n8\n3\n0 0", "5 3\n1\n9\n-4\n2\n1\n0 0"], "outputs": ["10\n", "3\n", "13\n", "14\n", "14\n", "15\n", "9\n", "7\n"]} | coding | 294 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers stones where stones[i] is the weight of the ith stone.
We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the hea... | {"functional": "def check(candidate):\n assert candidate([2,7,4,1,8,1]) == 1\n\n\ncheck(Solution().lastStoneWeight)"} | coding | 190 |
Solve the programming task below in a Python markdown code block.
This function should test if the `factor` is a factor of `base`.
Return `true` if it is a factor or `false` if it is not.
## About factors
Factors are numbers you can multiply together to get another number.
2 and 3 are factors of 6 because: `2 * 3 = ... | {"functional": "_inputs = [[10, 2], [63, 7], [2450, 5], [24612, 3], [9, 2], [653, 7], [2453, 5], [24617, 3]]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ... | coding | 190 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s. Return all the words vertically in the same order in which they appear in s.
Words are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed).
Each... | {"functional": "def check(candidate):\n assert candidate(s = \"HOW ARE YOU\") == [\"HAY\",\"ORO\",\"WEU\"]\n assert candidate(s = \"TO BE OR NOT TO BE\") == [\"TBONTB\",\"OEROOE\",\" T\"]\n assert candidate(s = \"CONTEST IS COMING\") == [\"CIC\",\"OSO\",\"N M\",\"T I\",\"E N\",\"S G\",\"T\"]\n\n\ncheck(Solut... | coding | 118 |
Solve the programming task below in a Python markdown code block.
Given are a positive integer N and a string S of length N consisting of lowercase English letters.
Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string T such that S = T + T.
-----Con... | {"inputs": ["1\n{", "1\ny", "1\n|", "1\n}", "1\n~", "1\n\u007f", "1\nz", "1\nz\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No", "No\n"]} | coding | 169 |
Solve the programming task below in a Python markdown code block.
You are given two positive integers ```a``` and ```b```.
You can perform the following operations on ```a``` so as to obtain ```b``` :
```
(a-1)/2 (if (a-1) is divisible by 2)
a/2 (if a is divisible by 2)
a*2
```
```b``` will always be a power o... | {"functional": "_inputs = [[1, 1], [2, 4], [3, 8], [4, 16], [4, 1], [1, 4]]\n_outputs = [[0], [1], [4], [2], [2], [2]]\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 ... | coding | 223 |
Solve the programming task below in a Python markdown code block.
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, ret... | {"functional": "_inputs = [[[1, 2, 3, 4, 3, 2, 1]], [[1, 100, 50, -51, 1, 1]], [[1, 2, 3, 4, 5, 6]], [[20, 10, 30, 10, 10, 15, 35]], [[20, 10, -80, 10, 10, 15, 35]], [[10, -80, 10, 10, 15, 35, 20]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ... | coding | 519 |
Solve the programming task below in a Python markdown code block.
Given is a tree with N vertices numbered 1 to N, and N-1 edges numbered 1 to N-1.
Edge i connects Vertex a_i and b_i bidirectionally and has a length of 1.
Snuke will paint each vertex white or black.
The niceness of a way of painting the graph is \max(X... | {"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n2 1\n", "6\n1 2\n2 3\n3 4\n4 5\n3 6\n", "35\n25 4\n33 7\n11 26\n32 4\n12 7\n31 27\n19 6\n10 22\n17 12\n28 24\n28 1\n24 15\n30 24\n24 11\n23 18\n14 15\n4 29\n33 24\n15 34\n11 3\n4 35\n5 34\n34 2\n16 19\n7 18\n19 31\n22 8\n13 26\n20 6\n20 9\n4 33\n4 8\n29 19\n15 21\n"], "outputs": ... | coding | 354 |
Solve the programming task below in a Python markdown code block.
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can tra... | {"inputs": ["1\na\n", "1\nb\n", "1\n`\n", "2\na\nb\n", "2\nb\nb\n", "2\nb\na\n", "2\nc\na\n", "2\naa\naa\n"], "outputs": ["0\n", "0\n", "0\n", "-1\n", "0\n", "-1\n", "-1\n", "0\n"]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
Check Tutorial tab to know how to to solve.
You are given a string $N$.
Your task is to verify that $N$ is a floating point number.
In this task, a valid float number must satisfy all of the following requirements:
$>$ Number can start with +,... | {"inputs": ["4\n4.0O0\n-1.00\n+4.54\nSomeRandomStuff\n"], "outputs": ["False\nTrue\nTrue\nFalse\n"]} | coding | 324 |
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 with N integers. You have to tell Chef whether this array is closed under multiplication.
We say that an array is closed under multiplication if... | {"inputs": ["3\n3\n1 0 3\n3\n1 -1 -1\n3\n1 3 3"], "outputs": ["1\n1\n0\n"]} | coding | 729 |
Solve the programming task below in a Python markdown code block.
Given two integers $n$ and $\textbf{r}$. In how many ways can $\textbf{r}$ items be chosen from $n$ items?
Input Format
The first line contains the number of test cases $\mathbf{T}$. Each of the next $\mathbf{T}$ lines contains two integers $n$ and $\t... | {"inputs": ["4\n2 1\n4 0\n5 2\n10 3\n"], "outputs": ["2\n1\n10\n120\n"]} | coding | 201 |
Solve the programming task below in a Python markdown code block.
----- Statement -----
You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the ... | {"inputs": ["2\n1\n2", "2\n2\n2", "2\n2\n3", "2\n3\n2", "2\n2\n5", "2\n4\n5", "2\n3\n5", "2\n5\n5"], "outputs": ["ba\ncba", "cba\ncba\n", "cba\ndcba\n", "dcba\ncba\n", "cba\nfedcba\n", "edcba\nfedcba\n", "dcba\nfedcba\n", "fedcba\nfedcba\n"]} | coding | 161 |
Solve the programming task below in a Python markdown code block.
Rakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate magic inde... | {"inputs": ["1\n10 12 4 5 3"], "outputs": ["0"]} | coding | 585 |
Solve the programming task below in a Python markdown code block.
Billi was on date with his girlfriend Ketty. They had the following conversation
Ketty :- "Billi, How much do u love me?"
Billi :- "Ummm...."
Ketty :- "Come on.... Do you love me or not? :'( "
Billi :- "Umm.....yes, I love you A^B units."
Ketty :- "... | {"inputs": ["329\n394 656 2\n191 710 7\n433 784 2\n796 789 1\n950 317 3\n561 620 5\n685 839 7\n441 740 1\n970 284 6\n130 153 6\n811 546 5\n892 88 2\n306 873 1\n691 20 5\n460 969 2\n62 882 5\n522 918 3\n584 358 7\n209 327 2\n214 808 2\n259 970 3\n959 213 2\n72 518 2\n969 561 6\n653 20 6\n654 433 7\n978 955 4\n789 538 1\... | coding | 332 |
Solve the programming task below in a Python markdown code block.
Chef is planning a huge party for all of you and has ordered M pizzas. He wants to invite as many people to the party. However, he knows that everyone will have exactly one slice of a pizza (regardless of the size) and he wants to make sure that he has e... | {"inputs": ["5 10\n1 2 3 4 5\n"], "outputs": ["31"]} | coding | 386 |
Solve the programming task below in a Python markdown code block.
After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys... | {"inputs": ["3 1 3\n1\n2\n3\n", "4 0 4\n1\n2\n3\n4\n", "4 1 4\n1\n2\n3\n4\n", "5 2 5\n1\n2\n2\n4\n5\n", "5 2 5\n1\n2\n3\n1\n5\n", "5 2 5\n1\n3\n3\n1\n5\n", "5 2 5\n1\n3\n3\n2\n5\n", "5 2 5\n1\n2\n3\n4\n5\n"], "outputs": ["..X", "....", "...X", "...XX", "....X", "....X", "....X", "...XX"]} | coding | 725 |
Solve the programming task below in a Python markdown code block.
Problem Statement
The Animal School is a primary school for animal children. You are a fox attending this school.
One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako. Arithmetical Restorations are the pro... | {"inputs": ["3?4\n12?\n5?6\n?1?4\n5?7?\n?9?2\n?????\n?????\n?????\n0", "3?4\n12?\n6?5\n?2?4\n5?7?\n?9?2\n?????\n?????\n?????\n0", "3?4\n12?\n6?5\n?2?4\n5?7?\n2?9?\n?????\n?????\n?????\n0", "3?4\n?21\n6?5\n?2?4\n5?7?\n2?9?\n?????\n?????\n?????\n0", "34?\n?21\n6?5\n4?2?\n5?7?\n2?9?\n?????\n?????\n?????\n0", "3?4\n12?\n5?... | coding | 654 |
Solve the programming task below in a Python markdown code block.
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car... | {"inputs": ["3 2 1 1\n", "5 4 3 1\n", "4 3 2 1\n", "98 2 1 1\n", "27 3 2 3\n", "13 7 6 2\n", "15 6 4 5\n", "21 3 1 3\n"], "outputs": ["4\n3\n1\n", "-1\n", "4\n3\n2\n", "98\n3\n1\n", "-1\n", "-1\n", "15\n11\n5\n", "-1\n"]} | coding | 429 |
Solve the programming task below in a Python markdown code block.
Maki is a house cat. One day she fortunately came at a wonderful-looking dried fish. Since she felt not hungry on that day, she put it up in her bed. However there was a problem; a rat was living in her house, and he was watching for a chance to steal he... | {"inputs": ["3\n0 0 100 101\n77 100 50\n110 010 18\n42 80 50\n4\n1 0 110 110\n8 22 50\n25 50 58\n9 154 65\n806 205 50\n0", "3\n0 1 100 101\n60 100 50\n110 010 18\n42 80 50\n4\n1 0 010 100\n8 21 50\n25 50 58\n50 150 65\n409 205 50\n0", "3\n0 0 100 101\n77 100 90\n110 110 18\n42 80 6\n4\n1 0 110 010\n8 22 50\n25 50 58\n1... | coding | 616 |
Solve the programming task below in a Python markdown code block.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and ... | {"inputs": ["1 1\nR\n", "1 1\nR\n", "1 2\nRB\n", "1 2\nRG\n", "1 2\nRG\n", "1 2\nRB\n", "1 3\nGRB\n", "1 3\nRGG\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]} | coding | 404 |
Solve the programming task below in a Python markdown code block.
Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.
Constraints
* 1 \leq N \leq 3000
* 1 \leq X \leq 2N
* N and X are integers.
Input
Input is given from St... | {"inputs": ["5 3", "1 6", "5 1", "1 1", "0 2", "3 6", "5 2", "4 2"], "outputs": ["47\n", "3\n", "32\n", "2\n", "1\n", "26\n", "6\n", "5\n"]} | coding | 212 |
Solve the programming task below in a Python markdown code block.
Welcome. In this kata, you are asked to square every digit of a number and concatenate them.
For example, if we run 9119 through the function, 811181 will come out, because 9^(2) is 81 and 1^(2) is 1.
**Note:** The function accepts an integer and retur... | {"functional": "_inputs = [[3212], [2112]]\n_outputs = [[9414], [4114]]\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 ... | coding | 113 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well.
Chef prepared a problem. The admin has rated this problem for x points.
A problem is called :
1) Easy if 1 ≤ x < 100
2) Medium if 100 ≤ x < 200
3) Hard if 200 ≤ x ≤ 300
... | {"inputs": ["3\n50\n172\n201\n"], "outputs": ["Easy\nMedium\nHard\n"]} | coding | 381 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an binary array nums and an integer k, return true if all 1's are at least k places away from each other, otherwise return false.
Please complete the following python code precisely:
```python
class Solution:
... | {"functional": "def check(candidate):\n assert candidate(nums = [1,0,0,0,1,0,0,1], k = 2) == True\n assert candidate(nums = [1,0,0,1,0,1], k = 2) == False\n assert candidate(nums = [1,1,1,1,1], k = 0) == True\n assert candidate(nums = [0,1,0,1], k = 1) == True\n\n\ncheck(Solution().kLengthApart)"} | coding | 84 |
Solve the programming task below in a Python markdown code block.
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.
* `0 u v`: Add an edge (u, v).
* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
Constraints
* 1 \leq N \leq 200,000... | {"inputs": ["4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n1 0 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 2\n1 1 2\n0 0 2\n1 1 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 1\n1 1 2\n0 0 2\n0 0 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n1 0 2\n1 1 2\n0 0 2\n0 1 3", "4 7\n1 1 1\n0 0 1\n0 2 3\n1 0 2\n1 0 2\n0 0 2\n0 1 3", "4 7\n1 0 1\n0 0 1\n0 2 3\n2... | coding | 247 |
Solve the programming task below in a Python markdown code block.
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference between the ma... | {"inputs": ["3 3\n7 12 8\n", "3 3\n7 12 8\n", "4 5\n3 1 7 5\n", "4 5\n3 1 7 5\n", "5 1\n6 4 6 7 7\n", "5 1\n6 4 6 7 7\n", "5 1\n6 4 6 11 7\n", "3 10\n100 100 100\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "6\n", "0\n"]} | coding | 411 |
Solve the programming task below in a Python markdown code block.
The factorial of the integer $n$, written $n!$, is defined as:
$n!=n\times(n-1)\times(n-2)\times\text{}\cdots\times3\times2\times1$
Calculate and print the factorial of a given integer.
For example, if $n=30$, we calculate $30\times29\times28\tim... | {"inputs": ["25\n"], "outputs": ["15511210043330985984000000\n"]} | coding | 371 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.
For example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.... | {"functional": "def check(candidate):\n assert candidate(grid = [[1],[22],[333]]) == [3]\n assert candidate(grid = [[-15,1,3],[15,7,12],[5,6,-2]]) == [3,1,2]\n\n\ncheck(Solution().findColumnWidth)"} | coding | 162 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [positioni, rangei] indicates that there is a street l... | {"functional": "def check(candidate):\n assert candidate(lights = [[-3,2],[1,2],[3,3]]) == -1\n assert candidate(lights = [[1,0],[0,1]]) == 1\n assert candidate(lights = [[1,2]]) == -1\n\n\ncheck(Solution().brightestPosition)"} | coding | 170 |
Solve the programming task below in a Python markdown code block.
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that p_{i} = i.
Your task is ... | {"inputs": ["4 1\n", "4 2\n", "5 3\n", "5 4\n", "4 4\n", "4 4\n", "5 2\n", "8 3\n"], "outputs": ["1\n", "7\n", "31\n", "76\n", "24\n", "24\n", "11\n", "141\n"]} | coding | 182 |
Solve the programming task below in a Python markdown code block.
In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.
NOTE: String letters are case... | {"inputs": ["ABCDCDC\nCDC\n"], "outputs": ["2\n"]} | coding | 292 |
Solve the programming task below in a Python markdown code block.
Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time.
The m... | {"inputs": ["5\n0 1\n1 1\n2 1\n1 3\n4 6"], "outputs": ["0\n1\n4\n5\n46"]} | coding | 742 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions.
Given the grid grid represented as a string ar... | {"functional": "def check(candidate):\n assert candidate(grid = [\" /\",\"/ \"]) == 2\n assert candidate(grid = [\" /\",\" \"]) == 1\n assert candidate(grid = [\"/\\\\\",\"\\\\/\"]) == 5\n\n\ncheck(Solution().regionsBySlashes)"} | coding | 124 |
Solve the programming task below in a Python markdown code block.
Compare given two sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}$ lexicographically.
Constraints
* $1 \leq n, m \leq 1,000$
* $0 \leq a_i, b_i \leq 1,000$
Input
The input is given in the following format.
$n$
$a_0 \;... | {"inputs": ["3\n1 4 3\n2\n2 4", "3\n1 4 3\n2\n2 2", "3\n1 4 3\n3\n2 2", "3\n1 4 3\n3\n2 1", "3\n1 4 3\n6\n2 1", "3\n1 4 5\n6\n2 1", "3\n1 4 8\n6\n2 1", "3\n1 4 8\n6\n4 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
The kingdom of Lazyland is the home to $n$ idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland.
Today $k$ important jobs for the kingdom ($k \le n$) should be performed. Every job should be done... | {"inputs": ["2 1\n1 1\n7 13\n", "2 2\n2 2\n7 13\n", "2 1\n1 1\n7 13\n", "2 2\n2 2\n7 13\n", "2 1\n1 1\n6 13\n", "2 2\n2 2\n7 12\n", "2 2\n1 2\n7 12\n", "2 1\n1 1\n6 11\n"], "outputs": ["0\n", "7\n", "0", "7", "0\n", "7\n", "0\n", "0\n"]} | coding | 523 |
Solve the programming task below in a Python markdown code block.
You are given an integer N.
Construct any permutation A of N integers such that the value LCM(1 + A_{1} , 2 + A_{2}, \ldots, N + A_{N}) is minimised.
Note:
LCM denotes the [least common multiple] of the integers.
A permutation of N integers contains ... | {"inputs": ["1\n2\n"], "outputs": ["2 1 \n"]} | coding | 286 |
Solve the programming task below in a Python markdown code block.
We have an N \times N square grid.
We will paint each square in the grid either black or white.
If we paint exactly A squares white, how many squares will be painted black?
-----Constraints-----
- 1 \leq N \leq 100
- 0 \leq A \leq N^2
-----Inputs----... | {"inputs": ["3\n2", "3\n3", "3\n0", "3\n1", "3\n6", "3\n5", "3\n7", "3\n9"], "outputs": ["7\n", "6\n", "9\n", "8\n", "3\n", "4\n", "2\n", "0\n"]} | coding | 163 |
Solve the programming task below in a Python markdown code block.
Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: $1$, $4$, $8$, $9$, ....
For a given number $n$, count the number of integers from $1$ to $n$ that Polycarp likes. In other words, find the... | {"inputs": ["1\n8\n", "1\n64\n", "1\n26\n", "1\n65\n", "1\n49\n", "1\n26\n", "1\n49\n", "1\n64\n"], "outputs": ["3\n", "10\n", "6\n", "10\n", "9\n", "6\n", "9\n", "10\n"]} | coding | 296 |
Solve the programming task below in a Python markdown code block.
There are $n$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $1$ to $n$.
Two fairs are currently taking place in B... | {"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n4 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 4 1\... | coding | 696 |
Solve the programming task below in a Python markdown code block.
Your task is to make function, which returns the sum of a sequence of integers.
The sequence is defined by 3 non-negative values: **begin**, **end**, **step**.
If **begin** value is greater than the **end**, function should returns **0**
*Examples*
~... | {"functional": "_inputs = [[2, 6, 2], [1, 5, 1], [1, 5, 3], [0, 15, 3], [16, 15, 3], [2, 24, 22], [2, 2, 2], [2, 2, 1], [1, 15, 3], [15, 1, 3]]\n_outputs = [[12], [15], [5], [45], [0], [26], [2], [2], [35], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r... | coding | 161 |
Solve the programming task below in a Python markdown code block.
The mayor of your city has decided to throw a party to gather the favour of his people in different regions of the city.
There are 3 distinct regions in the city namely A, B, C comprising of P_{A}, P_{B} and P_{C} number of people respectively.
Howev... | {"inputs": ["3\n2 3 4\n1 5 2\n8 8 8\n"], "outputs": ["6\n5\n16\n"]} | coding | 384 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [startrow, startcol] indicates that initially, a robot is... | {"functional": "def check(candidate):\n assert candidate(startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7]) == 18\n assert candidate(startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26]) == 0\n\n\ncheck(Solution().minCost)"} | coding | 306 |
Solve the programming task below in a Python markdown code block.
You are given a range of positive integers from $l$ to $r$.
Find such a pair of integers $(x, y)$ that $l \le x, y \le r$, $x \ne y$ and $x$ divides $y$.
If there are multiple answers, print any of them.
You are also asked to answer $T$ independent qu... | {"inputs": ["1\n746 100000100\n", "3\n1 10\n3 14\n1 10\n", "3\n1 10\n3 14\n1 10\n", "3\n1 10\n5 14\n1 10\n", "3\n1 10\n9 20\n1 14\n", "3\n1 10\n3 10\n1 10\n", "3\n1 10\n5 14\n1 15\n", "3\n1 10\n5 14\n1 14\n"], "outputs": ["746 1492\n", "1 2\n3 6\n1 2\n", "1 2\n3 6\n1 2\n", "1 2\n5 10\n1 2\n", "1 2\n9 18\n1 2\n", "1 2\n... | coding | 312 |
Solve the programming task below in a Python markdown code block.
An array $[b_1, b_2, \ldots, b_m]$ is a palindrome, if $b_i = b_{m+1-i}$ for each $i$ from $1$ to $m$. Empty array is also a palindrome.
An array is called kalindrome, if the following condition holds:
It's possible to select some integer $x$ and delet... | {"inputs": ["4\n1\n1\n2\n1 2\n3\n1 2 3\n5\n1 4 4 1 4\n"], "outputs": ["YES\nYES\nNO\nYES\n"]} | coding | 659 |
Solve the programming task below in a Python markdown code block.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the ... | {"inputs": ["6 2 1", "5 3 1", "5 3 2", "3 2 0", "7 2 1", "2 2 1", "7 3 2", "5 4 2"], "outputs": ["12\n", "144\n", "216\n", "2\n", "14\n", "4\n", "1488\n", "972\n"]} | coding | 283 |
Solve the programming task below in a Python markdown code block.
You will be given a string and you task is to check if it is possible to convert that string into a palindrome by removing a single character. If the string is already a palindrome, return `"OK"`. If it is not, and we can convert it to a palindrome by re... | {"functional": "_inputs = [['abba'], ['abbaa'], ['abbaab'], ['madmam'], ['raydarm'], ['hannah'], ['baba'], ['babab'], ['bababa'], ['abcbad'], ['abcdba'], ['dabcba'], ['abededba'], ['abdcdeba'], ['abcdedba'], ['abbcdedba']]\n_outputs = [['OK'], ['remove one'], ['not possible'], ['remove one'], ['not possible'], ['OK'], ... | coding | 237 |
Solve the programming task below in a Python markdown code block.
Finally, College has started calling students back to campus. There are so many students and thus due to some safety measures the college can’t call back all the students on the same day. It currently has the capacity of screening K students on a single ... | {"inputs": ["3\n3 3\n3 2\n4 3\n"], "outputs": ["1\n2\n2\n"]} | coding | 475 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Alok-nath is man of equality. He needs your help to divide his “sanskars” evenly amongst all his followers. By doing this, Alok-nath can create equality amongst his followers and he'll be calle... | {"inputs": ["2\n5 3\n1 2 4 5 6\n5 3\n1 2 4 5 7", "2\n5 3\n1 2 4 4 6\n5 3\n1 2 4 5 7", "2\n1 3\n0 2 6 4 6\n5 3\n1 2 0 1 2", "2\n5 3\n1 2 5 4 6\n5 3\n1 2 4 5 8", "2\n5 3\n1 2 4 4 6\n5 3\n1 2 0 5 7", "2\n5 3\n1 2 4 4 6\n5 3\n0 2 0 5 7", "2\n1 3\n1 2 4 4 6\n5 3\n0 2 0 5 7", "2\n1 3\n1 2 4 4 6\n5 3\n1 2 0 5 7"], "outputs": ... | coding | 450 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
For example, The integer 5 is "101" in binary and its complement is "010" whic... | {"functional": "def check(candidate):\n assert candidate(num = 5) == 2\n assert candidate(num = 1) == 0\n\n\ncheck(Solution().findComplement)"} | coding | 125 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an array of numbers and a number `n`, and your task will be to determine if `any` array elements, when summed (or taken individually), are divisible by `n`.
For example:
* `solve([1,3,4,7,6],9) == true`, because `3 + ... | {"functional": "_inputs = [[[1, 2, 3, 4, 5], 8], [[7, 2, 8, 5], 16], [[1, 2, 3, 4, 5], 10], [[3, 1, 5, 7], 14], [[1, 2, 3, 4, 5], 15], [[8, 5, 3, 9], 7], [[8, 5, 3], 7]]\n_outputs = [[True], [False], [True], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is... | coding | 296 |
Solve the programming task below in a Python markdown code block.
Make a function **"add"** that will be able to sum elements of **list** continuously and return a new list of sums.
For example:
```
add [1,2,3,4,5] == [1, 3, 6, 10, 15], because it's calculated like
this : [1, 1 + 2, 1 + 2 + 3, 1 + 2 + 3 + 4, 1 + 2 ... | {"functional": "_inputs = [[[5, 10, 15, 20, 25, 30, 35, 40]], [[6, 12, 18, 24, 30, 36, 42]], [[7, 14, 21, 28, 35, 42, 49, 56]], [[8, 16, 24, 32, 40, 48, 56, 64]], [[9, 18, 27, 36, 45, 54]]]\n_outputs = [[[5, 15, 30, 50, 75, 105, 140, 180]], [[6, 18, 36, 60, 90, 126, 168]], [[7, 21, 42, 70, 105, 147, 196, 252]], [[8, 24... | coding | 169 |
Solve the programming task below in a Python markdown code block.
Your task is to calculate the number of arrays such that: each array contains $n$ elements; each element is an integer from $1$ to $m$; for each array, there is exactly one pair of equal elements; for each array $a$, there exists an index $i$ such th... | {"inputs": ["3 4\n", "3 5\n", "2 2\n", "3 3\n", "2 3\n", "3 3\n", "2 2\n", "2 3\n"], "outputs": ["6\n", "10\n", "0\n", "3\n", "0\n", "3\n", "0\n", "0\n"]} | coding | 371 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a string s of lowercase letters, these letters form consecutive groups of the same character.
For example, a string like s = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z", and "yy".
A group is identified by an... | {"functional": "def check(candidate):\n assert candidate(s = \"abbxxxxzzy\") == [[3,6]]\n assert candidate(s = \"abc\") == []\n assert candidate(s = \"abcdddeeeeaabbbcd\") == [[3,5],[6,9],[12,14]]\n assert candidate(s = \"aba\") == []\n\n\ncheck(Solution().largeGroupPositions)"} | coding | 191 |
Solve the programming task below in a Python markdown code block.
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
Constraints
* 2 \leq N \leq 10^5
* 1 \leq A_i \leq... | {"inputs": ["3\n5\n6\n1", "3\n5\n3\n1", "3\n0\n3\n1", "3\n0\n0\n1", "3\n0\n0\n0", "3\n5\n5\n1", "3\n-1\n0\n1", "3\n-1\n1\n1"], "outputs": ["9\n", "6\n", "5\n", "2\n", "0\n", "8", "3\n", "4\n"]} | coding | 204 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given an integer $C$. Let $d$ be the smallest integer such that $2^{d}$ is strictly greater than $C$.
Consider all pairs of non-negative integers $(A... | {"inputs": ["2\n13\n10"], "outputs": ["70\n91"]} | coding | 452 |
Solve the programming task below in a Python markdown code block.
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?
Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't ... | {"inputs": ["1\n3\n2 2 1\n", "1\n3\n2 2 0\n", "1\n3\n4 2 0\n", "1\n3\n3 2 0\n", "1\n3\n4 3 0\n", "1\n3\n0 2 0\n", "1\n3\n0 2 1\n", "1\n3\n2 2 2\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | coding | 598 |
Solve the programming task below in a Python markdown code block.
You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of th... | {"inputs": ["6 1\n13\n5\n7\n15\n13\n7\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 6\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 11 12 13\n5 15 3 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 8 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 11 12 13\n5 15 11 6 ... | coding | 397 |
Solve the programming task below in a Python markdown code block.
Guy-Manuel and Thomas have an array $a$ of $n$ integers [$a_1, a_2, \dots, a_n$]. In one step they can add $1$ to any element of the array. Formally, in one step they can choose any integer index $i$ ($1 \le i \le n$) and do $a_i := a_i + 1$.
If either ... | {"inputs": ["1\n1\n0\n", "1\n1\n0\n", "4\n3\n2 -1 -1\n4\n-1 0 0 1\n2\n-1 2\n3\n0 -2 1\n", "4\n3\n2 -1 -1\n4\n-2 0 0 1\n2\n-1 2\n3\n0 -2 1\n", "4\n3\n2 -1 -1\n4\n-1 0 0 1\n2\n-1 2\n3\n0 -2 1\n", "1\n50\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -98\n", "1\n50\n2 2 ... | coding | 635 |
Solve the programming task below in a Python markdown code block.
Suppose there is a X x Y x Z 3D matrix A of numbers having coordinates (i, j, k) where 0 ≤ i < X, 0 ≤ j < Y, 0 ≤ k < Z. Now another X x Y x Z matrix B is defined from A such that the (i, j, k) element of B is the sum of all the the numbers in A in the cu... | {"inputs": ["2\n3 1 1\n1 \n8 \n22 \n1 2 3\n0 9 13 \n18 45 51", "2\n3 1 1\n1 \n8 \n22 \n1 2 3\n0 9 13 \n18 45 51"], "outputs": ["1 \n7 \n14 \n0 9 4 \n18 18 2", "1 \n7 \n14 \n0 9 4 \n18 18 2"]} | coding | 484 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of unique palindromes of length three that are a subsequence of s.
Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.
A palindr... | {"functional": "def check(candidate):\n assert candidate(s = \"aabca\") == 3\n assert candidate(s = \"adc\") == 0\n assert candidate(s = \"bbcbaba\") == 4\n\n\ncheck(Solution().countPalindromicSubsequence)"} | coding | 161 |
Solve the programming task below in a Python markdown code block.
King loves to go on tours with his friends.
King has N cars that can seat 5 people each and M cars that can seat 7 people each. Determine the maximum number of people that can travel together in these cars.
------ Input Format ------
- The first line... | {"inputs": ["4\n4 8\n2 13\n14 5\n8 8"], "outputs": ["76\n101\n105\n96"]} | coding | 442 |
Solve the programming task below in a Python markdown code block.
Notes
Template in C
Constraints
* 1 ≤ n ≤ 100000
* 1 ≤ q ≤ 1000
* 1 ≤ timei ≤ 50000
* 1 ≤ length of namei ≤ 10
* 1 ≤ Sum of timei ≤ 1000000
Input
n q
name1 time1
name2 time2
...
namen timen
In the first line the number of processes n and the quant... | {"inputs": ["5 100\np1 54\n2p 80\n3p 200\np4 350\np5 14", "5 100\np1 54\n2p 80\n3p 200\n4p 350\np5 14", "4 100\np1 150\np2 80\np3 240\n4p 350\np5 8", "2 100\np1 54\n2p 80\n3p 200\n4p 350\np5 14", "4 100\np1 150\no2 80\np3 240\n4p 350\np5 8", "4 101\np1 150\no2 80\np3 240\n4p 350\np4 8", "4 101\n1p 150\no2 80\np3 240\n4... | coding | 259 |
Solve the programming task below in a Python markdown code block.
# Summation Of Primes
The sum of the primes below or equal to 10 is **2 + 3 + 5 + 7 = 17**. Find the sum of all the primes **_below or equal to the number passed in_**.
From Project Euler's [Problem #10](https://projecteuler.net/problem=10 "Project Eul... | {"functional": "_inputs = [[5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [100], [200], [300], [400], [500], [1000], [2000], [3000], [4000], [5000], [25000]]\n_outputs = [[10], [10], [17], [17], [17], [17], [77], [129], [197], [328], [1060], [4227], [8275], [13887], [21536], [76127], [277050], [593823], [101350... | coding | 125 |
Solve the programming task below in a Python markdown code block.
This is a follow up from my kata The old switcheroo
Write
```python
def encode(str)
```
that takes in a string ```str``` and replaces all the letters with their respective positions in the English alphabet.
```python
encode('abc') == '123' # a is 1st... | {"functional": "_inputs = [['abc'], ['ABCD'], ['ZzzzZ'], ['abc-#@5'], ['this is a long string!! Please [encode] @C0RrEctly']]\n_outputs = [['123'], ['1234'], ['2626262626'], ['123-#@5'], ['208919 919 1 1215147 1920189147!! 161251195 [51431545] @30181853201225']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins... | coding | 162 |
Solve the programming task below in a Python markdown code block.
Write a function that takes an integer and returns an array `[A, B, C]`, where `A` is the number of multiples of 3 (but not 5) below the given integer, `B` is the number of multiples of 5 (but not 3) below the given integer and `C` is the number of multi... | {"functional": "_inputs = [[20], [2020], [4], [2], [30], [300], [14], [141], [1415], [91415]]\n_outputs = [[[5, 2, 1]], [[539, 269, 134]], [[1, 0, 0]], [[0, 0, 0]], [[8, 4, 1]], [[80, 40, 19]], [[4, 2, 0]], [[37, 19, 9]], [[377, 188, 94]], [[24377, 12188, 6094]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isin... | coding | 186 |
Solve the programming task below in a Python markdown code block.
In a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them.
Chef and Cook are playing a different match — they decided that the player who serves would change every time af... | {"inputs": ["3\n1 3 2\n0 3 2\n34 55 2"], "outputs": ["CHEF\nCOOK\nCHEF"]} | coding | 370 |
Solve the programming task below in a Python markdown code block.
Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions ... | {"inputs": ["1 1 2\n1\n2\n", "1 1 1\n1\n1\n", "2 2 1\n1 2\n1 2\n", "2 2 1\n1 2\n2 1\n", "2 2 1\n1 2\n4 1\n", "2 2 1\n1 1\n4 1\n", "2 2 1\n2 1\n4 1\n", "2 2 1\n2 1\n4 2\n"], "outputs": ["0\n", "1\n1 ", "1\n1 ", "1\n1 ", "0\n", "0\n", "0\n", "0\n"]} | coding | 341 |
Solve the programming task below in a Python markdown code block.
For a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ which is sorted by ascending order, eliminate all equivalent elements.
Constraints
* $1 \leq n \leq 100,000$
* $-1000,000,000 \leq a_i \leq 1,000,000,000$
* $a_0 \leq a_1 \leq ... \leq a_{n-... | {"inputs": ["4\n0 2 2 4", "4\n0 2 2 3", "4\n0 2 2 2", "4\n0 1 2 2", "4\n0 0 0 4", "4\n0 0 1 4", "4\n1 2 2 3", "4\n0 0 2 8"], "outputs": ["0 2 4\n", "0 2 3\n", "0 2\n", "0 1 2\n", "0 4\n", "0 1 4\n", "1 2 3\n", "0 2 8\n"]} | coding | 211 |
Solve the programming task below in a Python markdown code block.
Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into sec... | {"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]} | coding | 367 |
Solve the programming task below in a Python markdown code block.
Chef is eagerly waiting for a piece of information. His secret agent told him that this information would be revealed to him after K weeks.
X days have already passed and Chef is getting restless now. Find the number of remaining days Chef has to wait f... | {"inputs": ["4\n1 5\n1 6\n1 1\n1 2"], "outputs": ["2\n1\n6\n5\n"]} | coding | 475 |
Solve the programming task below in a Python markdown code block.
There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):
* Person S_i does one of the following... | {"inputs": ["3\n2\n1 2\n14\n0\n0 0\n9\n6\n2 6 9 3 7 7\n011000", "3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 9 6 7\n111000", "3\n2\n0 2\n10\n2\n1 1\n10\n6\n2 3 4 9 6 7\n111000", "3\n2\n1 2\n10\n2\n1 2\n10\n6\n2 3 1 9 6 7\n111000", "3\n2\n1 2\n14\n0\n2 0\n10\n6\n2 3 5 9 7 7\n111000", "3\n2\n0 2\n10\n2\n1 2\n10\n6\n2 3 1 9 2 7\n... | coding | 387 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.