task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected, but
also the sample output does not show the difference. For an example,
let us look at permutations.
A permutatio... | {"inputs": ["4\n1 4 3 2\n5\n2 3 4 5 1\n1\n1\n0", "4\n1 4 3 4\n5\n2 3 4 5 1\n1\n1\n0", "4\n1 4 3 2\n5\n1 3 4 5 1\n1\n1\n0", "4\n1 4 3 4\n5\n0 3 4 5 0\n0\n1\n0", "4\n1 3 3 0\n0\n3 3 3 1 1\n1\n1\n0", "4\n1 4 3 2\n0\n2 3 4 0 1\n1\n1\n1", "4\n1 4 3 4\n5\n0 3 4 5 1\n1\n1\n0", "4\n1 4 3 4\n5\n3 3 4 5 1\n1\n1\n0"], "outputs": ... | 432 | 302 |
coding | Solve the programming task below in a Python markdown code block.
Chef's coding class is very famous in Chefland.
This year X students joined his class and each student will require one chair to sit on. Chef already has Y chairs in his class. Determine the minimum number of new chairs Chef must buy so that every stud... | {"inputs": ["4\n20 14\n41 41\n35 0\n50 100\n"], "outputs": ["6\n0\n35\n0\n"]} | 354 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers ... | {"inputs": ["0\n", "0\n", "1\n", "00\n", "01\n", "00\n", "01\n", "000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]} | 398 | 76 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (... | {"functional": "def check(candidate):\n assert candidate(gas = [1,2,3,4,5], cost = [3,4,5,1,2]) == 3\n assert candidate(gas = [2,3,4], cost = [3,4,3]) == -1\n\n\ncheck(Solution().canCompleteCircuit)"} | 174 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Alice, the president of club FCB, wants to build a team for the new volleyball tournament. The team should consist of p players playing in p different positions. She also recognizes the importance of audience support, so she wants to select k people as p... | {"inputs": ["2 1 1\n30 9\n46\n73\n", "2 1 1\n30 9\n46\n87\n", "2 1 1\n76 91\n34\n77\n", "2 1 1\n76 146\n34\n77\n", "2 1 1\n76 291\n34\n77\n", "2 1 1\n76 291\n35\n77\n", "2 1 1\n131 291\n35\n77\n", "4 1 2\n2 4 10 3\n18\n19\n23\n3\n"], "outputs": ["103", "117\n", "153", "180\n", "325\n", "326\n", "326\n", "32\n"]} | 617 | 222 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array with $N$ integers: $A[1], A[2], \ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \ldots, A'[N]$. Your goal is t... | {"inputs": ["1\n4\n1 -3 2 -3"], "outputs": ["9"]} | 583 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s_1s_2... s_{n} (n is the length of the string), consisting only of characters "." and "#" and m queries.... | {"inputs": ["..\n1\n1 2\n", "##\n1\n1 2\n", ".#\n1\n1 2\n", "#.\n1\n1 2\n", "#.\n1\n1 2\n", "##\n1\n1 2\n", "..\n1\n1 2\n", ".#\n1\n1 2\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]} | 381 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows n sellers of antiques, the i-th of them auctioned k_{i} items. Currently the auction price of the j-th object of the i-th seller is s_{ij}. Valera... | {"inputs": ["1 50001\n1 50000\n", "1 50001\n1 50000\n", "1 1000000\n1 561774\n", "1 1000000\n1 561774\n", "1 1000000\n1 672641\n", "1 1000000\n1 1000000\n", "1 1000000\n1 1000000\n", "1 1100000\n1 1000000\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1 \n", "0\n\n", "0\n", "1\n1 \n"]} | 634 | 218 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
For example, The integer 5 is "101" in binary and its complement is "010" whic... | {"functional": "def check(candidate):\n assert candidate(5) == 2\n assert candidate(7) == 0\n assert candidate(10) == 5\n\n\ncheck(Solution().bitwiseComplement)"} | 125 | 52 |
coding | Solve the programming task below in a Python markdown code block.
There are N islands lining up from west to east, connected by N-1 bridges.
The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.
One day, disputes took place between some islands, and there were M requests from the... | {"inputs": ["2 1\n1 2\n", "5 2\n2 4\n2 5", "5 2\n1 5\n2 5", "5 1\n1 5\n2 5", "5 1\n0 5\n2 5", "5 2\n1 4\n2 8", "5 2\n0 5\n2 5", "4 1\n1 5\n2 5"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 302 | 139 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order.
The subtree sum of a node is defined as the sum of all the node ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([5,2,-3])) == [2,-3,4]\n assert candidate(root = tree_node([5,2,-5])) == [2]\n\n\ncheck(Solution().findFrequentTreeSum)"} | 167 | 64 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given two numbers, `a` and `b`, and your task is to determine if the first number `a` is divisible by `all` the prime factors of the second number `b`. For example: `solve(15,12) = False` because `15` is not divisible by all the... | {"functional": "_inputs = [[2, 256], [2, 253], [9, 243], [15, 12], [21, 2893401], [21, 2893406], [54, 2834352], [54, 2834359], [1000013, 7187761], [1000013, 7187762]]\n_outputs = [[True], [False], [True], [False], [True], [False], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isi... | 214 | 298 |
coding | Solve the programming task below in a Python markdown code block.
We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are... | {"inputs": ["4", "5", "2", "3", "6", "1", "73", "22"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 286 | 64 |
coding | Solve the programming task below in a Python markdown code block.
For given three integers $a, b, c$, print the minimum value and the maximum value.
Constraints
* $-1,000,000,000 \leq a, b, c \leq 1,000,000,000$
Input
The input is given in the following format.
$a \; b \; c\;$
Three integers $a, b, c$ are given... | {"inputs": ["6 5 3", "6 5 1", "6 5 0", "6 8 0", "9 2 0", "2 1 0", "0 1 0", "0 7 0"], "outputs": ["3 6\n", "1 6\n", "0 6\n", "0 8\n", "0 9\n", "0 2\n", "0 1\n", "0 7\n"]} | 144 | 110 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ models in the shop numbered from $1$ to $n$, with sizes $s_1, s_2, \ldots, s_n$.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrang... | {"inputs": ["4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 6 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 5 6 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 1 6 4 9\n5\n5 4 6 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n4\n6 6 3 6\n7\n1 4 ... | 618 | 457 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is playing a noob version of the game Flappy Bird with the following rules:
The bird starts at a height $H$ at $x = 0$.
There are $N$ obstacles (numbered $1$ throug... | {"inputs": ["3\n1 0\n2\n1\n2 1\n1 3\n1 1\n5 10\n1 2 3 4 5\n10 11 12 13 15\n"], "outputs": ["2\n2\n-1\n"]} | 757 | 69 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string text. You can swap two of the characters in the text.
Return the length of the longest substring with repeated characters.
Please complete the following python code precisely:
```python
class ... | {"functional": "def check(candidate):\n assert candidate(text = \"ababa\") == 3\n assert candidate(text = \"aaabaaa\") == 6\n assert candidate(text = \"aaabbaaa\") == 4\n assert candidate(text = \"aaaaa\") == 5\n assert candidate(text = \"abcdef\") == 1\n\n\ncheck(Solution().maxRepOpt1)"} | 78 | 88 |
coding | 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, find three non-overlapping subarrays of length k with maximum sum and return them.
Return the result as a list of indices representing the starting position of each interv... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,2,6,7,5,1], k = 2) == [0,3,5]\n assert candidate(nums = [1,2,1,2,1,2,1,2,1], k = 2) == [0,2,4]\n\n\ncheck(Solution().maxSumOfThreeSubarrays)"} | 118 | 97 |
coding | Solve the programming task below in a Python markdown code block.
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.
Given an integer N, determine whether it is a Harshad number.
-----Constraints-----
- 1?N?10^8
- N is an integer.
---... | {"inputs": ["1", "2", "3", "6", "8", "5", "4", "9"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | 164 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.
Some nodes initial are initially infected by malware. Wh... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]) == 0\n assert candidate(graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]) == 1\n assert candidate(graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]) == 1\n\n\ncheck(Solution().minMalw... | 231 | 140 |
coding | Solve the programming task below in a Python markdown code block.
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfl... | {"inputs": ["6\n1 2 6 4 5 6", "6\n1 2 4 4 5 6", "6\n1 2 4 3 4 6", "6\n1 2 6 2 2 2", "6\n1 2 3 4 5 6", "6\n1 2 3 4 5 6\n", "6\n1 2 11 4 5 6", "6\n1 2 6 2 3 -1"], "outputs": ["13\n", "12\n", "11\n", "9\n", "12", "12\n", "18\n", "10\n"]} | 219 | 166 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums of length n, and an integer array queries of length m.
Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that ... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,2,1], queries = [3,10,21]) == [2,3,4]\n assert candidate(nums = [2,3,4,5], queries = [1]) == [0]\n\n\ncheck(Solution().answerQueries)"} | 143 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each secon... | {"inputs": ["3 1\n0.1\n", "3 1\n0.9\n", "3 3\n9.9\n", "3 1\n9.5\n", "3 1\n9.9\n", "3 2\n0.9\n", "3 0\n0.1\n", "3 2\n9.5\n"], "outputs": ["0.1", "1", "10", "10", "10", "1", "0.1\n", "10"]} | 622 | 119 |
coding | Solve the programming task below in a Python markdown code block.
There are n incoming messages for Vasya. The i-th message is going to be received after t_{i} minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). ... | {"inputs": ["1 6 4 3 9\n2\n", "1 6 4 3 9\n2\n", "4 5 5 3 5\n1 5 5 4\n", "4 5 5 3 5\n2 5 5 4\n", "4 5 5 3 5\n1 5 5 4\n", "5 3 1 1 3\n2 2 2 1 1\n", "5 5 3 4 5\n1 2 3 4 5\n", "5 6 1 1 3\n2 2 2 1 1\n"], "outputs": ["6\n", "6\n", "20\n", "20\n", "20\n", "15\n", "35\n", "30\n"]} | 502 | 198 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Sheokand loves strings. Chef has $N$ strings $S_{1}, S_{2}, \dots, S_{N}$ which he wants to give to Sheokand; however, he doesn't want to give them away for free, so Sheokand... | {"inputs": ["4\nabcd\nabce\nabcdex\nabcde\n3\n3 abcy\n3 abcde\n4 abcde"], "outputs": ["abcd\nabcdex\nabcde"]} | 630 | 43 |
coding | Solve the programming task below in a Python markdown code block.
We have a long seat of width X centimeters.
There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would like to seat as many people as possible, but they are all very shy, and... | {"inputs": ["8 3 1", "8 3 3", "4 0 1", "12 3 2", "8 0 11", "17 4 0", "-1 0 1", "13 3 1"], "outputs": ["1\n", "0\n", "3\n", "2\n", "-1\n", "4\n", "-2\n", "3"]} | 203 | 97 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two numbers arr1 and arr2 in base -2, return the result of adding them together.
Each number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit. For example,... | {"functional": "def check(candidate):\n assert candidate(arr1 = [1,1,1,1,1], arr2 = [1,0,1]) == [1,0,0,0,0]\n assert candidate(arr1 = [0], arr2 = [0]) == [0]\n assert candidate(arr1 = [0], arr2 = [1]) == [1]\n\n\ncheck(Solution().addNegabinary)"} | 210 | 101 |
coding | Solve the programming task below in a Python markdown code block.
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c... | {"inputs": ["1\n4\n1 1\n1 1\n2 2\n3 4\n", "1\n4\n1 1\n1 1\n2 2\n3 4\n", "1\n4\n2 1\n1 1\n2 2\n3 4\n", "1\n4\n1 0\n1 2\n2 3\n3 4\n", "1\n4\n2 2\n1 1\n1 2\n3 8\n", "1\n4\n1 0\n2 2\n2 3\n3 0\n", "1\n4\n1 0\n1 1\n2 2\n3 6\n", "1\n4\n1 0\n1 4\n2 3\n3 4\n"], "outputs": ["4\n", "4\n", "4\n", "5\n", "8\n", "3\n", "6\n", "7\n"]... | 607 | 214 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Initially a number `1` is written on a board. It is possible to do the following operations with it:
```
multiply the number by 3;
increase the number by 5.```
Your task is to determine that using this two operations step by step, is it possible ... | {"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [100], [101], [12345], [54321]]\n_outputs = [[True], [False], [True], [False], [False], [True], [False], [True], [False], [True]]\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, ... | 414 | 221 |
coding | Solve the programming task below in a Python markdown code block.
Consider a list (list = []). You can perform the following commands:
insert i e: Insert integer $\boldsymbol{\mathrm{~e~}}$ at position $\boldsymbol{i}$.
print: Print the list.
remove e: Delete the first occurrence of integer $\boldsymbol{\mathrm{~e~... | {"inputs": ["12\ninsert 0 5\ninsert 1 10\ninsert 0 6\nprint\nremove 6\nappend 9\nappend 1\nsort\nprint\npop\nreverse\nprint\n"], "outputs": ["[6, 5, 10]\n[1, 5, 9, 10]\n[9, 5, 1]\n"]} | 462 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50.
Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org... | {"functional": "_inputs = [[[True, True, True, False], 'AND'], [[True, True, True, False], 'OR'], [[True, True, True, False], 'XOR'], [[True, True, False, False], 'AND'], [[True, True, False, False], 'OR'], [[True, True, False, False], 'XOR'], [[True, False, False, False], 'AND'], [[True, False, False, False], 'OR'], [... | 265 | 411 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radi... | {"inputs": ["2 4 2 2 1", "2 8 2 0 0", "5 4 2 0 1", "2 4 2 2 2", "5 8 2 0 1", "2 6 2 2 2", "2 8 2 0 1", "3 6 2 2 2"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 206 | 126 |
coding | Solve the programming task below in a Python markdown code block.
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct pos... | {"inputs": ["1 1\n1\n", "1 1\n2\n", "1 2\n2\n", "2 2\n4 2\n", "2 1\n2 1\n", "2 2\n1 3\n", "2 1\n4 1\n", "2 4\n1 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]} | 257 | 112 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:
There must be e... | {"functional": "def check(candidate):\n assert candidate(baseCosts = [1,7], toppingCosts = [3,4], target = 10) == 10\n assert candidate(baseCosts = [2,3], toppingCosts = [4,5,100], target = 18) == 17\n assert candidate(baseCosts = [3,10], toppingCosts = [2,5], target = 9) == 8\n assert candidate(baseCosts =... | 250 | 146 |
coding | Solve the programming task below in a Python markdown code block.
A certain business maintains a list of all its customers' names. The list is arranged in order of importance, with the last customer in the list being the most important. Now, he want to create a new list sorted alphabetically according to customers' las... | {"inputs": ["4\n6\na b c d\nA\nThomas a\nd d\ned edgars\nal Adams\n1\nTurnipHeadJohnson\n3\na a a a a a a a a a\nA A A A A A A A A A\nbob\n5\nBob Mackey\nMack Bobby\nbobby\nMack Mackey\nMackey", "4\n10\nAlan\naLan\nalAn\nalaN\nALan\nAlAn\nAlaN\naLAn\naLaN\nalAN\n4\nabcdefghijklmnop T\nabccefghijklmnop T\nt tt ttt tttt\... | 227 | 341 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ pieces of tangerine peel, the $i$-th of them has size $a_i$. In one step it is possible to divide one piece of size $x$ into two pieces of positive integer sizes $y$ and $z$ so that $y + z = x$.
You want that for each pair of pieces, their... | {"inputs": ["3\n5\n1 2 3 4 5\n1\n1033\n5\n600 900 1300 2000 2550\n"], "outputs": ["10\n0\n4\n"]} | 543 | 63 |
coding | Solve the programming task below in a Python markdown code block.
There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):
* Person S_i does one of the following... | {"inputs": ["3\n2\n1 2\n14\n0\n0 0\n9\n6\n2 6 9 3 7 7\n011000", "3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 9 6 7\n111000", "3\n2\n0 2\n10\n2\n1 1\n10\n6\n2 3 4 9 6 7\n111000", "3\n2\n1 2\n10\n2\n1 2\n10\n6\n2 3 1 9 6 7\n111000", "3\n2\n1 2\n14\n0\n2 0\n10\n6\n2 3 5 9 7 7\n111000", "3\n2\n0 2\n10\n2\n1 2\n10\n6\n2 3 1 9 2 7\n... | 387 | 405 |
coding | Solve the programming task below in a Python markdown code block.
Our football team finished the championship.
The result of each match look like "x:y". Results of all matches are recorded in the collection.
For example:
```["3:1", "2:2", "0:1", ...]```
Write a function that takes such collection and counts the point... | {"functional": "_inputs = [[['1:0', '2:0', '3:0', '4:0', '2:1', '3:1', '4:1', '3:2', '4:2', '4:3']], [['1:1', '2:2', '3:3', '4:4', '2:2', '3:3', '4:4', '3:3', '4:4', '4:4']], [['0:1', '0:2', '0:3', '0:4', '1:2', '1:3', '1:4', '2:3', '2:4', '3:4']], [['1:0', '2:0', '3:0', '4:0', '2:1', '1:3', '1:4', '2:3', '2:4', '3:4']... | 169 | 418 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the serve... | {"inputs": ["2\n1 5 5\n2 6 4\n", "2\n1 5 5\n2 8 4\n", "2\n1 5 5\n2 8 6\n", "2\n1 5 5\n2 6 6\n", "2\n1 5 5\n2 1 6\n", "2\n1 5 3\n2 1 6\n", "2\n1 5 5\n2 8 8\n", "2\n1 5 3\n2 1 7\n"], "outputs": ["LIVE\nLIVE\n", "LIVE\nLIVE\n", "LIVE\nLIVE\n", "LIVE\nLIVE\n", "LIVE\nDEAD\n", "LIVE\nDEAD\n", "LIVE\nLIVE\n", "LIVE\nDEAD\n"]... | 703 | 198 |
coding | Solve the programming task below in a Python markdown code block.
You are given a grid with dimension $n$ x $m$ and two points with coordinates $X(x1,y1)$ and $Y(x2,y2)$ . Your task is to find the number of ways in which one can go from point $A(0, 0)$ to point $B (n, m)$ using the $shortest$ possible path such that th... | {"inputs": ["1\n3 3 1 1 1 2"], "outputs": ["5"]} | 383 | 24 |
coding | Solve the programming task below in a Python markdown code block.
*This section assumes that you understand the basics discussed in HTML Parser - Part 1
.handle_comment(data)
This method is called when a comment is encountered (e.g. <!--comment-->).
The data argument is the content inside the comment tag:
from HT... | {"inputs": ["4\n<!--[if IE 9]>IE9-specific content\n<![endif]-->\n<div> Welcome to HackerRank</div>\n<!--[if IE 9]>IE9-specific content<![endif]-->\n"], "outputs": [">>> Multi-line Comment\n[if IE 9]>IE9-specific content\n<![endif]\n>>> Data\n Welcome to HackerRank\n>>> Single-line Comment\n[if IE 9]>IE9-specific conte... | 440 | 103 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given integers height and width which specify the dimensions of a brick wall you are building. You are also given a 0-indexed array of unique integers bricks, where the ith brick has a height of 1 and a width ... | {"functional": "def check(candidate):\n assert candidate(height = 2, width = 3, bricks = [1,2]) == 2\n assert candidate(height = 1, width = 1, bricks = [5]) == 0\n\n\ncheck(Solution().buildWall)"} | 195 | 65 |
coding | Solve the programming task below in a Python markdown code block.
The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds:
- divide the number x by 3 (x must be divisible by 3);
- multiply the number x by 2.
After each it... | {"inputs": ["6\n4 8 6 3 12 9"], "outputs": ["9 3 6 12 4 8"]} | 447 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out by these bridges, which allows you to travel to and from all cities.
R... | {"inputs": ["5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 1\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 3\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 0\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 6\n0 3 1\n3 4 8\n1 3 4\n3 3\n1 2 3\n2 0 3\n0... | 446 | 595 |
coding | Solve the programming task below in a Python markdown code block.
A company needs random numbers for its operation. $N$ random numbers have been generated using $N$ numbers as seeds and the following recurrence formula:
$\begin{aligned}F(K)=&\left(C(1)\times F(K-1)+C(2)\times F(K-2)+\cdots+C(N-1)\times F(K-N+1)+C(N)\t... | {"inputs": ["2 6\n13 8\n1 1\n"], "outputs": ["1 1 \n"]} | 484 | 28 |
coding | Solve the programming task below in a Python markdown code block.
The chef was searching for his pen in the garage but he found his old machine with a display and some numbers on it. If some numbers entered then some different output occurs on the display. Chef wants to crack the algorithm that the machine is following... | {"inputs": ["1\n7"], "outputs": ["21"]} | 207 | 15 |
coding | 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... | 398 | 209 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.
You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N.
Find the mi... | {"inputs": ["2\n1 0", "2\n1 1", "2\n0 2", "2\n2 2", "2\n0 1", "2\n2 0", "2\n0 0", "2\n0 3"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 237 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp found $n$ segments on the street. A segment with the index $i$ is described by two integers $l_i$ and $r_i$ — coordinates of the beginning and end of the segment, respectively. Polycarp realized that he didn't need all the segments, so he wanted... | {"inputs": ["7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 1\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 2\n1\n1 3\n", "7\n1\n1 2\n1\n1 2\n1\n1 2\n1\n2 2\n1\n1 2\n1\n1 2\n1\n1... | 563 | 502 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed string s, permute s to get a new string t such that:
All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then ... | {"functional": "def check(candidate):\n assert candidate(s = \"lEetcOde\") == \"lEOtcede\"\n assert candidate(s = \"lYmpH\") == \"lYmpH\"\n\n\ncheck(Solution().sortVowels)"} | 221 | 60 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions.
In one conversion you can convert all occurrences of one character in str1 to a... | {"functional": "def check(candidate):\n assert candidate(str1 = \"aabcc\", str2 = \"ccdee\") == True\n assert candidate(str1 = \"leetcode\", str2 = \"codeleet\") == False\n\n\ncheck(Solution().canConvert)"} | 119 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Katsusando loves omelette rice.
Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.
To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like ... | {"inputs": ["1 50\n1 4 3 1", "1 52\n5 9 7 8", "1 50\n1 7 6 3", "1 30\n5 4 2 30", "1 30\n6 4 2 30", "1 30\n3 2 3 30", "1 30\n6 6 2 30", "1 30\n5 4 10 6"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | 363 | 155 |
coding | Solve the programming task below in a Python markdown code block.
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1.
Your task is to write a program which sorts a giv... | {"inputs": ["2\nS1 G1", "2\nS1 H1", "5\nH4 B9 S4 D2 C3", "5\nH4 C9 S4 D2 C2", "5\nH4 B9 S4 E2 C3", "5\nI4 C9 S4 D2 C2", "5\nH3 B9 S4 E2 C3", "5\nH3 B9 S4 E2 B3"], "outputs": ["S1 G1\nStable\nS1 G1\nStable\n", "S1 H1\nStable\nS1 H1\nStable", "D2 C3 H4 S4 B9\nStable\nD2 C3 S4 H4 B9\nNot stable\n", "D2 C2 H4 S4 C9\nStable... | 533 | 321 |
coding | Solve the programming task below in a Python markdown code block.
Monica decides that she would like to get to know the neighbours in the apartment better. She makes a batch of wonderful chocolates and hangs them on the door in a basket hoping that her neighbors will take some and they can meet. The neighbours (includi... | {"inputs": ["3\n3\n2 1 1\n3\n0 5 0\n4\n3 0 2 1\n"], "outputs": ["4\n1\n3\n"]} | 741 | 44 |
coding | Solve the programming task below in a Python markdown code block.
You have two friends. You want to present each of them several positive integers. You want to present cnt_1 numbers to the first friend and cnt_2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that ... | {"inputs": ["3 1 2 3\n", "1 3 2 3\n", "1 1 2 3\n", "1 2 2 3\n", "2 1 2 3\n", "2 1 2 3\n", "1 2 2 3\n", "1 1 2 3\n"], "outputs": ["5\n", "4\n", "2\n", "3\n", "3\n", "3\n", "3\n", "2\n"]} | 461 | 118 |
coding | Solve the programming task below in a Python markdown code block.
You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.
For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it i... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "3 3 2\nzyx\n", "3 2 3\nejt\n", "3 2 2\nzyx\n", "3 2 3\nzyx\n", "3 2 2\naaa\n"], "outputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\nzyx\n", "1\nejt\n", "-1\n", "1\nzyx\n", "-1\n"]} | 352 | 137 |
coding | Solve the programming task below in a Python markdown code block.
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of t... | {"inputs": ["3\n2\n0\n2", "3\n2\n1\n2", "3\n0\n0\n3", "3\n1\n8\n1", "3\n2\n8\n0", "3\n2\n3\n1", "3\n2\n3\n2", "3\n2\n8\n2"], "outputs": ["4\n", "5\n", "3\n", "9\n", "8\n", "6\n", "7\n", "12\n"]} | 321 | 111 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
We call a subarray of an array complete if the following condition is satisfied:
The number of distinct elements in the subarray is equal to the number of ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,1,2,2]) == 4\n assert candidate(nums = [5,5,5,5]) == 10\n\n\ncheck(Solution().countCompleteSubarrays)"} | 120 | 60 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
Notes
Constraints
* Elements in S is sorted in ascending order
* n ≤ 100000
* ... | {"inputs": ["3\n2 2 3\n1\n5", "3\n1 2 3\n1\n4", "3\n1 2 4\n1\n4", "3\n2 2 4\n1\n4", "3\n2 2 5\n1\n4", "3\n0 2 5\n1\n4", "3\n1 2 5\n1\n4", "3\n1 4 5\n1\n4"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]} | 232 | 142 |
coding | Solve the programming task below in a Python markdown code block.
A string is said to be a child of a another string if it can be formed by deleting 0 or more characters from the other string. Letters cannot be rearranged. Given two strings of equal length, what's the longest string that can be constructed such that... | {"inputs": ["AA\nBB\n", "HARRY\nSALLY\n", "ABCDEF\nFBDAMN\n", "SHINCHAN\nNOHARAAA\n"], "outputs": ["0\n", " 2\n", "2\n", "3\n"]} | 493 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Due to another of his misbehaved,
the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates,
assigned him th... | {"functional": "_inputs = [[100], [300], [303], [50000], ['n'], [3.14], [0], [-10]]\n_outputs = [[5050], [45150], [46056], [1250025000], [None], [None], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_t... | 303 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Recently Vova found $n$ candy wrappers. He remembers that he bought $x$ candies during the first day, $2x$ candies during the second day, $4x$ candies during the third day, $\dots$, $2^{k-1} x$ candies during the $k$-th day. But there is an issue: Vova r... | {"inputs": ["1\n6\n", "1\n7\n", "1\n6\n", "1\n7\n", "1\n9\n", "1\n3\n", "1\n14\n", "1\n27\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "3\n", "1\n", "2\n", "9\n"]} | 698 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Gildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of $n$ rows and $n$ columns of square cells. The rows are numbered from $1$ to $n$, from top to bottom, and the columns are numbered from $1$... | {"inputs": ["1 1\nB\n", "1 1\nW\n", "1 1\nW\n", "1 1\nB\n", "2 2\nBW\nWB\n", "2 1\nWW\nWW\n", "2 1\nBB\nWW\n", "2 1\nBB\nBB\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "4\n", "4\n", "2\n", "0\n"]} | 721 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7.
gcd here m... | {"inputs": ["3 9\n", "5 8\n", "1 8\n", "1 9\n", "1 1\n", "1 1\n", "1 9\n", "1 8\n"], "outputs": ["3\n", "0\n", "120\n", "252\n", "1\n", "1\n", "252\n", "120\n"]} | 220 | 94 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).
Given an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.
Please com... | {"functional": "def check(candidate):\n assert candidate(matrix = [[1,2,3],[3,1,2],[2,3,1]]) == True\n assert candidate(matrix = [[1,1,1],[1,2,3],[1,2,3]]) == False\n\n\ncheck(Solution().checkValid)"} | 96 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is attending math classes. On each day, the teacher gives him homework. Yesterday, the teacher gave Chef a sequence of positive integers and ask... | {"inputs": ["3\n2\n2 8\n3 \n8 2 8\n3\n9 10 11"], "outputs": ["7\n10\n18"]} | 600 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Chef's current rating is X, and he wants to improve it. It is generally recommended that a person with rating X should solve problems whose difficulty lies in the range [X, X+200], i.e, problems whose difficulty is at least X and at most X+200.
You find... | {"inputs": ["5\n1300 1500\n1201 1402\n300 4000\n723 805\n1330 512\n"], "outputs": ["YES\nNO\nNO\nYES\nNO\n"]} | 667 | 68 |
coding | Solve the programming task below in a Python markdown code block.
In order to write a string, Atilla needs to first learn all letters that are contained in the string.
Atilla needs to write a message which can be represented as a string $s$. He asks you what is the minimum alphabet size required so that one can write ... | {"inputs": ["5\n1\na\n4\ndown\n10\ncodeforces\n3\nbcf\n5\nzzzzz\n"], "outputs": ["1\n23\n19\n6\n26\n"]} | 400 | 52 |
coding | Solve the programming task below in a Python markdown code block.
Isaac has to buy a new HackerPhone for his girlfriend Amy. He is exploring the shops in the town to compare the prices whereupon he finds a shop located on the first floor of a building, that has a unique pricing policy. There are N steps leading to the ... | {"inputs": ["3\n1 \n1\n2\n", "4\n1 \n2\n2\n2\n"], "outputs": ["2.0\n", "3.5\n"]} | 416 | 42 |
coding | 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, you are asked to construct the array ans of size n-k+1 where ans[i] is the number of distinct numbers in the subarray nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,2,2,1,3], k = 3) == [3,2,2,2,3]\n assert candidate(nums = [1,1,1,1,2,3,4], k = 4) == [1,2,3,4]\n\n\ncheck(Solution().distinctNumbers)"} | 121 | 93 |
coding | Solve the programming task below in a Python markdown code block.
I decided to plant vegetables in the vegetable garden. There were n seeds, so I sown n seeds one by one a day over n days. All seeds sprout and grow quickly. I can't wait for the harvest time.
One day, when I was watering the seedlings as usual, I notic... | {"inputs": ["5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 7\n0", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 8\n0", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 5\n0", "5\n1 2 3 9 4 5\n6\n1 3... | 453 | 462 |
coding | Solve the programming task below in a Python markdown code block.
Chef is playing a game which contains a binary string.
He can perform one operation only:
- Toggle the i_th bit of the string (0 to 1 or 1 to 0)
By performing operations on the string (can be zero times), you have to convert the string with no adjacent ... | {"inputs": ["1\n4\n1011"], "outputs": ["1"]} | 217 | 19 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to gift pairs to his friends this new year. But his friends like good pairs
only.
A pair (a , b) is called a good pair if 1 <= a < b <= N such that GCD(a*b , P) = 1.
Since Chef is busy in preparation for the party, he wants your help to find a... | {"inputs": ["2\n2 3\n3 3\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014"], "outputs": ["1\n1"]} | 211 | 223 |
coding | Solve the programming task below in a Python markdown code block.
There is a hallway of length $N-1$ and you have $M$ workers to clean the floor. Each worker is responsible for segment $[L_{i}, R_{i}]$, i.e., the segment starting at $L_{i}$ and ending at $R_{i}$. The segments might overlap.
Every unit of length of th... | {"inputs": ["3\n10 3\n1 10\n1 5\n6 10\n10 1\n2 10\n10 2\n5 10\n1 5"], "outputs": ["3\n-1\n5"]} | 630 | 60 |
coding | Solve the programming task below in a Python markdown code block.
For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) ≥ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 w... | {"inputs": ["1\n8\n1 2 2 2 4 4 4 5\n", "1\n6\n1 2 2 2 4 4 4 5\n", "1\n6\n1 1 2 2 4 4 4 5\n", "1\n9\n2 4 3 2 1 2 3 4 5\n", "1\n9\n2 4 4 2 1 2 3 4 5\n", "1\n9\n2 4 4 2 2 2 3 4 5\n", "1\n9\n2 4 4 2 2 2 3 3 5\n", "1\n9\n2 4 4 2 2 2 3 1 5\n"], "outputs": ["YES\n4 5\n", "YES\n4 5\n", "YES\n4 5\n", "YES\n1 2\n", "YES\n1 2\n",... | 541 | 256 |
coding | 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"]} | 676 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese .
You are given two strings A and B of the same length. Each string contains N Lower case Latin character (from 'a' to 'z'). A shift operation will remove the first character of a string and add the same cha... | {"inputs": ["5\nccadd\nbddcc", "5\nccade\nbddcc", "5\nccade\nccdcb", "5\nddacc\nbddcc", "5\nddacc\nccddb", "5\nccade\nbcdcc", "5\ncacde\nccdcb", "5\nc`cde\nccdcb"], "outputs": ["3", "3\n", "0\n", "1\n", "2\n", "3\n", "0\n", "0\n"]} | 285 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Arrow is getting paranoid about Malcom merlyn, his arch-enemy. All his efforts to subdue Merlyn have been in vain. These days Arrow is working on a problem with John Diggle. Diggle mentioned that the Felicity has been facing weird problem with their supe... | {"inputs": ["4\n1\n3\n5\n11"], "outputs": ["-1\n555\n33333\n55555533333"]} | 455 | 44 |
coding | Solve the programming task below in a Python markdown code block.
#### Background:
A linear regression line has an equation in the form `$Y = a + bX$`, where `$X$` is the explanatory variable and `$Y$` is the dependent variable. The parameter `$b$` represents the *slope* of the line, while `$a$` is called the *inte... | {"functional": "_inputs = [[[25, 30, 35, 40, 45, 50], [78, 70, 65, 58, 48, 42]], [[56, 42, 72, 36, 63, 47, 55, 49, 38, 42, 68, 60], [147, 125, 160, 118, 149, 128, 150, 145, 115, 140, 152, 155]], [[0, 10, 20, 30, 40], [0.51, 0.55, 0.57, 0.59, 0.63]]]\n_outputs = [[[114.381, -1.4457]], [[80.7777, 1.138]], [[0.514, 0.0028... | 574 | 402 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have the same color as you?" and collected the answers in an integer array answers where answers[i] is the answer of the ith ra... | {"functional": "def check(candidate):\n assert candidate(answers = [1,1,2]) == 5\n assert candidate(answers = [10,10,10]) == 11\n\n\ncheck(Solution().numRabbits)"} | 115 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed.
For example, when an array is passed like `[19, 5, 42, 2, 77]`, the output should... | {"functional": "_inputs = [[[5, 8, 12, 18, 22]], [[7, 15, 12, 18, 22]], [[25, 42, 12, 18, 22]], [[1, 8, 12, 18, 5]], [[13, 12, 5, 61, 22]]]\n_outputs = [[13], [19], [30], [6], [17]]\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_t... | 157 | 263 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:
0 <= i < j < k < nums.length
nums[i], nums[j], and nums[k] are pairwise distinct.
... | {"functional": "def check(candidate):\n assert candidate(nums = [4,4,2,4,3]) == 3\n assert candidate(nums = [1,1,1,1,1]) == 0\n\n\ncheck(Solution().unequalTriplets)"} | 146 | 61 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$, and an integer $x$. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was $[3, 6, ... | {"inputs": ["1\n1 1\n1\n", "1\n1 1\n1\n", "1\n1 1\n0\n", "1\n1 171\n1\n", "1\n1 1234\n1\n", "1\n1 1234\n1\n", "2\n3 3\n3 6 9\n3 3\n6 4 11\n", "1\n4 2\n2 2655 6548 2082\n"], "outputs": ["1 1\n", "1 1\n", "0 0\n", "1 1\n", "1 1\n", "1 1\n", "6 6\n7 8\n", "5644 5644\n"]} | 627 | 182 |
coding | Solve the programming task below in a Python markdown code block.
The Tower of Hanoi is a famous game consisting of $3$ rods and a number of discs of incrementally different diameters. The puzzle starts with the discs neatly stacked on one rod, ordered by ascending size with the smallest disc at the top. The game's obj... | {"inputs": ["3\n1 4 1\n"], "outputs": ["3\n"]} | 652 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Cirno_9baka has a paper tape with $n$ cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with $m$ kinds of colors. For some aesthetic reasons, he thinks that the $i$-th color must be used exactly $a_i$... | {"inputs": ["1\n7 3 3\n3 3 1\n", "1\n12 5 5\n3 3 3 2 1\n", "2\n12 6 2\n1 1 1 1 1 7\n12 6 2\n2 2 2 2 2 2\n", "10\n2 1 1\n2\n2 1 1\n2\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n2 1 1\n2\n1 1 1\n1\n1 1 1\n1\n2 1 1\n2\n2 1 1\n2\n", "10\n1 1 1\n1\n1 1 1\n1\n2 1 1\n2\n2 1 1\n2\n2 1 1\n2\n2 1 1\n2\n2 1 1\n2\n2 1 1\n2\n1 1 1\n1\n2 1 1\n2\... | 569 | 313 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.
A point of the cheese with index i (0-indexed) is:
reward1[i] if the first mouse eats it.
reward2[i] if th... | {"functional": "def check(candidate):\n assert candidate(reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2) == 15\n assert candidate(reward1 = [1,1], reward2 = [1,1], k = 2) == 2\n\n\ncheck(Solution().miceAndCheese)"} | 164 | 89 |
coding | 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 candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.
... | {"functional": "def check(candidate):\n assert candidate(candies = [5,8,6], k = 3) == 5\n assert candidate(candies = [2,5], k = 11) == 0\n\n\ncheck(Solution().maximumCandies)"} | 159 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Consider the prime number `23`. If we sum the square of its digits we get:
`2^2 + 3^2 = 13`, then for `13: 1^2 + 3^2 = 10`, and finally for `10: 1^2 + 0^2 = 1`.
Similarly, if we start with prime number `7`, the sequence is: `7->49->97->130->10->1`.
Gi... | {"functional": "_inputs = [[1, 25], [100, 1000], [100, 2000], [100, 3000], [100, 4000]]\n_outputs = [[4], [28], [47], [65], [95]]\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, tu... | 281 | 218 |
coding | Solve the programming task below in a Python markdown code block.
Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence $s$ of length $2 n$.
Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of $2 n$ vertices using the balanced bracket sequence $s$. For any t... | {"inputs": ["4\n1\n()\n3\n()(())\n3\n((()))\n4\n(())(())\n"], "outputs": ["1\n2\n3\n3\n"]} | 576 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Alexey is trying to develop a program for a very simple microcontroller. It makes readings from various sensors over time, and these readings must happen at specific regular ... | {"inputs": ["3\n3\n2 3 5\n4\n1 8 7 11\n4\n4 4 5 6"], "outputs": ["6\n7\n4"]} | 585 | 45 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals di... | {"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4], difference = 1) == 4\n assert candidate(arr = [1,3,5,7], difference = 1) == 1\n assert candidate(arr = [1,5,7,8,5,3,4,2,1], difference = -2) == 4\n\n\ncheck(Solution().longestSubsequence)"} | 119 | 100 |
coding | Solve the programming task below in a Python markdown code block.
Sunake is in the form of a polygonal line consisting of n vertices (without self-intersection). First, Sunake-kun's i-th vertex is at (xi, yi). You can move continuously by translating or rotating, but you cannot deform (change the length of the polygona... | {"inputs": ["4\n0 1\n1 1\n1 2\n3 2", "4\n0 2\n1 1\n1 2\n3 2", "4\n0 2\n1 1\n2 2\n3 2", "4\n0 1\n1 1\n1 2\n2 2", "11\n124 186\n8 143\n6 675\n0 186\n248 50\n-3 561\n154 66\n13 19\n37 0\n1 294\n1 30", "11\n124 186\n8 143\n6 675\n0 186\n248 50\n-3 561\n154 66\n13 19\n51 0\n1 294\n1 30", "11\n124 186\n0 143\n6 675\n0 186\n2... | 352 | 405 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given an array of integers whose elements have both a negative and a positive value, except for one integer that is either only negative or only positive. Your task will be to find that integer.
Examples:
`[1, -1, 2, -2, 3] =... | {"functional": "_inputs = [[[1, -1, 2, -2, 3]], [[-3, 1, 2, 3, -1, -4, -2]], [[1, -1, 2, -2, 3, 3]], [[-110, 110, -38, -38, -62, 62, -38, -38, -38]], [[-9, -105, -9, -9, -9, -9, 105]]]\n_outputs = [[3], [-4], [3], [-38], [-9]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, flo... | 185 | 284 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts ... | {"functional": "def check(candidate):\n assert candidate(n = 4, rounds = [1,3,1,2]) == [1,2]\n assert candidate(n = 2, rounds = [2,1,2,1,2,1,2,1,2]) == [2]\n assert candidate(n = 7, rounds = [1,3,5,7]) == [1,2,3,4,5,6,7]\n\n\ncheck(Solution().mostVisited)"} | 174 | 115 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these bu... | {"functional": "def check(candidate):\n assert candidate(buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]) == [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\n assert candidate(buildings = [[0,2,3],[2,5,3]]) == [[0,3],[5,0]]\n\n\ncheck(Solution().getSkyline)"} | 366 | 137 |
coding | Solve the programming task below in a Python markdown code block.
This is an easier version of the problem. In this version $n \le 1000$
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "3\n4 3 8\n", "3\n10 6 8\n", "3\n10 3 8\n", "3\n4 3 16\n", "3\n4 6 16\n"], "outputs": ["1 \n", "1\n", "2\n", "3 3 8\n", "10 6 6 \n", "10 3 3\n", "3 3 16\n", "4 6 16\n"]} | 675 | 136 |
coding | Solve the programming task below in a Python markdown code block.
There is a contest containing 2 problems A and B.
2 strong participants P and Q participated in the contest and solved both the problems.
P made AC submissions on problems A and B at time instants P_{A} and P_{B} respectively while Q made AC submissio... | {"inputs": ["4\n5 10 2 12\n10 30 15 15\n20 8 4 20\n6 6 6 6\n"], "outputs": ["P\nQ\nTIE\nTIE\n"]} | 571 | 62 |
coding | Solve the programming task below in a Python markdown code block.
In ChefLand, there is a mountain range consisting of $N$ hills (numbered $1$ through $N$) in a straight line. Let's denote the height of the $i$-th hill from the left by $h_i$.
Ada is working on the water supply system of ChefLand. On some of the hills, ... | {"inputs": ["1\n6\n4 16 32 6 8 2\n"], "outputs": ["2 "]} | 517 | 31 |
coding | Solve the programming task below in a Python markdown code block.
C: Prayer (Pray)
Some twins are famous for praying before the contest.
There are four integers $ H, W, X, Y $, and it seems unlucky if $ H \ times W $ and $ x + y $ are both odd numbers.
input
Four integers $ H, W, X, Y $ are given, separated by spac... | {"inputs": ["3 5 2 4", "3 9 1 4", "1 6 1 1", "1 6 0 1", "1 6 0 0", "1 3 0 1", "1 0 0 1", "0 0 0 1"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n"]} | 273 | 110 |
coding | Solve the programming task below in a Python markdown code block.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the locati... | {"inputs": ["10\n9 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n10\n2 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n0", "10\n9 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 1\n5 3\n0 5\n5 2\n10\n2 4\n4 3\n1 1\n4 2\n2 4\n5 8\n4 0\n5 3\n0 5\n5 2\n0", "10\n9 4\n4 4\n1 1\n4 2\n2 5\n5 8\n4 1\n5 3\n0 5\n5 2\n10\n2 4\n4 3\n1 1\n4 2\n2 4... | 535 | 774 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.