problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
"You must lift the dam. With a lever. I will give it to you.
You must block the canal. With a rock. I will not give the rock to you."
Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them.... | {"inputs": ["1\n1\n1000000000\n", "1\n1\n1000000000\n", "1\n1\n1000000001\n", "1\n1\n1000001001\n", "1\n1\n1000011001\n", "1\n1\n1000111001\n", "1\n1\n1000101001\n", "1\n1\n1000101101\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.
Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn... | {"inputs": ["2\n", "3\n", "4\n", "6\n", "5\n", "4\n", "6\n", "5\n"], "outputs": ["3\n2 1 2 ", "4\n2 1 3 2 ", "6\n2 4 1 3 2 4 ", "9\n2 4 6 1 3 5 2 4 6 ", "7\n2 4 1 3 5 2 4 ", "6\n2 4 1 3 2 4\n", "9\n2 4 6 1 3 5 2 4 6\n", "7\n2 4 1 3 5 2 4\n"]} | coding | 362 |
Solve the programming task below in a Python markdown code block.
Input
The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.
Output
Output "YES" or "NO".
Examples
Input
2 3
Output
YES
Input
3 2
Output
NO
Input
33 16
Output
YES
Input
26 5
Output
... | {"inputs": ["4 3\n", "2 2\n", "5 3\n", "2 4\n", "2 5\n", "1 9\n", "1 2\n", "9 4\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 103 |
Solve the programming task below in a Python markdown code block.
You will get an array of numbers.
Every preceding number is smaller than the one following it.
Some numbers will be missing, for instance:
```
[-3,-2,1,5] //missing numbers are: -1,0,2,3,4
```
Your task is to return an array of those missing numbers:
... | {"functional": "_inputs = [[[-3, -2, 1, 4]], [[-1, 0, 1, 2, 3, 4]], [[]], [[0]], [[-4, 4]]]\n_outputs = [[[-1, 0, 2, 3]], [[]], [[]], [[]], [[-3, -2, -1, 0, 1, 2, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_to... | coding | 120 |
Solve the programming task below in a Python markdown code block.
Complete the function that takes one argument, a list of words, and returns the length of the longest word in the list.
For example:
```python
['simple', 'is', 'better', 'than', 'complex'] ==> 7
```
Do not modify the input list.
Also feel free to reu... | {"functional": "_inputs = [[['simple', 'is', 'better', 'than', 'complex']], [['explicit', 'is', 'better', 'than', 'implicit']], [['beautiful', 'is', 'better', 'than', 'ugly']]]\n_outputs = [[7], [8], [9]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m... | coding | 93 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values:
0 represents an empty cell,
1 represents an obstacle that may be removed.
You can move up, down, left, or right from an... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,1],[1,1,0],[1,1,0]]) == 2\n assert candidate(grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]) == 0\n\n\ncheck(Solution().minimumObstacles)"} | coding | 150 |
Solve the programming task below in a Python markdown code block.
Akshat has X rupees to spend in the current month. His daily expenditure is Y rupees, i.e., he spends Y rupees each day.
Given that the current month has 30 days, find out if Akshat has enough money to meet his daily expenditures for this month.
-----... | {"inputs": ["3\n1000 10\n250 50\n1500 50\n"], "outputs": ["YES\nNO\nYES\n"]} | coding | 445 |
Solve the programming task below in a Python markdown code block.
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore... | {"inputs": ["1 2\n1\n", "1 5\n4\n", "1 5\n3\n", "1 8\n6\n", "1 7\n6\n", "1 9\n6\n", "1 8\n5\n", "1 6\n4\n"], "outputs": ["2\n0 1 ", "5\n0 1 2 3 4 ", "5\n0 1 2 3 4 ", "4\n0 2 4 6 ", "7\n0 1 2 3 4 5 6 ", "3\n0 3 6 ", "8\n0 1 2 3 4 5 6 7 ", "3\n0 2 4 "]} | coding | 703 |
Solve the programming task below in a Python markdown code block.
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and de... | {"inputs": ["3 2\n", "1 3\n", "4 3\n", "2 4\n", "2 4\n", "1 3\n", "4 3\n", "3 2\n"], "outputs": ["1 8", "1 1", "23 128", "29 32", "29 32", "1 1", "23 128", "1 8\n"]} | coding | 551 |
Solve the programming task below in a Python markdown code block.
You are given a board of size $n \times n$, where $n$ is odd (not divisible by $2$). Initially, each cell of the board contains one figure.
In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a s... | {"inputs": ["1\n2119\n", "1\n9693\n", "1\n2569\n", "1\n69791\n", "1\n69791\n", "1\n54111\n", "1\n39575\n", "1\n47045\n"], "outputs": ["3171549680\n", "303566175288\n", "5651594480\n", "113312287936960\n", "113312287936960\n", "52812341771840\n", "20660532731600\n", "34707166856360\n"]} | coding | 496 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A generic microwave supports cooking times for:
at least 1 second.
at most 99 minutes and 99 seconds.
To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by p... | {"functional": "def check(candidate):\n assert candidate(startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600) == 6\n assert candidate(startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76) == 6\n\n\ncheck(Solution().minCostSetTime)"} | coding | 368 |
Solve the programming task below in a Python markdown code block.
In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
- A level-0 burger is a patty.
- A level-L burger (L \geq... | {"inputs": ["2 1", "4 7", "0 1", "1 0", "8 7", "1 2", "2 5", "4 1"], "outputs": ["0\n", "3\n", "1\n", "0\n", "0\n", "1\n", "3\n", "0\n"]} | coding | 347 |
Solve the programming task below in a Python markdown code block.
# Task
Given a binary number, we are about to do some operations on the number. Two types of operations can be here:
* ['I', i, j] : Which means invert the bit from i to j (inclusive).
* ['Q', i] : Answer whether the i'th bit is 0 or 1.
The MSB (most... | {"functional": "_inputs = [['0011001100', [['I', 1, 10], ['I', 2, 7], ['Q', 2], ['Q', 1], ['Q', 7], ['Q', 5]]], ['1011110111', [['I', 1, 10], ['I', 2, 7], ['Q', 2], ['Q', 1], ['Q', 7], ['Q', 5]]], ['1011110111', [['I', 1, 10], ['I', 2, 7]]], ['0000000000', [['I', 1, 10], ['Q', 2]]]]\n_outputs = [[['0', '1', '1', '0']],... | coding | 375 |
Solve the programming task below in a Python markdown code block.
There is an N-car train.
You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back."
-----Constraints-----
- 1 \leq N \leq 100
- 1 \leq i \leq N
... | {"inputs": ["2 1", "2 2", "4 1", "2 0", "9 1", "1 1", "4 2", "4 2\n"], "outputs": ["2\n", "1\n", "4\n", "3\n", "9\n", "1", "3", "3\n"]} | coding | 148 |
Solve the programming task below in a Python markdown code block.
Let f(A, B), where A and B are positive integers, be the string satisfying the following conditions:
* f(A, B) has length A + B;
* f(A, B) contains exactly A letters `A` and exactly B letters `B`;
* The length of the longest substring of f(A, B) consist... | {"inputs": ["5\n2 6 1 5\n9 4 1 2\n2 3 6 4\n6 4 3 7\n7 2 5 8", "5\n1 6 1 5\n1 4 1 2\n2 3 6 3\n6 4 3 7\n8 2 5 8", "5\n1 6 1 5\n1 4 1 2\n2 3 6 3\n6 4 3 6\n8 2 5 8", "5\n1 6 1 5\n1 5 1 2\n2 3 6 1\n6 4 3 7\n8 2 5 7", "5\n1 6 1 5\n1 6 1 2\n2 3 6 1\n6 4 1 7\n8 2 5 7", "5\n1 6 1 5\n1 6 1 2\n2 3 6 1\n6 4 1 7\n8 4 5 7", "5\n0 6 ... | coding | 421 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in ... | {"inputs": ["3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4"], "outputs": ["0\n0\n3"]} | coding | 594 |
Solve the programming task below in a Python markdown code block.
We have two integers: A and B.
Print the largest number among A + B, A - B, and A \times B.
-----Constraints-----
- All values in input are integers.
- -100 \leq A,\ B \leq 100
-----Input-----
Input is given from Standard Input in the following forma... | {"inputs": ["0 0\n", "13 3\n", "91 0\n", "0 15\n", "10 1\n", "-13 3\n", "1 -33\n", "36 80\n"], "outputs": ["0\n", "39\n", "91\n", "15\n", "11\n", "-10\n", "34\n", "2880\n"]} | coding | 162 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.
A vertical area is an area of fixed-width extending infinitely along... | {"functional": "def check(candidate):\n assert candidate(points = [[8,7],[9,9],[7,4],[9,7]]) == 1\n assert candidate(points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]) == 3\n\n\ncheck(Solution().maxWidthOfVerticalArea)"} | coding | 140 |
Solve the programming task below in a Python markdown code block.
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of ... | {"inputs": ["2 4\n1 2\n", "2 2\n1 1\n", "2 3\n1 1\n", "2 9\n5 5\n", "2 1\n2 2\n", "2 1\n1 1\n", "2 4\n2 2\n", "2 9\n6 5\n"], "outputs": ["2.500000\n1.500000\n", "1.000000\n1.000000\n", "1.500000\n1.500000\n", "4.500000\n4.500000\n", "0.500000\n0.500000\n", "0.500000\n0.500000\n", "2.000000\n2.000000\n", "4.000000\n5.00... | coding | 534 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.
Please complete the following python code precisely:
```... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,1,2,3,1], target = 2) == 3\n assert candidate(nums = [-6,2,5,-2,-7,-1,3], target = -2) == 10\n\n\ncheck(Solution().countPairs)"} | coding | 99 |
Solve the programming task below in a Python markdown code block.
Alice has recently learned in her economics class that the market is said to be in equilibrium when the supply is equal to the demand.
Alice has market data for N time points in the form of two integer arrays S and D. Here, S_{i} denotes the supply at t... | {"inputs": ["2\n4\n1 2 3 4\n2 1 3 4\n4\n1 1 2 2\n1 2 1 1"], "outputs": ["2\n1"]} | coding | 438 |
Solve the programming task below in a Python markdown code block.
The restaurant AtCoder serves the following five dishes:
- ABC Don (rice bowl): takes A minutes to serve.
- ARC Curry: takes B minutes to serve.
- AGC Pasta: takes C minutes to serve.
- APC Ramen: takes D minutes to serve.
- ATC Hanbagu (hamburger p... | {"inputs": ["1\n1\n1\n1\n1\n", "29\n0\n8\n5\n22", "29\n0\n8\n5\n11", "29\n1\n8\n9\n11", "29\n0\n8\n10\n2", "29\n0\n8\n17\n2", "29\n-1\n8\n0\n3", "29\n0\n2\n-1\n3"], "outputs": ["41\n", "72\n", "61\n", "71\n", "52\n", "62\n", "43\n", "42\n"]} | coding | 527 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer num, return true if num is a perfect square or false otherwise.
A perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself.
... | {"functional": "def check(candidate):\n assert candidate(num = 16) == True\n assert candidate(num = 14) == False\n\n\ncheck(Solution().isPerfectSquare)"} | coding | 108 |
Solve the programming task below in a Python markdown code block.
Chef participated in a contest and got a rank X.
Chef is trying to find his name in the ranklist but there are too many pages.
Each page consists of 25 participants. Chef wants to find the exact page number which contains his name.
Help Chef find the... | {"inputs": ["4\n1\n34\n150\n74\n"], "outputs": ["1\n2\n6\n3\n"]} | coding | 381 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also ... | {"functional": "def check(candidate):\n assert candidate(intervals = [[1,3],[6,9]], newInterval = [2,5]) == [[1,5],[6,9]]\n assert candidate(intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]) == [[1,2],[3,10],[12,16]]\n\n\ncheck(Solution().insert)"} | coding | 185 |
Solve the programming task below in a Python markdown code block.
# Task
Given a string `str`, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome.
# Example
For `str = "abcdc"`, the output should be `"abcdcba"`.
# Input/Output
- `[in... | {"functional": "_inputs = [['abcdc'], ['ababab']]\n_outputs = [['abcdcba'], ['abababa']]\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): retu... | coding | 134 |
Solve the programming task below in a Python markdown code block.
New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $h$ hours and $m$ minutes, where $0 \le hh < 24$ and $0 \le mm < 60$. We use 24-hour time format!
Your task is to find th... | {"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n1 3\n", "1\n2 3\n", "1\n0 3\n", "1\n0 2\n", "1\n1 0\n", "1\n0 6\n"], "outputs": ["1378\n", "1378\n", "1377\n", "1317\n", "1437\n", "1438\n", "1380\n", "1434\n"]} | coding | 342 |
Solve the programming task below in a Python markdown code block.
M-kun is a brilliant air traffic controller.
On the display of his radar, there are N airplanes numbered 1, 2, ..., N, all flying at the same altitude.
Each of the airplanes flies at a constant speed of 0.1 per second in a constant direction. The curren... | {"inputs": ["2\n10 -1 U\n3 0 D", "2\n10 -1 U\n2 0 D", "2\n20 1 U\n11 47 D", "2\n20 1 U\n11 37 D", "2\n20 0 U\n11 37 D", "2\n20 0 U\n12 37 D", "2\n20 0 U\n12 70 D", "2\n10 0 U\n3 103 D"], "outputs": ["SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n", "SAFE\n"]} | coding | 574 |
Solve the programming task below in a Python markdown code block.
Chef has a string S with him. Chef is happy if the string contains a contiguous substring of length strictly greater than 2 in which all its characters are vowels.
Determine whether Chef is happy or not.
Note that, in english alphabet, vowels are a, e... | {"inputs": ["4\naeiou\nabxy\naebcdefghij\nabcdeeafg\n"], "outputs": ["Happy\nSad\nSad\nHappy\n"]} | coding | 405 |
Solve the programming task below in a Python markdown code block.
# Task
Let's call `product(x)` the product of x's digits. Given an array of integers a, calculate `product(x)` for each x in a, and return the number of distinct results you get.
# Example
For `a = [2, 8, 121, 42, 222, 23]`, the output should be `3`.... | {"functional": "_inputs = [[[2, 8, 121, 42, 222, 23]], [[239]], [[100, 101, 111]], [[100, 23, 42, 239, 22339, 9999999, 456, 78, 228, 1488]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]]\n_outputs = [[3], [1], [2], [10], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | coding | 332 |
Solve the programming task below in a Python markdown code block.
#It's show time!
Archers have gathered from all around the world to participate in the Arrow Function Faire. But the faire will only start if there are archers signed and if they all have enough arrows in their quivers - at least 5 is the requirement! Ar... | {"functional": "_inputs = [[[]], [[1, 2, 3, 4]], [[5, 6, 7, 8]], [[5, 6, 7, 4]], [[1, 2, 3, 4, 5, 6, 7, 8]]]\n_outputs = [[False], [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=tol, abs_tol=... | coding | 238 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le... | {"inputs": ["1\n6\n", "1\n6\n", "1\n2\n", "1\n1\n", "2\n1 1\n", "2\n3 9\n", "2\n1 1\n", "2\n3 9\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "3\n", "1\n", "3\n"]} | coding | 580 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
In this problem, a tree is an undirected graph that is connected and has no cycles.
You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two... | {"functional": "def check(candidate):\n assert candidate(edges = [[1,2],[1,3],[2,3]]) == [2,3]\n assert candidate(edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]) == [1,4]\n\n\ncheck(Solution().findRedundantConnection)"} | coding | 192 |
Solve the programming task below in a Python markdown code block.
In this kata you need to write a function that will receive two strings (```n1``` and ```n2```), each representing an integer as a binary number. A third parameter will be provided (```o```) as a string representing one of the following operators: add, s... | {"functional": "_inputs = [['1', '1', 'add'], ['1', '1', 'subtract'], ['1', '1', 'multiply'], ['10', '10', 'multiply'], ['100', '10', 'subtract']]\n_outputs = [['10'], ['0'], ['1'], ['100'], ['10']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.is... | coding | 216 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the ith monster... | {"functional": "def check(candidate):\n assert candidate(dist = [1,3,4], speed = [1,1,1]) == 3\n assert candidate(dist = [1,1,2,3], speed = [1,1,1,1]) == 1\n assert candidate(dist = [3,2,4], speed = [5,3,2]) == 1\n\n\ncheck(Solution().eliminateMaximum)"} | coding | 257 |
Solve the programming task below in a Python markdown code block.
Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way:
- The stud... | {"inputs": ["1\n2 6"], "outputs": ["3"]} | coding | 365 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit.
For example, if the path is 0 -> 1 -> 1 -> 0 -> 1,... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,0,1,0,1,0,1])) == 22\n assert candidate(root = tree_node([0])) == 0\n\n\ncheck(Solution().sumRootToLeaf)"} | coding | 228 |
Solve the programming task below in a Python markdown code block.
Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out!
Probably best have a sweepstake with your friends - because you have the best chance of knowing. Y... | {"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]]\n_outputs = [[3], [2], [6], [2], [-1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a... | coding | 270 |
Solve the programming task below in a Python markdown code block.
Take a sentence (string) and reverse each word in the sentence. Do not reverse the order of the words, just the letters in each word.
If there is punctuation, it should be interpreted as a regular character; no special rules.
If there is spacing before... | {"functional": "_inputs = [['How now brown cow'], ['racecar'], ['Hi mom'], [' '], [' '], ['go away'], ['I like noodles'], ['The red pen wrote on the wall'], ['Green trucks drive fast'], ['Pink trucks drive slow']]\n_outputs = [['woH won nworb woc'], ['racecar'], ['iH mom'], [' '], [' '], ['og yawa'], ['I ekil seldoon... | coding | 140 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a rooted tree with $N$ nodes (numbered $1$ through $N$); the root is node $1$. For each valid $i$, node $i$ has weight $w_{i}$, which i... | {"inputs": ["1\n3\n1 0 1\n1 2\n1 3"], "outputs": ["1"]} | coding | 585 |
Solve the programming task below in a Python markdown code block.
Sergey recently learned about country codes - two letter strings, denoting countries. For example, BY stands for Belarus and IN stands for India. Mesmerized by this new discovery, Sergey now looks for country codes everywhere!
Sergey has recently found a... | {"inputs": ["2\nINBY\nBYBY"], "outputs": ["3\n2"]} | coding | 292 |
Solve the programming task below in a Python markdown code block.
Heidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to escape to a nearby rebel base but the Doctor was very confused. Heidi... | {"inputs": ["1 1\n88372488\n74842436 22\n", "1 1\n88372488\n529378808 22\n", "1 1\n93269973\n529378808 22\n", "1 1\n93269973\n529378808 14\n", "1 1\n93269973\n858288489 14\n", "1 1\n93269973\n360212747 22\n", "1 1\n88372488\n319157478 348\n", "1 1\n88372488\n319157478 348\n"], "outputs": ["22\n", "0\n", "0\n", "0\n", "... | coding | 506 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.
For each index i, names[i] and heights[i] denote the name and height of the ith p... | {"functional": "def check(candidate):\n assert candidate(names = [\"Mary\",\"John\",\"Emma\"], heights = [180,165,170]) == [\"Mary\",\"Emma\",\"John\"]\n assert candidate(names = [\"Alice\",\"Bob\",\"Bob\"], heights = [155,185,150]) == [\"Bob\",\"Alice\",\"Bob\"]\n\n\ncheck(Solution().sortPeople)"} | coding | 115 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.
Please complete the following python code precisely:
```python
class Sol... | {"functional": "def check(candidate):\n assert candidate(s = \"foobar\", letter = \"o\") == 33\n assert candidate(s = \"jjjj\", letter = \"k\") == 0\n\n\ncheck(Solution().percentageLetter)"} | coding | 78 |
Solve the programming task below in a Python markdown code block.
Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers x, y are written on the blackboard. It is allo... | {"inputs": ["1 2 5\n", "0 1 8\n", "0 0 0\n", "0 0 1\n", "0 0 0\n", "0 0 1\n", "0 1 8\n", "0 0 0\n"], "outputs": ["2\n", "5\n", "0\n", "-1\n", "0\n", "-1\n", "5\n", "0\n"]} | coding | 401 |
Solve the programming task below in a Python markdown code block.
You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string s_{l}s_{l} + 1s_{l} + 2... s_{r}, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of o... | {"inputs": ["2\n10\n", "2\n01\n", "2\n01\n", "2\n10\n", "3\n111\n", "3\n011\n", "3\n110\n", "3\n001\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "0\n", "2\n", "2\n", "2\n"]} | coding | 284 |
Solve the programming task below in a Python markdown code block.
Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are digitised character recognition software... | {"functional": "_inputs = [['1F-RUDYARD K1PL1NG'], ['R0BERT MERLE - THE DAY 0F THE D0LPH1N'], ['R1CHARD P. FEYNMAN - THE FEYNMAN LECTURE5 0N PHY51C5'], ['R1CHARD P. FEYNMAN - 5TAT15T1CAL MECHAN1C5'], ['5TEPHEN HAWK1NG - A BR1EF H15T0RY 0F T1ME'], ['5TEPHEN HAWK1NG - THE UN1VER5E 1N A NUT5HELL'], ['ERNE5T HEM1NGWAY - A ... | coding | 147 |
Solve the programming task below in a Python markdown code block.
Given n number of people in a room, calculate the probability that any two people in that room have the same birthday (assume 365 days every year = ignore leap year). Answers should be two decimals unless whole (0 or 1) eg 0.05
Also feel free to reuse/ex... | {"functional": "_inputs = [[5], [15], [1], [365], [366]]\n_outputs = [[0.03], [0.25], [0], [1], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != ... | coding | 91 |
Solve the programming task below in a Python markdown code block.
For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows:
- Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations.
- Change S_i ... | {"inputs": ["2\n8 8", "2\n8 6", "2\n3 8", "2\n2 6", "2\n9 6", "2\n4 8", "2\n8 9", "2\n0 6"], "outputs": ["160\n", "136\n", "100\n", "72\n", "144\n", "112\n", "168\n", "48\n"]} | coding | 515 |
Solve the programming task below in a Python markdown code block.
Mr. Das is a teacher teaching for several years in a school. He is not computer savvy. Due to lockdown, now he has to take classes online. Recently he took an online exam for students of different classes. Now, he will call parents of all the students wh... | {"inputs": ["2\n3\nRahul 1345964789 47\nRupendra 1457856987 58\nPriya 1478569820 45\n2\nTanuja 4310779415 97\nAkash 3689781245 43"], "outputs": ["Priya 1478569820 45\nRahul 1345964789 47\nAkash 3689781245 43"]} | coding | 497 |
Solve the programming task below in a Python markdown code block.
Eshag has an array $a$ consisting of $n$ integers.
Eshag can perform the following operation any number of times: choose some subsequence of $a$ and delete every element from it which is strictly larger than $AVG$, where $AVG$ is the average of the numb... | {"inputs": ["1\n2\n1 2\n", "1\n2\n1 2\n", "1\n2\n0 2\n", "1\n2\n1 1\n", "1\n2\n1 4\n", "1\n2\n0 4\n", "1\n2\n1 6\n", "1\n2\n0 3\n"], "outputs": ["1\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 701 |
Solve the programming task below in a Python markdown code block.
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is ... | {"inputs": ["4 4\n1 2\n1 4\n1 3\n3 4", "4 4\n2 2\n1 4\n1 3\n3 4", "4 4\n1 2\n2 4\n1 3\n3 4", "5 5\n1 2\n5 5\n5 1\n3 4\n2 3", "5 1\n1 1\n6 5\n5 2\n3 4\n2 3", "5 1\n1 2\n5 5\n5 1\n3 4\n2 3", "5 1\n1 2\n6 5\n5 1\n3 4\n2 3", "5 1\n1 2\n6 5\n5 2\n3 4\n2 3"], "outputs": ["NO\n", "YES\n", "YES", "NO\n", "YES\n", "NO\n", "NO\n... | coding | 340 |
Solve the programming task below in a Python markdown code block.
In some other world, today is December D-th.
Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.
-----Constraints-----
- 22 \leq D \leq 25
- D is an integer.
-----... | {"inputs": ["4", "8", "6", "0", "1", "2", "3", "7"], "outputs": ["Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve\n", "Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve\n", "Christmas Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Eve Ev... | coding | 130 |
Solve the programming task below in a Python markdown code block.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size x_{i} × y_{i}. Each impression must be parallel to the sides of the... | {"inputs": ["2 2 2\n1 2\n2 1\n", "2 1 1\n1 1\n1 1\n", "2 1 2\n1 1\n1 1\n", "1 100 50\n4 20\n", "2 2 4\n3 1\n2 2\n", "2 2 4\n2 3\n2 1\n", "2 4 2\n1 2\n2 3\n", "2 1 4\n1 2\n1 2\n"], "outputs": ["4\n", "0\n", "2\n", "0\n", "0\n", "8\n", "8\n", "4\n"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
dot
The dot tool returns the dot product of two arrays.
import numpy
A = numpy.array([ 1, 2 ])
B = numpy.array([ 3, 4 ])
print numpy.dot(A, B) #Output : 11
cross
The cross tool returns the cross product of two arrays.
import numpy
A = numpy... | {"inputs": ["2\n1 2\n3 4\n1 2\n3 4\n"], "outputs": ["[[ 7 10]\n [15 22]]\n"]} | coding | 278 |
Solve the programming task below in a Python markdown code block.
Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty... | {"functional": "_inputs = [['3D2a5d2f'], ['4D1a8d4j3k'], ['4D2a8d4j2f'], ['3n6s7f3n'], ['0d4n8d2b'], ['0c3b1n7m'], ['7m3j4ik2a'], ['3A5m3B3Y'], ['5M0L8P1'], ['2B'], ['7M1n3K'], ['A4g1b4d'], ['111111'], ['4d324n2'], ['5919nf3u'], ['2n1k523n4i'], ['6o23M32d'], ['1B44n3r'], ['M21d1r32'], ['23M31r2r2'], ['8494mM25K2A'], ['... | coding | 302 |
Solve the programming task below in a Python markdown code block.
Alice has scored X marks in her test and Bob has scored Y marks in the same test. Alice is happy if she scored at least twice the marks of Bob’s score. Determine whether she is happy or not.
------ Input Format ------
- The first and only line of inpu... | {"inputs": ["2 1", "1 2"], "outputs": ["Yes", "No"]} | coding | 309 |
Solve the programming task below in a Python markdown code block.
It is the Indian version of the famous heist “The Italian Job”. N robbers have already broken into the National Museum and are just about to get inside the main vault which is full of jewels. They were lucky that just as they broke into the museum, the g... | {"inputs": ["2\n3 4\n2 4 2\n3 2\n2 4 2\n"], "outputs": ["YES\nNO\n"]} | coding | 548 |
Solve the programming task below in a Python markdown code block.
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.
Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps... | {"inputs": ["5 1 1 5\n1 1 1\n", "5 1 1 5\n1 1 1\n", "10 1 1 10\n1 5 6\n", "10 1 1 10\n1 5 6\n", "10 1 1 10\n1 9 6\n", "10 1 1 10\n1 2 6\n", "10 1 1 10\n1 7 6\n", "2 3 2 1\n1 1 2\n2 1 2\n4 1 2\n"], "outputs": ["XRRRR\n", "XRRRR", "RRRRRRRRR\n", "RRRRRRRRR", "RRRRRRRRR\n", "XRRRRRRRRR\n", "RRRRRRRRR\n", "XXL\n"]} | coding | 719 |
Solve the programming task below in a Python markdown code block.
We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls.
Ta... | {"inputs": ["3\nBBBGGGRRR", "3\nRRRBGGBGB", "3\nBRRGGGRBB", "3\nBGRGGRRBB", "3\nRGRBGRBGB", "3\nBBBGGRRGR", "3\nBBGBGRRRG", "3\nBBGBGGRRR"], "outputs": ["216", "36", "12", "24", "6", "72", "48", "144"]} | coding | 379 |
Solve the programming task below in a Python markdown code block.
The ugliness of a sequence of size N is defined as the number of pairs of neighboring elements which are not equal to each other. Formally, the ugliness of a sequence increase by 1 if for a value of i, 2 ≤ i ≤ N, the following condition holds true:
A_{i}... | {"inputs": ["2\n8 2\n1 2 1 2 2 2 1 2\n8 3\n1 2 2 1 1 1 2 3"], "outputs": ["0 0\n1 1 3\n"]} | coding | 700 |
Solve the programming task below in a Python markdown code block.
Monocarp wants to watch $n$ videos. Each video is only one minute long, but its size may be arbitrary. The $i$-th video has the size $a_i$ megabytes. All videos are published on the Internet. A video should be downloaded before it can be watched. Monocar... | {"inputs": ["1 1\n1\n", "1 294\n132\n", "2 15\n14 1\n", "2 15\n14 2\n", "4 3\n1 3 2 3\n", "5 6\n1 2 3 4 5\n", "5 5\n1 2 3 4 5\n", "4 100\n11 3 3 6\n"], "outputs": ["2\n", "133\n", "16\n", "18\n", "12\n", "16\n", "17\n", "24\n"]} | coding | 584 |
Solve the programming task below in a Python markdown code block.
DZY has a sequence a, consisting of n integers.
We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment o... | {"inputs": ["1\n1\n", "1\n3\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n5\n", "1\n4\n", "1\n42\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 287 |
Solve the programming task below in a Python markdown code block.
Welcome young Jedi! In this Kata you must create a function that takes an amount of US currency in `cents`, and returns a dictionary/hash which shows the least amount of coins used to make up that amount. The only coin denominations considered in this ex... | {"functional": "_inputs = [[56], [0], [100], [-3], [7.9]]\n_outputs = [[{'Nickels': 1, 'Pennies': 1, 'Dimes': 0, 'Quarters': 2}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 4}], [{'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}], [{'Nickels': ... | coding | 315 |
Solve the programming task below in a Python markdown code block.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone co... | {"inputs": ["2\n4\n9\n", "2\n1\n0\n", "2\n2\n0\n", "2\n2\n1\n", "2\n3\n9\n", "2\n0\n2\n", "2\n3\n1\n", "2\n3\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 499 |
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.
We say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < ... < indexk < nums.length for which nums[index1] | nums[index2] | ..... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1]) == 4\n assert candidate(nums = [5,3,2]) == 1\n\n\ncheck(Solution().minImpossibleOR)"} | coding | 156 |
Solve the programming task below in a Python markdown code block.
Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is describe... | {"inputs": ["a\n0\n", "b\n0\n", "a\n0\n", "aaab\n2\naa 0 0\naab 1 1\n", "aaab\n2\naa 0 0\nbaa 1 1\n", "aaab\n2\naa 0 0\naab 2 1\n", "aaab\n2\naa 1 0\naab 2 1\n", "aaab\n2\naa 1 1\naab 2 1\n"], "outputs": ["1\n", "1\n", "1\n", "3\n", "1\n", "0\n", "0\n", "0\n"]} | coding | 751 |
Solve the programming task below in a Python markdown code block.
To get on the Shinkansen, you need two tickets, a "ticket" and a "limited express ticket". These are separate tickets because some of the routes may not use the Shinkansen, but for routes that use only the Shinkansen, one ticket can be used as both a tic... | {"inputs": ["0 0 0", "1 1 0", "1 0 0", "0 1 0", "0 0 0", "0 1 0", "1 0 0", "1 1 0"], "outputs": ["Close\n", "Open\n", "Close\n", "Close\n", "Close\n", "Close\n", "Close\n", "Open\n"]} | coding | 416 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.
In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest p... | {"functional": "def check(candidate):\n assert candidate(a = 1, b = 2, c = 5) == [1, 2]\n assert candidate(a = 4, b = 3, c = 2) == [0, 0]\n\n\ncheck(Solution().numMovesStones)"} | coding | 246 |
Solve the programming task below in a Python markdown code block.
Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i and j i.e a... | {"inputs": ["aba", "aabcaaa"], "outputs": ["1", "4"]} | coding | 287 |
Solve the programming task below in a Python markdown code block.
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N].
In a single operation on the array, he performs the following two steps :
- Pick two indices i, j s.t. A[i] > A[j]
- A[i] -= A[j]
Sereja can apply these operations any num... | {"inputs": ["2\n1\n1\n3\n2 4 6"], "outputs": ["1\n6"]} | coding | 421 |
Solve the programming task below in a Python markdown code block.
Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked $n$ of them how much effort they needed to reach red.
"Oh, I just spent $x_i$ hours solving ... | {"inputs": ["1\n8\n", "1\n2\n", "1\n13\n", "1\n15\n", "1\n26\n", "1\n76\n", "1\n900\n", "1\n300\n"], "outputs": ["cyan\n", "cyan\n", "cyan\n", "cyan\n", "cyan\n", "cyan\n", "red\n", "red\n"]} | coding | 702 |
Solve the programming task below in a Python markdown code block.
There are N computers and N sockets in a one-dimensional world. The coordinate of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It is guaranteed that these 2N coordinates are pairwise distinct.
Snuke wants to connect each compu... | {"inputs": ["2\n-1\n1\n7\n78", "2\n1\n11\n4\n68", "2\n0\n2\n3\n312", "2\n0\n2\n20\n48", "2\n2\n11\n4\n68", "2\n1\n2\n3\n312", "2\n0\n2\n20\n56", "2\n0\n2\n21\n78"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n"]} | coding | 255 |
Solve the programming task below in a Python markdown code block.
Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the spoon and r... | {"inputs": ["3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky", "3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\njhfdb\ncacac\nopqrs\nddddd\nindia\nyucky", "3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naa... | coding | 487 |
Solve the programming task below in a Python markdown code block.
God's Blessing on This PermutationForces!
A Random Pebble
You are given a permutation $p_1,p_2,\ldots,p_n$ of length $n$ and a positive integer $k \le n$.
In one operation you can choose two indices $i$ and $j$ ($1 \le i < j \le n$) and swap $p_i$ wit... | {"inputs": ["4\n3 1\n2 3 1\n3 3\n1 2 3\n4 2\n3 4 1 2\n1 1\n1\n"], "outputs": ["1\n0\n2\n0\n"]} | coding | 550 |
Solve the programming task below in a Python markdown code block.
There is a town with N people and initially, the i^{th} person has A_{i} coins. However, some people of the town decide to become *monks*. If the i^{th} person becomes a monk, then:
He leaves the town thereby reducing the number of people in the town by ... | {"inputs": ["3\n4\n6 6 6 6\n3\n5 1 4\n5\n2 1 2 1 1\n"], "outputs": ["0\n1\n2\n"]} | coding | 666 |
Solve the programming task below in a Python markdown code block.
You have an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. You are allowed to perform the following operation on it:
Choose two elements from the array $a_i$ and $a_j$ ($i \ne j$) such that $\gcd(a_i, a_j)$ is not present in the array... | {"inputs": ["3\n6 10 15\n", "2\n1 1000000\n", "5\n4 20 1 25 30\n", "7\n838695 559130 335478 98670 152490 129030 72930\n", "10\n239529 302993 398153 204081 370085 184103 337965 450634 411842 217101\n", "57\n241 444 553 126 612 550 441 420 742 879 520 664 590 198 910 731 308 740 791 680 904 629 324 606 621 75 350 253 57 ... | coding | 507 |
Solve the programming task below in a Python markdown code block.
Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calcul... | {"inputs": ["1 1\nV\n", "1 1\nV\n", "1 1\nU\n", "2 1\nWT\n", "2 2\nBL\n", "2 2\nBL\n", "2 1\nWT\n", "2 2\nLB\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n"]} | coding | 277 |
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
This year CodeChef is organizing the SnackUp cooking contest. The favorite to win is of course our beautiful Chef Ada.
There are n judges in the contest, and for simplicity ... | {"inputs": ["1\n2"], "outputs": ["2\n2\n1 1 2\n2 1 2\n2\n1 1 2\n2 1 2"]} | coding | 498 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sometimes mysteries happen. Chef found a directed graph with N vertices and M edges in his kitchen!
The evening was boring and chef has nothing else to do, so to entertain himself, Chef though... | {"inputs": ["7 7\n1 2 \n3 2\n3 4\n7 4\n6 2\n5 6\n7 5", "7 7\n1 2 \n4 2\n3 4\n7 4\n6 2\n5 6\n7 5", "9 7\n1 2 \n4 2\n3 4\n7 4\n6 2\n5 6\n7 5", "7 7\n1 2 \n3 2\n2 4\n7 4\n6 2\n5 6\n7 5", "7 7\n1 2 \n3 2\n2 4\n4 4\n6 2\n5 6\n7 5", "8 7\n1 4 \n2 2\n3 4\n7 4\n6 2\n4 8\n7 6", "7 7\n1 2 \n3 2\n3 4\n7 4\n6 2\n5 6\n5 5", "7 7\n1... | coding | 451 |
Solve the programming task below in a Python markdown code block.
Given some positive integers, I wish to print the integers such that all take up the same width by adding a minimum number of leading zeroes. No leading zeroes shall be added to the largest integer.
For example, given `1, 23, 2, 17, 102`, I wish to prin... | {"functional": "_inputs = [[2], [1, 12, 34], [1009, 2], [1, 1, 13], [2, 5, 8], [1, 8, 27]]\n_outputs = [['2'], ['01\\n12\\n34'], ['1009\\n0002'], ['01\\n01\\n13'], ['2\\n5\\n8'], ['01\\n08\\n27']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | coding | 165 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of n strings strs, all of the same length.
We may choose any deletion indices, and we delete all the characters in those indices for each string.
For example, if we have strs = ["abcdef","uvwxyz... | {"functional": "def check(candidate):\n assert candidate(strs = [\"babca\",\"bbazb\"]) == 3\n assert candidate(strs = [\"edcba\"]) == 4\n assert candidate(strs = [\"ghi\",\"def\",\"abc\"]) == 0\n\n\ncheck(Solution().minDeletionSize)"} | coding | 240 |
Solve the programming task below in a Python markdown code block.
Gotham City is the home of Batman, and Batman likes to keep his people together.
There are N houses in the city. The resident of the i^{th} house is of type A_{i}. It is known that people of the same type are friends and people of different types are n... | {"inputs": ["3\n4\naaaa\n4\nabca\n7\nbabbaab\n"], "outputs": ["4 4 4 4 4\n1 2 2 2 2\n2 3 4 4 4 4 4 4\n"]} | coding | 548 |
Solve the programming task below in a Python markdown code block.
Algorithmic predicament - Bug Fixing #9
Oh no! Timmy's algorithim has gone wrong! help Timmy fix his algorithim!
Task
Your task is to fix timmy's algorithim so it returns the group name with the highest total age.
You will receive two groups of `peo... | {"functional": "_inputs = [[[{'name': 'kay', 'age': 1}, {'name': 'john', 'age': 13}, {'name': 'kay', 'age': 76}], [{'name': 'john', 'age': 1}, {'name': 'alice', 'age': 77}]], [[{'name': 'kay', 'age': 1}, {'name': 'john', 'age': 13}, {'name': 'kay', 'age': 76}], [{'name': 'john', 'age': 1}, {'name': 'alice', 'age': 76}]... | coding | 179 |
Solve the programming task below in a Python markdown code block.
A number K$K$ is said to be magical if it can be represented as a power of 2 only.That is K$K$=2x$2^{x}$ for some natural number x$x$.
Given a string of digits S$S$ of length N$N$, Let P be a valid arrangement of S.
By valid arrangement we mean that it ... | {"inputs": ["2\n35566\n31"], "outputs": ["65536\n-1"]} | coding | 471 |
Solve the programming task below in a Python markdown code block.
There is a task in Among Us in which $N$ temperature scale with unique readings are given and you have to make all of them equal. In one second you can choose an odd number and add or subtract that number in any one temperature value. Find minimum time (... | {"inputs": ["3\n5\n1 2 3 4 5\n4\n5 2 3 8\n2\n50 53"], "outputs": ["5\n4\n1"]} | coding | 346 |
Solve the programming task below in a Python markdown code block.
Let's call a string good if its length is at least $2$ and all of its characters are ${A}$ except for the last character which is ${B}$. The good strings are ${AB},{AAB},{AAAB},\ldots$. Note that ${B}$ is not a good string.
You are given an initially em... | {"inputs": ["4\nAABAB\nABB\nAAAAAAAAB\nA\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
3:33
It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. ... | {"inputs": ["6\n3 99\n9 14\n47 4\n6 6\n1 13\n1 4", "6\n3 99\n5 14\n47 4\n6 6\n1 13\n1 4", "6\n3 20\n5 14\n47 4\n6 6\n1 13\n1 4", "6\n3 20\n5 14\n47 4\n6 6\n2 13\n1 4", "6\n1 20\n5 14\n37 4\n6 6\n2 16\n1 4", "6\n5 99\n9 10\n47 11\n6 4\n1 13\n1 4", "6\n5 99\n9 10\n47 11\n6 6\n1 13\n1 4", "6\n3 99\n9 10\n47 11\n6 6\n1 13\... | coding | 631 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A distinct string is a string that is present only once in an array.
Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return a... | {"functional": "def check(candidate):\n assert candidate(arr = [\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"], k = 2) == \"a\"\n assert candidate(arr = [\"aaa\",\"aa\",\"a\"], k = 1) == \"aaa\"\n assert candidate(arr = [\"a\",\"b\",\"a\"], k = 3) == \"\"\n\n\ncheck(Solution().kthDistinct)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
"Everybody! Doremy's Perfect Math Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's math class, Doremy is teaching everyone subtraction. Now she gives you a quiz to prove that you are paying attention in cla... | {"inputs": ["2\n2\n1 2\n3\n5 10 25\n"], "outputs": ["2\n5\n"]} | coding | 610 |
Solve the programming task below in a Python markdown code block.
Chef got his dream seat in F1 and secured a 3^{rd} place in his debut race. He now wants to know the time gap between him and the winner of the race.
You are his chief engineer and you only know the time gap between Chef and the runner up of the race, g... | {"inputs": ["4\n1 1\n2 5\n3 2\n5 6\n"], "outputs": ["2\n7\n5\n11\n"]} | coding | 500 |
Solve the programming task below in a Python markdown code block.
We have a sequence of N integers: A_1, A_2, \cdots, A_N.
You can perform the following operation between 0 and K times (inclusive):
- Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly ... | {"inputs": ["2 1\n3 5", "2 3\n2 1", "2 2\n3 5", "2 2\n3 1", "2 2\n6 1", "2 3\n6 1", "2 4\n6 1", "2 6\n2 1"], "outputs": ["4\n", "3\n", "4\n", "4\n", "7\n", "7\n", "7\n", "3\n"]} | coding | 324 |
Solve the programming task below in a Python markdown code block.
You are given a string S of length n with each character being one of the first m lowercase English letters.
Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of LCS (longe... | {"inputs": ["1 2\nb\n", "1 3\nb\n", "1 1\na\n", "1 5\nc\n", "1 2\na\n", "1 26\nz\n", "1 26\ny\n", "1 36\ny\n"], "outputs": ["1\n", "2\n", "0\n", "4\n", "1\n", "25\n", "25\n", "35\n"]} | coding | 320 |
Solve the programming task below in a Python markdown code block.
The aim of the kata is to try to show how difficult it can be to calculate decimals of an irrational number with a certain precision. We have chosen to get a few decimals of the number "pi" using
the following infinite series (Leibniz 1646–1716):
PI / ... | {"functional": "_inputs = [[0.1], [0.01], [0.001], [0.0001], [1e-05], [1e-06]]\n_outputs = [[[10, 3.0418396189]], [[100, 3.1315929036]], [[1000, 3.1405926538]], [[10000, 3.1414926536]], [[100001, 3.1416026535]], [[1000001, 3.1415936536]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins... | coding | 498 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing tha... | {"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2) == 0.25000\n assert candidate(n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2) == 0.30000\n assert candidate(n = 3, edges = [[0,1]], succPr... | coding | 207 |
Solve the programming task below in a Python markdown code block.
You are given an array A of N integers . You want to convert the array A into a permutation of N integers. To do this, you can apply the following operation on array A exactly once .
Pick an integer X, where 1 ≤ X ≤ 2\cdot 10^{7}. For each i , 1 ≤ i ≤ N... | {"inputs": ["2\n3\n2 7 1\n2\n2 2"], "outputs": ["YES 4\nNO"]} | coding | 528 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)". Then, we removed all commas, decimal points, and spaces and ended up with the string s.
For example, "(1, 3)" becomes s = "(13)" and "(2, 0.5)" beco... | {"functional": "def check(candidate):\n assert candidate(s = \"(123)\") == [\"(1, 2.3)\",\"(1, 23)\",\"(1.2, 3)\",\"(12, 3)\"]\n assert candidate(s = \"(0123)\") == [\"(0, 1.23)\",\"(0, 12.3)\",\"(0, 123)\",\"(0.1, 2.3)\",\"(0.1, 23)\",\"(0.12, 3)\"]\n assert candidate(s = \"(00011)\") == [\"(0, 0.011)\",\"(0.... | coding | 262 |
Solve the programming task below in a Python markdown code block.
Let $\mathsf{AND}$ denote the bitwise AND operation , and $\mathsf{OR}$ denote the bitwise OR operation .
You are given an array $a$ of length $n$ and a non-negative integer $k$. You can perform at most $k$ operations on the array of the following type:... | {"inputs": ["4\n3 2\n2 1 1\n7 0\n4 6 6 28 6 6 12\n1 30\n0\n4 4\n3 1 3 1\n"], "outputs": ["2\n4\n2147483646\n1073741825\n"]} | coding | 646 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given an integer sequence $A$ with length $N$.
Find the number of (unordered) pairs of elements such that the average of these two elements is also present in the se... | {"inputs": ["3\n2\n2 2\n3\n2 1 3\n6\n4 2 5 1 3 5"], "outputs": ["1\n1\n7"]} | coding | 486 |
Solve the programming task below in a Python markdown code block.
Write a regex to validate a 24 hours time string.
See examples to figure out what you should check for:
Accepted:
01:00 - 1:00
Not accepted:
24:00
You should check for correct length and no spaces.
Also feel free to reuse/extend the following start... | {"functional": "_inputs = [['1:00'], ['13:1'], ['12:60'], ['12: 60'], ['24:00'], ['00:00'], ['24o:00'], ['24:000'], [''], ['09:00'], ['2400'], ['foo12:00bar'], ['010:00'], ['1;00']]\n_outputs = [[True], [False], [False], [False], [False], [True], [False], [False], [False], [True], [False], [False], [False], [False]]\ni... | coding | 91 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.