problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. # Introduction: Reversi is a game usually played by 2 people on a 8x8 board. Here we're only going to consider a single 8x1 row. Players take turns placing pieces, which are black on one side and white on the other, onto the board with their colour fac...
{"functional": "_inputs = [[[]], [[0]], [[0, 1]], [[0, 7, 4]], [[3]], [[3, 4]], [[3, 4, 5]], [[2, 1, 0]], [[0, 1, 4, 3, 2]], [[0, 1, 7, 2, 3]], [[3, 2, 7, 1, 0]], [[3, 4, 5, 6, 0, 2]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[7, 0, 1]], [[0, 7, 6]], [[1, 0, 2, 3, 4, 5, 6, 7]], [[5, 1, 3, 4, 6]], [[1, 7, 0, 5, 6, 4]]]\n_outputs = ...
coding
360
Solve the programming task below in a Python markdown code block. Athenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception. His song consists of $n$ notes, whic...
{"inputs": ["5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\n", "5\n6\n1 2 2 2 5 6\n2\n2 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\n", "5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 3\n", "5\n6\n1 2 2 4 5 6\n2\n2 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 2 2 2 2\n", "5\n6\n1 2 2 4 5 6\n2\n2 4\n6\n1...
coding
640
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or r...
{"functional": "def check(candidate):\n assert candidate(n = 12, k = 3) == 3\n assert candidate(n = 7, k = 2) == 7\n assert candidate(n = 4, k = 4) == -1\n\n\ncheck(Solution().kthFactor)"}
coding
115
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship...
{"functional": "def check(candidate):\n assert candidate(n = 3, relations = [[1,3],[2,3]]) == 2\n assert candidate(n = 3, relations = [[1,2],[2,3],[3,1]]) == -1\n\n\ncheck(Solution().minimumSemesters)"}
coding
184
Solve the programming task below in a Python markdown code block. There will be two arrays of integers. Determine all integers that satisfy the following two conditions: The elements of the first array are all factors of the integer being considered The integer being considered is a factor of all elements of the se...
{"inputs": ["2 3\n2 4\n16 32 96\n"], "outputs": ["3\n"]}
coding
523
Solve the programming task below in a Python markdown code block. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from a_{i} to b_{i}. Of course, Famil Door wants to have as many friends celebr...
{"inputs": ["1\nF 1 2\n", "1\nF 1 2\n", "1\nF 1 1\n", "1\nF 1 3\n", "1\nF 1 4\n", "1\nF 2 4\n", "1\nF 4 4\n", "1\nF 68 307\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
508
Solve the programming task below in a Python markdown code block. You are given positive integers A and B. Find the K-th largest positive integer that divides both A and B. The input guarantees that there exists such a number. -----Constraints----- - All values in input are integers. - 1 \leq A, B \leq 100 - The K-...
{"inputs": ["2 1 1", "4 8 1", "1 1 1", "1 1 1\n", "12 3 2", "8 12 3", "6 12 2", "16 1 1"], "outputs": ["1\n", "4\n", "1", "1\n", "1\n", "1\n", "3\n", "1\n"]}
coding
180
Solve the programming task below in a Python markdown code block. Little Leon lives in the forest. He has recently noticed that some trees near his favourite path are withering, while the other ones are overhydrated so he decided to learn how to control the level of the soil moisture to save the trees. There are $n$ t...
{"inputs": ["4\n3\n-2 -2 -2\n3\n10 4 7\n4\n4 -4 4 -4\n5\n1 -2 3 -4 5\n"], "outputs": ["2\n13\n36\n33\n"]}
coding
619
Solve the programming task below in a Python markdown code block. Consider an undirected graph containing $N$ nodes and $\mbox{M}$ edges. Each edge $\textit{M}_i$ has an integer cost, $C_i$, associated with it. The penalty of a path is the bitwise OR of every edge cost in the path between a pair of nodes, $\mbox{A}$ a...
{"inputs": ["3 4\n1 2 1\n1 2 1000\n2 3 3\n1 3 100\n1 3\n"], "outputs": ["3\n"]}
coding
626
Solve the programming task below in a Python markdown code block. ## Task Implement a function which finds the numbers less than `2`, and the indices of numbers greater than `1` in the given sequence, and returns them as a pair of sequences. Return a nested array or a tuple depending on the language: * The first se...
{"functional": "_inputs = [[[0, 1, 2, 1, 0, 2, 1, 1, 1, 0, 4, 5, 6, 2, 1, 1, 0]], [[0, 1, 1, 2, 0]], [[2, 2, 0]], [[0, 1, 2, 1, 0, 2, 1, 1]], [[1]], [[3, 0, 7, 0, 2, 0]]]\n_outputs = [[[[0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0], [2, 5, 10, 11, 12, 13]]], [[[0, 1, 1, 0], [3]]], [[[0], [0, 1]]], [[[0, 1, 1, 0, 1, 1], [2, 5]]], [...
coding
208
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. Let's define Fibonacci concatenation sequence as follows: f[0] = 0, f[1] = 1 f[i] = f[i-1] + f[i-2], for every i β‰₯ 2 Here f[i] denotes the i^{th} Fibonacci concatenation number and + repres...
{"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n2\n8\n"]}
coding
581
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"...
coding
401
Solve the programming task below in a Python markdown code block. Read problems statements in [Russian], [Vietnamese], [Hindi], [Mandarin chinese] and [Bengali] as well. Chef is interested in the history of SnackDown contests. He needs a program to verify if SnackDown was hosted in a given year. SnackDown was hosted ...
{"inputs": ["2\n2019\n2018"], "outputs": ["HOSTED\nNOT HOSTED"]}
coding
242
Solve the programming task below in a Python markdown code block. This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings a and b of length ...
{"inputs": ["5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n", "5\n2\n01\n10\n5\n01011\n11110\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n", "5\n2\n01\n10\n5\n01001\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n", "5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n...
coding
605
Solve the programming task below in a Python markdown code block. In a test, there are N problems, each carrying X marks. In each problem, Chef either received X marks or 0 marks. Determine whether is it possible for Chef to achieve exactly Y marks. ------ Input Format ------ - The first line of input will contai...
{"inputs": ["5\n1 8 4\n3 6 12\n4 5 0\n10 10 100\n8 5 36\n"], "outputs": ["NO\nYES\nYES\nYES\nNO\n"]}
coding
413
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 has a simple undirected graph with $N$ vertices (numbered $1$ through $N$) and $M$ edges. He wants to divide it into $K$ parts (subgraphs) for s...
{"inputs": ["1\n5 5\n1 2\n1 3\n2 3\n2 4\n3 4"], "outputs": ["2\n1 2 1 1 2"]}
coding
735
Solve the programming task below in a Python markdown code block. For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: $f(i, j) = \left\{\begin{array}{ll}{P [ i ]} & {\text{if} j = 1} \\{f(P [ i ], j - 1)} & {\text{otherwise}} \end{array} \right.$ Let g(i) be the minimum positive i...
{"inputs": ["9 2 5\n", "3 2 1\n", "7 4 4\n", "1 1 1\n", "9 7 9\n", "4 3 2\n", "5 4 5\n", "5 3 4\n"], "outputs": ["2 1 4 3 6 7 8 9 5 ", "1 2 3 ", "-1", "1 ", "2 3 4 5 6 7 8 9 1 ", "2 1 4 3 ", "2 3 4 5 1 ", "-1"]}
coding
351
Solve the programming task below in a Python markdown code block. Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequenc...
{"inputs": ["2\n2\n2 3\n4\n2 6 7 7"], "outputs": ["2\n64"]}
coding
472
Solve the programming task below in a Python markdown code block. A border of a string is a proper prefix of it that is also a suffix. For example: a and abra are borders of abracadabra, kan and kankan are borders of kankankan. de is a border of decode. Note that decode is not a border of decode because it's not pr...
{"inputs": ["aaaa\n", "ababa\n", "abcacb\n"], "outputs": ["10\n", "5\n", "3\n"]}
coding
663
Solve the programming task below in a Python markdown code block. Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from ...
{"inputs": ["1 0\n", "2 2\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "4 1\n1 2\n2 3\n3 4\n", "5 1\n1 2\n4 3\n5 3\n2 3\n", "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "10 5\n6 4\n4 1\n7 5\n8 7\n2 6\n3 6\n8 6\n10 3\n4 9\n"], "outputs": ["1", "3\n", "3", "1", "9", "15", "91", "1023"]}
coding
559
Solve the programming task below in a Python markdown code block. The purpose of this series is developing understanding of stastical problems in AS and A level maths. Let's get started with a simple concept in statistics: Mutually exclusive events. The probability of an OR event is calculated by the following rule: ...
{"functional": "_inputs = [[[[3, 0.4], [4, 0.1], [1, 0.01], [2, 0.09], [5, 0.2], [6, 0.1]], 1, 6], [[[1, 0.1], [2, 0.14], [3, 0.16], [4, 0.2], [5, 0.15], [6, 0.25]], 1, 4], [[[1, 0.6], [2, 0.1001], [3, 0.0999], [4, 0.1], [5, 0.05], [6, 0.05]], 3, 4], [[[6, 0.25], [1, 0.1], [3, 0.16], [2, 0.14], [5, 0.15], [4, 0.2]], 1,...
coding
601
Solve the programming task below in a Python markdown code block. The polar bears are going fishing. They plan to sail from (s_{x}, s_{y}) to (e_{x}, e_{y}). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x...
{"inputs": ["1 5 5 5 6\nE\n", "1 5 5 5 6\nE\n", "1 5 3 5 6\nE\n", "1 5 8 5 6\nE\n", "1 0 0 0 -1\nS\n", "1 0 0 0 -1\nS\n", "1 5 3 5 12\nE\n", "1 -2 0 0 0\nS\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "1\n", "1\n", "-1\n", "-1\n"]}
coding
489
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 has a string $S$. He also has another string $P$, called *pattern*. He wants to find the pattern in $S$, but that might be impossible. Therefore...
{"inputs": ["3\nakramkeeanany\naka\nsupahotboy\nbohoty\ndaehabshatorawy\nbadawy"], "outputs": ["aaakaeekmnnry\nabohotypsu\naabadawyehhorst"]}
coding
479
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. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer ar...
{"functional": "def check(candidate):\n assert candidate(segments = [[1,4,5],[4,7,7],[1,7,9]]) == [[1,4,14],[4,7,16]]\n assert candidate(segments = [[1,7,9],[6,8,15],[8,10,7]]) == [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]\n assert candidate(segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]) == [[1,4,12],[4,7,12]]\n\n\n...
coding
448
Solve the programming task below in a Python markdown code block. There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time. Unfortunately, reading service is provided ...
{"inputs": ["1 100 9\n11 2 10\n12 2 11\n0 0 0"], "outputs": ["9\n15\n16"]}
coding
559
Solve the programming task below in a Python markdown code block. A strongness of an even number is the number of times we can successively divide by 2 until we reach an odd number starting with an even number n. For example, if n = 12, then * 12 / 2 = 6 * 6 / 2 = 3 So we divided successively 2 times and we reached 3...
{"functional": "_inputs = [[1, 2], [5, 10], [48, 56], [129, 193], [2, 3], [4, 6], [3, 310], [33, 40], [456445, 678860], [324243, 897653214], [1151592177, 2129680158], [2085422641, 2128923730], [1082012216, 1876572332], [1806570867, 2067832928], [206346325, 1289058842]]\n_outputs = [[2], [8], [48], [192], [2], [4], [256...
coding
394
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here ------ Problem Statement ------ Maxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city. Β  If you remember, lucky numbers are positive integers whose ...
{"inputs": ["10\n2\n4\n2\n7\n5\n6\n7\n8\n9\n2", "10\n2\n2\n2\n4\n5\n8\n1\n2\n9\n5", "10\n2\n2\n1\n4\n5\n6\n3\n8\n9\n4", "10\n2\n3\n2\n5\n5\n4\n1\n2\n9\n5", "10\n2\n2\n1\n6\n5\n6\n3\n8\n9\n4", "10\n2\n4\n2\n7\n4\n6\n7\n8\n9\n2", "10\n2\n5\n4\n5\n5\n4\n1\n2\n9\n2", "10\n3\n4\n2\n9\n4\n6\n7\n8\n9\n2"], "outputs": ["0\n1\n...
coding
370
Solve the programming task below in a Python markdown code block. To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are...
{"inputs": ["7 2 2 2\n", "2 2 2 2\n", "1 0 2 0\n", "3 3 2 1\n", "1 1 0 0\n", "1 0 0 1\n", "1 0 1 0\n", "7 3 0 5\n"], "outputs": ["1\n", "3\n", "1\n", "3\n", "0\n", "0\n", "1\n", "1\n"]}
coding
354
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...
coding
499
Solve the programming task below in a Python markdown code block. Create a program of the square picking method, which is one of the classical random number generation methods. The square harvesting method was proposed by von Neumann in the mid-1940s. In the square picking method, when the number of digits of the gene...
{"inputs": ["2\n-2\n1", "2\n12\n0", "2\n20\n0", "2\n94\n0", "2\n88\n0", "2\n0\n36", "2\n1\n43", "2\n1\n39"], "outputs": ["Case 1:\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\nCase 2:\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "Case 1:\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\nCase 2:\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "Case 1:\n4\n0\n0\n0\n0\n0\n0\n0\n0...
coding
541
Solve the programming task below in a Python markdown code block. Takahashi, who is A years old, is riding a Ferris wheel. It costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who a...
{"inputs": ["6 111", "9 100", "9 010", "1 100", "2 100", "2 101", "0 000", "3 101"], "outputs": ["55\n", "50\n", "5\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
228
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "". A string is palindromic if it reads the same forward and backward. Β  Please com...
{"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]) == \"ada\"\n assert candidate(words = [\"notapalindrome\",\"racecar\"]) == \"racecar\"\n assert candidate(words = [\"def\",\"ghi\"]) == \"\"\n\n\ncheck(Solution().firstPalindrome)"}
coding
96
Solve the programming task below in a Python markdown code block. Alice wrote an exam containing N true or false questions (i.e. questions whose answer is either true or false). Each question is worth 1 mark and there is no negative marking in the examination. Alice scored K marks out of N. Bob wrote the same exam but...
{"inputs": ["3\n1 1\n50 0\n100 76\n"], "outputs": ["0\n50\n24\n"]}
coding
337
Solve the programming task below in a Python markdown code block. You are given a permutation $a$ of size $n$ and you should perform $n$ operations on it. In the $i$-th operation, you can choose a non-empty suffix of $a$ and increase all of its elements by $i$. How can we perform the operations to minimize the number o...
{"inputs": ["1\n8\n7 6 5 4 3 2 8 1\n", "1\n8\n8 1 7 6 5 4 3 2\n", "1\n9\n9 1 8 7 6 5 4 3 2\n", "1\n10\n10 3 2 1 9 8 7 6 5 4\n", "1\n10\n10 1 9 8 7 6 5 4 3 2\n", "1\n10\n8 7 6 5 4 3 9 2 10 1\n", "1\n10\n6 5 4 2 9 8 7 1 10 3\n", "1\n10\n9 8 7 6 5 4 3 2 10 1\n"], "outputs": ["7 1 2 3 4 5 6 8 \n", "1 3 4 5 6 7 8 2 \n", "1 ...
coding
696
Solve the programming task below in a Python markdown code block. You are given two arrays $a_1, a_2, \dots , a_n$ and $b_1, b_2, \dots , b_m$. Array $b$ is sorted in ascending order ($b_i < b_{i + 1}$ for each $i$ from $1$ to $m - 1$). You have to divide the array $a$ into $m$ consecutive subarrays so that, for each ...
{"inputs": ["1 1\n1\n1\n", "1 1\n2\n1\n", "1 1\n3\n2\n", "1 1\n5\n3\n", "1 1\n1\n1\n", "1 1\n5\n3\n", "1 1\n2\n1\n", "1 1\n3\n2\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1", "0", "0", "0"]}
coding
613
Solve the programming task below in a Python markdown code block. It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows. * 3 Play the game. * The person who gets 11 points f...
{"inputs": ["AABBAAABABAABBBAABA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABABAAABBAABBBABAA\nAAAAAAAAAAA\nABBBBBBBBBB\n0", "ABAABBBAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABABAAABBAABBBABAA\nAAAAAAAAAAA\nABBBBBABBBB\n0", "ABAABBBAABABAAABBAA\nAABBBABBABBAAABABABAAB\nBABAABAABABABBAAAB\nAABAABBA...
coding
453
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following: 0 represents a wall that you cannot pass through. 1 repres...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3) == [[0,1],[1,1],[2,1]]\n assert candidate(grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2) == [[2,1],[1,2]]\n assert candidate(grid = [[1,1,1],[0...
coding
372
Solve the programming task below in a Python markdown code block. We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. -----Constraints----- - 1 \leq N \leq 10000 - N is ...
{"inputs": ["8", "0", "1", "2", "3", "4", "6", "9"], "outputs": ["992\n", "0\n", "999\n", "998\n", "997\n", "996\n", "994\n", "991\n"]}
coding
163
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. You have $C = 100,000$ cakes, numbered $1$ through $C$. Each cake has an integer height; initially, the height of each cake is $0$. There are $N$ op...
{"inputs": ["1\n3 2\n2 6\n4 9\n1 4"], "outputs": ["3"]}
coding
723
Solve the programming task below in a Python markdown code block. We all love the future president (or Führer or duce or sōtō as he could find them more fitting) donald trump, but we might fear that some of his many fans like John Miller or John Barron are not making him justice, sounding too much like their (and our a...
{"functional": "_inputs = [['I will build a huge wall'], ['HUUUUUGEEEE WAAAAAALL'], ['MEXICAAAAAAAANS GOOOO HOOOMEEEE'], ['America NUUUUUKEEEE Oooobaaaamaaaaa'], ['listen migrants: IIII KIIIDD YOOOUUU NOOOOOOTTT']]\n_outputs = [[0], [4], [2.5], [1.89], [1.56]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinsta...
coding
438
Solve the programming task below in a Python markdown code block. Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs...
{"inputs": [".\n", "+\n", ">\n", "<\n", ",\n", "-\n", "[\n", "]\n"], "outputs": ["12\n", "10\n", "8\n", "9\n", "13\n", "11\n", "14\n", "15\n"]}
coding
509
Please solve the programming task below using a self-contained code snippet in a markdown code block. A cinemaΒ has nΒ rows of seats, numbered from 1 to nΒ and there are tenΒ seats in each row, labelled from 1Β to 10Β as shown in the figure above. Given the array reservedSeats containing the numbers of seats already reserve...
{"functional": "def check(candidate):\n assert candidate(n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]) == 4\n assert candidate(n = 2, reservedSeats = [[2,1],[1,8],[2,6]]) == 2\n assert candidate(n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]) == 4\n\n\ncheck(Solution().maxNumberOfFamilies)"}
coding
253
Solve the programming task below in a Python markdown code block. Snuke has a string x of length N. Initially, every character in x is `0`. Snuke can do the following two operations any number of times in any order: * Choose A consecutive characters in x and replace each of them with `0`. * Choose B consecutive chara...
{"inputs": ["7 2 3", "7 1 3", "3 3 2", "3 2 2", "9 7 2", "6 2 3", "5 2 3", "9 7 3"], "outputs": ["116\n", "128\n", "4\n", "6\n", "242\n", "55\n", "25\n", "129\n"]}
coding
260
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows: In each step, you will choose any 3 piles of coins (not necessarily consecutive). Of your choice, Alice will pick...
{"functional": "def check(candidate):\n assert candidate(piles = [2,4,1,2,7,8]) == 9\n assert candidate(piles = [2,4,5]) == 4\n assert candidate(piles = [9,8,7,6,5,1,2,3,4]) == 18\n\n\ncheck(Solution().maxCoins)"}
coding
169
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. Sergey recently learned about country codes - two letter strings, denoting countries. For example, BY stands for Belarus and IN stands for India. Mesmerized by this new disc...
{"inputs": ["2\nINBY\nBYBY"], "outputs": ["3\n2"]}
coding
320
Solve the programming task below in a Python markdown code block. The positive odd numbers are sorted in ascending order as $1,3,5,7,9,11,13,15,17,19\ldots$, and grouped as $(1),(3,5),(7,9,11),(13,15,17,19),...$ and so on. Thus, the first group is $\left(1\right)$, the second group is $(3,5)$, the third group is $(7,9...
{"inputs": ["3\n"], "outputs": ["27\n"]}
coding
342
Solve the programming task below in a Python markdown code block. Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled st...
{"inputs": ["1\n4"], "outputs": ["5"]}
coding
272
Solve the programming task below in a Python markdown code block. You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that...
{"inputs": ["0 9\n4 5\n0 4", "2 2\n5 8\n2 7", "0 9\n4 5\n0 6", "2 20\n5 9\n1 8", "2 20\n4 5\n0 4", "0 20\n4 5\n1 2", "1 34\n3 9\n1 8", "1 5\n27 4\n0 1"], "outputs": ["0\n", "0\n", "0\n", "6\n", "4\n", "0\n", "3\n", "27\n"]}
coding
271
Please solve the programming task below using a self-contained code snippet in a markdown code block. The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. For example, The integer 5 is "101" in binary and its complement is "010" whic...
{"functional": "def check(candidate):\n assert candidate(5) == 2\n assert candidate(7) == 0\n assert candidate(10) == 5\n\n\ncheck(Solution().bitwiseComplement)"}
coding
125
Solve the programming task below in a Python markdown code block. A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: - In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at m...
{"inputs": ["8", "2", "9", "3", "5", "6", "4", "7"], "outputs": ["8\n", "2\n", "9\n", "3\n", "5\n", "6\n", "4\n", "7\n"]}
coding
259
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 consisting of n non-negative integers. You are also given an array queries, where queries[i] = [xi, yi]. The answer to the ith query is the sum of all nums[j] where xi <= j...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]]) == [9,18,10]\n assert candidate(nums = [100,200,101,201,102,202,103,203], queries = [[0,7]]) == [303]\n\n\ncheck(Solution().solve)"}
coding
151
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. In one operation, you can replace any element in nums with any integer. nums is considered continuous if both of the following conditions are fulfilled: All elements in nums are u...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,5,3]) == 0\n assert candidate(nums = [1,2,3,5,6]) == 1\n assert candidate(nums = [1,10,100,1000]) == 3\n\n\ncheck(Solution().minOperations)"}
coding
163
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting of lowercase Latin letters "a", "b" and "c" and question marks "?". Let the number of question marks in the string $s$ be $k$. Let's replace each question mark with one of the letters "a", "b" and "c". Here we can o...
{"inputs": ["3\n???\n", "3\nabc\n", "3\nabc\n", "3\n???\n", "3\ncba\n", "3\nbac\n", "3\naac\n", "3\nabb\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
coding
703
Solve the programming task below in a Python markdown code block. # Task Given a string `str`, reverse it omitting all non-alphabetic characters. # Example For `str = "krishan"`, the output should be `"nahsirk"`. For `str = "ultr53o?n"`, the output should be `"nortlu"`. # Input/Output - `[input]` string `st...
{"functional": "_inputs = [['krishan'], ['ultr53o?n'], ['ab23c'], ['krish21an']]\n_outputs = [['nahsirk'], ['nortlu'], ['cba'], ['nahsirk']]\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...
coding
139
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n. Continuously replace n with the sum of its prime factors. Note that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n. Ret...
{"functional": "def check(candidate):\n assert candidate(n = 15) == 5\n assert candidate(n = 3) == 3\n\n\ncheck(Solution().smallestValue)"}
coding
102
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi. You can attend an event i at any day d where startTimei <= d <= endTimei. You can only at...
{"functional": "def check(candidate):\n assert candidate(events = [[1,2],[2,3],[3,4]]) == 3\n assert candidate(events= [[1,2],[2,3],[3,4],[1,2]]) == 4\n\n\ncheck(Solution().maxEvents)"}
coding
125
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree has more than one mode, return them in any order. Assume a BST is de...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,None,2,2])) == [2]\n assert candidate(root = tree_node([0])) == [0]\n\n\ncheck(Solution().findMode)"}
coding
214
Solve the programming task below in a Python markdown code block. You are given a string S of length N. Your task is to delete a [subsequence] of maximum length from the string, such that, after concatenating the remaining parts of the string, it becomes a [palindrome] of length greater than 1. If this is possible, p...
{"inputs": ["3\n6\nbabkhj\n3 \nabc \n4 \nqtoo"], "outputs": ["4\n-1\n2 \n"]}
coding
469
Solve the programming task below in a Python markdown code block. # Task Given array of integers, for each position i, search among the previous positions for the last (from the left) position that contains a smaller value. Store this value at position i in the answer. If no such value can be found, store `-1` instead...
{"functional": "_inputs = [[[3, 5, 2, 4, 5]], [[2, 2, 1, 3, 4, 5, 5, 3]], [[3, 2, 1]]]\n_outputs = [[[-1, 3, -1, 2, 4]], [[-1, -1, -1, 1, 3, 4, 4, 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.isclose(a, b, rel_tol=tol, abs_to...
coding
207
Solve the programming task below in a Python markdown code block. Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a spec...
{"inputs": ["1\n1\n1\n1\n", "1\n2\n1\n1\n", "1\n4\n1\n1\n", "1\n3\n1\n0\n", "1\n4\n1\n2\n", "1\n3\n1\n1\n", "1\n1\n3\n3 1 1\n", "1\n1\n7\n1 1 1 1 1 1 0\n"], "outputs": ["1", "1", "1\n", "0\n", "2\n", "1\n", "3", "2\n"]}
coding
544
Solve the programming task below in a Python markdown code block. There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of info...
{"inputs": ["000 0", "100 0", "4 3\n2 1 1\n2 3 3\n3 4 2", "4 3\n1 1 1\n2 3 3\n3 4 2", "4 3\n1 1 1\n2 3 3\n4 4 2", "4 3\n1 1 1\n2 3 3\n4 4 1", "3 3\n1 2 1\n1 3 1\n1 3 5", "3 3\n1 2 1\n1 3 1\n1 3 2"], "outputs": ["Yes\n", "Yes", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
574
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 operation you can replace any element of the array with any two elements that sum to it. For example, consider nums = [5,6,7]. In one operation, we can replace num...
{"functional": "def check(candidate):\n assert candidate(nums = [3,9,3]) == 2\n assert candidate(nums = [1,2,3,4,5]) == 0\n\n\ncheck(Solution().minimumReplacement)"}
coding
142
Solve the programming task below in a Python markdown code block. There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is neces...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "2 1\n9 13\n", "2 2\n9 13\n", "3 3\n3 8 6\n", "2 0\n17 10\n", "2 0\n17 13\n", "2 1\n17 13\n"], "outputs": ["1 1\n1 1\n", "1 1\n1 1\n", "1 2\n1 1\n2 2\n", "1 2\n1 1\n2 2\n", "2 1\n2 3\n", "1 2\n1 1\n2 2\n", "1 2\n1 1\n2 2\n", "1 2\n1 1\n2 2\n"]}
coding
526
Solve the programming task below in a Python markdown code block. Chef has a natural number N. Cheffina challenges chef to check whether the given number is divisible by the sum of its digits or not. If the given number is divisible then print "Yes" else "No". -----Input:----- - First-line will contain $T$, the number...
{"inputs": ["2\n16\n27"], "outputs": ["No\nYes"]}
coding
169
Solve the programming task below in a Python markdown code block. A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start...
{"inputs": ["8\n1 1 2\n344 3 0\n696 5 0\n73 9 5\n998 8 7\n344 2 19\n696 4 19\n999 10 20", "8\n1 1 2\n344 3 0\n696 5 0\n73 9 5\n998 8 7\n344 2 10\n696 4 19\n999 10 20", "8\n1 1 3\n344 3 0\n696 5 0\n73 9 5\n998 8 7\n344 2 10\n696 4 19\n999 10 20", "8\n1 2 3\n344 3 0\n696 5 0\n73 9 5\n998 8 7\n344 2 10\n696 4 19\n999 10 2...
coding
707
Solve the programming task below in a Python markdown code block. Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n. Tanya plans her journey as follows. First of all, she will choose some city c_1...
{"inputs": ["2\n2 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n", "2\n3 1\n", "2\n1 0\n", "2\n2 0\n", "2\n1 -1\n"], "outputs": ["2\n", "3\n", "2\n", "1\n", "3\n", "1\n", "2\n", "1\n"]}
coding
655
Solve the programming task below in a Python markdown code block. Dhruvil has always been a studious person and will be completing his Engineering soon. He is always kneen about solving problems and is preparing hard for his next interview at Hackerrank. He has practiced lots of problems and now he came across this pro...
{"inputs": ["2\n12\n226"], "outputs": ["2\n3"]}
coding
396
Solve the programming task below in a Python markdown code block. A permutation of length N is an array of N integers (P_{1},P_{2}, \dots,P_{N}) where every integer from 1 to N (inclusive) appears in it exactly once. The weight of a subsegment containing the elements (P_{l},P_{l+1}, \dots,P_{r}) is defined as follows: ...
{"inputs": ["4\n3 2\n3 5\n5 6\n4 10\n\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
618
Solve the programming task below in a Python markdown code block. ## Task You are given three non negative integers `a`, `b` and `n`, and making an infinite sequence just like fibonacci sequence, use the following rules: - step 1: use `ab` as the initial sequence. - step 2: calculate the sum of the last two digits of...
{"functional": "_inputs = [[7, 8, 9], [0, 0, 1000000]]\n_outputs = [[5], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
378
Solve the programming task below in a Python markdown code block. In this problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brain...
{"inputs": ["7\n", "3\n", "6\n", "1\n", "2\n", "0\n", "2+3\n", "9-7\n"], "outputs": ["+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n", "+++++++++++++++++++++++++++++++++++++++++++++++++....
coding
382
Solve the programming task below in a Python markdown code block. Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down a...
{"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n1\n", "1 1\n2\n", "1 2\n2\n", "1 2\n4\n", "1 3\n2\n", "1 3\n3\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "1\n", "2\n", "1\n", "1\n"]}
coding
472
Solve the programming task below in a Python markdown code block. Andi and Budi were given an assignment to tidy up their bookshelf of $n$ books. Each book is represented by the book title β€” a string $s_i$ numbered from $1$ to $n$, each with length $m$. Andi really wants to sort the book lexicographically ascending, wh...
{"inputs": ["5 2\nAA\nAB\nBB\nBA\nAZ\n", "5 2\nAA\nAB\nBB\nBA\nZA\n", "5 2\nAA\nAB\nCB\nBA\nAZ\n", "2 2\nAA\nAB\nCB\nBA\nAZ\n", "2 2\nAA\nBC\nCB\nAB\nAZ\n", "1 2\nAA\nAC\nBC\nBA\nZA\n", "5 2\nAA\nAB\nBC\nBA\nAZ\n", "3 2\nAA\nAB\nCB\nAB\nAZ\n"], "outputs": ["5 2 1 3 4\n", "2 1 3 4 5\n", "5 2 1 4 3\n", "2 1\n", "1 2\n", ...
coding
370
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. A competition with $N$ participants (numbered $1$ through $N$) is taking place in Chefland. There are $N-1$ rounds in the competition; in each round...
{"inputs": ["1\n3\n1110001101\n1010101011\n0000000011"], "outputs": ["4"]}
coding
651
Solve the programming task below in a Python markdown code block. You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the ...
{"inputs": ["1\n", "1\n", "2\n", "6\n", "10\n", "25\n", "52\n", "57\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n", "1\n", "1\n"]}
coding
315
Solve the programming task below in a Python markdown code block. Aklank is fond of numbers which are divisible by either P1 or P2. He termed those numbers as Bakku numbers. Recently his best friend gave him a range of numbers. Now he is wondering what is the probability of finding Bakku numbers from that range of numb...
{"inputs": ["7607 9769\n10\n1 1\n1 100000\n10000 100000\n999 1000\n7607 7607\n1 7605\n9770 10000\n15005 100000\n9 12345\n100000 100000"], "outputs": ["0.000000\n0.000230\n0.000233\n0.000000\n1.000000\n0.000000\n0.000000\n0.000247\n0.000162\n0.000000"]}
coding
350
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n processes forming a rooted tree structure. You are given two integer arrays pid and ppid, where pid[i] is the ID of the ith process and ppid[i] is the ID of the ith process's parent process. Each process ha...
{"functional": "def check(candidate):\n assert candidate(pid = [1,3,10,5], ppid = [3,0,5,3], kill = 5) == [5,10]\n assert candidate(pid = [1], ppid = [0], kill = 1) == [1]\n\n\ncheck(Solution().killProcess)"}
coding
202
Solve the programming task below in a Python markdown code block. Write a program that, given a word, computes the scrabble score for that word. ## Letter Values You'll need these: ``` Letter Value A, E, I, O, U, L, N, R, S, T 1 D, G 2 B, C, M, P ...
{"functional": "_inputs = [[''], ['a'], ['street'], ['STREET'], [' a'], ['st re et'], ['f'], ['quirky'], ['MULTIBILLIONAIRE'], ['alacrity']]\n_outputs = [[0], [1], [6], [6], [1], [6], [4], [22], [20], [13]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return...
coding
430
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 is attending math classes. On each day, the teacher gives him homework. Yesterday, the teacher gave Chef a sequence of positive integers and ask...
{"inputs": ["3\n2\n2 8\n3 \n8 2 8\n3\n9 10 11"], "outputs": ["7\n10\n18"]}
coding
600
Solve the programming task below in a Python markdown code block. Given a rooted tree of $N$ nodes, where each node is uniquely numbered in between [1..N]. The node 1 is the root of the tree. Each node has an integer value which is initially 0. You need to perform the following two kinds of queries on the tree: add t...
{"inputs": ["5\n1 2\n2 3\n2 4\n5 1\n6\nadd 4 30\nadd 5 20\nmax 4 5\nadd 2 -20\nmax 4 5\nmax 3 4\n"], "outputs": ["30\n20\n10\n"]}
coding
475
Solve the programming task below in a Python markdown code block. You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is cons...
{"inputs": ["1\n0 0\n", "1\n1 0\n", "1\n2 0\n", "1\n1 1\n", "1\n1 2\n", "1\n-1 0\n", "1\n1 -1\n", "2\n0 2\n2 9\n"], "outputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n0\n", "1\n1\n", "1\n2\n"]}
coding
267
Solve the programming task below in a Python markdown code block. A 3Γ—3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top righ...
{"inputs": ["8\n0\n5", "1\n0\n1", "1\n0\n2", "1\n0\n4", "1\n1\n2", "1\n0\n3", "8\n0\n6", "1\n1\n4"], "outputs": ["8 0 7\n4 5 6\n3 10 2\n", "1 0 2\n2 1 0\n0 2 1\n", "1 0 5\n6 2 -2\n-1 4 3\n", "1 0 11\n14 4 -6\n-3 8 7\n", "1 1 4\n5 2 -1\n0 3 3\n", "1 0 8\n10 3 -4\n-2 6 5\n", "8 0 10\n8 6 4\n2 12 4\n", "1 1 10\n13 4 -5\n-...
coding
360
Solve the programming task below in a Python markdown code block. Beaches are filled with sand, water, fish, and sun. Given a string, calculate how many times the words `"Sand"`, `"Water"`, `"Fish"`, and `"Sun"` appear without overlapping (regardless of the case). ## Examples ```python sum_of_a_beach("WAtErSlIde") ...
{"functional": "_inputs = [['SanD'], ['sunshine'], ['sunsunsunsun'], ['123FISH321'], ['weoqipurpoqwuirpousandiupqwoieurioweuwateruierqpoiweurpouifiShqowieuqpwoeuisUn'], ['sAnDsandwaTerwatErfishFishsunsunsandwater'], ['joifjepiojfoiejfoajoijawoeifjowejfjoiwaefjiaowefjaofjwoj fawojef '], ['jwefjwjfsandsandwaterwaterfishf...
coding
188
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"]}
coding
500
Solve the programming task below in a Python markdown code block. Consider the following game: There are two players, First and Second, sitting in front of a pile of $n$ stones. First always plays first. There is a set, $\mbox{S}$, of $m$ distinct integers defined as $S=\{s_0,s_1,\ldots,s_{m-1}\}$. The players move in...
{"inputs": ["15 3\n5 2 3\n"], "outputs": ["Second\n"]}
coding
471
Solve the programming task below in a Python markdown code block. We have an undirected graph G with N vertices numbered 1 to N and N edges as follows: - For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1. - There is an edge between Vertex X and Vertex Y. For each k=1,2,...,N-1, solve the proble...
{"inputs": ["4 1 3", "7 3 4", "9 2 4", "3 2 3", "5 1 4", "4 1 2", "8 4 5", "6 1 3"], "outputs": ["4\n2\n0\n", "6\n5\n4\n3\n2\n1\n", "9\n8\n6\n5\n4\n3\n1\n0\n", "2\n1\n", "5\n4\n1\n0\n", "3\n2\n1\n", "7\n6\n5\n4\n3\n2\n1\n", "6\n4\n3\n2\n0\n"]}
coding
463
Solve the programming task below in a Python markdown code block. Coach Moony wants the best team to represent their college in ICPC. He has $N$ students standing in a circle with certain rating $X_i$ on a competitive coding platform. It is an established fact that any coder with more rating on the platform is a better...
{"inputs": ["1\n7\n10 40 30 30 20 0 0"], "outputs": ["100"]}
coding
336
Solve the programming task below in a Python markdown code block. Vasya has recently got a job as a cashier at a local store. His day at work is $L$ minutes long. Vasya has already memorized $n$ regular customers, the $i$-th of which comes after $t_{i}$ minutes after the beginning of the day, and his service consumes $...
{"inputs": ["0 5 2\n", "0 1 1\n", "0 1 1\n", "0 2 1\n", "0 0 2\n", "0 0 1\n", "0 0 4\n", "0 6 2\n"], "outputs": ["2", "1", "1\n", "2\n", "0\n", "0\n", "0\n", "3\n"]}
coding
476
Solve the programming task below in a Python markdown code block. You are given an integer N. Is there a permutation of digits of integer that's divisible by 8? A permutation of digits of integer N is defined as an integer formed by rearranging the digits of N. For example, if the number N = 123, then {123, 132, 213, 2...
{"inputs": ["2\n61\n75\n"], "outputs": ["YES\nNO\n"]}
coding
297
Solve the programming task below in a Python markdown code block. LiLand is a country, consisting of n cities. The cities are numbered from 1 to n. The country is well known because it has a very strange transportation system. There are many one-way flights that make it possible to travel between the cities, but the fl...
{"inputs": ["3 3\n1 2\n2 3\n1 3\n", "4 3\n1 2\n2 3\n3 4\n1 4\n", "4 4\n1 2\n2 3\n3 4\n1 3\n", "4 2\n1 2\n2 4\n3 4\n1 4\n", "4 3\n1 2\n2 3\n3 4\n1 3\n", "4 3\n1 2\n2 3\n3 4\n2 3\n", "4 3\n1 2\n2 3\n3 4\n1 5\n", "4 3\n1 2\n2 3\n3 4\n0 3\n"], "outputs": ["Yes\n1\n1\n2\n", "Yes\n2\n2\n2\n", "Yes\n1\n1\n2\n2\n", "Yes\n2\n2\...
coding
514
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...
coding
442
Solve the programming task below in a Python markdown code block. Vasiliy has an exam period which will continue for n days. He has to pass exams on m subjects. Subjects are numbered from 1 to m. About every day we know exam for which one of m subjects can be passed on that day. Perhaps, some day you can't pass any ex...
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "1 1\n0\n1\n", "1 1\n0\n2\n", "1 1\n0\n3\n", "1 1\n1\n2\n", "1 1\n1\n4\n", "1 1\n1\n3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
693
Solve the programming task below in a Python markdown code block. Alice and Bob are playing One Card Poker. One Card Poker is a two-player game using playing cards. Each card in this game shows an integer between 1 and 13, inclusive. The strength of a card is determined by the number written on it, as follows: We...
{"inputs": ["8 7", "2 1", "0 0", "8 3", "3 1", "7 3", "4 1", "7 1"], "outputs": ["Alice\n", "Bob\n", "Draw\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Bob\n"]}
coding
344
Solve the programming task below in a Python markdown code block. You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return `true` if it is valid, or `false` if it is not. For example: `"abcabc"` is a valid word because `...
{"functional": "_inputs = [['abcabc'], ['Abcabc'], ['AbcabcC'], ['AbcCBa'], ['pippi'], ['?!?!?!'], ['abc123'], ['abcabcd'], ['abc!abc!'], ['abc:abc']]\n_outputs = [[True], [True], [False], [True], [False], [True], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)...
coding
278
Solve the programming task below in a Python markdown code block. Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. **The return value of the function must be an array, and the numbers must be Fixnums, NOT stri...
{"functional": "_inputs = [[2, 2], [3, 3], [3, 4], [4, 4], [2, 5]]\n_outputs = [[[[1, 2], [2, 4]]], [[[1, 2, 3], [2, 4, 6], [3, 6, 9]]], [[[1, 2, 3, 4], [2, 4, 6, 8], [3, 6, 9, 12]]], [[[1, 2, 3, 4], [2, 4, 6, 8], [3, 6, 9, 12], [4, 8, 12, 16]]], [[[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]]]]\nimport math\ndef _deep_eq(a, b, t...
coding
168
Solve the programming task below in a Python markdown code block. problem AOR Ika made a set $ S = \\ {a_1, ..., a_N \\} $ and a map $ f: S β†’ S $. $ f (a_i) = b_i $. For any element $ x $ in the set $ S $, all maps $ g, h: S β†’ S $ satisfying $ g (f (x)) = h (f (x)) $ are $ g (x). ) = Determine if h (x) $ is satisfied,...
{"inputs": ["5\n2 1 3 4 5\n3 4 2 5 1", "5\n1 2 3 4 5\n2 4 3 5 1", "5\n1 3 2 4 5\n3 4 2 5 1", "5\n2 1 3 4 5\n2 4 3 5 1", "5\n1 4 3 2 5\n3 4 2 5 1", "5\n2 1 3 4 5\n3 4 2 5 1", "5\n1 2 3 4 5\n2 4 3 5 1", "5\n2 1 3 4 5\n3 4 1 5 2"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
coding
153
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. Note that after backspacing an empty text, the text will continue empty. Β  Please ...
{"functional": "def check(candidate):\n assert candidate(s = \"ab#c\", t = \"ad#c\") == True\n assert candidate(s = \"ab##\", t = \"c#d#\") == True\n assert candidate(s = \"a#c\", t = \"b\") == False\n\n\ncheck(Solution().backspaceCompare)"}
coding
96
Solve the programming task below in a Python markdown code block. Master Shifu is training Po to become The Dragon Warrior and as a final assignment he must obtain maximum deliciousness from dumplings. There are $N$ plates of dumplings in front of him with deliciousness $A_1, A_2, \ldots, A_N$, Po can choose any numbe...
{"inputs": ["2\n4\n1 2 3 4\n5\n3 2 0 3 0"], "outputs": ["4\n4"]}
coding
313
Solve the programming task below in a Python markdown code block. Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example le...
{"inputs": ["2\nCODECHEF\nDRINKEATCODE", "2\nFEHCEDOC\nDRINKEATCODE", "2\nFEHCEEOC\nDRINKEATCODE", "2\nCOEECHFE\nDRJNKEATBODE", "2\nEFJEFCOB\nDRJNKEAUBODE", "2\nEJDEFCOB\nDQJNKEATBODE", "2\nEJDEFCOB\nCQJNKEATBODE", "2\nEODDFCJB\nEDOBTADKNJQC"], "outputs": ["2\n5", "2\n5\n", "1\n5\n", "1\n7\n", "3\n7\n", "4\n7\n", "4\n6...
coding
292
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. You are given an array A of N elements. You can do the following operations on that array: Remove the leftmost element of the array, with index l, for the cost A_{l}. Thi...
{"inputs": ["3\n5 2 7\n9 10 11 12 13\n5 0 7\n9 9 9 9 9\n5 2 7\n9 1 2 3 10\n"], "outputs": ["23\n45\n13\n"]}
coding
664
Solve the programming task below in a Python markdown code block. You have a collection of lovely poems. Unfortuantely they aren't formatted very well. They're all on one line, like this: ``` Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complica...
{"functional": "_inputs = [['Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated.'], [\"Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules.\"], ['Although pract...
coding
270