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.
Problem
Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N.
Constraints
* 1 β€ N β€ 12
Input
One natural number N is given in one line.
Output
Output the smallest natural... | {"inputs": ["5", "4", "6", "8", "7", "9", "4", "6"], "outputs": ["16\n", "6\n", "12\n", "24\n", "64\n", "36\n", "6\n", "12\n"]} | coding | 115 |
Solve the programming task below in a Python markdown code block.
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then t... | {"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["1\n1\n32\n1\n32\n654\n1\n32\n654\n10987\n1\n32\n654\n10987\n1514131211"]} | coding | 235 |
Solve the programming task below in a Python markdown code block.
A recent lab accident resulted in the creation of an extremely dangerous virus that replicates so rapidly it's hard to predict exactly how many cells it will contain after a given period of time. However, a lab technician made the following observations ... | {"inputs": ["2 4 1\n"], "outputs": ["3\n"]} | coding | 430 |
Solve the programming task below in a Python markdown code block.
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U an... | {"inputs": ["1\nR\n", "1\nU\n", "1\nR\n", "1\nU\n", "2\nUR\n", "2\nUR\n", "2\nRU\n", "3\nRUR\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]} | coding | 295 |
Solve the programming task below in a Python markdown code block.
## Task
Let's say we have a positive integer, `$n$`. You have to find the smallest possible positive integer that when multiplied by `$n$`, becomes a perfect power of integer `$k$`. A perfect power of `$k$` is any positive integer that can be represente... | {"functional": "_inputs = [[100, 3], [36, 2], [72, 4], [5, 2], [1152, 3]]\n_outputs = [[10], [1], [18], [5], [12]]\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 | 374 |
Solve the programming task below in a Python markdown code block.
Make a program that filters a list of strings and returns a list with only your friends name in it.
If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours! Otherwise, you can be sure he's not...
Ex: Input = ["Ryan", ... | {"functional": "_inputs = [[['Ryan', 'Kieran', 'Mark']], [['Ryan', 'Jimmy', '123', '4', 'Cool Man']], [['Jimm', 'Cari', 'aret', 'truehdnviegkwgvke', 'sixtyiscooooool']], [['Love', 'Your', 'Face', '1']], [['Hell', 'Is', 'a', 'badd', 'word']], [['Issa', 'Issac', 'Issacs', 'ISISS']], [['Robot', 'Your', 'MOMOMOMO']], [['Yo... | coding | 132 |
Solve the programming task below in a Python markdown code block.
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p_{i}, a_{i} and b_{i}, where p_{i} is the price of the i-th t-shirt, a_{i} is front color of the i-th t-shirt and b_{i} is back color of the i-th t-shirt. A... | {"inputs": ["1\n529469903\n1\n3\n1\n3\n", "1\n529469903\n1\n3\n1\n3\n", "1\n529469903\n1\n1\n1\n3\n", "1\n529469903\n1\n1\n1\n1\n", "2\n1000000000 1\n1 1\n1 2\n2\n2 1\n", "2\n1000000000 1\n1 1\n1 3\n2\n2 1\n", "2\n1000000000 1\n2 1\n1 3\n2\n2 1\n", "2\n1000000100 1\n1 1\n1 3\n2\n2 1\n"], "outputs": ["529469903 \n", "52... | coding | 717 |
Solve the programming task below in a Python markdown code block.
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).
You may perform the following operations until both a and s are empty:
Take the first element of a, push it into s and remove it from a (if a is not... | {"inputs": ["5 1\n3\n", "2 1\n1\n", "2 1\n1\n", "9 1\n6\n", "7 1\n1\n", "5 1\n3\n", "10 1\n6\n", "10 1\n1\n"], "outputs": ["3 2 1 5 4 ", "1 2 ", "1 2 ", "6 5 4 3 2 1 9 8 7 ", "1 7 6 5 4 3 2 ", "3 2 1 5 4 ", "6 5 4 3 2 1 10 9 8 7 ", "1 10 9 8 7 6 5 4 3 2 "]} | coding | 682 |
Solve the programming task below in a Python markdown code block.
In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many b... | {"inputs": ["3 4\n", "2 2\n"], "outputs": ["6\n", "1\n"]} | coding | 141 |
Solve the programming task below in a Python markdown code block.
You are given an array $a_1, a_2, \dots, a_n$ and an integer $k$.
You are asked to divide this array into $k$ non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let $f(i)$ be the index of subarray the... | {"inputs": ["4 1\n3 0 0 1\n", "4 1\n3 -1 6 0\n", "4 1\n3 -2 6 0\n", "4 1\n3 -2 1 0\n", "4 1\n2 -2 1 0\n", "4 1\n3 -2 2 0\n", "4 1\n0 -2 1 0\n", "4 1\n6 -2 1 0\n"], "outputs": ["4\n", "8\n", "7\n", "2\n", "1\n", "3\n", "-1\n", "5\n"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
## Task:
You have to write a function `pattern` which returns the following Pattern(See Examples) upto n number of rows.
* Note:```Returning``` the pattern is not the same as ```Printing``` the pattern.
### Rules/Note:
* The pattern should be create... | {"functional": "_inputs = [[1], [2], [3], [7], [17], [27], [0], [-89]]\n_outputs = [['1'], ['22\\n21'], ['333\\n322\\n321'], ['7777777\\n7666666\\n7655555\\n7654444\\n7654333\\n7654322\\n7654321'], ['77777777777777777\\n76666666666666666\\n76555555555555555\\n76544444444444444\\n76543333333333333\\n76543222222222222\\n... | coding | 637 |
Solve the programming task below in a Python markdown code block.
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y),... | {"inputs": ["2\n", "3\n", "4\n", "1\n", "3\n", "4\n", "1\n", "6\n"], "outputs": ["2\nC.\n.C\n", "5\nC.C\n.C.\nC.C\n", "8\nC.C.\n.C.C\nC.C.\n.C.C\n", "1\nC\n", "5\nC.C\n.C.\nC.C\n", "8\nC.C.\n.C.C\nC.C.\n.C.C\n", "1\nC\n", "18\nC.C.C.\n.C.C.C\nC.C.C.\n.C.C.C\nC.C.C.\n.C.C.C\n"]} | coding | 244 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... +... | {"functional": "def check(candidate):\n assert candidate(arr = [0,2,1,-6,6,-7,9,1,2,0,1]) == True\n assert candidate(arr = [0,2,1,-6,6,7,9,-1,2,0,1]) == False\n assert candidate(arr = [3,3,6,5,-2,2,5,1,-9,4]) == True\n\n\ncheck(Solution().canThreePartsEqualSum)"} | coding | 155 |
Solve the programming task below in a Python markdown code block.
A string $s$ of length $n$ ($1 \le n \le 26$) is called alphabetical if it can be obtained using the following algorithm:
first, write an empty string to $s$ (i.e. perform the assignment $s$ := "");
then perform the next step $n$ times;
at the $i$-th ... | {"inputs": ["1\nbabe\n", "1\nbabe\n", "1\nbbae\n", "1\ndcab\n", "1\nbaae\n", "1\nabae\n", "1\nabbe\n", "1\nebba\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 520 |
Solve the programming task below in a Python markdown code block.
A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input.
Input:... | {"inputs": ["3\nritesh\nsahil\nritesh"], "outputs": ["ritesh 2\nsahil 1"]} | coding | 252 |
Solve the programming task below in a Python markdown code block.
Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$.
For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to ... | {"inputs": ["1\n5\n", "1\n1\n", "1\n5\n", "1\n1\n", "1\n8\n", "1\n14\n", "2\n1 2\n", "2\n1 3\n"], "outputs": ["4 0\n", "1 0\n", "4 0\n", "1 0\n", "7 0\n", "13 0\n", "1 0\n", "2 0\n"]} | coding | 478 |
Solve the programming task below in a Python markdown code block.
Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems.
The boy h... | {"inputs": ["1\n1 2\n88\n", "1\n1 3\n88\n", "1\n1 3\n129\n", "1\n1 2\n148\n", "1\n17 2\n0 17 22 21 5 7 5 24 10 8 8 6 1 8 3 0 0\n", "1\n17 2\n0 17 22 20 5 7 5 24 10 8 8 6 1 8 3 0 0\n", "1\n17 2\n0 17 22 21 5 7 13 12 10 8 8 6 1 8 3 0 0\n", "1\n17 2\n0 17 22 21 5 7 13 24 10 8 8 6 1 8 3 0 0\n"], "outputs": ["140130951\n", ... | coding | 564 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array arr of integers, check if there exist two indices i and j such that :
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
Β
Please complete the following python code precisely:
```python
class Solution... | {"functional": "def check(candidate):\n assert candidate(arr = [10,2,5,3]) == True\n assert candidate(arr = [7,1,14,11]) == True\n assert candidate(arr = [3,1,7,11]) == False\n\n\ncheck(Solution().checkIfExist)"} | coding | 91 |
Solve the programming task below in a Python markdown code block.
All of the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringi... | {"functional": "_inputs = [['great blue heron', 'garlic naan'], ['chickadee', 'chocolate cake'], ['brown bear', 'bear claw'], ['marmot', 'mulberry tart'], ['porcupine', 'pie'], ['cat', 'yogurt'], ['electric eel', 'lasagna'], ['slow loris', 'salsas'], ['ox', 'orange lox'], ['blue-footed booby', 'blueberry'], ['fruit-fly... | coding | 196 |
Solve the programming task below in a Python markdown code block.
A sequence $a_1, a_2, \dots, a_n$ is called good if, for each element $a_i$, there exists an element $a_j$ ($i \ne j$) such that $a_i+a_j$ is a power of two (that is, $2^d$ for some non-negative integer $d$).
For example, the following sequences are goo... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n5\n", "1\n4\n", "1\n6\n", "1\n16\n", "1\n31\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 653 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1i... | {"functional": "def check(candidate):\n assert candidate(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]]) == 1\n assert candidate(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]]) == 2\n\n\ncheck(Solution().digArtifacts)"} | coding | 305 |
Solve the programming task below in a Python markdown code block.
A flower shop has got n bouquets, and the i-th bouquet consists of a_{i} flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets.
Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, an... | {"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n0\n", "3\n7 4 9\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
Constraints
* 1000 \leq N \leq 9999
Input
Input is given from Standard Input in the following format:
N
Output... | {"inputs": ["0", "1", "2", "3", "95", "79", "89", "36"], "outputs": ["0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 121 |
Solve the programming task below in a Python markdown code block.
# Task
let F(N) be the sum square of digits of N. So:
`F(1) = 1, F(3) = 9, F(123) = 14`
Choose a number A, the sequence {A0, A1, ...} is defined as followed:
```
A0 = A
A1 = F(A0)
A2 = F(A1) ...
```
if A = 123, we have:
```
123 β... | {"functional": "_inputs = [[1], [85], [810], [812], [818], [833]]\n_outputs = [[1], [8], [8], [8], [1], [1]]\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 le... | coding | 591 |
Solve the programming task below in a Python markdown code block.
The Chef commutes to work every day using the city's underground metro. The schedule for the trains has recently been changed and he wants to know how long it will take to travel from the station nearest to his house and the station nearest to his restau... | {"inputs": ["3\n2\n1 1 7\n0 6 5\n2\n0 1 1\n0 1 1\n2\n0 2 3\n0 1 3", "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 2 10\n2\n1 2 3\n0 2 3", "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 2 10\n2\n1 2 5\n0 2 3", "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 4 10\n2\n1 2 5\n0 2 3", "3\n2\n0 3 7\n0 6 5\n2\n0 1 2\n8 4 10\n2\n1 1 5\n0 2 3", "3\n2\n0 3 7\n0 6 5\n2\n... | coding | 737 |
Solve the programming task below in a Python markdown code block.
There is a ladder which leads to the door of heaven. Each step of ladder has a card in it. The card is blue if the number printed on it is even otherwise red.
Numbers on the ladder is in the following pattern :
1, 2, 3, 5, 8, 13, 21, 34, 55, 89
i.e., N... | {"inputs": ["9\n807\n763\n859\n676\n340\n599\n553\n136\n614"], "outputs": ["798\n798\n798\n798\n188\n188\n188\n44\n798"]} | coding | 338 |
Solve the programming task below in a Python markdown code block.
The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$.
Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to comp... | {"inputs": ["6\n0 1\n18 0\n18 0\n3 3\n1 8\n2 7", "6\n0 1\n18 0\n18 0\n3 3\n1 8\n4 7", "6\n0 11\n70 0\n18 5\n5 3\n1 8\n2 5", "6\n0 11\n70 0\n18 5\n3 3\n1 8\n2 5", "6\n0 11\n26 0\n18 5\n3 3\n1 8\n2 5", "6\n0 11\n26 0\n18 5\n3 3\n1 8\n2 4", "6\n0 11\n26 0\n18 5\n3 3\n1 8\n2 7", "6\n0 11\n18 0\n18 5\n3 3\n1 8\n2 7"], "outp... | coding | 253 |
Solve the programming task below in a Python markdown code block.
The well-known Fibonacci sequence $F_0, F_1, F_2,\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \geq 2$: $F_i = F_{i - 1} + F_{i - 2}$.
Given an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a + d, a + ... | {"inputs": ["3 1 1\n", "5 1 2\n", "2 1 1\n", "2 2 1\n", "2 2 1\n", "5 1 2\n", "2 1 1\n", "3 1 1\n"], "outputs": ["4417573500000000001 4417573500000000000\n", "4417573500000000001 8835147000000000000\n", "4417573500000000001 4417573500000000000\n", "8835147000000000001 4417573500000000000\n", "8835147000000000001 441757... | coding | 585 |
Solve the programming task below in a Python markdown code block.
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., ANβ1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it i... | {"inputs": ["5\n4 0 2 3 4\n4\n3\n4\n6\n1", "5\n4 0 2 3 4\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n4\n5\n4\n6\n1", "5\n4 1 2 6 4\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n4\n3\n7\n6\n1", "5\n4 0 2 3 4\n1\n3\n4\n6\n1", "5\n4 0 2 3 0\n4\n5\n4\n6\n1", "5\n4 1 2 3 4\n3\n5\n4\n6\n1"], "outputs": ["2\n2\n0\n0\n", "0\n2\n0\n0\n", "0\n2\n0\n8\n",... | coding | 545 |
Solve the programming task below in a Python markdown code block.
Kuro and Shiro are playing with a board composed of n squares lining up in a row.
The squares are numbered 1 to n from left to right, and Square s has a mark on it.
First, for each square, Kuro paints it black or white with equal probability, independent... | {"inputs": ["3\n", "1\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["499122178\n499122178\n499122178\n", "499122177\n", "1\n1\n", "2\n2\n2\n2\n", "499122179\n499122179\n311951363\n499122179\n499122179\n", "3\n3\n904658948\n904658948\n3\n3\n", "499122180\n499122180\n452329476\n140378116\n452329476\n49912218... | coding | 722 |
Solve the programming task below in a Python markdown code block.
Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released... | {"inputs": ["9 6\nAAAAAA\nACACAC\nGTTTTG\nACACAC\nGTTTTG\nACACAC\nACACAC\nTCCCCC\nTCCCCC\n0 0\n\n"], "outputs": ["1\n2\n0\n1\n0\n0\n0\n0\n0"]} | coding | 515 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string:
Choose an integer L with 1β€ L β€ N and apply S_{i} = (S_{i} + 1) \mod 10 for each 1 β€ i β€ L.
For example, if S=39590, then c... | {"inputs": ["6\n3 5\n380\n3 9\n380\n4 2\n0123\n5 13\n78712\n6 10\n051827\n8 25\n37159725\n\n"], "outputs": ["0\n3\n1\n3\n2\n5\n"]} | coding | 701 |
Solve the programming task below in a Python markdown code block.
Recently, chef Ciel often hears about lucky numbers.
Everybody knows that lucky numbers are positive integers
whose decimal representation contains only the lucky digits 4 and 7.
For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Ciel de... | {"inputs": ["6\nmlik 64\nCsel'i nriDk 24\nfhT crruy 1nd noitide 94654\nrcie temelo 85855\nunagi 1\n The first dao tasl letters acn ea b soacd 564", "6\nmlik 64\nCsel'i nriDk 24\nfhT crruy 1nd noitide 94654\nrcie temelo 85855\nunagi 1\n The first dao tasl letters abn ea b soacd 564", "6\nmlik 64\nCsel'i ... | coding | 616 |
Solve the programming task below in a Python markdown code block.
Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications:
Mat size must be $N$X$\mbox{M}$. ($N$ is an odd natural number, and $\mbox{M}$ is $3$ times $N$.)
The design should have 'WELC... | {"inputs": ["9 27\n"], "outputs": ["------------.|.------------\n---------.|..|..|.---------\n------.|..|..|..|..|.------\n---.|..|..|..|..|..|..|.---\n----------WELCOME----------\n---.|..|..|..|..|..|..|.---\n------.|..|..|..|..|.------\n---------.|..|..|.---------\n------------.|.------------\n"]} | coding | 459 |
Solve the programming task below in a Python markdown code block.
Our Chef who was a renouned mathematician has recently got into diamonds' business.
She has accidentally misplaced $Q$ diamonds into a jar which already had $N$ chocolates. She then started wondering about an interesting question as following.
If we pi... | {"inputs": ["1\n2 2"], "outputs": ["3.3333333333"]} | coding | 396 |
Solve the programming task below in a Python markdown code block.
Chef has $N$ doggo (dogs) , Lets number them $1$ to $N$.
Chef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities. Let the... | {"inputs": ["1\n4"], "outputs": ["2"]} | coding | 406 |
Solve the programming task below in a Python markdown code block.
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], wh... | {"inputs": ["12\n13 19 9 5 12 8 7 4 13 0 6 3", "12\n13 19 9 5 12 8 7 4 21 0 2 18", "12\n13 19 9 5 12 8 7 4 13 0 6 18", "12\n8 19 9 5 12 8 7 4 21 4 10 18", "12\n13 19 9 5 12 8 7 4 40 0 10 1", "12\n40 19 9 1 12 8 8 6 21 0 10 1", "12\n40 19 6 1 12 8 0 2 21 2 4 22", "12\n13 19 9 5 12 8 7 4 21 2 6 11"], "outputs": ["0 [3] 9... | coding | 486 |
Solve the programming task below in a Python markdown code block.
By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the col... | {"inputs": ["100 1\n+ 6\n", "100 1\n+ 51\n", "100 1\n+ 10\n", "101 1\n+ 51\n", "100 1\n+ 16\n", "101 1\n+ 74\n", "100 1\n+ 63\n", "100 1\n+ 25\n"], "outputs": ["Success\n", "Success\n", "Success\n", "Success\n", "Success\n", "Success\n", "Success\n", "Success\n"]} | coding | 743 |
Solve the programming task below in a Python markdown code block.
We have found a new chess character β pook. It has the qualities of both a rook and a pawn. Specifically, treating the chessboard to be an N\times N grid where (i, j) denotes the intersection of the i-th row and the j-th column, a pook placed at square (... | {"inputs": ["3\n1\n2\n3"], "outputs": ["1\n1\n2"]} | coding | 438 |
Solve the programming task below in a Python markdown code block.
A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not.
The string t is called a s... | {"inputs": ["?\na\n", "a\na\n", "b\na\n", "a\naa\n", "?\ncb\n", "b\naa\n", "?\nca\n", "?\ncc\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 505 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers numsΒ and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same el... | {"functional": "def check(candidate):\n assert candidate(nums = [2,7,11,15], target = 9) == [0,1]\n assert candidate(nums = [3,2,4], target = 6) == [1,2]\n assert candidate(nums = [3,3], target = 6) == [0,1]\n\n\ncheck(Solution().twoSum)"} | coding | 110 |
Solve the programming task below in a Python markdown code block.
Motu and Patlu are playing with a Magical Ball. Patlu find some interesting pattern in the motion of the ball that ball always bounce back from the ground after travelling a linear distance whose value is some power of $2$. Patlu gave Motu total distance... | {"inputs": ["1\n13"], "outputs": ["2"]} | coding | 241 |
Solve the programming task below in a Python markdown code block.
Given a string of words and numbers. Extract the expression including:
1. the operator: either addition or subtraction
2. the two numbers that we are operating on
Return the result of the calculation.
Example:
"Panda has 48 apples and loses 4" return... | {"functional": "_inputs = [['Panda has 48 apples and loses 4'], ['Jerry has 34 apples and gains 6'], ['Tom has 20 apples and gains 15'], ['Fred has 110 bananas and loses 50'], ['Pippi has 20 tunas and gains 0']]\n_outputs = [[44], [40], [35], [60], [20]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a,... | coding | 153 |
Solve the programming task below in a Python markdown code block.
There are 2 stores in Chefland and both sell the same product. The first store sells the product for 100 rupees whereas the second store sells it for 200 rupees.
It is the holiday season and both stores have announced a special discount. The first store... | {"inputs": ["4\n5 20\n10 60\n7 7\n10 55\n"], "outputs": ["FIRST\nSECOND\nFIRST\nBOTH\n"]} | coding | 635 |
Solve the programming task below in a Python markdown code block.
For a given weighted directed graph G(V, E), find the distance of the shortest route that meets the following criteria:
* It is a closed cycle where it ends at the same point it starts.
* It visits each vertex exactly once.
Constraints
* 2 β€ |V| β€ 15
... | {"inputs": ["3 3\n0 0 1\n1 2 1\n0 2 1", "1 1\n0 0 0\n1 2 1\n0 2 1", "3 3\n0 0 1\n2 2 1\n0 2 1", "3 3\n0 1 1\n1 2 1\n0 0 1", "3 3\n0 0 0\n1 2 1\n0 2 1", "3 3\n0 0 1\n2 2 1\n0 2 2", "3 3\n0 2 1\n1 2 1\n0 0 1", "3 3\n0 0 0\n1 0 1\n0 2 1"], "outputs": ["-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 305 |
Solve the programming task below in a Python markdown code block.
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume tha... | {"inputs": ["1 5\n1\n", "1 5\n4\n", "1 1\n1\n", "1 8\n1\n", "1 2\n1\n", "1 3\n1\n", "1 4\n1\n", "1 6\n1\n"], "outputs": ["4\n", "1\n", "0\n", "7\n", "1\n", "2\n", "3\n", "5\n"]} | coding | 499 |
Solve the programming task below in a Python markdown code block.
You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any nu... | {"inputs": ["1 1\n1 1\n1\n1\n", "1 1\n1 1\n1\n1\n", "1 1\n1 1\n1\n0\n", "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "3 3\n1 1\n1 2 3\n1 2 3\n", "3 3\n1 2\n1 2 3\n1 2 3\n", "3 3\n2 2\n1 2 3\n1 2 3\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]} | coding | 524 |
Solve the programming task below in a Python markdown code block.
You are given an array of $n$ integers $a_1, a_2, \ldots, a_n$. The integers are either $1$ or $-1$. You have to perform the following operation exactly once on the array $a$:
Choose an index $i$ ($1 \leq i < n$) and flip the signs of $a_i$ and $a_{i+1}... | {"inputs": ["4\n5\n-1 1 1 -1 -1\n5\n1 1 -1 -1 -1\n2\n1 1\n4\n1 -1 -1 1\n"], "outputs": ["3\n3\n-2\n4\n"]} | coding | 460 |
Solve the programming task below in a Python markdown code block.
You are given an equilateral triangle ΞABC with the side BC being the base. Each side of the triangle is of length L. There are L-1 additional points on each of the sides dividing the sides into equal parts of unit lengths. Points on the sides of the tri... | {"inputs": ["2\n4 3\n4 4"], "outputs": ["Case 1: 3\nCase 2: 1"]} | coding | 541 |
Solve the programming task below in a Python markdown code block.
Killgrave wants to use his mind control powers to get money from the Justice League superheroes living in $N$ houses in Happy Harbor that are numbered sequentially from $1$ to $N$. There are $\mbox{M}$ roads, and each road $j$ connects two different hous... | {"inputs": ["3 2\n6 8 2\n1 2\n3 2\n"], "outputs": ["8 2\n"]} | coding | 708 |
Solve the programming task below in a Python markdown code block.
Your start-up's BA has told marketing that your website has a large audience in Scandinavia and surrounding countries. Marketing thinks it would be great to welcome visitors to the site in their own language. Luckily you already use an API that detects t... | {"functional": "_inputs = [['english'], ['dutch'], ['IP_ADDRESS_INVALID'], [''], [2]]\n_outputs = [['Welcome'], ['Welkom'], ['Welcome'], ['Welcome'], ['Welcome']]\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... | coding | 535 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.
A substring is a contiguous sequence of characters with... | {"functional": "def check(candidate):\n assert candidate(s = \"aa\") == 0\n assert candidate(s = \"abca\") == 2\n assert candidate(s = \"cbzxy\") == -1\n assert candidate(s = \"cabbac\") == 4\n\n\ncheck(Solution().maxLengthBetweenEqualCharacters)"} | coding | 93 |
Solve the programming task below in a Python markdown code block.
Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!
In the morning, there are $n$ opportunities to buy shares. The $i$-th... | {"inputs": ["1 1 1\n1\n1\n", "1 1 4\n3\n4\n", "1 1 7\n5\n6\n", "1 1 7\n5\n7\n", "1 1 5\n5\n6\n", "1 1 4\n4\n5\n", "1 1 5\n1\n4\n", "1 1 4\n8\n7\n"], "outputs": ["1\n", "5\n", "8\n", "9\n", "6\n", "5\n", "20\n", "4\n"]} | coding | 573 |
Solve the programming task below in a Python markdown code block.
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to... | {"inputs": ["3\n", "7\n", "4\n", "6\n", "1\n", "2\n", "5\n", "9\n"], "outputs": ["NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 307 |
Solve the programming task below in a Python markdown code block.
A permutation $p_1,p_2...p_N$ of $\{1, 2, ..., N\}$ is beautiful if $p_i \& p_{i+1}$ is greater than 0 for every $1 \leq i < N$ . You are given an integer $N$, and your task is toconstruct a beautiful permutation of length $N$ or determine that it's impo... | {"inputs": ["3\n4\n3\n5"], "outputs": ["-1\n1 3 2\n2 3 1 5 4"]} | coding | 314 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a very large integer n, represented as a string,ββββββ and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.
You want to maximi... | {"functional": "def check(candidate):\n assert candidate(n = \"99\", x = 9) == \"999\"\n assert candidate(n = \"-13\", x = 2) == \"-123\"\n\n\ncheck(Solution().maxValue)"} | coding | 220 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Chef wants to implement wildcard pattern matching supporting only the wildcard '?'. The wildcard character '?' can be substituted by any single lower case English letter for matching. He... | {"inputs": ["2\ns?or?\nsco??\nstor?\nsco??", "2\ns?o?r\nsco??\nstor?\nsco??", "2\nr?o?s\nsco??\nstor?\nsco??", "2\nr?o?s\nsco??\n?rots\nsco??", "2\nr?o?s\nsco??\n@rots\nsco??", "2\nr?o?s\nsco??\n@rots\n??ocs", "2\nr?o?s\nsco??\n@rots\ntco??", "2\nr?o?s\nsco??\n@rots\nuco??"], "outputs": ["Yes\nNo", "Yes\nNo\n", "No\nNo... | coding | 398 |
Solve the programming task below in a Python markdown code block.
# Task
Consider the following ciphering algorithm:
```
For each character replace it with its code.
Concatenate all of the obtained numbers.
```
Given a ciphered string, return the initial one if it is known that it consists only of lowercase letters.
... | {"functional": "_inputs = [['10197115121'], ['98'], ['122']]\n_outputs = [['easy'], ['b'], ['z']]\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... | coding | 236 |
Solve the programming task below in a Python markdown code block.
A notice on the notice board read:
βIs there an end to it?
While the number remains greater than one, if 2 divides the number completely, divide the number by 2; while the number remains greater than 1, if the number is not divisible by 2 , multiply th... | {"inputs": ["0", "1", "16"], "outputs": ["No", "Yes", "Yes"]} | coding | 152 |
Solve the programming task below in a Python markdown code block.
Ivan unexpectedly saw a present from one of his previous birthdays. It is array of $n$ numbers from $1$ to $200$. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, mor... | {"inputs": ["2\n2 9\n", "2\n1 9\n", "2\n1 2\n", "2\n1 3\n", "2\n2 21\n", "2\n1 21\n", "2\n3 30\n", "2\n1 30\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
The chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2.
He just started calculating the powers of two. And adding the digits of the results.
But he got puzzled after a few calculations. So gave yo... | {"inputs": ["3\n5\n10\n4"], "outputs": ["5\n7\n7"]} | coding | 199 |
Solve the programming task below in a Python markdown code block.
Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \leq B \leq C \leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A ... | {"inputs": ["1 2 3 4\n", "1 2 2 5\n", "1 2 2 3\n", "1 0 2 5\n", "1 2 2 5\n", "1 2 3 4\n", "32 89 451 476\n", "32 89 451 476\n"], "outputs": ["4\n", "3\n", "3\n", "0\n", "3", "4", "72384\n", "72384"]} | coding | 471 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x.
As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b di... | {"inputs": ["2\n2\n2\n", "2\n4\n2\n", "2\n2\n14\n", "100\n5\n2\n5\n6\n7\n2\n9\n10\n11\n12\n13\n15\n16\n17\n18\n19\n25\n21\n22\n23\n24\n16\n26\n27\n28\n3\n30\n31\n32\n5\n33\n35\n36\n5\n38\n39\n40\n55\n42\n43\n34\n45\n75\n47\n48\n49\n50\n47\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n6\n64\n65\n66\n67\n68\n69\n70\n71\n7... | coding | 312 |
Solve the programming task below in a Python markdown code block.
Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in N colors. Those colors are conveniently numbered 1 through N. Snuke currently has no slime. His objective is to have slimes of all the colors together.
... | {"inputs": ["2 6\n1 101", "2 3\n1 101", "2 2\n1 100", "2 0\n1 100", "2 10\n1 101", "2 10\n1 100", "4 4\n2 1 3 4", "4 10\n1 1 3 4"], "outputs": ["8\n", "5\n", "4\n", "2\n", "12\n", "12", "10\n", "9\n"]} | coding | 362 |
Solve the programming task below in a Python markdown code block.
Let x be a string of length at least 1.
We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x.
For example, a, bbc and cdcdc are good strings, while aa, bbbb... | {"inputs": ["ddc", "aaa", "dec", "aa`", "eec", "aa_", "cee", "ba_"], "outputs": ["1\n1\n", "3\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]} | coding | 518 |
Solve the programming task below in a Python markdown code block.
A number $a_2$ is said to be the arithmetic mean of two numbers $a_1$ and $a_3$, if the following condition holds: $a_1 + a_3 = 2\cdot a_2$.
We define an arithmetic mean deviation of three numbers $a_1$, $a_2$ and $a_3$ as follows: $d(a_1, a_2, a_3) = |... | {"inputs": ["3\n3 4 5\n2 2 6\n1 6 5\n"], "outputs": ["0\n1\n0\n"]} | coding | 746 |
Solve the programming task below in a Python markdown code block.
You will be given a two-dimensional array with row consisting values 0 or 1.
A move consists of choosing any column or row, and toggling all the 0βs as 1βs and 1βs as 0βs.
After making the required moves, every row represents a binary number and the ... | {"inputs": ["3 4\n0 0 1 1\n1 0 1 0\n1 1 0 0"], "outputs": ["39"]} | coding | 344 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of n strings strs, all of the same length.
The strings can be arranged such that there is one on each line, making a grid.
For example, strs = ["abc", "bce", "cae"] can be arranged as follows:
... | {"functional": "def check(candidate):\n assert candidate(strs = [\"cba\",\"daf\",\"ghi\"]) == 1\n assert candidate(strs = [\"a\",\"b\"]) == 0\n assert candidate(strs = [\"zyx\",\"wvu\",\"tsr\"]) == 3\n\n\ncheck(Solution().minDeletionSize)"} | coding | 196 |
Solve the programming task below in a Python markdown code block.
CQXYM is counting permutations length of $2n$.
A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the ar... | {"inputs": ["1\n100000\n", "1\n100000\n", "2\n99997\n3\n", "2\n99997\n3\n", "2\n99997\n4\n", "4\n1\n2\n9\n91234\n", "4\n2\n2\n9\n91234\n", "4\n1\n2\n3\n91234\n"], "outputs": ["553573229\n", "553573229\n", "979296788\n360\n", "979296788\n360\n", "979296788\n20160\n", "1\n12\n830455698\n890287984\n", "12\n12\n830455698\n... | coding | 737 |
Solve the programming task below in a Python markdown code block.
Singh is getting bored at work. He has a lot of ideas (N) to work on (as side projects) but is unable to choose one.
He chooses a random number (R) and lines up his ideas in a circle. He starts counting from first and removes the R^th idea in the circle... | {"inputs": ["23 9000001", "23 9000000"], "outputs": ["6", "4"]} | coding | 209 |
Solve the programming task below in a Python markdown code block.
Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital l... | {"inputs": ["4\n5 1\nfrauD\n5 1\nFRAUD\n4 4\nLife\n10 4\nsTRAWBerry"], "outputs": ["chef\nbrother\nboth\nnone"]} | coding | 630 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$ of 0's and 1's. You are allowed to perform the following operation:
choose a non-empty contiguous substring of $s$ that contains an equal number of 0's and 1's;
flip all characters in the substring, that is, replace all 0's w... | {"inputs": ["2\n0\n1\n", "2\n0\n1\n", "4\n1\n10\n1\n11\n", "4\n1\n10\n01\n11\n", "4\n00\n10\n01\n11\n", "4\n00\n10\n01\n11\n", "3\n100101\n1100011\n10101010\n", "3\n100101\n1100011\n10001010\n"], "outputs": ["0\n1\n", "0\n1\n", "1\n10\n1\n11\n", "1\n10\n01\n11\n", "00\n10\n01\n11\n", "00\n10\n01\n11\n", "010110\n011011... | coding | 477 |
Solve the programming task below in a Python markdown code block.
You are given a prime number p, n integers a_1, a_2, β¦, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 β€ i < j β€ n) for which (a_i + a_j)(a_i^2 + a_j^2) β‘ k mod p.
Input
The first line contains integers n, p, k (2 β€ n β€ 3 β
10^5... | {"inputs": ["2 2 1\n1 0\n", "2 2 0\n1 0\n", "2 2 2\n1 0\n", "2 3 2\n1 0\n", "2 4 0\n1 0\n", "2 37 0\n3 1\n", "2 56 0\n3 1\n", "2 56 0\n6 1\n"], "outputs": ["1", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 358 |
Solve the programming task below in a Python markdown code block.
Chef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries. For this he has came up with an idea - he will gr... | {"inputs": ["1\n4 2\n0 1\n1 2\n3\n0 2\n0 3\n2 1\n\n"], "outputs": ["YO\nNO\nYO"]} | coding | 504 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Russian here
Polo, the Penguin, likes the XOR operation. Please read NOTE if you are not familiar with XOR operation.
XOR-sum of a list of numbers is the result of XOR-ing all of them. XOR-sum of (A[1] XOR A[2] XOR ... XOR A... | {"inputs": ["2\n3\n1 2 3\n3 1 2\n4\n1 2 2\n1 3 2\n4 3 1"], "outputs": ["3\n3"]} | coding | 716 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an n x n integer matrix grid.
Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:
maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 ... | {"functional": "def check(candidate):\n assert candidate(grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]) == [[9,9],[8,6]]\n assert candidate(grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]) == [[2,2,2],[2,2,2],[2,2,2]]\n\n\ncheck(Solution().largestLocal)"} | coding | 150 |
Solve the programming task below in a Python markdown code block.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
d_1 is the distance between the 1-st and the 2-nd station;
d_2 is the distance between the 2-nd and the 3-rd station;
...
d_{n... | {"inputs": ["3\n1 1 1\n3 1\n", "3\n1 1 1\n2 1\n", "3\n1 1 1\n3 1\n", "4\n2 3 4 9\n1 3\n", "3\n4 37 33\n3 3\n", "4\n1 1 1 1\n2 4\n", "4\n1 1 2 1\n2 4\n", "3\n4 37 33\n3 3\n"], "outputs": ["1\n", "1\n", "1\n", "5\n", "0\n", "2\n", "2\n", "0\n"]} | coding | 500 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice and Bob have an undirected graph of n nodes and three types of edges:
Type 1: Can be traversed by Alice only.
Type 2: Can be traversed by Bob only.
Type 3: Can be traversed by both Alice and Bob.
Given an arra... | {"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]) == 2\n assert candidate(n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]) == 0\n assert candidate(n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]) == -1\n\n\ncheck(Solution().maxNumEdgesToRemove)... | coding | 219 |
Solve the programming task below in a Python markdown code block.
You have an unbiased dice which you want to keep rolling until you get N consecutive even numbers. You've rolled the dice M times and surprisingly, all rolls resulted in even numbers. What is the expected number of additional rolls needed until you get N... | {"inputs": ["10\n7 2\n8 2\n7 7\n7 2\n5 4\n5 3\n3 1\n4 2\n1 0\n8 2", "25\n6 6\n20 7\n17 8\n11 9\n23 9\n22 19\n2 1\n10 8\n20 20\n5 4\n9 8\n4 4\n4 2\n19 11\n6 0\n2 1\n9 8\n23 1\n25 16\n5 1\n22 18\n17 9\n14 11\n17 6\n13 11", "100\n358 303\n334 7\n74 12\n379 123\n856 31\n687 45\n565 469\n526 243\n283 172\n93 81\n732 336\n92... | coding | 378 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n couples sitting in 2n seats arranged in a row and want to hold hands.
The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the ith seat. The couples ... | {"functional": "def check(candidate):\n assert candidate(row = [0,2,1,3]) == 1\n assert candidate(row = [3,2,0,1]) == 0\n\n\ncheck(Solution().minSwapsCouples)"} | coding | 180 |
Solve the programming task below in a Python markdown code block.
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the proc... | {"inputs": ["1\n", "2\n", "6\n", "3\n", "4\n", "5\n", "2\n", "1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 602 |
Solve the programming task below in a Python markdown code block.
Consider a string, $S$, of $n$ lowercase English letters where each character, $s_i$ ($0\leq i<n)$, denotes the letter at index $\boldsymbol{i}$ in $S$. We define an $(a,b,c,d)$ palindromic tuple of $S$ to be a sequence of indices in $S$ satisfying the f... | {"inputs": ["ghhggh\n", "abbaab\n", "akakak\n", "kkkkkkz\n", "kkkkkkz\n"], "outputs": ["4\n", "4\n", "2\n", "15\n", "15\n"]} | coding | 608 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other word... | {"functional": "def check(candidate):\n assert candidate(s = \"aba\", t = \"baba\") == 6\n assert candidate(s = \"ab\", t = \"bb\") == 3\n assert candidate(s = \"a\", t = \"a\") == 0\n assert candidate(s = \"abe\", t = \"bbc\") == 10\n\n\ncheck(Solution().countSubstrings)"} | coding | 175 |
Solve the programming task below in a Python markdown code block.
Internet search engines, such as Google, automatically sort and categorize web pages around the world to create a huge database. It also parses the search keywords entered by the user and creates an inquiry statement for database search.
In each case, c... | {"inputs": ["Rain, rain, go ot Spain.", "Rain, iarn, og ot Spain.", "Rain, arin, go to Spain.", "Rain, raio, go ot Spain.", "Rain, rain, og ot .niapS", "Rajn, rain, og ot .niapS", "Rain, rain, go to Spain.", "Win today's preliminary contest and be qualified to visit University fo Aizu."], "outputs": ["Rain rain Spain\n... | coding | 266 |
Solve the programming task below in a Python markdown code block.
Chef has a string $S$ consisting of lowercase English characters. Chef defined functions left shift $L(X)$ and right shift $R(X)$ as follows.
$L(X)$ is defined as shifting all characters of string $X$ one step towards left and moving the first character... | {"inputs": ["4\na\nab\nabcd\naaaaa"], "outputs": ["YES\nYES\nNO\nYES"]} | coding | 408 |
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a string and your task will be to return the length of the longest prefix that is also a suffix. A prefix is the start of a string while the suffix is the end of a string. For instance, the prefixes of the string `"abcd"`... | {"functional": "_inputs = [['abcd'], ['abcda'], ['abcdabc'], ['abcabc'], ['abcabca'], ['abcdabcc'], ['aaaaa'], ['aaaa'], ['aaa'], ['aa'], ['a'], ['acbacc']]\n_outputs = [[0], [1], [3], [3], [1], [0], [2], [2], [1], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ... | coding | 278 |
Solve the programming task below in a Python markdown code block.
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of ... | {"inputs": ["1\n0\n", "3\n8 1 2\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n3 3 0\n", "3\n4 3 0\n", "3\n4 3 1\n", "3\n5 3 1\n"], "outputs": ["0\n", "7\n", "1\n", "0\n", "3\n", "4\n", "3\n", "4\n"]} | coding | 311 |
Solve the programming task below in a Python markdown code block.
------Read problems statements in Hindi,
Mandarin chinese
, Russian and Vietnamese as well. ------
Chef likes to play with cards a lot. Today, he's playing a game with three cards. Each card has a letter written on the top face and another (possibly id... | {"inputs": ["3\nbob\nrob\ndbc\nocb\nboc\nobc"], "outputs": ["yes\nyes\nno"]} | coding | 463 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move eithe... | {"functional": "def check(candidate):\n assert candidate(m = 3, n = 7) == 28\n assert candidate(m = 3, n = 2) == 3\n assert candidate(m = 7, n = 3) == 28\n assert candidate(m = 3, n = 3) == 6\n\n\ncheck(Solution().uniquePaths)"} | coding | 173 |
Solve the programming task below in a Python markdown code block.
You have managed to intercept an important message and you are trying to read it.
You realise that the message has been encoded and can be decoded by switching each letter with a corresponding letter.
You also notice that each letter is paired with the... | {"functional": "_inputs = [['sr'], ['svool'], ['r slkv mlylwb wvxlwvh gsrh nvhhztv'], ['qzezxirkg rh z srts ovevo wbmznrx fmgbkvw zmw rmgvikivgvw kiltiznnrmt ozmtfztv rg szh yvvm hgzmwziwravw rm gsv vxnzxirkg ozmtfztv hkvxrurxzgrlm zolmthrwv sgno zmw xhh rg rh lmv lu gsv gsivv vhhvmgrzo gvxsmloltrvh lu dliow drwv dvy x... | coding | 203 |
Solve the programming task below in a Python markdown code block.
Below is a right-angled triangle:
```
|\
| \
| \
| \
o | \ h
| \
| ΞΈ \
|_______\
a
```
Your challange is to write a function (```missingAngle``` in C/C#, ```missing_angle``` in Ruby), that calculates the angle ΞΈ in de... | {"functional": "_inputs = [[0, 400, 300], [5, 4, 0], [8, 0, 5], [16.7, 0, 12.3], [7, 5, 0]]\n_outputs = [[37], [37], [39], [47], [44]]\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, (lis... | coding | 179 |
Solve the programming task below in a Python markdown code block.
There is a horizontal row of $n$ cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile should follow these directions: if $cube[i]$ is on top of $cube[j]$ then $side Length[j]\geq side Length[i]$.
When s... | {"inputs": ["2\n6\n4 3 2 1 3 4\n3\n1 3 2\n"], "outputs": ["Yes\nNo\n"]} | coding | 562 |
Solve the programming task below in a Python markdown code block.
**DESCRIPTION:**
Your strict math teacher is teaching you about right triangles, and the Pythagorean Theorem --> a^2 + b^2 = c^2 whereas a and b are the legs of the right triangle and c is the hypotenuse of the right triangle. On the test however, the... | {"functional": "_inputs = [[1, 1], [3, 4], [4, 6], [5, 12], [8, 10]]\n_outputs = [[[1]], [[2, 3, 4, 6]], [[3, 4, 5, 6, 7, 8, 9]], [[8, 9, 10, 11, 12, 14, 15, 16]], [[3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 397 |
Solve the programming task below in a Python markdown code block.
There are n cities numbered from 1 to n in Berland. Some of them are connected by two-way roads. Each road has its own length β an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. A... | {"inputs": ["2\n0 5\n5 0\n1\n1 2 5\n", "2\n0 5\n5 0\n1\n1 2 3\n", "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n", "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763\n", "3\n0 983 173\n983 0 810\n173 810 0\n3\n2 2 567\n2 3 767\n1 2 763\n", "3\n0 983 173\n983 0 810\n173 810 0\n3\n2 3 567\n2 3 767\n1 2 763\n",... | coding | 589 |
Solve the programming task below in a Python markdown code block.
problem
AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided to create a password that meets all of the following conditions.
1. T... | {"inputs": ["5\npassword\nlogin\nnimda\nroot\nmaster", "5\nbraprswp\nlofho\nojdma\nsnnt\nfuarsm", "5\nbraprsxp\noofhk\nojcma\nsnnt\nfuarsm", "5\napssword\nlogin\nnimda\nroot\nmaster", "5\nopssward\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin\nnjmda\nroot\nmaster", "5\ndra... | coding | 349 |
Solve the programming task below in a Python markdown code block.
You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t.
A path in the tree is said to be palindromic if at least one permutation of the labels in t... | {"inputs": ["5\n3 1\n3 5\n5 4\n5 2\nticdm\n", "5\n3 1\n3 2\n5 4\n5 2\nticdm\n", "5\n1 2\n2 3\n2 4\n3 5\nabcbb\n", "5\n1 2\n4 3\n2 4\n3 5\nabcbb\n", "5\n3 1\n3 5\n1 4\n5 2\nticdm\n", "5\n3 1\n3 2\n5 4\n5 1\nticdm\n", "5\n1 2\n2 3\n3 4\n3 5\nabcbb\n", "7\n6 2\n4 3\n1 7\n5 2\n7 2\n1 4\nafefdfs\n"], "outputs": ["1 1 1 1 1\... | coding | 476 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
A zero-based permutation nums is an array of distinct in... | {"functional": "def check(candidate):\n assert candidate(nums = [0,2,1,5,3,4]) == [0,1,2,4,5,3]\n assert candidate(nums = [5,0,1,2,3,4]) == [4,5,0,1,2,3]\n\n\ncheck(Solution().buildArray)"} | coding | 114 |
Solve the programming task below in a Python markdown code block.
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list of commands that will be given... | {"inputs": ["F\n1\n", "F\n0\n", "TF\n1\n", "FT\n1\n", "TTFFF\n49\n", "FFFTFFF\n2\n", "FTTTFTFF\n8\n", "FFFFTFTF\n1\n"], "outputs": ["0\n", "1\n", "2\n", "2\n", "4\n", "6\n", "8\n", "5\n"]} | coding | 323 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.
A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.
Β
Pl... | {"functional": "def check(candidate):\n assert candidate(matrix = [[3,7,8],[9,11,13],[15,16,17]]) == [15]\n assert candidate(matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]) == [12]\n assert candidate(matrix = [[7,8],[1,2]]) == [7]\n\n\ncheck(Solution().luckyNumbers)"} | coding | 97 |
Solve the programming task below in a Python markdown code block.
You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$.
Let's ... | {"inputs": ["4 2\n0 1 2 3\n", "4 2\n1 1 2 3\n", "4 2\n1 0 2 3\n", "4 2\n0 1 2 3\n", "1 1\n1000000000\n", "1 1\n1000000000\n", "1 1\n1010000000\n", "6 3\n3 2 0 6 10 12\n"], "outputs": ["0\n0 1 2 3 \n", "1\n1 1 2 4 \n", "0\n1 0 2 3 \n", "0\n0 1 2 3 \n", "0\n1000000000 \n", "0\n1000000000 \n", "0\n1010000000 \n", "3\n3 2 ... | coding | 476 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.