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.
Maya is teaching Alex about HyperText Markup Language (HTML). Alex is confused about div and span tags, so Maya decides to reduce the concept to a simpler visual by representing div tags as square brackets and span tags as parentheses. In other words, sh... | {"inputs": ["3\n1 1\n1 2\n2 2\n"], "outputs": ["3\n18\n160\n"]} | coding | 671 |
Solve the programming task below in a Python markdown code block.
Apple considers any iPhone with a battery health of 80\% or above, to be in *optimal* condition.
Given that your iPhone has X\% battery health, find whether it is in *optimal* condition.
------ Input Format ------
- The first line of input will cont... | {"inputs": ["4\n97\n42\n80\n10\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | coding | 367 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].
A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal dire... | {"functional": "def check(candidate):\n assert candidate(x = 2, y = 1) == 1\n assert candidate(x = 5, y = 5) == 4\n\n\ncheck(Solution().minKnightMoves)"} | coding | 137 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in ... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,2,3],[0,2],[0,1,3],[0,2]]) == False\n assert candidate(graph = [[1,3],[0,2],[1,3],[0,2]]) == True\n\n\ncheck(Solution().isBipartite)"} | coding | 260 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connect... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]) == 3\n assert candidate(n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]) == 1\n\n\ncheck(Solution().countCompleteComponents)"} | coding | 186 |
Solve the programming task below in a Python markdown code block.
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.
Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420.
We sha... | {"functional": "_inputs = [[0.1], [0.15], [0.5], [0.75], [0.9]]\n_outputs = [[132], [160], [538], [3088], [21780]]\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 | 323 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.
A substring is a contiguous non-empty sequence of chara... | {"functional": "def check(candidate):\n assert candidate(s = \"abcba\") == 7\n assert candidate(s = \"abacad\") == 9\n assert candidate(s = \"a\") == 1\n\n\ncheck(Solution().numberOfSubstrings)"} | coding | 96 |
Solve the programming task below in a Python markdown code block.
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of tow... | {"inputs": ["4 2 5\n1 2 8 7", "4 2 5\n1 1 5 7", "4 2 5\n1 2 5 7", "7 2 101\n18 8 32 1 146 3 37", "7 2 101\n13 8 32 1 146 3 37", "7 2 101\n13 8 32 1 182 3 37", "7 2 101\n20 14 32 1 72 3 37", "7 2 100\n13 8 32 1 182 3 37"], "outputs": ["5\n", "9\n", "11", "-151\n", "-141\n", "-213\n", "-7\n", "-214\n"]} | coding | 387 |
Solve the programming task below in a Python markdown code block.
SKIT’s canteen sells Patties in packages of 6, 9 or 20 . Thus, it is possible, for example, to buy exactly 15 Patties (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 Patties, since no non- negative integer comb... | {"inputs": ["2\n45\n1", "5\n1991\n991\n43\n57\n1000000"], "outputs": ["True\nFalse", "True\nTrue\nFalse\nTrue\nTrue"]} | coding | 310 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s that you must perform k replacement operations on. The replacement operations are given as three 0-indexed parallel arrays, indices, sources, and targets, all of length k.
To complet... | {"functional": "def check(candidate):\n assert candidate(s = \"abcd\", indices = [0,2], sources = [\"a\",\"cd\"], targets = [\"eee\",\"ffff\"]) == \"eeebffff\"\n assert candidate(s = \"abcd\", indices = [0,2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"]) == \"eeecd\"\n\n\ncheck(Solution().findReplaceS... | coding | 300 |
Solve the programming task below in a Python markdown code block.
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input da... | {"inputs": ["ab\ncc\ncd\n", "ab\ncc\ndd\n", "ab\ncc\ndc\n", "ba\ncc\ndd\n", "aa\ncc\ndd\n", "aa\ndc\ndd\n", "aa\ndc\ncd\n", "aa\ndc\nbd\n"], "outputs": ["5\n", "6\n", "5\n", "6\n", "6\n", "5\n", "5\n", "5\n"]} | coding | 235 |
Solve the programming task below in a Python markdown code block.
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned indiv... | {"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "2\n5 1\n", "2\n5 1\n", "2\n5 0\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "3\n", "5\n", "5\n", "5\n"]} | coding | 428 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.
After converting, each digit should be interpreted as a base 10 number, and the sum should be ... | {"functional": "def check(candidate):\n assert candidate(n = 34, k = 6) == 9\n assert candidate(n = 10, k = 10) == 1\n\n\ncheck(Solution().sumBase)"} | coding | 115 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that n... | {"functional": "def check(candidate):\n assert candidate(num = \"327\") == 2\n assert candidate(num = \"094\") == 0\n assert candidate(num = \"0\") == 0\n assert candidate(num = \"9999999999999\") == 101\n\n\ncheck(Solution().numberOfCombinations)"} | coding | 133 |
Solve the programming task below in a Python markdown code block.
Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.
Example
$arr=[1,2,2,3]$
Delete the $2$ elements $1$ and $3$ leaving $arr=[2,2]$. If both twos plus either the $1$ or the $3$ are ... | {"inputs": ["STDIN Function\n----- --------\n5 arr[] size n = 5\n3 3 2 1 3 arr = [3, 3, 2, 1, 3]\n"], "outputs": ["2 \n"]} | coding | 368 |
Solve the programming task below in a Python markdown code block.
You have an array $a$ of size $n$ consisting only of zeroes and ones and an integer $k$. In one operation you can do one of the following:
Select $2$ consecutive elements of $a$ and replace them with their minimum (that is, let $a := [a_{1}, a_{2}, \ldo... | {"inputs": ["1\n32 32\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "7\n3 2\n0 1 0\n5 3\n1 0 1 1 0\n2 2\n1 1\n4 4\n0 0 0 0\n6 3\n0 0 1 0 0 1\n7 5\n1 1 1 1 1 1 1\n5 3\n0 0 1 0 0\n"], "outputs": ["NO\n", "YES\nYES\nYES\nNO\nYES\nYES\nYES\n"]} | coding | 749 |
Solve the programming task below in a Python markdown code block.
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". Today is the time to make a rectangle with sticks, but I would like to see if I can make a rectangle using the ... | {"inputs": ["0 1 2 2", "0 0 2 2", "2 0 1 2", "1 1 0 4", "2 0 2 2", "1 1 0 6", "2 0 2 4", "0 1 0 6"], "outputs": ["no\n", "yes\n", "no\n", "no\n", "no\n", "no\n", "no\n", "no\n"]} | coding | 262 |
Solve the programming task below in a Python markdown code block.
On the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.
You are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.
-... | {"inputs": ["C", "T", "C", "T", "G", "A", "A\n", "G\n"], "outputs": ["G\n", "A\n", "G\n", "A\n", "C", "T", "T\n", "C\n"]} | coding | 142 |
Solve the programming task below in a Python markdown code block.
Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or 2 classes. Each one has its own unique haunted house. Therefore, many ... | {"inputs": ["0^ 3 746\n0d 179 4\n1e 8 1320\n_4 20 77\nd3 494 257\nf2 13 50\n3a 88 113\n1c 78 14\n2d 318 11", "0^ 3 746\n0d 179 4\n1e 8 1320\n_4 20 77\nd3 494 160\nf2 13 50\n3a 88 113\n1c 78 14\n2d 318 11", "0^ 3 746\n0d 179 4\n1e 8 1320\n_4 20 147\nd3 494 257\nf2 13 50\n3a 88 113\n1c 78 14\n2d 318 11", "0^ 3 746\n0d 17... | coding | 551 |
Solve the programming task below in a Python markdown code block.
Your task is to return the sum of Triangular Numbers up-to-and-including the `nth` Triangular Number.
Triangular Number: "any of the series of numbers (1, 3, 6, 10, 15, etc.) obtained by continued summation of the natural numbers 1, 2, 3, 4, 5, etc."
`... | {"functional": "_inputs = [[6], [34], [-291], [943], [-971]]\n_outputs = [[56], [7140], [0], [140205240], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if ... | coding | 228 |
Solve the programming task below in a Python markdown code block.
Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.
For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ... | {"inputs": ["5\n", "9\n", "1\n", "0\n", "3\n", "4\n", "6\n", "7\n"], "outputs": ["0\n", "10\n", "0\n", "0\n", "0\n", "0\n", "10\n", "10\n"]} | coding | 289 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.
However, th... | {"functional": "def check(candidate):\n assert candidate(scores = [1,3,5,10,15], ages = [1,2,3,4,5]) == 34\n assert candidate(scores = [4,5,6,5], ages = [2,1,2,1]) == 16\n assert candidate(scores = [1,2,3,5], ages = [8,9,10,1]) == 6\n\n\ncheck(Solution().bestTeamScore)"} | coding | 179 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land o... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,0,1],[0,0,0],[1,0,1]]) == 2\n assert candidate(grid = [[1,0,0],[0,0,0],[0,0,0]]) == 4\n\n\ncheck(Solution().maxDistance)"} | coding | 163 |
Solve the programming task below in a Python markdown code block.
Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not.
He has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exists some ... | {"inputs": ["1\n3\n21 11 6"], "outputs": ["3"]} | coding | 452 |
Solve the programming task below in a Python markdown code block.
There is a special offer in Vasya's favourite supermarket: if the customer buys $a$ chocolate bars, he or she may take $b$ additional bars for free. This special offer can be used any number of times.
Vasya currently has $s$ roubles, and he wants to get... | {"inputs": ["1\n709551 1 1 1\n", "1\n754851 1 1 1\n", "1\n6713132 1 0 1\n", "1\n4 8980272 0 4\n", "1\n9085944 1 0 1\n", "1\n4 8980272 0 1\n", "1\n4 8980272 0 2\n", "1\n4 8980272 0 3\n"], "outputs": ["1419102\n", "1509702\n", "6713132\n", "1\n", "9085944\n", "4\n", "2\n", "1\n"]} | coding | 444 |
Solve the programming task below in a Python markdown code block.
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consis... | {"inputs": ["1\n0 0 0 0\n", "1\n0 0 0 0\n", "1\n0 0 1 0\n", "1\n0 0 2 0\n", "1\n4 0 0 0\n", "1\n1 0 0 0\n", "1\n2 0 0 0\n", "1\n1 0 1 0\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "4\n", "1\n", "2\n", "1\n"]} | coding | 750 |
Solve the programming task below in a Python markdown code block.
The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent buildings... | {"inputs": ["3\n3\n010\n5\n10001\n7\n0000000", "3\n3\n011\n5\n10001\n7\n0000000", "3\n3\n010\n5\n10001\n7\n0010000", "3\n3\n010\n5\n10001\n7\n1010000", "3\n3\n010\n5\n10000\n7\n1010000", "3\n3\n010\n5\n10011\n7\n0000000", "3\n3\n001\n5\n10101\n7\n0000000", "3\n3\n010\n5\n00011\n7\n1010000"], "outputs": ["0\n1\n7", "0\n... | coding | 318 |
Solve the programming task below in a Python markdown code block.
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in ... | {"inputs": ["3\n3 1 1\n2 1 1\n2 3 1\n", "3\n1 3 2\n1 2 1\n3 2 1\n", "3\n1 3 1\n1 2 7\n3 2 1\n", "3\n1 3 1\n1 2 7\n3 2 2\n", "3\n3 1 2\n2 1 1\n2 3 1\n", "3\n1 3 4\n1 2 1\n3 2 1\n", "3\n1 3 1\n1 2 1\n3 2 2\n", "3\n1 3 3\n1 2 1\n3 2 1\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 442 |
Solve the programming task below in a Python markdown code block.
Chef is given a binary string A of length N. He can perform the following operation on A any number of times:
Choose L and R (1 ≤ L ≤ R ≤ N), such that, in the [substring] A[L,R], the number of 1s is equal to the number of 0s and reverse the substring A[... | {"inputs": ["2\n5\n01100\n4\n0000\n"], "outputs": ["00011\n0000"]} | coding | 474 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consi... | {"functional": "def check(candidate):\n assert candidate(sentence1 = \"My name is Haley\", sentence2 = \"My Haley\") == True\n assert candidate(sentence1 = \"of\", sentence2 = \"A lot of words\") == False\n assert candidate(sentence1 = \"Eating right now\", sentence2 = \"Eating\") == True\n assert candidate... | coding | 276 |
Solve the programming task below in a Python markdown code block.
# Task
You're given a two-dimensional array of integers `matrix`. Your task is to determine the smallest non-negative integer that is not present in this array.
# Input/Output
- `[input]` 2D integer array `matrix`
A non-empty rectangular matrix. ... | {"functional": "_inputs = [[[[0, 2], [5, 1]]], [[[4, 5, 3, 21, 3, 8], [2, 2, 6, 5, 10, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 0], [1, 3, 6, 5, 5, 1], [2, 7, 3, 4, 4, 3]]], [[[4, 5, 3, -4, 3, 8], [2, 0, 6, 5, 4, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 11], [1, 3, 10, 5, 5, 1], [12, 7, 3, 4, 4, 3]]], [[[1, 2], [3, 4]]],... | coding | 182 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is... | {"functional": "def check(candidate):\n assert candidate(source = \"abc\", target = \"abcbc\") == 2\n assert candidate(source = \"abc\", target = \"acdbc\") == -1\n assert candidate(source = \"xyz\", target = \"xzyxz\") == 3\n\n\ncheck(Solution().shortestWay)"} | coding | 146 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef and Divyam are playing a game. They start with a rational number $X$, such that $0 < X < 1$.
In each turn, Chef chooses a positive real number $Y$. Then Divyam ... | {"inputs": ["2\n1 2\n2 3"], "outputs": ["Yes\nNo"]} | coding | 514 |
Solve the programming task below in a Python markdown code block.
There is an integer $n$ without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.
On her turn, Alice must swap any two digits of the integer that are on different po... | {"inputs": ["3\n12\n132\n487456398\n"], "outputs": ["2\n1\n3\n"]} | coding | 365 |
Solve the programming task below in a Python markdown code block.
Chef would like go shopping to buy ingredients for his special dish. The local grocery store has some special discount offers. If you want to buy some set of ingredients you will pay for all ingredients except the cheapest one. Chef would like to spend a... | {"inputs": ["1\n4\n1 2 3 4\n3\n2 1 2\n2 3 4\n3 1 2 3"], "outputs": ["6"]} | coding | 441 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin Chinese] and [Vietnamese] as well.
Chef placed $N$ boxes (numbered $1$ through $N$) in a straight line. For each valid $i$, the $i$-th box contains $A_{i}$ balls.
Then, Chef painted the boxes using $M$ distinct col... | {"inputs": ["1 \n4 2 \n10 20 15 28"], "outputs": ["5"]} | coding | 576 |
Solve the programming task below in a Python markdown code block.
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substr... | {"inputs": ["3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi", "3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nipp", "3\ncodechef\n2\ncode\ndhef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nipp", "3\ncodechef\n2\ncode\ndhef\nfoo\n1\nbar\nmississippi\n4\ns... | coding | 380 |
Solve the programming task below in a Python markdown code block.
It is a complicated version of problem F1. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is c... | {"inputs": ["1\n688 10\n", "1\n701 10\n", "1\n5828 1\n", "1\n9772 1\n", "1\n4955 2\n", "1\n2388 2\n", "1\n2388 4\n", "1\n2388 1\n"], "outputs": ["688\n", "701\n", "6666\n", "9999\n", "4994\n", "2422\n", "2388\n", "3333\n"]} | coding | 421 |
Solve the programming task below in a Python markdown code block.
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one ... | {"inputs": ["2 5 4 0 4\n", "4 5 9 2 1\n", "0 0 0 0 0\n", "1 2 1 2 3\n", "2 3 4 5 6\n", "1 1 1 1 1\n", "0 1 2 3 4\n", "0 0 0 0 1\n"], "outputs": ["3\n", "-1\n", "-1\n", "-1\n", "4\n", "1\n", "2\n", "-1\n"]} | coding | 368 |
Solve the programming task below in a Python markdown code block.
Create a function which checks a number for three different properties.
- is the number prime?
- is the number even?
- is the number a multiple of 10?
Each should return either true or false, which should be given as an array. Remark: The Haskell varia... | {"functional": "_inputs = [[0], [2], [5], [25], [131], [1], [100], [179424691], [179424693]]\n_outputs = [[[False, True, True]], [[True, True, False]], [[True, False, False]], [[False, False, False]], [[True, False, False]], [[False, False, False]], [[False, True, True]], [[True, False, False]], [[False, False, False]]... | coding | 206 |
Solve the programming task below in a Python markdown code block.
You are given two arrays A and B of length N. Let S be the set of integers from 1 to N. Can you find the maximum possible value of (A_{i1}+A_{i2}+...+A_{ik})^{2}+(B_{i1}+B_{i2}+...+B_{ik})^{2} where {i1,i2...ik} is a non-empty subset of S?
Input Format ... | {"inputs": ["1 \n2 \n-1 5 \n4 -5 \n"], "outputs": ["50\n"]} | coding | 366 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of ze... | {"inputs": ["0\n", "1\n", "1\n", "0\n", "110\n", "010\n", "100\n", "000\n"], "outputs": ["0\n", "0\n", "0", "0", "010\n", "010\n", "100\n", "000\n"]} | coding | 690 |
Solve the programming task below in a Python markdown code block.
Alice and Borys are playing tennis.
A tennis match consists of games. In each game, one of the players is serving and the other one is receiving.
Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vic... | {"inputs": ["3\n2 1\n1 1\n0 5\n", "2\n99999 0\n0 99999\n", "2\n99999 1\n1 99999\n", "2\n99998 1\n1 99998\n", "2\n0 100000\n100000 0\n"], "outputs": ["4\n0 1 2 3\n2\n0 2\n2\n2 3\n", "2\n49999 50000\n2\n49999 50000\n", "2\n49999 50001\n2\n49999 50001\n", "4\n49998 49999 50000 50001\n4\n49998 49999 50000 50001\n", "1\n500... | coding | 706 |
Solve the programming task below in a Python markdown code block.
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove... | {"inputs": ["a\na\n", "a\nb\n", "a\nb\n", "a\na\n", "b\nb\n", "aa\na\n", "a\nab\n", "b\ncb\n"], "outputs": ["a\n", "-\n", "-", "a", "b\n", "a\n", "a\n", "b\n"]} | coding | 312 |
Solve the programming task below in a Python markdown code block.
There are $N$ cars (numbered $1$ through $N$) on a circular track with length $N$. For each $i$ ($2 \le i \le N$), the $i$-th of them is at a distance $i-1$ clockwise from car $1$, i.e. car $1$ needs to travel a distance $i-1$ clockwise to reach car $i$.... | {"inputs": ["3\n5\n3 0 0 0 0\n5\n1 1 1 1 1\n5\n5 4 3 2 1"], "outputs": ["3\n5\n15"]} | coding | 429 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).
Return the indices of people whose list of favorite companies is not a subset of any... | {"functional": "def check(candidate):\n assert candidate(favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"google\",\"microsoft\"],[\"google\",\"facebook\"],[\"google\"],[\"amazon\"]]) == [0,1,4] \n assert candidate(favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"leetcode\",\"amazon\"]... | coding | 108 |
Solve the programming task below in a Python markdown code block.
You are given a sequence whose $n^{\text{th}}$ term is
$T_{n}=n^{K}$
You have to evaluate the series
$S_n=T_1+T_2+T_3+\cdots+T_n$
Find $S_n\:\text{mod}\:(10^9+7)$.
Input Format
The first line of input contains $\mathbf{T}$, the number of test cases... | {"inputs": ["3\n5 3\n4 2\n4 1\n"], "outputs": ["225\n30\n10\n"]} | coding | 314 |
Solve the programming task below in a Python markdown code block.
We are still with squared integers.
Given 4 integers `a, b, c, d` we form the sum of the squares of `a` and `b`
and then the sum of the squares of `c` and `d`. We multiply the two sums hence a number `n` and we try to
decompose `n` in a sum of two squar... | {"functional": "_inputs = [[1, 2, 1, 3], [2, 3, 4, 5], [1, 2, 2, 3], [1, 1, 3, 5], [10, 11, 12, 13], [1, 20, -4, -5], [100, 100, 100, 100], [0, 0, 0, 0], [-14, 12, -10, 8], [7, 96, -1, 81], [112, 0, 0, 1]]\n_outputs = [[[[1, 7], [5, 5]]], [[[2, 23], [7, 22]]], [[[1, 8], [4, 7]]], [[[2, 8]]], [[[2, 263], [23, 262]]], [[... | coding | 629 |
Solve the programming task below in a Python markdown code block.
Guys don’t misinterpret this it is three only.
-----Input:-----
- First line will contain an integer $X$.
-----Output:-----
A single line containing the answer to the problem modulo 1000000007.
-----Constraints-----
- $1 \leq X < 10^5$
-----Sample In... | {"inputs": ["1", "2"], "outputs": ["3", "14"]} | coding | 119 |
Solve the programming task below in a Python markdown code block.
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x_1, the second friend lives at the point x_2, and the third friend lives at the point x_3. They plan to celebrate the New Year together, so they need ... | {"inputs": ["7 1 4\n", "1 2 3\n", "1 3 2\n", "4 2 6\n", "6 9 3\n", "8 1 9\n", "3 5 4\n", "2 1 3\n"], "outputs": ["6\n", "2\n", "2\n", "4\n", "6\n", "8\n", "2\n", "2\n"]} | coding | 314 |
Solve the programming task below in a Python markdown code block.
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, ... | {"inputs": ["2\n4\n1\n0", "2\n2\n6\n0", "2\n0\n6\n0", "2\n7\n0\n0", "2\n2\n1\n0", "2\n1\n8\n0", "2\n4\n6\n0", "2\n0\n8\n0"], "outputs": ["1\n2\n1\n", "1\n1\n2\n", "1\n", "1\n2\n", "1\n1\n1\n", "1\n1\n3\n", "1\n2\n2\n", "1\n"]} | coding | 277 |
Solve the programming task below in a Python markdown code block.
Hossam woke up bored, so he decided to create an interesting array with his friend Hazem.
Now, they have an array $a$ of $n$ positive integers, Hossam will choose a number $a_i$ and Hazem will choose a number $a_j$.
Count the number of interesting pair... | {"inputs": ["2\n3\n1 1 1\n2\n1 2\n", "2\n5\n6 2 3 8 1\n6\n7 2 8 3 2 10\n", "2\n5\n1 1 1 1 1\n6\n7 2 8 3 2 10\n"], "outputs": ["6\n2\n", "2\n4\n", "20\n4\n"]} | coding | 530 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef has A units of solid and B units of liquid. He combines them to create a mixture. What kind of mixture does Chef produce: a solution, a solid, or a liqui... | {"inputs": ["3\n10 5\n0 3\n3 0\n"], "outputs": ["Solution\nLiquid\nSolid\n"]} | coding | 363 |
Solve the programming task below in a Python markdown code block.
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).
A customer ordered a bowl of ramen and told which toppings to put on his ramen to... | {"inputs": ["pxo", "yxx", "opo", "oxp", "xyx", "opn", "xpo", "xzx"], "outputs": ["800\n", "700\n", "900\n", "800\n", "700\n", "800\n", "800\n", "700\n"]} | coding | 305 |
Solve the programming task below in a Python markdown code block.
There are N integers written on a blackboard. The i-th integer is A_i.
Takahashi and Aoki will arrange these integers in a row, as follows:
* First, Takahashi will arrange the integers as he wishes.
* Then, Aoki will repeatedly swap two adjacent intege... | {"inputs": ["4\n2 0 4 6", "4\n1 0 4 6", "4\n1 0 2 6", "4\n1 0 2 2", "4\n2 0 2 2", "4\n2 0 3 2", "4\n2 0 6 2", "4\n2 3 4 1"], "outputs": ["0 2 4 6 ", "1 0 4 6 ", "1 0 2 6 ", "1 0 2 2 ", "0 2 2 2 ", "0 3 2 2 ", "0 2 2 6 ", "3 2 4 1 "]} | coding | 267 |
Solve the programming task below in a Python markdown code block.
Alice has an array of N integers — A_{1}, A_{2}, \ldots, A_{N}. She wants the product of all the elements of the array to be a non-negative integer. That is, it can be either 0 or positive. But she doesn't want it to be negative.
To do this, she is will... | {"inputs": ["4\n3\n1 9 8\n4\n2 -1 9 100\n4\n2 -1 0 100\n4\n2 -1 -1 100\n"], "outputs": ["0\n1\n0\n0\n"]} | coding | 579 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$. The array is called 3SUM-closed if for all distinct indices $i$, $j$, $k$, the sum $a_i + a_j + a_k$ is an element of the array. More formally, $a$ is 3SUM-closed if for all integers $1 \leq i < j < k \leq n$, th... | {"inputs": ["1\n4\n-3 -1 1 1\n", "1\n4\n-1 -4 2 3\n", "1\n4\n7 7 7 -21\n", "1\n4\n3 -3 -3 9\n", "1\n3\n0 65536 65536\n", "4\n3\n-1 0 1\n5\n1 -2 -2 1 -3\n6\n0 0 0 0 0 0\n4\n-1 2 -3 4\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\nNO\nYES\nNO\n"]} | coding | 608 |
Solve the programming task below in a Python markdown code block.
Little Chief loves math. Most of all, he loves equations. He can solve any equation in the whole world. Recently he found one interesting and easy equation
x1^{d}+x2^{d}+x3^{d} ≡ m (mod N)
Where x1, x2 and x3 are non negative integer numbers.
But, as ... | {"inputs": ["2\n2 2 3 5\n1 2013 3 31", "2\n2 2 3 5\n1 2013 3 31"], "outputs": ["4\n1\n", "4\n1"]} | coding | 451 |
Solve the programming task below in a Python markdown code block.
Suppose you are living with two cats: A and B. There are $n$ napping spots where both cats usually sleep.
Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:
Cat A changes its napping place in order:... | {"inputs": ["1\n35 950009\n", "1\n2 1615745\n", "1\n6 1687697\n", "1\n59 950009\n", "1\n22 313455\n", "1\n6 2518353\n", "1\n62 950009\n", "1\n35 669530\n"], "outputs": ["26\n", "1\n", "5\n", "4\n", "21\n", "3\n", "45\n", "24\n"]} | coding | 748 |
Solve the programming task below in a Python markdown code block.
Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend ... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n2 1\n2 2\n", "2\n2 1\n2 2\n", "2\n4 1\n2 2\n", "3\n3 1\n3 2\n3 3\n", "3\n3 1\n3 2\n3 3\n", "3\n5 1\n3 2\n3 3\n"], "outputs": ["1\n", "1\n", "0\n1\n", "0\n1\n", "0\n1\n", "0\n2\n1\n", "0\n2\n1\n", "0\n2\n1\n"]} | coding | 514 |
Solve the programming task below in a Python markdown code block.
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying... | {"inputs": ["1 1\n1\n", "1 2\n2\n", "1 3\n3\n", "1 4\n4\n", "1 5\n5\n", "1 7\n1\n", "1 5\n1\n", "1 9\n9\n"], "outputs": ["0", "0", "0", "0", "0", "11", "7", "0"]} | coding | 729 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.
You are g... | {"functional": "def check(candidate):\n assert candidate(edges = [[1,2],[2,3],[4,2]]) == 2\n assert candidate(edges = [[1,2],[5,1],[1,3],[1,4]]) == 1\n\n\ncheck(Solution().findCenter)"} | coding | 139 |
Solve the programming task below in a Python markdown code block.
In this Kata, we are going to reverse a string while maintaining the spaces (if any) in their original place.
For example:
```
solve("our code") = "edo cruo"
-- Normal reversal without spaces is "edocruo".
-- However, there is a space at index 3, so th... | {"functional": "_inputs = [['codewars'], ['your code'], ['your code rocks'], ['i love codewars']]\n_outputs = [['srawedoc'], ['edoc ruoy'], ['skco redo cruoy'], ['s rawe docevoli']]\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_t... | coding | 239 |
Solve the programming task below in a Python markdown code block.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the $n$ piles with stones numbered from $1$ to $n$.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was $x_1, x... | {"inputs": ["1\n3\n2\n", "1\n1\n5\n", "1\n6\n1\n", "1\n1\n1\n", "1\n0\n0\n", "1\n7\n3\n", "1\n2\n1\n", "1\n0\n0\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]} | coding | 622 |
Solve the programming task below in a Python markdown code block.
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team ... | {"inputs": ["2 2 2 2 4 4\n", "5 5 1 5 5 5\n", "5 5 1 3 5 5\n", "3 3 1 3 9 9\n", "1 1 1 1 1 1\n", "5 5 0 5 5 5\n", "1 1 1 2 1 1\n", "5 5 0 3 5 5\n"], "outputs": ["2 2 \n", "1 1 1 1 1 \n", "1 1 1 1 1 \n", "3 3 3 \n", "1 \n", "1 1 1 1 1 \n", "1 \n", "1 1 1 1 1 \n"]} | coding | 416 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
You are given an integer sequence $A$ with length $N$. Find the number of ordered pairs of positive integers $(a, b)$ such that $a$ occurs in $A$ at least $b... | {"inputs": ["3\n5\n1 2 3 4 5\n5\n1 1 2 2 3\n5\n3 3 2 2 2"], "outputs": ["1\n4\n3"]} | coding | 400 |
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 sequence of integers A_{1}, A_{2}, \ldots, A_{N} and an integer K. Find the number of contiguous subsequences A_{L}, A_{L+1}, \ldots, A_{R} such that R-L+1 ≥ K a... | {"inputs": ["1\n5 3\n1 2 3 4 5"], "outputs": ["1"]} | coding | 425 |
Solve the programming task below in a Python markdown code block.
Given an array (a list in Python) of integers and an integer `n`, find all occurrences of `n` in the given array and return another array containing all the index positions of `n` in the given array.
If `n` is not in the given array, return an empty arr... | {"functional": "_inputs = [[[6, 9, 3, 4, 3, 82, 11], 3], [[6, 9, 3, 4, 3, 82, 11], 99], [[10, 16, 20, 6, 14, 11, 20, 2, 17, 16, 14], 16], [[20, 20, 10, 13, 15, 2, 7, 2, 20, 3, 18, 2, 3, 2, 16, 10, 9, 9, 7, 5, 15, 5], 20]]\n_outputs = [[[2, 4]], [[]], [[1, 9]], [[0, 1, 8]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ... | coding | 160 |
Solve the programming task below in a Python markdown code block.
You are given an array of positive integers a_1, a_2, ..., a_{n} × T of length n × T. We know that for any i > n it is true that a_{i} = a_{i} - n. Find the length of the longest non-decreasing sequence of the given array.
-----Input-----
The first li... | {"inputs": ["1 1\n5\n", "1 1\n5\n", "1 1\n10\n", "1 1\n12\n", "2 1\n1 2\n", "2 2\n1 2\n", "2 2\n1 2\n", "2 1\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "3\n", "3\n", "2\n"]} | coding | 249 |
Solve the programming task below in a Python markdown code block.
Two red beads are placed between every two blue beads. There are N blue beads. After looking at the arrangement below work out the number of red beads.
@
@@
@
@@
@
@@
@
@@
@
@@
@
Implement count_red_beads(n) (in PHP count_red_beads($n); in Java, Javasc... | {"functional": "_inputs = [[0], [1], [3], [5]]\n_outputs = [[0], [0], [4], [8]]\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\... | coding | 144 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to fi... | {"inputs": ["0\n", "1\n", "1\n", "0\n", "110\n", "010\n", "000\n", "100\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "010\n", "010\n", "000\n", "100\n"]} | coding | 680 |
Solve the programming task below in a Python markdown code block.
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and... | {"inputs": ["4\n0 0\n3 0\n2 1\n0 3", "4\n0 0\n3 1\n2 1\n0 3", "4\n0 0\n3 0\n2 0\n0 3", "4\n0 0\n3 1\n2 0\n0 3", "4\n0 0\n3 1\n2 1\n0 2", "4\n0 0\n3 1\n2 3\n0 3", "4\n0 0\n3 1\n2 1\n-1 2", "4\n0 0\n3 1\n2 1\n-1 4"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "1", "0\n", "0\n"]} | coding | 316 |
Solve the programming task below in a Python markdown code block.
You are given two positive integer lists with a random number of elements (1 <= n <= 100). Create a [GCD](https://en.wikipedia.org/wiki/Greatest_common_divisor) matrix and calculate the average of all values.
Return a float value rounded to 3 decimal p... | {"functional": "_inputs = [[[1, 2, 3], [4, 5, 6]], [[5, 5, 5], [10, 10, 10]], [[4, 7, 2, 10, 99, 4], [55, 32, 1, 344, 35234, 3]]]\n_outputs = [[1.444], [5.0], [2.0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=... | coding | 210 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.
The numeric value... | {"functional": "def check(candidate):\n assert candidate(n = 3, k = 27) == \"aay\"\n assert candidate(n = 5, k = 73) == \"aaszz\"\n\n\ncheck(Solution().getSmallestString)"} | coding | 246 |
Solve the programming task below in a Python markdown code block.
Vishesh has gone to watch the new Spider-Man movie, but he is having troubles choosing which Popcorn-and-Coke combo to buy.
There are three combos A, B, and C available at the counter. You are given the time (in minute) for which each Popcorn bucket and... | {"inputs": ["3\n3 6\n5 10\n8 7\n99 1\n55 55\n33 51\n54 146\n5436 627\n1527 5421\n"], "outputs": ["15\n110\n6948\n"]} | coding | 623 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array colors, in which there are three colors: 1, 2 and 3.
You are also given some queries. Each query consists of two integers i and c, return the shortest distance between the given index i and the ... | {"functional": "def check(candidate):\n assert candidate(colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]]) == [3,0,3]\n assert candidate(colors = [1,2], queries = [[0,3]]) == [-1]\n\n\ncheck(Solution().shortestDistanceColor)"} | coding | 123 |
Solve the programming task below in a Python markdown code block.
ChefTown is the biggest city and the capital of ChefLand. There are N beautiful buildings: restaurants, museums, living houses with large kitchens and so on. Every building has its height. For every i (1≤i≤N) there is exactly one building with height i. ... | {"inputs": ["2 1\n2 1", "4 2\n1 2 3 4"], "outputs": ["2", "3"]} | coding | 490 |
Solve the programming task below in a Python markdown code block.
Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Help him fin... | {"inputs": ["1 \n4 \n4 4 7 6 \n"], "outputs": ["9"]} | coding | 412 |
Solve the programming task below in a Python markdown code block.
Bob has a string (S), which is initially empty. In one operation, he can select a lowercase character (a-z) uniformly at random and appends it to S. He then evaluates whether S is a palindrome or not; if it is, he gets 1 point.
Given that Bob performs ... | {"inputs": ["3\n2\n3\n4"], "outputs": ["576923082\n153846156\n214497044"]} | coding | 527 |
Solve the programming task below in a Python markdown code block.
You are given an undirected connected weighted graph consisting of $n$ vertices and $m$ edges. Let's denote the length of the shortest path from vertex $1$ to vertex $i$ as $d_i$.
You have to erase some edges of the graph so that at most $k$ edges rema... | {"inputs": ["3 3 2\n1 2 1\n3 2 1\n1 3 3\n", "3 3 2\n1 2 1\n3 2 1\n1 3 3\n", "4 4 0\n1 2 1\n2 3 1\n3 4 1\n1 4 2\n", "4 4 0\n1 2 1\n2 3 1\n3 4 1\n1 4 2\n", "4 4 0\n1 2 1\n2 3 1\n3 4 1\n1 4 0\n", "4 5 2\n4 1 8\n2 4 1\n2 1 3\n3 4 9\n3 1 5\n", "4 5 0\n4 1 8\n2 4 1\n2 1 3\n3 4 9\n3 1 5\n", "4 5 0\n4 1 8\n2 4 1\n2 1 3\n3 4 9\... | coding | 518 |
Solve the programming task below in a Python markdown code block.
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the char... | {"inputs": ["1\n<\n", "1\n>\n", "1\n>\n", "1\n<\n", "2\n<>\n", "2\n><\n", "2\n>>\n", "2\n<<\n"], "outputs": ["1\n", "1\n", "1", "1", "2\n", "0\n", "2\n", "2\n"]} | coding | 420 |
Solve the programming task below in a Python markdown code block.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in... | {"inputs": ["1 1\ny", "1 1\nz", "2 2\nba\nbb", "2 2\nab\nbb", "2 2\naa\nbc", "2 2\nbb\nbb", "2 0\nbb\nbb", "2 2\naa\nbb"], "outputs": ["Yes\n", "Yes", "No\n", "No\n", "No\n", "Yes\n", "Yes\n", "No"]} | coding | 299 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of words where each word consists of lowercase English letters.
wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of th... | {"functional": "def check(candidate):\n assert candidate(words = [\"a\",\"b\",\"ba\",\"bca\",\"bda\",\"bdca\"]) == 4\n assert candidate(words = [\"xbc\",\"pcxbcf\",\"xb\",\"cxbc\",\"pcxbc\"]) == 5\n assert candidate(words = [\"abcd\",\"dbqca\"]) == 1\n\n\ncheck(Solution().longestStrChain)"} | coding | 212 |
Solve the programming task below in a Python markdown code block.
A variation of determining leap years, assuming only integers are used and years can be negative and positive.
Write a function which will return the days in the year and the year entered in a string. For example 2000, entered as an integer, will retur... | {"functional": "_inputs = [[0], [-64], [2016], [1974], [-10], [666], [1857], [2000], [-300], [-1]]\n_outputs = [['0 has 366 days'], ['-64 has 366 days'], ['2016 has 366 days'], ['1974 has 365 days'], ['-10 has 365 days'], ['666 has 365 days'], ['1857 has 365 days'], ['2000 has 366 days'], ['-300 has 365 days'], ['-1 ha... | coding | 226 |
Solve the programming task below in a Python markdown code block.
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more t... | {"inputs": ["1 1 1 0 0\n", "4 1 2 2 0\n", "1 5 5 1 1\n", "1 2 3 0 0\n", "1 1 1 1 0\n", "9 1 4 2 0\n", "4 2 2 0 1\n", "8 3 4 2 0\n"], "outputs": ["1\n", "3\n", "1\n", "1\n", "1\n", "4\n", "3\n", "3\n"]} | coding | 482 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A super ugly number is a positive integer whose prime factors are in the array primes.
Given an integer n and an array of integers primes, return the nth super ugly number.
The nth super ugly number is guaranteed to f... | {"functional": "def check(candidate):\n assert candidate(n = 12, primes = [2,7,13,19]) == 32 \n assert candidate(n = 1, primes = [2,3,5]) == 1\n\n\ncheck(Solution().nthSuperUglyNumber)"} | coding | 108 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A transaction is possibly invalid if:
the amount exceeds $1000, or;
if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.
You are given an array of strings tra... | {"functional": "def check(candidate):\n assert candidate(transactions = [\"alice,20,800,mtv\",\"alice,50,100,beijing\"]) == [\"alice,20,800,mtv\",\"alice,50,100,beijing\"]\n assert candidate(transactions = [\"alice,20,800,mtv\",\"alice,50,1200,mtv\"]) == [\"alice,50,1200,mtv\"]\n assert candidate(transactions ... | coding | 144 |
Solve the programming task below in a Python markdown code block.
There were and still are many problem in CW about palindrome numbers and palindrome strings. We suposse that you know which kind of numbers they are. If not, you may search about them using your favourite search engine.
In this kata you will be given a ... | {"functional": "_inputs = [[11], [188], [191], [2541]]\n_outputs = [[22], [191], [202], [2552]]\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... | coding | 205 |
Solve the programming task below in a Python markdown code block.
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a seque... | {"inputs": ["4\n<<<\n<><\n<=>\n<=<"], "outputs": ["4\n2\n2\n3"]} | coding | 452 |
Solve the programming task below in a Python markdown code block.
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there e... | {"inputs": ["3 4", "3 6", "5 4", "3 1", "6 4", "4 6", "5 6", "3 2"], "outputs": ["6\n", "9\n", "15\n", "1\n", "21\n", "16\n", "25\n", "3\n"]} | coding | 246 |
Solve the programming task below in a Python markdown code block.
Create a function that will return ```true``` if the input is in the following date time format ```01-09-2016 01:20``` and ```false``` if it is not.
This Kata has been inspired by the Regular Expressions chapter from the book Eloquent JavaScript.
Also f... | {"functional": "_inputs = [['01-09-2016 01:20'], ['01-09-2016 01;20'], ['01_09_2016 01:20'], ['14-10-1066 12:00'], ['Tenth of January'], ['20 Sep 1988'], ['19-12-2050 13:34'], ['Tue Sep 06 2016 01:46:38 GMT+0100'], ['01-09-2016 00:00'], ['01-09-2016 2:00']]\n_outputs = [[True], [False], [False], [True], [False], [False... | coding | 98 |
Solve the programming task below in a Python markdown code block.
Chef has an array A of length N.
Chef forms a binary array B of length N using the parity of the sums of adjacent elements in A. Formally,
B_{i} = (A_{i} + A_{i+1}) \, \% \, 2 for 1 ≤ i ≤ N - 1
B_{N} = (A_{N} + A_{1}) \, \% \, 2
Here x \, \% \, y deno... | {"inputs": ["4\n2\n0 0\n2\n1 0\n4\n1 0 1 0\n3\n1 0 0\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | coding | 649 |
Solve the programming task below in a Python markdown code block.
There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the sa... | {"inputs": ["2\n1 5\n4 3", "2\n1 5\n3 3", "2\n1 5\n3 3\n", "3\n6 5\n-1 7\n3 3", "3\n0 5\n-1 7\n3 3", "3\n6 8\n-1 10\n3 3", "3\n6 5\n-1 10\n3 3", "3\n6 5\n-1 10\n3 3\n"], "outputs": ["3\n", "3", "3\n", "6\n", "4\n", "5\n", "5", "5\n"]} | coding | 524 |
Solve the programming task below in a Python markdown code block.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that poin... | {"inputs": ["3\n2 5 3", "3\n2 8 3", "3\n2 8 2", "3\n2 0 4", "3\n1 0 6", "3\n1 0 1", "3\n2 4 3", "12\n001 0 107 5 0 196 001 1 2 101 0 110"], "outputs": ["4\n", "7\n", "8\n", "2\n", "5\n", "0\n", "3", "94\n"]} | coding | 372 |
Solve the programming task below in a Python markdown code block.
For every positive integer N, there exists a unique sequence starting with 1 and ending with N and such that every number in the sequence is either the double of the preceeding number or the double plus 1.
For example, given N = 13, the sequence is [1,... | {"functional": "_inputs = [[1], [100], [12345], [54321]]\n_outputs = [[[1]], [[1, 3, 6, 12, 25, 50, 100]], [[1, 3, 6, 12, 24, 48, 96, 192, 385, 771, 1543, 3086, 6172, 12345]], [[1, 3, 6, 13, 26, 53, 106, 212, 424, 848, 1697, 3395, 6790, 13580, 27160, 54321]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstan... | coding | 187 |
Solve the programming task below in a Python markdown code block.
Given a lowercase Latin character (letter), check if it appears in the string ${codeforces}$.
-----Input-----
The first line of the input contains an integer $t$ ($1 \leq t \leq 26$) — the number of test cases.
The only line of each test case contain... | {"inputs": ["1\na\n", "1\ns\n", "2\na\na\n", "10\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\n", "26\nq\na\nz\nw\ns\nx\ne\nd\nc\nr\nf\nv\nt\ng\nb\ny\nh\nn\nu\nj\nm\ni\nk\no\nl\np\n"], "outputs": ["NO\n", "YES\n", "NO\nNO\n", "NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\n", "NO\nNO\nNO\nNO\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO... | coding | 215 |
Solve the programming task below in a Python markdown code block.
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and ... | {"inputs": ["1\n0\n", "1\n2\n", "1\n1\n", "1\n31\n", "1\n44\n", "1\n33\n", "1\n64\n", "1\n11\n"], "outputs": ["0\n", "0\n", "1\n", "31\n", "0\n", "33\n", "0\n", "11\n"]} | coding | 321 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Russian here
Polo, the Penguin, likes the XOR operation. Please read NOTE if you are not familiar with XOR operation.
XOR-sum of a list of numbers is the result of XOR-ing all of them. XOR-sum of (A[1] XOR A[2] XOR ... XOR A... | {"inputs": ["1\n2\n1 2", "1\n2\n1 2"], "outputs": ["6", "6"]} | coding | 606 |
Solve the programming task below in a Python markdown code block.
Bob has got some injury in his leg and due to this he can take exactly M steps in one move.
Bob enters a square field of size NxN. The field is only having one gate(for both entrance and exit) at its one of the corners. Bob started walking along the per... | {"inputs": ["2\n1\n2"], "outputs": ["2\n8"]} | coding | 471 |
Solve the programming task below in a Python markdown code block.
We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
- When A \mbox{ XOR } B is written i... | {"inputs": ["3\n1 2 1", "3\n1 4 1", "3\n2 2 3", "3\n1 1 1", "3\n1 4 2", "3\n1 7 1", "3\n1 2 3", "3\n1 2 3\n"], "outputs": ["6\n", "10\n", "2\n", "0\n", "14\n", "12\n", "6", "6\n"]} | coding | 388 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.