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. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef's son Chefu found some matches in the kitchen and he immediately starting playing with them. The first thing Chefu wanted to do was to calculate the re...
{"inputs": ["3\n123 234\n10101 1010\n4 4"], "outputs": ["13\n10\n7"]}
coding
386
Solve the programming task below in a Python markdown code block. Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal line...
{"inputs": ["4 3 1", "1 2 2", "1 5 1", "4 6 1", "1 9 1", "8 6 1", "1 9 2", "9 6 1"], "outputs": ["35\n", "1\n", "5\n", "12371\n", "34\n", "276953291\n", "21\n", "437876582\n"]}
coding
371
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features ...
{"functional": "def check(candidate):\n assert candidate(features = [\"cooler\",\"lock\",\"touch\"], responses = [\"i like cooler cooler\",\"lock touch cool\",\"locker like touch\"]) == [\"touch\",\"cooler\",\"lock\"]\n assert candidate(features = [\"a\",\"aa\",\"b\",\"c\"], responses = [\"a\",\"a aa\",\"a a a a ...
coding
198
Solve the programming task below in a Python markdown code block. Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount o...
{"inputs": ["7\n2\n3\n", "1\n7\n8\n", "4\n2\n2\n", "4\n1\n3\n", "4\n1\n2\n", "4\n3\n1\n", "4\n2\n1\n", "1\n1\n1\n"], "outputs": ["YES\n2 1\n", "NO\n", "YES\n0 2\n", "YES\n1 1\n", "YES\n0 2\n", "YES\n0 4\n", "YES\n0 4\n", "YES\n0 1\n"]}
coding
558
Solve the programming task below in a Python markdown code block. There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? --...
{"inputs": ["2", "0", "9", "4", "5", "8", "3", "1"], "outputs": ["3\n", "0\n", "45\n", "10\n", "15\n", "36\n", "6", "1"]}
coding
140
Solve the programming task below in a Python markdown code block. Mainak has an array $a_1, a_2, \ldots, a_n$ of $n$ positive integers. He will do the following operation to this array exactly once: Pick a subsegment of this array and cyclically rotate it by any amount. Formally, he can do the following exactly once:...
{"inputs": ["1\n2\n1 10\n", "1\n3\n3 2 1\n", "1\n3\n7 3 1\n", "1\n4\n8 2 2 1\n", "1\n3\n100 3 1\n", "1\n3\n999 2 1\n", "1\n3\n999 3 1\n", "1\n3\n999 100 1\n"], "outputs": ["9\n", "1\n", "4\n", "6\n", "97\n", "997\n", "996\n", "899\n"]}
coding
668
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$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and ...
{"inputs": ["2\n5 4 1\n1 5 4 3 2\n5 4 1\n1 5 4 3 2\n", "2\n5 4 1\n1 5 4 3 2\n5 4 1\n1 5 4 3 2\n", "2\n5 4 1\n1 5 2 3 2\n5 4 1\n1 5 4 3 2\n", "2\n5 4 1\n1 5 2 3 2\n5 1 1\n1 5 4 3 2\n", "2\n5 4 1\n1 5 4 3 2\n5 4 1\n1 5 4 6 2\n", "2\n5 4 1\n1 5 4 3 2\n5 4 1\n1 5 7 6 2\n", "2\n5 4 1\n2 5 2 3 2\n5 1 0\n1 5 4 0 2\n", "2\n5 4...
coding
725
Solve the programming task below in a Python markdown code block. The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. ...
{"inputs": ["3\nab\nb\ndef\n", "3\nab\na\ndef\n", "3\nab\na\ndeg\n", "3\nba\na\ndeg\n", "3\nba\na\ndef\n", "3\nab\nc\ndef\n", "3\nac\nabc\nca\n", "3\nab\nacb\nba\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "5\n", "5\n"]}
coding
673
Solve the programming task below in a Python markdown code block. You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words. -----Constraints----- - s_1, s_2 and s_3 are composed of lowercas...
{"inputs": ["k nearest robhgien", "k tseraen robhgien", "l tseraeo robhgien", "l oearest robghien", "l oearest neihgbor", "l pearest neihgbor", "m pearest neihgbor", "m tseraep neihgbor"], "outputs": ["KNR\n", "KTR\n", "LTR\n", "LOR\n", "LON\n", "LPN\n", "MPN\n", "MTN\n"]}
coding
171
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1. You are also given a 2D integer array edges where edges[i] = [fromi, toi, weighti] denotes ...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5) == 9\n assert candidate(n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2) == -1\n\n\ncheck(Solution().minimumWeight)"}
coding
248
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Eidi gifts are a tradition in which children receive money from elder relatives during the Eid celebration. Chef has three children (numbered $1, 2,...
{"inputs": ["5\n5 7 10 10 20 50\n5 5 5 20 10 20\n10 1 17 5 10 15\n3 6 3 8 10 9\n8 5 5 50 10 10"], "outputs": ["FAIR\nNOT FAIR\nNOT FAIR\nNOT FAIR\nFAIR"]}
coding
576
Solve the programming task below in a Python markdown code block. In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied. In this kata we want to find all intege...
{"functional": "_inputs = [[5], [12], [13], [16], [17], [20], [9001], [9004], [9005], [9008], [90001], [90002], [90004], [90005], [90009], [900001], [900004], [900005], [9000001], [9000004], [90000001], [90000004], [900000012], [9000000041]]\n_outputs = [[[[3, 1]]], [[[4, 1]]], [[[7, 3]]], [[[4, 0]]], [[[9, 4]]], [[[6,...
coding
312
Solve the programming task below in a Python markdown code block. Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with $6$ places after the decimal. Note: This challenge introduces precision problems. The te...
{"inputs": ["6 \n-4 3 -9 0 4 1\n"], "outputs": ["0.500000\n0.333333\n0.166667\n"]}
coding
556
Solve the programming task below in a Python markdown code block. In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively. Two antennas can communicate directly if the distance between the...
{"inputs": ["1\n0\n7\n1\n5\n3", "1\n0\n7\n0\n5\n3", "1\n0\n9\n0\n5\n3", "1\n0\n5\n8\n4\n1", "1\n0\n7\n2\n5\n3", "1\n1\n9\n0\n5\n3", "1\n0\n5\n8\n4\n0", "1\n0\n2\n8\n4\n1"], "outputs": [":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n"]}
coding
451
Solve the programming task below in a Python markdown code block. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists ...
{"inputs": ["1\n.\n", "1\n.\n", "1\n/\n", "1\n0\n", "1\n-\n", "1\n,\n", "1\n+\n", "1\n*\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
404
Solve the programming task below in a Python markdown code block. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tel...
{"inputs": ["1\n*\n1\na\n", "1\n*\n1\nz\n", "1\n*\n1\na\n", "1\n*\n1\nz\n", "1\n*\n1\ny\n", "1\n*\n1\nb\n", "1\n*\n2\na\nz\n", "2\n**\n1\naa\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n"]}
coding
717
Solve the programming task below in a Python markdown code block. Chef Ada is building a new restaurant in the following way: - First, $N$ points $X_1, X_2, \ldots, X_N$ are chosen on the $x$-axis. - Then, $N$ columns (numbered $1$ through $N$) are made. For simplicity, the columns are represented as vertical segments;...
{"inputs": ["1\n5\n1 1\n2 2\n3 3\n4 4\n5 5"], "outputs": ["27"]}
coding
614
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except the identifier) consist of lowercase ...
{"functional": "def check(candidate):\n assert candidate(logs = [\"dig1 8 1 5 1\",\"let1 art can\",\"dig2 3 6\",\"let2 own kit dig\",\"let3 art zero\"]) == [\"let1 art can\",\"let3 art zero\",\"let2 own kit dig\",\"dig1 8 1 5 1\",\"dig2 3 6\"]\n assert candidate(logs = [\"a1 9 2 3 1\",\"g1 act car\",\"zo4 4 7\",\...
coding
181
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. You are given a positive integer N. You have to print exactly N + 1 positive integers satisfying the following conditions: Exactly one value should appear twice, all the remai...
{"inputs": ["2\n3\n4\n"], "outputs": ["1 2 2 3\n1 2 3 3 7"]}
coding
371
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums consisting of 3 * n elements. You are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,2]) == -1\n assert candidate(nums = [7,9,5,8,1,3]) == 1\n\n\ncheck(Solution().minimumDifference)"}
coding
211
Solve the programming task below in a Python markdown code block. # Letterss of Natac In a game I just made up that doesn’t have anything to do with any other game that you may or may not have played, you collect resources on each turn and then use those resources to build settlements, roads, and cities or buy a develo...
{"functional": "_inputs = [['bwoo'], [''], ['ogogoogogo'], ['bwbwwwbb']]\n_outputs = [[['road']], [[]], [['city']], [['road']]]\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, tupl...
coding
505
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. The array nums is beautiful if: nums.length is even. nums[i] != nums[i + 1] for all i % 2 == 0. Note that an empty array is considered beautiful. You can delete any numb...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,3,5]) == 1\n assert candidate(nums = [1,1,2,2,3,3]) == 2\n\n\ncheck(Solution().minDeletion)"}
coding
171
Solve the programming task below in a Python markdown code block. There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order. Constraints 0 ≤ height of mountain (integer) ≤ 10,000 Input Hei...
{"inputs": ["100\n0\n0\n3561\n000\n98\n9\n15\n1\n297", "100\n-3\n-4\n629\n010\n48\n2\n1\n4\n112", "100\n-4\n-2\n629\n110\n71\n1\n1\n3\n112", "100\n-8\n0\n651\n010\n104\n1\n1\n3\n112", "100\n-8\n0\n552\n011\n104\n1\n1\n3\n112", "100\n-8\n0\n901\n011\n104\n1\n1\n3\n112", "100\n-8\n0\n901\n011\n193\n1\n1\n3\n112", "100\n-...
coding
248
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such ...
{"functional": "def check(candidate):\n assert candidate(n = 8) == 6\n assert candidate(n = 1) == 1\n assert candidate(n = 4) == -1\n\n\ncheck(Solution().pivotInteger)"}
coding
119
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb. The bombs are represented by a...
{"functional": "def check(candidate):\n assert candidate(bombs = [[2,1,3],[6,1,4]]) == 2\n assert candidate(bombs = [[1,1,5],[10,10,5]]) == 1\n assert candidate(bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]) == 5\n\n\ncheck(Solution().maximumDetonation)"}
coding
220
Solve the programming task below in a Python markdown code block. Bob needs a fast way to calculate the volume of a cuboid with three values: `length`, `width` and the `height` of the cuboid. Write a function to help Bob with this calculation. ```if:shell In bash the script is ran with the following 3 arguments: `leng...
{"functional": "_inputs = [[2, 5, 6], [6.3, 3, 5]]\n_outputs = [[60], [94.5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
114
Solve the programming task below in a Python markdown code block. You are given a string $S$ and an integer $L$. A operation is described as :- "You are allowed to pick any substring from first $L$ charcaters of $S$, and place it at the end of the string $S$. A string $A$ is a substring of an string $B$ if $A$ can be ...
{"inputs": ["2\n1 rga\n2 cab"], "outputs": ["arg\nabc"]}
coding
358
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of size n containing each element from 0 to n - 1 (inclusive). Each of the elements from 1 to n - 1 represents an item, and the element 0 represents an empty space. In one operation...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,0,3,1]) == 3\n assert candidate(nums = [1,2,3,4,0]) == 0\n assert candidate(nums = [1,0,2,4,3]) == 2\n\n\ncheck(Solution().sortArray)"}
coding
204
Solve the programming task below in a Python markdown code block. Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to increase creativity by drawing pictures. Let's draw a pattern well using a square stamp. I want t...
{"inputs": ["1\n2 3\nRRGG\nGGRB\nBRRR\nBRRR", "1\n2 1\nRRGG\nGGRB\nBRRR\nBRRR", "1\n2 1\nGGRR\nGGRB\nBRRR\nBRRR", "1\n1 1\nGGRR\nGGRB\nBRRR\nBRRR", "1\n2 3\nRRGG\nGGRB\nBRRR\nRRBR", "1\n2 1\nRRGG\nGGRB\nRRRB\nBRRR", "1\n2 4\nRRGG\nGGRB\nBRRR\nRRRB", "1\n4 1\nGRGR\nGGRB\nRRRB\nBRRR"], "outputs": ["6\n", "12\n", "9\n", "...
coding
551
Solve the programming task below in a Python markdown code block. There are N+1 towns. The i-th town is being attacked by A_i monsters. We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters. What is the maximum total number of monsters the heroes ca...
{"inputs": ["1\n1 1\n1\n", "2\n3 5 2\n7 5", "2\n3 5 1\n7 5", "2\n3 5 1\n0 5", "2\n2 5 1\n0 5", "2\n2 9 1\n0 5", "2\n2 9 1\n0 2", "2\n2 1 1\n0 2"], "outputs": ["1\n", "10\n", "9\n", "5\n", "5\n", "5\n", "2\n", "2\n"]}
coding
282
Solve the programming task below in a Python markdown code block. A binary string S of length N is called *K-balanced string* if it holds the following property: For each index i\;(1 ≤ i ≤ N) such that S_{i} = '1', there must exist an index j\;(1 ≤ j ≤ N) such that S_{j} = '1' and \mid i - j \mid = K, where \mid x \...
{"inputs": ["4\n2 1\n01\n3 1\n111\n4 2\n1101\n5 3\n11110\n\n"], "outputs": ["1\n0\n1\n2\n"]}
coding
653
Solve the programming task below in a Python markdown code block. ABC Gene There is a gene sequence represented by the string `ABC`. You can rewrite this gene sequence by performing the following operations several times. * Choose one of the letters `A`,` B`, `C`. Let this be x. Replace all x in the gene sequence wit...
{"inputs": ["BAC", "ACB", "CAB", "CBA", "ACA", "BCA", "BAB", "ABA"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
331
Solve the programming task below in a Python markdown code block. A sequence $a_1, a_2, \dots, a_k$ is called an arithmetic progression if for each $i$ from $1$ to $k$ elements satisfy the condition $a_i = a_1 + c \cdot (i - 1)$ for some fixed $c$. For example, these five sequences are arithmetic progressions: $[5, 7,...
{"inputs": ["2\n3 4\n", "2\n3 4\n", "2\n3 3\n", "2\n2 3\n", "3\n1 2 7\n", "3\n1 2 7\n", "3\n1 2 11\n", "3\n2 2 11\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
coding
612
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array. Return the maximum number of operations you can perfor...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], k = 5) == 2\n assert candidate(nums = [3,1,3,4,3], k = 6) == 1\n\n\ncheck(Solution().maxOperations)"}
coding
100
Solve the programming task below in a Python markdown code block. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on p...
{"inputs": ["1\na\n", "1\nk\n", "1\nH\n", "1\nk\n", "1\na\n", "1\nH\n", "1\nj\n", "1\nb\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
coding
376
Solve the programming task below in a Python markdown code block. Beppa and her circle of geek friends keep up to date on a group chat in the instant messaging app SwerChat$^{\text{TM}}$. The group has $n$ members, excluding Beppa. Each of those members has a unique ID between $1$ and $n$. When a user opens a group ch...
{"inputs": ["4\n5\n1 4 2 5 3\n4 5 1 2 3\n6\n1 2 3 4 5 6\n1 2 3 4 5 6\n8\n8 2 4 7 1 6 5 3\n5 6 1 4 8 2 7 3\n1\n1\n1\n"], "outputs": ["2\n0\n4\n0\n"]}
coding
762
Solve the programming task below in a Python markdown code block. ## Welcome to my (amazing) kata! You are given a gigantic number to decode. Each number is a code that alternates in a pattern between encoded text and a smaller, encoded number. The pattern's length varies with every test, but the alternation between...
{"functional": "_inputs = [[103115104105123101118119981001098], [103115104105123101118119981001098103115104105123101118119981001098103115104105123101118119981001098], [10910111611511211510710912610510611511810811512311912012111610910412010810911911110112010110911998100109810512210511412010811512110710810912011910211810...
coding
513
Solve the programming task below in a Python markdown code block. You have a digit sequence S of length 4. You are wondering which of the following formats S is in: - YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order - MMYY...
{"inputs": ["3367", "2206", "1291", "1211", "2352", "2340", "2265", "2454"], "outputs": ["NA\n", "YYMM\n", "MMYY\n", "AMBIGUOUS\n", "NA\n", "NA\n", "NA\n", "NA\n"]}
coding
248
Please solve the programming task below using a self-contained code snippet in a markdown code block. A permutation perm of n integers of all the integers in the range [1, n] can be represented as a string s of length n - 1 where: s[i] == 'I' if perm[i] < perm[i + 1], and s[i] == 'D' if perm[i] > perm[i + 1]. Given ...
{"functional": "def check(candidate):\n assert candidate(s = \"I\") == [1,2]\n assert candidate(s = \"DI\") == [2,1,3]\n\n\ncheck(Solution().findPermutation)"}
coding
139
Solve the programming task below in a Python markdown code block. A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and...
{"functional": "_inputs = [['ACM'], ['MID CENTRAL'], ['BBC'], ['???'], ['axg '], ['234 234 WEF ASDF AAA 554211 ???? '], ['A C M'], ['ABCDEFGHIJKLMNOPQRSTUVWXYZ'], ['A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'], ['ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ...
coding
333
Solve the programming task below in a Python markdown code block. While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordere...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 1 1\n3\n", "1 1 1\n4\n", "1 1 2\n3\n", "2 5 0\n3 4\n", "1 13 1\n13\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "0\n", "3\n", "1\n"]}
coding
438
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a sorted unique integer array nums. A range [a,b] is the set of all integers from a to b (inclusive). Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, e...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,4,5,7]) == [\"0->2\",\"4->5\",\"7\"]\n assert candidate(nums = [0,2,3,4,6,8,9]) == [\"0\",\"2->4\",\"6\",\"8->9\"]\n\n\ncheck(Solution().summaryRanges)"}
coding
161
Solve the programming task below in a Python markdown code block. You are given an array A_{1}, A_{2}, \dots, A_{N} of length N. You can perform the following operation any number of times (possibly 0 times) : Choose any two indices i and j and replace either A_{i} or A_{j} with \gcd(A_{i},A_{j}). Find the minimum pos...
{"inputs": ["2\n2\n5 10\n3\n2 2 6\n"], "outputs": ["10\n6\n"]}
coding
454
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters. In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the string $s...
{"inputs": ["4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc\n", "4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabdd\nbadc\n", "4\n4\nabcd\nabdc\n5\nababa\nabaab\n4\nasdf\nasdg\n4\nabcd\nbadc\n", "4\n4\nabcd\nabdc\n5\naaabc\nbabaa\n4\nfdsa\nasdg\n4\nabdd\nbadc\n", "4\n4\ndabb\nabdb\n5\nababa\naba...
coding
569
Solve the programming task below in a Python markdown code block. Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the lose...
{"inputs": ["3\n", "2\n", "1\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["3\n4\n", "-1\n", "2\n", "-1\n", "-1\n", "6\n", "8\n", "-1\n"]}
coding
442
Solve the programming task below in a Python markdown code block. One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to...
{"inputs": ["1 2\n", "1 5\n", "3 7\n", "4 9\n", "2 5\n", "2 6\n", "3 8\n", "1 4\n"], "outputs": ["1\n", "0\n", "2\n", "3\n", "1\n", "0\n", "1\n", "0\n"]}
coding
390
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 32-bit integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used. All the letters in the answer string should be lowercase characters, and...
{"functional": "def check(candidate):\n assert candidate(num = 26) == \"1a\"\n assert candidate(num = -1) == \"ffffffff\"\n\n\ncheck(Solution().toHex)"}
coding
124
Solve the programming task below in a Python markdown code block. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string $s$ of length $n$, consistin...
{"inputs": ["1\n11\n80000000000\n", "1\n11\n83583640644\n", "1\n11\n83583640644\n", "1\n11\n80000000000\n", "1\n11\n81840233933\n", "1\n18\n80000000000\n", "1\n21\n80000000000\n", "1\n15\n80000000000\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
402
Solve the programming task below in a Python markdown code block. Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personal...
{"inputs": ["3\n1 1 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 2 1\n0 2 3 2\n0 1 3 1\n2 1 1 2\n5 3 4 2\n4 3 6 1\n4 2 5 1\n0", "3\n1 2 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 0 1\n0 2 3 2\n0 0 3 2\n2 2 1 2\n5 3 4 2\n4 3 6 1\n4 0 5 1\n0", "3\n1 1 2 3\n0 0 2 2\n1 2 0 3\n0\n1 2 2 1\n0 2 3 2\n0 1 3 0\n2 1 1 2\n5 3 4 2\n4 3 6 1\n4 2 5 1\n0", "3\n1...
coding
763
Solve the programming task below in a Python markdown code block. Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the togg...
{"inputs": ["1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n", "0 0 0\n0 0 0\n0 0 0\n", "0 0 0\n0 1 0\n0 0 0\n", "0 0 0\n0 0 0\n0 0 1\n", "0 0 0\n0 0 0\n0 0 1\n", "0 0 0\n0 1 0\n0 0 0\n", "0 0 0\n0 0 0\n0 0 0\n"], "outputs": ["001\n010\n100\n", "010\n011\n100\n", "111\n111\n111\n", "101\n000\n101\n", "111\n110\n100\n", ...
coding
318
Solve the programming task below in a Python markdown code block. bhargav has dream to study his MS is foreign country. So, He started his preparation for GRE. There are huge number of words that he has to prepare for. So, firs he wanted to group all synonyms and antonyms. As there are huge number of words that he has ...
{"inputs": ["ashtrick\n25\namberhed\ndouglasb\nashmartin\nroogle\neglownasht\ndutterwo\naverists\ndueglors\naeufahef\neutifhre\naedsrntf\naleifksc\nalejfisj\neshmarin\naksiefjs\ndharanis\nqueofjsl\ndileeeep\nprashant\naravinds\nakhilesh\ndheufncs\najeufjvjs\naeuigvsr\naskhtakuen"], "outputs": ["10 6"]}
coding
227
Solve the programming task below in a Python markdown code block. Chef is planning to buy a new car for his birthday. After a long search, he is left with 2 choices: Car 1: Runs on diesel with a fuel economy of x_{1} km/l Car 2: Runs on petrol with a fuel economy of x_{2} km/l Chef also knows that the current price o...
{"inputs": ["3\n10 5 3 20\n7 2 7 2\n1 5 3 2"], "outputs": ["-1\n0\n1"]}
coding
554
Solve the programming task below in a Python markdown code block. There is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked. A crazy robot has escaped from this lab. It is cur...
{"inputs": ["4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n...#.\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n.#...\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n..L\n...\n4 5\n#....\n..##L\n.#...\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n..L\n...\n4 5\n#....\n..##L\n..#..\n.....\...
coding
679
Solve the programming task below in a Python markdown code block. Given an array $a$, consisting of $n$ integers, find: $$\max\limits_{1 \le i < j \le n} LCM(a_i,a_j),$$ where $LCM(x, y)$ is the smallest positive integer that is divisible by both $x$ and $y$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, ...
{"inputs": ["2\n2 5\n", "2\n1 1\n", "2\n1 1\n", "2\n2 5\n", "2\n3 5\n", "3\n13 35 77\n", "4\n12 9 1 8\n", "4\n12 9 1 8\n"], "outputs": ["10", "1", "1\n", "10\n", "15\n", "1001", "72", "72\n"]}
coding
282
Solve the programming task below in a Python markdown code block. `late_clock` function receive an array with 4 digits and should return the latest time that can be built with those digits. The time should be in `HH:MM` format. Examples: ``` [1, 9, 8, 3] => 19:38 [9, 1, 2, 5] => 21:59 ``` You can suppose the input is...
{"functional": "_inputs = [[[9, 1, 2, 5]], [[1, 9, 8, 3]], [[0, 2, 2, 2]], [[3, 5, 0, 2]], [[9, 0, 1, 1]], [[2, 3, 2, 4]], [[1, 2, 8, 9]]]\n_outputs = [['21:59'], ['19:38'], ['22:20'], ['23:50'], ['19:10'], ['23:42'], ['19:28']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f...
coding
139
Solve the programming task below in a Python markdown code block. # Task A common way for prisoners to communicate secret messages with each other is to encrypt them. One such encryption algorithm goes as follows. You take the message and place it inside an `nx6` matrix (adjust the number of rows depending on the me...
{"functional": "_inputs = [['Attack at noon or we are done for'], [\"Let's kill them all\"], ['Meet me behind the kitchen tomorrow at seven in the evening']]\n_outputs = [['A.ow.f tanedo tt..or a.oan. cnrre. ko.e..'], [\"Lkhl eie. tlm. 'l.. s.a. .tl.\"], ['Men.eoaete e.dknrtnhn eb.i.r..ei tetttosi.n .hhcoweneg miehm.v....
coding
280
Solve the programming task below in a Python markdown code block. Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations: * find(s, t): report the minimum element in as, as+1, . . . ,at. * update(i, x): change ai to x. Note that the initial values of ai (i = 0, 1, . . ...
{"inputs": ["1 3\n1 0 1\n0 0 5\n0 0 0", "1 3\n1 0 0\n0 0 5\n1 0 0", "1 3\n1 -1 0\n0 0 5\n1 0 0", "1 3\n1 -1 0\n0 0 9\n1 0 0", "1 3\n1 -1 0\n0 0 5\n0 0 0", "1 3\n1 -1 0\n0 0 4\n1 0 0", "1 3\n1 -1 0\n1 0 9\n1 0 0", "1 3\n1 -1 1\n0 0 5\n0 0 0"], "outputs": ["2147483647\n", "2147483647\n5", "2147483647\n5\n", "2147483647\n...
coding
375
Solve the programming task below in a Python markdown code block. Snackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in descending ord...
{"inputs": ["2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1"], "outputs": ["2\n4"]}
coding
448
Solve the programming task below in a Python markdown code block. You are given a directed graph with $n$ vertices and $m$ directed edges without self-loops or multiple edges. Let's denote the $k$-coloring of a digraph as following: you color each edge in one of $k$ colors. The $k$-coloring is good if and only if ther...
{"inputs": ["2 1\n2 1\n", "2 1\n2 1\n", "2 2\n2 1\n1 2\n", "2 2\n2 1\n1 2\n", "10 2\n8 7\n4 5\n", "10 2\n8 7\n10 5\n", "10 2\n8 7\n10 5\n", "10 2\n4 7\n10 5\n"], "outputs": ["1\n1 \n", "1\n1\n", "2\n2 1 \n", "2\n2 1\n", "1\n1 1\n", "1\n1 1 \n", "1\n1 1\n", "1\n1 1\n"]}
coding
435
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D in...
{"functional": "def check(candidate):\n assert candidate(roads = [[0,1],[0,2],[0,3]], seats = 5) == 3\n assert candidate(roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2) == 7\n assert candidate(roads = [], seats = 1) == 0\n\n\ncheck(Solution().minimumFuelCost)"}
coding
229
Solve the programming task below in a Python markdown code block. Given a matrix you need to find the submatrix with the largest number of elements, where the GCD (Greatest Common Divisor) of its elements is greater than one. A submatrix of the matrix is a sub-section composed of contiguous rows and columns of the orig...
{"inputs": ["3 3\n2 6 8\n4 8 3\n6 9 4\n"], "outputs": ["4\n"]}
coding
198
Solve the programming task below in a Python markdown code block. There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordina...
{"inputs": ["1 1\n0\n0\n", "1 1\n1\n1\n", "1 1\n0\n1\n", "1 1\n5\n5\n", "1 1\n0\n0\n", "1 1\n5\n5\n", "1 1\n0\n1\n", "1 1\n1\n1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
639
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty...
{"functional": "def check(candidate):\n assert candidate(s = \"lEeTcOdE\") == \"E\"\n assert candidate(s = \"arRAzFif\") == \"R\"\n assert candidate(s = \"AbCdEfGhIjK\") == \"\"\n\n\ncheck(Solution().greatestLetter)"}
coding
111
Solve the programming task below in a Python markdown code block. An array A of length N is said to be *pseudo-sorted* if it can be made non-decreasing after performing the following operation at most once. Choose an i such that 1 ≤ i ≤ N-1 and swap A_{i} and A_{i+1} Given an array A, determine if it is *pseudo-sorted...
{"inputs": ["3\n5\n3 5 7 8 9\n4\n1 3 2 3\n3\n3 2 1\n"], "outputs": ["YES\nYES\nNO\n"]}
coding
442
Solve the programming task below in a Python markdown code block. A sum of p rubles is charged from Arkady's mobile phone account every day in the morning. Among the following m days, there are n days when Arkady will top up the account: in the day d_{i} he will deposit t_{i} rubles on his mobile phone account. Arkady ...
{"inputs": ["1 1 1\n1 1\n", "1 2 1\n1 1\n", "1 2 1\n1 3\n", "1 1 1\n1 1\n", "1 2 1\n1 1\n", "1 2 1\n1 3\n", "1 2 1\n1 0\n", "1 4 1\n1 3\n"], "outputs": ["0\n", "1\n", "0\n", " 0", " 1", " ...
coding
723
Solve the programming task below in a Python markdown code block. Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cann...
{"inputs": ["2", "1", "0", "3", "6", "4", "7", "8"], "outputs": ["Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
coding
178
Solve the programming task below in a Python markdown code block. ```if-not:sql Implement a function that receives two IPv4 addresses, and returns the number of addresses between them (including the first one, excluding the last one). ``` ```if:sql Given a database of first and last IPv4 addresses, calculate the numbe...
{"functional": "_inputs = [['150.0.0.0', '150.0.0.1'], ['10.0.0.0', '10.0.0.50'], ['20.0.0.10', '20.0.1.0'], ['10.11.12.13', '10.11.13.0'], ['160.0.0.0', '160.0.1.0'], ['170.0.0.0', '170.1.0.0'], ['50.0.0.0', '50.1.1.1'], ['180.0.0.0', '181.0.0.0'], ['1.2.3.4', '5.6.7.8']]\n_outputs = [[1], [50], [246], [243], [256], [...
coding
328
Solve the programming task below in a Python markdown code block. There are some candies that need to be distributed to some children as fairly as possible (i.e. the variance of result needs to be as small as possible), but I don't know how to distribute them, so I need your help. Your assignment is to write a function...
{"functional": "_inputs = [[-5, 0], [10, 0], [15, 0], [-5, -5], [10, -5], [15, -5]]\n_outputs = [[[]], [[]], [[]], [[]], [[]], [[]]]\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,...
coding
636
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on: * make as few changes as possible. * if the string contains equal...
{"functional": "_inputs = [['code'], ['CODe'], ['COde'], ['Code']]\n_outputs = [['code'], ['CODE'], ['code'], ['code']]\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 ...
coding
267
Solve the programming task below in a Python markdown code block. You will receive an uncertain amount of integers in a certain order ```k1, k2, ..., kn```. You form a new number of n digits in the following way: you take one of the possible digits of the first given number, ```k1```, then the same with the given numb...
{"functional": "_inputs = [[23, 17, 89], [22, 22, 22, 22], [230, 15, 8]]\n_outputs = [[[8, 218, 379, 2388]], [[1, 2222]], [[4, 218, 358, 1152]]]\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 isinstan...
coding
535
Solve the programming task below in a Python markdown code block. Complete the function that takes a string as an input, and return a list of all the unpaired characters (i.e. they show up an odd number of times in the string), in the order they were encountered as an array. In case of multiple appearances to choose ...
{"functional": "_inputs = [['Hello World'], ['Codewars'], ['woowee'], ['wwoooowweeee'], ['racecar'], ['Mamma'], ['Mama'], ['\u00bc x 4 = 1'], ['\u00bc x 4 = 1 and \u00bd x 4 = 2']]\n_outputs = [[['H', 'e', ' ', 'W', 'r', 'l', 'd']], [['C', 'o', 'd', 'e', 'w', 'a', 'r', 's']], [[]], [[]], [['e']], [['M']], [['M', 'm']],...
coding
262
Solve the programming task below in a Python markdown code block. In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large a...
{"inputs": ["50\n0\n25\n9", "50\n0\n164\n9", "50\n0\n25\n14", "50\n0\n35\n14", "50\n0\n35\n18", "50\n8\n3308\n3", "50\n8\n5734\n3", "50\n8\n5734\n4"], "outputs": ["3C11\n3C39\n3C25\n3C09\n", "3C11\n3C39\n3C08\n3C09\n", "3C11\n3C39\n3C25\n3C14\n", "3C11\n3C39\n3C35\n3C14\n", "3C11\n3C39\n3C35\n3C18\n", "3C11\n3C08\n3C32...
coding
423
Solve the programming task below in a Python markdown code block. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: - Operation A: The displayed value is doubled. - Operation B: The displayed value increases by K. Square1001 ...
{"inputs": ["4\n4", "4\n7", "4\n2", "4\n0", "4\n1", "4\n6", "4\n5", "4\n3"], "outputs": ["12\n", "15\n", "8\n", "1\n", "5\n", "14\n", "13\n", "10"]}
coding
218
Solve the programming task below in a Python markdown code block. There is a sequence whose $n^{\text{th}}$ term is $T_n=n^2-(n-1)^2$ Evaluate the series $S_n=T_1+T_2+T_3+\cdots+T_n$ Find $S_n\:\text{mod}\:(10^9+7)$. Example $n=3$ The series is $1^2-0^2+2^2-1^2+3^2-2^2=1+3+5=9$. Function Descriptio...
{"inputs": ["2\n2\n1\n"], "outputs": ["4\n1\n"]}
coding
312
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the array restaurants where  restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters. The veganFriendly filter will be either true (meaning you ...
{"functional": "def check(candidate):\n assert candidate(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10) == [3,1,5] \n assert candidate(restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganF...
coding
227
Solve the programming task below in a Python markdown code block. You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move. There are $n$ doors, the $i$-th door init...
{"inputs": ["1 1 1\n1\n", "1 2 3\n3\n", "1 2 3\n3\n", "1 1 1\n1\n", "1 2 1\n1\n", "1 1 3\n3\n", "1 2 1\n2\n", "1 3 1\n2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
coding
535
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Given an array A of N non-negative integers, you can choose any non-negative integer X and replace every element A_{i} with (A_{i}\oplus X) Here, \oplus deno...
{"inputs": ["1\n2\n4 6"], "outputs": ["6 2"]}
coding
409
Solve the programming task below in a Python markdown code block. Polycarp has $n$ friends, the $i$-th of his friends has $a_i$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $a_i$ to be the same. To solve this, Polycarp performs the following set of ac...
{"inputs": ["1\n2\n1 691\n", "1\n2\n1 691\n", "1\n3\n1 1 67\n", "1\n3\n1 1 67\n", "1\n3\n1 1 65\n", "1\n3\n0 1 65\n", "1\n3\n0 1 91\n", "1\n3\n0 0 91\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "-1\n", "1\n", "-1\n", "-1\n"]}
coding
712
Please solve the programming task below using a self-contained code snippet in a markdown code block. You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 th...
{"functional": "def check(candidate):\n assert candidate(plants = [2,2,3,3], capacity = 5) == 14\n assert candidate(plants = [1,1,1,4,2,3], capacity = 4) == 30\n assert candidate(plants = [7,7,7,7,7,7,7], capacity = 8) == 49\n\n\ncheck(Solution().wateringPlants)"}
coding
263
Solve the programming task below in a Python markdown code block. Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a ...
{"inputs": ["6\n4\n1 0 2 6\n6\n10 7 14 8 0 6\n2\n0 2\n3\n1 2 3\n6\n1 0 3 10 5 12\n2\n0 1023\n", "6\n4\n1 0 2 3\n6\n10 7 14 8 0 12\n2\n0 2\n3\n1 2 3\n6\n1 4 6 10 11 12\n2\n0 302\n", "6\n4\n1 0 2 3\n6\n10 7 14 8 0 12\n2\n0 2\n3\n1 2 3\n6\n1 4 9 10 18 12\n2\n1 302\n", "6\n4\n1 0 2 3\n6\n10 7 14 8 0 12\n2\n0 2\n3\n1 2 3\n6...
coding
694
Solve the programming task below in a Python markdown code block. Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are n video ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n2720\n", "1\n5280\n", "1\n5970\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "4\n", "2720\n", "5280\n", "5970\n"]}
coding
685
Solve the programming task below in a Python markdown code block. You are given an integer N. Construct a permutation P of length N such that For all i (1 ≤ i ≤ N-1), i divides abs(P_{i+1}-P_{i}). Recall that a permutation of length N is an array where every integer from 1 to N occurs exactly once. It can be prove...
{"inputs": ["2\n2\n3\n"], "outputs": ["1 2\n2 1 3\n"]}
coding
437
Solve the programming task below in a Python markdown code block. Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order....
{"inputs": ["2\n1\n", "2\n2\n", "2\n1\n", "2\n2\n", "3\n1 2\n", "3\n1 3\n", "3\n2 3\n", "3\n2 1\n"], "outputs": ["2\n", "1\n", " 2", " 1", "3\n", "2\n", "1\n", "3\n"]}
coding
249
Solve the programming task below in a Python markdown code block. You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the...
{"inputs": ["ab\n", "ab\n", "ba\n", "ac\n", "ab\n", "aba\n", "aba\n", "abb\n"], "outputs": ["abba", "abba\n", "baab\n", "acca\n", "abba\n", "abaaba", "abaaba\n", "abbbba\n"]}
coding
314
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has a two-dimensional matrix A of dimensions N × M, (N rows and M columns). He calls the matrix A beautiful if there exist an a×b submatrix, such that all of its eleme...
{"inputs": ["3 4\n1 8 3 4\n5 2 3 1\n3 6 2 2\n4\n1 1\n2 2\n2 3\n3 2"], "outputs": ["0\n4\n15\n9"]}
coding
663
Solve the programming task below in a Python markdown code block. Reducing Problems - Bug Fixing #8 Oh no! Timmy's reduce is causing problems, Timmy's goal is to calculate the two teams scores and return the winner but timmy has gotten confused and sometimes teams don't enter their scores, total the scores out of 3! H...
{"functional": "_inputs = [[[1, 2, 2], [1, 0, 0]], [[6, 45, 1], [1, 55, 0]], [[57, 2, 1], []], [[], [3, 4, 3]], [[], []]]\n_outputs = [[True], [False], [True], [False], [False]]\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=t...
coding
119
Solve the programming task below in a Python markdown code block. We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving ...
{"inputs": ["1\n2\n6", "1\n2\n7", "1\n2\n1", "1\n1\n1", "1\n8\n2", "1\n1\n0", "1\n0\n0", "1\n2\n3"], "outputs": ["8\n", "9\n", "3\n", "2\n", "10\n", "1\n", "0\n", "5"]}
coding
358
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Special Sum of 4 numbers (a, b, c, d) is defined as: |a+b-c-d| + |a+c-b-d| + |a+d-b-c| + |c+d-a-b| + |b+d-a-c| + |b+c-a-d| where |x| denotes absolute value of x. Read problems statements...
{"inputs": ["3\n4\n1 2 3 3\n5\n1 2 3 4 5\n6\n9 18 28 23 12 9"], "outputs": ["10\n76\n1176"]}
coding
391
Solve the programming task below in a Python markdown code block. Takaki Tono is a Computer Programmer in Tokyo. His boss at work shows him an online puzzle, which if solved would earn the solver a full expense paid trip to Los Angeles, California. Takaki really wants to solve this, as the love of his life, Akari, live...
{"inputs": ["5\n1 2 7 4 5\n1 2\n2 3\n2 4\n2 5\n7\nC 1 5\nF 1 5\nC 2 4\nC 1 2\nF 1 3\nF 3 4\nF 2 4"], "outputs": ["1\n4\n2\n1\n6\n5\n2"]}
coding
722
Solve the programming task below in a Python markdown code block. Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to...
{"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "3\n1 2 3\n", "3\n1 1 3\n", "3\n1 1 1\n", "3\n0 2 3\n"], "outputs": ["0 ", "1 ", "0\n", "1\n", "0 1 2 ", "0 2 1 ", "0 2 3 \n", "1 0 2 \n"]}
coding
388
Solve the programming task below in a Python markdown code block. # Valid HK Phone Number ## Overview In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example: ## Task Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that...
{"functional": "_inputs = [['1234 5678'], ['2359 1478'], ['85748475'], ['3857 4756'], ['sklfjsdklfjsf'], [' 1234 5678 '], ['abcd efgh'], ['9684 2396'], ['836g 2986'], ['0000 0000'], ['123456789'], [' 987 634 '], [' 6 '], ['8A65 2986'], ['8368 2aE6'], ['8c65 2i86']]\n_outputs = [[True], [True], [False], [Fa...
coding
142
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1. Return the minimum number of moves to make every value in nums unique. The test cases ar...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2]) == 1\n assert candidate(nums = [3,2,1,2,1,7]) == 6\n\n\ncheck(Solution().minIncrementForUnique)"}
coding
117
Solve the programming task below in a Python markdown code block. Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color x_{i} and the kit for away games of this team has color y_{i} (x_{i} ≠ y_{i})...
{"inputs": ["2\n1 2\n2 1\n", "2\n1 2\n1 2\n", "2\n1 2\n3 4\n", "2\n1 2\n1 2\n", "2\n1 2\n3 4\n", "2\n1 2\n1 0\n", "2\n1 4\n2 1\n", "2\n1 2\n3 0\n"], "outputs": ["2 0\n2 0\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n2 0\n", "1 1\n1 1\n"]}
coding
400
Solve the programming task below in a Python markdown code block. Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$. The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and...
{"inputs": ["3\n2 2 3\n2 0 4", "3\n1 2 3\n2 0 4", "3\n2 2 3\n2 -1 4", "3\n2 4 5\n2 -1 4", "3\n3 4 5\n2 -1 4", "3\n6 4 5\n2 -1 4", "3\n6 5 5\n2 -1 4", "3\n6 5 5\n2 -1 3"], "outputs": ["3.000000\n2.236068\n2.080084\n2.000000\n", "4.000000\n2.449490\n2.154435\n2.000000", "4.000000\n3.162278\n3.036589\n3.000000\n", "6.0000...
coding
554
Solve the programming task below in a Python markdown code block. a is an array of n positive integers, all of which are not greater than n. You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap ...
{"inputs": ["3\n1 1 1\n3\n1 1\n2 1\n1 1\n", "3\n1 1 1\n3\n2 1\n2 1\n1 1\n", "3\n2 1 1\n3\n1 1\n2 1\n1 1\n", "3\n1 1 2\n3\n2 1\n2 1\n1 1\n", "3\n1 1 1\n3\n2 2\n2 1\n1 1\n", "3\n1 1 0\n3\n2 1\n2 1\n1 1\n", "3\n1 1 1\n3\n1 1\n2 1\n3 1\n", "10\n3 5 4 3 7 8 6 7 2 3\n10\n4 5\n2 10\n4 3\n9 9\n9 2\n5 1\n6 4\n1 1\n5 6\n6 4\n"],...
coding
280
Solve the programming task below in a Python markdown code block. Remember the game 2048? The main part of this game is merging identical tiles in a row. * Implement a function that models the process of merging all of the tile values in a single row. * This function takes the array line as a parameter and returns...
{"functional": "_inputs = [[[2, 0, 2, 2]], [[2, 0, 2, 4]], [[0, 0, 2, 2]], [[2, 2, 0, 0]], [[2, 2, 2, 2, 2]], [[8, 16, 16, 8]]]\n_outputs = [[[4, 2, 0, 0]], [[4, 4, 0, 0]], [[4, 0, 0, 0]], [[4, 0, 0, 0]], [[4, 4, 2, 0, 0]], [[8, 32, 8, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isi...
coding
258
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR". Plea...
{"functional": "def check(candidate):\n assert candidate(0.625) == \"0.101\"\n assert candidate(0.1) == \"ERROR\"\n\n\ncheck(Solution().printBin)"}
coding
100
Solve the programming task below in a Python markdown code block. Mahmoud has n line segments, the i-th of them has length a_{i}. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should...
{"inputs": ["3\n4 1 2\n", "3\n2 2 3\n", "3\n2 3 4\n", "3\n5 6 7\n", "3\n2 4 5\n", "3\n1 1 1\n", "3\n1 1 1\n", "3\n5 6 7\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
314
Solve the programming task below in a Python markdown code block. Indraneel's student has given him data from two sets of experiments that the student has performed. Indraneel wants to establish a correlation between the two sets of data. Each data set is a sequence of $N$ numbers. The two data sets do not match number...
{"inputs": ["7\n3 8 4 23 9 11 28\n2 3 22 26 8 16 12"], "outputs": ["4\n3 4 23 9\n2 3 22 8"]}
coding
470
Solve the programming task below in a Python markdown code block. ## Description: Remove all exclamation marks from the end of words. Words are separated by spaces in the sentence. ### Examples ``` remove("Hi!") === "Hi" remove("Hi!!!") === "Hi" remove("!Hi") === "!Hi" remove("!Hi!") === "!Hi" remove("Hi! Hi!") ===...
{"functional": "_inputs = [['Hi!'], ['Hi!!!'], ['!Hi'], ['!Hi!'], ['Hi! Hi!']]\n_outputs = [['Hi'], ['Hi'], ['!Hi'], ['!Hi'], ['Hi Hi']]\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, (l...
coding
126