problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.
The first node is considered odd, and the second node is ev... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5])), list_node([1,3,5,2,4]))\n assert is_same_list(candidate(head = list_node([2,1,3,5,6,4,7])), list_node([2,3,6,7,1,5,4]))\n\n\ncheck(Solution().oddEvenList)"} | coding | 184 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array receiver of length n and an integer k. n players are playing a ball-passing game.
You choose the starting player, i. The game proceeds as follows: player i passes the ball to player rece... | {"functional": "def check(candidate):\n assert candidate(receiver = [2,0,1], k = 4) == 6\n assert candidate(receiver = [1,1,1,2,3], k = 3) == 10\n\n\ncheck(Solution().getMaxFunctionValue)"} | coding | 189 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A maximum tree is a tree where every node has a value greater than any other value in its subtree.
You are given the root of a maximum binary tree and an integer val.
Just as in the previous problem, the given tree wa... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,1,3,None,None,2]), val = 5), tree_node([5,4,None,1,3,None,None,2]))\n assert is_same_tree(candidate(root = tree_node([5,2,4,None,1]), val = 3), tree_node([5,2,4,None,1,None,3]))\n assert is_same_tree(candidate(root = tree... | coding | 311 |
Solve the programming task below in a Python markdown code block.
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from ... | {"inputs": ["3\nAAA\nBABA\nAABBBABBBB\n", "3\nAAA\nAABA\nAABBBABBBB\n", "3\nAAB\nBABA\nAABBBABBBB\n", "3\nAAB\nBABA\nBBBBABBBAA\n", "3\nAAB\nBAAA\nBBBBABBBAA\n", "3\nAAA\nBABB\nAABBBABBBB\n", "3\nAAB\nABAB\nBBBBABBBAA\n", "3\nBAA\nBAAA\nBBBBABBBAA\n"], "outputs": ["3\n2\n0\n", "3\n2\n0\n", "1\n2\n0\n", "1\n2\n2\n", "1\... | coding | 438 |
Solve the programming task below in a Python markdown code block.
The chef is trying to decode 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 ... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678"]} | coding | 216 |
Solve the programming task below in a Python markdown code block.
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions: the length of... | {"inputs": ["4 3\n", "6 6\n", "5 2\n", "3 2\n", "3 3\n", "6 3\n", "6 2\n", "4 2\n"], "outputs": ["abca\n", "abcdef\n", "ababa\n", "aba\n", "abc\n", "abcabc\n", "ababab\n", "abab\n"]} | coding | 386 |
Solve the programming task below in a Python markdown code block.
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.
Only Japanese students or overseas students can pass the Qualification contests. The s... | {"inputs": ["5 4 2\nccccc", "5 2 2\nccbcc", "5 2 2\nccccc", "10 2 0\nabccabaabb", "10 1 0\nabccabaabb", "10 2 1\nabccabaabb", "10 2 1\nbbaacaccba", "10 1 3\nabccabaabb"], "outputs": ["No\nNo\nNo\nNo\nNo\n", "No\nNo\nYes\nNo\nNo\n", "No\nNo\nNo\nNo\nNo", "Yes\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nNo\nNo\n", "Yes\nNo\nNo\nNo\nNo... | coding | 465 |
Solve the programming task below in a Python markdown code block.
You are given two positive integers N and K. How many multisets of rational numbers satisfy all of the following conditions?
- The multiset has exactly N elements and the sum of them is equal to K.
- Each element of the multiset is one of 1, \frac{1}{2... | {"inputs": ["4 2\n", "1 1\n", "2 1\n", "2 2\n", "3 1\n", "6 4\n", "88 11\n", "97 24\n"], "outputs": ["2\n", "1\n", "1\n", "1\n", "1\n", "2\n", "843932061\n", "120274922\n"]} | coding | 301 |
Solve the programming task below in a Python markdown code block.
You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest.... | {"inputs": ["1 2 4\nST\n", "1 2 1\nST\n", "1 3 3\nSaT\n", "2 1 4\nS\nT\n", "2 1 1\nS\nT\n", "1 3 2\nTyS\n", "1 3 2\nTzS\n", "1 3 3\nTyS\n"], "outputs": ["\n", "\n", "a\n", "\n", "\n", "y\n", "z\n", "y\n"]} | coding | 592 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.
Remove any number of beans (possibly none) from each bag such that the number... | {"functional": "def check(candidate):\n assert candidate(beans = [4,1,6,5]) == 4\n assert candidate(beans = [2,10,3,2]) == 7\n\n\ncheck(Solution().minimumRemoval)"} | coding | 146 |
Solve the programming task below in a Python markdown code block.
As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.
The «Two Paths» company, where Bob's brothe... | {"inputs": ["2\n2 1\n", "3\n1 3\n2 1\n", "3\n3 1\n1 2\n", "3\n2 3\n2 1\n", "3\n3 2\n1 2\n", "4\n3 2\n3 4\n1 4\n", "4\n2 3\n1 3\n2 4\n", "4\n4 2\n2 3\n2 1\n"], "outputs": ["0", "0", "0", "0\n", "0\n", "1", "1", "0"]} | coding | 365 |
Solve the programming task below in a Python markdown code block.
A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible.
INPUT
First line is T, ... | {"inputs": ["6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii"], "outputs": ["38\n51\n9\n1\n77\n95"]} | coding | 184 |
Solve the programming task below in a Python markdown code block.
Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.
Johnny's truck has a gas tank that holds exactly n liters,... | {"inputs": ["16 5 2\n8 2\n5 1\n", "16 5 2\n8 2\n2 1\n", "16 5 2\n8 2\n5 1\n", "153 8 1\n96 83995\n", "200 8 1\n96 83995\n", "153 40 1\n96 83995\n", "153 11 1\n96 83995\n", "153 11 1\n96 74103\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 523 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is given an array A consisting of N positive integers. Chef shuffles the array A and creates a new array B of length N, where B_{i} = (A_{i} + i) \bmod 2... | {"inputs": ["3\n3\n1 2 3\n3\n2 4 5\n2\n2 4\n"], "outputs": ["2\n3\n1"]} | coding | 591 |
Solve the programming task below in a Python markdown code block.
You know combinations: for example,
if you take 5 cards from a 52 cards deck you have 2,598,960 different combinations.
In mathematics the number of x combinations you can take from a set of n elements
is called the binomial coefficient of n and x, or ... | {"functional": "_inputs = [[1, 6], [6, 4], [4, 4], [4, 2], [35, 7], [36, 7], [184756, 20], [184756, 10], [3268760, 25], [155117520, 30], [155117530, 30]]\n_outputs = [[0], [2], [1], [-1], [3], [-1], [10], [-1], [10], [15], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f... | coding | 658 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.
When you visit a room, you... | {"functional": "def check(candidate):\n assert candidate(rooms = [[1],[2],[3],[]]) == True\n assert candidate(rooms = [[1,3],[3,0,1],[2],[0]]) == False\n\n\ncheck(Solution().canVisitAllRooms)"} | coding | 183 |
Solve the programming task below in a Python markdown code block.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can t... | {"inputs": ["1", "2", "4", "9", "3", "7", "5", "6"], "outputs": ["1\n", "2\n", "3\n", "4\n", "2\n", "3\n", "3\n", "3\n"]} | coding | 264 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums and two positive integers m and k.
Return the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.
A subarray of nums is almost ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,6,7,3,1,7], m = 3, k = 4) == 18\n assert candidate(nums = [5,9,9,2,4,5,4], m = 1, k = 3) == 23\n assert candidate(nums = [1,2,1,2,1,2,1], m = 3, k = 3) == 0\n\n\ncheck(Solution().maxSum)"} | coding | 131 |
Solve the programming task below in a Python markdown code block.
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left. An 'R' indicates he should move one unit right. A 'U' indicates he s... | {"inputs": ["R\n", "R\n", "LR\n", "UL\n", "UD\n", "LU\n", "RR\n", "LR\n"], "outputs": ["-1\n", "-1\n", "0\n", "1\n", "0\n", "1\n", "1\n", "0\n"]} | coding | 415 |
Solve the programming task below in a Python markdown code block.
For a positive integer X, let f(X) be the number of positive divisors of X.
Given a positive integer N, find \sum_{K=1}^N K\times f(K).
-----Constraints-----
- 1 \leq N \leq 10^7
-----Input-----
Input is given from Standard Input in the following form... | {"inputs": ["7", "0", "5", "6", "4", "4\n", "1\n", "110"], "outputs": ["71\n", "0\n", "33\n", "57\n", "23", "23\n", "1\n", "32807\n"]} | coding | 186 |
Solve the programming task below in a Python markdown code block.
In the 2-D world of Flatland, the Circles were having their sports day and wanted to end it with a nice formation. So, they called upon Mr. Sphere from Spaceland for help. Mr Sphere decides to arrange the Circles in square formations. He starts with $N$ ... | {"inputs": ["2\n85\n114"], "outputs": ["2\n4"]} | coding | 289 |
Solve the programming task below in a Python markdown code block.
Chef spent N days working really hard! He planned loads of tasks: as many as Ai tasks to do on the ith day! Chef's work was brutal, so he only managed to finish Bi tasks on the ith day.
The good news is that Chef has a Time Machine!
The Time Machine has... | {"inputs": ["1\n4 2 2\n5 7 6 1\n3 3 1 1\n6 3\n1 4"], "outputs": ["3"]} | coding | 720 |
Solve the programming task below in a Python markdown code block.
In Uttu's college, a semester is said to be a:
Overload semester if the number of credits taken > 65.
Underload semester if the number of credits taken < 35.
Normal semester otherwise
Given the number of credits X taken by Uttu, determine whether the s... | {"inputs": ["4\n65\n80\n23\n58\n"], "outputs": ["Normal\nOverload\nUnderload\nNormal\n"]} | coding | 393 |
Solve the programming task below in a Python markdown code block.
Hardutta is planning an inter college football league. He has invited n teams, including our own team from BPHC. Now, one of the organizers Ramehta was hell bent on knowing one thing : How many matches will all the teams play in their home kit and how ma... | {"inputs": ["6\n2 3\n2 1\n2 1\n3 2\n3 2\n3 1", "3\n1 100000\n1 100000\n100000 2", "30\n1 10\n1 7\n6 10\n2 6\n10 2\n1 8\n3 8\n10 2\n7 4\n10 4\n9 1\n3 7\n1 8\n2 5\n3 4\n2 7\n3 1\n6 9\n8 10\n4 1\n5 1\n7 8\n6 7\n9 8\n7 3\n6 2\n9 1\n7 1\n8 9\n9 6", "73\n11 46\n78 14\n79 84\n3 7\n77 94\n67 62\n2 12\n12 46\n17 21\n89 35\n68 2... | coding | 422 |
Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $m$. You have to construct the array $a$ of length $n$ consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly $m$ and the value $\sum\lim... | {"inputs": ["1\n5 1\n", "1\n53 5\n", "1\n60 2\n", "1\n60 2\n", "1\n53 5\n", "1\n2 33\n", "1\n60 1\n", "1\n1 33\n"], "outputs": ["2\n", "10\n", "4\n", "4\n", "10\n", "33\n", "2\n", "0\n"]} | coding | 629 |
Solve the programming task below in a Python markdown code block.
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.
Input
jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.
Output
ekjfkj q iydwbu dkcruh.
Examp... | {"inputs": ["5\n", "6\n", "8\n", "3\n", "9\n", "2\n", "4\n", "7\n"], "outputs": ["71\n", "73\n", "97\n", "31\n", "107\n", "17\n", "37\n", "79\n"]} | coding | 147 |
Solve the programming task below in a Python markdown code block.
## Objective
Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Write a function that takes `n` and returns it's sXORe.
## Exampl... | {"functional": "_inputs = [[0], [1], [2], [50], [1000000], [1000001], [9999999999999999999999999]]\n_outputs = [[0], [1], [3], [51], [1000000], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if... | coding | 175 |
Solve the programming task below in a Python markdown code block.
Description
THE BY DOLM @ STER is a training simulation game scheduled to be released on EXIDNA by 1rem on April 1, 2010. For the time being, it probably has nothing to do with an arcade game where the network connection service stopped earlier this mon... | {"inputs": ["3 10\nDobkeradops\n7 3 18 0\nPaatQata\n1 0 6 1\ndop\n5 9 28 13\n2 2\nBydp syStem ahplA\n7 11 4 0\nFedrn Infermo\n243 80 32 80", "3 10\nDobkesadops\n7 1 18 0\nPaatQaua\n1 0 0 1\ndop\n8 9 28 13\n2 3\nBydp syStem ahplA\n20 1 4 0\nEedrn Infeqmo\n438 102 15 80", "3 18\nDobkesadops\n7 1 18 0\nPaatQaua\n1 0 0 1\n... | coding | 557 |
Solve the programming task below in a Python markdown code block.
Chef has an array of N integers. Chef can rearrange this array in any manner.
Chef doesn’t like the array if any two adjacent elements are equal. Determine whether there exists a rearrangement of the array that Chef likes.
------ Input Format ------
... | {"inputs": ["2\n5\n1 1 1 1 1\n3\n3 3 4\n"], "outputs": ["No\nYes\n"]} | coding | 363 |
Solve the programming task below in a Python markdown code block.
You are given an array A consisting of N positive integers and a positive integer K.
Find whether there exists a *subset* S of the elements of A such that the product of all elements of S is divisible by K.
Note that a *subset* is obtained by deleting ... | {"inputs": ["3\n2 2\n7 8\n5 3\n1 1 2 1 1\n3 6\n7 2 3\n"], "outputs": ["YES\nNO\nYES"]} | coding | 449 |
Solve the programming task below in a Python markdown code block.
Given a string, you progressively need to concatenate the first letter from the left and the first letter to the right and "1", then the second letter from the left and the second letter to the right and "2", and so on.
If the string's length is odd dro... | {"functional": "_inputs = [['abc def'], ['CodeWars'], ['CodeWars Rocks'], ['1234567890'], [\"$'D8KB)%PO@s\"]]\n_outputs = [['af1be2cd3'], ['Cs1or2da3eW4'], ['Cs1ok2dc3eo4WR5a 6rs7'], ['101292383474565'], [\"$s1'@2DO38P4K%5B)6\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ... | coding | 138 |
Solve the programming task below in a Python markdown code block.
You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from t... | {"inputs": ["4 2\n1\n1\n2\n6", "4 2\n1\n1\n3\n1", "4 2\n1\n1\n3\n0", "4 2\n1\n4\n3\n0", "3 4\n1\n0\n2\n6", "4 2\n1\n1\n3\n6", "4 2\n1\n2\n3\n0", "4 2\n1\n0\n2\n6"], "outputs": ["6\n", "4\n", "3\n", "5\n", "2\n", "6\n", "3\n", "6\n"]} | coding | 294 |
Solve the programming task below in a Python markdown code block.
Indian National Olympiad in Informatics 2012
You are given a table with 2 rows and N columns. Each cell has an integer in it. The score of such a table is defined as follows: for each column, consider the sum of the two numbers in the column; the maximum... | {"inputs": ["and output corresponding to the example above.\nSample input\n4\n7 1 6 2\nSample output\n9 10 10 11\nNote: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous ... | coding | 620 |
Solve the programming task below in a Python markdown code block.
You are given an undirected graph consisting of $n$ vertices and $n$ edges, where $n$ is divisible by $6$. Each edge has a weight, which is a positive (greater than zero) integer.
The graph has the following structure: it is split into $\frac{n}{3}$ tri... | {"inputs": ["6\n4 2 6 6 6 4\n", "12\n1 3 3 7 8 5 2 2 2 2 4 2\n", "18\n5 8 3 8 9 10 7 10 2 7 3 2 1 10 7 7 8 9\n", "18\n58 40 14 8 86 29 5 50 24 42 96 53 72 54 95 62 30 77\n", "18\n626 619 11 809 967 233 474 747 648 256 397 174 705 695 520 682 402 925\n"], "outputs": ["2\n", "36\n", "20\n", "20\n", "20\n"]} | coding | 543 |
Solve the programming task below in a Python markdown code block.
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect... | {"inputs": ["4 3 0\n1 2\n2 3\n3 4\n2 3", "4 2 2\n2 2\n2 3\n1 4\n2 3", "4 2 2\n1 2\n2 3\n1 4\n1 3", "4 3 1\n1 3\n2 3\n3 4\n2 1", "4 3 0\n0 2\n2 3\n3 4\n2 3", "4 2 2\n2 2\n2 3\n1 4\n3 3", "6 3 0\n0 2\n4 3\n3 4\n5 3", "6 3 0\n0 0\n4 3\n3 4\n5 3"], "outputs": ["1 1 1 1\n", "1 2 2 1\n", "2 1 2 1\n", "2 2 1 1\n", "1 1 1 1\n"... | coding | 469 |
Solve the programming task below in a Python markdown code block.
Check Tutorial tab to know how to to solve.
You are given a string $\mbox{S}$ and width $\boldsymbol{w}$.
Your task is to wrap the string into a paragraph of width $\boldsymbol{w}$.
Function Description
Complete the wrap function in the edito... | {"inputs": ["ABCDEFGHIJKLIMNOQRSTUVWXYZ\n4\n"], "outputs": ["ABCD\nEFGH\nIJKL\nIMNO\nQRST\nUVWX\nYZ\n"]} | coding | 215 |
Solve the programming task below in a Python markdown code block.
Given an array $A$ of length $N$, we can define rotation as follows. If we rotate $A$ to the right, all elements move to the right one unit, and the last element moves to the beginning. That is, it becomes $[A_{N}, A_{1},A_{2},\ldots,A_{N-1}]$. Similarly... | {"inputs": ["2\n1 2\n2\n1 1"], "outputs": ["6\n12"]} | coding | 753 |
Solve the programming task below in a Python markdown code block.
You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other.
Given two strings x a... | {"inputs": ["27\n0!!!\n0\n1\n1!!!\n2!!!\n2\n3!!!\n999999999\n0!\n0\n11!\n40000000\n3!!\n721\n3\n2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n7!!!\n3!!!!\n0!\n2\n1\n2\n0\n0\n3!!!!\n4!!!!\n15!\n999999999\n999999999\n4!!\n7!!!\n5000!!\n40321\n8!\n3!\n5\n5!!\n3!!!\n7!\n3!!\n3!\n7\n6!\n719\n719!!\n6!!!\n6!\n721\n721!!!!\n6... | coding | 218 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).
Return the running sum of nums.
Please complete the following python code precisely:
```python
class Solution:
de... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == [1,3,6,10]\n assert candidate(nums = [1,1,1,1,1]) == [1,2,3,4,5]\n assert candidate(nums = [3,1,2,10,1]) == [3,4,6,16,17]\n\n\ncheck(Solution().runningSum)"} | coding | 85 |
Solve the programming task below in a Python markdown code block.
Make a function that returns the value multiplied by 50 and increased by 6. If the value entered is a string it should return "Error".
Note: in `C#`, you'll always get the input as a string, so the above applies if the string isn't representing a double... | {"functional": "_inputs = [['hello'], [1], [5], [0], [1.2], [3], ['RyanIsCool']]\n_outputs = [['Error'], [56], [256], [6], [66], [156], ['Error']]\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 isinst... | coding | 95 |
Solve the programming task below in a Python markdown code block.
Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.
a + b + c + d = n
Create a program that outputs the number of combinations that satisfy the conditions.
Input
Given multiple datasets. Each datas... | {"inputs": ["2\n0\n8", "2\n0\n1", "2\n1\n8", "2\n2\n8", "2\n1\n1", "2\n4\n8", "2\n1\n2", "2\n4\n1"], "outputs": ["10\n1\n165\n", "10\n1\n4\n", "10\n4\n165\n", "10\n10\n165\n", "10\n4\n4\n", "10\n35\n165\n", "10\n4\n10\n", "10\n35\n4\n"]} | coding | 158 |
Solve the programming task below in a Python markdown code block.
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the... | {"inputs": ["C>A\nC<B\nB>A\n", "C<B\nB<A\nC>A\n", "C<B\nB>A\nA<C\n", "A>C\nC>B\nB<A\n", "C<B\nC<A\nB<A\n", "A>B\nC>B\nA<C\n", "A>C\nC<B\nB>A\n", "B>A\nC<A\nC>B\n"], "outputs": ["ACB\n", "Impossible\n", "ACB\n", "BCA\n", "CBA\n", "BAC\n", "CAB\n", "Impossible\n"]} | coding | 294 |
Solve the programming task below in a Python markdown code block.
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1... | {"inputs": ["3 4\n1 2 7\n", "2 0\n182 2\n", "3 8\n1 2 7\n", "3 1\n2 2 2\n", "4 0\n1 4 4 4\n", "4 0\n1 4 4 7\n", "4 0\n1 4 5 7\n", "4 1\n1 1 4 2\n"], "outputs": ["1\n", "180\n", "1\n", "0\n", "3\n", "6\n", "6\n", "2\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of card... | {"inputs": ["1\n8\n", "1\n8\n", "1\n7\n", "1\n6\n", "2\n5 4\n", "2\n5 4\n", "2\n5 1\n", "2\n5 2\n"], "outputs": ["1", "1", "1\n", "1\n", "2", "2", "2\n", "2\n"]} | coding | 520 |
Solve the programming task below in a Python markdown code block.
There is data that records the customer number of the business partner and the trading date on a monthly basis. Please create a program that reads this month's data and last month's data and outputs the customer number of the company with which you have ... | {"inputs": ["123,10\n56,12\n35,14\n\n123,3\n56,4\n123,5", "123,10\n56,12\n45,13\n\n113,4\n56,4\n123,5", "132,10\n56,12\n45,13\n\n113,4\n56,4\n123,5", "123,10\n51,62\n34,14\n\n124,3\n56,4\n123,5", "123,10\n65,12\n34,14\n\n123,3\n56,4\n123,5", "123,10\n57,12\n35,14\n\n123,3\n57,4\n123,5", "0032,1\n56,12\n21,45\n\n12,34\n... | coding | 261 |
Solve the programming task below in a Python markdown code block.
C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ tha... | {"inputs": ["332\n++a\n", "4\n0*a++\n", "332\na++\n", "1000\n++a\n", "1000\na++\n", "584\n7*++a\n", "584\n6*++a\n", "584\n5*++a\n"], "outputs": ["333\n", "0\n", "332\n", "1001\n", "1000\n", "4095\n", "3510\n", "2925\n"]} | coding | 619 |
Solve the programming task below in a Python markdown code block.
Petya is preparing a problem for a local contest in his school. The problem is to find a longest increasing subsequence in a given permutation. A permutation of size n$n$ is a sequence of n$n$ numbers a1,…,an$a_1, \ldots, a_n$ such that every number from... | {"inputs": ["2\n3 2\n1 2\n2 1\n1"], "outputs": ["YES\n2 3 1\nNO"]} | coding | 707 |
Solve the programming task below in a Python markdown code block.
Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.
However, if the result exceeds 10^{18}, print -1 instead.
-----Constraints-----
- 2 \leq N \leq 10^5
- 0 \leq A_i \leq 10^{18}
- All values in input are integers.
-----Input-----
Inp... | {"inputs": ["3\n011 1 315218201", "3\n001 188 468791915", "3\n011 188 468791915", "3\n011 291 468791915", "3\n011 133 468791915", "3\n011 133 735631313", "3\n011 133 315218201", "3\n101 2947 468791915"], "outputs": ["3467400211\n", "88132880020\n", "969461680220\n", "1500602919915\n", "685842571645\n", "1076228610919\n... | coding | 257 |
Solve the programming task below in a Python markdown code block.
Everlasting Sa-Ga, a new, hot and very popular role-playing game, is out on October 19, 2008. Fans have been looking forward to a new title of Everlasting Sa-Ga.
Little Jimmy is in trouble. He is a seven-year-old boy, and he obtained the Everlasting Sa-... | {"inputs": ["4 3\n8 20\n0 0", "8 3\n8 20\n0 0", "4 3\n6 20\n0 0", "6 3\n8 20\n0 0", "6 6\n8 20\n0 0", "9 30\n7 6\n0 0", "4 6\n8 20\n0 0", "6 3\n8 26\n0 0"], "outputs": ["b\nb\n", "b\nb\n", "b\nb\n", "b\nb\n", "b\nb\n", "a\na\n", "a\nb\n", "b\nb\n"]} | coding | 560 |
Solve the programming task below in a Python markdown code block.
Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves.
Print the number of moves needed to transform $n$ to $m$.... | {"inputs": ["1 1\n", "1 2\n", "1 4\n", "1 5\n", "1 6\n", "2 5\n", "4 9\n", "2 7\n"], "outputs": ["0\n", "1\n", "2\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]} | coding | 364 |
Solve the programming task below in a Python markdown code block.
You are playing a game called Guru Guru Gururin. In this game, you can move with the vehicle called Gururin. There are two commands you can give to Gururin: 'R' and 'L'. When 'R' is sent, Gururin rotates clockwise by 90 degrees. Otherwise, when 'L' is se... | {"inputs": ["RL", "QL", "LQ", "KR", "KQ", "QK", "RK", "SK"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 513 |
Solve the programming task below in a Python markdown code block.
Write a function `insertDash(num)`/`InsertDash(int num)` that will insert dashes ('-') between each two odd numbers in num. For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number.
Note that the number will always ... | {"functional": "_inputs = [[454793], [123456], [1003567], [24680], [13579]]\n_outputs = [['4547-9-3'], ['123456'], ['1003-567'], ['24680'], ['1-3-5-7-9']]\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 i... | coding | 114 |
Solve the programming task below in a Python markdown code block.
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of t... | {"inputs": ["1 1\nf\n1 1\n", "1 1\nf\n1 1\n", "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n1 3\n6 4\n", "6 6\nxzyacc\n1 2\n3 1\n2 3\n5 4\n1 3\n6 4\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n"], "outputs": ["... | coding | 482 |
Solve the programming task below in a Python markdown code block.
Three friends are going to meet each other. Initially, the first friend stays at the position $x = a$, the second friend stays at the position $x = b$ and the third friend stays at the position $x = c$ on the coordinate axis $Ox$.
In one minute each fri... | {"inputs": ["5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 2 2\n0 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 4 2\n0 3 3\n4 1 4\n10 5 8\n", "5\n1 1 1\n1 2 2\n3 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 4 0\n0 3 3\n4 4 4\n10 5 8\n", "5\n1 1 1\n2 4 2\n0 3 3\n4 1 4\n10 8 8\n", "5\n1 1... | coding | 586 |
Solve the programming task below in a Python markdown code block.
Chef is a very experienced and well-known cook. He has participated in many cooking competitions in the past — so many that he does not even remember them all.
One of these competitions lasted for a certain number of days. The first day of the competitio... | {"inputs": ["3\nsaturday sunday 2 4\nmonday wednesday 1 20\nsaturday sunday 3 5"], "outputs": ["2\nmany\nimpossible"]} | coding | 456 |
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 even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.
The array nums is complementary if for... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,4,3], limit = 4) == 1\n assert candidate(nums = [1,2,2,1], limit = 2) == 2\n assert candidate(nums = [1,2,1,2], limit = 2) == 0\n\n\ncheck(Solution().minMoves)"} | coding | 172 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed strings str1 and str2.
In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b... | {"functional": "def check(candidate):\n assert candidate(str1 = \"abc\", str2 = \"ad\") == True\n assert candidate(str1 = \"zc\", str2 = \"ad\") == True\n assert candidate(str1 = \"ab\", str2 = \"d\") == False\n\n\ncheck(Solution().canMakeSubsequence)"} | coding | 200 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer num. You will apply the following steps exactly two times:
Pick a digit x (0 <= x <= 9).
Pick another digit y (0 <= y <= 9). The digit y can be equal to x.
Replace all the occurrences of x in... | {"functional": "def check(candidate):\n assert candidate(num = 555) == 888\n assert candidate(num = 9) == 8\n assert candidate(num = 123456) == 820000\n assert candidate(num = 10000) == 80000\n assert candidate(num = 9288) == 8700\n\n\ncheck(Solution().maxDiff)"} | coding | 160 |
Solve the programming task below in a Python markdown code block.
There are league games and tournament games in sports competitions. In soccer league games, points are given to each of the wins, losses, and draws, and the rankings are competed based on the points. The points are win (3 points), negative (0 points), an... | {"inputs": ["4\nJapan 1 0 2\nEgypt 1 2 0\nCanada 0 2 1\nniapS 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 1\nItaly 1 1 1\n0", "4\nJapan 1 0 2\nEgypt 1 2 0\nCaaadn 0 2 1\nniapS 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 1\nItaly 1 1 1\n0", "4\nJapan 1 0 2\nEgypt 1 2 0\nCaaadn 0 2 1\nniapS 2 0 1\n3\nIodia 0 2 0\nPoland 1 0 1\nItaly 1 1 1\n... | coding | 405 |
Solve the programming task below in a Python markdown code block.
Bear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also find the nu... | {"inputs": ["4\n2 3\n1 2\n3 5\n2 4 3\n3 100\n1 3 5\n4 3\n1 2 3 4"], "outputs": ["2 1\n4 2\n9 1\n2 2"]} | coding | 530 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums consisting of n elements, and an integer k.
Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calcula... | {"functional": "def check(candidate):\n assert candidate(nums = [1,12,-5,-6,50,3], k = 4) == 12.75\n assert candidate(nums = [5], k = 1) == 5.00000\n\n\ncheck(Solution().findMaxAverage)"} | coding | 109 |
Solve the programming task below in a Python markdown code block.
### Task:
You have to write a function `pattern` which creates the following pattern (See Examples) upto desired number of rows.
If the Argument is `0` or a Negative Integer then it should return `""` i.e. empty string.
### Examples:
`pattern(9)`:
... | {"functional": "_inputs = [[7], [1], [4], [0], [-25]]\n_outputs = [['1234567\\n2345671\\n3456712\\n4567123\\n5671234\\n6712345\\n7123456'], ['1'], ['1234\\n2341\\n3412\\n4123'], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ... | coding | 271 |
Solve the programming task below in a Python markdown code block.
New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wante... | {"inputs": ["3 2\n1 1\n", "3 2\n2 1\n", "3 3\n1 1\n", "3 3\n2 1\n", "3 2\n2 1\n", "3 3\n2 1\n", "3 2\n1 1\n", "3 3\n1 1\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO", "YES", "YES", "YES"]} | coding | 614 |
Solve the programming task below in a Python markdown code block.
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody g... | {"inputs": ["3 2 1 1\n", "2 4 2 2\n", "1 1 1 1\n", "4 5 2 3\n", "9 7 4 7\n", "5 5 3 2\n", "4 5 2 3\n", "9 7 4 7\n"], "outputs": ["3\n2 1\n3 1\n3 2\n", "0\n", "0\n", "1\n4 3\n", "2\n8 7\n9 7\n", "6\n3 2\n4 2\n4 3\n5 2\n5 3\n5 4\n", "1\n4 3\n", "2\n8 7\n9 7\n"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
You're given an undirected graph with $n$ nodes and $m$ edges. Nodes are numbered from $1$ to $n$.
The graph is considered harmonious if and only if the following property holds: For every triple of integers $(l, m, r)$ such that $1 \le l < m < r \le n... | {"inputs": ["3 1\n1 3\n", "3 1\n1 3\n", "5 1\n1 3\n", "4 1\n1 3\n", "200000 1\n1 200000\n", "200000 1\n1 200000\n", "200000 3\n7 9\n9 8\n4 5\n", "200000 3\n4 9\n9 8\n4 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "199998\n", "199998\n", "0\n", "2\n"]} | coding | 538 |
Solve the programming task below in a Python markdown code block.
An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; R stands for red and W stands for white.
You can do the following two kinds of operations an... | {"inputs": ["2\nRQ", "2\nRS", "2\nRT", "2\nRU", "2\nRP", "2\nRO", "2\nRV", "2\nRN"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 297 |
Solve the programming task below in a Python markdown code block.
You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.
Implement a function `likes :: [String] -> String`, which... | {"functional": "_inputs = [[[]], [['Peter']], [['Jacob', 'Alex']], [['Max', 'John', 'Mark']], [['Alex', 'Jacob', 'Mark', 'Max']]]\n_outputs = [['no one likes this'], ['Peter likes this'], ['Jacob and Alex like this'], ['Max, John and Mark like this'], ['Alex, Jacob and 2 others like this']]\nimport math\ndef _deep_eq(a... | coding | 231 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings words (0-indexed).
In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].
Return ... | {"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"aabc\",\"bc\"]) == True\n assert candidate(words = [\"ab\",\"a\"]) == False\n\n\ncheck(Solution().makeEqual)"} | coding | 119 |
Solve the programming task below in a Python markdown code block.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: th... | {"inputs": ["3\n1 1 1\n", "3\n2 1 1\n", "3\n1 2 1\n", "3\n1 1 2\n", "3\n1 1 0\n", "3\n3 4 2\n", "3\n4 5 5\n", "3\n3 4 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "1\n", "5\n", "7\n", "4\n"]} | coding | 329 |
Solve the programming task below in a Python markdown code block.
On the great island of Baltia, there live N people, numbered from 1 to N. There are exactly M pairs of people that are friends with each other. The people of Baltia want to organize a successful party, but they have very strict rules on what a party is a... | {"inputs": ["5 0\n", "6 3\n1 4\n1 3\n5 1\n", "6 3\n1 2\n4 2\n5 2\n", "6 3\n1 4\n4 2\n5 1\n", "6 3\n1 4\n5 2\n5 4\n", "6 3\n1 2\n4 2\n5 1\n", "6 3\n1 4\n4 3\n5 1\n", "6 3\n1 5\n4 2\n5 4\n"], "outputs": ["1 2 3 4 5\n", "2 3 4 5 6\n", "1 3 4 5 6\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 426 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions:
- There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there shouldn't... | {"inputs": ["3\n1 1\n3\n2 1\n2 2\n5 2\n1 2 3 4 6"], "outputs": ["3\n2\n11"]} | coding | 490 |
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... | coding | 352 |
Solve the programming task below in a Python markdown code block.
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and whi... | {"inputs": ["........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n", "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n", ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.\n", "..BB....\n........\nWW.W..WW\nW...W...\n.W...W..\n.W..W... | coding | 694 |
Solve the programming task below in a Python markdown code block.
There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0, 0). He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. When a com... | {"inputs": ["4\nL\nLUUDR\nLLUU\nDDDUUUUU\n", "4\nL\nUURDL\nLLUU\nDDDUUUUU\n", "4\nL\nUURDL\nLLUU\nUUUUUDDD\n", "4\nL\nLUUDR\nLLUU\nUUUUUDDD\n", "4\nL\nRUUDL\nLLUU\nUUUUUDDD\n", "4\nL\nUULDR\nLLUU\nUDUUUDDU\n", "4\nL\nRDUUL\nUULL\nUUUUUDDD\n", "4\nL\nRUUDL\nLLUU\nUUUUDDDU\n"], "outputs": ["-1 0\n-1 2\n0 0\n0 1\n", "-1 0... | coding | 624 |
Solve the programming task below in a Python markdown code block.
Decompose a number `num` into an array (tuple in Haskell, array of arrays `long[][]` in C# or Java) of the form `[[k1,k2,k3...], r]`, `([k1,k2,k3...], r)` in Haskell, `[[k1,k2,k3...], [r]]` in C# or Java) such that:
1. each kn is more than one
2. eack ... | {"functional": "_inputs = [[0], [4], [9], [25], [8330475], [9819938], [8331299], [8328441]]\n_outputs = [[[[], 0]], [[[2], 0]], [[[3], 1]], [[[4, 2], 0]], [[[22, 13, 10, 8, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 0]], [[[23, 12, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 0]]... | coding | 555 |
Solve the programming task below in a Python markdown code block.
You're looking through different hex codes, and having trouble telling the difference between #000001 and #100000
We need a way to tell which is red, and which is blue!
That's where you create ```hex_color()```!
It should read an RGB input, and re... | {"functional": "_inputs = [[''], ['000 000 000'], ['121 245 255'], ['027 100 100'], ['021 021 021'], ['255 000 000'], ['000 147 000'], ['212 103 212'], ['101 101 092']]\n_outputs = [['black'], ['black'], ['blue'], ['cyan'], ['white'], ['red'], ['green'], ['magenta'], ['yellow']]\nimport math\ndef _deep_eq(a, b, tol=1e-... | coding | 271 |
Solve the programming task below in a Python markdown code block.
There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this si... | {"inputs": ["2\n3527\n47269"], "outputs": ["1305\n25047"]} | coding | 280 |
Solve the programming task below in a Python markdown code block.
Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.
You are given a weighted directe... | {"inputs": ["2 2\n1 2 1\n2 1 2\n", "2 2\n1 2 1\n2 1 2\n", "2 2\n2 2 1\n2 1 2\n", "3 3\n1 2 1\n2 3 1\n3 1 1\n", "3 3\n1 2 1\n2 3 2\n3 1 3\n", "4 3\n1 2 1\n2 3 1\n3 4 2\n", "4 3\n1 2 1\n3 4 1\n2 1 2\n", "3 3\n1 2 1\n1 3 2\n3 2 3\n"], "outputs": ["2\n", "2\n", "2\n", "1\n", "3\n", "2\n", "2\n", "2\n"]} | coding | 511 |
Solve the programming task below in a Python markdown code block.
*This is the second Kata in the Ciphers series. This series is meant to test our coding knowledge.*
## Ciphers #2 - The reversed Cipher
This is a lame method I use to write things such that my friends don't understand. It's still fairly readable if you ... | {"functional": "_inputs = [['Hello World!']]\n_outputs = [['lleHo dlroW!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | coding | 206 |
Solve the programming task below in a Python markdown code block.
Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?
Each... | {"inputs": ["8 5\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n"], "outputs": ["2\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 511 |
Solve the programming task below in a Python markdown code block.
Given two integers `a` and `b`, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return `a` or `b`.
**Note:** `a` and `b` are not ordered!
## Examples
```python
g... | {"functional": "_inputs = [[0, 1], [1, 2], [5, -1], [505, 4], [321, 123], [0, -1], [-50, 0], [-1, -5], [-5, -5], [-505, 4], [-321, 123], [0, 0], [-5, -1], [5, 1], [-17, -17], [17, 17]]\n_outputs = [[1], [3], [14], [127759], [44178], [-1], [-1275], [-15], [-5], [-127755], [-44055], [0], [-15], [15], [-17], [17]]\nimport... | coding | 378 |
Solve the programming task below in a Python markdown code block.
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.
Example ... | {"inputs": ["1 2 3 4 5\n"], "outputs": ["10 14\n"]} | coding | 447 |
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Fehc is Chef's best friend. They grew up with each other, and often help each other with competitive programming.
Chef is participating in a programming contest prepared b... | {"inputs": ["3\n7 2\n5 1\n6 1\n7 3\n2 1\n4 2\n6 1\n10 0"], "outputs": ["9\n12\n30"]} | coding | 671 |
Solve the programming task below in a Python markdown code block.
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence.
The sequence A needs to satisfy the conditions below:
- A consists of integers between X and Y (inclusive).
- For each 1\leq i \leq |A|-1, A_{i+1} is a multiple ... | {"inputs": ["2 7\n", "2 8\n", "1 1\n", "3 20\n", "8 17\n", "25 100\n", "52627 828929983\n", "1 576460752303423488\n"], "outputs": ["2\n", "3\n", "1\n", "3\n", "2\n", "3\n", "14\n", "60\n"]} | coding | 188 |
Solve the programming task below in a Python markdown code block.
Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to $\mbox{1}$.
Example
$a=[1,1,2,2,4,4,5,5,5]$
There are two subarrays meeting the criterion: $[1,1,2,2]$ and $[4,... | {"inputs": ["6\n4 6 5 3 3 1\n", "6\n1 2 2 3 1 2\n"], "outputs": ["3\n", "5\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
Student A and student B are giving each other test answers during a test.
They don't want to be caught so they are sending each other coded messages.
Student A is sending student B the message: `Answer to Number 5 Part b`.
He starts of with a square... | {"functional": "_inputs = [['ArNran u rstm5twob e ePb'], ['ArNran u rstm8twob e ePc'], ['92287a76 585a2y0'], [' a29068686a275y5'], ['8a 55y0y0y5a7 78'], ['9y98a877a95976a758726a89a5659957ya y'], ['aa297625 88a02670997 86ya880 00a9067'], ['826a976a508a9a 687600a2800 895055y a'], [' a702a067629y022ay865y9yy92a60226 98... | coding | 267 |
Solve the programming task below in a Python markdown code block.
Naruto has recently joined the Ninja Academy for higher education, while filling the admission form he is required to choose minimum $X$ subjects out of a list of $N$ subjects. He is not very interested in studies but wants to get a good overall CPI. How... | {"inputs": ["1 \n5 2 \n50 40 30 20 10 "], "outputs": ["43.3333333333\n\n"]} | coding | 486 |
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"]} | coding | 757 |
Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.
A message is a sequence of n integers a1, a2... | {"inputs": ["3 1 5\n1 2 3\n7\n", "3 1 5\n1 0 3\n7\n", "3 1 5\n1 1 3\n7\n", "3 1 1\n1 0 3\n7\n", "3 1 1\n2 0 3\n7\n", "3 1 1\n2 0 0\n7\n", "3 1 5\n1 2 3\n4\n", "3 1 1\n2 0 0\n14\n"], "outputs": ["3 4 0\n", "3 2 0\n", "3 3 0\n", "0 0 0\n", "0 0 0\n", "0 0 0\n", "0 1 2 ", "0 0 0\n"]} | coding | 580 |
Solve the programming task below in a Python markdown code block.
Tsumugi brought $n$ delicious sweets to the Light Music Club. They are numbered from $1$ to $n$, where the $i$-th sweet has a sugar concentration described by an integer $a_i$.
Yui loves sweets, but she can eat at most $m$ sweets each day for health rea... | {"inputs": ["1 1\n7\n", "1 1\n7\n", "2 1\n6052 42201\n", "2 1\n6052 44516\n", "2 1\n6052 17658\n", "2 2\n51200 19970\n", "2 2\n51200 19970\n", "2 1\n70563 22973\n"], "outputs": ["7\n", "7\n", "6052 54305 \n", "6052 56620 \n", "6052 29762 \n", "19970 71170\n", "19970 71170\n", "22973 116509 \n"]} | coding | 611 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.
You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in t... | {"functional": "def check(candidate):\n assert candidate(colors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]) == 3\n assert candidate(colors = \"a\", edges = [[0,0]]) == -1\n\n\ncheck(Solution().largestPathValue)"} | coding | 237 |
Solve the programming task below in a Python markdown code block.
Assume `"#"` is like a backspace in string. This means that string `"a#bc#d"` actually is `"bd"`
Your task is to process a string with `"#"` symbols.
## Examples
```
"abc#d##c" ==> "ac"
"abc##d######" ==> ""
"#######" ==> ""
"" ... | {"functional": "_inputs = [['abjd####jfk#'], ['gfh#jds###d#dsd####dasdaskhj###dhkjs####df##s##d##'], ['831####jns###s#cas/*####-5##s##6+yqw87e##hfklsd-=-28##fds##'], ['######831###dhkj####jd#dsfsdnjkf###d####dasns'], [''], ['#######'], ['####gfdsgf##hhs#dg####fjhsd###dbs########afns#######sdanfl##db#####s#a'], ['#hskjd... | coding | 118 |
Solve the programming task below in a Python markdown code block.
Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up,... | {"inputs": ["2\n5\n7\n", "2\n3\n2\n", "1\n1\n1\n", "1\n2\n4\n", "1\n1\n4\n", "1\n2\n3\n", "2\n3\n8\n", "1\n2\n8\n"], "outputs": ["7\n", "0\n", "0\n", "7\n", "0\n", "0\n", "7\n", "7\n"]} | coding | 434 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the ith house.
Return the ma... | {"functional": "def check(candidate):\n assert candidate(colors = [1,1,1,6,1,1,1]) == 3\n assert candidate(colors = [1,8,3,8,3]) == 4\n assert candidate(colors = [0,1]) == 1\n\n\ncheck(Solution().maxDistance)"} | coding | 130 |
Solve the programming task below in a Python markdown code block.
You are given a string S constisting of uppercase Latin letters. Is it possible to reorder the characters in this string to get a string with prefix "LTIME" and suffix "EMITL"?
We remind you that a prefix of a string is any substring which contains its f... | {"inputs": ["3\nLTIMEAZAZAITLME\nLLLTTTIIIMMMEEEAHA\nLTIMEM"], "outputs": ["YES\nYES\nNO"]} | coding | 392 |
Solve the programming task below in a Python markdown code block.
The cows have just learned what a primitive root is! Given a prime p, a primitive root $\operatorname{mod} p$ is an integer x (1 ≤ x < p) such that none of integers x - 1, x^2 - 1, ..., x^{p} - 2 - 1 are divisible by p, but x^{p} - 1 - 1 is.
Unfortunat... | {"inputs": ["3\n", "5\n", "7\n", "2\n", "2\n", "7\n", "5\n", "3\n"], "outputs": ["1\n", "2\n", "2\n", "1\n", "1", "2", "2", "1"]} | coding | 251 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.
One envelope can fit into another if and only if both the width and height of one envelo... | {"functional": "def check(candidate):\n assert candidate(envelopes = [[5,4],[6,4],[6,7],[2,3]]) == 3\n assert candidate(envelopes = [[1,1],[1,1],[1,1]]) == 1\n\n\ncheck(Solution().maxEnvelopes)"} | coding | 139 |
Solve the programming task below in a Python markdown code block.
# Task
Determine the client's membership level based on the invested `amount` of money and the given thresholds for membership levels.
There are four membership levels (from highest to lowest): `Platinum, Gold, Silver, Bronze`
The minimum investment i... | {"functional": "_inputs = [[100000, 1000000, 100000, 10000, 1000], [1001, 1000000, 100000, 10000, 1000], [998, 1000000, 100000, 10000, 1000], [0, 1000000, 100000, 10000, 1000]]\n_outputs = [['Gold'], ['Bronze'], ['Not a member'], ['Not a member']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)... | coding | 501 |
Solve the programming task below in a Python markdown code block.
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
Constraints
* $0 < n \leq 10000$
* $-1000000 \leq a_i \leq 1000000$
Input
In the first line, an integ... | {"inputs": ["5\n1 1 -3 0 0", "5\n1 1 -5 0 0", "5\n13 1 5 4 17", "5\n13 1 5 7 17", "5\n13 0 5 7 17", "5\n13 0 7 7 17", "5\n23 0 7 7 17", "5\n23 0 0 7 17"], "outputs": ["-3 1 -1\n", "-5 1 -3\n", "1 17 40\n", "1 17 43\n", "0 17 42\n", "0 17 44\n", "0 23 54\n", "0 23 47\n"]} | coding | 183 |
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 and his friend Magda have $2N$ mutual friends: $N$ of these friends are chefs and the other $N$ are chefettes. The chefs are numbered $1$ throug... | {"inputs": ["2\n3\n4 5 6\n1 2 3\n5\n4 8 6 4 1\n2 5 7 4 7"], "outputs": ["10\n23"]} | coding | 647 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.