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.
Problem statement
Jota knows only the characters from `a` to` z` and the addition symbol `+`. Jota has an older sister, Tachiko. In addition to that, Tatsuko knows multiplication `*`, parentheses `(`, `)`, and integers (numbers) between `1` and` 9`. How... | {"inputs": ["5\nb+a+a", "5\nb+b+b", "5\na+a+b", "5\na+b+b", "5\nb+b+a", "5\nc+a+a", "5\nb+a+b", "5\nc+a+b"], "outputs": ["5\n", "3\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n"]} | 617 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Call a number stepping if adjacent digits, as well as the first and last digits, differ by one. How many n-digit base 11 stepping numbers are there? Give your answer modulo 4294967143.
For example, 8789A9 is a 6-digit base 11 stepping number. 9A0A and 2... | {"inputs": ["4\n2\n4\n6\n10"], "outputs": ["19\n54\n171\n1958"]} | 188 | 34 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k.
Define a pair (u, v) which consists of one element from the first array and one element from the second array.
Return t... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,7,11], nums2 = [2,4,6], k = 3) == [[1,2],[1,4],[1,6]]\n assert candidate(nums1 = [1,1,2], nums2 = [1,2,3], k = 2) == [[1,1],[1,1]]\n\n\ncheck(Solution().kSmallestPairs)"} | 140 | 106 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array pairs, where pairs[i] = [xi, yi], and:
There are no duplicates.
xi < yi
Let ways be the number of rooted trees that satisfy the following conditions:
The tree consists of nodes whose values a... | {"functional": "def check(candidate):\n assert candidate(pairs = [[1,2],[2,3]]) == 1\n assert candidate(pairs = [[1,2],[2,3],[1,3]]) == 2\n assert candidate(pairs = [[1,2],[2,3],[2,4],[1,5]]) == 0\n\n\ncheck(Solution().checkWays)"} | 243 | 89 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an integer k, partition s into k substrings such that the letter changes needed to make each substring a semi-palindrome are minimized.
Return the minimum number of letter changes required.
A semi... | {"functional": "def check(candidate):\n assert candidate(s = \"abcac\", k = 2) == 1\n assert candidate(s = \"abcdef\", k = 2) == 2\n assert candidate(s = \"aabbaa\", k = 3) == 0\n\n\ncheck(Solution().minimumChanges)"} | 464 | 73 |
coding | Solve the programming task below in a Python markdown code block.
There are two groups, one of $N$ boys and the other of $N$ girls numbered from $1$ to $N$.
You are given two arrays $A$ and $B$ containing $N$ numbers each, denoting the height of boys and girls in the group.
You have to form $N$ couples, where each cou... | {"inputs": ["1\n3\n4 5 1\n2 2 2"], "outputs": ["7"]} | 482 | 26 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We are playing the Guessing Game. The game will work as follows:
I pick a number between 1 and n.
You guess a number.
If you guess the right number, you win the game.
If you guess the wrong number, then I will tell y... | {"functional": "def check(candidate):\n assert candidate(n = 10) == 16\n assert candidate(n = 1) == 0\n assert candidate(n = 2) == 1\n\n\ncheck(Solution().getMoneyAmount)"} | 180 | 58 |
coding | Solve the programming task below in a Python markdown code block.
You have a tree of $n$ vertices. You are going to convert this tree into $n$ rubber bands on infinitely large plane. Conversion rule follows:
For every pair of vertices $a$ and $b$, rubber bands $a$ and $b$ should intersect if and only if there is an ed... | {"inputs": ["3\n1 3\n2 3\n", "3\n1 3\n2 3\n", "3\n1 2\n2 3\n", "4\n1 2\n2 3\n3 4\n", "4\n1 2\n2 4\n3 4\n", "4\n1 3\n2 4\n3 4\n", "4\n1 2\n1 4\n3 4\n", "4\n1 4\n2 4\n3 4\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n"]} | 559 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to make a feast. In order to do that, he needs a lot of different ingredients. Each ingredient has a certain tastiness; the tastiness of each ingredient may be any positive integer. Initially, for each tastiness between $K$ and $K+N-1$ (inclus... | {"inputs": ["2\n2 1\n3 3"], "outputs": ["0\n2"]} | 556 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a stri... | {"inputs": ["7\n", "4\n", "5\n", "9\n", "8\n", "2\n", "3\n", "0\n"], "outputs": ["7\n", "4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 417 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If no such uncommon subsequence exists, return -1.
An uncommon subsequence between two strings is a string that is a su... | {"functional": "def check(candidate):\n assert candidate(a = \"aaa\", b = \"bbb\") == 3\n assert candidate(a = \"aaa\", b = \"aaa\") == -1\n\n\ncheck(Solution().findLUSlength)"} | 107 | 55 |
coding | Solve the programming task below in a Python markdown code block.
Faizal and Sultan are having a one-on-one faceoff. Before stepping into the fight, each of them smoked a special kind of weed from Jhalwa. Smoking k grams of this weed grants the smoker the ability to resurrect k times after dying. Sultan smoked M grams ... | {"inputs": ["3\n2 1\n12 6\n6969 8563"], "outputs": ["7\n255\n988402422\n"]} | 711 | 46 |
coding | Solve the programming task below in a Python markdown code block.
```if:python,php
In this kata you will have to write a function that takes `litres` and `price_per_litre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre,... | {"functional": "_inputs = [[10, 21.5], [40, 10], [15, 5.83]]\n_outputs = [[212.5], [390], [83.7]]\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... | 315 | 195 |
coding | Solve the programming task below in a Python markdown code block.
[Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not.
### About syllables
[Syllables](https://en.wi... | {"functional": "_inputs = [['An old silent pond...\\nA frog jumps into the pond,\\nsplash! Silence again.'], ['An old silent pond...\\nA frog jumps into the pond, splash!\\nSilence again.'], ['An old silent pond...\\nA frog jumps into the pond,\\nsplash!\\nSilence again.'], ['An old silent pond... A frog jumps into the... | 571 | 370 |
coding | Solve the programming task below in a Python markdown code block.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one c... | {"inputs": ["1\n3\n", "1\n1\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n4\n", "1\n0\n", "4\n4 1 2 10\n"], "outputs": ["3 0\n", "1 0\n", "1 0\n", "3 0\n", "2 0\n", "4 0\n", "0 0\n", "12 5\n"]} | 403 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:
pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].
Note that ^ denotes the bitwise-xor operation.
It can be proven that t... | {"functional": "def check(candidate):\n assert candidate(pref = [5,2,0,3,1]) == [5,7,2,3,2]\n assert candidate(pref = [13]) == [13]\n\n\ncheck(Solution().findArray)"} | 111 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
You are given a function f which is defined as :
Your task is to find the value of
where M is given in input.
------ Input Format ------
First line contains T, the number of test ... | {"inputs": ["2\n5 114 1\n2\n50 3874 3\n31\n17\n21"], "outputs": ["72\n3718\n624\n1144"]} | 381 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Given an array A having N elements, a subarray S of A is called good if XOR(S) ≥ K, where XOR(S) denotes the [bitwise XOR] of all the elements of the subarray S.
Find the length of the smallest subarray S which is good. If there is no good subarray, pri... | {"inputs": ["3\n5 15\n1 4 2 8 1\n5 7\n1 4 2 8 1\n5 20\n1 4 2 8 1"], "outputs": ["4\n1\n-1"]} | 657 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more t... | {"inputs": ["1 1 1 0 0\n", "4 1 2 2 0\n", "1 5 5 1 1\n", "1 2 3 0 0\n", "1 1 1 1 0\n", "9 1 4 2 0\n", "4 2 2 0 1\n", "8 3 4 2 0\n"], "outputs": ["1\n", "3\n", "1\n", "1\n", "1\n", "4\n", "3\n", "3\n"]} | 482 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given n item's value and label as two integer arrays values and labels. You are also given two integers numWanted and useLimit.
Your task is to find a subset of items with the maximum sum of their values such ... | {"functional": "def check(candidate):\n assert candidate(values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1) == 9\n assert candidate(values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2) == 12\n assert candidate(values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, ... | 145 | 162 |
coding | Solve the programming task below in a Python markdown code block.
Round any given number to the closest 0.5 step
I.E.
```
solution(4.2) = 4
solution(4.3) = 4.5
solution(4.6) = 4.5
solution(4.8) = 5
```
Round **up** if number is as close to previous and next 0.5 steps.
```
solution(4.75) == 5
```
Also feel free to re... | {"functional": "_inputs = [[4.2], [4.25], [4.4], [4.6], [4.75], [4.8], [4.5], [4.55], [4.74], [4.74999999999], [4.74999999991]]\n_outputs = [[4], [4.5], [4.5], [4.5], [5], [5], [4.5], [4.5], [4.5], [4.5], [4.5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r... | 131 | 275 |
coding | 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'000\n", "1\nIAO'2000\n", "1\nIAO'2015\n", "1\nIAO'1015\n", "1\nIAO'3015\n", "1\nIAO'1014\n"], "outputs": ["3001\n", "3089\n", "3000\n", "12000\n", "12015\n", "11015\n", "13015\n", "11014\n"]} | 395 | 160 |
coding | Solve the programming task below in a Python markdown code block.
It's almost summertime, so Big Cat and Little Cat are getting in shape. They decide the core of their fitness plan is to start jogging every day.
Their city consists of $N$ intersections connected by $\mbox{M}$ bidirectional roads. The cats decide that ... | {"inputs": ["4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n"], "outputs": ["3\n"]} | 513 | 40 |
coding | Solve the programming task below in a Python markdown code block.
For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path).
Constraints
* 1 ≤ |V| ≤ 100000
* 0 ≤ di ≤ 10000
* 0 ≤ |E| ≤ 500000
* There are no parallel edges
* Ther... | {"inputs": ["4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n0 2 4\n1 2 0\n2 3 1\n1 3 5", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 1 1\n1 2 5\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 2 1\n0 3 4\n1 2 2\n2 2 2\n1 3 2", "4 5 0\n0 2 2\n0 3 4\n1 3 2\n3 2 2\n1 3 2", ... | 426 | 382 |
coding | Solve the programming task below in a Python markdown code block.
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the s... | {"inputs": ["1 1 1\nX\n", "1 1 1\nX\n", "1 1 2\nX\n", "1 1 1\nX\n", "1 1 2\nX\n", "1 2 2\nX.\n", "1 2 2\n.X\n", "1 2 2\nX*\n"], "outputs": ["IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "RL\n", "LR\n", "IMPOSSIBLE\n"]} | 595 | 138 |
coding | Solve the programming task below in a Python markdown code block.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it.
Each of the 2N - 1 squares ... | {"inputs": ["39 0", "630 0", "279 0", "328 0", "272 0", "173 0", "218 0", "674 0"], "outputs": ["1369", "394384", "76729", "106276", "72900", "29241", "46656", "451584"]} | 419 | 119 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have.
E.g Given the array **[7, 6, 15, 8]**
- 7 has **3 on** bits (000...0**111**)
- 6 has **2 on** bits (000...00**11**)
- 15 has *... | {"functional": "_inputs = [[[3, 8, 3, 6, 5, 7, 9, 1]], [[9, 4, 5, 3, 5, 7, 2, 56, 8, 2, 6, 8, 0]]]\n_outputs = [[[1, 8, 3, 3, 5, 6, 9, 7]], [[0, 2, 2, 4, 8, 8, 3, 5, 5, 6, 9, 7, 56]]]\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... | 321 | 277 |
coding | Solve the programming task below in a Python markdown code block.
Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of card... | {"inputs": ["1\n8\n", "1\n8\n", "1\n7\n", "1\n6\n", "2\n5 4\n", "2\n5 4\n", "2\n5 1\n", "2\n5 2\n"], "outputs": ["1", "1", "1\n", "1\n", "2", "2", "2\n", "2\n"]} | 520 | 90 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.
Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the en... | {"inputs": ["1\na\n", "1\ns\n", "1\ns\n", "1\na\n", "1\nt\n", "1\n`\n", "2\naa\n", "2\naa\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]} | 322 | 86 |
coding | Solve the programming task below in a Python markdown code block.
For an array of non-negative integers $a$ of size $n$, we construct another array $d$ as follows: $d_1 = a_1$, $d_i = |a_i - a_{i - 1}|$ for $2 \le i \le n$.
Your task is to restore the array $a$ from a given array $d$, or to report that there are multi... | {"inputs": ["1\n2\n5 5\n", "1\n2\n1 1\n", "1\n2\n3 3\n", "1\n2\n2 2\n", "1\n2\n4 4\n", "1\n2\n7 7\n", "1\n2\n2 3\n", "1\n2\n6 6\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "2 5\n", "-1\n"]} | 373 | 121 |
coding | Solve the programming task below in a Python markdown code block.
------ Problem Statement ------
Write a program that accepts sets of three numbers, and prints the second-maximum number among the three.
------ Input ------
First line contains the number of triples, N.
The next N lines which follow each have three... | {"inputs": ["3\n1 2 3\n10 15 5\n100 999 500"], "outputs": ["2\n10\n500"]} | 189 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Gildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of $n$ rows and $n$ columns of square cells. The rows are numbered from $1$ to $n$, from top to bottom, and the columns are numbered from $1$... | {"inputs": ["1 1\nB\n", "1 1\nW\n", "1 1\nW\n", "1 1\nB\n", "2 2\nBW\nWB\n", "2 1\nWW\nWW\n", "2 1\nBB\nWW\n", "2 1\nBB\nBB\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "4\n", "4\n", "2\n", "0\n"]} | 721 | 110 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
You are given a sequence $a$ consisting of $n$ positive integers.
Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements... | {"inputs": ["6\n8\n1 2 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 1 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n3 1\n3\n3 1 2\n", "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 1\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 1\n4\n1 2 3 2\n1\n26\n2\n2 1\n3\n2 1 1\n", "6\n8\n1 1 2... | 757 | 590 |
coding | Solve the programming task below in a Python markdown code block.
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.
According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 who... | {"inputs": ["1 0 1\n4 1 2\n1 0 1", "1 8 6\n2 9 7\n1 7 7", "0 8 8\n0 8 8\n0 0 8", "2 2 2\n2 1 0\n2 2 2", "1 0 1\n4 1 2\n0 0 1", "1 8 6\n4 9 7\n1 7 7", "0 8 2\n0 8 8\n0 0 8", "1 0 1\n4 1 4\n0 0 1"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 347 | 190 |
coding | Solve the programming task below in a Python markdown code block.
At the store, the salespeople want to make all prices round.
In this problem, a number that is a power of $10$ is called a round number. For example, the numbers $10^0 = 1$, $10^1 = 10$, $10^2 = 100$ are round numbers, but $20$, $110$ and $256$ are not ... | {"inputs": ["4\n1\n1\n1\n1\n", "1\n100000000\n", "14\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n2\n178\n20\n999999999\n9000\n987654321\n", "7\n100\n40000000\n89657\n326894\n2325566\n74444\n200055\n"], "outputs": ["0\n0\n0\n0\n", "0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n1\n78\n10\n899999999\n80... | 651 | 284 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n matrix grid consisting of positive integers.
You can start at any cell in the first column of the matrix, and traverse the grid in the following way:
From a cell (row, col), you can mo... | {"functional": "def check(candidate):\n assert candidate(grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]) == 3\n assert candidate(grid = [[3,2,4],[2,1,9],[1,1,7]]) == 0\n\n\ncheck(Solution().maxMoves)"} | 172 | 93 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
For example, "Hello World", "HELLO", "hello world hello world" are all sentences.
Words consist of only uppercas... | {"functional": "def check(candidate):\n assert candidate(sentence = \"leetcode exercises sound delightful\") == True\n assert candidate(sentence = \"eetcode\") == True\n assert candidate(sentence = \"Leetcode is cool\") == False\n\n\ncheck(Solution().isCircularSentence)"} | 222 | 60 |
coding | Solve the programming task below in a Python markdown code block.
# Story&Task
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all houses in the city were built in one row.
Let's enumerate all the houses from left to right, starting with 0. A house is c... | {"functional": "_inputs = [[[1, 2, 3, 1, 2]], [[3, 2, 1, 4]], [[1, 2, 3]], [[3, 2, 1]], [[1, 1, 1]]]\n_outputs = [[[3, 2, 0, 2, 0]], [[2, 3, 4, 0]], [[3, 2, 0]], [[0, 0, 0]], [[1, 1, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,... | 466 | 257 |
coding | Solve the programming task below in a Python markdown code block.
Chef got his dream seat in F1 and secured a 3^{rd} place in his debut race. He now wants to know the time gap between him and the winner of the race.
You are his chief engineer and you only know the time gap between Chef and the runner up of the race, g... | {"inputs": ["4\n1 1\n2 5\n3 2\n5 6\n"], "outputs": ["2\n7\n5\n11\n"]} | 500 | 37 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [xi, yi].
For the ith query, find the maximum value of nums1[j] + nums2[j] among all in... | {"functional": "def check(candidate):\n assert candidate(nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]]) == [6,10,7]\n assert candidate(nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]]) == [9,9,9]\n assert candidate(nums1 = [2,1], nums2 = [2,3], queries = [[3,3]]) == [-1]\n\... | 178 | 150 |
coding | Solve the programming task below in a Python markdown code block.
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an ... | {"inputs": ["3\n5\n9\n6\n2\n2\n0", "3\n5\n9\n6\n3\n2\n0", "3\n5\n9\n5\n3\n2\n0", "3\n5\n9\n1\n3\n2\n0", "3\n5\n9\n1\n4\n2\n0", "3\n5\n9\n2\n4\n2\n0", "3\n5\n9\n4\n2\n19\n0", "3\n5\n5\n3\n8\n19\n0"], "outputs": ["Case 1: 3\nCase 2: 5\nCase 3: 9\nCase 4: 6\nCase 5: 2\nCase 6: 2\n", "Case 1: 3\nCase 2: 5\nCase 3: 9\nCase ... | 264 | 482 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Chef is judging a game called "Broken telephone". There are total N players taking part in the game. They are all sitting in a line. In the start of the game, first player is given a secret mes... | {"inputs": ["3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 1\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 3\n5\n1 3 1 1 2\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 0 1 1 1\n4\n5 5 5 5", "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n9 5 5 5", "3\n7\n1 1 1 3 3 3 3\n5\n1 3 1 1 2\n4\n5 5 9 5", "3\n7\n1 2 1 3... | 547 | 397 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef calls a sequence *good* if it does not contain any two adjacent identical elements.
Initially, Chef has a sequence $a_{1}, a_{2}, \ldots, a_{N}... | {"inputs": ["1\n5 2\n1 1 2 5 2\n1 3\n4 2"], "outputs": ["5\n3"]} | 435 | 36 |
coding | Solve the programming task below in a Python markdown code block.
The eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object.
For example:
>>> eval("9 + 5")
14
>>> x = 2
>>> eval("x + 3")
5
Here, eval() ca... | {"inputs": ["print(2 + 3)\n"], "outputs": ["5\n"]} | 214 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You have a binary string S of length N. In one operation you can select a substring of S and reverse it. For example, on reversing the substring S[2,4] for S=11000, we change 1 \textcolor{red}{100} 0 \rightarrow 1 \textcolor{red}{001} 0.
Find the minimu... | {"inputs": ["4\n3\n000\n4\n1001\n4\n1010\n6\n010101"], "outputs": ["0\n1\n2\n2"]} | 577 | 47 |
coding | Solve the programming task below in a Python markdown code block.
The capital of Berland looks like a rectangle of size n × m of the square blocks of same size.
Fire!
It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are know... | {"inputs": ["8 5 1\n3 3\n", "10 5 1\n3 3\n", "10 5 1\n3 5\n", "10 5 1\n3 3\n", "5 1 2\n4 1\n5 1\n", "5 1 2\n4 1\n5 1\n", "5 1 2\n4 1\n1 1\n", "5 1 2\n4 1\n2 1\n"], "outputs": ["2\n", "2\n", "4\n", "2\n", "1\n", "1\n", "1\n", "1\n"]} | 445 | 153 |
coding | Solve the programming task below in a Python markdown code block.
This is a problem that involves adding numbers to items in a list.
In a list you will have to add the item's remainder when divided by a given divisor to each item.
For example if the item is 40 and the divisor is 3 you would have to add 1 since 40 minu... | {"functional": "_inputs = [[[2, 7, 5, 9, 100, 34, 32, 0], 3], [[], 2], [[1000, 999, 998, 997], 5], [[0, 0, 0, 0], 5], [[4, 3, 2, 1], 5], [[33, 23, 45, 78, 65], 10]]\n_outputs = [[[4, 8, 7, 9, 101, 35, 34, 0]], [[]], [[1000, 1003, 1001, 999]], [[0, 0, 0, 0]], [[8, 6, 4, 2]], [[36, 26, 50, 86, 70]]]\nimport math\ndef _de... | 326 | 359 |
coding | Solve the programming task below in a Python markdown code block.
We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to sat... | {"inputs": ["byeybe", "eybcxb", "ebyeyb", "eybeyb", "eybdyb", "eybcyb", "byecxb", "cyebxb"], "outputs": ["1\n", "6\n", "1\n", "1\n", "2\n", "2\n", "6\n", "4\n"]} | 242 | 80 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of cha... | {"inputs": ["3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n", "3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBRBR\n", "3\n5 3\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n", "3\n5 2\nBGGGG\n5 4\nRBRGR\n5 5\nBBRBR\n", "3\n5 3\nBGGGG\n5 3\nRBRGR\n5 2\nBBBRR\n", "3\n5 2\nBGGGG\n5 4\nRBRGR\n5 5\nBRBRB\n", "3\n5 1\nBGGGG\n5 2\nRBRGR\n5 5\nBBRBR\n", "3\n5 1... | 591 | 294 |
coding | Solve the programming task below in a Python markdown code block.
You are given three piles of casino chips: white, green and black chips:
* the first pile contains only white chips
* the second pile contains only green chips
* the third pile contains only black chips
Each day you take exactly two chips of different ... | {"functional": "_inputs = [[[1, 1, 1]], [[1, 2, 1]], [[4, 1, 1]], [[8, 2, 8]], [[8, 1, 4]], [[7, 4, 10]], [[12, 12, 12]], [[1, 23, 2]]]\n_outputs = [[1], [2], [2], [9], [5], [10], [18], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a,... | 482 | 251 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is ... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5]) == 24\n assert candidate(n = 3, edges = [[0,1],[1,2]], price = [1,1,1]) == 2\n\n\ncheck(Solution().maxOutput)"} | 223 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping su... | {"inputs": ["aaa\na\nb\n", "cumurcumur\num\ncur\n", "cumurcumur\nul\ncur\n", "abbbaaccca\nba\naca\n", "cunurcumur\nul\ncur\n", "abbbaaccca\nab\naca\n", "xxxbbbcccoca\nca\ncb\n", "xxxbbbcccoca\nca\nca\n"], "outputs": ["aaa\n", "umumcurcur\n", "curcurmmuu", "babaacabcc", "curcurmnuu", "ababacabcc\n", "cacbcbcboxxx\n", "c... | 390 | 150 |
coding | Solve the programming task below in a Python markdown code block.
There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the ... | {"inputs": ["1\n1000000\n", "1\n1000000\n", "1\n1000001\n", "1\n1000100\n", "1\n0000001\n", "1\n1000110\n", "1\n0001001\n", "1\n1001110\n"], "outputs": ["2 1\n", "2 1\n", "2 1 ", "2 1 ", "2 1 ", "2 1 ", "2 1 ", "2 1 "]} | 531 | 145 |
coding | Solve the programming task below in a Python markdown code block.
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.
Constraints... | {"inputs": ["5 2", "1 2", "1 3", "1 5", "1 4", "1 8", "1 6", "1 9"], "outputs": ["1\n", "2\n", "3\n", "5\n", "4\n", "8\n", "6\n", "9\n"]} | 212 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 f... | {"inputs": ["2\nS 1\nH 2", "2\nS 0\nH 1", "2\nS 2\nH 2", "2\nS 1\nH 1", "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2"], "outputs": ["Stable\nS 1\nH 2\n", "Stable\nS 0\nH 1\n", "Stable\nS 2\nH 2\n", "Stable\nS 1\nH 1", "Not stab... | 485 | 325 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit '0' with the letter 'O', and the digit '1' with t... | {"functional": "def check(candidate):\n assert candidate(num = \"257\") == \"IOI\"\n assert candidate(num = \"3\") == \"ERROR\"\n\n\ncheck(Solution().toHexspeak)"} | 170 | 50 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s consisting of n characters which are either 'X' or 'O'.
A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the chara... | {"functional": "def check(candidate):\n assert candidate(s = \"XXX\") == 1\n assert candidate(s = \"XXOX\") == 2\n assert candidate(s = \"OOOO\") == 0\n\n\ncheck(Solution().minimumMoves)"} | 124 | 57 |
coding | Solve the programming task below in a Python markdown code block.
# Write Number in Expanded Form
You will be given a number and you will need to return it as a string in [Expanded Form](https://www.mathplacementreview.com/arithmetic/whole-numbers.php#expanded-form). For example:
```python
expanded_form(12) # Should ... | {"functional": "_inputs = [[2], [12], [42], [70304], [4982342]]\n_outputs = [['2'], ['10 + 2'], ['40 + 2'], ['70000 + 300 + 4'], ['4000000 + 900000 + 80000 + 2000 + 300 + 40 + 2']]\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_to... | 192 | 250 |
coding | Solve the programming task below in a Python markdown code block.
We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds.
Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.
Let S and T be the sum of the numb... | {"inputs": ["3 3 2", "3 3 3", "0 3 2", "2 4 3", "3 4 2", "3 4 2\n", "7 5 5\n", "8 6 0\n"], "outputs": ["8\n", "7\n", "1\n", "4\n", "8", "8\n", "29\n", "9\n"]} | 372 | 97 |
coding | Solve the programming task below in a Python markdown code block.
Much cooler than your run-of-the-mill Fibonacci numbers, the Triple Shiftian are so defined: `T[n] = 4 * T[n-1] - 5 * T[n-2] + 3 * T[n-3]`.
You are asked to create a function which accept a base with the first 3 numbers and then returns the nth element.... | {"functional": "_inputs = [[[1, 1, 1], 25], [[1, 2, 3], 25], [[3, 2, 1], 25], [[6, 7, 2], 25], [[1, 1, 1], 35], [[1, 2, 3], 35], [[3, 2, 1], 35], [[6, 7, 2], 35], [[3, 2, 1], 0], [[6, 7, 2], 2]]\n_outputs = [[1219856746], [2052198929], [2827228055], [-2575238999], [10127083068293], [17037073417493], [23471258855679], [... | 312 | 396 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.