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.
A single car can accommodate at most 4 people.
N friends want to go to a restaurant for a party. Find the minimum number of cars required to accommodate all the friends.
------ Input Format ------
- The first line contains a single integer T - the nu... | {"inputs": ["4\n4\n2\n7\n98\n"], "outputs": ["1\n1\n2\n25\n"]} | coding | 285 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.
For every unique integer target in nums, count the number of times target immediately follows an occurrence of... | {"functional": "def check(candidate):\n assert candidate(nums = [1,100,200,1,100], key = 1) == 100\n assert candidate(nums = [2,2,2,2,3], key = 2) == 2\n\n\ncheck(Solution().mostFrequent)"} | coding | 165 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, the depth of each node is the shortest distance to the root.
Return the smallest subtree such that it contains all the deepest nodes in the original tree.
A node is called the deepest ... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([3,5,1,6,2,0,8,None,None,7,4])), tree_node([2,7,4]))\n assert is_same_tree(candidate(root = tree_node([1])), tree_node([1]))\n assert is_same_tree(candidate(root = tree_node([0,1,3,None,2])), tree_node([2]))\n\n\ncheck(Solut... | coding | 185 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).
You are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] ... | {"functional": "def check(candidate):\n assert candidate(trips = [[2,1,5],[3,3,7]], capacity = 4) == False\n assert candidate(trips = [[2,1,5],[3,3,7]], capacity = 5) == True\n\n\ncheck(Solution().carPooling)"} | coding | 176 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.
Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes m... | {"functional": "def check(candidate):\n assert candidate(satisfaction = [-1,-8,0,5,-9]) == 14\n assert candidate(satisfaction = [4,3,2]) == 20\n assert candidate(satisfaction = [-1,-4,-5]) == 0\n\n\ncheck(Solution().maxSatisfaction)"} | coding | 150 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.
A subarray is a contiguous part of an array.
Please complete the following python code precisely... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,0,-2,-3,1], k = 5) == 7\n\n\ncheck(Solution().subarraysDivByK)"} | coding | 92 |
Solve the programming task below in a Python markdown code block.
There are two types of vehicles in Chefland.
Bus which has a capacity of 100 people.
Car which has a capacity of 4 people.
There are N people who want to travel from place A to place B. You know that a single bus emits X units of smoke while a single ca... | {"inputs": ["3\n9 40 8\n15 20 20\n105 80 10\n"], "outputs": ["24\n20\n100\n"]} | coding | 488 |
Solve the programming task below in a Python markdown code block.
There are $X$ people participating in a quiz competition and their IDs have been numbered from $1$ to $X$ (both inclusive). Beth needs to form a team among these $X$ participants. She has been given an integer $Y$. She can choose participants whose ID nu... | {"inputs": ["2\n10 3\n15 5"], "outputs": ["18\n10"]} | coding | 302 |
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"]} | coding | 560 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.
Please complete the following python code precisely:
```python
class So... | {"functional": "def check(candidate):\n assert candidate(grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]) == 8\n assert candidate(grid = [[3,2],[1,0]]) == 0\n\n\ncheck(Solution().countNegatives)"} | coding | 81 |
Solve the programming task below in a Python markdown code block.
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer ... | {"inputs": ["5 5\n0 1 4\n0 2 3\n1 0 1\n1 3 4\n1 0 4\n1 2 2\n1 1 3\n1 1 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0", "5 8\n0 1 4\n0 2 1\n1 1 2\n1 3 4\n1 1 4\n1 3 0\n0 1 3\n1 2 4\n1 3 0\n1 0 4\n1 0 2\n1 3 0", "5 12\n0 2 4\n0 2 3\n1 1 2\n1 3 4\n1 1 4\n1 3 2\n0 1 3\n1 2 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0", "5 12\n0 1 4\n0 2 3\n1 1 2\n1 3 4\... | coding | 367 |
Solve the programming task below in a Python markdown code block.
For a [permutation] P of the integers 1 to N, we define a new array A_{P} of length N-2 as follows:
For 1 ≤ i ≤ N-2, (A_{P})_i denotes the number of [inversions] in the subarray P[i : i+2], i.e, the number of inversions in the array [P_{i}, P_{i+1}, P_{... | {"inputs": ["4\n4\n0 1 3 2\n4\n0 1 2 3\n4\n0 0 0 0\n5\n0 1 2 1 0"], "outputs": ["YES\nNO\nYES\nNO"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
Your dad doesn't really *get* punctuation, and he's always putting extra commas in when he posts. You can tolerate the run-on sentences, as he does actually talk like that, but those extra commas have to go!
Write a function called ```dadFilter``` that ... | {"functional": "_inputs = [['all this,,,, used to be trees,,,,,,'], ['Listen,,,, kid,,,,,,'], ['Luke,,,,,,,,, I am your father,,,,,,,,, '], [\"i,, don't believe this round earth,,, show me evadence!!\"], [\"Dead or alive,,,, you're coming with me,,, \"]]\n_outputs = [['all this, used to be trees'], ['Listen, kid'], ... | coding | 119 |
Solve the programming task below in a Python markdown code block.
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly $\frac{n}{k}$ time... | {"inputs": ["1 1\n2\n", "1 1\n2\n", "1 1\n1\n", "2 1\n1 1\n", "2 2\n2 2\n", "2 1\n1 2\n", "2 2\n2 1\n", "2 2\n2 2\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "1\n", "0\n", "0"]} | coding | 575 |
Solve the programming task below in a Python markdown code block.
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could hav... | {"inputs": ["2\n1 1\n", "2\n2 1\n", "2\n1 0\n", "2\n2 0\n", "2\n2 2\n", "2\n0 0\n", "2\n1 2\n", "3\n1 3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 388 |
Solve the programming task below in a Python markdown code block.
Given an `x` and `y` find the smallest and greatest numbers **above** and **below** a given `n` that are divisible by both `x` and `y`.
### Examples
```python
greatest(2, 3, 20) => 18 # 18 is the greatest number under 20 that is divisible by both 2 an... | {"functional": "_inputs = [[2, 3, 20], [13, 17, 100], [10, 100, 100], [1000000007, 1000000009, 10000000000000000000]]\n_outputs = [[18], [0], [0], [9000000144000000567]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_... | coding | 423 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n points on a 2D plane, find if there is such a line parallel to the y-axis that reflects the given points symmetrically.
In other words, answer whether or not if there exists a line that after reflecting all po... | {"functional": "def check(candidate):\n assert candidate(points = [[1,1],[-1,1]]) == True\n assert candidate(points = [[1,1],[-1,-1]]) == False\n\n\ncheck(Solution().isReflected)"} | coding | 124 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.
You are given an m x n matrix mat and two integers r and c re... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,2],[3,4]], r = 1, c = 4) == [[1,2,3,4]]\n assert candidate(mat = [[1,2],[3,4]], r = 2, c = 4) == [[1,2],[3,4]]\n\n\ncheck(Solution().matrixReshape)"} | coding | 179 |
Solve the programming task below in a Python markdown code block.
You have to write two methods to *encrypt* and *decrypt* strings.
Both methods have two parameters:
```
1. The string to encrypt/decrypt
2. The Qwerty-Encryption-Key (000-999)
```
The rules are very easy:
```
The crypting-regions are these 3 lines from... | {"functional": "_inputs = [['A', 111], ['Abc', 212], ['Ball', 134], ['Ball', 444], ['This is a test.', 348], ['Do the kata Kobayashi Maru Test. Endless fun and excitement when finding a solution.', 583]]\n_outputs = [['S'], ['Smb'], ['>fdd'], ['>gff'], ['Iaqh qh g iyhi,'], ['Sr pgi jlpl Jr,lqlage Zlow Piapc I.skiaa dw.... | coding | 635 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an even integer n. You initially have a permutation perm of size n where perm[i] == i (0-indexed).
In one operation, you will create a new array arr, and for each i:
If i % 2 == 0, then arr... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 1\n assert candidate(n = 4) == 2\n assert candidate(n = 6) == 4\n\n\ncheck(Solution().reinitializePermutation)"} | coding | 185 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a message channel between servers ui and vi, and they can pass any number ... | {"functional": "def check(candidate):\n assert candidate(edges = [[0,1],[1,2]], patience = [0,2,1]) == 8\n assert candidate(edges = [[0,1],[0,2],[1,2]], patience = [0,10,10]) == 3\n\n\ncheck(Solution().networkBecomesIdle)"} | coding | 416 |
Solve the programming task below in a Python markdown code block.
Given a sequence A of length N, the weight of this sequence is defined as
\text{weight}(A) = \sum_{i = 1}^{N} i\cdot A_{i}
Given an integer N, we pick a permutation A of [1, 2 \dots N] uniformly at random. What is the expected weight of this permutatio... | {"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n499122181\n12\n"]} | coding | 634 |
Solve the programming task below in a Python markdown code block.
How many bees are in the beehive?
* bees can be facing UP, DOWN, LEFT, or RIGHT
* bees can share parts of other bees
Examples
Ex1
```
bee.bee
.e..e..
.b..eeb
```
*Answer: 5*
Ex2
```
bee.bee
e.e.e.e
eeb.eeb
```
*Answer: 8*
# Notes
* The ... | {"functional": "_inputs = [[None]]\n_outputs = [[0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_e... | coding | 162 |
Solve the programming task below in a Python markdown code block.
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many ... | {"inputs": ["8\n", "1\n", "9\n", "5\n", "2\n", "6\n", "4\n", "3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 275 |
Solve the programming task below in a Python markdown code block.
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following restrictions are set:
* In each row at most two different colours c... | {"inputs": ["1 1\nq\n", "1 2\njj\n", "2 1\ns\ns\n", "2 1\nr\ns\n", "2 2\nab\nab\n", "2 2\naa\nab\n", "2 2\naa\nba\n", "2 2\nac\nab\n"], "outputs": ["0\nq\n", "1\naj\n", "1\ns\na\n", "0\nr\ns\n", "2\nba\nab\n", "1\nba\nab\n", "1\nab\nba\n", "1\nbc\nab\n"]} | coding | 406 |
Solve the programming task below in a Python markdown code block.
The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per s... | {"inputs": ["6 3\n1\n6\n201449\n16\n7\n60700\n7", "6 3\n1\n6\n201449\n18\n7\n60700\n7", "7 3\n1\n34\n966369\n7\n9\n40177\n11", "7 3\n1\n62\n334284\n16\n7\n60700\n7", "6 3\n1\n62\n201449\n16\n7\n60700\n7", "6 1\n1\n62\n190402\n16\n6\n60700\n7", "6 3\n1\n62\n334284\n16\n7\n60700\n7", "6 3\n1\n62\n201449\n16\n6\n60700\n7"... | coding | 171 |
Solve the programming task below in a Python markdown code block.
## Task
You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input.
## Example
For `arr = [1, 1, 1]... | {"functional": "_inputs = [[[1, 1, 1]], [[-1000, 0, -2, 0]], [[2, 1, 10, 1]], [[2, 3, 3, 5, 5, 5, 4, 12, 12, 10, 15]]]\n_outputs = [[3], [5], [12], [13]]\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... | coding | 203 |
Solve the programming task below in a Python markdown code block.
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after x is the smallest prime number greater than x. For example, the next prime numbe... | {"inputs": ["2 6\n", "7 8\n", "5 9\n", "2 3\n", "3 7\n", "3 9\n", "5 6\n", "5 7\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n"]} | coding | 400 |
Solve the programming task below in a Python markdown code block.
Problem statement
AOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is.... | {"inputs": ["5 3 6 9\n9 1 5 3 1", "5 3 6 9\n9 1 6 3 1", "8 3 6 9\n9 1 6 3 1", "2 3 6 9\n9 7 5 3 1", "5 3 6 8\n9 1 5 3 1", "5 3 6 9\n9 7 5 3 1", "9 3 1 9\n22 2 6 2 0", "8 3 6 9\n15 1 6 3 1"], "outputs": ["1\n", "1\n", "1\n", "0\n", "1\n", "2", "4\n", "1\n"]} | coding | 707 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
There are $N$ circles in a plane. Circle $i$ and circle $j$ form a *good pair* if it is possible to choose a point $P_{1}$ on the perimeter of circle ... | {"inputs": ["2 3\n0 0 5\n8 3 2\n0\n10\n20"], "outputs": ["0\n1\n0"]} | coding | 601 |
Solve the programming task below in a Python markdown code block.
Dima got into number sequences. Now he's got sequence a_1, a_2, ..., a_{n}, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2·x) = f(x); f(2·x + 1) = f(x) + 1.
Di... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n7\n", "2\n1 1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
You are given an array A containing N integers. A [subsequence] of this array is called *good* if all the elements of this subsequence are distinct.
Find the number of *good* non-empty subsequences of A. This number can be large, so report it modulo 10^... | {"inputs": ["2\n2\n1 1\n2\n1 2\n"], "outputs": ["2\n3\n"]} | coding | 434 |
Solve the programming task below in a Python markdown code block.
Bob has received a binary string of length N transmitted by Alice. He knows that due to errors in transmission, up to K bits might have been corrupted (and hence flipped). However, he also knows that the string Alice had intended to transmit was not peri... | {"inputs": ["3 \n5 0 \n00000 \n3 1 \n001 \n3 3 \n101\n"], "outputs": ["0\n3\n6\n"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
Two players (numbered $\mbox{1}$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows:
Player $\mbox{1}$ always moves first.
Initially there are $N$ towers of various heights.
The players move in alternating turns. In each... | {"inputs": ["2\n2 \n1 2\n3 \n1 2 3\n"], "outputs": ["1\n2\n"]} | coding | 534 |
Solve the programming task below in a Python markdown code block.
Problem
It seems that a magician with a smoky smell will show off his magic.
"Now, think of one favorite integer."
You decide to think of your counting years in your head.
The magician has thrown the query $ N $ times.
Each query is one of the followi... | {"inputs": ["3\n1 1\n1 6\n2 8", "3\n1 0\n1 7\n3 9", "3\n1 2\n1 6\n2 8", "3\n1 1\n1 7\n3 9", "3\n2 0\n1 3\n2 4", "3\n2 1\n1 3\n2 4", "3\n1 2\n2 8\n2 8", "3\n1 2\n2 8\n3 8"], "outputs": ["-8 6\n", "9 0\n", "-8 12\n", "9 7\n", "-4 3\n", "-7 3\n", "-16 2\n", "0 2\n"]} | coding | 576 |
Solve the programming task below in a Python markdown code block.
You are given two integers $x$ and $y$. You can perform two types of operations: Pay $a$ dollars and increase or decrease any of these integers by $1$. For example, if $x = 0$ and $y = 7$ there are four possible outcomes after this operation: $x = 0$... | {"inputs": ["1\n62 7\n2 4\n", "1\n62 7\n3 4\n", "1\n62 3\n3 4\n", "1\n62 3\n6 4\n", "1\n62 2\n6 4\n", "1\n62 2\n4 4\n", "1\n62 2\n7 4\n", "1\n35 2\n7 4\n"], "outputs": ["138\n", "193\n", "189\n", "366\n", "368\n", "248\n", "428\n", "239\n"]} | coding | 501 |
Solve the programming task below in a Python markdown code block.
Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.
He has very high awareness of safety, and decides to buy two bells, one for each hand.
The store sells three kinds of bells for the price of ... | {"inputs": ["6 1 66", "0 1 66", "1 1 34", "2 1 73", "0 0 25", "-2 0 3", "-4 1 6", "-5 4 1"], "outputs": ["7\n", "1\n", "2\n", "3\n", "0\n", "-2\n", "-3\n", "-4\n"]} | coding | 276 |
Solve the programming task below in a Python markdown code block.
Tsetso likes to play with arrays.
An Array A[1,2,\ldots,N] is said to be a Tsetso array if A[1] \cdot A[N] = max(A_{1},A_{2},\ldots,A_{N-1},A_{N}).
Bedo, his teammate, likes to solve problems so much, so Tsetso gave him an array A of N \bf{distinct} i... | {"inputs": ["1\n7 3\n3 6 24 4 1 8 2\n1 7\n2 5\n4 7"], "outputs": ["7\n4\n4"]} | coding | 648 |
Solve the programming task below in a Python markdown code block.
$n$ students are taking an exam. The highest possible score at this exam is $m$. Let $a_{i}$ be the score of the $i$-th student. You have access to the school database which stores the results of all students.
You can change each student's score as long... | {"inputs": ["2\n4 7\n1 4 0 4\n4 5\n1 1 3 4\n", "2\n4 8\n1 2 3 4\n4 1\n1 4 2 4\n", "2\n4 4\n1 3 3 3\n4 5\n1 2 4 4\n", "2\n4 2\n1 3 3 3\n4 5\n1 2 4 4\n", "2\n4 3\n1 2 5 0\n4 8\n1 2 3 4\n", "2\n4 9\n2 3 3 4\n4 5\n1 2 3 4\n", "2\n4 9\n2 3 3 4\n4 5\n1 2 3 7\n", "2\n4 7\n1 4 0 4\n4 5\n1 1 3 8\n"], "outputs": ["7\n5\n", "8\n1... | coding | 497 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.
Please complete the following python code precisely:
```python
class Solution:
def countNumbersWithUniqueDigits(self... | {"functional": "def check(candidate):\n assert candidate(n = 2) == 91\n assert candidate(n = 0) == 1\n\n\ncheck(Solution().countNumbersWithUniqueDigits)"} | coding | 78 |
Solve the programming task below in a Python markdown code block.
You are given a string of lower case letters. Your task is to figure out the index of the character on whose removal it will make the string a palindrome. There will always be a valid solution.
In case the string is already a palindrome, then -1 is also... | {"inputs": ["3\naaab\nbaa\naaa"], "outputs": ["3\n0\n-1"]} | coding | 313 |
Solve the programming task below in a Python markdown code block.
The country of Byteland contains N cities and N - 1 bidirectional roads between them such that there is a path between any two cities. The cities are numbered (0,...,N - 1). The people were very unhappy about the time it took to commute, especially sales... | {"inputs": ["2\n3\n0 1\n1 2\n5\n0 1\n1 2\n2 3\n2 4\n"], "outputs": ["2\n4\n"]} | coding | 408 |
Solve the programming task below in a Python markdown code block.
You are given a string S. Each character of S is uppercase or lowercase English letter.
Determine if S satisfies all of the following conditions:
- The initial character of S is an uppercase A.
- There is exactly one occurrence of C between the third c... | {"inputs": ["AaCa\n", "AtBoCo", "ACodes", "AtBnCo", "ACodds", "@tBnCo", "sddoCA", "oCnBt@"], "outputs": ["AC\n", "WA\n", "WA\n", "WA\n", "WA\n", "WA\n", "WA\n", "WA\n"]} | coding | 206 |
Solve the programming task below in a Python markdown code block.
You are given n integers a_1, a_2, …, a_n and an integer k. Find the maximum value of i ⋅ j - k ⋅ (a_i | a_j) over all pairs (i, j) of integers with 1 ≤ i < j ≤ n. Here, | is the [bitwise OR operator](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
... | {"inputs": ["1\n2 1\n2 2\n", "1\n2 1\n2 0\n", "1\n2 1\n0 0\n", "1\n2 1\n2 1\n", "1\n2 2\n2 2\n", "1\n2 1\n1 0\n", "1\n2 2\n2 1\n", "1\n2 2\n0 0\n"], "outputs": ["0\n", "0\n", "2\n", "-1\n", "-2\n", "1\n", "-4\n", "2\n"]} | coding | 546 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n matrix mat that has its rows sorted in non-decreasing order and an integer k.
You are allowed to choose exactly one element from each row to form an array.
Return the kth smallest array sum amon... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,3,11],[2,4,6]], k = 5) == 7\n assert candidate(mat = [[1,3,11],[2,4,6]], k = 9) == 17\n assert candidate(mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7) == 9\n assert candidate(mat = [[1,1,10],[2,2,9]], k = 7) == 12\n\n\ncheck(Solution().kthSmalle... | coding | 107 |
Solve the programming task below in a Python markdown code block.
Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the string "bobseesanna" can be created by some ways:
* bobseesanna = bob + sees + anna
* bobseesanna = bob + s + ee + s + anna
... | {"inputs": ["bobseesanna"], "outputs": ["18"]} | coding | 228 |
Solve the programming task below in a Python markdown code block.
The integers 14 and 15, are contiguous (1 the difference between them, obvious) and have the same number of divisors.
```python
14 ----> 1, 2, 7, 14 (4 divisors)
15 ----> 1, 3, 5, 15 (4 divisors)
```
The next pair of contiguous integers with this propert... | {"functional": "_inputs = [[1, 50], [3, 100], [3, 200], [6, 350], [6, 1000], [7, 1500], [7, 2500], [7, 3000], [9, 4000], [9, 5000], [11, 5000]]\n_outputs = [[8], [7], [18], [86], [214], [189], [309], [366], [487], [622], [567]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | coding | 488 |
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"]} | coding | 219 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:
Type-1: Remove the character at the start of the string s and append it to the end of the string.
Typ... | {"functional": "def check(candidate):\n assert candidate(s = \"111000\") == 2\n assert candidate(s = \"010\") == 0\n assert candidate(s = \"1110\") == 1\n\n\ncheck(Solution().minFlips)"} | coding | 194 |
Solve the programming task below in a Python markdown code block.
Chef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:
input: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]
output: inte... | {"inputs": ["2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4"], "outputs": ["0\n11"]} | coding | 474 |
Solve the programming task below in a Python markdown code block.
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.
Your task is to add spaces to the text by the fol... | {"inputs": ["x\n", "w\n", "y\n", "xx\n", "yx\n", "xy\n", "wy\n", "x,x\n"], "outputs": ["x\n", "w\n", "y\n", "xx\n", "yx\n", "xy\n", "wy\n", "x, x\n"]} | coding | 291 |
Solve the programming task below in a Python markdown code block.
Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs a_{i} rubles. Only one person can hang clothes on one hook.
Tonight Sere... | {"inputs": ["1 1\n1\n2\n", "1 1\n1\n1\n", "1 1\n1\n2\n", "1 1\n1\n1\n", "1 1\n2\n2\n", "1 2\n1\n2\n", "2 1\n2 1\n2\n", "2 1\n2 1\n2\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "1\n", "-1\n", "3\n", "3\n"]} | coding | 390 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A binary tree is named Even-Odd if it meets the following conditions:
The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
For every even-index... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,10,4,3,None,7,9,12,8,6,None,None,2])) == True\n assert candidate(root = tree_node([5,4,2,3,3,7])) == False\n assert candidate(root = tree_node([5,9,1,3,5,7])) == False\n assert candidate(root = tree_node([1])) == True\n assert c... | coding | 225 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.
You must write an algorithm that runs in linear ti... | {"functional": "def check(candidate):\n assert candidate(nums = [3,6,9,1]) == 3\n assert candidate(nums = [10]) == 0\n\n\ncheck(Solution().maximumGap)"} | coding | 96 |
Solve the programming task below in a Python markdown code block.
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two ... | {"inputs": ["2\n0 1\n1 -2\n", "2\n0 1\n1 -3\n", "2\n0 1\n1 -6\n", "2\n0 1\n1 -1\n", "3\n0 1\n1 2\n2 -2\n", "3\n0 1\n1 1\n2 -2\n", "3\n-1 1\n1 2\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n"]} | coding | 354 |
Solve the programming task below in a Python markdown code block.
To celebrate today's launch of my Hero's new book: Alan Partridge: Nomad, We have a new series of kata arranged around the great man himself.
Given an array of terms, if any of those terms relate to Alan Partridge, return Mine's a Pint!
The number of !... | {"functional": "_inputs = [[['Grouse', 'Partridge', 'Pheasant']], [['Pheasant', 'Goose', 'Starling', 'Robin']], [['Grouse', 'Partridge', 'Partridge', 'Partridge', 'Pheasant']], [[]], [['Grouse', 'Partridge', 'Pheasant', 'Goose', 'Starling', 'Robin', 'Thrush', 'Emu', 'PearTree', 'Chat', 'Dan', 'Square', 'Toblerone', 'Ly... | coding | 200 |
Solve the programming task below in a Python markdown code block.
For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ i... | {"inputs": ["7\n1 0\n0 1\n0 3\n0 0\n1 0\n0 7\n1 0", "7\n1 0\n0 1\n1 2\n0 0\n1 0\n0 7\n1 0", "7\n0 0\n0 2\n0 3\n0 2\n0 4\n0 3\n1 4", "7\n1 0\n0 1\n0 2\n0 0\n1 0\n1 7\n1 0", "7\n0 2\n0 2\n0 1\n0 0\n1 4\n1 3\n0 0", "7\n0 0\n1 3\n1 0\n0 0\n0 4\n1 3\n1 9", "7\n1 0\n0 2\n1 2\n0 0\n1 0\n0 7\n1 0", "7\n0 0\n0 2\n0 1\n0 0\n0 0\... | coding | 286 |
Solve the programming task below in a Python markdown code block.
Han Solo and Chewbacca start a space journey to planet Naboo on the Millennium Falcon. During the journey they land at a mysterious planet with high gravity where they find n diamond stones scattered all around. All the stones are of same weight. Each st... | {"inputs": ["7\n1 2 3 4 5 6 7"], "outputs": ["1 2 4 7\n3 5 6"]} | coding | 431 |
Solve the programming task below in a Python markdown code block.
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob.
The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The... | {"inputs": ["3\n5\n3 1 3 3 4\n1 6 2 5 3\n5\n1 6 2 5 3\n3 1 3 3 4\n3\n4 1 3\n2 2 7"], "outputs": ["Alice\nBob\nDraw"]} | coding | 710 |
Solve the programming task below in a Python markdown code block.
We have a string S of length N consisting of A, T, C, and G.
Strings T_1 and T_2 of the same length are said to be complementary when, for every i (1 \leq i \leq l), the i-th character of T_1 and the i-th character of T_2 are complementary. Here, A and T... | {"inputs": ["1 A\n", "4 AGCT\n", "4 ATAT\n", "10 AAATACCGCG\n"], "outputs": ["0\n", "2\n", "4\n", "6\n"]} | coding | 307 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, add a dot (".") as the thousands separator and return it in string format.
Please complete the following python code precisely:
```python
class Solution:
def thousandSeparator(self, n: int) -... | {"functional": "def check(candidate):\n assert candidate(n = 987) == \"987\"\n assert candidate(n = 1234) == \"1.234\"\n assert candidate(n = 123456789) == \"123.456.789\"\n assert candidate(n = 0) == \"0\"\n\n\ncheck(Solution().thousandSeparator)"} | coding | 69 |
Solve the programming task below in a Python markdown code block.
Recently Johnny have learned bogosort sorting algorithm. He thought that it is too ineffective. So he decided to improve it. As you may know this algorithm shuffles the sequence randomly until it is sorted. Johnny decided that we don't need to shuffle th... | {"inputs": ["3\n2\n3\n7", "3\n4\n7\n3", "3\n2\n2\n8", "3\n3\n3\n7", "3\n4\n6\n8", "3\n3\n3\n5", "3\n4\n3\n5", "3\n2\n6\n7"], "outputs": ["2\n10/3\n8810/693\n", "5\n8810/693\n10/3\n", "2\n2\n439331/27027\n", "10/3\n10/3\n8810/693\n", "5\n1826/189\n439331/27027\n", "10/3\n10/3\n149/21\n", "5\n10/3\n149/21\n", "2\n1826/18... | coding | 380 |
Solve the programming task below in a Python markdown code block.
Alice is visiting New York City. To make the trip fun, Alice will take photos of the city skyline and give the set of photos as a present to Bob. However, she wants to find the set of photos with maximum beauty and she needs your help.
There are $n$ bui... | {"inputs": ["2\n2 1\n-2 -3\n", "1\n1\n1000000000\n", "1\n1\n-1000000000\n", "5\n1 2 3 5 4\n1 5 3 2 4\n", "5\n1 4 3 2 5\n-3 4 -10 2 7\n", "8\n8 7 3 2 6 4 1 5\n4 -1 4 -1 -1 2 2 3\n", "10\n5 1 6 2 8 3 4 10 9 7\n1 1 -1 -1 -1 1 -1 1 -1 1\n", "10\n4 7 3 2 5 1 9 10 6 8\n-4 40 -46 -8 -16 4 -10 41 12 3\n"], "outputs": ["-3\n", ... | coding | 754 |
Solve the programming task below in a Python markdown code block.
The beauty of a sequence a of length n is defined as a_1 \oplus \cdots \oplus a_n, where \oplus denotes the bitwise exclusive or (XOR).
You are given a sequence A of length N. Snuke will insert zero or more partitions in A to divide it into some number ... | {"inputs": ["3\n2 2 0", "3\n1 4 2", "3\n1 2 0", "3\n1 8 2", "3\n1 6 2", "3\n1 0 0", "3\n1 6 3", "3\n0 0 3"], "outputs": ["3\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 378 |
Solve the programming task below in a Python markdown code block.
# Task
Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array.
# Example
For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]`
... | {"functional": "_inputs = [[[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], [[2]], [[1, 2]], [[1, 1, 2, 2]]]\n_outputs = [[6], [5], [1], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.is... | coding | 369 |
Solve the programming task below in a Python markdown code block.
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N.
You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with t... | {"inputs": ["2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3", "2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3", "2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 6\n2 4\n2 3", "2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 0\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3", "2\n8 4\n6 1 2 4 5 7 6\n1 2\n4 4... | coding | 375 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row ... | {"functional": "def check(candidate):\n assert candidate(wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]) == 2\n assert candidate(wall = [[1],[1],[1]]) == 3\n\n\ncheck(Solution().leastBricks)"} | coding | 197 |
Solve the programming task below in a Python markdown code block.
A policeman wants to catch a thief. Both the policeman and the thief can only move on a line on integer coordinates between $0$ and $N$ (inclusive).
Initially, the policeman is at a coordinate $x$ and the thief is at a coordinate $y$. During each second,... | {"inputs": ["5\n0 1 1 1\n1 4 1 5\n4 2 1 7\n3 7 2 10\n8 2 3 15"], "outputs": ["No\nNo\nYes\nYes\nYes"]} | coding | 488 |
Solve the programming task below in a Python markdown code block.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers $a$ and $b$ and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of ($a \oplus x$... | {"inputs": ["6\n6 12\n4 4\n7 832\n55 8\n2891 508\n1 1\n", "6\n6 12\n4 4\n1 832\n55 8\n7888 2912\n1 2\n", "6\n6 1\n4 3\n53 832\n28 8\n4925 2912\n3 1\n", "6\n6 3\n4 3\n90 832\n28 8\n4402 2912\n3 2\n", "6\n6 12\n4 4\n90 832\n55 8\n3049 508\n1 1\n", "6\n6 1\n4 3\n53 832\n28 8\n4925 2912\n3 0\n", "6\n6 12\n4 4\n90 832\n55 8... | coding | 335 |
Solve the programming task below in a Python markdown code block.
G --Derangement / Derangement
Story
Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a crush on C... | {"inputs": ["5\n2 1 3 5 4", "5\n2 1 0 5 4", "5\n4 1 0 5 4", "5\n4 1 0 5 6", "5\n4 0 0 5 6", "5\n4 0 0 0 3", "5\n4 0 1 0 3", "5\n7 0 1 0 3"], "outputs": ["4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 526 |
Solve the programming task below in a Python markdown code block.
There is a fair going on in Chefland. Chef wants to visit the fair along with his N friends. Chef manages to collect K passes for the fair. Will Chef be able to enter the fair with all his N friends?
A person can enter the fair using one pass, and each... | {"inputs": ["4\n5 8\n6 3\n2 2\n1 2\n"], "outputs": ["YES\nNO\nNO\nYES\n"]} | coding | 446 |
Solve the programming task below in a Python markdown code block.
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 2^0, 2^1 and 2^2 respective... | {"inputs": ["1\n4\n", "1\n8\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n5\n", "1\n7\n", "1\n16\n"], "outputs": ["-4\n", "6\n", "-3\n", "0\n", "7\n", "1\n", "14\n", "74\n"]} | coding | 245 |
Solve the programming task below in a Python markdown code block.
## Task
You have to write three functions namely - `PNum, GPNum and SPNum` (JS, Coffee), `p_num, g_p_num and s_p_num` (Python and Ruby), `pNum, gpNum and spNum` (Java, C#), `p-num, gp-num and sp-num` (Clojure) - to check whether a given argument `n` is ... | {"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [100]]\n_outputs = [[False], [True], [False], [False], [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, (... | coding | 528 |
Solve the programming task below in a Python markdown code block.
If we alternate the vowels and consonants in the string `"have"`, we get the following list, arranged alphabetically:
`['ahev', 'aveh', 'ehav', 'evah', 'vahe', 'veha']`. These are the only possibilities in which vowels and consonants are alternated. The ... | {"functional": "_inputs = [['java'], ['oruder'], ['zodiac'], ['apple'], ['acidity'], ['codewars'], ['orudere']]\n_outputs = [['ajav'], ['edorur'], ['acidoz'], ['lapep'], ['caditiy'], ['failed'], ['ederoru']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | coding | 389 |
Solve the programming task below in a Python markdown code block.
We call an quadruple of positive integers, $(W,X,Y,Z)$, beautiful if the following condition is true:
$W\oplus X\oplus Y\oplus Z\neq0$
Note: $\theta$ is the bitwise XOR operator.
Given $\mbox{A}$, $\mbox{B}$, $\mbox{C}$, and $\mbox{D}$, count the numb... | {"inputs": ["1 2 3 4\n"], "outputs": ["11\n"]} | coding | 518 |
Solve the programming task below in a Python markdown code block.
Set
Given the sequence a_1, a_2, .., a_N.
How many values are there in this sequence?
input
N
a_1 a_2 ... a_N
output
Output the number of types of values in the sequence.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq a_i \ leq 10 ^ 9
Inp... | {"inputs": ["6\n8 5 9 1 2 1", "6\n8 5 9 0 2 1", "6\n1 2 9 0 2 0", "6\n1 5 9 0 2 1", "6\n1 5 9 0 2 0", "6\n8 6 9 1 2 1", "6\n1 2 15 0 2 0", "6\n-1 1 0 0 7 1"], "outputs": ["5\n", "6\n", "4\n", "5\n", "5\n", "5", "4\n", "4\n"]} | coding | 149 |
Solve the programming task below in a Python markdown code block.
Alice is driving from her home to her office which is A kilometers away and will take her X hours to reach.
Bob is driving from his home to his office which is B kilometers away and will take him Y hours to reach.
Determine who is driving faster, else... | {"inputs": ["3\n20 6 20 5\n10 3 20 6\n9 1 1 1\n"], "outputs": ["Bob\nEqual\nAlice\n"]} | coding | 436 |
Solve the programming task below in a Python markdown code block.
Let F(S) denote the number of distinct elements in the array S. For example, F([1, 2, 3, 2]) = 3, F([1, 2]) = 2.
You are given an array A containing N integers. Find if it is possible to divide the elements of the array A into two arrays B and C such th... | {"inputs": ["3\n2\n1 2\n3\n1 2 3\n4\n3 1 1 2\n"], "outputs": ["YES\nNO\nYES\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
The only difference between this problem and D2 is that you don't have to provide the way to construct the answer in this problem, but you have to do it in D2.
There's a table of $n \times m$ cells ($n$ rows and $m$ columns). The value of $n \cdot m$ is... | {"inputs": ["1\n6 1 0\n", "1\n1 2 1\n", "1\n2 1 0\n", "1\n6 3 8\n", "1\n4 1 0\n", "1\n1 4 2\n", "1\n7 4 2\n", "1\n8 1 0\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 446 |
Solve the programming task below in a Python markdown code block.
Problem statement
There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $.
Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play.
* Alternately select one of the following... | {"inputs": ["2\n0 2", "2\n0 4", "2\n0 1", "2\n1 0", "2\n0 7", "2\n2 0", "2\n4 0", "2\n5 0"], "outputs": ["Second\n", "Second\n", "First\n", "First\n", "First\n", "Second\n", "Second\n", "First\n"]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Chef likes to write poetry. Today, he has decided to write a X pages long poetry, but unfortunately his notebook has only Y pages left in it. Thus he decided to buy a new CHEFMATE notebook and ... | {"inputs": ["3\n3 1 2 2\n3 4\n2 2 \n3 1 2 2\n2 3\n2 3 \n3 1 2 2\n1 1\n1 2"], "outputs": ["LuckyChef\nUnluckyChef\nUnluckyChef"]} | coding | 753 |
Solve the programming task below in a Python markdown code block.
# Definition
**_Strong number_** is the number that *the sum of the factorial of its digits is equal to number itself*.
## **_For example_**: **_145_**, since
```
1! + 4! + 5! = 1 + 24 + 120 = 145
```
So, **_145_** is a **_Strong number_**.
____
# ... | {"functional": "_inputs = [[40585], [2999999]]\n_outputs = [['STRONG!!!!'], ['Not Strong !!']]\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)... | coding | 622 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of AND triples.
An AND triple is a triple of indices (i, j, k) such that:
0 <= i < nums.length
0 <= j < nums.length
0 <= k < nums.length
nums[i] & nums[j] & nums[k] == 0... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 12\n assert candidate(nums = [0,0,0]) == 27\n\n\ncheck(Solution().countTriplets)"} | coding | 125 |
Solve the programming task below in a Python markdown code block.
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number a_{i} written on it.
They take turns playing, starting with Conan. In each t... | {"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "1\n4\n", "1\n16\n", "2\n1 1\n", "1\n485\n"], "outputs": ["Conan\n", "Conan\n", "Conan", "Conan", "Conan\n", "Conan\n", "Agasa\n", "Conan\n"]} | coding | 399 |
Solve the programming task below in a Python markdown code block.
You will be given the prime factors of a number as an array.
E.g: ```[2,2,2,3,3,5,5,13]```
You need to find the number, n, to which that prime factorization belongs.
It will be:
```
n = 2³.3².5².13 = 23400
```
Then, generate the divisors of this number.... | {"functional": "_inputs = [[[2, 3, 5, 5]], [[2, 3, 3, 3, 7]], [[3, 3, 3, 11]], [[2, 13, 2, 5, 2, 5, 3, 3]]]\n_outputs = [[[150, 11, 2, 75]], [[378, 15, 2, 189]], [[297, 7, 3, 99]], [[23400, 71, 2, 11700]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ... | coding | 668 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has recently got a broadband internet connection. His history of internet data usage is provided as below.
During the first T_{1} minutes, the internet data used was D_... | {"inputs": ["3\n2 2\n2 1\n2 3\n2 2\n1 2\n2 3\n3 0\n1 2\n2 4\n10 10"], "outputs": ["6\n3\n110"]} | coding | 580 |
Solve the programming task below in a Python markdown code block.
Given a string made up of letters a, b, and/or c, switch the position of letters a and b (change a to b and vice versa). Leave any incidence of c untouched.
Example:
'acb' --> 'bca'
'aabacbaa' --> 'bbabcabb'
Also feel free to reuse/extend the following... | {"functional": "_inputs = [['abc'], ['aaabcccbaaa'], ['ccccc'], ['abababababababab'], ['aaaaa']]\n_outputs = [['bac'], ['bbbacccabbb'], ['ccccc'], ['babababababababa'], ['bbbbb']]\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... | coding | 96 |
Solve the programming task below in a Python markdown code block.
This is simple version of harder [Square Sums](/kata/square-sums).
# Square sums
Write function `square_sums_row` (or `squareSumsRow`/`SquareSumsRow` depending on language rules) that, given integer number `N` (in range `2..43`), returns array of integ... | {"functional": "_inputs = [[5], [24]]\n_outputs = [[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)):\n if len(a) != len(b): return False\n re... | coding | 622 |
Solve the programming task below in a Python markdown code block.
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwa... | {"inputs": ["f\n", "a\n", "g\n", "b\n", "e\n", "c\n", "h\n", "d\n"], "outputs": ["Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n"]} | coding | 650 |
Solve the programming task below in a Python markdown code block.
You have a string $s$ of length $n$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that... | {"inputs": ["1\n9\n>>>>>>>><\n", "1\n9\n>>>>>>>><\n", "1\n9\n<>>>>>>>>\n", "3\n2\n<>\n3\n><<\n1\n>\n", "3\n2\n<>\n3\n><<\n1\n>\n", "3\n2\n><\n3\n><<\n1\n>\n", "3\n2\n><\n3\n<<>\n1\n>\n", "3\n2\n<>\n3\n<<>\n1\n>\n"], "outputs": ["0\n", "0\n", "1\n", "1\n0\n0\n", "1\n0\n0\n", "0\n0\n0\n", "0\n1\n0\n", "1\n1\n0\n"]} | coding | 486 |
Solve the programming task below in a Python markdown code block.
Vacations have arrived and Chef wants to go to his home in ChefLand. There are two types of routes he can take:
Take a flight from his college to ChefArina which takes X minutes and then take a bus from ChefArina to ChefLand which takes Y minutes.
Take... | {"inputs": ["3\n10 12 11\n3 5 15\n9 4 13\n"], "outputs": ["TRAIN\nPLANEBUS\nEQUAL\n"]} | coding | 474 |
Solve the programming task below in a Python markdown code block.
There is a circular track of length M consisting of M checkpoints and M bidirectional roads such that each road has a length of 1 unit.
Chef is currently at checkpoint A and wants to reach checkpoint B. Find the minimum length of the road he needs to tr... | {"inputs": ["4\n1 3 100\n1 98 100\n40 30 50\n2 1 2\n"], "outputs": ["2\n3\n10\n1\n"]} | coding | 433 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the number of all the arithmetic subsequences of nums.
A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two con... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,6,8,10]) == 7\n assert candidate(nums = [7,7,7,7,7]) == 16\n\n\ncheck(Solution().numberOfArithmeticSlices)"} | coding | 244 |
Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game i... | {"inputs": ["4\n0 0 1 2\n", "4\n1 0 1 2\n", "5\n4 1 4 7 6\n", "5\n4 1 1 7 6\n", "5\n4 1 0 1 2\n", "5\n4 2 0 1 2\n", "5\n8 2 0 1 2\n", "5\n4 1 1 7 2\n"], "outputs": ["0\n0\n1\n", "1\n1\n3\n", "4\n5\n9\n17\n", "4\n5\n6\n14\n", "4\n5\n5\n7\n", "4\n6\n6\n9\n", "8\n10\n10\n13\n", "4\n5\n6\n14\n"]} | coding | 583 |
Solve the programming task below in a Python markdown code block.
You are given $n$ numbers $a_1, a_2, \dots, a_n$. With a cost of one coin you can perform the following operation:
Choose one of these numbers and add or subtract $1$ from it.
In particular, we can apply this operation to the same number several times.... | {"inputs": ["2\n0 1\n", "2\n0 2\n", "2\n0 0\n", "2\n0 4\n", "2\n1 4\n", "2\n-1 1\n", "2\n-1 0\n", "2\n-1 2\n"], "outputs": ["1\n", "2\n", "2\n", "4\n", "3\n", "2", "1\n", "3\n"]} | coding | 527 |
Solve the programming task below in a Python markdown code block.
A professor invented Cookie Breeding Machine for his students who like cookies very much.
When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie ... | {"inputs": ["3\n3 1\n4 4\n1 2", "3\n3 1\n4 50\n1 2", "3\n3 1\n4 75\n1 2", "3\n3 2\n2 98\n1 9", "3\n3 1\n4 75\n1 0", "3\n3 1\n4 64\n1 2", "3\n3 1\n4 37\n1 2", "3\n3 1\n4 89\n1 2"], "outputs": ["255\n504\n2\n", "255\n458\n2\n", "255\n433\n2\n", "256\n156\n9\n", "255\n433\n0\n", "255\n444\n2\n", "255\n471\n2\n", "255\n419... | coding | 410 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.
Return true if the square is white, and false if the square is black.
The c... | {"functional": "def check(candidate):\n assert candidate(coordinates = \"a1\") == False\n assert candidate(coordinates = \"h3\") == True\n assert candidate(coordinates = \"c7\") == False\n\n\ncheck(Solution().squareIsWhite)"} | coding | 117 |
Solve the programming task below in a Python markdown code block.
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an ... | {"inputs": ["3\n5\n9\n6\n2\n2\n0", "3\n5\n9\n6\n3\n2\n0", "3\n5\n9\n5\n3\n2\n0", "3\n5\n9\n1\n3\n2\n0", "3\n5\n9\n1\n4\n2\n0", "3\n5\n9\n2\n4\n2\n0", "3\n5\n9\n4\n2\n19\n0", "3\n5\n5\n3\n8\n19\n0"], "outputs": ["Case 1: 3\nCase 2: 5\nCase 3: 9\nCase 4: 6\nCase 5: 2\nCase 6: 2\n", "Case 1: 3\nCase 2: 5\nCase 3: 9\nCase ... | coding | 264 |
Solve the programming task below in a Python markdown code block.
ByteLand is a large country with a tree-like road system. It has $N$ cities and $(N-1)$ unidirected roads. The capital of ByteLand is a city, numbered $\mbox{1}$, and all the roads go away from the capital. So people use these roads to reach any city fro... | {"inputs": ["5 2\n1 2 1 2 1\n1 2\n2 3\n3 4\n4 5\n2 4\n2 5\n"], "outputs": ["2\n3\n"]} | coding | 691 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese .
Given an array of n non-negative integers: A_{1}, A_{2}, …, A_{N}. Your mission is finding a pair of integers A_{u}, A_{v} (1 ≤ u < v ≤ N) such that (A_{u} and A_{v}) is as large as possible.
And is a bit... | {"inputs": ["4\n2\n4\n0\n8", "4\n2\n4\n2\n7", "4\n1\n8\n7\n5", "4\n2\n3\n3\n7", "4\n7\n7\n3\n1", "4\n2\n4\n2\n8", "4\n2\n4\n0\n3", "4\n2\n4\n0\n0"], "outputs": ["0\n", "4\n", "5\n", "3\n", "7\n", "2\n", "2\n", "0\n"]} | coding | 321 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.