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. You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the...
{"inputs": ["sunday\nsunday\n", "monday\nmonday\n", "monday\nfriday\n", "monday\nsunday\n", "friday\nmonday\n", "friday\nsunday\n", "sunday\nmonday\n", "sunday\nfriday\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]}
coding
427
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings. If there are multiple such strings, return the lexicographically smallest one. R...
{"functional": "def check(candidate):\n assert candidate(a = \"abc\", b = \"bca\", c = \"aaa\") == \"aaabca\"\n assert candidate(a = \"ab\", b = \"ba\", c = \"aba\") == \"aba\"\n\n\ncheck(Solution().minimumString)"}
coding
173
Solve the programming task below in a Python markdown code block. The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In o...
{"inputs": ["4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(16+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(97+98)/99\n(26+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(27+4)/10\n(12+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(27+4)/10\n(13+33)/15\n(5+1)/7\n", "4\n(99+98)/97\n(20+4)/17\n(13+33)/15\n(5+1)/7\n", "4...
coding
420
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given n​​​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTi...
{"functional": "def check(candidate):\n assert candidate(tasks = [[1,2],[2,4],[3,2],[4,1]]) == [0,2,3,1]\n assert candidate(tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]) == [4,3,2,0,1]\n\n\ncheck(Solution().getOrder)"}
coding
248
Solve the programming task below in a Python markdown code block. You need count how many valleys you will pass. Start is always from zero level. Every time you go down below 0 level counts as an entry of a valley, and as you go up to 0 level from valley counts as an exit of a valley. One passed valley is equal one ...
{"functional": "_inputs = [['UFFFD'], ['DFFFD'], ['UFFFU'], ['DFFFU'], ['UFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDUFFDDUFFDDUDUDUDUDUDUUUUUUUUU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU']]\n_o...
coding
190
Solve the programming task below in a Python markdown code block. This is a peculiar functioning setup. Two Tanks are separated from each other by a wall .There is a pipe in the wall which connects both tanks which allows flow of water between them . Due to this ,there is change in temperature of both tanks , every m...
{"inputs": ["2\n4 5 10\n2 2 5"], "outputs": ["Yes\nNo"]}
coding
346
Solve the programming task below in a Python markdown code block. Given is an undirected connected graph with N vertices numbered 1 to N, and M edges numbered 1 to M. The given graph may contain multi-edges but not self loops. Each edge has an integer label between 1 and N (inclusive). Edge i has a label c_i, and it co...
{"inputs": ["3 4\n1 2 1\n2 3 2\n3 1 3\n1 3 1\n"], "outputs": ["1\n2\n1\n"]}
coding
621
Solve the programming task below in a Python markdown code block. You are given an array a consisting of n integers. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, ..., a_r] (1 ≤ l ≤ r ≤ n). A subarray is considered good if every integer that occurs in this subarray occurs there exactly thrice. For examp...
{"inputs": ["9\n2 2 2 2 1 1 2 2 2\n", "9\n4 2 2 2 1 1 2 2 2\n", "9\n4 2 2 1 1 1 2 2 2\n", "9\n1 2 2 2 1 1 2 2 2\n", "10\n1 2 3 4 1 2 5 1 2 3\n", "10\n1 2 3 4 1 2 7 1 2 3\n", "10\n1 2 5 4 1 2 7 1 2 3\n", "10\n2 2 5 4 1 2 7 1 2 3\n"], "outputs": ["3\n", "2\n", "5\n", "3", "0\n", "0\n", "0\n", "0\n"]}
coding
355
Solve the programming task below in a Python markdown code block. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record a...
{"inputs": ["L\n", "R\n", "RR\n", "DL\n", "LD\n", "UL\n", "DDR\n", "ULD\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "BUG\n"]}
coding
463
Solve the programming task below in a Python markdown code block. Your website is divided vertically in sections, and each can be of different size (height). You need to establish the section index (starting at `0`) you are at, given the `scrollY` and `sizes` of all sections. Sections start with `0`, so if first se...
{"functional": "_inputs = [[1, [300, 200, 400, 600, 100]], [299, [300, 200, 400, 600, 100]], [300, [300, 200, 400, 600, 100]], [1599, [300, 200, 400, 600, 100]], [1600, [300, 200, 400, 600, 100]]]\n_outputs = [[0], [0], [1], [4], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstan...
coding
282
Solve the programming task below in a Python markdown code block. There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not...
{"inputs": ["1\n1\n", "4\n1 2 3 6", "4\n1 2 6 6", "4\n1 4 3 6", "4\n0 4 3 6", "4\n0 4 3 7", "4\n0 4 4 7", "4\n0 4 0 7"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
213
Solve the programming task below in a Python markdown code block. Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day ...
{"inputs": ["0\n0\n", "0\n1\n", "10\n01\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n", "011101\n000001\n", "011101\n000000\n"], "outputs": ["0\n", "1\n", "11\n", "111\n", "0100\n", "00010\n", "011100\n", "011101\n"]}
coding
471
Solve the programming task below in a Python markdown code block. Given are a permutation p_1, p_2, \dots, p_N of (1, 2, ..., N) and an integer K. Maroon performs the following operation for i = 1, 2, \dots, N - K + 1 in this order: * Shuffle p_i, p_{i + 1}, \dots, p_{i + K - 1} uniformly randomly. Find the expecte...
{"inputs": ["3 3\n1 2 3", "3 2\n2 1 3", "3 2\n2 3 1", "3 3\n1 2 2", "3 3\n1 2 1", "3 3\n1 3 3", "3 3\n2 3 3", "3 3\n2 3 1"], "outputs": ["499122178\n", "1\n", "2\n", "499122178\n", "499122178\n", "499122178\n", "499122178\n", "499122178\n"]}
coding
446
Please solve the programming task below using a self-contained code snippet in a markdown code block. Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and each node has a distinct value from 1 to n. Initially, the first pla...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6,7,8,9,10,11]), n = 11, x = 3) == True\n assert candidate(root = tree_node([1,2,3]), n = 3, x = 1) == False\n\n\ncheck(Solution().btreeGameWinningMove)"}
coding
364
Solve the programming task below in a Python markdown code block. Nina received an odd New Year's present from a student: a set of $n$ unbreakable sticks. Each stick has a length, $\boldsymbol{l}$, and the length of the $i^{\mbox{th}}$ stick is $\boldsymbol{l_{i-1}}$. Deciding to turn the gift into a lesson, Nina asks ...
{"inputs": ["6\n1 2 3 4 5 6 \n", "8\n4 5 1 5 1 9 4 5 \n"], "outputs": ["0 \n", "3\n"]}
coding
729
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: - Append a_i to the end of b. - Reverse the order of the elements in b. Find t...
{"inputs": ["3\n1 2 3\n", "4\n1 2 3 4\n", "1\n1000000000\n", "6\n0 6 7 6 7 0\n"], "outputs": ["3 1 2\n", "4 2 1 3\n", "1000000000\n", "0 6 6 0 7 7\n"]}
coding
384
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 goal. You want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is...
{"functional": "def check(candidate):\n assert candidate(nums = [5,-7,3,5], goal = 6) == 0\n assert candidate(nums = [7,-9,15,-2], goal = -5) == 1\n assert candidate(nums = [1,2,3], goal = -7) == 7\n\n\ncheck(Solution().minAbsDifference)"}
coding
154
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.   Please complete the following python code precisely: ```...
{"functional": "def check(candidate):\n assert candidate(heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]) == 4\n assert candidate(heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]) == 10\n\n\ncheck(Solution().trapRainWater)"}
coding
86
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can...
{"functional": "def check(candidate):\n assert candidate(basket1 = [4,2,2,2], basket2 = [1,4,1,2]) == 1\n assert candidate(basket1 = [2,3,4,1], basket2 = [3,2,5,1]) == -1\n\n\ncheck(Solution().minCost)"}
coding
194
Solve the programming task below in a Python markdown code block. ### Task The __dot product__ is usually encountered in linear algebra or scientific computing. It's also called __scalar product__ or __inner product__ sometimes: > In mathematics, the __dot product__, or __scalar product__ (or sometimes __inner product...
{"functional": "_inputs = [[[], []], [[1, 2, 3, 4, 5], [0, 1, 1, 1, 0]], [[1, 2, 3, 4, 5], [0, 0, 1, 1, -4]], [[1, 3, 5], [4, -2, 1]]]\n_outputs = [[0], [6], [-17], [-3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs...
coding
481
Solve the programming task below in a Python markdown code block. Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset...
{"inputs": ["1 5 9\n", "2 3 3\n", "2 3 5\n", "1 0 1\n", "5 6 0\n", "2 1 0\n", "2 3 1\n", "5 4 6\n"], "outputs": ["14\n", "2\n", "3\n", "1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
282
Solve the programming task below in a Python markdown code block. This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "...
{"inputs": ["((()))\n", "()()()\n", "))))))\n", "((((((\n", "(())()\n", ")))(((\n", ")())))\n", ")())((\n"], "outputs": ["0\n((()))", "0\n()()()", "-1", "-1", "0\n(())()", "-1\n", "-1\n", "-1\n"]}
coding
311
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer array skill of even length n where skill[i] denotes the skill of the ith player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal. The chem...
{"functional": "def check(candidate):\n assert candidate(skill = [3,2,5,1,3,4]) == 22\n assert candidate(skill = [3,4]) == 12\n assert candidate(skill = [1,1,2,3]) == -1\n\n\ncheck(Solution().dividePlayers)"}
coding
153
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. "It's totally fun to play troublemakers ― totally." - Lee Pace Sakshi had a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbere...
{"inputs": ["1\n2 2 3\n1 1\n1 2\n2 1"], "outputs": ["2"]}
coding
749
Solve the programming task below in a Python markdown code block. Gildong is now developing a puzzle game. The puzzle consists of n platforms numbered from 1 to n. The player plays the game as a character that can stand on each platform and the goal of the game is to move the character from the 1-st platform to the n-t...
{"inputs": ["3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 1 4 3 1 0 2 1 0\n", "3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 1 4 2 1 0 2 0 0\n", "3\n4\n1 1 1 0\n5\n2 3 2 1 0\n9\n3 1 4 1 1 0 2 1 0\n", "3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 2 4 3 1 0 2 1 0\n", "3\n4\n2 1 1 0\n5\n2 3 2 1 0\n9\n3 1 4 1 0 0 2 1 0\n", "3\n4\n1 1 1 0\n5\n4 2 2 1 0\n9\n...
coding
647
Solve the programming task below in a Python markdown code block. Consider a zero-indexed matrix with $m$ rows and $n$ columns, where each row is filled gradually. Given the first row of the matrix, you can generate the elements in the subsequent rows using the following formula: $a_{i,j}=a_{i-1,j}\oplus a_{i-1,j+1}\t...
{"inputs": ["4 2\n6 7 1 3\n"], "outputs": ["1 6 2 5\n"]}
coding
514
Solve the programming task below in a Python markdown code block. A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction. This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order ...
{"inputs": ["UF\n1 0", "FT\n1 0", "FF\n2 0", "UF\n0 0", "TF\n1 0", "FF\n1 0", "FF\n1 0\n", "TF\n1 0\n"], "outputs": ["No\n", "Yes\n", "Yes\n", "No\n", "No", "No", "No\n", "No\n"]}
coding
265
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Please complete the follo...
{"functional": "def check(candidate):\n assert candidate(\"AAB\") == 8\n assert candidate(\"AAABBC\") == 188\n assert candidate(\"V\") == 1\n\n\ncheck(Solution().numTilePossibilities)"}
coding
90
Solve the programming task below in a Python markdown code block. Chef categorises an instagram account as *spam*, if, the *following* count of the account is more than 10 times the count of *followers*. Given the *following* and *follower* count of an account as X and Y respectively, find whether it is a *spam* acco...
{"inputs": ["4\n1 10\n10 1\n11 1\n97 7\n"], "outputs": ["NO\nNO\nYES\nYES\n"]}
coding
437
Solve the programming task below in a Python markdown code block. Chefland has all the cities on a straight line. There are $N$ cities in Chefland numbered $1$ to $N$. City $i$ is located at coordinate $x_i$ on the x-axis. Guru wants to travel from city $A$ to city $B$. He starts at time t=0. He has following choices t...
{"inputs": ["1\n4 1 3 2 4 3 2 4\n1 2 3 4"], "outputs": ["6"]}
coding
503
Solve the programming task below in a Python markdown code block. The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 > 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not. A sequence of integ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
562
Solve the programming task below in a Python markdown code block. Given integers ${b}$ and $a$, find the smallest integer ${h}$, such that there exists a triangle of height ${h}$, base ${b}$, having an area of at least $a$. Example $b=4$ ${a=6}$ The minimum height ${h}$ is $3$. One example is a triangle formed...
{"inputs": ["2 2\n", "17 100\n"], "outputs": ["2\n", "12\n"]}
coding
485
Solve the programming task below in a Python markdown code block. Some scientists are working on protein recombination, and during their research, they have found a remarkable fact: there are 4 proteins in the protein ring that mutate after every second according to a fixed pattern. For simplicity, proteins are called ...
{"inputs": ["5 15\nAAAAD\n"], "outputs": ["DDDDA\n"]}
coding
583
Solve the programming task below in a Python markdown code block. Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer. -----Constraints----- - 1 \leq N \leq 10^9 - N is an integer. -----Input----- Input is given from Standard Input ...
{"inputs": ["7", "2", "0", "70", "12", "16", "26", "38"], "outputs": ["4\n", "1\n", "0\n", "64\n", "9\n", "16\n", "25\n", "36\n"]}
coding
131
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Kerim is an environment-friendly guy. Today, he accepted Samir's challenge of planting 20 million trees by 2020. Currently, there are $N$ trees (numbered $1$ ...
{"inputs": ["1\n3\n2 7 4"], "outputs": ["2"]}
coding
585
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s consisting of n characters which are either 'X' or 'O'. A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the chara...
{"functional": "def check(candidate):\n assert candidate(s = \"XXX\") == 1\n assert candidate(s = \"XXOX\") == 2\n assert candidate(s = \"OOOO\") == 0\n\n\ncheck(Solution().minimumMoves)"}
coding
124
Solve the programming task below in a Python markdown code block. Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out by these bridges, which allows you to travel to and from all cities. R...
{"inputs": ["5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 1\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 3\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 0\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 6\n0 3 1\n3 4 8\n1 3 4\n3 3\n1 2 3\n2 0 3\n0...
coding
446
Solve the programming task below in a Python markdown code block. We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c)...
{"inputs": ["2 3 3\n2 2\nRLR\nLUD", "2 6 3\n2 2\nRLR\nLUD", "2 3 3\n2 0\nRRL\nLUD", "2 5 3\n2 2\nRLR\nLUD", "2 6 3\n1 2\nRLR\nLUD", "2 3 3\n2 1\nRRL\nLUD", "2 5 3\n2 4\nRLR\nLUD", "2 6 3\n1 0\nRLR\nLUD"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n"]}
coding
595
Solve the programming task below in a Python markdown code block. Description overhauled by V --- I've invited some kids for my son's birthday, during which I will give to each kid some amount of candies. Every kid hates receiving less amount of candies than any other kids, and I don't want to have any candies left ...
{"functional": "_inputs = [[1], [2], [5], [6], [9], [10], [60], [61], [100], [101]]\n_outputs = [[1], [2], [60], [60], [2520], [2520], [9690712164777231700912800], [591133442051411133755680800], [69720375229712477164533808935312303556800], [7041757898200960193617914702466542659236800]]\nimport math\ndef _deep_eq(a, b, ...
coding
178
Solve the programming task below in a Python markdown code block. How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. T...
{"inputs": ["4 1 1 3 4\n", "4 2 1 3 4\n", "4 1 2 3 4\n", "3 452 979 51\n", "3 287 979 395\n", "3 887 104 641\n", "3 452 979 395\n", "4 802 765 992 1\n"], "outputs": ["28\n", "29\n", "30", "2563\n", "3430", "3018", "3595\n", "5312"]}
coding
293
Solve the programming task below in a Python markdown code block. Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards shoul...
{"inputs": ["2 2\n1\n5\n3\n7\n6 5\n2\n9\n7\n2\n3\n3\n24\n2\n7\n3\n5\n4 5\n4\n0\n2\n8\n1\n9\n6\n0\n6\n7 4\n1\n1\n2\n1\n2\n1\n4\n2\n2\n4\n6\n2 3\n1\n1\n2\n2\n2\n0 0", "2 2\n1\n6\n3\n24\n6 5\n3\n9\n0\n2\n6\n3\n3\n3\n3\n3\n5\n4 5\n9\n0\n0\n8\n1\n9\n6\n0\n6\n7 4\n0\n0\n2\n0\n0\n1\n2\n2\n3\n4\n6\n2 3\n2\n1\n2\n2\n2\n0 0", "2...
coding
690
Solve the programming task below in a Python markdown code block. Given two arrays, the purpose of this Kata is to check if these two arrays are the same. "The same" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,...
{"functional": "_inputs = [[[[2, 5], [3, 6]], [[5, 2], [3, 6]]], [[[2, 5], [3, 6]], [[6, 3], [5, 2]]], [[[2, 5], [3, 6]], [[6, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[2, 6], [5, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[3, 5], [6, 2], [5, 2]]], [[], []], [[[2, 3], [3, 4]], [[4, 3], [2, 4]]], [[[2, 3], [3, 2]], [[2,...
coding
334
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNu...
{"functional": "def check(candidate):\n assert candidate(orders = [[\"David\",\"3\",\"Ceviche\"],[\"Corina\",\"10\",\"Beef Burrito\"],[\"David\",\"3\",\"Fried Chicken\"],[\"Carla\",\"5\",\"Water\"],[\"Carla\",\"5\",\"Ceviche\"],[\"Rous\",\"3\",\"Ceviche\"]]) == [[\"Table\",\"Beef Burrito\",\"Ceviche\",\"Fried Chicke...
coding
218
Solve the programming task below in a Python markdown code block. Divya's watch of worth Rs10 cr is abducted by N thieves(1,2....i...N). The fight over the watch leads to a final decision that it should belong to the thief who wins a simple game. The rules of the game state that every thief registers a time in the for...
{"inputs": ["2\n3\n12:28:26\n07:26:04\n11:23:17\n2\n07:43:25\n06:23:34"], "outputs": ["3\n1"]}
coding
329
Solve the programming task below in a Python markdown code block. After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n. This sequence had the following property: if you write out the sums of all its...
{"inputs": ["1 1\n0\n", "1 1\n?\n", "1 1\n-1\n", "3 1\n4 ? 5\n", "3 2\n4 ? 5\n", "3 2\n? 1 2\n", "3 1\n-5 ? 0\n", "3 1\n-1 ? 1\n"], "outputs": ["0\n", "0\n", "-1 ", "Incorrect sequence\n", "4 0 5 ", "0 1 2\n", "-5 -1 0\n", "-1 0 1\n"]}
coding
580
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the charact...
{"inputs": ["1\n2\n00\n10"], "outputs": ["2"]}
coding
578
Solve the programming task below in a Python markdown code block. Each army fighting the world war Z is denoted with a word consisting any combination of 26 alphabets. An army is a match for his/her opponent if and only if his name is an anagram of his/her opponent. Your job as a programmer is to help find whether two ...
{"inputs": ["3\nman app\na b\nabcde edcba"], "outputs": ["No\nNo\nYes"]}
coding
236
Solve the programming task below in a Python markdown code block. Given few numbers, you need to print out the digits that are not being used. Example: ```python unused_digits(12, 34, 56, 78) # "09" unused_digits(2015, 8, 26) # "3479" ``` Note: - Result string should be sorted - The test case won't pass Integer wit...
{"functional": "_inputs = [[12, 34, 56, 78], [2015, 8, 26], [276, 575], [643], [864, 896, 744], [364, 500, 715, 730], [93, 10, 11, 40], [1, 11, 111, 1111, 11111], [9, 87, 654, 3210]]\n_outputs = [['09'], ['3479'], ['013489'], ['0125789'], ['01235'], ['289'], ['25678'], ['023456789'], ['']]\nimport math\ndef _deep_eq(a,...
coding
125
Solve the programming task below in a Python markdown code block. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elepha...
{"inputs": ["1\n1 2\n", "1\n1 1\n", "1\n1 4\n", "1\n2 1\n", "2\n1 1\n1 1\n", "2\n1 2\n2 3\n", "2\n1 2\n2 1\n", "2\n1 1\n0 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
421
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well. A semester in Chef's University has $120$ working days. The University's requirement is that a student should be present for at least $75\%$ of the working da...
{"inputs": ["3\n50\n00000000000000000000000000000000000000000000000000\n50\n01010101010101010101010101010101010101010101010101\n2\n01"], "outputs": ["NO\nYES\nYES"]}
coding
620
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array groups of length n. You are also given an integer array nums. You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i] ...
{"functional": "def check(candidate):\n assert candidate(groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]) == True\n assert candidate(groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]) == False\n assert candidate(groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]) == False\n\n\ncheck(Solution()...
coding
204
Solve the programming task below in a Python markdown code block. Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10). Constraints * 2 ≤ N ≤ 10^5 * N is an integer. Input Inpu...
{"inputs": ["3", "5", "7", "4", "9", "8", "2", "6"], "outputs": ["3\n", "5\n", "7\n", "4\n", "9\n", "8\n", "2\n", "6\n"]}
coding
152
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string queryIP, return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a correct IP of any type. A valid IPv4 address is an IP in the form "x1.x2.x3.x4" whe...
{"functional": "def check(candidate):\n assert candidate(queryIP = \"172.16.254.1\") == \"IPv4\"\n assert candidate(queryIP = \"2001:0db8:85a3:0:0:8A2E:0370:7334\") == \"IPv6\"\n assert candidate(queryIP = \"256.256.256.256\") == \"Neither\"\n\n\ncheck(Solution().validIPAddress)"}
coding
457
Solve the programming task below in a Python markdown code block. Problem One day, mo3tthi and tubuann decided to play a game with magic pockets and biscuits. Now there are $ K $ pockets, numbered $ 1,2, \ ldots, K $. The capacity of the $ i $ th pocket is $ M_i $, which initially contains $ N_i $ biscuits. mo3tthi an...
{"inputs": ["1\n2 5", "1\n2 6", "1\n2 7", "1\n1 6", "1\n4 5", "1\n4 6", "1\n3 5", "1\n2 3"], "outputs": ["mo3tthi\n", "mo3tthi\n", "mo3tthi\n", "tubuann\n", "mo3tthi\n", "tubuann\n", "tubuann\n", "mo3tthi\n"]}
coding
528
Solve the programming task below in a Python markdown code block. n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k ...
{"inputs": ["2 2\n1 2\n", "2 2\n1 2\n", "3 2\n1 3 2\n", "3 3\n1 2 3\n", "3 3\n1 2 3\n", "3 2\n1 3 2\n", "3 2\n2 3 2\n", "3 2\n2 3 0\n"], "outputs": ["2 ", "2", "3 ", "3 ", "3", "3", "3\n", "3\n"]}
coding
374
Solve the programming task below in a Python markdown code block. A faro shuffle of a deck of playing cards is a shuffle in which the deck is split exactly in half and then the cards in the two halves are perfectly interwoven, such that the original bottom card is still on the bottom and the original top card is still ...
{"functional": "_inputs = [[2], [52], [542], [1250], [1954]]\n_outputs = [[1], [8], [540], [156], [30]]\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) ...
coding
233
Solve the programming task below in a Python markdown code block. Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He w...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n2 3 1\n", "3\n1 2 3\n", "3\n1 3 2\n", "3\n2 1 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]}
coding
375
Solve the programming task below in a Python markdown code block. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 ...
{"inputs": ["1 1\n4\n", "1 1\n4\n", "1 1\n7\n", "1 1\n6\n", "1 1\n44\n", "1 1\n44\n", "1 1\n14\n", "3 4\n1 2 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "3\n"]}
coding
308
Solve the programming task below in a Python markdown code block. Adding tip to a restaurant bill in a graceful way can be tricky, thats why you need make a function for it. The function will receive the restaurant bill (always a positive number) as an argument. You need to 1) **add at least 15%** in tip, 2) round tha...
{"functional": "_inputs = [[1], [7], [12], [86], [99], [1149], [983212]]\n_outputs = [[2], [9], [15], [100], [150], [1500], [1500000]]\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, (lis...
coding
277
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1. Note that an integer is sai...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3], nums2 = [2,4]) == 2\n assert candidate(nums1 = [1,2,3,6], nums2 = [2,3,4,5]) == 2\n\n\ncheck(Solution().getCommon)"}
coding
125
Solve the programming task below in a Python markdown code block. In this Kata we focus on finding a sum S(n) which is the total number of divisors taken for all natural numbers less or equal to n. More formally, we investigate the sum of n components denoted by d(1) + d(2) + ... + d(n) in which for any i starting from...
{"functional": "_inputs = [[5], [10], [20], [59], [105], [785], [1001], [8009], [9999999999999], [9999999999998], [9999999999995], [9999999949950]]\n_outputs = [[10], [27], [66], [249], [510], [5364], [7077], [73241], [300880375389561], [300880375389537], [300880375389493], [300880373832097]]\nimport math\ndef _deep_eq...
coding
466
Solve the programming task below in a Python markdown code block. You are given a sequence A_1, A_2, ..., A_N and an integer K. Print the maximum possible length of a sequence B that satisfies the following conditions: * B is a (not necessarily continuous) subsequence of A. * For each pair of adjacents elements of B,...
{"inputs": ["8 3\n0\n2\n4\n0\n5\n6\n9\n7\n4\n4", "8 3\n1\n5\n2\n3\n6\n6\n9\n8\n4\n1", "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n4\n4", "10 3\n1\n5\n4\n3\n6\n6\n9\n7\n4\n4", "10 3\n0\n1\n4\n3\n6\n6\n9\n7\n4\n4", "10 3\n1\n5\n4\n3\n8\n6\n9\n7\n3\n4", "10 1\n0\n1\n4\n0\n5\n9\n9\n7\n8\n4", "10 3\n1\n5\n2\n0\n6\n6\n9\n8\n4\n1"], "outp...
coding
220
Solve the programming task below in a Python markdown code block. There are N cities on a number line. The i-th city is located at coordinate x_i. Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D. Then, you will depart from coordinate X and perform Mo...
{"inputs": ["1 575\n89\n", "1 81\n385\n", "3 3\n1 5 11", "1 3\n1 5 11", "1 3\n2 5 11", "1 3\n2 4 11", "3 3\n1 7 11", "3 3\n1 7 11\n"], "outputs": ["486\n", "304\n", "2\n", "2\n", "1\n", "1\n", "2", "2\n"]}
coding
397
Solve the programming task below in a Python markdown code block. There is a field with plants — a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$); out of its $NM$ cells, $K$ cells contain plants, while the rest contain weeds. Two cells are adjacent if they have a common side. Y...
{"inputs": ["2\n4 4 9\n1 4\n2 1\n2 2\n2 3\n3 1\n3 3\n4 1\n4 2\n4 3\n4 4 1\n1 1"], "outputs": ["20\n4"]}
coding
651
Solve the programming task below in a Python markdown code block. You are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to be neigh...
{"inputs": ["2\n5\nRBBRG\n5\nRBGOV"], "outputs": ["1\n0"]}
coding
315
Solve the programming task below in a Python markdown code block. Wabbit is playing a game with $n$ bosses numbered from $1$ to $n$. The bosses can be fought in any order. Each boss needs to be defeated exactly once. There is a parameter called boss bonus which is initially $0$. When the $i$-th boss is defeated, the c...
{"inputs": ["3 0\n1 1 1\n", "1 0\n1000000\n", "1 500000\n-1\n", "5 1\n-1 -2 -3 -4 5\n", "5 5\n-1 -2 -3 -4 -5\n", "13 2\n3 1 4 1 5 -9 -2 -6 -5 -3 -5 -8 -9\n", "10 3\n950 882 856 786 677 480 302 258 147 98\n", "70 2\n1 1 1 1 1 -1 -1 -1 -1 -1 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3...
coding
735
Solve the programming task below in a Python markdown code block. Given a positive integer N, MoEngage wants you to determine if it is possible to rearrange the digits of N (in decimal representation) and obtain a [multiple] of 5. For example, when N = 108, we can rearrange its digits to construct 180 = 36 \cdot 5 wh...
{"inputs": ["3\n3\n115\n3\n103\n3\n119"], "outputs": ["Yes\nYes\nNo"]}
coding
533
Solve the programming task below in a Python markdown code block. ------Read problems statements in Mandarin chinese , Russian and Vietnamese as well. ------ Professor GukiZ decided to distribute all of his candies to his $N$ students (numbered $1$ through $N$). Let's denote the number of candies GukiZ gave to the $i...
{"inputs": ["2\n4 3 4 \n2 1 5\n2 2 9\n3 6"], "outputs": ["12\n9"]}
coding
752
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. Count the number of pairs of indices $(i, j)$ such that $i < j$ and $a_i \cdot a_j = i + j$. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 10^...
{"inputs": ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2\n", "3\n2\n3 1\n3\n4 1 5\n5\n3 1 5 9 2\n", "3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 4\n", "3\n2\n2 1\n3\n4 1 5\n5\n3 1 4 9 2\n", "3\n2\n3 1\n3\n4 2 5\n5\n3 1 4 5 2\n", "3\n2\n3 2\n3\n2 1 5\n5\n3 1 5 9 4\n", "3\n2\n3 1\n3\n4 1 5\n5\n6 1 5 9 4\n", "3\n2\n3 2\n3\n4 1 5\n5\n6 1 5 9 4\...
coding
426
Solve the programming task below in a Python markdown code block. A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not. Ahcl wants to construct a beautiful string. He has a string $s$, consisting of...
{"inputs": ["3\na???cb\na??bbc\na?b?c\n", "3\na???cb\na??bbc\nc?b?a\n", "3\na???cb\na??bbc\ncab??\n", "3\na???cb\na??bbb\na?b?c\n", "3\na???cb\na??bbc\nc?a?a\n", "3\na???cb\na??bbb\na?c?b\n", "3\na???cb\nbbb??a\na>c?b\n", "3\na???cb\na??bbb\na?a?c\n"], "outputs": ["ababcb\n-1\nacbac\n", "ababcb\n-1\ncabca\n", "ababcb\n...
coding
524
Solve the programming task below in a Python markdown code block. Let's pretend your company just hired your friend from college and paid you a referral bonus. Awesome! To celebrate, you're taking your team out to the terrible dive bar next door and using the referral bonus to buy, and build, the largest three-dimensio...
{"functional": "_inputs = [[9, 2], [10, 2], [11, 2], [21, 1.5], [454, 5], [455, 5], [4, 4], [3, 4], [0, 4], [-1, 4]]\n_outputs = [[1], [2], [2], [3], [5], [6], [1], [0], [0], [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...
coding
205
Solve the programming task below in a Python markdown code block. There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may sho...
{"inputs": ["2\nFA\n", "2\nFF\n", "2\nIF\n", "2\nFA\n", "2\nFF\n", "2\nFA\n", "2\nIF\n", "2\nAF\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "0", "1", "1", "1\n"]}
coding
336
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots, a_n$ where all $a_i$ are integers and greater than $0$. In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$). If $gcd(a_i, a_j)$ is equal to the minimum element of the whole ar...
{"inputs": ["1\n5\n2 6 2 4 5\n", "1\n5\n2 6 2 4 5\n", "1\n5\n2 6 2 4 1\n", "1\n5\n2 6 2 4 8\n", "1\n5\n2 6 4 4 1\n", "1\n5\n2 6 2 4 6\n", "1\n5\n3 6 4 4 1\n", "1\n5\n2 4 2 4 1\n"], "outputs": ["NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
520
Solve the programming task below in a Python markdown code block. White Falcon has a tree with $N$ nodes. Each node contains a linear function. Let's denote by $f_u(x)$ the linear function contained in the node $\mbox{u}$. Let's denote the path from node $\mbox{u}$ to node $\boldsymbol{\nu}$ like this: $p_1,p_2,p_3,...
{"inputs": ["2\n1 1\n1 2\n1 2\n2\n1 2 2 1 1\n2 1 2 1\n"], "outputs": ["3\n"]}
coding
558
Solve the programming task below in a Python markdown code block. Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 $\le$ HH $\le$ 23, 00 $\le$ MM $\le$ 59). He looks at the clock every $x$ minutes, and the clock is currently showing time $s$. How many different palindromes will Victor see in to...
{"inputs": ["1\n01:01 1439\n", "6\n03:12 360\n00:00 1\n13:22 2\n15:15 10\n11:11 1440\n22:30 27\n", "7\n09:09 855\n07:07 986\n01:01 251\n09:09 77\n02:02 28\n01:01 711\n06:06 1062\n", "10\n05:17 516\n03:42 1088\n10:47 1114\n21:01 954\n09:54 999\n00:47 846\n13:15 511\n15:51 712\n07:04 332\n04:42 17\n"], "outputs": ["16\n"...
coding
581
Solve the programming task below in a Python markdown code block. For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$. If any such permutation of the elem...
{"inputs": ["3\naaaabccc\naabbcc\nppppmmnnoooopp"], "outputs": ["Dynamic\nNot\nDynamic"]}
coding
517
Solve the programming task below in a Python markdown code block. Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of ...
{"inputs": ["1\n1\n", "1\n1\n", "3\n1 3 3\n", "3\n1 1 1\n", "3\n3 3 3\n", "3\n1 3 3\n", "3\n3 3 3\n", "3\n1 1 1\n"], "outputs": ["0", "0\n", "1", "3", "3", "1\n", "3\n", "3\n"]}
coding
303
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the ith person. A Person x will not send a friend request to a person y (x != y) if any of the following c...
{"functional": "def check(candidate):\n assert candidate(ages = [16,16]) == 2\n assert candidate(ages = [16,17,18]) == 2\n assert candidate(ages = [20,30,100,110,120]) == 3\n\n\ncheck(Solution().numFriendRequests)"}
coding
200
Solve the programming task below in a Python markdown code block. How much bigger is a 16-inch pizza compared to an 8-inch pizza? A more pragmatic question is: How many 8-inch pizzas "fit" in a 16-incher? The answer, as it turns out, is exactly four 8-inch pizzas. For sizes that don't correspond to a round number of 8...
{"functional": "_inputs = [[16], [12], [8], [6], [0]]\n_outputs = [['pizzas: 4, slices: 0'], ['pizzas: 2, slices: 2'], ['pizzas: 1, slices: 0'], ['pizzas: 0, slices: 4'], ['pizzas: 0, slices: 0']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl...
coding
254
Please solve the programming task below using a self-contained code snippet in a markdown code block. A valid cut in a circle can be: A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or A cut that is represented by a straight line that touch...
{"functional": "def check(candidate):\n assert candidate(n = 4) == 2\n assert candidate(n = 3) == 3\n\n\ncheck(Solution().numberOfCuts)"}
coding
140
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c. A provinc...
{"functional": "def check(candidate):\n assert candidate(isConnected = [[1,1,0],[1,1,0],[0,0,1]]) == 2\n assert candidate(isConnected = [[1,0,0],[0,1,0],[0,0,1]]) == 3\n\n\ncheck(Solution().findCircleNum)"}
coding
165
Solve the programming task below in a Python markdown code block. Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi,...
{"inputs": ["1 1\n1 1\n1 1\n", "1 1\n1 1\n2 2\n", "1 1\n1 1\n1 2\n", "1 1\n1 2\n2 2\n", "1 1\n2 1\n1 2\n", "1 1\n1 2\n1 2\n", "1 1\n0 1\n1 2\n", "1 1\n0 1\n2 2\n"], "outputs": ["1 1\n", "0 0\n", "0 0\n", "1 0\n", "0 0\n", "1 1\n", "0 0\n", "0 0\n"]}
coding
491
Solve the programming task below in a Python markdown code block. Given are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353. * Let us repeat the following operation on the integer k. Operation: if t...
{"inputs": ["3\n011", "3\n001", "3\n000", "3\n010", "3\n101", "3\n110", "3\n100", "3\n111"], "outputs": ["20", "12", "6", "14", "28", "34", "26", "40"]}
coding
348
Solve the programming task below in a Python markdown code block. Faizal and Sultan are having a one-on-one faceoff. Before stepping into the fight, each of them smoked a special kind of weed from Jhalwa. Smoking k grams of this weed grants the smoker the ability to resurrect k times after dying. Sultan smoked M grams ...
{"inputs": ["3\n2 1\n12 6\n6969 8563"], "outputs": ["7\n255\n988402422\n"]}
coding
711
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the sum of values of its deepest leaves.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __init...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,None,6,7,None,None,None,None,8])) == 15\n assert candidate(root = tree_node([6,7,8,2,7,1,3,9,None,1,4,None,None,None,5])) == 19\n\n\ncheck(Solution().deepestLeavesSum)"}
coding
120
Solve the programming task below in a Python markdown code block. There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_...
{"inputs": ["4 4\n2 3 5 7\n1 2 7\n1 3 9\n1 3 6\n3 4 18", "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 21\n3 4 18", "4 4\n2 3 1 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18", "4 4\n2 3 5 7\n1 4 7\n1 2 9\n1 3 15\n3 4 18", "4 4\n2 3 5 7\n1 2 7\n1 3 9\n1 3 21\n3 4 18", "4 4\n2 3 1 7\n1 2 7\n2 3 9\n2 3 12\n3 4 18", "4 4\n2 3 5 7\n1 4 7\n1 3 9\n1 3 ...
coding
588
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n and an integer p representing an array arr of length n where all elements are set to 0's, except position p which is set to 1. You are also given an integer array banned containing restricte...
{"functional": "def check(candidate):\n assert candidate(n = 4, p = 0, banned = [1,2], k = 4) == [0,-1,-1,1]\n assert candidate(n = 5, p = 0, banned = [2,4], k = 3) == [0,-1,-1,-1,-1]\n assert candidate(n = 4, p = 2, banned = [0,1,3], k = 1) == [-1,-1,0,-1]\n\n\ncheck(Solution().minReverseOperations)"}
coding
178
Solve the programming task below in a Python markdown code block. Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day a...
{"inputs": ["1 1\n1\n", "1 1\n0\n", "1 1\n0\n", "1 1\n1\n", "2 1\n0\n", "4 1\n0100\n", "2 1\n0100\n", "8 1\n0100\n"], "outputs": ["0\n", "1\n", "1", "0", "1\n", "1\n", "1\n", "1\n"]}
coding
431
Please solve the programming task below using a self-contained code snippet in a markdown code block. The width of a sequence is the difference between the maximum and minimum elements in the sequence. Given an array of integers nums, return the sum of the widths of all the non-empty subsequences of nums. Since the an...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,3]) == 6\n assert candidate(nums = [2]) == 0\n\n\ncheck(Solution().sumSubseqWidths)"}
coding
173
Please solve the programming task below using a self-contained code snippet in a markdown code block. A sentence is a string of single-space separated words where each word consists only of lowercase letters. A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other senten...
{"functional": "def check(candidate):\n assert candidate(s1 = \"this apple is sweet\", s2 = \"this apple is sour\") == [\"sweet\",\"sour\"]\n assert candidate(s1 = \"apple apple\", s2 = \"banana\") == [\"banana\"]\n\n\ncheck(Solution().uncommonFromSentences)"}
coding
126
Solve the programming task below in a Python markdown code block. In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$, there exist no positive integers $x$, $y$, $z$ such that $x^n + y^n = z^n$. However he never disclosed the proof. Later, this claim was named Fermat's Last Theorem or Fermat's C...
{"inputs": ["6\n6\n2\n0", "6\n6\n0\n0", "6\n4\n4\n0", "6\n5\n2\n0", "6\n0\n0\n1", "6\n3\n2\n0", "6\n5\n0\n1", "6\n7\n4\n0"], "outputs": ["27\n27\n6\n", "27\n27\n", "27\n10\n10\n", "27\n34\n6\n", "27\n", "27\n11\n6\n", "27\n34\n", "27\n2\n10\n"]}
coding
555
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of integers, a move consists of choosing any element and decreasing it by 1. An array A is a zigzag array if either: Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] <...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 2\n assert candidate(nums = [9,6,1,6,2]) == 4\n\n\ncheck(Solution().movesToMakeZigzag)"}
coding
188
Solve the programming task below in a Python markdown code block. A tennis tournament is about to take place with $N$ players participating in it. Every player plays with every other player exactly once and there are no ties. That is, every match has a winner and a loser. With Naman's birthday approaching, he wants to...
{"inputs": ["2\n3\n2"], "outputs": ["YES\n010\n001\n100\nNO"]}
coding
455
Please solve the programming task below using a self-contained code snippet in a markdown code block. You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n. However, there are city restrictions on the heights of the new buildings: The height of each buildin...
{"functional": "def check(candidate):\n assert candidate(n = 5, restrictions = [[2,1],[4,1]]) == 2\n assert candidate(n = 6, restrictions = []) == 5\n assert candidate(n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]) == 5\n\n\ncheck(Solution().maxBuilding)"}
coding
219
Solve the programming task below in a Python markdown code block. Read problems statements in [Russian]. Chef has an array A of size N. Chef wants to choose any subsequence of size exactly \lceil \frac{N}{2} \rceil from the array such that GCD of all the elements in that sequence must be 2. Chef names such a kind of ...
{"inputs": ["3\n5\n1 2 3 4 5\n4\n1 2 3 4\n3\n30 42 70"], "outputs": ["NO\nYES\nNO"]}
coding
624
Please solve the programming task below using a self-contained code snippet in a markdown code block. The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. For example, "ACGAATTCCG" is a DNA sequence. When studying DNA, it is useful to identify repeated sequences within the D...
{"functional": "def check(candidate):\n assert candidate(s = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\") == [\"AAAAACCCCC\",\"CCCCCAAAAA\"]\n assert candidate(s = \"AAAAAAAAAAAAA\") == [\"AAAAAAAAAA\"]\n\n\ncheck(Solution().findRepeatedDnaSequences)"}
coding
151
Solve the programming task below in a Python markdown code block. n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all n...
{"inputs": ["3\n000\n", "3\n007\n", "3\n007\n", "3\n000\n", "3\n111\n", "3\n100\n", "3\n001\n", "3\n101\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
404
Solve the programming task below in a Python markdown code block. You are given the sequence of Nucleotides of one strand of DNA through a string S of length N. S contains the character A, T, C, and G only. Chef knows that: A is complementary to T. T is complementary to A. C is complementary to G. G is complementary t...
{"inputs": ["4\n4\nATCG\n4\nGTCC\n5\nAAAAA\n3\nTAC\n"], "outputs": ["TAGC\nCAGG\nTTTTT\nATG\n"]}
coding
440
Solve the programming task below in a Python markdown code block. Your retro heavy metal band, VÄxën, originally started as kind of a joke, just because why would anyone want to use the crappy foosball table in your startup's game room when they could be rocking out at top volume in there instead? Yes, a joke, but now ...
{"functional": "_inputs = [['Announcing the Macbook Air Guitar'], ['Facebook introduces new heavy metal reaction buttons'], [\"Strong sales of Google's VR Metalheadsets send tech stock prices soaring\"], ['Vegan Black Metal Chef hits the big time on Amazon TV']]\n_outputs = [['\u00c4nn\u00f6\u00fcnc\u00efng th\u00eb M\...
coding
712
Solve the programming task below in a Python markdown code block. You are given a function $f(X)=X^2$. You are also given $\mbox{K}$ lists. The $i^{\mbox{th}}$ list consists of $N_i$ elements. You have to pick one element from each list so that the value from the equation below is maximized: $S=(f(X_1)~+f(X_2)+~.......
{"inputs": ["3 1000\n2 5 4\n3 7 8 9 \n5 5 7 8 9 10 \n"], "outputs": ["206\n"]}
coding
512