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.
You are given two positive integer arrays nums1 and nums2, both of length n.
The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).
You ca... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,7,5], nums2 = [2,3,5]) == 3\n assert candidate(nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]) == 0\n assert candidate(nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]) == 20\n\n\ncheck(Solution().minAbsoluteSumDiff)"} | coding | 197 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a link... | {"functional": "def check(candidate):\n assert is_same_list(candidate(l1 = list_node([7,2,4,3]), l2 = list_node([5,6,4])), list_node([7,8,0,7]))\n assert is_same_list(candidate(l1 = list_node([2,4,3]), l2 = list_node([5,6,4])), list_node([8,0,7]))\n assert is_same_list(candidate(l1 = list_node([0]), l2 = list_... | coding | 163 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.
Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,4],[3,2]]) == [0,1]\n assert candidate(mat = [[10,20,15],[21,30,14],[7,16,32]]) == [1,1]\n\n\ncheck(Solution().findPeakGrid)"} | coding | 166 |
Solve the programming task below in a Python markdown code block.
## Find Mean
Find the mean (average) of a list of numbers in an array.
## Information
To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list.
For an example list of `1, 3, 5, 7`
... | {"functional": "_inputs = [[[1]], [[1, 3, 5, 7]], [[-1, 3, 5, -7]], [[5, 7, 3, 7]], [[]]]\n_outputs = [[1], [4], [0], [5.5], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tu... | coding | 177 |
Solve the programming task below in a Python markdown code block.
This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries.
Polycarp grew a tree from $n$ vertices. We remind you that a tree of $n$ vertices is an undirected connected graph of $n$ vertice... | {"inputs": ["1\n1\n1\n1\n", "1\n2\n1\n1\n1\n1\n", "3\n3 1\n2 1\n1\n2\n1 2\n", "5\n4 2\n5 4\n1 4\n3 5\n1\n4\n1 3 5 2\n", "2\n1 2\n5\n1\n2\n1\n1\n1\n1\n2\n2 1\n2\n1 2\n", "6\n1 6\n6 5\n1 2\n2 3\n2 4\n1\n4\n5 2 4 3\n", "6\n1 2\n2 3\n1 4\n4 5\n4 6\n1\n4\n3 4 5 6\n", "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n3\n4 6 7\n"], "outpu... | coding | 730 |
Solve the programming task below in a Python markdown code block.
You have a laser with P amount of energy in it. You are playing a game where you have to use the laser to destroy some crystals, each with some health of their own. Initially, you have 0 points.
Each crystal has an associated health. The health of the it... | {"inputs": ["1\n200\n100"], "outputs": ["0"]} | coding | 514 |
Solve the programming task below in a Python markdown code block.
Two beavers, Timur and Marsel, play the following game.
There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of eac... | {"inputs": ["1 9 3\n", "2 1 2\n", "1 2 1\n", "1 2 2\n", "2 2 1\n", "1 7 1\n", "2 2 2\n", "1 1 2\n"], "outputs": ["Timur\n", "Marsel\n", "Timur\n", "Marsel\n", "Marsel\n", "Timur\n", "Marsel\n", "Marsel\n"]} | coding | 365 |
Solve the programming task below in a Python markdown code block.
The problem is quite simple. You're given a number N and a positive integer K. Tell if N can be represented as a sum of K prime numbers (not necessarily distinct).
Input Format
The first line contains a single integer T, denoting the number of test c... | {"inputs": ["2\n10 2\n1 6\n"], "outputs": ["Yes\nNo\n"]} | coding | 226 |
Solve the programming task below in a Python markdown code block.
The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.
There is a permutation $p_i$ of number... | {"inputs": ["2\n3 4 2 1\n", "2\n1 4 4 2\n", "2\n1 2 4 2\n", "2\n3 4 2 1\n", "3\n6 3 2 5 4 1\n", "3\n5 4 1 6 3 2\n", "3\n5 4 1 6 3 2\n", "3\n6 1 2 5 4 2\n"], "outputs": ["-1\n", "-1\n", "-1\n", "\n-1\n", "3\n", "2\n", "2\n", "-1\n"]} | coding | 453 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a new alien language that uses the English alphabet. However, the order of the letters is unknown to you.
You are given a list of strings words from the alien language's dictionary. Now it is claimed that the... | {"functional": "def check(candidate):\n assert candidate(words = [\"wrt\",\"wrf\",\"er\",\"ett\",\"rftt\"]) == \"wertf\"\n assert candidate(words = [\"z\",\"x\"]) == \"zx\"\n assert candidate(words = [\"z\",\"x\",\"z\"]) == \"\"\n\n\ncheck(Solution().alienOrder)"} | coding | 177 |
Solve the programming task below in a Python markdown code block.
Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range fro... | {"inputs": ["1\n17\n17", "5\n2 3 3 3 3\n3 3 2 2 2", "5\n1 1 1 2 2\n6 2 1 1 1", "5\n1 1 1 4 2\n6 2 1 1 1", "5\n1 1 1 4 2\n6 2 1 1 0", "5\n1 1 1 4 2\n6 0 1 1 0", "5\n1 1 1 4 2\n6 1 1 1 0", "5\n1 1 1 4 2\n6 2 1 2 0"], "outputs": ["1", "4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 562 |
Solve the programming task below in a Python markdown code block.
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zul... | {"inputs": ["1\n1\n", "1\n4\n", "1\n1\n", "1\n4\n", "1\n2\n", "1\n5\n", "1\n3\n", "2\n3 6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]} | coding | 445 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.
You are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that ther... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]) == 4\n assert candidate(n = 3, edges = [[1,2],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().magnificentSets)"} | coding | 241 |
Solve the programming task below in a Python markdown code block.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know th... | {"inputs": ["9 7", "5 5", "9 3", "2 4", "2 6", "1 4", "4 7", "6 5"], "outputs": ["-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "1 2 3 4 5 6 7 8 9\n", "-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11\n", "3 4 5\n", "5 6 7\n", "4\n", "4 5 6 7 8 9 10\n", "0 1 2 3 4 5 6 7 8 9 10\n"]} | coding | 346 |
Solve the programming task below in a Python markdown code block.
Create a program that reads the attendance numbers of students in a class and the data that stores the ABO blood group and outputs the number of people for each blood type. There are four types of ABO blood types: A, B, AB, and O.
Input
A comma-separ... | {"inputs": ["1,B\n2,A\n3,B\n4,AB\n5,B\n5,O\n7,A\n8,O\n9,AB\n10,A\n11,A\n12,B\n13,AB\n14,A", "1,B\n2,B\n3,B\n4,AB\n5,B\n6,O\n7,A\n8,O\n9,AB\n10,A\n11,A\n12,B\n13,AB\n14,A", "1,B\n2,A\n3,B\n4,AB\n5,A\n6,O\n7,A\n8,O\n9,AB\n11,A\n11,A\n12,B\n13,AB\n14,A", "1,B\n2,B\n3,B\n4A,B\n5,B\n6,O\n7,A\n8,O\n9,AB\n10,A\n21,A\n12,B\n13... | coding | 246 |
Solve the programming task below in a Python markdown code block.
# Task
A media access control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment.
The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six gr... | {"functional": "_inputs = [['00-1B-63-84-45-E6'], ['Z1-1B-63-84-45-E6'], ['not a MAC-48 address'], ['FF-FF-FF-FF-FF-FF'], ['00-00-00-00-00-00'], ['G0-00-00-00-00-00'], ['12-34-56-78-9A-BC'], ['02-03-04-05-06-07-'], ['02-03-04-05'], ['02-03-04-FF-00-F0']]\n_outputs = [[True], [False], [False], [True], [True], [False], [... | coding | 268 |
Solve the programming task below in a Python markdown code block.
Lucas numbers are numbers in a sequence defined like this:
```
L(0) = 2
L(1) = 1
L(n) = L(n-1) + L(n-2)
```
Your mission is to complete the function that returns the `n`th term of this sequence.
**Note:** It should work for negative numbers as well; ho... | {"functional": "_inputs = [[-10], [-1]]\n_outputs = [[123], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n retur... | coding | 227 |
Solve the programming task below in a Python markdown code block.
Is the number even?
If the numbers is even return `true`. If it's odd, return `false`.
Oh yeah... the following symbols/commands have been disabled!
use of ```%```
use of ```.even?``` in Ruby
use of ```mod``` in Python
Also feel free to reuse/ext... | {"functional": "_inputs = [[2], [3], [14], [15], [26], [27]]\n_outputs = [[True], [False], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple))... | coding | 94 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two arrays of integers nums and index. Your task is to create target array under the following rules:
Initially target array is empty.
From left to right read nums[i] and index[i], insert at index index[i] the ... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,3,4], index = [0,1,2,2,1]) == [0,4,1,3,2]\n assert candidate(nums = [1,2,3,4,0], index = [0,1,2,3,0]) == [0,1,2,3,4]\n assert candidate(nums = [1], index = [0]) == [1]\n\n\ncheck(Solution().createTargetArray)"} | coding | 145 |
Solve the programming task below in a Python markdown code block.
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano ke... | {"inputs": ["1\n1\n", "1\n50\n", "1\n68\n", "1\n72\n", "1\n10\n", "1\n14\n", "1\n12\n", "1\n17\n"], "outputs": ["1", "1 \n", "1", "1", "1", "1", "1", "1"]} | coding | 615 |
Solve the programming task below in a Python markdown code block.
You are given a positive integer N. You have to split each digit of N into either of two non-empty subsequences A or B.
For example, if N = 104, some possible values of (A, B) can be (10, 4), (14, 0) and (1, 4). Note that, after separating the digits ... | {"inputs": ["2\n10\n73452"], "outputs": ["NO\nYES\n"]} | coding | 599 |
Solve the programming task below in a Python markdown code block.
Take a string and return a hash with all the ascii values of the characters in the string.
Returns nil if the string is empty.
The key is the character, and the value is the ascii value of the character.
Repeated characters are to be ignored and non-alph... | {"functional": "_inputs = [[''], ['a'], ['aaa'], ['hello world'], ['ABaa ^']]\n_outputs = [[None], [{'a': 97}], [{'a': 97}], [{'h': 104, 'e': 101, 'l': 108, 'o': 111, 'w': 119, 'r': 114, 'd': 100}], [{'A': 65, 'B': 66, 'a': 97}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ... | coding | 95 |
Solve the programming task below in a Python markdown code block.
You are given an array of n positive integers a_1, a_2, …, a_n. Your task is to calculate the number of arrays of n positive integers b_1, b_2, …, b_n such that:
* 1 ≤ b_i ≤ a_i for every i (1 ≤ i ≤ n), and
* b_i ≠ b_{i+1} for every i (1 ≤ i ≤ n -... | {"inputs": ["2\n2 5\n", "2\n2 6\n", "2\n7 6\n", "2\n4 3\n", "2\n2 3\n", "2\n2 10\n", "2\n12 3\n", "3\n2 1 1\n"], "outputs": ["8\n", "10\n", "36\n", "9\n", "4", "18\n", "33\n", "0\n"]} | coding | 329 |
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... | coding | 185 |
Solve the programming task below in a Python markdown code block.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they... | {"inputs": ["xx..\n.oo.\nx...\noox.\n", "x.ox\nox..\nx.o.\noo.x\n", "x..x\n..oo\no...\nx.xo\n", "o.x.\no...\n.x..\nooxx\n", ".xox\no.x.\nx.o.\n..o.\n", "o.oo\n.x.o\nx.x.\n.x..\n", ".xx.\n.xoo\n.oox\n....\n", "xxox\no.x.\nx.oo\nxo.o\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 493 |
Solve the programming task below in a Python markdown code block.
For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik.... | {"inputs": ["3\n1\n1\n2", "3\n1\n1\n0", "3\n0\n1\n2", "3\n0\n2\n2", "3\n1\n2\n1", "3\n0\n1\n3", "3\n0\n3\n2", "3\n1\n2\n0"], "outputs": ["2\n", "1\n", "3\n", "2\n", "2\n", "3\n", "2\n", "2\n"]} | coding | 212 |
Solve the programming task below in a Python markdown code block.
You have N coins each of which has a value ai. Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R.
Constraints
* 1 ≤ K ... | {"inputs": ["2 2 2 9\n5 1", "2 2 2 9\n9 1", "2 1 1 9\n6 1", "2 2 2 9\n9 2", "2 2 2 9\n1 2", "2 3 2 9\n1 2", "2 3 2 9\n1 0", "2 3 1 9\n1 0"], "outputs": ["1\n", "0\n", "2\n", "0\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 192 |
Solve the programming task below in a Python markdown code block.
A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $s_1 s_2 \ldots s_n$. It is necessary to make this string non-decreasing in the least number of operations. In other words, each character should be not ... | {"inputs": ["8\n1\n1\n2\n10\n3\n101\n4\n1100\n5\n11001\n6\n100010\n10\n0000110000\n7\n0101010\n"], "outputs": ["0\n1\n2\n1\n2\n3\n1\n5\n"]} | coding | 624 |
Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game i... | {"inputs": ["4\n1 0 0 2\n", "4\n1 0 0 0\n", "4\n1 0 1 2\n", "5\n4 1 4 7 6\n", "5\n2 1 4 7 6\n", "5\n2 2 4 7 6\n", "5\n2 2 6 7 6\n", "5\n2 2 9 7 6\n"], "outputs": ["1\n1\n2\n", "1\n1\n2\n", "1\n1\n3\n", "4\n5\n9\n17\n", "2\n3\n7\n15\n", "2\n4\n8\n17\n", "2\n4\n10\n19\n", "2\n4\n13\n22\n"]} | coding | 583 |
Solve the programming task below in a Python markdown code block.
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and... | {"inputs": ["1\n1\n", "2\n1 2\n", "2\n2 1\n", "6\n6 5 4 3 2 1\n", "6\n1 2 3 4 5 6\n", "10\n10 7 4 2 5 8 9 6 3 1\n", "10\n10 2 7 8 6 5 3 4 2 1\n", "10\n10 9 7 8 6 5 3 0 2 1\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n", "4\n", "3\n", "2\n"]} | coding | 320 |
Solve the programming task below in a Python markdown code block.
Write a function that reverses the bits in an integer.
For example, the number `417` is `110100001` in binary. Reversing the binary is `100001011` which is `267`.
You can assume that the number is not negative.
Also feel free to reuse/extend the follow... | {"functional": "_inputs = [[417], [267], [0], [2017], [1023], [1024]]\n_outputs = [[267], [417], [0], [1087], [1023], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\... | coding | 105 |
Solve the programming task below in a Python markdown code block.
prison
There are an infinite number of prisoners. Initially, the prisoners are numbered 0, 1, 2, ....
Do the following N times:
* Release the 0th prisoner and execute the k, 2k, 3k, ... th prisoners.
* Then renumber the remaining prisoners. At this ti... | {"inputs": ["5 2", "7 2", "2 2", "1 2", "4 3", "8 2", "6 2", "7 4"], "outputs": ["15\n", "63\n", "1\n", "0\n", "4\n", "127\n", "31\n", "10\n"]} | coding | 263 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string.
Please complete the following python code precisely:
```python
class Solution:
def fi... | {"functional": "def check(candidate):\n assert candidate(words = [\"at\", \"\", \"\", \"\", \"ball\", \"\", \"\", \"car\", \"\", \"\",\"dad\", \"\", \"\"], s = \"ta\") == -1\n assert candidate(words = [\"at\", \"\", \"\", \"\", \"ball\", \"\", \"\", \"car\", \"\", \"\",\"dad\", \"\", \"\"], s = \"ball\") == 4\n\n... | coding | 78 |
Solve the programming task below in a Python markdown code block.
You want to build a standard house of cards, but you don't know how many cards you will need. Write a program which will count the minimal number of cards according to the number of floors you want to have. For example, if you want a one floor house, you... | {"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[7], [15], [26]]\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 | 246 |
Solve the programming task below in a Python markdown code block.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (... | {"inputs": ["3\n1", "3\n2", "3\n4", "3\n8", "3\n3", "3\n6", "3\n0", "3\n0\n"], "outputs": ["5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5", "5\n"]} | coding | 433 |
Solve the programming task below in a Python markdown code block.
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, t... | {"inputs": ["1\n2\n", "1\n1\n", "2\n2 3\n", "2\n1 1\n", "2\n1 2\n", "2\n3 4\n", "2\n3 3\n", "2\n1 4\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0\n", "2\n", "2\n", "1\n"]} | coding | 380 |
Solve the programming task below in a Python markdown code block.
Chef's favorite game is chess. Today, he invented a new piece and wants to see its strengths.
From a cell (X, Y), the new piece can move to any cell of the chessboard such that its color is different from that of (X, Y).
The new piece is currently loca... | {"inputs": ["3\n1 1 8 8\n5 7 5 8\n3 3 3 3\n"], "outputs": ["2\n1\n0\n"]} | coding | 455 |
Solve the programming task below in a Python markdown code block.
Oliver and Nova are true lovers. Inspite of knowing that Nova will die Oliver married her at the lake where they met. But they had a conflict about even and odd numbers. Nova likes the odd numbers and Oliver prefers even. One day they went to a fair wher... | {"inputs": ["1\n111"], "outputs": ["YESS(sunglass emo)"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
Today, Chef woke up to find that he had no clean socks. Doing laundry is such a turn-off for Chef, that in such a situation, he always buys new socks instead of cleaning the old dirty ones. He arrived at the fashion store with money rupees in his pocket ... | {"inputs": ["0 2 3", "1 2 9", "1 1 9", "1 2 7", "0 2 6", "2 2 9", "2 1 9", "1 2 5"], "outputs": ["Unlucky Chef\n", "Lucky Chef\n", "Lucky Chef\n", "Unlucky Chef\n", "Unlucky Chef\n", "Unlucky Chef\n", "Unlucky Chef\n", "Lucky Chef\n"]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions ... | {"inputs": ["3 8\n100 7 21", "3 8\n100 8 21", "3 2\n100 8 21", "3 8\n100 4 21", "3 2\n100 2 21", "3 8\n100 7 200", "3 0\n100 0 200", "3 2\n100 12 21"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 769 |
Solve the programming task below in a Python markdown code block.
Doremy's new city is under construction! The city can be regarded as a simple undirected graph with $n$ vertices. The $i$-th vertex has altitude $a_i$. Now Doremy is deciding which pairs of vertices should be connected with edges.
Due to economic reason... | {"inputs": ["4\n4\n2 2 3 1\n6\n5 2 3 1 5 2\n12\n7 2 4 9 1 4 6 3 7 4 2 3\n4\n1000000 1000000 1000000 1000000\n"], "outputs": ["3\n9\n35\n2\n"]} | coding | 746 |
Solve the programming task below in a Python markdown code block.
Your friend has n cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the foll... | {"inputs": ["z\n", "1\n", "0\n", "a\n", "y\n", "w\n", "w\n", "0\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 506 |
Solve the programming task below in a Python markdown code block.
Recently Vasya found a golden ticket — a sequence which consists of $n$ digits $a_1a_2\dots a_n$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $350178$ is lucky ... | {"inputs": ["2\n00\n", "2\n44\n", "2\n55\n", "2\n02\n", "2\n36\n", "2\n11\n", "2\n00\n", "2\n55\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]} | coding | 334 |
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'], [... | coding | 265 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n integer array grid where grid[i][j] could be:
1 representing the starting square. There is exactly one starting square.
2 representing the ending square. There is exactly one ending square.
0 r... | {"functional": "def check(candidate):\n assert candidate([[1,0,0,0],[0,0,0,0],[0,0,2,-1]]) == 2\n assert candidate([[1,0,0,0],[0,0,0,0],[0,0,0,2]]) == 4\n assert candidate([[0,1],[2,0]]) == 0\n\n\ncheck(Solution().uniquePathsIII)"} | coding | 143 |
Solve the programming task below in a Python markdown code block.
The chef was chatting with his friend who was a mathematician.
Chef said "Hi !".
His friend replied that '!' is the symbol of factorial.
Chef had never heard about it and he asked more about it. Then his friend taught him how to calculate the factorial... | {"inputs": ["3\n5\n4\n6"], "outputs": ["120\n24\n720"]} | coding | 158 |
Solve the programming task below in a Python markdown code block.
While Alice was drinking sugarcane juice, she started wondering about the following facts:
The juicer sells each glass of sugarcane juice for 50 coins.
He spends 20\% of his total income on buying sugarcane.
He spends 20\% of his total income on buying s... | {"inputs": ["4\n2\n4\n5\n10\n"], "outputs": ["30\n60\n75\n150\n"]} | coding | 624 |
Solve the programming task below in a Python markdown code block.
My friend John likes to go to the cinema. He can choose between system A and system B.
```
System A : he buys a ticket (15 dollars) every time
System B : he buys a card (500 dollars) and a first ticket for 0.90 times the ticket price,
then for each addi... | {"functional": "_inputs = [[500, 15, 0.9], [100, 10, 0.95], [0, 10, 0.95], [250, 20, 0.9], [500, 20, 0.9], [2500, 20, 0.9]]\n_outputs = [[43], [24], [2], [21], [34], [135]]\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, a... | coding | 443 |
Solve the programming task below in a Python markdown code block.
You are given a binary string S of length N. Your task is to check if there exists a [substring] of S which is the binary representation of a [prime number].
Formally, check if there exist integers L and R such that 1 ≤ L ≤ R ≤ N, and the substring S_{L... | {"inputs": ["3\n1\n111\n101101"], "outputs": ["No\nYes\nYes"]} | coding | 521 |
Solve the programming task below in a Python markdown code block.
Construct an N \times M matrix with entries having positive integers such that:
If M > 1, i^{th} row is strictly increasing from left to right with a fixed common difference d_{i} for all 1≤ i ≤ N.
If N > 1, j^{th} column is strictly increasing from top... | {"inputs": ["3\n3 3\n1 2\n1 1\n"], "outputs": ["1 2 3\n3 6 9\n5 10 15\n1 2\n1\n"]} | coding | 488 |
Solve the programming task below in a Python markdown code block.
Mr. Yamada Springfield Tanaka was appointed as Deputy Deputy Director of the National Land Readjustment Business Bureau. Currently, his country is in the midst of a major land readjustment, and if this land readjustment can be completed smoothly, his pro... | {"inputs": ["2\n-3 0 000 29\n-2 -100 18 100\n0\n-100 -20 -13 -280\n20 100 100 2\n0", "2\n-3 1 100 34\n-5 -100 18 100\n0\n-100 -20 -13 -284\n20 100 100 3\n0", "2\n-100 0 100 43\n-20 -100 18 100\n0\n-100 -4 -9 -284\n20 100 100 3\n0", "2\n-100 0 101 43\n-20 -100 18 100\n0\n-100 -4 -9 -284\n20 100 100 3\n0", "2\n-100 0 101... | coding | 585 |
Solve the programming task below in a Python markdown code block.
We have N non-negative integers: A_1, A_2, ..., A_N.
Consider painting at least one and at most N-1 integers among them in red, and painting the rest in blue.
Let the beauty of the painting be the \mbox{XOR} of the integers painted in red, plus the \mbox... | {"inputs": ["3\n5 6 5", "3\n4 6 5", "3\n4 8 5", "3\n4 8 9", "3\n4 8 4", "3\n5 8 5", "3\n0 6 5", "3\n8 8 9"], "outputs": ["8\n", "7\n", "17\n", "21\n", "16\n", "18\n", "11\n", "9\n"]} | coding | 452 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words and a string s, determine if s is an acronym of words.
The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in... | {"functional": "def check(candidate):\n assert candidate(words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\") == True\n assert candidate(words = [\"an\",\"apple\"], s = \"a\") == False\n assert candidate(words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\") == True\n\n\ncheck(Solution(... | coding | 149 |
Solve the programming task below in a Python markdown code block.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of s... | {"inputs": ["1\n4\n5\n", "1\n5\n4\n", "1\n5\n5\n", "1\n6\n5\n", "1\n5\n0\n", "1\n6\n6\n", "1\n2\n6\n", "1\n2\n1\n"], "outputs": ["4 ", "4 ", "5 ", "5\n", "0\n", "6\n", "2\n", "1\n"]} | coding | 540 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.
Please complete the following python code precisely:
```python
class Solution:
def judgeSquareSum(self, c: int)... | {"functional": "def check(candidate):\n assert candidate(c = 5) == True\n assert candidate(c = 3) == False\n\n\ncheck(Solution().judgeSquareSum)"} | coding | 74 |
Solve the programming task below in a Python markdown code block.
Two people are playing Nimble! The rules of the game are:
The game is played on a line of $n$ squares, indexed from $\mbox{0}$ to $n-1$. Each square $\boldsymbol{i}$ (where $0\leq i<n$) contains $c_i$ coins. For example:
The players move in alternatin... | {"inputs": ["2\n5\n0 2 3 0 6\n4\n0 0 0 0\n"], "outputs": ["First\nSecond\n"]} | coding | 573 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.
A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to t... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1],[1,0]]) == 2\n assert candidate(grid = [[0,0,0],[1,1,0],[1,1,0]]) == 4\n assert candidate(grid = [[1,0,0],[1,1,0],[1,1,0]]) == -1\n\n\ncheck(Solution().shortestPathBinaryMatrix)"} | coding | 187 |
Solve the programming task below in a Python markdown code block.
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two num... | {"inputs": ["1 0 0\n2 1\n", "1 1 0\n3 4\n", "1 0 0\n2 1\n", "1 1 0\n3 4\n", "1 0 0\n0 1\n", "1 1 0\n3 3\n", "1 1 0\n0 1\n", "1 1 0\n10 1\n"], "outputs": ["1\n", "4\n", "1\n", "4\n", "1\n", "3\n", "1\n", "1\n"]} | coding | 517 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: ... | {"functional": "def check(candidate):\n assert candidate(points = [[0,0],[2,2],[3,10],[5,2],[7,0]]) == 20\n assert candidate(points = [[3,12],[-2,5],[-4,1]]) == 18\n assert candidate(points = [[0,0],[1,1],[1,0],[-1,1]]) == 4\n assert candidate(points = [[-1000000,-1000000],[1000000,1000000]]) == 4000000\n ... | coding | 158 |
Solve the programming task below in a Python markdown code block.
You are given two arrays of integers $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$.
Let's define a transformation of the array $a$:
Choose any non-negative integer $k$ such that $0 \le k \le n$.
Choose $k$ distinct array indices $1 \le i_1 < i_2... | {"inputs": ["1\n1\n2\n1\n", "1\n1\n3\n2\n", "1\n1\n1\n2\n", "1\n1\n3\n1\n", "1\n1\n5\n4\n", "1\n1\n4\n3\n", "1\n1\n1\n0\n", "1\n1\n2\n3\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]} | coding | 606 |
Solve the programming task below in a Python markdown code block.
Indian National Olympiad in Informatics 2015
A string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u and v are ... | {"inputs": ["3 176"], "outputs": ["6"]} | coding | 556 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.
There may be duplicates in the original arr... | {"functional": "def check(candidate):\n assert candidate(nums = [3,4,5,1,2]) == True\n assert candidate(nums = [2,1,3,4]) == False\n assert candidate(nums = [1,2,3]) == True\n\n\ncheck(Solution().check)"} | coding | 130 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger than the box above it in wi... | {"functional": "def check(candidate):\n assert candidate(box = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]) == 6\n assert candidate(box = [[1, 1, 1], [2, 3, 4], [2, 6, 7], [3, 4, 5]]) == 10\n\n\ncheck(Solution().pileBox)"} | coding | 148 |
Solve the programming task below in a Python markdown code block.
Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days.
Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not mak... | {"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3"]} | coding | 341 |
Solve the programming task below in a Python markdown code block.
To participate in a prize draw each one gives his/her firstname.
Each letter of a firstname
has a value which is its rank in the English alphabet. `A` and `a` have rank `1`, `B` and `b` rank `2` and so on.
The *length* of the firstname is added to th... | {"functional": "_inputs = [['Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin', [4, 2, 1, 4, 3, 1, 2], 4], ['Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden', [1, 3, 5, 5, 3, 6], 2], ['Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth', [3, 1, 4, 4, 3, 2], 4], ['Lagon,Lily', [1, 5], 2], ['Elijah,Michael,Avery,Sophia,Samantha... | coding | 497 |
Solve the programming task below in a Python markdown code block.
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]... | {"inputs": ["a\n", "l\n", "v\n", "l\n", "a\n", "v\n", "k\n", "b\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 501 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Given three positive integers N, L and R, find the number of non-decreasing sequences of size at least 1 and at most N, such that each element of the sequence lies between L and R, both inclusi... | {"inputs": ["2\n1 4 5\n2 4 5", "2\n1 4 5\n2 4 5"], "outputs": ["2\n5", "2\n5"]} | coding | 326 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).
There is at least one empty seat, ... | {"functional": "def check(candidate):\n assert candidate(seats = [1,0,0,0,1,0,1]) == 2\n assert candidate(seats = [1,0,0,0]) == 3\n assert candidate(seats = [0,1]) == 1\n\n\ncheck(Solution().maxDistToClosest)"} | coding | 144 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a special keyboard with all keys in a single row.
Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25). Initially, your finger is at index 0. To type a character, ... | {"functional": "def check(candidate):\n assert candidate(keyboard = \"abcdefghijklmnopqrstuvwxyz\", word = \"cba\") == 4\n assert candidate(keyboard = \"pqrstuvwxyzabcdefghijklmno\", word = \"leetcode\") == 73\n\n\ncheck(Solution().calculateTime)"} | coding | 162 |
Solve the programming task below in a Python markdown code block.
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
In one second we can add an arbitrary (possibly negati... | {"inputs": ["1\n0\n", "1\n8\n", "1\n5\n", "1\n0\n", "1\n5\n", "1\n8\n", "1\n1\n", "1\n9\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 363 |
Solve the programming task below in a Python markdown code block.
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through in... | {"inputs": ["5 2\n", "6 8\n", "1 1\n", "1 1\n", "3 4\n", "6 9\n", "1 2\n", "3 2\n"], "outputs": ["3\n", "3\n", "1\n", "1\n", "2\n", "3\n", "1\n", "2\n"]} | coding | 737 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if... | {"inputs": ["2\ngg\n", "2\nzg\n", "2\ngg\n", "2\nzg\n", "2\nfg\n", "2\ngz\n", "2\nfh\n", "2\nhf\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 327 |
Solve the programming task below in a Python markdown code block.
Let be `n` an integer prime with `10` e.g. `7`.
`1/7 = 0.142857 142857 142857 ...`.
We see that the decimal part has a cycle: `142857`. The length of this cycle is `6`. In the same way:
`1/11 = 0.09 09 09 ...`. Cycle length is `2`.
# Task
Given an ... | {"functional": "_inputs = [[3], [33], [18118], [69], [197], [65], [97], [19], [111], [53], [59], [93], [51], [159], [183], [167], [94], [133], [218713], [38127], [431541], [221193], [1234567]]\n_outputs = [[1], [2], [-1], [22], [98], [-1], [96], [18], [3], [13], [58], [15], [16], [13], [60], [166], [-1], [18], [9744], ... | coding | 402 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.
On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any tim... | {"functional": "def check(candidate):\n assert candidate(prices = [7,1,5,3,6,4]) == 7\n assert candidate(prices = [1,2,3,4,5]) == 4\n assert candidate(prices = [7,6,4,3,1]) == 0\n\n\ncheck(Solution().maxProfit)"} | coding | 126 |
Solve the programming task below in a Python markdown code block.
Positive integers have so many gorgeous features.
Some of them could be expressed as a sum of two or more consecutive positive numbers.
___
# Consider an Example :
* `10` , could be expressed as a sum of `1 + 2 + 3 + 4 `.
___
# Task
**_Given_** *Posi... | {"functional": "_inputs = [[69], [8], [57], [6], [13], [16], [91], [75], [38], [25], [32], [65], [99], [522], [974], [755], [512], [739], [1006], [838], [1092], [727], [648], [1024], [851], [541], [1011], [822], [382131], [118070], [17209], [32768], [161997], [400779], [198331], [325482], [88441], [65536], [323744], [1... | coding | 352 |
Solve the programming task below in a Python markdown code block.
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements.
Your goal is to obt... | {"inputs": ["3\n1\n1\n5\n2 3 5 7 8\n2\n2 4\n", "3\n1\n1\n5\n2 4 5 7 8\n2\n1 2\n", "3\n1\n1\n5\n2 4 5 6 8\n2\n1 2\n", "3\n1\n2\n5\n3 4 5 7 9\n2\n2 4\n", "3\n1\n1\n5\n2 4 5 7 9\n2\n1 4\n", "3\n1\n1\n5\n1 4 5 7 8\n2\n1 2\n", "3\n1\n2\n5\n1 4 5 7 8\n2\n1 2\n", "3\n1\n1\n5\n1 4 5 7 9\n2\n1 4\n"], "outputs": ["1\n3\n2\n", "1... | coding | 729 |
Solve the programming task below in a Python markdown code block.
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing the... | {"inputs": ["1 1\na1\na1\n", "1 1\na1\na1\n", "1 2\na1\na1\n", "1 100\na1\na1\n", "2 1\n1\n12\n12\n", "2 1\na\nab\nab\n", "2 1\n1\n12\n12\n", "2 1\na\nab\nab\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "7 7\n", "7 7\n", "7 7\n", "7 7\n"]} | coding | 709 |
Solve the programming task below in a Python markdown code block.
#Sorting on planet Twisted-3-7
There is a planet... in a galaxy far far away. It is exactly like our planet, but it has one difference:
#The values of the digits 3 and 7 are twisted.
Our 3 means 7 on the planet Twisted-3-7. And 7 means 3.
Your task is ... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[12, 13, 14]], [[9, 2, 4, 7, 3]]]\n_outputs = [[[1, 2, 7, 4, 5, 6, 3, 8, 9]], [[12, 14, 13]], [[2, 7, 4, 3, 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, ab... | coding | 305 |
Solve the programming task below in a Python markdown code block.
Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to pla... | {"inputs": ["1\n7 0\n", "1\n0 0\n", "1\n7 1\n", "1\n1 0\n", "1\n3 1\n", "1\n0 1\n", "1\n1 1\n", "1\n2 0\n"], "outputs": ["7\n", "0\n", "7\n", "1\n", "3\n", "0\n", "1\n", "2\n"]} | coding | 451 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We define the conversion array conver of an array arr as follows:
conver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.
We also define the score of an array arr as... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,7,5,10]) == [4,10,24,36,56]\n assert candidate(nums = [1,1,2,4,8,16]) == [2,4,8,16,32,64]\n\n\ncheck(Solution().findPrefixScore)"} | coding | 161 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. Each $a_i$ is one of the six following numbers: $4, 8, 15, 16, 23, 42$.
Your task is to remove the minimum number of elements to make this array good.
An array of length $k$ is called good if $k$ i... | {"inputs": ["1\n4\n", "1\n4\n", "1\n8\n", "1\n42\n", "1\n42\n", "1\n15\n", "1\n16\n", "1\n23\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 690 |
Solve the programming task below in a Python markdown code block.
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya ... | {"inputs": ["1 7 3\n", "0 1 0\n", "0 0 0\n", "0 0 1\n", "0 0 2\n", "0 1 0\n", "0 1 1\n", "0 1 2\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n"]} | coding | 378 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Bear Limak has a string S.
Each character of S is a digit '0' or '1'.
Help Limak and check if all the '1' digits form a single non-empty segment (consecutive subsequence) in... | {"inputs": ["6\n001111110\n00110011\n000\n1111\n101010101\n101111111111"], "outputs": ["YES\nNO\nNO\nYES\nNO\nNO"]} | coding | 456 |
Solve the programming task below in a Python markdown code block.
Abhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the string from beginn... | {"inputs": ["3\ngoogle\nbreakraekb\naman"], "outputs": ["SHANKY\nPANDEY\nANKU"]} | coding | 353 |
Solve the programming task below in a Python markdown code block.
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
-----Input-----
A single line contains a n... | {"inputs": ["a\n", "A\n", "z\n", "P\n", "z\n", "a\n", "P\n", "A\n"], "outputs": ["A\n", "A\n", "Z\n", "P\n", "Z\n", "A\n", "P\n", "A\n"]} | coding | 124 |
Solve the programming task below in a Python markdown code block.
Motu and Patlu are racing against each other on a circular track of radius $R$. Initially they are at the same point on the track and will run in same direction .The coach ordered them to run $X$ rounds of the circular field. Patlu wants to know how many... | {"inputs": ["2\n3 10 2 5\n2 20 5 10"], "outputs": ["1\n0"]} | coding | 329 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.
Return the difference between the maximum and minimum values Bob can make by remapping exact... | {"functional": "def check(candidate):\n assert candidate(num = 11891) == 99009\n assert candidate(num = 90) == 99\n\n\ncheck(Solution().minMaxDifference)"} | coding | 181 |
Solve the programming task below in a Python markdown code block.
Mr K has a rectangular plot of land which may have marshes where fenceposts cannot be set. He wants you to find the perimeter of the largest rectangular fence that can be built on this land.
For example, in the following $m\times n=4\times4$ grid, $\bol... | {"inputs": ["2 2\n.x\nx.\n", "2 5\n.....\nxxxx.\n", "4 5\n.....\n.x.x.\n.....\n.....\n"], "outputs": ["impossible\n", "impossible \n", "14\n"]} | coding | 447 |
Solve the programming task below in a Python markdown code block.
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbrevi... | {"inputs": ["1\nIAO'001\n", "1\nIAO'089\n", "1\nIAO'089\n", "1\nIAO'001\n", "1\nIAO'088\n", "1\nIAO'002\n", "1\nIAO'102\n", "1\nIAO'079\n"], "outputs": ["3001\n", "3089\n", "3089\n", "3001\n", "3088\n", "3002\n", "2102\n", "3079\n"]} | coding | 399 |
Solve the programming task below in a Python markdown code block.
Consider a rooted binary tree with $n$ vertices containing numbers. Each vertex of the tree either has two sons (left son and right son), or no sons. We will call such a tree heap, if and only if for all vertices (except the root), the number assigned th... | {"inputs": ["5\n2 1 1 1 1\n"], "outputs": ["2\n"]} | coding | 646 |
Solve the programming task below in a Python markdown code block.
Define a "prime prime" number to be a rational number written as one prime number over another prime number: `primeA / primeB` (e.g. `7/31`)
Given a whole number `N`, generate the number of "prime prime" rational numbers less than 1, using only prime nu... | {"functional": "_inputs = [[6], [4], [10], [65], [0], [1000], [666]]\n_outputs = [[[3, 1]], [[1, 0]], [[6, 3]], [[153, 63]], [[0, 0]], [[14028, 6266]], [[7260, 3213]]]\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_to... | coding | 217 |
Solve the programming task below in a Python markdown code block.
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length i... | {"inputs": ["4\n3 2 3 2", "4\n4 1 3 2", "4\n4 1 3 0", "4\n4 1 3 1", "4\n4 1 6 1", "4\n4 0 6 1", "4\n4 0 9 1", "4\n8 0 9 1"], "outputs": ["0\n", "2\n", "2\n", "1\n", "1\n", "2\n", "2\n", "2\n"]} | coding | 273 |
Solve the programming task below in a Python markdown code block.
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: 'U': go up, (x, y) → (x, y... | {"inputs": ["0 0\nD\n", "0 1\nD\n", "0 1\nD\n", "0 0\nD\n", "2 2\nRU\n", "1 2\nRU\n", "0 -1\nU\n", "-1 0\nR\n"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n"]} | coding | 465 |
Solve the programming task below in a Python markdown code block.
## Task
Your challenge is to write a function named `getSlope`/`get_slope`/`GetSlope` that calculates the slope of the line through two points.
## Input
```if:javascript,python
Each point that the function takes in is an array 2 elements long. The fir... | {"functional": "_inputs = [[[1, 1], [2, 2]], [[-5, -5], [9, 9]], [[1, 8], [2, 9]], [[8, 3], [-4, 5]], [[5, 3], [8, 9]], [[1, 3], [0, 3]], [[11, 1], [1, 11]], [[1, 1], [1, 2]], [[-5, 9], [-5, 12]], [[1, 1], [1, 1]], [[-5, 9], [-5, 9]]]\n_outputs = [[1], [1], [1], [-0.16666666666666666], [2], [0], [-1], [None], [None], [... | coding | 315 |
Solve the programming task below in a Python markdown code block.
From an array A containing N integers, you construct a binary string S of length (N - 1) as follows. For all 1 ≤ i < N:
If A_{i} < A_{i+1}, then S_{i} = 0.
If A_{i} > A_{i+1}, then S_{i} = 1.
Given the string S, determine the count of indices i (1 ≤ i ≤... | {"inputs": ["3\n2\n0\n7\n000111\n6\n11100\n"], "outputs": ["1\n1\n2\n"]} | coding | 554 |
Solve the programming task below in a Python markdown code block.
Two players A and B have a list of $n$ integers each. They both want to maximize the subtraction between their score and their opponent's score.
In one turn, a player can either add to his score any element from his list (assuming his list is not empty... | {"inputs": ["2\n1 4\n5 1\n", "2\n2 1\n5 6\n", "2\n2 1\n5 2\n", "2\n1 4\n5 1\n", "2\n2 1\n5 6\n", "3\n100 100 100\n100 100 100\n", "3\n100 100 100\n100 100 101\n", "3\n100 100 100\n100 100 100\n"], "outputs": ["0", "-3", "0\n", "0\n", "-3\n", "0", "0\n", "0\n"]} | coding | 678 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.
You must solve the problem without using any built-in library for handling large integers (such as Big... | {"functional": "def check(candidate):\n assert candidate(num1 = \"11\", num2 = \"123\") == \"134\"\n assert candidate(num1 = \"456\", num2 = \"77\") == \"533\"\n assert candidate(num1 = \"0\", num2 = \"0\") == \"0\"\n\n\ncheck(Solution().addStrings)"} | coding | 112 |
Solve the programming task below in a Python markdown code block.
Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows:
* The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1.
* Edge i connected Vertex a_i and b_i.
* The length of each edge w... | {"inputs": ["4\n1 2\n2 3\n3 4\n8 6 6 8", "5\n1 2\n1 3\n1 2\n1 5\n9 21 16 4 22", "5\n1 2\n1 2\n1 2\n1 5\n2 13 16 7 28", "5\n1 2\n1 2\n1 2\n1 4\n2 13 16 7 28", "5\n1 2\n1 3\n1 3\n1 5\n9 21 16 5 22", "5\n1 2\n1 3\n1 2\n1 4\n8 21 29 19 6", "5\n1 2\n1 2\n1 4\n1 5\n2 13 16 19 5", "5\n1 2\n1 3\n1 4\n1 5\n5 13 16 19 22"], "out... | coding | 606 |
Solve the programming task below in a Python markdown code block.
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press t... | {"inputs": ["1\n", "4\n", "1\n", "4\n", "0\n", "7\n", "6\n", "2\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 414 |
Solve the programming task below in a Python markdown code block.
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.
There are $n$ positive integers $a_1, a_2, \ldots, a_n$ on Bob's homework paper, where $n$ is always an even number. Bob is asked to divide those numbers... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n2 0\n", "2\n0 0\n", "2\n669 34\n", "2\n669 52\n", "4\n8 5 2 3\n"], "outputs": ["4\n", "4\n", "9\n", "4\n", "0\n", "494209\n", "519841\n", "164\n"]} | coding | 519 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.