task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
One day, Vogons wanted to build a new hyperspace highway through a distant system with $n$ planets. The $i$-th planet is on the orbit $a_i$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be... | {"inputs": ["1\n1 100\n1\n", "4\n10 1\n2 1 4 5 2 4 5 5 1 2\n5 2\n3 2 1 2 2\n2 2\n1 1\n2 2\n1 2\n", "1\n49 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"], "outputs": ["1\n", "4\n4\n2\n2\n", "2\n"]} | 577 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times:
* Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this o... | {"inputs": ["5 2\nbacba", "5 2\nbacaa", "5 1\nbabba", "5 1\nbabbb", "5 1\nbabbc", "5 2\nbabbc", "5 2\ncabab", "5 1\nbacaa"], "outputs": ["aaaab\n", "aaaaa\n", "aabba\n", "abbbb\n", "abbcc\n", "aabbc\n", "aabab\n", "aaaac\n"]} | 235 | 111 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
... | {"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n5\n", "1\n3\n", "1\n0\n", "1\n-1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 449 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Johnny is a farmer and he annually holds a beet farmers convention "Drop the beet".
Every year he takes photos of farmers handshaking. Johnny knows that no two farmers handshake more than once. He also knows that some of the possible handshake combinati... | {"functional": "_inputs = [[0], [1], [3], [6], [7]]\n_outputs = [[1], [2], [3], [4], [5]]\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): ret... | 151 | 179 |
coding | Solve the programming task below in a Python markdown code block.
Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number.
For example: If ```arr``` contains [4... | {"functional": "_inputs = [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]]\n_outputs = [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | 139 | 245 |
coding | Solve the programming task below in a Python markdown code block.
Given two arrays, the purpose of this Kata is to check if these two arrays are the same. "The same" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,... | {"functional": "_inputs = [[[[2, 5], [3, 6]], [[5, 2], [3, 6]]], [[[2, 5], [3, 6]], [[6, 3], [5, 2]]], [[[2, 5], [3, 6]], [[6, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[2, 6], [5, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[3, 5], [6, 2], [5, 2]]], [[], []], [[[2, 3], [3, 4]], [[4, 3], [2, 4]]], [[[2, 3], [3, 2]], [[2,... | 334 | 370 |
coding | Solve the programming task below in a Python markdown code block.
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.
You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the cu... | {"inputs": ["3\n1 5\n3 9\n7 8\n", "6\n8 3\n4 9\n12 19\n18 1\n13 5\n7 6\n"], "outputs": ["3\n", "8\n"]} | 300 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently
they can be guessed due to common cultural references.
You can get your passphrases stronger by different means. One is the following:
choos... | {"functional": "_inputs = [['I LOVE YOU!!!', 1], ['I LOVE YOU!!!', 0], ['AAABBCCY', 1], ['MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015', 2], [\"TO BE HONEST WITH YOU I DON'T USE THIS TEXT TOOL TOO OFTEN BUT HEY... MAYBE YOUR NEEDS ARE DIFFERENT.\", 5], ['IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED PASSPHR... | 286 | 1,106 |
coding | Solve the programming task below in a Python markdown code block.
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are n toy cars. Each pair collides. The result of a collisio... | {"inputs": ["1\n-1\n", "1\n-1\n", "2\n-1 0\n0 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 2\n1 -1\n", "2\n-1 3\n3 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 0\n0 -1\n"], "outputs": ["1\n1 ", "1\n1\n", "2\n1 2 ", "1\n2 ", "1\n1 ", "0\n", "1\n2\n", "2\n1 2\n"]} | 497 | 144 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.
Return the number of steps performed until nums becomes a non-decreasing ... | {"functional": "def check(candidate):\n assert candidate(nums = [5,3,4,4,7,3,6,11,8,5,11]) == 3\n assert candidate(nums = [4,5,7,7,13]) == 0\n\n\ncheck(Solution().totalSteps)"} | 106 | 74 |
coding | Solve the programming task below in a Python markdown code block.
The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it.
However, one day, the members somehow entered the sequence into the document at the same time, crea... | {"inputs": ["5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMTTM\n", "5\n3\nTMT\n3\nMTT\n6\nTTTMMT\n6\nTMTTTT\n6\nTTMMTT\n", "5\n3\nTTM\n3\nTTM\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTTM\n3\nTMT\n6\nTMTMT... | 471 | 369 |
coding | Solve the programming task below in a Python markdown code block.
Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is an edge connecting Vertex i and j; otherwise, there is no such edge.
... | {"inputs": ["2\n01\n10", "3\n011\n111\n110", "3\n010\n101\n010", "3\n011\n111\n111", "3\n011\n110\n111", "3\n010\n101\n110", "3\n011\n011\n110", "3\n011\n111\n011"], "outputs": ["2", "-1\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 434 | 151 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
Find the number of unique good subsequences of binary.
For exa... | {"functional": "def check(candidate):\n assert candidate(binary = \"001\") == 2\n assert candidate(binary = \"11\") == 2\n assert candidate(binary = \"101\") == 5\n\n\ncheck(Solution().numberOfUniqueGoodSubsequences)"} | 221 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the cour... | {"inputs": ["1 1\na\na\n", "1 1\na\nz\n", "1 1\nz\nz\n", "1 1\na\nz\n", "1 1\nz\nz\n", "1 1\na\na\n", "1 1\n{\nz\n", "1 1\n|\nz\n"], "outputs": ["0\n\n", "1\n1 \n", "0\n\n", "1\n1 \n", "0\n\n", "0\n\n", "1\n1\n", "1\n1\n"]} | 449 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numb... | {"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n"], "outputs": ["Second\n", "First\n", "Second\n", "First\n", "Second\n", "Second\n", "First\n", "Second\n"]} | 282 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have n dice, and each dice has k faces numbered from 1 to k.
Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers... | {"functional": "def check(candidate):\n assert candidate(n = 1, k = 6, target = 3) == 1\n assert candidate(n = 2, k = 6, target = 7) == 6\n assert candidate(n = 30, k = 30, target = 500) == 222616187\n\n\ncheck(Solution().numRollsToTarget)"} | 135 | 100 |
coding | Solve the programming task below in a Python markdown code block.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The i... | {"inputs": ["5 3\n2\n5\n0\n5\n3\n0 0", "5 1\n0\n0\n0\n3\n1\n0 0", "5 3\n2\n5\n0\n8\n0\n0 0", "5 3\n2\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n2\n8\n0\n0 0", "5 3\n2\n5\n-4\n8\n3\n0 0", "5 3\n1\n9\n-4\n2\n1\n0 0"], "outputs": ["10\n", "3\n", "13\n", "14\n", "14\n", "15\n", "9\n", "7\n"]} | 294 | 197 |
coding | Solve the programming task below in a Python markdown code block.
Mark loves eating chocolates and also likes to be fit. Given the calorie count for every chocolate he eats, find what he has to do to burn the calories.
The name of the chocolates along with its calorie count are given as follows:
Calories per one whole... | {"inputs": ["DDTM"], "outputs": ["17\n1\n6"]} | 361 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curve... | {"inputs": ["{}\n", "{}\n", "{a}\n", "{y}\n", "{x}\n", "{z}\n", "{a}\n", "{x}\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 232 | 76 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Consider the following ciphering algorithm:
```
For each character replace it with its code.
Concatenate all of the obtained numbers.
```
Given a ciphered string, return the initial one if it is known that it consists only of lowercase letters.
... | {"functional": "_inputs = [['10197115121'], ['98'], ['122']]\n_outputs = [['easy'], ['b'], ['z']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len... | 236 | 179 |
coding | Solve the programming task below in a Python markdown code block.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following form... | {"inputs": ["3\n3 3 1", "3\n3 1 3", "3\n3 3 2", "3\n6 1 3", "3\n3 5 2", "3\n0 5 2", "3\n6 1 4", "3\n6 1 6"], "outputs": ["3 1 3\n3 3 1\n", "1 3 3\n3 1 3\n3 3 1\n", "3 2 3\n3 3 2\n", "3 6 1\n6 1 3\n6 3 1\n", "3 2 5\n3 5 2\n5 2 3\n", "0 2 5\n0 5 2\n2 0 5\n", "4 6 1\n6 1 4\n6 4 1\n", "1 6 6\n6 1 6\n6 6 1\n"]} | 225 | 226 |
coding | Solve the programming task below in a Python markdown code block.
Hello! Your are given x and y and 2D array size tuple (width, height) and you have to:
Calculate the according index in 1D space (zero-based).
Do reverse operation.
Implement:
to_1D(x, y, size):
--returns index in 1D space
to_2D(n, size)
--returns ... | {"functional": "_inputs = [[0, 0, [3, 3]], [1, 1, [3, 3]], [2, 2, [3, 3]], [0, 0, [1, 1]], [1, 5, [4, 6]], [2, 3, [4, 6]]]\n_outputs = [[0], [4], [8], [0], [21], [14]]\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... | 358 | 242 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and an integer threshold.
Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following... | {"functional": "def check(candidate):\n assert candidate(nums = [3,2,5,4], threshold = 5) == 3\n assert candidate(nums = [1,2], threshold = 2) == 1\n assert candidate(nums = [2,3,4,5], threshold = 4) == 3\n\n\ncheck(Solution().longestAlternatingSubarray)"} | 197 | 88 |
coding | Solve the programming task below in a Python markdown code block.
You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest.
There are $N$ submissions, numbered $1$ through $N$. For each valid $i... | {"inputs": ["1\n5\n1 3\n4 4\n4 10\n1 11\n2 7"], "outputs": ["2"]} | 418 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Chef has recently been playing a lot of chess in preparation for the ICCT (International Chef Chess Tournament).
Since putting in long hours is not an easy task, Chef's mind wanders elsewhere. He starts counting the number of squares with odd side length... | {"inputs": ["2\n3\n8"], "outputs": ["10\n120"]} | 219 | 21 |
coding | Solve the programming task below in a Python markdown code block.
### The Story:
Bob is working as a bus driver. However, he has become extremely popular amongst the city's residents. With so many passengers wanting to get aboard his bus, he sometimes has to face the problem of not enough space left on the bus! He want... | {"functional": "_inputs = [[10, 5, 5], [100, 60, 50], [20, 5, 5]]\n_outputs = [[0], [10], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b)... | 437 | 191 |
coding | Solve the programming task below in a Python markdown code block.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 10^9.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all r... | {"inputs": ["1 1\n4\n", "1 1\n4\n", "2 2\n1 2\n", "2 1\n5 1\n", "2 2\n1 4\n", "2 3\n6 7\n", "2 3\n6 7\n", "2 1\n5 1\n"], "outputs": ["4\n", "4", "1\n", "5\n", "1\n", "7\n", "7", "5"]} | 426 | 111 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Round the given number `n` to the nearest multiple of `m`.
If `n` is exactly in the middle of 2 multiples of m, return `n` instead.
# Example
For `n = 20, m = 3`, the output should be `21`.
For `n = 19, m = 3`, the output should be `18`.
... | {"functional": "_inputs = [[20, 3], [19, 3], [1, 10], [50, 100], [123, 456]]\n_outputs = [[21], [18], [0], [50], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ... | 197 | 206 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed string s, permute s to get a new string t such that:
All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then ... | {"functional": "def check(candidate):\n assert candidate(s = \"lEetcOde\") == \"lEOtcede\"\n assert candidate(s = \"lYmpH\") == \"lYmpH\"\n\n\ncheck(Solution().sortVowels)"} | 221 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Given $\mbox{1}$ friendly number and $n$ unfriendly numbers, determine how many numbers are divisors of the friendly number but not the unfriendly numbers.
Input Format
The first line contains $2$ space-separated integers, $n$ (the number of unfriendly... | {"inputs": ["8 16\n2 5 7 4 3 8 3 18\n"], "outputs": ["1\n"]} | 534 | 34 |
coding | Solve the programming task below in a Python markdown code block.
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with ... | {"inputs": ["bbbbbb\nbb\n", "aaaaa\naaa\n", "bbbbbb\nbb\n", "aaaaa\naaa\n", "bbbbbb\nbc\n", "aabaa\naaa\n", "bbbbba\nbc\n", "aabaa\naab\n"], "outputs": ["3", "1", "3", "1", "0\n", "0\n", "0\n", "1\n"]} | 469 | 90 |
coding | Solve the programming task below in a Python markdown code block.
The $String$ Family gave birth to a new $Tripartite$ $trio$ $sisters$ and named them $Hema$, $Rekha$ and $Sushma$. Hema and Rekha are very fond of parties whereas Sushma hates them. One day Hema and Rekha asked their parents to buy them candies to distri... | {"inputs": ["1\n2\n2 3\n1"], "outputs": ["7"]} | 450 | 20 |
coding | Solve the programming task below in a Python markdown code block.
A hostel has N rooms in a straight line. It has to accommodate X people. Unfortunately, out of these X people, Y of them are infected with chickenpox. Due to safety norms, the following precaution must be taken:
No person should occupy a room directly a... | {"inputs": ["3\n4 0\n5 3\n3 3\n"], "outputs": ["4\n8\n5\n"]} | 497 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You are given a matrix A that consists of N rows and M columns. Every number in the matrix is either zero or one. Calculate the number of such triples (i, j, h) where for all the pairs (x, y), where both x and y belong to [1; h] if y ≥ x, A[i+x-1][j+y-1]... | {"inputs": ["2 3\n011\n111"], "outputs": ["6"]} | 350 | 22 |
coding | 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"]} | 707 | 34 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You are given a string consisting of `"D", "P" and "C"`. A positive integer N is called DPC of this string if it satisfies the following properties:
```
For each i = 1, 2, ... , size of the string:
If i-th character is "D", then N can be d... | {"functional": "_inputs = [['DDPDD'], ['DDDDPDDCCCDDPDCCPCDCDDPCPCCDDCD'], ['DPCPDPPPDCPDPDPC'], ['DDDDDDCD'], ['CDDDPDDD'], ['DDDDDDPCCDPDPP']]\n_outputs = [[20], [15782844], [-1], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i... | 302 | 231 |
coding | Solve the programming task below in a Python markdown code block.
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i.
Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segm... | {"inputs": ["5 1\n0 0 0 1 0", "5 2\n0 0 0 1 0", "5 2\n0 0 0 0 0", "5 2\n1 0 0 0 0", "5 2\n0 0 0 0 1", "5 0\n0 0 0 0 1", "5 2\n1 0 0 2 0", "5 2\n0 0 0 2 0"], "outputs": ["1 1 2 1 2\n", "3 3 4 3 3\n", "2 3 3 3 2\n", "2 3 3 4 2\n", "2 4 3 3 2\n", "0 0 0 0 1\n", "3 3 4 4 4\n", "3 3 4 4 3\n"]} | 391 | 222 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $m$. Calculate the number of pairs of arrays $(a, b)$ such that:
the length of both arrays is equal to $m$; each element of each array is an integer between $1$ and $n$ (inclusive); $a_i \le b_i$ for any index $i$ ... | {"inputs": ["2 2\n", "1 1\n", "1 2\n", "1 2\n", "1 1\n", "7 7\n", "2 3\n", "9 1\n"], "outputs": ["5\n", "1\n", "1\n", "1\n", "1\n", "38760\n", "7\n", "45\n"]} | 375 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to gift his girlfriend a necklace made of beads. The beads can be made of either Stone, Glass, Quartz, Ruby or Diamond (he need not use all five types of beads) .
Each bead has a value associated with its beauty as follows
-2 for Stone
-1 fo... | {"inputs": ["1 2 2 3 4\n3\n2 0\n1 -2\n3 6"], "outputs": ["4\n1\n12"]} | 487 | 39 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array.
# Example
For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]`
... | {"functional": "_inputs = [[[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], [[2]], [[1, 2]], [[1, 1, 2, 2]]]\n_outputs = [[6], [5], [1], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.is... | 369 | 277 |
coding | Solve the programming task below in a Python markdown code block.
There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that ... | {"inputs": ["2 2\n3\n1 1 0\n1 2 10\n2 1 22", "2 2\n3\n2 1 20\n1 2 10\n2 1 0", "2 2\n3\n1 1 0\n1 2 10\n2 1 14", "2 4\n3\n1 1 0\n1 2 10\n2 1 22", "2 2\n3\n1 1 0\n1 2 10\n1 1 14", "2 4\n3\n1 1 1\n1 2 10\n2 1 22", "2 2\n3\n1 1 0\n2 2 10\n2 1 22", "2 2\n3\n1 2 20\n1 2 10\n2 1 0"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\... | 557 | 254 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer $n$. Pair the integers $1$ to $2n$ (i.e. each integer should be in exactly one pair) so that each sum of matched pairs is consecutive and distinct.
Formally, let $(a_i, b_i)$ be the pairs that you matched. $\{a_1, b_1, a_2, b_2,... | {"inputs": ["1\n99988\n", "1\n99990\n", "1\n99992\n", "1\n99994\n", "1\n99996\n", "1\n99998\n", "1\n31704\n", "1\n100000\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 492 | 119 |
coding | Solve the programming task below in a Python markdown code block.
You're given a tree with $n$ vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
-----Input-----
The first line contains an intege... | {"inputs": ["1\n", "1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "3\n1 2\n1 3\n", "3\n1 2\n2 3\n", "3\n1 3\n2 3\n"], "outputs": ["-1", "-1\n", "0", "0\n", "0\n", "-1", "-1\n", "-1\n"]} | 358 | 104 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and an integer k.
A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
Return the length of the longest possible ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,3,1,3], k = 3) == 3\n assert candidate(nums = [1,1,2,2,1,1], k = 2) == 4\n\n\ncheck(Solution().longestEqualSubarray)"} | 131 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists of n int... | {"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 298 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a string good if its length is at least $2$ and all of its characters are ${A}$ except for the last character which is ${B}$. The good strings are ${AB},{AAB},{AAAB},\ldots$. Note that ${B}$ is not a good string.
You are given an initially em... | {"inputs": ["4\nAABAB\nABB\nAAAAAAAAB\nA\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 500 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Let’s get to know our hero: Agent #134 - Mr. Slayer.
He was sent by his CSV agency to Ancient Rome in order to resolve some important national issues. However, something incredible has happened - the enemies have taken Julius Caesar as a prisoner!!!
Ca... | {"functional": "_inputs = [['123,.)(!?', 10], ['', 10], [None, 10], [' ', 10], ['Hello world!', 127], ['eBIIL TLOIA!', -127], ['ksdjai8983hdk?}{', 15], ['Hello world!', 0]]\n_outputs = [['123,.)(!?'], [''], [''], [''], ['eBIIL TLOIA!'], ['Hello world!'], ['zHsypx8983wsz?}{'], ['Hello world!']]\nimport math\ndef _deep... | 278 | 275 |
coding | Solve the programming task below in a Python markdown code block.
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. ... | {"inputs": ["1\n0\n", "2\n0 1\n", "2\n0 0\n", "5\n0 0 0 1 3\n", "5\n0 0 0 2 3\n", "5\n0 1 0 1 3\n", "7\n0 1 0 0 0 0 0\n", "7\n0 1 0 0 0 0 1\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "3\n", "3\n", "6\n", "6\n"]} | 478 | 138 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi]. This means that on the ith day you need to pai... | {"functional": "def check(candidate):\n assert candidate(paint = [[1,4],[4,7],[5,8]]) == [3,3,1]\n assert candidate(paint = [[1,4],[5,8],[4,7]]) == [3,3,1]\n assert candidate(paint = [[1,5],[2,4]]) == [4,0]\n\n\ncheck(Solution().amountPainted)"} | 173 | 98 |
coding | Solve the programming task below in a Python markdown code block.
Consider some set of distinct characters $A$ and some string $S$, consisting of exactly $n$ characters, where each character is present in $A$.
You are given an array of $m$ integers $b$ ($b_1 < b_2 < \dots < b_m$).
You are allowed to perform the foll... | {"inputs": ["3 1 2\n1\n", "2 1 1\n1\n", "8 1 8\n2\n", "8 1 8\n2\n", "2 1 1\n1\n", "3 1 3\n1\n", "3 1 5\n1\n", "3 1 4\n1\n"], "outputs": ["6\n", "1\n", "8519680\n", "8519680\n", "1\n", "18\n", "75\n", "40\n"]} | 703 | 133 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one.
At least how many operations are necessary to satisfy the following conditions?
* ... | {"inputs": ["4\n1 0 1 0", "4\n0 0 1 0", "4\n0 0 0 0", "4\n0 0 0 1", "4\n0 0 1 1", "4\n0 1 1 1", "4\n0 0 1 2", "4\n0 1 1 2"], "outputs": ["5\n", "6\n", "7\n", "6\n", "7\n", "6\n", "6\n", "5\n"]} | 275 | 126 |
coding | Solve the programming task below in a Python markdown code block.
## Description:
Remove all exclamation marks from the end of words. Words are separated by spaces in the sentence.
### Examples
```
remove("Hi!") === "Hi"
remove("Hi!!!") === "Hi"
remove("!Hi") === "!Hi"
remove("!Hi!") === "!Hi"
remove("Hi! Hi!") ===... | {"functional": "_inputs = [['Hi!'], ['Hi!!!'], ['!Hi'], ['!Hi!'], ['Hi! Hi!']]\n_outputs = [['Hi'], ['Hi'], ['!Hi'], ['!Hi'], ['Hi Hi']]\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, (l... | 126 | 188 |
coding | Solve the programming task below in a Python markdown code block.
You will be given two numbers `m,n`. The numbers could span from `0` to `10000`. We can get their product by using binary reduction as show in the table below.
Example (to understand the table please read the description below it)
real value of m(r... | {"functional": "_inputs = [[100, 15], [15, 0], [0, 0]]\n_outputs = [[[960, 480, 60]], [[]], [[]]]\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... | 459 | 188 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to convert a given number into a string with commas added for easier readability. The number should be rounded to 3 decimal places and the commas should be added at intervals of three digits before the decimal point. There does not need to ... | {"functional": "_inputs = [[1], [1000], [100.2346], [1000000000.23], [9123.212], [-1], [-1000000.123], [-2000.0], [-999.9999], [-1234567.0001236]]\n_outputs = [['1'], ['1,000'], ['100.235'], ['1,000,000,000.23'], ['9,123.212'], ['-1'], ['-1,000,000.123'], ['-2,000'], ['-1,000'], ['-1,234,567']]\nimport math\ndef _deep_... | 233 | 334 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions... | {"inputs": ["1\nbaaa\n", "1\nbaaa\n", "3\ncbabc\n", "2\nabcab\n", "3\nbbabc\n", "2\nabbab\n", "3\ncbabc\n", "2\nabcab\n"], "outputs": ["aaab\n", "aaab", "a\n", "aab\n", "a\n", "aab\n", "a", "aab"]} | 494 | 95 |
coding | Solve the programming task below in a Python markdown code block.
Shivam owns a gambling house, which has a special wheel called The Wheel of Fortune.
This wheel is meant for giving free coins to people coming in the house.
The wheel of fortune is a game of chance. It uses a spinning wheel with exactly N numbered po... | {"inputs": ["2\n3\n1 2 3\n3\n1\n2\n3\n6\n2 1 5 3 2 1\n4\n1\n2\n3\n5"], "outputs": ["3\n3\n3\n2\n2\n6\n6"]} | 526 | 64 |
coding | Solve the programming task below in a Python markdown code block.
You were given a string of integer temperature values. Create a function `close_to_zero(t)` and return the closest value to 0 or `0` if the string is empty. If two numbers are equally close to zero, return the positive integer.
Also feel free to reuse/ex... | {"functional": "_inputs = [[''], ['-1 50 -4 20 22 -7 0 10 -8'], ['28 35 -21 17 38 -17']]\n_outputs = [[0], [0], [17]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ... | 86 | 203 |
coding | Solve the programming task below in a Python markdown code block.
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
Given two strings consisting of digits 0 and 1 only, find the XOR of the two strings.
To know more about XOR Click Here
Debug the given function... | {"inputs": ["10101\n00101\n"], "outputs": ["10000\n"]} | 322 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching ... | {"inputs": ["A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "TANB\nXNCPR\n1\n15 h 6 r\n9 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 27 r\n6 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 2 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 54 r\n6 h 27 r\... | 597 | 272 |
coding | Solve the programming task below in a Python markdown code block.
Create a method `sayHello`/`say_hello`/`SayHello` that takes as input a name, city, and state to welcome a person. Note that `name` will be an array consisting of one or more values that should be joined together with one space between each, and the leng... | {"functional": "_inputs = [[['John', 'Smith'], 'Phoenix', 'Arizona'], [['Franklin', 'Delano', 'Roosevelt'], 'Chicago', 'Illinois'], [['Wallace', 'Russel', 'Osbourne'], 'Albany', 'New York'], [['Lupin', 'the', 'Third'], 'Los Angeles', 'California'], [['Marlo', 'Stanfield'], 'Baltimore', 'Maryland']]\n_outputs = [['Hello... | 152 | 313 |
coding | Solve the programming task below in a Python markdown code block.
Chef has invented 1-minute Instant Noodles. As the name suggests, each packet takes exactly 1 minute to cook.
Chef's restaurant has X stoves and only 1 packet can be cooked in a single pan.
How many customers can Chef serve in Y minutes if each custom... | {"inputs": ["3 7", "7 8"], "outputs": ["21", "56"]} | 367 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if:
nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,4,1], costs = [3,7,6,4,2]) == 8\n assert candidate(nums = [0,1,2], costs = [1,1,1]) == 2\n\n\ncheck(Solution().minCost)"} | 188 | 77 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :
let x be the sum of all elements currently in your array.
choose index i, such tha... | {"functional": "def check(candidate):\n assert candidate(target = [9,3,5]) == True\n assert candidate(target = [1,1,1,2]) == False\n assert candidate(target = [8,5]) == True\n\n\ncheck(Solution().isPossible)"} | 144 | 64 |
coding | Solve the programming task below in a Python markdown code block.
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016... | {"inputs": ["2 1\n1 2\n", "2 1\n2 1\n", "2 1\n2 1\n", "2 1\n2 1\n", "2 1\n1 2\n", "4 1\n2 1\n", "4 1\n4 1\n", "3 1\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1", "1", "-1\n", "-1\n", "-1\n"]} | 556 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a s... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "2\n1 2\n", "2\n3 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 578 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains $a$ stones, the second of them contains $b$ stones and the third of them contains $c$ stones.
Each time she can do one of two operations: take ... | {"inputs": ["3\n3 4 5\n1 0 5\n5 3 2\n", "3\n3 4 5\n1 0 5\n7 3 2\n", "3\n0 4 5\n1 0 5\n7 3 2\n", "3\n0 8 5\n1 0 5\n7 3 2\n", "3\n0 8 5\n0 0 5\n7 3 2\n", "3\n3 4 5\n1 0 5\n5 3 2\n", "3\n0 8 5\n0 0 5\n12 3 1\n", "3\n0 8 5\n0 0 5\n12 3 2\n"], "outputs": ["9\n0\n6\n", "9\n0\n6\n", "6\n0\n6\n", "6\n0\n6\n", "6\n0\n6\n", "9\n... | 499 | 248 |
coding | Solve the programming task below in a Python markdown code block.
There is an empty grid (all cells are colored white) of N rows and M columns.
Chef can fill each cell with either RED or GREEN color.
Chef defines a *valid* path as a path of cells starting from (1,1) and ending at (N,M), where, Chef moves either righ... | {"inputs": ["3\n1 1\n1 2\n2 3\n"], "outputs": ["0\n2\n72\n"]} | 498 | 31 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximi... | {"inputs": ["1 0\n0\n", "1 0\n0\n", "1 0\n1\n", "1 1\n0\n", "1 1\n1\n", "1 0\n0\n", "1 0\n1\n", "1 1\n0\n"], "outputs": ["0\n0\n", "0\n0\n", "1\n1\n", "1\n1\n", "1\n1\n", "0\n0 ", "1\n1 ", "1\n1 "]} | 306 | 116 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string S of length N and an integer K. You can perform the following operation on the string:
Select a *prefix* of the string S and flip all the characters of the prefix. A flip corresponds to changing 0 to 1 and vice-versa.
Find ... | {"inputs": ["3\n3 3\n000\n4 2\n0110\n5 3\n10101\n"], "outputs": ["1\n0\n2\n"]} | 627 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Problem
There are n vertices that are not connected to any of the vertices.
An undirected side is stretched between each vertex.
Find out how many sides can be stretched when the diameter is set to d.
The diameter represents the largest of the shortest ... | {"inputs": ["0 1", "4 5", "6 5", "0 2", "4 1", "6 9", "0 8", "8 1"], "outputs": ["0\n", "2\n", "5\n", "-1\n", "6\n", "7\n", "26\n", "28\n"]} | 189 | 80 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick.
You can connect any two sticks of lengths x and y into one stic... | {"functional": "def check(candidate):\n assert candidate(sticks = [2,4,3]) == 14\n assert candidate(sticks = [1,8,3,5]) == 30\n assert candidate(sticks = [5]) == 0\n\n\ncheck(Solution().connectSticks)"} | 143 | 71 |
coding | Solve the programming task below in a Python markdown code block.
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points ... | {"inputs": ["1 1\n2 2\n", "1 1\n0 1\n", "1 1\n1 1\n", "1 1\n-1 1\n", "2 1\n0 2\n0 0\n", "2 1\n0 2\n-1 0\n", "2 2\n-3 1\n-4 -1\n", "3 2\n0 5\n-3 2\n1 8\n"], "outputs": ["1\n2 2\n", "1\n0 1\n", "1\n1 1\n", "1\n-1 1\n", "1\n0 2\n", "1\n-1 2\n", "1\n-3 -1\n", "1\n0 5\n"]} | 267 | 178 |
coding | Solve the programming task below in a Python markdown code block.
Chef is playing a videogame, and is getting close to the end. He decides to finish the rest of the game in a single session.
There are X levels remaining in the game, and each level takes Chef Y minutes to complete. To protect against eye strain, Chef a... | {"inputs": ["4\n2 12 10\n3 12 10\n7 20 8\n24 45 15\n"], "outputs": ["24\n36\n156\n1185"]} | 300 | 58 |
coding | Solve the programming task below in a Python markdown code block.
For a pole vaulter, it is very important to begin the approach run at the best possible starting mark. This is affected by numerous factors and requires fine-tuning in practice. But there is a guideline that will help a beginning vaulter start at approxi... | {"functional": "_inputs = [[1.52], [1.83], [1.22], [2.13], [1.75]]\n_outputs = [[9.45], [10.67], [8.27], [11.85], [10.36]]\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)):\... | 335 | 212 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums consisting of 2 * n integers.
You need to divide nums into n pairs such that:
Each element belongs to exactly one pair.
The elements present in a pair are equal.
Return true if nu... | {"functional": "def check(candidate):\n assert candidate(nums = [3,2,3,2,2,2]) == True\n assert candidate(nums = [1,2,3,4]) == False\n\n\ncheck(Solution().divideArray)"} | 106 | 57 |
coding | Solve the programming task below in a Python markdown code block.
There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i.
Taro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order... | {"inputs": ["3\n2 2 20\n2 1 7\n3 1 40", "3\n2 3 20\n2 1 7\n3 1 40", "3\n3 5 20\n1 1 7\n3 1 40", "3\n2 2 20\n2 1 30\n3 1 47", "3\n2 2 20\n2 1 30\n3 2 47", "3\n2 2 20\n2 1 29\n3 2 47", "3\n2 2 20\n2 1 29\n3 4 47", "3\n4 2 20\n2 1 35\n3 0 71"], "outputs": ["40\n", "60\n", "67\n", "50\n", "77\n", "76\n", "96\n", "71\n"]} | 505 | 235 |
coding | Solve the programming task below in a Python markdown code block.
# Task
John won the championship of a TV show. He can get some bonuses.
He needs to play a game to determine the amount of his bonus.
Here are some cards in a row. A number is written on each card.
In each turn, John can take a card, but only from th... | {"functional": "_inputs = [[[1, 2, 5]], [[1]], [[1, 1]], [[1, 2, 1]], [[4, 10, 2, 3, 1, 3, 1, 6, 9]]]\n_outputs = [[50], [2], [6], [22], [6722]]\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 isinstan... | 400 | 222 |
coding | Solve the programming task below in a Python markdown code block.
An array A of size N is called *good* if the following conditions hold:
For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].)
JJ has an array A of size N. He wants ... | {"inputs": ["3\n5\n1 2 3 4 4\n3\n0 0 0\n6\n2 3 5 7 11 13\n"], "outputs": ["2\n3\n0\n"]} | 590 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Chef is currently standing at stair 0 and he wants to reach stair numbered X.
Chef can climb either Y steps or 1 step in one move.
Find the minimum number of moves required by him to reach exactly the stair numbered X.
------ Input Format ------
- ... | {"inputs": ["4\n4 2\n8 3\n3 4\n2 1\n"], "outputs": ["2\n4\n3\n2\n"]} | 364 | 36 |
coding | Solve the programming task below in a Python markdown code block.
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the $n$ days of summer. On the $i$-th day, $a_i$ ... | {"inputs": ["1 0 0\n7\n", "1 0 1\n7\n", "1 0 0\n10\n", "1 0 0\n10\n", "1 0 1\n10\n", "2 1 0\n2 1\n", "2 0 1\n2 1\n", "2 2 2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 628 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to ... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "2\n1 1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "2\n"]} | 572 | 94 |
coding | Solve the programming task below in a Python markdown code block.
One of the built-in functions of Python is divmod, which takes two arguments $\boldsymbol{\alpha}$ and $\boldsymbol{b}$ and returns a tuple containing the quotient of $a/b$ first and then the remainder $\boldsymbol{a}$.
For example:
>>> print divmo... | {"inputs": ["177\n10\n"], "outputs": ["17\n7\n(17, 7)\n"]} | 291 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.
... | {"functional": "def check(candidate):\n assert candidate(candies = [5,8,6], k = 3) == 5\n assert candidate(candies = [2,5], k = 11) == 0\n\n\ncheck(Solution().maximumCandies)"} | 159 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Mario was going to gift Princess Peach a string S of even length N.
Mario was clumsy and thus, broke the string in the middle. He now has two strings A and B such that A = S[1, \frac{N}{2}] and B = S[\frac{N}{2} + 1, N].
Mario is not sure about the o... | {"inputs": ["4\n6\nabcabc\n6\nabcdef\n4\naaaa\n4\nbaab"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 601 | 37 |
coding | Solve the programming task below in a Python markdown code block.
There are 32 letters in the Polish alphabet: 9 vowels and 23 consonants.
Your task is to change the letters with diacritics:
```
ą -> a,
ć -> c,
ę -> e,
ł -> l,
ń -> n,
ó -> o,
ś -> s,
ź -> z,
ż -> z
```
and print out the string without the use of th... | {"functional": "_inputs = [['J\u0119drzej B\u0142\u0105dzi\u0144ski'], ['Lech Wa\u0142\u0119sa'], ['Maria Sk\u0142odowska-Curie'], ['W\u0142adys\u0142aw Reymont'], ['Miko\u0142aj Kopernik'], ['J\u00f3zef Pi\u0142sudski'], ['Czes\u0142aw Mi\u0142osz'], ['Agnieszka Radwa\u0144ska'], ['Wojciech Szcz\u0119sny'], ['Za\u017c... | 154 | 539 |
coding | Solve the programming task below in a Python markdown code block.
Write
```python
function combine()
```
that combines arrays by alternatingly taking elements passed to it.
E.g
```python
combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c'... | {"functional": "_inputs = [[['a', 'b', 'c'], [1, 2, 3]], [['a', 'b', 'c'], [1, 2, 3, 4, 5]], [['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]], [[{'a': 1}, {'b': 2}], [1, 2]], [[{'a': 2, 'b': 1}, {'a': 1, 'b': 2}], [1, 2, 3, 4], [5, 6], [7]]]\n_outputs = [[['a', 1, 'b', 2, 'c', 3]], [['a', 1, 'b', 2, 'c', 3, 4, 5]], [['a... | 226 | 430 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:
i < j < k,
nums[j] - nums[i] == diff, a... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,4,6,7,10], diff = 3) == 2\n assert candidate(nums = [4,5,6,7,8,9], diff = 2) == 2\n\n\ncheck(Solution().arithmeticTriplets)"} | 130 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance c_{i} and width w_{i}.
Stepan decided to expose some of his cups ... | {"inputs": ["1 1 1\n1 1\n1 1\n", "1 1 1\n1 1\n1 1\n", "1 1 1\n1 0\n1 1\n", "3 1 8\n4 2\n5 5\n4 2\n3 2\n", "2 2 2\n5 3\n6 3\n4 2\n8 1\n", "3 1 8\n0 2\n5 5\n4 2\n3 2\n", "2 2 2\n5 3\n6 3\n4 2\n8 2\n", "3 1 6\n0 2\n5 5\n4 2\n3 2\n"], "outputs": ["0\n", "0\n", "2\n", "8\n", "0\n", "8\n", "0\n", "0\n"]} | 672 | 206 |
coding | Solve the programming task below in a Python markdown code block.
You're fed up about changing the version of your software manually. Instead, you will create a little script that will make it for you.
# Exercice
Create a function `nextVersion`, that will take a string in parameter, and will return a string containin... | {"functional": "_inputs = [['1.2.3'], ['0.9.9'], ['1'], ['1.2.3.4.5.6.7.8'], ['9.9']]\n_outputs = [['1.2.4'], ['1.0.0'], ['2'], ['1.2.3.4.5.6.7.9'], ['10.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 ... | 145 | 227 |
coding | Solve the programming task below in a Python markdown code block.
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s_1s_2... s_{n} (n is the length of the string), consisting only of characters "." and "#" and m queries.... | {"inputs": ["..\n1\n1 2\n", "##\n1\n1 2\n", ".#\n1\n1 2\n", "#.\n1\n1 2\n", "#.\n1\n1 2\n", "##\n1\n1 2\n", "..\n1\n1 2\n", ".#\n1\n1 2\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]} | 381 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2.
One day he played a game in his class. He brought some number plates on each of ... | {"inputs": ["5\n2222222\n24256\n65536\n023223\n33579\n"], "outputs": ["7\n4\n1\n4\n0\n"]} | 647 | 55 |
coding | Solve the programming task below in a Python markdown code block.
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along ... | {"inputs": ["4\nflovr-with-eggs 010\nchadken-him -26\nflotrswithout-efg- 7\nriwpep--tdpsghif 0001\n3\nf\nilour.wfth\n.huix-ruokf\na\nld\nkicj", "4\nflovr-with-eggs 000\nchbdken-him -26\nflotrswithouu-efg- 7\nriwpep--tdpsghif 0001\n3\nf\nitour.wflh\n.huix-rupkf\na\nkd\nkibj", "4\nflovr-with-eggs 010\nchbdken-him -26\nfl... | 397 | 727 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers... | {"functional": "def check(candidate):\n assert candidate(nums = [1,13,10,12,31]) == 6\n assert candidate(nums = [2,2,2]) == 1\n\n\ncheck(Solution().countDistinctIntegers)"} | 108 | 61 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and s... | {"inputs": ["1\n0 2\n", "1\n0 0\n", "1\n1 0\n", "1\n1 1\n", "1\n1 2\n", "1\n0 79\n", "1\n0 10\n", "1\n0 -1\n"], "outputs": ["3\n", "0\n", "1\n", "0\n", "1\n", "13\n", "4\n", "1\n"]} | 413 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Given a string, return the minimal number of parenthesis reversals needed to make balanced parenthesis.
For example:
```Javascript
solve(")(") = 2 Because we need to reverse ")" to "(" and "(" to ")". These are 2 reversals.
solve("(((())") = 1 We need... | {"functional": "_inputs = [[')()('], ['((()'], ['((('], ['())((('], ['())()))))()()(']]\n_outputs = [[2], [1], [-1], [3], [4]]\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... | 152 | 189 |
coding | Solve the programming task below in a Python markdown code block.
Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity.
Input
The input is given in the following format:
Sales unit price, sales quantity
Sales unit price, sales quanti... | {"inputs": ["100,20\n50,10\n80,35", "100,20\n01,05\n80,35", "100,20\n01,05\n80,36", "100,20\n01,05\n81,35", "000,20\n01,05\n80,36", "100,20\n50,10\n81,35", "000,10\n01,05\n80,36", "100,20\n50,01\n81,35"], "outputs": ["5300\n22\n", "4805\n20\n", "4885\n20\n", "4840\n20\n", "2885\n20\n", "5335\n22\n", "2885\n17\n", "4885... | 205 | 246 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7.
Note:
A string is palindromic if it reads the same forward... | {"functional": "def check(candidate):\n assert candidate(s = \"103301\") == 2\n assert candidate(s = \"0000000\") == 21\n assert candidate(s = \"9999900000\") == 2\n\n\ncheck(Solution().countPalindromes)"} | 139 | 79 |
coding | Solve the programming task below in a Python markdown code block.
Transpose
We can generate the transposition of an array using the tool numpy.transpose.
It will not affect the original array, but it will create a new array.
import numpy
my_array = numpy.array([[1,2,3],
[4,5,6]])
print nu... | {"inputs": ["2 2\n1 2\n3 4\n"], "outputs": ["[[1 3]\n [2 4]]\n[1 2 3 4]\n"]} | 302 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Luntik has decided to try singing. He has $a$ one-minute songs, $b$ two-minute songs and $c$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert.
He wants to make the abso... | {"inputs": ["4\n1 1 1\n2 1 3\n5 5 5\n1 1 2\n", "4\n1 1 1\n2 1 3\n5 2 5\n1 1 2\n", "4\n1 2 2\n2 1 1\n3 2 5\n1 1 2\n", "4\n1 2 2\n2 2 1\n3 2 2\n1 1 2\n", "4\n1 1 2\n2 2 1\n3 2 2\n2 1 2\n", "4\n2 2 0\n4 2 1\n6 4 5\n1 1 2\n", "4\n1 1 2\n2 2 1\n4 2 2\n2 1 2\n", "4\n2 2 0\n4 2 0\n6 4 5\n1 1 2\n"], "outputs": ["0\n1\n0\n1\n",... | 398 | 310 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $k$.
Your task is to construct such a string $s$ of length $n$ that for each $i$ from $1$ to $k$ there is at least one $i$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and ... | {"inputs": ["3\n7 3\n4 4\n6 2\n", "3\n7 3\n4 4\n6 2\n", "3\n3 3\n4 4\n6 2\n", "3\n7 3\n4 2\n6 2\n", "3\n7 2\n4 4\n6 2\n", "3\n7 3\n4 2\n5 2\n", "3\n7 3\n4 2\n5 1\n", "3\n7 3\n4 4\n5 1\n"], "outputs": ["abcabca\nabcd\nababab\n", "abcabca\nabcd\nababab\n", "abc\nabcd\nababab\n", "abcabca\nabab\nababab\n", "abababa\nabcd\... | 462 | 228 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.