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. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers $1$, $5$, $10$ and $50$ respectively. The use of other roman digits is not allowed. Numbers in this system are written as a seq...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["4\n", "10\n", "20\n", "35\n", "56\n", "83\n", "116\n", "155\n"]}
424
79
coding
Solve the programming task below in a Python markdown code block. [Chopsticks (singular: chopstick) are short, frequently tapered sticks used in pairs of equal length, which are used as the traditional eating utensils of China, Japan, Korea and Vietnam. Originated in ancient China, they can also be found in some areas ...
{"inputs": ["5 2\n1\n3\n3\n9\n4", "5 2\n2\n3\n3\n9\n4", "5 2\n6\n0\n3\n9\n6", "5 0\n6\n0\n3\n5\n4", "5 2\n3\n3\n3\n9\n4", "5 2\n6\n3\n3\n9\n4", "5 2\n6\n3\n3\n9\n6", "5 2\n0\n3\n3\n9\n4"], "outputs": ["2", "2\n", "1\n", "0\n", "2\n", "2\n", "2\n", "1\n"]}
513
157
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 1 2 6 3 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n1 1 1\n", "6\n8\n1 1 2 6 3 2 1 1\n3\n2 3 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 1\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1 1 2 6 3 2 1 2\n3\n2 1 3\n4\n2 10 9 1\n1\n26\n2\n1 1\n3\n2 1 1\n", "6\n8\n1...
743
598
coding
Solve the programming task below in a Python markdown code block. Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move ...
{"inputs": ["3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n2 2 4\n5\n0 0 0 2 2\n", "3\n3\n1 2 2\n3\n2 2 3\n5\n0 1 0 2 2\n", "3\n3\n2 2 2\n3\n2 2 1\n5\n0 0 0 2 2\n", "3\n3\n4 4 0\n3\n2 2 4\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n0 2 ...
568
326
coding
Solve the programming task below in a Python markdown code block. There is a long-established secondhand bookstore called JOI secondhand bookstore in your town, and you often use the JOI secondhand bookstore. Each book has a standard price, and you can buy it at that price if you go to the JOI secondhand bookstore. At...
{"inputs": ["7 2\n4 1\n0 1\n9 2\n10 3\n8 2\n4 8\n8 2", "7 2\n4 1\n9 1\n9 2\n3 5\n2 2\n4 3\n11 2", "7 2\n4 1\n0 1\n4 2\n10 3\n8 2\n4 8\n8 2", "7 4\n4 1\n13 1\n9 2\n3 5\n3 2\n4 3\n11 2", "7 5\n4 1\n13 2\n9 2\n10 3\n8 2\n4 8\n11 2", "7 1\n4 1\n13 2\n9 2\n10 3\n8 2\n4 8\n11 2", "7 4\n7 2\n0 1\n20 6\n15 2\n0 7\n5 5\n12 4", ...
467
327
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence a consisting ...
{"inputs": ["2 2\n1 62\n", "2 2\n1 71\n", "2 2\n44 44\n", "2 2\n47 47\n", "2 2\n88 44\n", "2 2\n47 71\n", "2 2\n33 44\n", "2 2\n54 71\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
460
132
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is going on a road trip and needs to apply for inter-district and inter-state travel e-passes. It takes A minutes to fill each inter-district e-pass appl...
{"inputs": ["3\n2 1 2\n00\n2 1 1\n01\n4 2 1\n1101"], "outputs": ["2\n2\n5"]}
464
45
coding
Solve the programming task below in a Python markdown code block. ## Your Story "A *piano* in the home meant something." - *Fried Green Tomatoes at the Whistle Stop Cafe* You've just realized a childhood dream by getting a beautiful and beautiful-sounding upright piano from a friend who was leaving the country. You im...
{"functional": "_inputs = [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]]\n_outputs = [['white'], ['black'], ['black'], ['white'], ['white'], ['white'], ['white'], ['black'], ['white'], ['black'], ['white']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
769
231
coding
Solve the programming task below in a Python markdown code block. N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals. The preliminary stage consists of several rounds, which will take place as follows:...
{"inputs": ["2\n1 2\n9 0", "2\n2 3\n9 0", "2\n1 2\n9 1", "2\n2 2\n9 0", "2\n2 6\n9 0", "2\n2 6\n8 0", "2\n2 6\n8 1", "2\n2 6\n8 2"], "outputs": ["1\n", "2\n", "3\n", "1\n", "6\n", "6\n", "8\n", "10\n"]}
570
127
coding
Solve the programming task below in a Python markdown code block. Chef's new friend hErd gave him two functions f and g. The function f is defined over x (x≥ 1) as: f(x) = \begin{cases} 0, & \text{if } x = 1 \\ f( \frac{x}{2} ) + 1, & \text{if } x \text{ is even} \\ f( \lfloor \frac{x}{2} \rfloor ), & \text{if } x ...
{"inputs": ["3\n1 1\n1 2\n1 20"], "outputs": ["1\n4\n35"]}
573
30
coding
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"]}
447
64
coding
Solve the programming task below in a Python markdown code block. Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems. Polycarp decided to store the hash of the password, generated by the following algorithm: take the passwor...
{"inputs": ["1\na\nabcd\n", "1\na\nabcd\n", "1\na\ndbca\n", "1\na\nebca\n", "1\na\nabce\n", "1\ndaaaaaaaa\nbbbbbbbbb\n", "1\ndaaaaaaaa\nbbbbbbbbb\n", "1\ndaaaaaaba\nbbbbbbbbb\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
613
118
coding
Solve the programming task below in a Python markdown code block. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black. Here, it is not allowed to paint two adjacent vertices both ...
{"inputs": ["1", "3\n1 2\n2 0", "3\n1 2\n2 3", "4\n1 2\n1 3\n2 4", "4\n1 2\n2 3\n2 4", "4\n1 2\n1 3\n3 4", "4\n1 2\n2 3\n3 4", "4\n1 4\n1 3\n2 4"], "outputs": ["2", "5\n", "5", "8\n", "9\n", "8\n", "8\n", "8\n"]}
327
136
coding
Solve the programming task below in a Python markdown code block. Problem There are N villages. Each village is numbered from 1 to N. Due to the recent merger boom, several villages have been merged. Two or more merged villages will become one new city, and villages that are not merged with any village will remain vil...
{"inputs": ["4 0", "7 0", "8 0", "0 0", "5 0", "13 0", "26 0", "16 0"], "outputs": ["4\n", "7\n", "8\n", "0\n", "5", "13\n", "26\n", "16\n"]}
462
83
coding
Solve the programming task below in a Python markdown code block. Create a program that converts data based on the given conversion table. The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion tabl...
{"inputs": ["3\nA a\n0 0\n5 4\n10\nB\nB\nC\n0\n1\n4\n5\na\nb\nA\n3\n@ a\n0 5\n5 4\n3\nA\nB\nC\n0\n1\n4\n5\na\nb\n@\n0", "3\nA a\n0 0\n5 4\n10\nB\nB\nC\n0\n1\n4\n5\na\nc\nA\n3\n@ a\n0 5\n5 4\n3\nA\nB\nC\n0\n1\n1\n5\na\nb\n@\n0", "3\nA a\n0 1\n5 5\n10\nB\nB\nC\n0\n1\n0\n5\na\nc\nA\n3\n@ a\n0 5\n5 5\n3\nA\nB\nC\n0\n1\n4\n...
469
707
coding
Solve the programming task below in a Python markdown code block. You are given a Directed Acyclic Graph (DAG) with $n$ vertices and $m$ edges. Each vertex $v$ has an integer, $a_v$, associated with it and the initial value of $a_v$ is $0$ for all vertices. You must perform $\textit{q}$ queries on the DAG, where each q...
{"inputs": ["6 5 18\n1 2\n1 3\n3 4\n2 4\n5 6\n1 1 3\n3 1\n3 2\n3 3\n3 4\n1 2 2\n3 1\n3 2\n3 3\n3 4\n2 6 7\n3 5\n3 6\n2 1 3\n3 1\n3 2\n3 3\n3 4\n"], "outputs": ["3\n3\n3\n3\n3\n2\n3\n2\n0\n0\n3\n2\n3\n2\n"]}
633
145
coding
Solve the programming task below in a Python markdown code block. - Input: Integer `n` - Output: String Example: `a(4)` prints as ``` A A A A A A A A ``` `a(8)` prints as ``` A A A A A A A A A A A A A A A A A ...
{"functional": "_inputs = [[4], [7], [11], [30], [-5], [0], [3]]\n_outputs = [[' A \\n A A \\n A A A \\nA A'], [' A \\n A A \\n A A \\n A A A A \\n A A \\nA A'], [' A \\n A A \\n A A \\n A A \\n A A \\n...
280
515
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. An isla...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]) == 1\n assert candidate(grid = [[1,1,0,1,1],[1,0,0,0,0],[0,0,0,0,1],[1,1,0,1,1]]) == 3\n\n\ncheck(Solution().numDistinctIslands)"}
138
121
coding
Solve the programming task below in a Python markdown code block. Timur initially had a binary string$^{\dagger}$ $s$ (possibly of length $0$). He performed the following operation several (possibly zero) times: Add ${0}$ to one end of the string and ${1}$ to the other end of the string. For example, starting from the...
{"inputs": ["1\n1\n1\n", "9\n3\n100\n4\n0111\n5\n10101\n6\n101010\n7\n1010110\n1\n1\n2\n10\n2\n11\n10\n1011011010\n"], "outputs": ["1\n", "1\n2\n5\n0\n3\n1\n0\n2\n4\n"]}
687
110
coding
Solve the programming task below in a Python markdown code block. Chinese Version Russian Version You are given a tree with N nodes and each has a value associated with it. You are given Q queries, each of which is either an update or a retrieval operation. The update query is of the format i j X This means you'd...
{"inputs": ["6 2\n1 2\n1 4\n2 6\n4 5\n4 3\n2 2\n1 6 3\n5 3 5\n6 4\n5 1\n"], "outputs": ["31\n18\n"]}
548
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros. Return the string that represents the kth largest integer in nums. Note: Duplicate numbers shou...
{"functional": "def check(candidate):\n assert candidate(nums = [\"3\",\"6\",\"7\",\"10\"], k = 4) == \"3\"\n assert candidate(nums = [\"2\",\"21\",\"12\",\"1\"], k = 3) == \"2\"\n assert candidate(nums = [\"0\",\"0\"], k = 2) == \"0\"\n\n\ncheck(Solution().kthLargestNumber)"}
142
99
coding
Solve the programming task below in a Python markdown code block. Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No". Constraints * 0 ≤ a, b, c ≤ 100 Input Three integers a, b and c separated by a single space are given in a line. Output Print "Yes" or "No" in a l...
{"inputs": ["1 6 8", "3 7 1", "1 6 9", "3 7 2", "1 9 9", "3 7 3", "1 9 2", "2 7 3"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
118
94
coding
Solve the programming task below in a Python markdown code block. Chef Tobby asked Bhuvan to brush up his knowledge of statistics for a test. While studying some distributions, Bhuvan learns the fact that for symmetric distributions, the mean and the median are always the same. Chef Tobby asks Bhuvan out for a game and...
{"inputs": ["3\n1\n2\n3"], "outputs": ["1\n1 2\n1 2 3"]}
473
28
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 and an integer k. In one operation, you can choose any index i where 0 <= i < nums.length and change nums[i] to nums[i] + x where x is an integer from the range [-k, k]. You can app...
{"functional": "def check(candidate):\n assert candidate(nums = [1], k = 0) == 0\n assert candidate(nums = [0,10], k = 2) == 6\n assert candidate(nums = [1,3,6], k = 3) == 0\n\n\ncheck(Solution().smallestRangeI)"}
156
79
coding
Solve the programming task below in a Python markdown code block. Complete the function that takes two numbers as input, ```num``` and ```nth``` and return the `nth` digit of `num` (counting from right to left). ## Note - If ```num``` is negative, ignore its sign and treat it as a positive value - If ```nth``` is not ...
{"functional": "_inputs = [[5673, 4], [129, 2], [-2825, 3], [0, 20], [65, 0], [24, -8], [-456, 5], [-1234, 2], [-5540, 1], [678998, 0], [-67854, -57], [0, -3]]\n_outputs = [[5], [2], [8], [0], [-1], [-1], [0], [3], [0], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
253
285
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has an undirected graph on N vertices. There are edges between all but M pairs of vertices. A permutation p on the vertices of the graph is represented as p[1], p[2],...
{"inputs": ["2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2", "2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2"], "outputs": ["2\n0", "2\n0"]}
400
70
coding
Solve the programming task below in a Python markdown code block. Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keywo...
{"functional": "_inputs = [['Welcome home', 'secret'], ['hello', 'wednesday'], ['HELLO', 'wednesday'], ['HeLlO', 'wednesday'], ['WELCOME HOME', 'gridlocked'], ['alpha bravo charlie', 'delta'], ['Home Base', 'seven'], ['basecamp', 'covert'], ['one two three', 'rails'], ['Test', 'unbuntu']]\n_outputs = [['wticljt dljt'],...
243
299
coding
Solve the programming task below in a Python markdown code block. Aaron is struggling with trigonometric functions, so his teacher gave him extra homework. Given an integer, $n$, he must answer the following question: What is the maximum value of $sin(x)+sin(y)+sin(z)$, where $x}$, $y$, and $z$ are positive integers a...
{"inputs": ["3\n"], "outputs": ["2.524412954\n"]}
256
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge. The graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicat...
{"functional": "def check(candidate):\n assert candidate(edges = [1,0,0,0,0,7,7,5]) == 7\n assert candidate(edges = [2,0,0,2]) == 0\n\n\ncheck(Solution().edgeScore)"}
166
63
coding
Solve the programming task below in a Python markdown code block. In telecomunications we use information coding to detect and prevent errors while sending data. A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the...
{"functional": "_inputs = [['01011001'], ['00110001'], ['11111111'], ['00000000'], ['11100111'], ['00111100 00111101'], ['00001111 11100001'], ['01011110 00011000'], ['11111111 11011100 11100011'], ['00111110 00110100 00111011'], ['01101110 01100000 01010110 10001111 01100011'], ['10100011 00111001 11001100 01010100 10...
463
569
coding
Solve the programming task below in a Python markdown code block. Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7. -----Constraints----- - 1 \leq S \leq 2000 - All...
{"inputs": ["3", "1", "8", "9", "6", "7", "2", "7\n"], "outputs": ["1\n", "0\n", "4\n", "6\n", "2\n", "3", "0", "3\n"]}
154
61
coding
Solve the programming task below in a Python markdown code block. There are N pieces of source code. The characteristics of the i-th code is represented by M integers A_{i1}, A_{i2}, ..., A_{iM}. Additionally, you are given integers B_1, B_2, ..., B_M and C. The i-th code correctly solves this problem if and only if A_...
{"inputs": ["2 3 -10\n1 2 3\n3 2 1\n1 1 2", "2 3 -10\n1 2 3\n3 2 1\n1 1 1", "2 3 -11\n1 2 3\n3 2 1\n1 1 1", "2 3 -15\n1 2 3\n3 2 1\n1 2 2", "2 3 -10\n1 2 3\n6 2 1\n1 1 2", "2 3 -10\n1 2 0\n3 2 1\n1 1 1", "2 3 -11\n1 2 3\n3 3 1\n1 1 1", "2 3 -15\n2 2 3\n3 2 1\n1 2 2"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "0\n...
442
246
coding
Solve the programming task below in a Python markdown code block. For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows: - f(b,n) = n, when n < b - f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b Here, {\rm floor}(n / b) denotes the largest integer not excee...
{"inputs": ["1\n1\n", "1\n2\n", "2\n1\n", "2\n2\n", "4\n1\n", "87654\n30\n", "87654\n138\n", "87654\n45678\n"], "outputs": ["2\n", "-1\n", "2\n", "3\n", "2\n", "10\n", "100\n", "-1\n"]}
385
108
coding
Solve the programming task below in a Python markdown code block. # Task Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees. # Example For `a = [-1, 150, 190, 17...
{"functional": "_inputs = [[[-1, 150, 190, 170, -1, -1, 160, 180]], [[-1, -1, -1, -1, -1]], [[4, 2, 9, 11, 2, 16]]]\n_outputs = [[[-1, 150, 160, 170, -1, -1, 180, 190]], [[-1, -1, -1, -1, -1]], [[2, 2, 4, 9, 11, 16]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
265
291
coding
Solve the programming task below in a Python markdown code block. Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities. Takahashi will buy some integers in this store. He c...
{"inputs": ["3 6\n3 1\n4 4\n2 5", "3 1\n3 3\n4 4\n2 5", "3 6\n4 1\n4 4\n2 5", "3 6\n2 3\n4 4\n2 5", "3 6\n0 0\n4 2\n3 5", "3 1\n3 3\n4 4\n4 5", "3 6\n0 1\n4 4\n2 5", "3 6\n0 1\n3 4\n2 5"], "outputs": ["9\n", "0\n", "10\n", "12\n", "5\n", "0\n", "10\n", "10\n"]}
333
178
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'. Suppose we need to investigate a mutation from a gene string startGene to a gene string endGene where one mutat...
{"functional": "def check(candidate):\n assert candidate(start = \"AACCGGTT\", end = \"AACCGGTA\", bank = [\"AACCGGTA\"]) == 1\n assert candidate(start = \"AACCGGTT\", end = \"AAACGGTA\", bank = [\"AACCGGTA\",\"AACCGCTA\",\"AAACGGTA\"]) == 2\n assert candidate(start = \"AAAAACCC\", end = \"AACCCCCC\", bank = [...
237
133
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple "croak" are mixed. Return the minimum n...
{"functional": "def check(candidate):\n assert candidate(croakOfFrogs = \"croakcroak\") == 1 \n assert candidate(croakOfFrogs = \"crcoakroak\") == 2 \n assert candidate(croakOfFrogs = \"croakcrook\") == -1\n\n\ncheck(Solution().minNumberOfFrogs)"}
186
88
coding
Solve the programming task below in a Python markdown code block. Your task is to create function```isDivideBy``` (or ```is_divide_by```) to check if an integer number is divisible by each out of two arguments. A few cases: ``` (-12, 2, -6) -> true (-12, 2, -5) -> false (45, 1, 6) -> false (45, 5, 15) -> ...
{"functional": "_inputs = [[8, 2, 4], [12, -3, 4], [8, 3, 4], [48, 2, -5], [-100, -25, 10], [10000, 5, -3], [4, 4, 2], [5, 2, 3], [-96, 25, 17], [33, 1, 33]]\n_outputs = [[True], [True], [False], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a...
174
285
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,5,9], threshold = 6) == 5\n assert candidate(nums = [2,3,5,7,11], threshold = 11) == 3\n assert candidate(nums = [19], threshold = 5) == 4\n\n\ncheck(Solution().smallestDivisor)"}
158
89
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. Chefina likes prefix and suffix sums, so Chef decided to give some to her as her birthday present. He created a sequence $a_{1}, a_{2}, \ldots, a_{N}...
{"inputs": ["4\n1\n-1 1\n1\n0 0\n2\n4 3 1 4\n3\n5 3 7 10 5 10"], "outputs": ["0\n1\n2\n4"]}
681
57
coding
Solve the programming task below in a Python markdown code block. In Berland recently a new collection of toys went on sale. This collection consists of 10^9 types of toys, numbered with integers from 1 to 10^9. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different ty...
{"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 1\n1 3\n", "2 1\n2 3\n", "2 0\n2 3\n", "2 0\n2 6\n", "2 0\n2 12\n", "3 7\n1 3 4\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "1\n1\n", "0\n\n", "0\n\n", "0\n\n", "2\n2 5 \n"]}
570
134
coding
Solve the programming task below in a Python markdown code block. Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such ...
{"inputs": ["2\n1 2\n", "2\n1 2\n", "3\n1 2\n1 3\n", "3\n1 2\n2 3\n", "3\n1 3\n2 3\n", "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n", "5\n1 3\n2 3\n3 4\n4 5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "2\n"]}
500
142
coding
Solve the programming task below in a Python markdown code block. After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, an...
{"inputs": ["Z\n1\na\n", "9\n1\n9\n", "9\n1\n13\n", "hb\n1\nAa\n", "abc\n1\nb\n", "hb\n1\nBa\n", "cba\n1\nb\n", "abcde\n1\nf\n"], "outputs": ["1 0", "0 0", "1 0\n", "2 0", "1 0", "2 0\n", "1 0\n", "5 0"]}
517
116
coding
Solve the programming task below in a Python markdown code block. There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i, the amount of sales q and the corresponding unit price p. Then, the...
{"inputs": ["4\n0010 3716 520\n14 3661 29\n1507 2460 80\n1101 670 2276\n2\n0011 100 0\n954 1100 000\n2\n715 245 100\n883 426 100\n0", "4\n0010 2000 520\n14 3661 29\n1507 375 1160\n1100 670 2276\n2\n0011 100 0\n954 1100 000\n2\n715 245 100\n50 426 100\n0", "4\n0110 1753 712\n14 3661 29\n266 2654 1160\n1101 451 793\n2\n0...
391
1,024
coding
Solve the programming task below in a Python markdown code block. Chef is watching TV. The current volume of the TV is X. Pressing the volume up button of the TV remote increases the volume by 1 while pressing the volume down button decreases the volume by 1. Chef wants to change the volume from X to Y. Find the minimu...
{"inputs": ["2\n50 54\n12 10\n"], "outputs": ["4\n2\n"]}
290
28
coding
Solve the programming task below in a Python markdown code block. # Task You are given integer `n` determining set S = {1, 2, ..., n}. Determine if the number of k-element subsets of S is `ODD` or `EVEN` for given integer k. # Example For `n = 3, k = 2`, the result should be `"ODD"` In this case, we have 3 2-ele...
{"functional": "_inputs = [[3, 2], [2, 1], [1, 1], [20, 10], [48, 12]]\n_outputs = [['ODD'], ['EVEN'], ['ODD'], ['EVEN'], ['EVEN']]\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, ...
305
204
coding
Solve the programming task below in a Python markdown code block. Return an output string that translates an input string `s`/`$s` by replacing each character in `s`/`$s` with a number representing the number of times that character occurs in `s`/`$s` and separating each number with the character(s) `sep`/`$sep`. Also ...
{"functional": "_inputs = [['hello world', '-'], ['19999999', ':'], ['^^^**$', 'x']]\n_outputs = [['1-1-3-3-2-1-1-2-1-3-1'], ['1:7:7:7:7:7:7:7'], ['3x3x3x2x2x1']]\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...
103
227
coding
Solve the programming task below in a Python markdown code block. Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another o...
{"inputs": ["2\n1 1\n", "2\n1 0\n", "2\n0 2\n", "2\n2 2\n", "2\n2 0\n", "2\n0 0\n", "2\n1 2\n", "3\n2 2 8\n"], "outputs": ["2\n", "1\n", "2\n", "4\n", "2\n", "0\n", "3\n", "4\n"]}
548
104
coding
Solve the programming task below in a Python markdown code block. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ ...
{"inputs": ["4\n1 2 2 4\n2 1 1\n3 0\n4 1 3", "4\n1 2 0 4\n2 1 1\n3 0\n4 1 3", "4\n1 2 1 4\n2 1 1\n3 0\n4 1 3", "4\n1 2 1 4\n2 1 2\n3 0\n4 1 3", "4\n1 2 0 4\n2 1 2\n3 0\n4 1 3", "4\n1 2 0 4\n2 1 4\n3 0\n0 1 3", "4\n1 2 0 4\n2 1 3\n3 0\n4 1 3", "4\n1 2 0 4\n2 1 3\n3 0\n4 1 4"], "outputs": ["0 1 0 1\n1 0 0 0\n0 0 0 0\n0 0...
462
494
coding
Solve the programming task below in a Python markdown code block. Suppose you are given a string s of length n consisting of lowercase English letters. You need to compress it using the smallest possible number of coins. To compress the string, you have to represent s as a concatenation of several non-empty strings: s...
{"inputs": ["3 3 1\naba\n", "4 2 1\nabcd\n", "4 1 1\nabcd\n", "4 10 2\naaaa\n", "4 10 1\naaaa\n", "1 3102 3554\nb\n", "1 3102 6861\nb\n", "1 5003 6861\nb\n"], "outputs": ["7", "8\n", "4", "14\n", "12", "3102", "3102\n", "5003\n"]}
535
145
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Given the rating R of a person, tell which division he belongs to. The rating range for each division are given below: Division 1: 2000 ≤ Rating. Division 2: 1600 ≤ Ratin...
{"inputs": ["3\n1500\n4000\n1900"], "outputs": ["3\n1\n2\n"]}
380
32
coding
Solve the programming task below in a Python markdown code block. Check Tutorial tab to know how to to solve. You are given a string $\mbox{S}$ and width $\boldsymbol{w}$. Your task is to wrap the string into a paragraph of width $\boldsymbol{w}$. Function Description Complete the wrap function in the edito...
{"inputs": ["ABCDEFGHIJKLIMNOQRSTUVWXYZ\n4\n"], "outputs": ["ABCD\nEFGH\nIJKL\nIMNO\nQRST\nUVWX\nYZ\n"]}
215
40
coding
Solve the programming task below in a Python markdown code block. The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by...
{"inputs": ["3 6\n", "3 4\n", "2 2\n", "3 9\n", "4 5\n", "2 7\n", "4 9\n", "3 9\n"], "outputs": ["5\n", "-1\n", "-1\n", "7\n", "5\n", "7\n", "7\n", "7\n"]}
344
86
coding
Solve the programming task below in a Python markdown code block. You are playing a game where you have been sent in a town to collect 10 types of coin and their symbol are defined with $A, B, C, D, E, F, G, H , I, J$. In that town every enemy have a coin. By killing one you will get a coin from that enemy. Each enemy ...
{"inputs": ["1\nABCDEFGHIJ"], "outputs": ["10"]}
275
16
coding
Solve the programming task below in a Python markdown code block. Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively. Constraints * $0 \leq S \leq 86400$ Input An integer $S$ is given in a li...
{"inputs": ["8", "6", "4", "2", "1", "3", "9", "0"], "outputs": ["0:0:8\n", "0:0:6\n", "0:0:4\n", "0:0:2\n", "0:0:1\n", "0:0:3\n", "0:0:9\n", "0:0:0\n"]}
154
94
coding
Solve the programming task below in a Python markdown code block. Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation : * Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k...
{"inputs": ["1\n0\n0", "1\n28\n3", "1\n28\n5", "1\n28\n8", "1\n28\n4", "1\n24\n8", "1\n49\n3", "1\n22\n8"], "outputs": ["0\n", "32\n", "33024\n", "1024\n", "64\n", "65536\n", "1088\n", "16384\n"]}
394
121
coding
Solve the programming task below in a Python markdown code block. # Feynman's squares Richard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing. Recently, an old farmer found some papers and ...
{"functional": "_inputs = [[1], [2], [3], [5], [8], [15]]\n_outputs = [[1], [5], [14], [55], [204], [1240]]\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...
273
193
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. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last i...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,1,4]) == True\n assert candidate(nums = [3,2,1,0,4]) == False\n\n\ncheck(Solution().canJump)"}
96
57
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring). The score after splitting a string is the number of zero...
{"functional": "def check(candidate):\n assert candidate(s = \"011101\") == 5 \n assert candidate(s = \"00111\") == 5\n assert candidate(s = \"1111\") == 3\n\n\ncheck(Solution().maxScore)"}
107
68
coding
Solve the programming task below in a Python markdown code block. There are N cubes stacked vertically on a desk. You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1. You can perform the following operation any number o...
{"inputs": ["1", "0", "0\n", "1\n", "0010", "1010", "0000", "1000"], "outputs": ["0\n", "0", "0\n", "0\n", "2\n", "4\n", "0\n", "2\n"]}
251
75
coding
Solve the programming task below in a Python markdown code block. Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w
{"inputs": ["w32njmda", "admjn23w", "acmjn23w", "3cmjn2aw", "3dmjn2aw", "wa2njmd3", "xa2njmd3", "xa3njmd3"], "outputs": ["admjn23w\n", "w32njmda\n", "w32njmca\n", "wa2njmc3\n", "wa2njmd3\n", "3dmjn2aw\n", "3dmjn2ax\n", "3dmjn3ax\n"]}
69
130
coding
Solve the programming task below in a Python markdown code block. After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency. These were the great news for Alice, whose grand...
{"inputs": ["3\n13 7 6\n6 2\n", "3\n13 2 6\n6 2\n", "3\n23 2 2\n6 2\n", "3\n23 2 4\n6 6\n", "3\n13 2 2\n6 2\n", "3\n23 2 2\n6 3\n", "3\n23 2 4\n6 3\n", "3\n20 7 6\n6 2\n"], "outputs": ["4\n", "2\n", "6\n", "12\n", "2\n", "6\n", "6\n", "6\n"]}
490
159
coding
Solve the programming task below in a Python markdown code block. Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take...
{"inputs": ["1 1 1 1\n1 1\n", "2 2 0 1\n1 2\n", "2 2 1 1\n1 2\n", "2 6 2 2\n1 2\n1 5\n", "5 9 2 2\n4 6\n1 5\n", "5 9 2 2\n4 6\n1 6\n", "2 6 2 2\n1 4\n1 5\n", "8 9 2 2\n4 6\n1 6\n"], "outputs": ["1\n", "0\n", "4\n", "8\n", "40\n", "48\n", "16\n", "120\n"]}
471
175
coding
Solve the programming task below in a Python markdown code block. You are given that a mango weighs X kilograms and a truck weighs Y kilograms. You want to cross a bridge that can withstand a weight of Z kilograms. Find the maximum number of mangoes you can load in the truck so that you can cross the bridge safely. ...
{"inputs": ["4\n2 5 11\n4 10 20\n1 1 1\n6 40 90\n"], "outputs": ["3\n2\n0\n8\n"]}
496
49
coding
Solve the programming task below in a Python markdown code block. The Bubble Cup hypothesis stood unsolved for 130 years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem: Given a number ...
{"inputs": ["1\n9\n", "1\n5\n", "1\n1\n", "1\n18\n", "1\n20\n", "1\n10\n", "2\n2 3\n", "2\n2 5\n"], "outputs": ["9\n", "4\n", "1\n", "30\n", "36\n", "12\n", "2\n2\n", "2\n4\n"]}
292
100
coding
Solve the programming task below in a Python markdown code block. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30...
{"inputs": ["0 1\n", "0 9\n", "0 9\n", "0 1\n", "10 1\n", "10 2\n", "10 9\n", "10 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]}
422
90
coding
Solve the programming task below in a Python markdown code block. Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maxi...
{"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n1 1\n", "2\n1 3\n", "2\n2 1\n", "2\n0 0\n", "2\n1 0\n"], "outputs": ["0", "1", "1\n", "0\n", "2\n", "1\n", "0\n", "1\n"]}
381
100
coding
Solve the programming task below in a Python markdown code block. Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table $M$ with $n$ rows and $n$ columns such that $M_{ij}=a_i \cdot a_j$ where $a_1, \dots, a_n$ is some sequence of positive integers. Of course, the ...
{"inputs": ["3\n0 2 4\n2 0 8\n4 8 0\n", "3\n0 4 4\n4 0 4\n4 4 0\n", "3\n0 6 6\n6 0 4\n6 4 0\n", "3\n0 6 6\n6 0 9\n6 9 0\n", "3\n0 9 9\n9 0 9\n9 9 0\n", "3\n0 4 8\n4 0 8\n8 8 0\n", "3\n0 6 6\n6 0 9\n6 9 0\n", "3\n0 4 8\n4 0 8\n8 8 0\n"], "outputs": ["1 2 4 ", "2 2 2 ", "3 2 2 ", "2 3 3 ", "3 3 3 ", "2 2 4 ", "2 3 3 ", "...
460
239
coding
Solve the programming task below in a Python markdown code block. Apple considers any iPhone with a battery health of 80\% or above, to be in *optimal* condition. Given that your iPhone has X\% battery health, find whether it is in *optimal* condition. ------ Input Format ------ - The first line of input will cont...
{"inputs": ["4\n97\n42\n80\n10\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
367
32
coding
Solve the programming task below in a Python markdown code block. Chef is frustrated in this lockown. So to overcome this he plans to travel various mountains. He is very strange so he sets some conditions for $each$ Type 2 query(mentioned below) (i.e. $1$ $i$) : - Let Chef has travelled till $ith$ mountain from left ...
{"inputs": ["1\n10 5\n1 3 5 4 5 6 7 8 4 5\n1 7\n1 3\n1 1\n0 2 7\n1 3"], "outputs": ["-1\n6\n5\n5"]}
687
67
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the number of prime numbers that are strictly less than n.   Please complete the following python code precisely: ```python class Solution: def countPrimes(self, n: int) -> int: ```
{"functional": "def check(candidate):\n assert candidate(n = 10) == 4\n assert candidate(n = 0) == 0\n assert candidate(n = 1) == 0\n\n\ncheck(Solution().countPrimes)"}
66
57
coding
Solve the programming task below in a Python markdown code block. The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange ...
{"inputs": ["3 2\n2 1 2\n0\n3 3 4 8\n3 2\n4 1 5 8 9\n3 2 5 9\n5 2 4 5 7 9\n3 3\n2 1 4\n3 2 5 9\n2 2 4\n3 3\n2 1 2\n3 1 2 9\n2 2 4\n0 0", "3 2\n2 1 4\n0\n3 3 4 8\n3 2\n4 1 5 8 9\n3 2 5 9\n5 1 4 5 7 9\n3 3\n2 1 4\n3 2 5 9\n2 2 4\n3 3\n2 1 2\n3 1 2 9\n2 2 4\n0 0", "3 2\n2 1 2\n0\n3 3 4 8\n3 2\n4 1 5 2 9\n3 2 5 9\n5 2 4 5 ...
544
942
coding
Solve the programming task below in a Python markdown code block. # Task Find the integer from `a` to `b` (included) with the greatest number of divisors. For example: ``` divNum(15, 30) ==> 24 divNum(1, 2) ==> 2 divNum(0, 0) ==> 0 divNum(52, 156) ==> 120 ``` If there are several numbers that have the sam...
{"functional": "_inputs = [[15, 30], [1, 2], [52, 156], [159, 4], [15, 48]]\n_outputs = [[24], [2], [120], ['Error'], [48]]\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)):...
165
206
coding
Solve the programming task below in a Python markdown code block. Suppose there is a circle. There are $N$ petrol pumps on that circle. Petrol pumps are numbered $\mbox{0}$ to $(N-1)$ (both inclusive). You have two pieces of information corresponding to each of the petrol pump: (1) the amount of petrol that particular ...
{"inputs": ["3\n1 5\n10 3\n3 4\n"], "outputs": ["1\n"]}
318
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n. We call an integer k fair if the number of even digits in k is equal to the number of odd digits in it. Return the smallest fair integer that is greater than or equal to n.   Please...
{"functional": "def check(candidate):\n assert candidate(n = 2) == 10\n assert candidate(n = 403) == 1001\n\n\ncheck(Solution().closestFair)"}
94
49
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. The ugliness of a string is defined as the count of two consecutive ones i.e. "11" in the given string. For example, the ugliness of string "10111" is $2$. You are...
{"inputs": ["2 \n3\n3 6 5\n2\n7 6"], "outputs": ["5 6 3\n6 7"]}
507
35
coding
Solve the programming task below in a Python markdown code block. Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to...
{"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "3\n1 2 3\n", "3\n1 1 3\n", "3\n1 1 1\n", "3\n0 2 3\n"], "outputs": ["0 ", "1 ", "0\n", "1\n", "0 1 2 ", "0 2 1 ", "0 2 3 \n", "1 0 2 \n"]}
388
116
coding
Solve the programming task below in a Python markdown code block. We have N colored balls arranged in a row from left to right; the color of the i-th ball from the left is c_i. You are given Q queries. The i-th query is as follows: how many different colors do the l_i-th through r_i-th balls from the left have? -----C...
{"inputs": ["4 1\n1 2 1 3\n1 3\n2 4\n3 3", "4 2\n1 2 1 3\n1 3\n2 4\n3 3", "4 3\n1 1 1 3\n1 3\n2 4\n3 3", "4 1\n0 2 1 3\n1 3\n2 4\n3 3", "4 2\n1 2 1 3\n1 3\n3 4\n3 3", "4 2\n1 1 1 3\n1 3\n3 4\n3 3", "4 2\n1 1 1 1\n1 3\n3 4\n3 5", "4 3\n1 2 1 5\n1 3\n2 4\n3 3"], "outputs": ["2\n", "2\n3\n", "1\n2\n1\n", "3\n", "2\n2\n", ...
338
254
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.). The numerical value of some string of lowercase English letters s is the concatenation of the let...
{"functional": "def check(candidate):\n assert candidate(firstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\") == True\n assert candidate(firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\") == False\n assert candidate(firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\") == True...
228
92
coding
Solve the programming task below in a Python markdown code block. Moamen and Ezzat are playing a game. They create an array $a$ of $n$ non-negative integers where every element is less than $2^k$. Moamen wins if $a_1 \,\&\, a_2 \,\&\, a_3 \,\&\, \ldots \,\&\, a_n \ge a_1 \oplus a_2 \oplus a_3 \oplus \ldots \oplus a_n$...
{"inputs": ["1\n1 0\n", "1\n1 0\n", "3\n3 1\n2 1\n4 0\n", "3\n6 1\n2 1\n4 0\n", "3\n6 1\n2 0\n4 0\n", "3\n3 1\n2 1\n4 0\n", "3\n11 1\n2 0\n4 0\n", "5\n22 59\n26 60\n72 72\n47 3\n97 16\n"], "outputs": ["1\n", "1\n", "5\n2\n1\n", "32\n2\n1\n", "32\n1\n1\n", "5\n2\n1\n", "1025\n1\n1\n", "719147166\n712743436\n592556526\n3...
510
241
coding
Solve the programming task below in a Python markdown code block. Problem There are $ 2 $ teams, Team UKU and Team Ushi. Initially, Team UKU has $ N $ people and Team Uku has $ M $ people. Team UKU and Team Ushi decided to play a game called "U & U". "U & U" has a common score for $ 2 $ teams, and the goal is to work ...
{"inputs": ["6 5", "5 9", "7 9", "1 1", "1 2", "1 3", "2 3", "3 3"], "outputs": ["2\n", "3\n", "3\n", "2\n", "1\n", "1\n", "3\n", "2\n"]}
574
78
coding
Solve the programming task below in a Python markdown code block. Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, bu...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n0\n", "1\n10\n", "2\n1 2\n"], "outputs": ["yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n"]}
480
121
coding
Solve the programming task below in a Python markdown code block. # Task We have a N×N `matrix` (N<10) and a robot. We wrote in each point of matrix x and y coordinates of a point of matrix. When robot goes to a point of matrix, reads x and y and transfer to point with x and y coordinates. For each point in...
{"functional": "_inputs = [[[['0,1', '0,0', '1,2'], ['1,1', '1,0', '0,2'], ['2,1', '2,0', '0,0']], 2], [[['0,1', '0,0'], ['1,1', '1,0']], 2]]\n_outputs = [[8], [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=t...
567
227
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a two-dimensional graph with points on it, find a line which passes the most number of points. Assume all the points that passed by the line are stored in list S sorted by their number. You need to return [S[0],...
{"functional": "def check(candidate):\n assert candidate([[0,0],[1,1],[1,0],[2,0]]) == [0,2]\n\n\ncheck(Solution().bestLine)"}
166
46
coding
Solve the programming task below in a Python markdown code block. Zonal Computing Olympiad 2012, 26 Nov 2011 A sequence of opening and closing brackets is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), (()) and ()(()) are well-...
{"inputs": ["20\n1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2"], "outputs": ["2 4 6 9"]}
666
59
coding
Solve the programming task below in a Python markdown code block. Manager of HackerX company is having big trouble. Workers are very unhappy with the way salary is given to them. They want every worker to have the same salary, otherwise they will go on a strike. Their current salaries are denoted by a sequence of N in...
{"inputs": ["4 2\n9 12 3 6\n0\n3\n"], "outputs": ["3\n3\n"]}
516
31
coding
Solve the programming task below in a Python markdown code block. Chef started watching a movie that runs for a total of X minutes. Chef has decided to watch the first Y minutes of the movie at twice the usual speed as he was warned by his friends that the movie gets interesting only after the first Y minutes. How lo...
{"inputs": ["50 24", "100 20"], "outputs": ["38", "90"]}
461
29
coding
Solve the programming task below in a Python markdown code block. Playing with Stones Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows: 1. Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in e...
{"inputs": ["3\n1 2\n2 21\n3 0", "3\n1 1\n2 21\n3 0", "3\n1 1\n2 21\n5 0", "3\n0 5\n9 58\n46 1", "3\n0 5\n9 23\n46 1", "3\n0 5\n9 23\n66 1", "3\n0 5\n9 19\n66 1", "3\n0 5\n9 19\n17 1"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
478
171
coding
Solve the programming task below in a Python markdown code block. Today is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and therefore, wan...
{"inputs": ["3\n3 4 1\n5 2 1\n3 4 3", "3\n3 4 1\n5 2 2\n3 4 3", "3\n3 4 1\n5 0 2\n3 4 3", "3\n3 0 1\n5 0 2\n1 4 3", "3\n3 0 1\n7 0 2\n1 4 3", "3\n3 1 1\n7 0 2\n1 4 3", "3\n0 1 1\n7 0 2\n1 4 3", "3\n0 1 1\n0 0 2\n1 4 3"], "outputs": ["0\n2\n0", "0\n1\n0\n", "0\n3\n0\n", "2\n3\n0\n", "2\n5\n0\n", "1\n5\n0\n", "0\n5\n0\n"...
401
237
coding
Solve the programming task below in a Python markdown code block. Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II. * insert $k$: Insert a node containing $k$ as key into $T$. * find $k$: Report whether $T$ has a node containing...
{"inputs": ["18\ninsert 4\ninsert 2\ninsert 3\ninsert 7\ninsert 8\ninsert 1\nfind 0\nfind 2\nfind 3\nfind 4\nfind 5\nfind 6\nfind 3\nfind 5\nprint\ndelete 3\ndelete 7\nprint", "18\ninsert 8\ninsert 2\ninsert 3\ninsert 7\ninsert 22\ninsert 1\nfind 1\nfind 2\nfind 1\nfind 4\nfind 5\nfind 6\nfind 7\nfind 8\nprint\ndelete ...
609
1,129
coding
Solve the programming task below in a Python markdown code block. There is a circular track of length M consisting of M checkpoints and M bidirectional roads such that each road has a length of 1 unit. Chef is currently at checkpoint A and wants to reach checkpoint B. Find the minimum length of the road he needs to tr...
{"inputs": ["4\n1 3 100\n1 98 100\n40 30 50\n2 1 2\n"], "outputs": ["2\n3\n10\n1\n"]}
433
53
coding
Solve the programming task below in a Python markdown code block. There are league games and tournament games in sports competitions. In soccer league games, points are given to each of the wins, losses, and draws, and the rankings are competed based on the points. The points are win (3 points), negative (0 points), an...
{"inputs": ["4\nJapan 1 0 2\nEgypt 1 2 0\nCanada 0 2 1\nniapS 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 1\nItaly 1 1 1\n0", "4\nJapan 1 0 2\nEgypt 1 2 0\nCaaadn 0 2 1\nniapS 2 0 1\n3\nIndia 0 2 0\nPoland 1 0 1\nItaly 1 1 1\n0", "4\nJapan 1 0 2\nEgypt 1 2 0\nCaaadn 0 2 1\nniapS 2 0 1\n3\nIodia 0 2 0\nPoland 1 0 1\nItaly 1 1 1\n...
405
862
coding
Solve the programming task below in a Python markdown code block. You have N soldiers numbered from 1 to N. Each of your soldiers is either a liar or a truthful person. You have M sets of information about them. Each set of information tells you the number of liars among a certain range of your soldiers. Let L be the t...
{"inputs": ["3 2\n1 2 1\n2 3 1\n", "20 11\n3 8 4\n1 9 6\n1 13 9\n5 11 5\n4 19 12\n8 13 5\n4 8 4\n7 9 2\n10 13 3\n7 16 7\n14 19 4\n"], "outputs": ["1 2\n", "13 14\n"]}
470
122
coding
Solve the programming task below in a Python markdown code block. On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most on...
{"inputs": ["1 0\n545\n", "1 0\n493\n", "1 0\n358\n", "1 0\n420\n", "1 0\n149\n", "1 0\n249\n", "1 0\n654\n", "1 0\n294\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
613
118
coding
Solve the programming task below in a Python markdown code block. Given a set of $N$ axis-aligned rectangles in the plane, find the area of regions which are covered by at least one rectangle. Constraints * $ 1 \leq N \leq 2000 $ * $ −10^9 \leq x1_i < x2_i\leq 10^9 $ * $ −10^9 \leq y1_i < y2_i\leq 10^9 $ Input The ...
{"inputs": ["2\n1 0 3 6\n1 2 4 3", "2\n1 0 3 6\n1 2 4 6", "2\n1 0 3 6\n1 4 4 6", "2\n1 0 3 6\n1 4 7 6", "2\n0 0 6 4\n1 2 4 3", "2\n1 0 3 1\n1 2 3 3", "2\n1 0 6 1\n1 2 3 3", "2\n0 0 3 4\n1 2 4 3"], "outputs": ["13\n", "16\n", "14\n", "20\n", "24\n", "4\n", "7\n", "13"]}
344
195
coding
Solve the programming task below in a Python markdown code block. AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen ea...
{"inputs": ["0", "3", "4", "8", "7", "5", "2", "1"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
235
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And ...
{"functional": "def check(candidate):\n assert candidate(s = \"PAYPALISHIRING\", numRows = 3) == \"PAHNAPLSIIGYIR\"\n assert candidate(s = \"PAYPALISHIRING\", numRows = 4) == \"PINALSIGYAHRPI\"\n assert candidate(s = \"A\", numRows = 1) == \"A\"\n\n\ncheck(Solution().convert)"}
157
92
coding
Solve the programming task below in a Python markdown code block. Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example...
{"inputs": ["a\n", "b\n", "c\n", "d\n", "e\n", "f\n", "g\n", "h\n"], "outputs": ["a\n", "b\n", "c\n", "d\n", "e\n", "f\n", "g\n", "h\n"]}
362
70
coding
Solve the programming task below in a Python markdown code block. Homer has two friends Alice and Bob. Both of them are string fans. One day, Alice and Bob decide to play a game on a string $s = s_1 s_2 \dots s_n$ of length $n$ consisting of lowercase English letters. They move in turns alternatively and Alice makes t...
{"inputs": ["1\na\n", "1\na\n", "1\nb\n", "3\na\nbbbb\naz\n", "3\na\nbbbb\nza\n", "3\na\nabbb\nza\n", "3\na\nbbbb\nay\n", "3\na\nabbb\naz\n"], "outputs": ["b\n", "b\n", "a\n", "b\nazaz\nby\n", "b\nazaz\naz\n", "b\nbzaz\naz\n", "b\nazaz\nbz\n", "b\nbzaz\nby\n"]}
522
133
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array cookies, where cookies[i] denotes the number of cookies in the ith bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All ...
{"functional": "def check(candidate):\n assert candidate(cookies = [8,15,10,20,8], k = 2) == 31\n assert candidate(cookies = [6,1,3,2,2,4,1,2], k = 3) == 7\n\n\ncheck(Solution().distributeCookies)"}
146
82