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. This function should take two string parameters: a person's name (`name`) and a quote of theirs (`quote`), and return a string attributing the quote to the person in the following format: ```python '[name] said: "[quote]"' ``` For example, if `name` is...
{"functional": "_inputs = [['Grae', 'Practice makes perfect'], ['Dan', 'Get back to work, Grae'], ['Alex', 'Python is great fun'], ['Bethany', 'Yes, way more fun than R'], ['Darrell', 'What the heck is this thing?']]\n_outputs = [['Grae said: \"Practice makes perfect\"'], ['Dan said: \"Get back to work, Grae\"'], ['Ale...
coding
185
Solve the programming task below in a Python markdown code block. Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc. A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i. He would like to make ...
{"inputs": ["7\n1 2\n2 3\n2 4\n2 5\n4 6\n6 7", "7\n1 4\n2 3\n2 4\n4 5\n4 6\n6 7", "7\n1 4\n2 3\n2 4\n4 5\n7 6\n6 7", "7\n1 4\n2 3\n2 4\n1 5\n7 6\n6 7", "7\n1 4\n2 3\n2 4\n1 5\n7 6\n6 5", "7\n1 4\n2 3\n2 4\n4 5\n7 3\n6 3", "7\n1 2\n2 3\n4 4\n1 5\n7 6\n6 7", "7\n1 4\n2 3\n2 4\n1 5\n5 6\n7 7"], "outputs": ["2 4\n", "2 3\n...
coding
522
Solve the programming task below in a Python markdown code block. "What do you know about happiness?" — Yoda Chef is happy only if three conditions hold: - Chef finished cooking a delicious meal - Chef got AC for a programming problem with an almost correct code - Chef got a new problem with a sequence of integers Tod...
{"inputs": ["4\n4\n1 1 2 3\n4\n2 1 3 3\n5\n5 4 4 3 1\n5\n3 2 1 1 4"], "outputs": ["Truly Happy\nPoor Chef\nPoor Chef\nTruly Happy"]}
coding
562
Solve the programming task below in a Python markdown code block. You are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations with this multiset. During each operation you choose ...
{"inputs": ["6\n4\n1024 512 8 512\n1\n2048\n3\n32 512 2\n2\n4096 1\n1\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n", "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n", "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n1\n2048 2 2048 2048 2048 2048 20...
coding
720
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n / 2) - 1. For example, if n = 4, then node 0 is the twin of node 3,...
{"functional": "def check(candidate):\n assert candidate(head = list_node([5,4,2,1])) == 6\n assert candidate(head = list_node([4,2,2,3])) == 7\n assert candidate(head = list_node([1,100000])) == 100001\n\n\ncheck(Solution().pairSum)"}
coding
228
Please solve the programming task below using a self-contained code snippet in a markdown code block. We are given a list nums of integers representing a list compressed with run-length encoding. Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there ar...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == [2,4,4,4]\n assert candidate(nums = [1,1,2,3]) == [1,3,3]\n\n\ncheck(Solution().decompressRLElist)"}
coding
143
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 smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them. You may assume that no str...
{"functional": "def check(candidate):\n assert candidate(words = [\"alex\",\"loves\",\"leetcode\"]) == \"alexlovesleetcode\"\n assert candidate(words = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]) == \"gctaagttcatgcatc\"\n\n\ncheck(Solution().shortestSuperstring)"}
coding
103
Solve the programming task below in a Python markdown code block. You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become d...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0", "0", "0", "0"]}
coding
298
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. You are given a multi-set S of N integers, and an integer K. You want to find the maximum value of minimal excluded non-negative integer (MEX) of the multi-set given that you...
{"inputs": ["4\n3 0\n1 0 2\n3 1\n1 0 2\n4 3\n2 5 4 9\n2 0\n3 4"], "outputs": ["3\n4\n6\n0"]}
coding
573
Solve the programming task below in a Python markdown code block. Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the...
{"inputs": ["FVF\nr \n", "FVF\nq \n", "FFV\nq \n", "VFF\nq \n", "VFG\nq \n", "GtPXu\nd\n", "GPtXu\nd\n", "XPtGu\nd\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
296
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a multi-dimensional array containing `2 or more` sub-arrays of integers. Your task is to find the maximum product that can be formed by taking any one element from each sub-array. ``` Examples: solve( [[1, 2],[3, 4]] ) = ...
{"functional": "_inputs = [[[[1, 2], [3, 4]]], [[[10, -15], [-1, -3]]], [[[-1, 2, -3, 4], [1, -2, 3, -4]]], [[[-11, -6], [-20, -20], [18, -4], [-20, 1]]], [[[14, 2], [0, -16], [-12, -16]]], [[[-3, -4], [1, 2, -3]]], [[[-2, -15, -12, -8, -16], [-4, -15, -7], [-10, -5]]]]\n_outputs = [[8], [45], [12], [17600], [3584], [1...
coding
192
Solve the programming task below in a Python markdown code block. You are given two positive integers $A$ and $B$. Find the number of pairs of positive integers $(X, Y)$ such that $1 \le X \le A$, $1 \le Y \le B$ and $X + Y$ is even. -----Input----- - The first line of the input contains a single integer $T$ denoting ...
{"inputs": ["4\n1 1\n2 3\n4 6\n8 9"], "outputs": ["1\n3\n12\n36"]}
coding
274
Solve the programming task below in a Python markdown code block. ### Combine strings function ```if:coffeescript,haskell,javascript Create a function named `combineNames` that accepts two parameters (first and last name). The function should return the full name. ``` ```if:python,ruby Create a function named (`combine...
{"functional": "_inputs = [['James', 'Stevens'], ['Davy', 'Back'], ['Arthur', 'Dent']]\n_outputs = [['James Stevens'], ['Davy Back'], ['Arthur Dent']]\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 is...
coding
178
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix. A falling path starts at any element in the first row and chooses the element in the next row that is either directly...
{"functional": "def check(candidate):\n assert candidate(matrix = [[2,1,3],[6,5,4],[7,8,9]]) == 13\n assert candidate(matrix = [[-19,57],[-40,-5]]) == -59\n\n\ncheck(Solution().minFallingPathSum)"}
coding
148
Solve the programming task below in a Python markdown code block. At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows: - The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.) - Ea...
{"inputs": ["3 2\n1 8 6\nssr\n", "5 2\n8 7 2\nrsrpr", "5 2\n8 7 6\nrsrpr", "5 2\n8 7 6\nrsrpr\n", "5 2\n12 7 2\nrsrpr", "5 2\n14 7 2\nrsrpr", "5 2\n18 7 2\nrsrpr", "5 2\n18 7 1\nrsrpr"], "outputs": ["8\n", "19\n", "27", "27\n", "23\n", "25\n", "29\n", "27\n"]}
coding
592
Solve the programming task below in a Python markdown code block. Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In e...
{"inputs": ["1\n0 2\n", "1\n3 2\n", "1\n3 2\n", "1\n0 2\n", "1\n0 1\n", "1\n-5 1\n", "1\n-1 2\n", "1\n-1 1\n"], "outputs": ["1899\n", "1902\n", "1902\n", "1899\n", "Infinity\n", "Infinity\n", "1898\n", "Infinity\n"]}
coding
625
Solve the programming task below in a Python markdown code block. Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: the Euclidean distance between A and B is one u...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "0\n", "5\n", "6\n", "7\n"], "outputs": ["4\n", "8\n", "16\n", "20\n", "1\n", "28\n", "32\n", "36\n"]}
coding
268
Solve the programming task below in a Python markdown code block. Slime has a sequence of positive integers $a_1, a_2, \ldots, a_n$. In one operation Orac can choose an arbitrary subsegment $[l \ldots r]$ of this sequence and replace all values $a_l, a_{l + 1}, \ldots, a_r$ to the value of median of $\{a_l, a_{l + 1},...
{"inputs": ["1\n5 2\n2 1 5 1 1\n", "1\n5 2\n2 1 5 1 1\n", "1\n5 2\n4 1 5 1 1\n", "1\n5 2\n4 1 5 2 1\n", "1\n6 3\n3 1 1 6 1 6\n", "1\n6 3\n4 1 4 1 1 3\n", "1\n6 2\n3 1 3 1 1 2\n", "1\n6 3\n5 1 5 2 2 3\n"], "outputs": ["yes\n", "yes\n", "no\n", "yes\n", "yes\n", "yes\n", "yes\n", "yes\n"]}
coding
643
Solve the programming task below in a Python markdown code block. ------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ The structure of the company ShareChat can be described by a simple graph (without multiedges and self-loops) with $N$ vertices numbered $1$ through $N$ ...
{"inputs": ["2\n7 7\n1 2\n2 3\n3 4\n2 5\n3 5\n5 6\n6 7\n3 3\n1 2\n2 3\n3 1"], "outputs": ["6\n4\n6\n6\n6\n10\n6\n1\n1\n1"]}
coding
514
Solve the programming task below in a Python markdown code block. Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adja...
{"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "3\n0 1 0\n", "3\n1 1 0\n", "3\n0 1 1\n", "3\n0 1 0\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
342
Solve the programming task below in a Python markdown code block. Range Minimum Query is a well-known problem: given an array of distinct integers with size $n=2^k$ and $m$ queries, find the minimum element on subsegment $[L_i,R_i]$. One of the most efficient and famous solutions to this problem is a segment tree. A s...
{"inputs": ["2\n1 1 1\n", "4\n3 1 3 1 2 4 1\n"], "outputs": ["NO \n", "YES\n1 1 3 1 2 3 4 \n"]}
coding
709
Solve the programming task below in a Python markdown code block. AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as show...
{"inputs": ["1\n1 400", "1\n1 400\n", "3\n2 5\n4 6\n2 4", "3\n1 3\n5 8\n1 3", "3\n1 3\n8 8\n1 3", "3\n2 3\n4 4\n2 4", "3\n2 1\n8 8\n1 3", "3\n2 1\n4 9\n1 8"], "outputs": ["0", "0\n", "0\n", "2\n", "5\n", "1\n", "7\n", "3\n"]}
coding
313
Solve the programming task below in a Python markdown code block. In this kata, the number 0 is infected. You are given a list. Every turn, any item in the list that is adjacent to a 0 becomes infected and transforms into a 0. How many turns will it take for the whole list to become infected? ``` [0,1,1,0] ==> [0,0,0,...
{"functional": "_inputs = [[[0]], [[0, 1, 1, 0]], [[0, 1, 1, 1, 0]], [[1, 1, 0, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]]]\n_outputs = [[0], [1], [2], [2], [3], [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_tol=tol...
coding
254
Solve the programming task below in a Python markdown code block. Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased i...
{"inputs": ["2\n??\n", "2\n??\n", "4\n0523\n", "4\n1928\n", "4\n00??\n", "4\n50??\n", "4\n99??\n", "4\n??99\n"], "outputs": ["Bicarp\n", "Bicarp\n", "Bicarp\n", "Bicarp\n", "Monocarp\n", "Monocarp\n", "Monocarp\n", "Monocarp\n"]}
coding
524
Solve the programming task below in a Python markdown code block. The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he sees a s...
{"inputs": ["6\n18\n..H..T...HTH....T.\n3\n...\n10\nH..H..T..T\n2\nHT\n11\n.T...H..H.T\n7\nH..T..H"], "outputs": ["Valid\nValid\nInvalid\nValid\nInvalid\nInvalid"]}
coding
626
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively. You are also given two 0-indexed integer arrays...
{"functional": "def check(candidate):\n assert candidate(initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]) == 8\n assert candidate(initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]) == 0\n\n\ncheck(Solution().minNumberOfHours)"}
coding
242
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. You are given a function f which is defined as : Your task is to find the value of where M is given in input. ------ Input Format ------ First line contains T, the number of test ...
{"inputs": ["2\n5 114 1\n2\n50 3874 3\n31\n17\n21"], "outputs": ["72\n3718\n624\n1144"]}
coding
381
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing. A 0-indexed string num of length n + 1 is created using the following conditions: n...
{"functional": "def check(candidate):\n assert candidate(pattern = \"IIIDIDDD\") == \"123549876\"\n assert candidate(pattern = \"DDD\") == \"4321\"\n\n\ncheck(Solution().smallestNumber)"}
coding
169
Solve the programming task below in a Python markdown code block. # Task: We define the "self reversed power sequence" as one shown below: Implement a function that takes 2 arguments (`ord max` and `num dig`), and finds the smallest term of the sequence whose index is less than or equal to `ord max`, and has exactl...
{"functional": "_inputs = [[5, 10], [7, 11], [7, 14], [8, 16], [10, 20]]\n_outputs = [[[True, 10]], [[False, -1]], [[True, 13]], [[True, 15]], [[True, 17]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
coding
406
Solve the programming task below in a Python markdown code block. Alice buys a toy with a selling price of 100 rupees. There is a discount of x percent on the toy. Find the amount Alice needs to pay for it. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of t...
{"inputs": ["4\n5\n9\n11\n21\n"], "outputs": ["95\n91\n89\n79\n"]}
coding
233
Solve the programming task below in a Python markdown code block. Get excited, folks, because it is time for the final match of Codechef Premier League (CPL)! Mike and Tracy also want to watch the grand finale, but unfortunately, they could not get tickets to the match. However, Mike is not someone who gives up so easi...
{"inputs": ["2\n8 38\n7 8 19 7 8 7 10 20\n4 5\n2 10 4 9"], "outputs": ["7\n2"]}
coding
668
Solve the programming task below in a Python markdown code block. According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment....
{"inputs": ["6 10\n4 6 4 1 9 3\n", "6 10\n4 3 4 1 9 3\n", "6 10\n4 3 4 2 9 3\n", "6 10\n4 3 2 2 9 3\n", "6 10\n4 3 0 2 9 3\n", "6 10\n5 6 4 1 9 3\n", "5 1\n24 30 18 9 76\n", "5 1\n24 28 18 9 76\n"], "outputs": ["30\n", "30\n", "30\n", "30\n", "30\n", "30\n", "0\n", "0\n"]}
coding
281
Solve the programming task below in a Python markdown code block. *`This kata is a tribute/fanwork to the TV-show: Supernatural`* Balls! Those wayward Winchester boys are in trouble again, hunting something down in New Orleans. You are Bobby Singer, you know how "idjits" they can be, so you have to prepare. They wil...
{"functional": "_inputs = [['vampire'], ['pagan god'], ['werepuppy']]\n_outputs = [['Behead it with a machete, idjits!'], ['It depends on which one it is, idjits!'], ['I have friggin no idea yet, idjits!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return...
coding
489
Solve the programming task below in a Python markdown code block. Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuf...
{"inputs": ["4\n2\n", "1\n1\n", "2\n2\n", "3\n1\n", "3\n2\n", "3\n0\n", "2\n0\n", "2\n1\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "2\n", "1\n", "2\n"]}
coding
469
Solve the programming task below in a Python markdown code block. You are given a sequence of integers $A_1,A_2,…,A_N$ and a magical non-zero integer $x$ You have to select a subsegment of sequence A (possibly empty), and replace the elements in that subsegment after dividing them by x. Formally, replace any one subseg...
{"inputs": ["3 2\n1 -2 3"], "outputs": ["0.5"]}
coding
334
Solve the programming task below in a Python markdown code block. There is one card each with the numbers from "1" to "10", for a total of 10 cards. This card has numbers on the front and nothing on the back. Using this card, you and your opponent will play the game according to the following rules. 1. You and your op...
{"inputs": ["1 2 3\n5 2 8\n8 1 5", "1 2 3\n5 1 8\n8 1 5", "1 2 3\n8 2 9\n8 2 6", "1 2 3\n6 2 8\n8 1 5", "1 2 3\n6 2 8\n8 1 4", "1 2 3\n6 2 8\n4 1 5", "1 2 3\n5 1 8\n8 1 9", "1 2 3\n6 1 8\n5 2 8"], "outputs": ["YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n", "YES\nYES\nYES\n...
coding
459
Solve the programming task below in a Python markdown code block. Consider an array containing cats and dogs. Each dog can catch only one cat, but cannot catch a cat that is more than `n` elements away. Your task will be to return the maximum number of cats that can be caught. For example: ```Haskell solve(['D','C','C...
{"functional": "_inputs = [[['D', 'C', 'C', 'D', 'C'], 1], [['C', 'C', 'D', 'D', 'C', 'D'], 2], [['C', 'C', 'D', 'D', 'C', 'D'], 1], [['D', 'C', 'D', 'C', 'C', 'D'], 3], [['C', 'C', 'C', 'D', 'D'], 3], [['C', 'C', 'C', 'D', 'D'], 2], [['C', 'C', 'C', 'D', 'D'], 1], [['C', 'C', 'C', 'D', 'D', 'D', 'C', 'D', 'D', 'D', 'C...
coding
263
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Andy and Bob are the only two delivery men of Pizza-chef store. Today, the store received N orders. It's known that the amount of tips may be different when handled by different delivery man. ...
{"inputs": ["5 3 3\n1 2 3 4 5\n5 4 3 2 1", "5 3 3\n1 2 3 4 5\n5 4 3 0 1", "5 3 3\n1 0 3 5 5\n5 4 3 0 1", "5 3 3\n1 2 3 4 5\n2 4 2 0 2", "5 3 3\n1 2 5 4 5\n2 4 2 1 3", "5 3 3\n1 2 5 4 9\n2 4 2 1 2", "5 3 3\n1 2 4 4 9\n2 4 2 1 2", "5 3 3\n1 0 3 4 5\n5 2 3 0 1"], "outputs": ["21", "21\n", "22\n", "18\n", "20\n", "24\n", "...
coding
447
Solve the programming task below in a Python markdown code block. Take the following IPv4 address: `128.32.10.1` This address has 4 octets where each octet is a single byte (or 8 bits). * 1st octet `128` has the binary representation: `10000000` * 2nd octet `32` has the binary representation: `00100000` * 3rd octet `...
{"functional": "_inputs = [[2154959208], [0], [2149583361]]\n_outputs = [['128.114.17.104'], ['0.0.0.0'], ['128.32.10.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_tol=tol)\n if isinstance(a, (list, tuple)):\...
coding
348
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.   Please complete the following python c...
{"functional": "def check(candidate):\n assert candidate(words = [\"abcw\",\"baz\",\"foo\",\"bar\",\"xtfn\",\"abcdef\"]) == 16 \n assert candidate(words = [\"a\",\"ab\",\"abc\",\"d\",\"cd\",\"bcd\",\"abcd\"]) == 4 \n assert candidate(words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]) == 0 \n\n\ncheck(Solution().maxProdu...
coding
89
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: * 232 * 110011 * 54322345 Complete the function to test if the given number (`num`) **can be rearr...
{"functional": "_inputs = [[5], [1212], ['ololo'], [1331], [194], [111222], ['Hello world!'], [3357665], ['357665'], [-42]]\n_outputs = [[False], [True], ['Not valid'], [True], [False], [False], ['Not valid'], [True], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)...
coding
256
Solve the programming task below in a Python markdown code block. Toad Zitz has an array of integers, each integer is between 0 and m-1 inclusive. The integers are a_1, a_2, …, a_n. In one operation Zitz can choose an integer k and k indices i_1, i_2, …, i_k such that 1 ≤ i_1 < i_2 < … < i_k ≤ n. He should then change...
{"inputs": ["1 1\n0\n", "2 2\n0 1\n", "2 1\n0 0\n", "2 2\n1 0\n", "2 2\n1 1\n", "2 3\n1 0\n", "2 2\n0 0\n", "4 6\n0 3 5 1\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "3\n"]}
coding
418
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Russian]. Chef opted for Bio-Statistics as an Open-Elective course in his university, but soon got bored, and decided to text his friends during lectures. The instructor caught Chef, and decided to puni...
{"inputs": ["2\n8\n5 9 2 9 7 2 5 3\n9\n5 9 2 9 7 2 5 3 1"], "outputs": ["2\n1"]}
coding
663
Solve the programming task below in a Python markdown code block. A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i su...
{"inputs": ["3\n6 6 1\n1 9 1", "3\n1 4 1\n1 0 1", "3\n1 4 1\n0 0 1", "3\n2 4 1\n0 0 1", "3\n6 0 1\n1 3 1", "3\n2 4 1\n1 0 1", "3\n6 6 1\n0 9 1", "3\n3 4 1\n0 0 1"], "outputs": ["13\n10\n0\n", "6\n1\n0\n", "5\n0\n0\n", "6\n0\n0\n", "7\n4\n0\n", "7\n1\n0\n", "12\n9\n0\n", "7\n0\n0\n"]}
coding
560
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any computer can reach any...
{"functional": "def check(candidate):\n assert candidate(n = 4, connections = [[0,1],[0,2],[1,2]]) == 1\n assert candidate(n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]) == 2\n assert candidate(n = 6, connections = [[0,1],[0,2],[0,3],[1,2]]) == -1\n assert candidate(n = 5, connections = [[0,1],[0,2],...
coding
172
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y': if the ith character is 'Y', it means that customers come at the ith hour whereas ...
{"functional": "def check(candidate):\n assert candidate(customers = \"YYNY\") == 2\n assert candidate(customers = \"NNNNN\") == 0\n assert candidate(customers = \"YYYY\") == 4\n\n\ncheck(Solution().bestClosingTime)"}
coding
213
Solve the programming task below in a Python markdown code block. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, th...
{"inputs": ["1\n", "a\n", ".\n", ";\n", ";\n", ".\n", "0\n", "b\n"], "outputs": ["\"1\"\n-\n", "-\n\"a\"\n", "-\n\".\"\n", "-\n\",\"\n", "-\n\",\"\n", "-\n\".\"\n", "\"0\"\n-\n", "-\n\"b\"\n"]}
coding
475
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise. A query word queries[i] matches pattern if you can inse...
{"functional": "def check(candidate):\n assert candidate(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FB\") == [True,False,True,True,False]\n assert candidate(queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FoBa...
coding
126
Solve the programming task below in a Python markdown code block. A permutation of size $n$ is an array of size $n$ such that each integer from $1$ to $n$ occurs exactly once in this array. An inversion in a permutation $p$ is a pair of indices $(i, j)$ such that $i > j$ and $a_i < a_j$. For example, a permutation $[4,...
{"inputs": ["1\n1\n", "1\n1\n", "1\n-1\n", "1\n-1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n-1 2\n"], "outputs": ["0\n", " 0", "0\n", " 0", "0\n", "1\n", " ...
coding
688
Solve the programming task below in a Python markdown code block. Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won $x$ rounds in a row. For example, if Bob won five rounds ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n?\n", "1\n0\n", "1\n1\n", "1\n?\n", "5\n01?01\n", "5\n10?10\n"], "outputs": ["1 \n", "1 \n", "1 \n", "1\n", "1\n", "1\n", "5 1 0 0 0 \n", "5 1 0 0 0\n"]}
coding
597
Solve the programming task below in a Python markdown code block. You are given a string s of length n consisting of lowercase English letters. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths a...
{"inputs": ["4 1\nabac\n1 2 3\n", "4 1\nabac\n1 2 3\n", "1 2\nz\n1 1 1\n1 1 1\n", "1 2\nz\n1 1 1\n1 1 1\n", "7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3\n", "7 4\nabacaba\n1 1 1\n2 4 2\n2 1 3\n2 4 3\n", "7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3\n", "24 1\nccacbbabcacabababaacaacc\n1 13 12\n"], "outputs": ["NO\n", "NO\n", ...
coding
670
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal. For example, if nums = [6,1,7,4,1]: Choosi...
{"functional": "def check(candidate):\n assert candidate(nums = [2,1,6,4]) == 1\n assert candidate(nums = [1,1,1]) == 3\n assert candidate(nums = [1,2,3]) == 0\n\n\ncheck(Solution().waysToMakeFair)"}
coding
205
Solve the programming task below in a Python markdown code block. Chef has planned that he will drink exactly X liters of tea daily. He has an empty jar having a capacity of Y liters. Chef can visit the tea shop to refill the jar. In each refill, the jar is completely filled to the brim and Chef is charged Z rupees. ...
{"inputs": ["4\n3 3 3\n6 3 3\n5 7 2\n9 4 5\n"], "outputs": ["3\n6\n2\n15\n"]}
coding
485
Solve the programming task below in a Python markdown code block. An array $b$ of length $k$ is called good if its arithmetic mean is equal to $1$. More formally, if $$\frac{b_1 + \cdots + b_k}{k}=1.$$ Note that the value $\frac{b_1+\cdots+b_k}{k}$ is not rounded up or down. For example, the array $[1,1,1,2]$ has an a...
{"inputs": ["1\n1\n1\n", "4\n3\n1 1 1\n2\n1 2\n4\n8 4 6 2\n1\n-2\n"], "outputs": ["0\n", "0\n1\n16\n1\n"]}
coding
557
Solve the programming task below in a Python markdown code block. Clock shows 'h' hours, 'm' minutes and 's' seconds after midnight. Your task is to make 'Past' function which returns time converted to milliseconds. ## Example: ```python past(0, 1, 1) == 61000 ``` Input constraints: `0 <= h <= 23`, `0 <= m <= 59`, ...
{"functional": "_inputs = [[0, 1, 1], [1, 1, 1], [0, 0, 0], [1, 0, 1], [1, 0, 0]]\n_outputs = [[61000], [3661000], [0], [3601000], [3600000]]\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(...
coding
128
Solve the programming task below in a Python markdown code block. Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release ye...
{"inputs": ["8\n1 6 5 4 3 2 7 8"], "outputs": ["2 6"]}
coding
483
Solve the programming task below in a Python markdown code block. A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of $a \oplus b$ for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value amo...
{"inputs": ["1 2\n", "1 1\n", "1 1\n", "1 3\n", "1 3\n", "1 2\n", "1 1\n", "8 16\n"], "outputs": ["3\n", "0\n", "0\n", "3\n", "3\n", "3\n", "0\n", "31\n"]}
coding
276
Solve the programming task below in a Python markdown code block. ```if:python,php In this kata you will have to write a function that takes `litres` and `price_per_litre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre,...
{"functional": "_inputs = [[10, 21.5], [40, 10], [15, 5.83]]\n_outputs = [[212.5], [390], [83.7]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len...
coding
315
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 costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules: ...
{"functional": "def check(candidate):\n assert candidate(costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4) == 11\n assert candidate(costs = [1,2,4,1], k = 3, candidates = 3) == 4\n\n\ncheck(Solution().totalCost)"}
coding
308
Solve the programming task below in a Python markdown code block. Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$...
{"inputs": ["1\n4\n", "1\n4\n", "1\n7\n", "1\n9\n", "1\n2\n", "1\n1\n", "1\n8\n", "1\n6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
665
Solve the programming task below in a Python markdown code block. We want to find the numbers higher or equal than 1000 that the sum of every four consecutives digits cannot be higher than a certain given value. If the number is ``` num = d1d2d3d4d5d6 ```, and the maximum sum of 4 contiguous digits is ```maxSum```, the...
{"functional": "_inputs = [[2000, 3], [2000, 4], [2000, 7], [3000, 7], [4000, 4], [5000, 2], [5000, 3], [5000, 4], [5000, 5], [5000, 6], [5000, 7], [5000, 8], [5000, 9]]\n_outputs = [[[11, 1110, 12555]], [[21, 1120, 23665]], [[85, 1200, 99986]], [[141, 1600, 220756]], [[35, 2000, 58331]], [[5, 1100, 6111]], [[15, 1200,...
coding
754
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. Return the array in the form [x1,y1,x2,y2,...,xn,yn].   Please complete the following python code precisely: ```python class Solu...
{"functional": "def check(candidate):\n assert candidate(nums = [2,5,1,3,4,7], n = 3) == [2,3,5,4,1,7] \n assert candidate(nums = [1,2,3,4,4,3,2,1], n = 4) == [1,4,2,3,3,2,4,1]\n assert candidate(nums = [1,1,2,2], n = 2) == [1,2,1,2]\n\n\ncheck(Solution().shuffle)"}
coding
102
Solve the programming task below in a Python markdown code block. Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer n is decided first. Both Koyomi and...
{"inputs": ["1\n2\n3\n", "1\n1\n3\n", "1\n6\n7\n", "1\n1\n3\n", "1\n2\n3\n", "1\n6\n7\n", "1\n1\n4\n", "1\n8\n7\n"], "outputs": ["Karen\n", "Karen\n", "Karen\n", "Karen\n", "Karen\n", "Karen\n", "Karen\n", "Karen\n"]}
coding
619
Solve the programming task below in a Python markdown code block. B: Ebi-chan and Integer Sequences- problem Ebi-chan likes sequences. I especially like arithmetic progressions. This time, I decided to create a sequence that meets the following conditions. * Arithmetic progression of length n * When the i-th element...
{"inputs": ["3 0", "3 4", "3 1", "6 4", "2 4", "2 3", "2 5", "1 2"], "outputs": ["1\n", "13\n", "2\n", "5\n", "25\n", "16\n", "36\n", "3\n"]}
coding
322
Solve the programming task below in a Python markdown code block. One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if ...
{"inputs": ["4\n2 2 3 2\n", "4\n2 2 4 2\n", "4\n1 2 3 2\n", "5\n6 7 6 7 6\n", "5\n6 11 6 7 6\n", "5\n6 11 6 6 6\n", "5\n6 11 5 6 6\n", "6\n1 2 3 4 5 6\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
297
Solve the programming task below in a Python markdown code block. Chef and Chefina are at positions X and Y on a number line. They both love badminton. It is known that badminton courts are located at every integer point. They want to find a court such that the *maximum* distance travelled by either of them is minim...
{"inputs": ["4\n3 5\n7 6\n1 10\n63 31\n"], "outputs": ["1\n1\n5\n16\n"]}
coding
352
Solve the programming task below in a Python markdown code block. Pushkar is very good in Number Theory. He takes two numbers $A\ and\ B$ and declares them a Pushkar Pair. Pushkar Pair has a property that $A$ has a $Modular\ Inverse$ modulo $B$. He asks you to tell him the largest number $L$ that divides both of them...
{"inputs": ["1\n3 4"], "outputs": ["1"]}
coding
199
Solve the programming task below in a Python markdown code block. There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs...
{"inputs": ["1 2\n1\n", "1 2\n2\n", "3 2\n5 2 7", "3 2\n4 1 7", "3 2\n4 2 7", "3 2\n5 2 6", "3 1\n5 2 6", "3 2\n4 1 5"], "outputs": ["0\n", "1\n", "2\n", "3\n", "3\n", "3\n", "6\n", "3"]}
coding
375
Solve the programming task below in a Python markdown code block. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a i...
{"inputs": ["11\n", "111\n", "110\n", "100\n", "101\n", "1111\n", "1011\n", "1001\n"], "outputs": ["1\n", "11\n", "11", "10", "11\n", "111\n", "111", "101"]}
coding
297
Solve the programming task below in a Python markdown code block. The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese. When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Spe...
{"inputs": ["4", "6", "9", "8", "5", "0", "1", "7"], "outputs": ["hon\n", "pon\n", "hon\n", "pon\n", "hon\n", "pon\n", "pon\n", "hon\n"]}
coding
270
Solve the programming task below in a Python markdown code block. Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If...
{"inputs": [">><", "><>", "<<>", "<>>", "<>>><<<<<><<>>><", "<>>>><<<<><<<>><", "<>><<<><<<<>>>><", "<<>><<><<<<>>>><"], "outputs": ["4\n", "2\n", "3\n", "3", "29\n", "28\n", "26\n", "24\n"]}
coding
231
Solve the programming task below in a Python markdown code block. π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρος (perime...
{"inputs": ["0.15\n0.05\n0.0", "1.052205526162189\n0.05\n0.0", "0.15\n0.892857233308306\n0.0", "0.15\n0.897940711549928\n0.0", "1.0557371636651482\n0.05\n0.0", "0.4926473169582818\n0.05\n0.0", "0.5656950408067312\n0.05\n0.0", "1.0653255099845902\n0.05\n0.0"], "outputs": ["3/1\n19/6", "3/1\n19/6\n", "3/1\n3/1\n", "3/1\n...
coding
488
Solve the programming task below in a Python markdown code block. in Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$ (the sam...
{"inputs": ["2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4"], "outputs": ["12\n0"]}
coding
581
Solve the programming task below in a Python markdown code block. Given an array of integers, find the sum of its elements. For example, if the array $ar=[1,2,3]$, $1+2+3=6$, so return $6$. Function Description Complete the simpleArraySum function in the editor below. It must return the sum of the array elements ...
{"inputs": ["6\n1 2 3 4 10 11\n"], "outputs": ["31\n"]}
coding
231
Solve the programming task below in a Python markdown code block. You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You need to permute the array elements so that value $\sum_{i = 1}^{n - k}|A [ i ] - A [ i + k ]|$ became minimal possible. In particular,...
{"inputs": ["3 2\n1 2 4\n", "2 1\n1 100\n", "2 1\n1 100\n", "3 2\n1 2 4\n", "4 3\n1 2 4 8\n", "4 3\n1 2 4 8\n", "4 1\n1 2 4 8\n", "5 3\n1 2 6 0 2\n"], "outputs": ["1\n", "99\n", "99\n", "1\n", "1\n", "1\n", "7\n", "1\n"]}
coding
317
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, transform string s into string t using the following operation any number of times: Choose a non-empty substring in s and sort it in place so the characters are in ascending order. For e...
{"functional": "def check(candidate):\n assert candidate(s = \"84532\", t = \"34852\") == True\n assert candidate(s = \"34521\", t = \"23415\") == True\n assert candidate(s = \"12345\", t = \"12435\") == False\n assert candidate(s = \"1\", t = \"2\") == False\n\n\ncheck(Solution().isTransformable)"}
coding
152
Solve the programming task below in a Python markdown code block. Help Johnny! He can't make his code work! Easy Code Johnny is trying to make a function that adds the sum of two encoded strings, but he can't find the error in his code! Help him! Also feel free to reuse/extend the following starter code: ```python def ...
{"functional": "_inputs = [['a', 'b']]\n_outputs = [[195]]\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 return all(_...
coding
81
Solve the programming task below in a Python markdown code block. Four-digit palindromes start with `[1001,1111,1221,1331,1441,1551,1551,...]` and the number at position `2` is `1111`. You will be given two numbers `a` and `b`. Your task is to return the `a-digit` palindrome at position `b` if the palindromes were a...
{"functional": "_inputs = [[2, 2], [3, 10], [4, 5], [5, 19], [6, 3], [6, 20], [7, 3]]\n_outputs = [[22], [191], [1441], [11811], [102201], [119911], [1002001]]\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...
coding
267
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses hav...
{"functional": "def check(candidate):\n assert candidate(costs = [[1,5,3],[2,9,4]]) == 5\n assert candidate(costs = [[1,3],[2,4]]) == 5\n\n\ncheck(Solution().minCostII)"}
coding
176
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules: The cost of painting a digit (i + 1) is given by cost[i] (0-indexed). The total cost used mus...
{"functional": "def check(candidate):\n assert candidate(cost = [4,3,2,5,6,7,2,5,5], target = 9) == \"7772\"\n assert candidate(cost = [7,6,5,5,5,6,8,7,8], target = 12) == \"85\"\n assert candidate(cost = [2,4,6,2,4,6,4,4,4], target = 5) == \"0\"\n assert candidate(cost = [6,10,15,40,40,40,40,40,40], target...
coding
148
Solve the programming task below in a Python markdown code block. James found a love letter that his friend Harry has written to his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes. To do this, he follows two rules: He can only re...
{"inputs": ["4\nabc\nabcba\nabcd\ncba\n"], "outputs": ["2\n0\n4\n2\n"]}
coding
418
Solve the programming task below in a Python markdown code block. Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each othe...
{"inputs": ["1\na\na\n", "1\na\na\n", "1\na\n`\n", "1\n`\n`\n", "1\n_\n`\n", "1\n_\na\n", "1\n_\n_\n", "1\n`\n_\n"], "outputs": ["no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]}
coding
530
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surro...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]) == 16\n assert candidate(grid = [[1]]) == 4\n assert candidate(grid = [[1,0]]) == 4\n\n\ncheck(Solution().islandPerimeter)"}
coding
179
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fi...
{"functional": "def check(candidate):\n assert candidate(image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2) == [[2,2,2],[2,2,0],[2,0,1]]\n assert candidate(image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0) == [[0,0,0],[0,0,0]]\n\n\ncheck(Solution().floodFill)"}
coding
237
Solve the programming task below in a Python markdown code block. You are given a decimal representation of an integer $x$ without leading zeros. You have to perform the following reduction on it exactly once: take two neighboring digits in $x$ and replace them with their sum without leading zeros (if the sum is $0$, ...
{"inputs": ["2\n10057\n90\n"], "outputs": ["10012\n9\n"]}
coding
446
Solve the programming task below in a Python markdown code block. After learning a lot about space exploration, a little girl named Ana wants to change the subject. Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's ...
{"inputs": ["3\naa\nbb\ncd\n", "3\naa\nbc\ncd\n", "3\naa\ncc\ncd\n", "3\naa\ncc\ndd\n", "3\naa\ncd\ndd\n", "3\naa\nbb\ncd\n", "6\naab\nabcac\ndffe\ned\naa\naade\n", "6\naab\nabcbc\ndffe\ned\naa\nabde\n"], "outputs": ["1\n", "0\n", "1\n", "3\n", "1\n", "1\n", "6\n", "3\n"]}
coding
547
Solve the programming task below in a Python markdown code block. Given an integer `n`, find two integers `a` and `b` such that: ```Pearl A) a >= 0 and b >= 0 B) a + b = n C) DigitSum(a) + Digitsum(b) is maximum of all possibilities. ``` You will return the digitSum(a) + digitsum(b). ``` For example: solve(29) = 11...
{"functional": "_inputs = [[18], [29], [45], [1140], [7019], [50000000], [15569047737], [2452148459], [1], [0]]\n_outputs = [[18], [11], [18], [33], [35], [68], [144], [116], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, re...
coding
191
Solve the programming task below in a Python markdown code block. Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'. There is a single robot in the maze. Its start position is denoted with the character '...
{"inputs": ["2 2\n..\nSE\n0\n", "2 2\nSE\n##\n0\n", "2 2\nSE\n##\n0\n", "2 2\n..\nSE\n0\n", "2 2\n#E\nS.\n2\n", "2 2\n./\nSE\n0\n", "2 2\nS.\n/E\n1\n", "2 2\nS.\nE/\n1\n"], "outputs": ["6\n", "6\n", "6\n", "6\n", "0\n", "6\n", "0\n", "6\n"]}
coding
611
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.   Please complete the following python code precisely: ```python class Solutio...
{"functional": "def check(candidate):\n assert candidate(s = \"Let's take LeetCode contest\") == \"s'teL ekat edoCteeL tsetnoc\"\n assert candidate( s = \"Mr Ding\") == \"rM gniD\"\n\n\ncheck(Solution().reverseWords)"}
coding
72
Please solve the programming task below using a self-contained code snippet in a markdown code block. A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are valid IP addr...
{"functional": "def check(candidate):\n assert candidate(s = \"25525511135\") == [\"255.255.11.135\",\"255.255.111.35\"]\n assert candidate(s = \"0000\") == [\"0.0.0.0\"]\n assert candidate(s = \"101023\") == [\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]\n\n\ncheck(Solution().restoreI...
coding
214
Solve the programming task below in a Python markdown code block. Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time ...
{"inputs": ["3\nappme\norange\napple\n1\ngrape", "3\nappme\norange\napple\n0\ngrape", "3\nappme\nprange\napple\n0\ngrape", "3\nappme\nprange\napple\n0\ngrepa", "3\nappme\nprangd\napple\n0\ngrepa", "3\nappme\nprangd\napple\n0\ngreqa", "3\nappme\nprangd\napple\n0\naqerg", "3\nappme\ndgnarp\napple\n0\naqerg"], "outputs": ...
coding
391
Solve the programming task below in a Python markdown code block. Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way ot...
{"inputs": ["9 3\n8 3\n4 4\n2 1", "9 3\n8 3\n4 4\n4 1", "9 3\n2 3\n4 4\n1 1", "9 3\n8 3\n4 2\n2 1", "9 3\n8 3\n4 2\n2 1\n", "10000 1\n1 10000\n", "9999 2\n2 9999\n2 10000\n", "10000 2\n1 9999\n1 10000\n"], "outputs": ["4\n", "3\n", "9\n", "4", "4\n", "100000000\n", "49995000\n", "99990000\n"]}
coding
350
Solve the programming task below in a Python markdown code block. In Japan, people make offerings called hina arare, colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contain...
{"inputs": ["6\nG W Y Q Y W", "6\nG X X O X X", "6\nF W Y P Y W", "6\nF W Y O Y W", "6\nG W Y O Y W", "6\nE W Y O Y W", "6\nF W Y Q Y W", "6\nE W Y P Y W"], "outputs": ["Four\n", "Three\n", "Four\n", "Four\n", "Four\n", "Four\n", "Four\n", "Four\n"]}
coding
315
Solve the programming task below in a Python markdown code block. Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. Please note that you should find all ...
{"inputs": ["4\n1 0\n2 2\n0 2\n0 1", "4\n1 0\n3 2\n0 2\n0 1", "4\n1 0\n2 2\n1 2\n0 1", "4\n1 1\n3 2\n0 2\n0 1", "4\n2 0\n2 2\n1 2\n0 1", "4\n1 1\n3 0\n0 2\n0 1", "4\n1 1\n3 1\n0 2\n0 1", "4\n2 1\n3 1\n0 2\n0 1"], "outputs": ["4\n1 0\n2 2\n0 2\n0 1\n", "4\n1 0\n3 2\n0 2\n0 1\n", "4\n1 0\n2 2\n1 2\n0 1\n", "4\n0 1\n1 1\n...
coding
351
Solve the programming task below in a Python markdown code block. Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other wo...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n28\n", "1\n-1\n", "1\n-2\n", "3\n1 2 3\n", "3\n3 2 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "2\n", "2\n"]}
coding
189
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two string arrays creators and ids, and an integer array views, all of length n. The ith video on a platform was created by creators[i], has an id of ids[i], and has views[i] views. The popularity of a c...
{"functional": "def check(candidate):\n assert candidate(creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4]) == [[\"alice\",\"one\"],[\"bob\",\"two\"]]\n assert candidate(creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = ...
coding
271
Solve the programming task below in a Python markdown code block. In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of ...
{"inputs": ["9", "30", "22", "41", "91", "36", "36\n", "91\n"], "outputs": ["2\n", "3\n", "4\n", "5\n", "3", "8", "8\n", "3\n"]}
coding
347
Solve the programming task below in a Python markdown code block. Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by s...
{"inputs": ["1 2 3 3\nw\n", "1 2 3 3\nw\n", "1 3 3 3\nw\n", "1 0 3 3\nw\n", "1 4 3 3\nw\n", "1 2 5 3\nw\n", "4 2 3 10\nwwhw\n", "4 2 1 10\nwwhw\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "2\n", "3\n"]}
coding
602
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 got interested in bits and wanted to learn about them, so his friend Pintu gave him a special function $F(X,Y,Z) = (X \wedge Z) \cdot (Y \wedge ...
{"inputs": ["2\n7 12 4 17\n7 12 0 8"], "outputs": ["15\n7"]}
coding
675
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col]. The rank is an integer that represents how large an element is compared to other elements. It is calculated usi...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,2],[3,4]]) == [[1,2],[2,3]]\n assert candidate(matrix = [[7,7],[7,7]]) == [[1,1],[1,1]]\n assert candidate(matrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]) == [[4,2,3],[1,3,4],[5,1,6],[1,3,4]]\n assert candidate(matrix = [[7,3,6]...
coding
191