task_type
stringclasses 1
value | problem
stringlengths 261
3.34k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 62
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Solve the programming task below in a Python markdown code block.
Given an array $a$ of length $n$ and an integer $k$, you are tasked to find any two numbers $l$ and $r$ ($l \leq r$) such that:
For each $x$ $(l \leq x \leq r)$, $x$ appears in $a$ at least $k$ times (i.e. $k$ or more array elements are equal to $x$).
The value $r-l$ is maximized.
If no numbers satisfy the conditions, output -1.
For example, if $a=[11, 11, 12, 13, 13, 14, 14]$ and $k=2$, then:
for $l=12$, $r=14$ the first condition fails because $12$ does not appear at least $k=2$ times.
for $l=13$, $r=14$ the first condition holds, because $13$ occurs at least $k=2$ times in $a$ and $14$ occurs at least $k=2$ times in $a$.
for $l=11$, $r=11$ the first condition holds, because $11$ occurs at least $k=2$ times in $a$.
A pair of $l$ and $r$ for which the first condition holds and $r-l$ is maximal is $l = 13$, $r = 14$.
-----Input-----
The first line of the input contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of test cases follows.
The first line of each test case contains the integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $1 \leq k \leq n$) — the length of the array $a$ and the minimum amount of times each number in the range $[l, r]$ should appear respectively.
Then a single line follows, containing $n$ integers describing the array $a$ ($1 \leq a_i \leq 10^9$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case output $2$ numbers, $l$ and $r$ that satisfy the conditions, or "-1" if no numbers satisfy the conditions.
If multiple answers exist, you can output any.
-----Examples-----
Input
4
7 2
11 11 12 13 13 14 14
5 1
6 3 5 2 1
6 4
4 3 4 3 3 4
14 2
1 1 2 2 2 3 3 3 3 4 4 4 4 4
Output
13 14
1 3
-1
1 4
-----Note-----
None
|
{"inputs": ["1\n1 1\n114514\n", "4\n7 2\n11 11 12 13 13 14 14\n5 1\n6 3 5 2 1\n6 4\n4 3 4 3 3 4\n14 2\n1 1 2 2 2 3 3 3 3 4 4 4 4 4\n"], "outputs": ["114514 114514\n", "13 14\n1 3\n-1\n1 4\n"]}
| 679
| 148
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array A of size N.
A partitioning of the array A is the splitting of A into one or more non-empty contiguous subarrays such that each element of A belongs to exactly one of these subarrays.
Find the number of ways to partition A such that the parity of the sum of elements within the subarrays is alternating. In other words, if S_{i} denotes the sum of the elements in the i-th subarray, then either
S_{1} is odd, S_{2} is even, S_{3} is odd and so on.
or S_{1} is even, S_{2} is odd, S_{3} is even and so on.
For example if A = [1, 2, 3, 3, 5]. One way to partition A is [1, 2] [3, 3] [5]. Another way to partition A is [1] [2] [3] [3, 5]. Note that there exists more ways to partition this array.
Since the answer may be large, output it modulo 998244353.
------ Input Format ------
- The first line contains a single integer T - the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N - the size of the array A.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A.
------ Output Format ------
For each test case, output the answer modulo 998244353.
------ Constraints ------
$1 ≤ T ≤ 10000$
$1 ≤ N ≤ 2 \cdot 10^{5} $
$0 ≤ A_{i} ≤ 10^{9} $
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
----- Sample Input 1 ------
3
3
1 2 3
4
4 4 4 4
5
1 2 3 3 5
----- Sample Output 1 ------
2
1
5
----- explanation 1 ------
Test case 1: The array can be partitioned as follows
- $[1] [2] [3]$
- $[1, 2, 3]$
Test case 2: The array can be partitioned as follows
- $[4, 4, 4, 4]$
|
{"inputs": ["3\n3\n1 2 3\n4\n4 4 4 4\n5\n1 2 3 3 5"], "outputs": ["2\n1\n5\n"]}
| 552
| 47
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
Return the length of n. If there is no such n, return -1.
Note: n may not fit in a 64-bit signed integer.
Please complete the following python code precisely:
```python
class Solution:
def smallestRepunitDivByK(self, k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(k = 1) == 1\n assert candidate(k = 2) == -1\n assert candidate(k = 3) == 3\n\n\ncheck(Solution().smallestRepunitDivByK)"}
| 118
| 60
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered both chandeliers that can change its color cyclically. For example: red – brown – yellow – red – brown – yellow and so on.
There are many chandeliers that differs in color set or order of colors. And the person responsible for the light made a critical mistake — they bought two different chandeliers.
Since chandeliers are different, some days they will have the same color, but some days — different. Of course, it looks poor and only annoys Vasya. As a result, at the $k$-th time when chandeliers will light with different colors, Vasya will become very angry and, most probably, will fire the person who bought chandeliers.
Your task is to calculate the day, when it happens (counting from the day chandeliers were installed). You can think that Vasya works every day without weekends and days off.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 500000$; $1 \le k \le 10^{12}$) — the number of colors in the first and the second chandeliers and how many times colors should differ to anger Vasya.
The second line contains $n$ different integers $a_i$ ($1 \le a_i \le 2 \cdot \max(n, m)$) that describe the first chandelier's sequence of colors.
The third line contains $m$ different integers $b_j$ ($1 \le b_i \le 2 \cdot \max(n, m)$) that describe the second chandelier's sequence of colors.
At the $i$-th day, the first chandelier has a color $a_x$, where $x = ((i - 1) \mod n) + 1)$ and the second one has a color $b_y$, where $y = ((i - 1) \mod m) + 1)$.
It's guaranteed that sequence $a$ differs from sequence $b$, so there are will be days when colors of chandeliers differs.
-----Output-----
Print the single integer — the index of day when Vasya will become angry.
-----Examples-----
Input
4 2 4
4 2 3 1
2 1
Output
5
Input
3 8 41
1 3 2
1 6 4 3 5 7 2 8
Output
47
Input
1 2 31
1
1 2
Output
62
-----Note-----
In the first example, the chandeliers will have different colors at days $1$, $2$, $3$ and $5$. That's why the answer is $5$.
|
{"inputs": ["1 2 1\n1\n2 1\n", "1 2 1\n1\n2 1\n", "1 2 1\n2\n2 1\n", "1 2 31\n1\n1 2\n", "1 2 23\n1\n1 2\n", "1 2 31\n1\n1 2\n", "2 2 2\n2 1\n1 2\n", "2 2 2\n2 1\n1 2\n"], "outputs": ["1\n", "1\n", "2\n", "62\n", "46\n", "\n62\n", "2\n", "2\n"]}
| 660
| 161
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.
Given an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array. The elements in original may be returned in any order.
Please complete the following python code precisely:
```python
class Solution:
def findOriginalArray(self, changed: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(changed = [1,3,4,2,6,8]) == [1,3,4]\n assert candidate(changed = [6,3,0,1]) == []\n assert candidate(changed = [1]) == []\n\n\ncheck(Solution().findOriginalArray)"}
| 119
| 80
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
The Physics teacher in Tanu's class is teaching concepts of a bouncing ball. The rubber ball that she is using has the property that if the ball is dropped from height H then, it bounces back to maximum height H/F. So after first bounce it rises up to maximum height H/F, after second bounce to maximum height H/F^{2}, after third bounce to maximum height H/F^{3}, and so on.
The class has N children, and the teacher wants to select two children such that when the taller child drops the ball from his height, ball reaches a maximum height equal to the height of the shorter child after some (possibly zero) number of bounces. Note that zero bounces mean heights of the two children will be same. Given the heights of the children in the class Height[i], can you tell how many ways are there for the teacher to select two children for the demonstration? Note that when heights are same, the pair is only counted once (See first example for further clarification).
------ Input ------
First line contains T, number of testcases. Then 2*T lines follow, 2 per testcase.
First line of each testcase consists of two space-separated intergers N and F. Second line of each testcase contains N space-separated integers representing the array Height.
------ Output ------
For each testcase, print a single line containing the answer to the problem.
------ Constraints ------
$For 40 points: 1 ≤ T ≤ 100, 1 ≤ N ≤ 10^{3}, 2 ≤ F ≤ 10^{9}, 1 ≤ Height[i] ≤ 10^{9}
$$For 60 points: 1 ≤ T ≤ 100, 1 ≤ N ≤ 10^{4}, 2 ≤ F ≤ 10^{9}, 1 ≤ Height[i] ≤ 10^{9}$
----- Sample Input 1 ------
2
3 2
2 2 2
3 2
2 1 4
----- Sample Output 1 ------
3
3
----- explanation 1 ------
In the first case, the three pairs are (child 1, child 2), (child 2, child 3) and (child 1, child 3).
For the second case also, the three pairs are (child 1, child 2), (child 2, child 3) and (child 1, child 3).
|
{"inputs": ["2\n3 2\n2 2 2\n3 2\n2 1 4"], "outputs": ["3\n3"]}
| 534
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game:
Let's define f(n) as the sum of all odd divisors of n. I.e. f(10) = 1 + 5 = 6 and f(21) = 1 + 3 + 7 + 21 = 32. The game is to calculate f(l) + f(l + 1) + ... + f(r - 1) + f(r) for the given integers l and r.
Have fun! But be careful, the integers might be quite big.
------ Input ------
The first line of the input contains one integer T denoting the number of test cases.
The only line of the test case description contains two positive integers l and r.
------ Output ------
For each test case, output the required sum on a separate line.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ l ≤ r ≤ 10^{5}$
----- Sample Input 1 ------
2
1 10
42 42
----- Sample Output 1 ------
45
32
----- explanation 1 ------
In the first example case, f(1) + f(2) + ... + f(10) = 1 + 1 + 4 + 1 + 6 + 4 + 8 + 1 + 13 + 6 = 45
In the second example case, f(42) = 32.
|
{"inputs": ["2\n2 4\n6 8", "2\n4 4\n6 8", "2\n2 7\n6 8", "2\n2 9\n3 7", "2\n1 0\n3 4", "2\n2 9\n4 7", "2\n1 0\n1 4", "2\n1 5\n3 42"], "outputs": ["6\n13\n", "1\n13\n", "24\n13\n", "38\n23\n", "0\n5\n", "38\n19\n", "0\n7\n", "13\n736\n"]}
| 377
| 154
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.
Return the sorted array.
Please complete the following python code precisely:
```python
class Solution:
def frequencySort(self, nums: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,2,2,3]) == [3,1,1,2,2,2]\n assert candidate(nums = [2,3,1,3,2]) == [1,3,3,2,2]\n assert candidate(nums = [-1,1,-6,4,5,-6,1,4,1]) == [5,-1,4,4,-6,-6,1,1,1]\n\n\ncheck(Solution().frequencySort)"}
| 89
| 126
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.
However, there are city restrictions on the heights of the new buildings:
The height of each building must be a non-negative integer.
The height of the first building must be 0.
The height difference between any two adjacent buildings cannot exceed 1.
Additionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [idi, maxHeighti] indicates that building idi must have a height less than or equal to maxHeighti.
It is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.
Return the maximum possible height of the tallest building.
Please complete the following python code precisely:
```python
class Solution:
def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 5, restrictions = [[2,1],[4,1]]) == 2\n assert candidate(n = 6, restrictions = []) == 5\n assert candidate(n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]) == 5\n\n\ncheck(Solution().maxBuilding)"}
| 219
| 90
|
coding
|
Solve the programming task below in a Python markdown code block.
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano keyboard.
Paul is very clever and knows that the essential thing is to properly assign fingers to notes he's going to play. If he chooses an inconvenient fingering, he will then waste a lot of time trying to learn how to play the melody by these fingers and he will probably not succeed.
Let's denote the fingers of hand by numbers from 1 to 5. We call a fingering any sequence b_1, …, b_n of fingers numbers. A fingering is convenient if for all 1≤ i ≤ n - 1 the following holds:
* if a_i < a_{i+1} then b_i < b_{i+1}, because otherwise Paul needs to take his hand off the keyboard to play the (i+1)-st note;
* if a_i > a_{i+1} then b_i > b_{i+1}, because of the same;
* if a_i = a_{i+1} then b_i≠ b_{i+1}, because using the same finger twice in a row is dumb. Please note that there is ≠, not = between b_i and b_{i+1}.
Please provide any convenient fingering or find out that there is none.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) denoting the number of notes.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 2⋅10^5) denoting the positions of notes on the keyboard.
Output
If there is no convenient fingering, print -1. Otherwise, print n numbers b_1, b_2, …, b_n, each from 1 to 5, denoting a convenient fingering, separated by spaces.
Examples
Input
5
1 1 4 2 2
Output
1 4 5 4 5
Input
7
1 5 7 8 10 3 1
Output
1 2 3 4 5 4 3
Input
19
3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8
Output
1 3 4 5 4 5 4 5 4 5 4 5 4 3 5 4 3 5 4
Note
The third sample test is kinda "Non stop" song by Reflex.
|
{"inputs": ["1\n1\n", "1\n50\n", "1\n68\n", "1\n72\n", "1\n10\n", "1\n14\n", "1\n12\n", "1\n17\n"], "outputs": ["1", "1 \n", "1", "1", "1", "1", "1", "1"]}
| 615
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Given a number `n`, return a string representing it as a sum of distinct powers of three, or return `"Impossible"` if that's not possible to achieve.
# Input/Output
`[input]` integer `n`
A positive integer n.
`1 ≤ n ≤ 10^16`.
`[output]` a string
A string representing the sum of powers of three which adds up to n, or `"Impossible"` if there is no solution. If the solution does exist, it should be return as `"3^a1+3^a2+ ... +3^an"`, where ai for `0 ≤ i ≤ n` represents the corresponding exponent of the term. The terms in the string should also be sorted in descending order, meaning that higher powers should appear before the lower ones in the string (`"3^0+3^1"` is incorrect, whereas `"3^1+3^0"` is correct).
# Example
For `n = 4`, the output should be `"3^1+3^0"`.
4 can be represented as `3+1` which is in fact 3 to the power of 1 plus 3 to the power of 0
For `n = 2`, the output should be `"Impossible"`.
There is no way to represent 2 as a sum of `distinct powers` of 3.
Also feel free to reuse/extend the following starter code:
```python
def sum_of_threes(n):
```
|
{"functional": "_inputs = [[4], [2], [28], [84], [1418194818], [87754], [531441], [8312964441463288], [5559060566575209], [243]]\n_outputs = [['3^1+3^0'], ['Impossible'], ['3^3+3^0'], ['3^4+3^1'], ['Impossible'], ['3^10+3^9+3^8+3^7+3^5+3^3+3^1+3^0'], ['3^12'], ['Impossible'], ['3^33+3^9+3^1'], ['3^5']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(sum_of_threes(*i), o[0])"}
| 328
| 327
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:
* Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s.
For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`.
You are given the strings a, b, and c. Find the minimum possible length of s.
Constraints
* 1 \leq |a|, |b|, |c| \leq 2000
* a, b, and c consists of lowercase English letters and `?`s.
Input
Input is given from Standard Input in the following format:
a
b
c
Output
Print the minimum possible length of s.
Examples
Input
a?c
der
cod
Output
7
Input
atcoder
atcoder
???????
Output
7
|
{"inputs": ["`?c\nder\ncod", "`?d\nder\ncod", "`?d\nddr\ncod", "`?d\nddr\ncoe", "`?d\nddr\ncof", "`>d\nddr\ncof", "d>`\nddr\ncof", "d>_\nddr\ncof"], "outputs": ["7\n", "8\n", "7\n", "7\n", "7\n", "8\n", "9\n", "9\n"]}
| 256
| 116
|
coding
|
Solve the programming task below in a Python markdown code block.
After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.
Sasha selects any k out of n slots he wishes and puts bullets there. Roma spins the cylinder so that every of n possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner.
Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one.
More formally, the cylinder of n bullet slots able to contain k bullets can be represented as a string of n characters. Exactly k of them are "X" (charged slots) and the others are "." (uncharged slots).
Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string.
Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each xi query must be answered: is there a bullet in the positions xi?
Input
The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer xi (1 ≤ xi ≤ n) the number of slot to describe.
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Output
For each query print "." if the slot should be empty and "X" if the slot should be charged.
Examples
Input
3 1 3
1
2
3
Output
..X
Input
6 3 6
1
2
3
4
5
6
Output
.X.X.X
Input
5 2 5
1
2
3
4
5
Output
...XX
Note
The lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.
|
{"inputs": ["3 1 3\n1\n2\n3\n", "4 0 4\n1\n2\n3\n4\n", "4 1 4\n1\n2\n3\n4\n", "5 2 5\n1\n2\n2\n4\n5\n", "5 2 5\n1\n2\n3\n1\n5\n", "5 2 5\n1\n3\n3\n1\n5\n", "5 2 5\n1\n3\n3\n2\n5\n", "5 2 5\n1\n2\n3\n4\n5\n"], "outputs": ["..X", "....", "...X", "...XX", "....X", "....X", "....X", "...XX"]}
| 725
| 170
|
coding
|
Solve the programming task below in a Python markdown code block.
We need you to implement a method of receiving commands over a network, processing the information and responding.
Our device will send a single packet to you containing data and an instruction which you must perform before returning your reply.
To keep things simple, we will be passing a single "packet" as a string.
Each "byte" contained in the packet is represented by 4 chars.
One packet is structured as below:
```
Header Instruction Data1 Data2 Footer
------ ------ ------ ------ ------
H1H1 0F12 0012 0008 F4F4
------ ------ ------ ------ ------
The string received in this case would be - "H1H10F1200120008F4F4"
Instruction: The calculation you should perform, always one of the below.
0F12 = Addition
B7A2 = Subtraction
C3D9 = Multiplication
FFFF = This instruction code should be used to identify your return value.
```
- The Header and Footer are unique identifiers which you must use to form your reply.
- Data1 and Data2 are the decimal representation of the data you should apply your instruction to. _i.e 0109 = 109._
- Your response must include the received header/footer, a "FFFF" instruction code, and the result of your calculation stored in Data1.
- Data2 should be zero'd out to "0000".
```
To give a complete example:
If you receive message "H1H10F1200120008F4F4".
The correct response would be "H1H1FFFF00200000F4F4"
```
In the event that your calculation produces a negative result, the value returned should be "0000", similarily if the value is above 9999 you should return "9999".
Goodluck, I look forward to reading your creative solutions!
Also feel free to reuse/extend the following starter code:
```python
def communication_module(packet):
```
|
{"functional": "_inputs = [['H1H10F1200120008F4F4'], ['D7D70F1200250015G8G8'], ['X7X7B7A201400058L0L0'], ['Y2Y2B7A210000902N5N5'], ['R5R5C3D900120008K4K4'], ['S2S2C3D900250005I9I9'], ['E4E40F1239128908Z3Z3'], ['A6A6C3D911150015M0M0'], ['T7T7B7A200258908P2P2'], ['S4S4B7A201153215U8U8']]\n_outputs = [['H1H1FFFF00200000F4F4'], ['D7D7FFFF00400000G8G8'], ['X7X7FFFF00820000L0L0'], ['Y2Y2FFFF00980000N5N5'], ['R5R5FFFF00960000K4K4'], ['S2S2FFFF01250000I9I9'], ['E4E4FFFF99990000Z3Z3'], ['A6A6FFFF99990000M0M0'], ['T7T7FFFF00000000P2P2'], ['S4S4FFFF00000000U8U8']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(communication_module(*i), o[0])"}
| 481
| 559
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
If the character read is a letter, that letter is written onto the tape.
If the character read is a digit d, the entire current tape is repeatedly written d - 1 more times in total.
Given an integer k, return the kth letter (1-indexed) in the decoded string.
Please complete the following python code precisely:
```python
class Solution:
def decodeAtIndex(self, s: str, k: int) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"leet2code3\", k = 10) == \"o\"\n assert candidate(s = \"ha22\", k = 5) == \"h\"\n assert candidate(s = \"a2345678999999999999999\", k = 1) == \"a\"\n\n\ncheck(Solution().decodeAtIndex)"}
| 145
| 101
|
coding
|
Solve the programming task below in a Python markdown code block.
Iahub got bored, so he invented a game to be played on paper.
He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak for which their positions are in range [i, j] (that is i ≤ k ≤ j). Flip the value of x means to apply operation x = 1 - x.
The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.
```
@param {Array} line of the input there are n integers: a1, a2, ..., an. 1 ≤ n ≤ 100. It is guaranteed that each of those n values is either 0 or 1
@return {Integer} the maximal number of 1s that can be obtained after exactly one move
```
Examples :
```
[1, 0, 0, 1, 0, 0] => 5
[1, 0, 0, 1] => 4
```
Note:
In the first case, flip the segment from 2 to 6 (i = 2, j = 6). That flip changes the sequence, it becomes: [1 1 1 0 1 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1 1].
In the second case, flipping only the second and the third element (i = 2, j = 3) will turn all numbers into 1.
(c)ll931110 & fchirica
Also feel free to reuse/extend the following starter code:
```python
def flipping_game(num):
```
|
{"functional": "_inputs = [[[1, 0, 0, 1, 0, 0]], [[1, 0, 0, 1]], [[1]], [[0]], [[1, 0, 0, 0, 1, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1]]]\n_outputs = [[5], [4], [0], [1], [7], [18], [22], [18]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(flipping_game(*i), o[0])"}
| 492
| 434
|
coding
|
Solve the programming task below in a Python markdown code block.
The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen.
After the fighting stopped, Heidi gave them another task to waste their time on.
There are $n$ points on a plane. Given a radius $r$, find the maximum number of points that can be covered by an $L^1$-ball with radius $r$.
An $L^1$-ball with radius $r$ and center $(x_0, y_0)$ in a 2D-plane is defined as the set of points $(x, y)$ such that the Manhattan distance between $(x_0, y_0)$ and $(x, y)$ is at most $r$.
Manhattan distance between $(x_0, y_0)$ and $(x, y)$ is defined as $|x - x_0| + |y - y_0|$.
-----Input-----
The first line contains two integers $n, r$ ($1 \le n \le 300\,000, 1 \le r \le 10^6$), the number of points and the radius of the ball, respectively.
Each of the next $n$ lines contains integers $x_i, y_i$ ($-10^6 \leq x_i, y_i \leq 10^6$), describing the coordinates of the $i$-th point.
It is guaranteed, that all points are distinct.
-----Output-----
Print one integer — the maximum number points that an $L^1$-ball with radius $r$ can cover.
-----Examples-----
Input
5 1
1 1
1 -1
-1 1
-1 -1
2 0
Output
3
Input
5 2
1 1
1 -1
-1 1
-1 -1
2 0
Output
5
-----Note-----
In the first example, a ball centered at $(1, 0)$ covers the points $(1, 1)$, $(1, -1)$, $(2, 0)$.
In the second example, a ball centered at $(0, 0)$ covers all the points.
Note that $x_0$ and $y_0$ need not be integer.
|
{"inputs": ["5 1\n1 1\n1 -2\n0 1\n0 0\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n0 1\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n0 1\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n0 2\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n-1 0\n2 0\n", "1 1000000\n1000000 -419484\n", "5 1\n1 1\n2 -2\n0 1\n-1 0\n2 0\n"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "2\n", "1\n", "2\n"]}
| 513
| 249
|
coding
|
Solve the programming task below in a Python markdown code block.
We have a permutation P = P_1, P_2, \ldots, P_N of 1, 2, \ldots, N.
You have to do the following N - 1 operations on P, each exactly once, in some order:
- Swap P_1 and P_2.
- Swap P_2 and P_3.
\vdots
- Swap P_{N-1} and P_N.
Your task is to sort P in ascending order by configuring the order of operations.
If it is impossible, print -1 instead.
-----Constraints-----
- All values in input are integers.
- 2 \leq N \leq 2 \times 10^5
- P is a permutation of 1, 2, \ldots, N.
-----Input-----
Input is given from Standard Input in the following format:
N
P_1 P_2 \ldots P_N
-----Output-----
If it is impossible to sort P in ascending order by configuring the order of operations, print -1.
Otherwise, print N-1 lines to represent a sequence of operations that sorts P in ascending order.
The i-th line (1 \leq i \leq N - 1) should contain j, where the i-th operation swaps P_j and P_{j + 1}.
If there are multiple such sequences of operations, any of them will be accepted.
-----Sample Input-----
5
2 4 1 5 3
-----Sample Output-----
4
2
3
1
The following sequence of operations sort P in ascending order:
- First, swap P_4 and P_5, turning P into 2, 4, 1, 3, 5.
- Then, swap P_2 and P_3, turning P into 2, 1, 4, 3, 5.
- Then, swap P_3 and P_4, turning P into 2, 1, 3, 4, 5.
- Finally, swap P_1 and P_2, turning P into 1, 2, 3, 4, 5.
|
{"inputs": ["5\n2 4 1 5 3\n", "5\n5 4 3 2 1\n"], "outputs": ["4\n2\n3\n1\n", "-1\n"]}
| 464
| 48
|
coding
|
Solve the programming task below in a Python markdown code block.
The `depth` of an integer `n` is defined to be how many multiples of `n` it is necessary to compute before all `10` digits have appeared at least once in some multiple.
example:
```
let see n=42
Multiple value digits comment
42*1 42 2,4
42*2 84 8 4 existed
42*3 126 1,6 2 existed
42*4 168 - all existed
42*5 210 0 2,1 existed
42*6 252 5 2 existed
42*7 294 9 2,4 existed
42*8 336 3 6 existed
42*9 378 7 3,8 existed
```
Looking at the above table under `digits` column you can find all the digits from `0` to `9`, Hence it required `9` multiples of `42` to get all the digits. So the depth of `42` is `9`. Write a function named `computeDepth` which computes the depth of its integer argument.Only positive numbers greater than zero will be passed as an input.
Also feel free to reuse/extend the following starter code:
```python
def compute_depth(n):
```
|
{"functional": "_inputs = [[8], [13], [7], [25], [42], [1]]\n_outputs = [[12], [8], [10], [36], [9], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(compute_depth(*i), o[0])"}
| 337
| 192
|
coding
|
Solve the programming task below in a Python markdown code block.
A: Union Ball
Problem Statement
There are N balls in a box. The i-th ball is labeled with a positive integer A_i.
You can interact with balls in the box by taking actions under the following rules:
* If integers on balls in the box are all odd or all even, you cannot take actions anymore.
* Otherwise, you select arbitrary two balls in the box and remove them from the box. Then, you generate a new ball labeled with the sum of the integers on the two balls and put it into the box.
For given balls, what is the maximum number of actions you can take under the above rules?
Input
N
A_1 A_2 ... A_N
* The first line gives an integer N representing the initial number of balls in a box.
* The second line contains N integers, the i-th of which is the integer on the i-th ball.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9
* Inputs consist only of integers.
Output
Output the maximum number of actions you can take in one line.
Sample Input 1
3
4 5 6
Output for Sample Input 1
2
First, you select and remove balls labeled with 4 and 5, respectively, and add a ball labeled with 9. Next, you select and remove balls labeled with 6 and 9, respectively, and add a ball labeled with 15. Now, the balls in the box only have odd numbers. So you cannot take any actions anymore. The number of actions you took is two, and there is no way to achieve three actions or more. Thus the maximum is two and the series of the above actions is one of the optimal ways.
Sample Input 2
4
4 2 4 2
Output for Sample Input 2
0
You cannot take any actions in this case.
Example
Input
3
4 5 6
Output
2
|
{"inputs": ["3\n6 5 6", "3\n3 5 6", "3\n6 6 6", "3\n3 6 6", "3\n6 6 2", "3\n6 9 2", "3\n6 0 2", "3\n6 1 2"], "outputs": ["2\n", "1\n", "0\n", "2\n", "0\n", "2\n", "0\n", "2\n"]}
| 439
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of the tasks come from the driving is right side!). Every driver when parking wants to leave for themselves some extra space to move their car freely, that's why a driver is looking for a place where the distance between his car and the one behind his will be no less than b meters and the distance between his car and the one in front of his will be no less than f meters (if there's no car behind then the car can be parked at the parking lot segment edge; the same is true for the case when there're no cars parked in front of the car). Let's introduce an axis of coordinates along the pavement. Let the parking lot begin at point 0 and end at point L. The drivers drive in the direction of the coordinates' increasing and look for the earliest place (with the smallest possible coordinate) where they can park the car. In case there's no such place, the driver drives on searching for his perfect peaceful haven. Sometimes some cars leave the street and free some space for parking. Considering that there never are two moving cars on a street at a time write a program that can use the data on the drivers, entering the street hoping to park there and the drivers leaving it, to model the process and determine a parking lot space for each car.
Input
The first line contains three integers L, b и f (10 ≤ L ≤ 100000, 1 ≤ b, f ≤ 100). The second line contains an integer n (1 ≤ n ≤ 100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number represents the request type. If the request type is equal to 1, then in that case the second number indicates the length of a car (in meters) that enters the street looking for a place to park. And if the request type is equal to 2, then the second number identifies the number of such a request (starting with 1) that the car whose arrival to the parking lot was described by a request with this number, leaves the parking lot. It is guaranteed that that car was parked at the moment the request of the 2 type was made. The lengths of cars are integers from 1 to 1000.
Output
For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone.
Examples
Input
30 1 2
6
1 5
1 4
1 5
2 2
1 5
1 4
Output
0
6
11
17
23
Input
30 1 1
6
1 5
1 4
1 5
2 2
1 5
1 4
Output
0
6
11
17
6
Input
10 1 1
1
1 12
Output
-1
|
{"inputs": ["8 1 0\n1\n1 8\n", "1 1 0\n1\n1 8\n", "1 2 0\n1\n1 8\n", "1 3 0\n1\n1 8\n", "10 1 1\n1\n1 9\n", "4 1 2\n1\n1 10\n", "10 1 1\n1\n1 8\n", "10 1 0\n1\n1 8\n"], "outputs": ["0\n", "-1\n", "-1\n", "-1\n", "0\n", "-1\n", "0\n", "0\n"]}
| 730
| 154
|
coding
|
Solve the programming task below in a Python markdown code block.
Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
-----Input-----
The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i.
-----Output-----
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
-----Examples-----
Input
3
AaA
Output
2
Input
7
bcAAcbc
Output
3
Input
6
aaBCCe
Output
5
-----Note-----
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6.
|
{"inputs": ["1\nA\n", "1\ng\n", "1\nA\n", "1\ng\n", "1\nh\n", "1\ni\n", "1\nf\n", "1\ne\n"], "outputs": ["1\n", "1\n", "1", "1", "1\n", "1\n", "1\n", "1\n"]}
| 480
| 84
|
coding
|
Solve the programming task below in a Python markdown code block.
For an array A of length N, let F(A) denote the sum of the product of all the subarrays of A. Formally,
F(A) = \sum_{L=1}^N \sum_{R=L}^N (\prod_{i=L}^R A_{i}\right )
For example, let A = [1, 0, 1], then there are 6 possible subarrays:
Subarray [1, 1] has product = 1
Subarray [1, 2] has product = 0
Subarray [1, 3] has product = 0
Subarray [2, 2] has product = 0
Subarray [2, 3] has product = 0
Subarray [3, 3] has product = 1
So F(A) = 1+1 = 2.
Given a binary array A, determine the value of F(A).
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N denoting the length of the array.
- The second line contains N space-separated integers denoting the array A.
------ Output Format ------
For each test case, output on a new line the value of F(A).
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{5}$
$0 ≤ A_{i} ≤ 1$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
3
1 0 1
1
0
2
1 1
4
1 1 0 1
----- Sample Output 1 ------
2
0
3
4
----- explanation 1 ------
Test case $1$: Explained in the statement.
Test case $2$: There is only $1$ subarray and it has product $= 0$.
Test case $3$: All the $3$ subarrays have product $= 1$.
|
{"inputs": ["4\n3\n1 0 1\n1\n0\n2\n1 1\n4\n1 1 0 1\n"], "outputs": ["2\n0\n3\n4\n"]}
| 481
| 48
|
coding
|
Solve the programming task below in a Python markdown code block.
Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.
Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is $n$.
Madoka is too tired of math to solve it herself, so help her to solve this problem!
-----Input-----
Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. Description of the test cases follows.
The only line of each test case contains an integer $n$ ($1 \le n \le 1000$) — the required sum of the digits.
-----Output-----
For each test case print the maximum number you can obtain.
-----Examples-----
Input
5
1
2
3
4
5
Output
1
2
21
121
212
-----Note-----
The only numbers with the sum of digits equal to $2$ without zeros are $2$ and $11$. But the last one has two ones in a row, so it's not valid. That's why the answer is $2$.
The only numbers with the sum of digits equal to $3$ without zeros are $111$, $12$, $21$, and $3$. The first one has $2$ ones in a row, so it's not valid. So the maximum valid number is $21$.
The only numbers with the sum of digits equals to $4$ without zeros are $1111$, $211$, $121$, $112$, $13$, $31$, $22$, and $4$. Numbers $1111$, $211$, $112$, $22$ aren't valid, because they have some identical digits in a row. So the maximum valid number is $121$.
|
{"inputs": ["5\n1\n2\n3\n4\n5\n"], "outputs": ["1\n2\n21\n121\n212\n"]}
| 441
| 37
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.
Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:
- Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.
For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.
If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.
Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.
Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
-----Constraints-----
- 1 ≦ x ≦ 10^{15}
- x is an integer.
-----Input-----
The input is given from Standard Input in the following format:
x
-----Output-----
Print the answer.
-----Sample Input-----
7
-----Sample Output-----
2
|
{"inputs": ["7\n", "1\n", "6\n", "65\n", "11\n", "12\n", "1752\n", "449171\n"], "outputs": ["2\n", "1\n", "1\n", "12\n", "2\n", "3\n", "319\n", "81668\n"]}
| 329
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Sort the given strings in alphabetical order, case **insensitive**. For example:
```
["Hello", "there", "I'm", "fine"] --> ["fine", "Hello", "I'm", "there"]
["C", "d", "a", "B"]) --> ["a", "B", "C", "d"]
```
Also feel free to reuse/extend the following starter code:
```python
def sortme(words):
```
|
{"functional": "_inputs = [[['Hello', 'there', \"I'm\", 'fine']], [['C', 'd', 'a', 'B']], [['CodeWars']], [[]]]\n_outputs = [[['fine', 'Hello', \"I'm\", 'there']], [['a', 'B', 'C', 'd']], [['CodeWars']], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(sortme(*i), o[0])"}
| 111
| 212
|
coding
|
Solve the programming task below in a Python markdown code block.
For an array A of length N, let F(A) denote the sum of the product of all the subarrays of A. Formally,
F(A) = \sum_{L=1}^N \sum_{R=L}^N (\prod_{i=L}^R A_{i}\right )
For example, let A = [1, 0, 1], then there are 6 possible subarrays:
Subarray [1, 1] has product = 1
Subarray [1, 2] has product = 0
Subarray [1, 3] has product = 0
Subarray [2, 2] has product = 0
Subarray [2, 3] has product = 0
Subarray [3, 3] has product = 1
So F(A) = 1+1 = 2.
Given a binary array A, determine the sum of F(A) over all the N! orderings of A modulo 998244353.
Note that orderings here are defined in terms of indices, not elements; which is why every array of length N has N! orderings. For example, the 3! = 6 orderings of A = [1, 0, 1] are:
[1, 0, 1] corresponding to indices [1, 2, 3]
[1, 1, 0] corresponding to indices [1, 3, 2]
[0, 1, 1] corresponding to indices [2, 1, 3]
[0, 1, 1] corresponding to indices [2, 3, 1]
[1, 1, 0] corresponding to indices [3, 1, 2]
[1, 0, 1] corresponding to indices [3, 2, 1]
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N denoting the le
- The second line contains N space-separated integers denoting the array A.
------ Output Format ------
For each test case, output the sum of F(A) over all the N! orderings of A, modulo 998244353.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{5}$
$0 ≤ A_{i} ≤ 1$
- The sum of $N$ over all test cases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
3
1 0 1
1
0
2
1 1
4
1 1 0 1
----- Sample Output 1 ------
16
0
6
120
|
{"inputs": ["4\n3\n1 0 1\n1\n0\n2\n1 1\n4\n1 1 0 1\n"], "outputs": ["16\n0\n6\n120\n"]}
| 641
| 51
|
coding
|
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 k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.
Please complete the following python code precisely:
```python
class Solution:
def countPairs(self, nums: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,2,2,2,1,3], k = 2) == 4\n assert candidate(nums = [1,2,3,4], k = 1) == 0\n\n\ncheck(Solution().countPairs)"}
| 109
| 71
|
coding
|
Solve the programming task below in a Python markdown code block.
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings!
The sequence of round brackets is called valid if and only if: the total number of opening brackets is equal to the total number of closing brackets; for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.
Gabi bought a string s of length m (m ≤ n) and want to complete it to obtain a valid sequence of brackets of length n. He is going to pick some strings p and q consisting of round brackets and merge them in a string p + s + q, that is add the string p at the beginning of the string s and string q at the end of the string s.
Now he wonders, how many pairs of strings p and q exists, such that the string p + s + q is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 10^9 + 7.
-----Input-----
First line contains n and m (1 ≤ m ≤ n ≤ 100 000, n - m ≤ 2000) — the desired length of the string and the length of the string bought by Gabi, respectively.
The second line contains string s of length m consisting of characters '(' and ')' only.
-----Output-----
Print the number of pairs of string p and q such that p + s + q is a valid sequence of round brackets modulo 10^9 + 7.
-----Examples-----
Input
4 1
(
Output
4
Input
4 4
(())
Output
1
Input
4 3
(((
Output
0
-----Note-----
In the first sample there are four different valid pairs: p = "(", q = "))" p = "()", q = ")" p = "", q = "())" p = "", q = ")()"
In the second sample the only way to obtain a desired string is choose empty p and q.
In the third sample there is no way to get a valid sequence of brackets.
|
{"inputs": ["4 1\n(\n", "8 1\n(\n", "9 1\n(\n", "4 1\n(\n", "2 2\n)(\n", "2 2\n))\n", "2 2\n)(\n", "2 2\n))\n"], "outputs": ["4\n", "56\n", "0\n", "4\n", "0\n", "0\n", "0\n", "0\n"]}
| 487
| 107
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array nums consisting of positive integers.
Split the array into one or more disjoint subarrays such that:
Each element of the array belongs to exactly one subarray, and
The GCD of the elements of each subarray is strictly greater than 1.
Return the minimum number of subarrays that can be obtained after the split.
Note that:
The GCD of a subarray is the largest positive integer that evenly divides all the elements of the subarray.
A subarray is a contiguous part of the array.
Please complete the following python code precisely:
```python
class Solution:
def minimumSplits(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [12,6,3,14,8]) == 2\n assert candidate(nums = [4,12,6,14]) == 1\n\n\ncheck(Solution().minimumSplits)"}
| 156
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
Find the convex hull of a given set of points P. In other words, find the smallest convex polygon containing all the points of P. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
Please note that you should find all the points of P on both corner and boundary of the convex polygon.
Constraints
* 3 ≤ n ≤ 100000
* -10000 ≤ xi, yi ≤ 10000
* No point in the P will occur more than once.
Input
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points in P. The coordinate of the i-th point pi is given by two integers xi and yi.
Output
In the first line, print the number of points on the corner/boundary of the convex polygon. In the following lines, print x y coordinates of the set of points. The coordinates should be given in the order of counter-clockwise visit of them starting from the point in P with the minimum y-coordinate, or the leftmost such point in case of a tie.
Examples
Input
7
2 1
0 0
1 2
2 2
4 2
1 3
3 3
Output
5
0 0
2 1
4 2
3 3
1 3
Input
4
0 0
2 2
0 2
0 1
Output
4
0 0
2 2
0 2
0 1
|
{"inputs": ["4\n1 0\n2 2\n0 2\n0 1", "4\n1 0\n3 2\n0 2\n0 1", "4\n1 0\n2 2\n1 2\n0 1", "4\n1 1\n3 2\n0 2\n0 1", "4\n2 0\n2 2\n1 2\n0 1", "4\n1 1\n3 0\n0 2\n0 1", "4\n1 1\n3 1\n0 2\n0 1", "4\n2 1\n3 1\n0 2\n0 1"], "outputs": ["4\n1 0\n2 2\n0 2\n0 1\n", "4\n1 0\n3 2\n0 2\n0 1\n", "4\n1 0\n2 2\n1 2\n0 1\n", "4\n0 1\n1 1\n3 2\n0 2\n", "4\n2 0\n2 2\n1 2\n0 1\n", "3\n3 0\n0 2\n0 1\n", "4\n0 1\n1 1\n3 1\n0 2\n", "4\n0 1\n2 1\n3 1\n0 2\n"]}
| 351
| 314
|
coding
|
Solve the programming task below in a Python markdown code block.
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
-----Input-----
The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).
-----Output-----
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
-----Examples-----
Input
2 4
Output
1 3
3 1
Input
4 7
Output
2 1 0 4
4 0 2 1
1 3 3 0
0 3 2 2
-----Note-----
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
|
{"inputs": ["2 4\n", "4 7\n", "1 8\n", "9 3\n", "2 7\n", "4 3\n", "3 2\n", "3 2\n"], "outputs": ["4 0 \n0 4 \n", "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 \n", "8 \n", "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 3 0 \n0 0 0 0 0 0 0 0 3 \n", "7 0 \n0 7 \n", "3 0 0 0 \n0 3 0 0 \n0 0 3 0 \n0 0 0 3 \n", "2 0 0 \n0 2 0 \n0 0 2 \n", "2 0 0 \n0 2 0 \n0 0 2 \n"]}
| 333
| 378
|
coding
|
Solve the programming task below in a Python markdown code block.
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. $\left. \begin{array}{l}{\text{Rey}} \\{\text{to my}} \\{\text{heart}} \end{array} \right.$
Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start.
After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right.
Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a_1, a_2, ..., a_{k} such that $n = \prod_{i = 1}^{k} a_{i}$
in other words, n is multiplication of all elements of the given array.
Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that $\operatorname{gcd}(p, q) = 1$, where $gcd$ is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 10^9 + 7.
Please note that we want $gcd$ of p and q to be 1, not $gcd$ of their remainders after dividing by 10^9 + 7.
-----Input-----
The first line of input contains a single integer k (1 ≤ k ≤ 10^5) — the number of elements in array Barney gave you.
The second line contains k integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ 10^18) — the elements of the array.
-----Output-----
In the only line of output print a single string x / y where x is the remainder of dividing p by 10^9 + 7 and y is the remainder of dividing q by 10^9 + 7.
-----Examples-----
Input
1
2
Output
1/2
Input
3
1 1 1
Output
0/1
|
{"inputs": ["1\n2\n", "1\n1\n", "1\n3\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n8\n", "1\n2\n"], "outputs": ["1/2\n", "0/1\n", "1/4\n", "1/4", "0/1", "3/8\n", "43/128\n", "1/2"]}
| 605
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US.
Calculate Pooja's account balance after an attempted transaction.
-----Input-----
Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja's initial account balance.
-----Output-----
Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.
-----Example - Successful Transaction-----
Input:
30 120.00
Output:
89.50
-----Example - Incorrect Withdrawal Amount (not multiple of 5)-----
Input:
42 120.00
Output:
120.00
-----Example - Insufficient Funds-----
Input:
300 120.00
Output:
120.00
|
{"inputs": ["30 120.00\n\n", "42 120.00\n\n", "300 120.00\n\n"], "outputs": ["89.50", "120.00", "120.00"]}
| 281
| 69
|
coding
|
Solve the programming task below in a Python markdown code block.
Omkar's most recent follower, Ajit, has entered the Holy Forest. Ajit realizes that Omkar's forest is an n by m grid (1 ≤ n, m ≤ 2000) of some non-negative integers. Since the forest is blessed by Omkar, it satisfies some special conditions:
1. For any two adjacent (sharing a side) cells, the absolute value of the difference of numbers in them is at most 1.
2. If the number in some cell is strictly larger than 0, it should be strictly greater than the number in at least one of the cells adjacent to it.
Unfortunately, Ajit is not fully worthy of Omkar's powers yet. He sees each cell as a "0" or a "#". If a cell is labeled as "0", then the number in it must equal 0. Otherwise, the number in it can be any nonnegative integer.
Determine how many different assignments of elements exist such that these special conditions are satisfied. Two assignments are considered different if there exists at least one cell such that the numbers written in it in these assignments are different. Since the answer may be enormous, find the answer modulo 10^9+7.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 2000, nm ≥ 2) – the dimensions of the forest.
n lines follow, each consisting of one string of m characters. Each of these characters is either a "0" or a "#".
It is guaranteed that the sum of n over all test cases does not exceed 2000 and the sum of m over all test cases does not exceed 2000.
Output
For each test case, print one integer: the number of valid configurations modulo 10^9+7.
Example
Input
4
3 4
0000
00#0
0000
2 1
#
#
1 2
##
6 29
#############################
#000##0###0##0#0####0####000#
#0#0##00#00##00####0#0###0#0#
#0#0##0#0#0##00###00000##00##
#000##0###0##0#0##0###0##0#0#
#############################
Output
2
3
3
319908071
Note
For the first test case, the two valid assignments are
0000\\\ 0000\\\ 0000
and
0000\\\ 0010\\\ 0000
|
{"inputs": ["3\n5 3\n###\n###\n###\n###\n0##\n3 3\n###\n###\n#0#\n2 4\n####\n####\n", "5\n5 4\n0000\n0000\n00#0\n0000\n0000\n4 4\n#000\n00#0\n#000\n0000\n4 3\n000\n0#0\n#00\n000\n5 1\n0\n0\n0\n0\n0\n2 8\n00#00000\n000#000#\n", "1\n6 10\n0####0###0\n00#000##00\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\n###0##0#00\n#00##000#0\n00##00#0#0\n", "1\n6 10\n0####0###0\n00#0000#0#\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\n###0##0#00\n#00##000#0\n00##00#0#0\n", "1\n6 10\n0####0###0\n00#0000#0#\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\n#\"#0##0#00\n#00##000#0\n00##00#0#0\n", "1\n6 10\n0####0###0\n00#0000#0#\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\n00#0##0#\"#\n#00##000#0\n00##00#0#0\n", "1\n6 10\n0###0####0\n00#000##00\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\n###0##0#00\n#00##000#0\n00##00#0#0\n", "1\n6 10\n0####0###0\n00#0000#0#\n##0#0###00\n0#0##00#00\n#####0##00\n###00#0#0#\n###00#0###\n00#0##0###\n#00##000#0\n00##00#0#0\n"], "outputs": ["16384\n256\n255\n", "2\n8\n4\n1\n8\n", "589934536\n", "589934536\n", "589934536\n", "589934536\n", "589934536\n", "589934536\n"]}
| 630
| 840
|
coding
|
Solve the programming task below in a Python markdown code block.
As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma.
We consider any sequence consisting of the letters of the English alphabet to be a word. So axxb,abbba and bbbccddx are words for our purpose. And aaabbaaa, abbba and bbb are examples of palindromes.
By a subword of a word, we mean a contiguous subsequence of the word. For example the subwords of the word abbba are a, b, ab, bb, ba, abb, bbb, bba, abbb, bbba and abbba.
In this task you will given a word and you must find the longest subword of this word that is also a palindrome.
For example if the given word is abbba then the answer is abbba. If the given word is abcbcabbacba then the answer is bcabbacb.
-----Input:-----
The first line of the input contains a single integer $N$ indicating the length of the word. The following line contains a single word of length $N$, made up of the letters a,b,…, z.
-----Output:-----
The first line of the output must contain a single integer indicating the length of the longest subword of the given word that is a palindrome. The second line must contain a subword that is a palindrome and which of maximum length. If there is more than one subword palindrome of maximum length, it suffices to print out any one.
-----Constraints:-----
- $1 \leq N \leq 5000$.
- You may assume that in $30 \%$ of the inputs $1 \leq N \leq 300$.
-----Sample Input 1:-----
5
abbba
-----Sample Output 1:-----
5
abbba
-----Sample Input 2:-----
12
abcbcabbacba
-----Sample Output 2:-----
8
bcabbacb
|
{"inputs": ["5\nabbba", "12\nabcbcabbacba"], "outputs": ["5\nabbba", "8\nbcabbacb"]}
| 440
| 35
|
coding
|
Solve the programming task below in a Python markdown code block.
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.
The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.
To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.
Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.
-----Input-----
The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.
The second line contains sequence of integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 5), where a_{i} is academic performance of the i-th student of the group A.
The third line contains sequence of integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 5), where b_{i} is academic performance of the i-th student of the group B.
-----Output-----
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
-----Examples-----
Input
4
5 4 4 4
5 5 4 5
Output
1
Input
6
1 1 1 1 1 1
5 5 5 5 5 5
Output
3
Input
1
5
3
Output
-1
Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
Output
4
|
{"inputs": ["1\n5\n3\n", "1\n1\n2\n", "1\n1\n1\n", "1\n1\n1\n", "1\n1\n2\n", "1\n1\n3\n", "1\n2\n3\n", "1\n2\n4\n"], "outputs": ["-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 505
| 103
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef Avi likes the number K. Given a list of N integers, help him find the sum of all distinct numbers repeating exactly K times. Each of those numbers should be considered only once in the sum, not K times.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains two lines:
- The first line contains two space-separated integers N, K.
- The second line contains N space-separated integers.
------ Output Format ------
For each testcase, print the sum of all numbers occurring exactly K times. If there is no such number, print -1 instead.
------ Constraints ------
$1≤ T≤ 10$
$1≤ N≤10,000$
$1 ≤ K ≤ N$
$0 ≤ A_{i} ≤ 10^{9}$
----- Sample Input 1 ------
3
4 1
2 3 4 4
5 3
9 9 1 1 9
2 1
2 2
----- Sample Output 1 ------
5
9
-1
----- explanation 1 ------
Test Case 1: The numbers 2 and 3 occur exactly once. So the answer is 2 + 3 = 5.
Test Case 2: The number 9 occurs exactly three times. So the answer is 9.
Test Case 3: There is no number which occurs exactly once. Hence the answer is -1.
|
{"inputs": ["3\n4 1\n2 3 4 4\n5 3\n9 9 1 1 9\n2 1\n2 2"], "outputs": ["5\n9\n-1"]}
| 327
| 51
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.
The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.
A valid square has four equal sides with positive length and four equal angles (90-degree angles).
Please complete the following python code precisely:
```python
class Solution:
def validSquare(self, p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12]) == False\n assert candidate(p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1]) == True\n\n\ncheck(Solution().validSquare)"}
| 143
| 96
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array $a[0 \ldots n-1]$ of length $n$ which consists of non-negative integers. Note that array indices start from zero.
An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all $i$ ($0 \le i \le n - 1$) the equality $i \bmod 2 = a[i] \bmod 2$ holds, where $x \bmod 2$ is the remainder of dividing $x$ by 2.
For example, the arrays [$0, 5, 2, 1$] and [$0, 17, 0, 3$] are good, and the array [$2, 4, 6, 7$] is bad, because for $i=1$, the parities of $i$ and $a[i]$ are different: $i \bmod 2 = 1 \bmod 2 = 1$, but $a[i] \bmod 2 = 4 \bmod 2 = 0$.
In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).
Find the minimum number of moves in which you can make the array $a$ good, or say that this is not possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases in the test. Then $t$ test cases follow.
Each test case starts with a line containing an integer $n$ ($1 \le n \le 40$) — the length of the array $a$.
The next line contains $n$ integers $a_0, a_1, \ldots, a_{n-1}$ ($0 \le a_i \le 1000$) — the initial array.
-----Output-----
For each test case, output a single integer — the minimum number of moves to make the given array $a$ good, or -1 if this is not possible.
-----Example-----
Input
4
4
3 2 7 6
3
3 2 6
1
7
7
4 9 2 1 18 3 0
Output
2
1
-1
0
-----Note-----
In the first test case, in the first move, you can swap the elements with indices $0$ and $1$, and in the second move, you can swap the elements with indices $2$ and $3$.
In the second test case, in the first move, you need to swap the elements with indices $0$ and $1$.
In the third test case, you cannot make the array good.
|
{"inputs": ["7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "4\n4\n3 2 7 6\n3\n6 4 4\n1\n7\n7\n7 7 2 2 2 3 2\n", "4\n4\n6 2 7 6\n3\n6 4 4\n1\n7\n7\n6 7 4 2 2 3 2\n", "4\n4\n6 2 7 6\n3\n6 4 4\n1\n8\n7\n6 7 4 2 2 0 2\n", "4\n4\n6 2 7 1\n3\n6 2 4\n1\n8\n7\n6 7 4 2 2 0 2\n", "4\n4\n6 2 7 9\n3\n6 4 4\n1\n7\n7\n6 7 4 2 2 0 2\n", "4\n4\n6 2 7 6\n3\n6 1 4\n1\n8\n7\n6 7 4 2 2 0 2\n"], "outputs": ["0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n", "2\n-1\n-1\n1\n", "-1\n-1\n-1\n-1\n", "-1\n-1\n0\n-1\n", "1\n-1\n0\n-1\n", "1\n-1\n-1\n-1\n", "-1\n0\n0\n-1\n"]}
| 621
| 427
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.
A uni-value grid is a grid where all the elements of it are equal.
Return the minimum number of operations to make the grid uni-value. If it is not possible, return -1.
Please complete the following python code precisely:
```python
class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(grid = [[2,4],[6,8]], x = 2) == 4\n assert candidate(grid = [[1,5],[2,3]], x = 1) == 5\n assert candidate(grid = [[1,2],[3,4]], x = 2) == -1\n\n\ncheck(Solution().minOperations)"}
| 130
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Arun has an integer N. His friend likes the number 1, so Arun wants to reduce N to 1.
To do so, he can perform the following move several times (possibly, zero):
Pick two integers X and Y such that X+Y is even and X^{Y} is a divisor of N. Then, replace N by \dfrac{N}{X^{Y}}
Note that at each step, X^{Y} only needs to be a divisor of the *current* value of N, and not necessarily a divisor of the integer Arun initially started with.
Find the minimum number of moves Arun needs to reduce N to 1. If it is not possible to reduce N to 1 using the given operation, print -1 instead.
------ Input Format ------
- The first line of input will contain an integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input containing one integer N.
------ Output Format ------
For each test case, output on a new line the answer — the minimum number of moves needed to reduce N to 1, or -1 if it is not possible to do so.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{18}$
----- Sample Input 1 ------
2
25
24
----- Sample Output 1 ------
1
-1
----- explanation 1 ------
Test case $1$: Choose $X = 25$ and $Y = 1$. $X+Y = 26$ is even, and $X^{Y} = 25$ is a divisor of $N = 25$ so this is a valid choice of $X$ and $Y$. Dividing $N$ by $X^{Y}$ leaves us with $\frac{25}{25} = 1$ and we are done.
Test case $2$: It can be shown that no matter which moves are made, $24$ cannot be reduced to $1$.
|
{"inputs": ["2\n25\n24\n"], "outputs": ["1\n-1"]}
| 453
| 22
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Please complete the following python code precisely:
```python
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
```
|
{"functional": "def check(candidate):\n assert is_same_list(candidate(l1 = list_node([7,2,4,3]), l2 = list_node([5,6,4])), list_node([7,8,0,7]))\n assert is_same_list(candidate(l1 = list_node([2,4,3]), l2 = list_node([5,6,4])), list_node([8,0,7]))\n assert is_same_list(candidate(l1 = list_node([0]), l2 = list_node([0])), list_node([0]))\n\n\ncheck(Solution().addTwoNumbers)"}
| 163
| 135
|
coding
|
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 from the city.
The monsters walk toward the city at a constant speed. The speed of each monster is given to you in an integer array speed of size n, where speed[i] is the speed of the ith monster in kilometers per minute.
You have a weapon that, once fully charged, can eliminate a single monster. However, the weapon takes one minute to charge. The weapon is fully charged at the very start.
You lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a loss, and the game ends before you can use your weapon.
Return the maximum number of monsters that you can eliminate before you lose, or n if you can eliminate all the monsters before they reach the city.
Please complete the following python code precisely:
```python
class Solution:
def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int:
```
|
{"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)"}
| 257
| 99
|
coding
|
Solve the programming task below in a Python markdown code block.
The bear has a string s = s_1s_2... s_{|}s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = s_{i}s_{i} + 1... s_{j} contains at least one string "bear" as a substring.
String x(i, j) contains string "bear", if there is such index k (i ≤ k ≤ j - 3), that s_{k} = b, s_{k} + 1 = e, s_{k} + 2 = a, s_{k} + 3 = r.
Help the bear cope with the given problem.
-----Input-----
The first line contains a non-empty string s (1 ≤ |s| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters.
-----Output-----
Print a single number — the answer to the problem.
-----Examples-----
Input
bearbtear
Output
6
Input
bearaabearc
Output
20
-----Note-----
In the first sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, 10), (6, 11), (7, 10), (7, 11).
|
{"inputs": ["a\n", "a\n", "`\n", "_\n", "^\n", "]\n", "\\\n", "[\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 486
| 70
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
Please complete the following python code precisely:
```python
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
```
|
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,3], nums2 = [2]) == 2.00000\n assert candidate(nums1 = [1,2], nums2 = [3,4]) == 2.50000\n\n\ncheck(Solution().findMedianSortedArrays)"}
| 95
| 77
|
coding
|
Solve the programming task below in a Python markdown code block.
Frieza wants to become immortal. In order to do that he must acquire all the seven dragon balls. In a legendary fight, he is able to defeat Kami, the Guardian of the dragon balls. Now he has come across a case that contains the dragon balls and he needs your help to open it.
The case requires a pin number to be unlocked. And the clever Kami has left a puzzle on the case which must be cracked to unlock the case.
On the case, is displayed a string, $S$ of length $N$ consisting of lowercase alphabets. To unlock, he needs to convert this string into a pin number $R$.
The trick to creating that pin lies in his name $[f, r, i, e, z, a]$. Every character in $S$ is either $good$ or $bad$. It is $good$, if it is a part of the letter set $[f, r, i, e, z, a]$. It is $bad$ otherwise. He'll have to traverse $S$ one by one and count consecutive letters that are $good$ or $bad$ and then store these corresponding counts in the same order in $R$. Thus the pin number, $R$ will be a concatenation of the counts of these letters. See Sample Input for more details.
You have to help him find out $R$.
------ Input: ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
Each test case contains a single string $S$ consisting of lowercase characters $[a-z]$.
------ Output: ------
For each test case, output in a single line answer denoting the decoded string which Frieza can use to attain immortality.
------ Constraints ------
$1 ≤ T ≤ 5$
$1 ≤ N ≤ 10^{5}$
$S$ consists of only lower case alphabets.
----- Sample Input 1 ------
2
krillinisdead
futuretrunks
----- Sample Output 1 ------
122111221
132114
----- explanation 1 ------
*Example case 1:* The string $S$ is "krillinisdead". The letter, "k" does not belong to the set $[f, r, i, e, z, a]$ and hence it's count, i.e., 1 is appended to the string $R$. "ri" belongs to the set $[f, r, i, e, z, a]$ and hence 2 is appended to $R$. "ll" doesn't belong to the set $[f, r, i, e, z, a]$, so it's count 2 is appended to the string $R$. The string $R$ keeps getting updated and the final answer is returned when the input string has been completely traversed.
|
{"inputs": ["2\nkrillinisdead\nfuturetrunks"], "outputs": ["122111221\n132114"]}
| 629
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
A number is called 2050-number if it is $2050$, $20500$, ..., ($2050 \cdot 10^k$ for integer $k \ge 0$).
Given a number $n$, you are asked to represent $n$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.
-----Input-----
The first line contains a single integer $T$ ($1\le T\leq 1000$) denoting the number of test cases.
The only line of each test case contains a single integer $n$ ($1\le n\le 10^{18}$) denoting the number to be represented.
-----Output-----
For each test case, output the minimum number of 2050-numbers in one line.
If $n$ cannot be represented as the sum of 2050-numbers, output $-1$ instead.
-----Examples-----
Input
6
205
2050
4100
20500
22550
25308639900
Output
-1
1
2
1
2
36
-----Note-----
In the third case, $4100 = 2050 + 2050$.
In the fifth case, $22550 = 20500 + 2050$.
|
{"inputs": ["1\n1\n", "1\n1\n", "1\n62\n", "1\n57\n", "1\n68\n", "1\n12\n", "1\n10\n", "1\n22\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 347
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef Shifu and Chef Po are participating in the Greatest Dumpling Fight of 2012.
Of course, Masterchef Oogway has formed the rules of the fight.
There is a long horizontal rope of infinite length with a center point P.
Initially both Chef Shifu and Chef Po will stand on the center P of the rope facing each other.
Don't worry, the rope is thick enough to hold Chef Po and Chef Shifu at the same place and at the same time.
Chef Shifu can jump either A or B units to the left or right in one move.
Chef Po can jump either C or D units to the left or right in one move.
Masterchef Oogway wants to place exactly one dumpling on the rope such that
both Chef Shifu and Chef Po will be able to reach it independently in one or more moves.
Also the dumpling can be placed at most K units away from the center of the rope.
Masterchef Oogway will let you watch the fight if you can decide the number of possible positions on the rope to place the dumpling.
------ Input ------
First line contains T, the number of test cases. Each of the next T lines contains five positive integers, A B C D K.
1≤T≤1000
1≤A,B,C,D,K≤10^{18}
------ Output ------
For each test case, output on a newline, the number of possible positions to place the dumpling on the rope.
----- Sample Input 1 ------
3
2 4 3 6 7
1 2 4 5 1
10 12 3 9 16
----- Sample Output 1 ------
3
3
5
----- explanation 1 ------
For the second case,
Chef Po jumps 2 units to the right and then 1 unit to the left.
Chef Shifu jumps 5 units to the right and then 4 units to the left
to reach 1 unit right from the center.
Chef Po jumps 2 units to the left and then 1 unit to the right.
Chef Shifu jumps 5 units to the left and then 4 units to the right
to reach 1 unit left from the center.
Dumpling can also be placed at the center as a chef can reach it in 2 moves.
Thus, there are three different positions at most 1 unit away from the center
that are reachable by both the chefs in one or more moves.
|
{"inputs": ["3\n2 5 0 6 0\n1 4 4 5 2\n10 12 3 1 8", "3\n2 5 0 6 0\n1 4 5 5 2\n10 12 3 1 8", "3\n2 4 0 32 0\n2 1 6 5 1\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 5 5 2\n5 12 3 1 12", "3\n2 4 0 32 0\n2 1 6 5 2\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 8 5 2\n5 12 3 1 12", "3\n2 4 3 6 7\n1 2 4 5 1\n10 12 3 9 16", "3\n2 4 0 10 0\n0 4 4 5 1\n1 12 3 5 16"], "outputs": ["1\n5\n9\n", "1\n1\n9\n", "1\n3\n7\n", "1\n1\n25\n", "1\n5\n7\n", "1\n5\n25\n", "3\n3\n5", "1\n1\n33\n"]}
| 533
| 354
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
While vacationing in Egypt, Chef found a recipe of an ancient dish. The receipt is a sequence of hieroglyphs written on a magic paper - it survived for thousands of years! The sequence is written on a long scroll. Unfortunately, the scroll is split into pieces, and possibly, some pieces of the scroll are missing. Chef has a total of N pieces, numbered for convenience from 1 to N. He gave the pieces of a tape to his friend who studies hieroglyphs for analysis. Chef was happy to hear that there are some relations between the pieces. Some of the pieces may follow other pieces.
The informations about these relations is given as a list of M pairs (A_{i}, B_{i}). Such a pair means that the A_{i}^{th} piece can be immediately followed by the B_{i}^{th} one.
Chef is working on recovering the recipe to prepare this dish for his Egyptian friends. He wants to place all the pieces into lines such that any pair of consecutive pieces (L, R) in a line must be explicitly allowed by one of the M rules described above. In other words, for some i (1 ≤ i ≤ M), (A_{i}, B_{i}) = (L, R). It appears that in general, not all the pieces can be placed in a single line while following the rules. So, please help Chef find what is the minimum number of lines required for all the pieces to be placed acoording to the rules.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space-separated integers N and M denoting the number of pieces and number of relations of those N pieces. Next M lines contain two space-separated integers A and B denoting that piece number A can be followed by piece number B, all those pairs are guaraneed to be unique within a test case.
------ Output ------
For each test case, output a single line containing the minimum number of lines required for all the pieces to be placed acoording to the rules.
------ Constraints ------
$1 ≤ T ≤ 20$
$1 ≤ N ≤ 100$
$1 ≤ M ≤ N^{2}$
$1 ≤ A_{i} ≤ N$
$1 ≤ B_{i} ≤ N$
$There is no sequence S_{1}, S_{2}, ..., S_{k} such that the piece S_{i} can be immediately followed by the piece S_{i+1} for all i from 1 to k-1, and that piece S_{k} can be followed by piece S_{1}.$
----- Sample Input 1 ------
3
3 3
1 2
2 3
1 3
3 2
1 2
1 3
5 4
1 3
2 3
3 4
2 5
----- Sample Output 1 ------
1
2
2
|
{"inputs": ["3\n3 3\n1 2\n2 3\n1 3\n3 2\n1 2\n1 3\n5 4\n1 3\n2 3\n3 4\n2 5"], "outputs": ["1\n2\n2"]}
| 660
| 64
|
coding
|
Solve the programming task below in a Python markdown code block.
For a set $S$ of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in $S$.
* insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.
* find($x$): Report the number of $x$ in $S$.
* delete($x$): Delete all $x$ from $S$.
* dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.
Constraints
* $1 \leq q \leq 200,000$
* $0 \leq x \leq 1,000,000,000$
* The total number of elements printed by dump operations does not exceed $1,000,000$
* The sum of numbers printed by find operations does not exceed $2,000,000$
Input
The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $x$
or
1 $x$
or
2 $x$
or
3 $L$ $R$
where the first digits 0, 1, 2 and 3 represent insert, find, delete and dump operations respectively.
Output
For each insert operation, print the number of elements in $S$.
For each find operation, print the number of specified elements in $S$.
For each dump operation, print the corresponding elements in ascending order. Print an element in a line.
Example
Input
10
0 1
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 4
3 1 4
Output
1
2
3
4
2
0
1
4
1
1
3
4
|
{"inputs": ["10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n0 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 2\n1 3\n0 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 3\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 5\n2 2\n1 1\n1 1\n1 3\n1 4\n3 1 4", "10\n0 1\n0 1\n0 2\n0 0\n2 2\n1 1\n1 1\n1 3\n1 4\n0 1 1", "10\n0 0\n0 1\n0 2\n0 0\n2 0\n1 1\n1 1\n1 3\n1 4\n0 1 1", "10\n0 0\n0 1\n0 2\n1 0\n2 0\n1 1\n1 1\n1 3\n1 4\n0 1 1", "10\n0 0\n0 1\n0 2\n1 0\n2 0\n0 1\n1 1\n1 3\n1 4\n0 2 1"], "outputs": ["1\n2\n3\n4\n2\n2\n1\n4\n1\n1\n3\n4\n", "1\n2\n3\n4\n2\n0\n0\n4\n1\n1\n4\n", "1\n2\n3\n4\n2\n2\n1\n0\n1\n1\n3\n", "1\n2\n3\n4\n2\n2\n0\n0\n1\n1\n", "1\n2\n3\n4\n2\n2\n0\n0\n4\n", "1\n2\n3\n4\n1\n1\n0\n0\n3\n", "1\n2\n3\n1\n1\n1\n0\n0\n3\n", "1\n2\n3\n1\n3\n2\n0\n0\n4\n"]}
| 448
| 550
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Russian also.
Chef plays with the sequence of N numbers. During a single move Chef is able to choose a non-decreasing subsequence of the sequence and to remove it from the sequence. Help him to remove all the numbers in the minimal number of moves.
------ Input ------
The first line of each test case contains a single N denoting the number of integers in the given sequence. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N} denoting the given sequence
------ Output ------
Output a single line containing the minimal number of moves required to remove all the numbers from the sequence.
------ Constraints ------
$1 ≤ N ≤ 100000.$
$1 ≤ A_{i} ≤ 100000.$
------ Scoring ------
Subtask 1 (10 points): N = 10
Subtask 2 (40 points): N = 2000
Subtask 2 (50 points): N = 100000
----- Sample Input 1 ------
3
1 2 3
----- Sample Output 1 ------
1
----- explanation 1 ------
----- Sample Input 2 ------
4
4 1 2 3
----- Sample Output 2 ------
2
----- explanation 2 ------
|
{"inputs": ["3 \n1 2 3", "3 \n1 2 5", "3 \n5 1 0", "3 \n1 2 8", "3 \n1 1 8", "3 \n2 1 3", "3 \n2 1 5", "3 \n2 2 5"], "outputs": ["1", "1\n", "3\n", "1\n", "1\n", "2\n", "2\n", "1\n"]}
| 304
| 117
|
coding
|
Solve the programming task below in a Python markdown code block.
Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
-----Constraints-----
- 1≦A,B,C≦10
-----Input-----
The input is given from Standard Input in the following format:
A B C
-----Output-----
If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.
-----Sample Input-----
5 5 7
-----Sample Output-----
YES
Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.
|
{"inputs": ["2 7 5", "2 7 3", "2 4 3", "2 4 1", "2 4 0", "3 4 0", "4 4 0", "1 0 1"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 206
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
A greek once sifted some numbers. And it did something wonderful!
-----Input:-----
- First line will contain an integer $N$
-----Output:-----
Output in a single line answer to the problem.
-----Constraints-----
- $1 \leq N \leq 10^5$
-----Sample Input 1:-----
10
-----Sample Output 1:-----
4
-----Sample Input 2:-----
20
-----Sample Output 2:-----
8
|
{"inputs": ["10", "20"], "outputs": ["4", "8"]}
| 112
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $a=[1, 3, 3, 7]$ is good because there is the element $a_4=7$ which equals to the sum $1 + 3 + 3$.
You are given an array $a$ consisting of $n$ integers. Your task is to print all indices $j$ of this array such that after removing the $j$-th element from the array it will be good (let's call such indices nice).
For example, if $a=[8, 3, 5, 2]$, the nice indices are $1$ and $4$: if you remove $a_1$, the array will look like $[3, 5, 2]$ and it is good; if you remove $a_4$, the array will look like $[8, 3, 5]$ and it is good.
You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.
-----Input-----
The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of elements in the array $a$.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — elements of the array $a$.
-----Output-----
In the first line print one integer $k$ — the number of indices $j$ of the array $a$ such that after removing the $j$-th element from the array it will be good (i.e. print the number of the nice indices).
In the second line print $k$ distinct integers $j_1, j_2, \dots, j_k$ in any order — nice indices of the array $a$.
If there are no such indices in the array $a$, just print $0$ in the first line and leave the second line empty or do not print it at all.
-----Examples-----
Input
5
2 5 1 2 2
Output
3
4 1 5
Input
4
8 3 5 2
Output
2
1 4
Input
5
2 1 2 4 3
Output
0
-----Note-----
In the first example you can remove any element with the value $2$ so the array will look like $[5, 1, 2, 2]$. The sum of this array is $10$ and there is an element equals to the sum of remaining elements ($5 = 1 + 2 + 2$).
In the second example you can remove $8$ so the array will look like $[3, 5, 2]$. The sum of this array is $10$ and there is an element equals to the sum of remaining elements ($5 = 3 + 2$). You can also remove $2$ so the array will look like $[8, 3, 5]$. The sum of this array is $16$ and there is an element equals to the sum of remaining elements ($8 = 3 + 5$).
In the third example you cannot make the given array good by removing exactly one element.
|
{"inputs": ["2\n4 5\n", "2\n2 2\n", "2\n1 1\n", "2\n1 5\n", "2\n1 2\n", "2\n5 1\n", "2\n1 5\n", "2\n1 1\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]}
| 756
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
You get a new job working for Eggman Movers. Your first task is to write a method that will allow the admin staff to enter a person’s name and return what that person's role is in the company.
You will be given an array of object literals holding the current employees of the company. You code must find the employee with the matching firstName and lastName and then return the role for that employee or if no employee is not found it should return "Does not work here!"
The array is preloaded and can be referenced using the variable `employees` (`$employees` in Ruby). It uses the following structure.
```python
employees = [ {'first_name': "Dipper", 'last_name': "Pines", 'role': "Boss"}, ...... ]
```
There are no duplicate names in the array and the name passed in will be a single string with a space between the first and last name i.e. Jane Doe or just a name.
Also feel free to reuse/extend the following starter code:
```python
employees = [{'first_name': 'Ollie', 'last_name': 'Hepburn', 'role': 'Boss'}, {'first_name': 'Morty', 'last_name': 'Smith', 'role': 'Truck Driver'}, {'first_name': 'Peter', 'last_name': 'Ross', 'role': 'Warehouse Manager'}, {'first_name': 'Cal', 'last_name': 'Neil', 'role': 'Sales Assistant'}, {'first_name': 'Jesse', 'last_name': 'Saunders', 'role': 'Admin'}, {'first_name': 'Anna', 'last_name': 'Jones', 'role': 'Sales Assistant'}, {'first_name': 'Carmel', 'last_name': 'Hamm', 'role': 'Admin'}, {'first_name': 'Tori', 'last_name': 'Sparks', 'role': 'Sales Manager'}, {'first_name': 'Peter', 'last_name': 'Jones', 'role': 'Warehouse Picker'}, {'first_name': 'Mort', 'last_name': 'Smith', 'role': 'Warehouse Picker'}, {'first_name': 'Anna', 'last_name': 'Bell', 'role': 'Admin'}, {'first_name': 'Jewel', 'last_name': 'Bell', 'role': 'Receptionist'}, {'first_name': 'Colin', 'last_name': 'Brown', 'role': 'Trainee'}]
def find_employees_role(name):
```
|
{"functional": "_inputs = [['Dipper Pines'], ['Morty Smith'], ['Anna Bell'], ['Anna'], ['Bell Anna'], ['Jewel Bell'], ['Bell Jewel']]\n_outputs = [['Does not work here!'], ['Truck Driver'], ['Admin'], ['Does not work here!'], ['Does not work here!'], ['Receptionist'], ['Does not work here!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(find_employees_role(*i), o[0])"}
| 524
| 225
|
coding
|
Solve the programming task below in a Python markdown code block.
There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.
How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?
Find the count modulo 1\ 000\ 000\ 007.
-----Constraints-----
- 1 \leq N \leq 10^5
- 0 \leq M \leq N-1
- 1 \leq a_1 < a_2 < ... < a_M \leq N-1
-----Input-----
Input is given from Standard Input in the following format:
N M
a_1
a_2
.
.
.
a_M
-----Output-----
Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.
-----Sample Input-----
6 1
3
-----Sample Output-----
4
There are four ways to climb up the stairs, as follows:
- 0 \to 1 \to 2 \to 4 \to 5 \to 6
- 0 \to 1 \to 2 \to 4 \to 6
- 0 \to 2 \to 4 \to 5 \to 6
- 0 \to 2 \to 4 \to 6
|
{"inputs": ["1 0\n", "2 0\n", "7 0\n", "25 0\n", "4 1\n3", "6 1\n1", "4 1\n2", "5 1\n1"], "outputs": ["1\n", "2\n", "21\n", "121393\n", "2\n", "5\n", "1\n", "3\n"]}
| 385
| 97
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.
Please complete the following python code precisely:
```python
class Solution:
def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]) == True\n assert candidate(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]) == False\n\n\ncheck(Solution().checkStraightLine)"}
| 95
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol".
For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest alphanumeric palindrome that could be made by combining the characters in any order but using each character only once. The function should not be case sensitive.
For example if passed "Hannah" it should return 6 and if passed "aabbcc_yYx_" it should return 9 because one possible palindrome would be "abcyxycba".
Also feel free to reuse/extend the following starter code:
```python
def longest_palindrome(s):
```
|
{"functional": "_inputs = [['A'], ['Hannah'], ['xyz__a_/b0110//a_zyx'], ['$aaabbbccddd_!jJpqlQx_.///yYabababhii_'], ['']]\n_outputs = [[1], [6], [13], [25], [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 len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(longest_palindrome(*i), o[0])"}
| 160
| 216
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes.
You are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, col2i], you should do the following operation:
Add 1 to every element in the submatrix with the top left corner (row1i, col1i) and the bottom right corner (row2i, col2i). That is, add 1 to mat[x][y] for all row1i <= x <= row2i and col1i <= y <= col2i.
Return the matrix mat after performing every query.
Please complete the following python code precisely:
```python
class Solution:
def rangeAddQueries(self, n: int, queries: List[List[int]]) -> List[List[int]]:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 3, queries = [[1,1,2,2],[0,0,1,1]]) == [[1,1,0],[1,2,1],[0,1,1]]\n assert candidate(n = 2, queries = [[0,0,1,1]]) == [[1,1],[1,1]]\n\n\ncheck(Solution().rangeAddQueries)"}
| 207
| 100
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
1. Append a_i to the end of b.
2. Reverse the order of the elements in b.
Find the sequence b obtained after these n operations.
Constraints
* 1 \leq n \leq 2\times 10^5
* 0 \leq a_i \leq 10^9
* n and a_i are integers.
Input
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n
Output
Print n integers in a line with spaces in between. The i-th integer should be b_i.
Examples
Input
4
1 2 3 4
Output
4 2 1 3
Input
3
1 2 3
Output
3 1 2
Input
1
1000000000
Output
1000000000
Input
6
0 6 7 6 7 0
Output
0 6 6 0 7 7
|
{"inputs": ["3\n2 2 3", "3\n4 2 3", "3\n6 2 3", "3\n6 2 5", "3\n6 4 5", "3\n2 4 5", "3\n2 2 5", "3\n2 2 4"], "outputs": ["3 2 2\n", "3 4 2\n", "3 6 2\n", "5 6 2\n", "5 6 4\n", "5 2 4\n", "5 2 2\n", "4 2 2\n"]}
| 278
| 142
|
coding
|
Solve the programming task below in a Python markdown code block.
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Input
The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
Output
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Examples
Input
0
Output
0
Input
10
Output
1
Input
991
Output
3
Note
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
|
{"inputs": ["8\n", "1\n", "9\n", "5\n", "2\n", "6\n", "4\n", "3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 275
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
To help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued together pairs of tiles with 0 written on them. Lavanya now has square tiles with 1 on them and rectangular tiles with two 0's on them, made up of two square tiles with 0 stuck together). Thus, she can no longer make all possible binary sequences using these tiles.
To amuse herself, Lavanya has decided to pick a number $N$ and try and construct as many binary sequences of length $N$ as possible using her collection of tiles. For example if $N$ = 1, she can only make the sequence 1. For $N$=2, she can make 11 and 00. For $N$=4, there are 5 possibilities: 0011, 0000, 1001, 1100 and 1111.
Lavanya would like you to write a program to compute the number of arrangements possible with $N$ tiles so that she can verify that she has generated all of them. Since she cannot count beyond 15746, it is sufficient to report this number modulo 15746.
-----Input:-----
A single line with a single integer $N$.
-----Output:-----
A single integer indicating the number of binary sequences of length $N$, modulo 15746, that Lavanya can make using her tiles.
-----Constraints:-----
You may assume that $N \leq$ 1000000.
-----Sample Input:-----
4
-----Sample Output:-----
5
-----Explanation:-----
This corresponds to the example discussed above.
|
{"inputs": ["4"], "outputs": ["5"]}
| 405
| 12
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi.
How many ways are there to choose K consecutive integers?
Constraints
* All values in input are integers.
* 1 \leq K \leq N \leq 50
Input
Input is given from Standard Input in the following format:
N K
Output
Print the answer.
Examples
Input
3 2
Output
2
Input
13 3
Output
11
|
{"inputs": ["6 2", "2 1", "2 0", "0 0", "0 1", "6 1", "9 0", "6 0"], "outputs": ["5\n", "2\n", "3\n", "1\n", "0\n", "6\n", "10\n", "7\n"]}
| 127
| 79
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is not feeling well today. He measured his body temperature using a thermometer and it came out to be X °F.
A person is said to have fever if his body temperature is strictly greater than 98 °F.
Determine if Chef has fever or not.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains one integer X - the body temperature of Chef in °F.
------ Output Format ------
For each test case, output YES if Chef has fever. Otherwise, output NO.
You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical).
------ Constraints ------
$1 ≤T ≤10$
$94 ≤X ≤103$
----- Sample Input 1 ------
3
98
100
96
----- Sample Output 1 ------
NO
YES
NO
----- explanation 1 ------
Test Case 1: Since $X = 98$ is not greater than $98$, Chef does not have fever.
Test Case 2: Since $X = 100$ is greater than $98$, Chef has fever.
Test Case 3: Since $X = 96$ is not greater than $98$, Chef does not have fever.
|
{"inputs": ["3\n98\n100\n96\n"], "outputs": ["NO\nYES\nNO\n"]}
| 309
| 28
|
coding
|
Solve the programming task below in a Python markdown code block.
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero).
The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.
Input
The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106).
The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).
Output
Print the maximum possible total sociability of all groups.
Examples
Input
5
1 2 3 1 2
Output
3
Input
3
3 3 3
Output
0
Note
In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.
In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.
|
{"inputs": ["1\n0\n", "3\n8 1 2\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n3 3 0\n", "3\n4 3 0\n", "3\n4 3 1\n", "3\n5 3 1\n"], "outputs": ["0\n", "7\n", "1\n", "0\n", "3\n", "4\n", "3\n", "4\n"]}
| 311
| 114
|
coding
|
Solve the programming task below in a Python markdown code block.
-----Input-----
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
-----Output-----
Output "YES" or "NO".
-----Examples-----
Input
NEAT
Output
YES
Input
WORD
Output
NO
Input
CODER
Output
NO
Input
APRILFOOL
Output
NO
Input
AI
Output
YES
Input
JUROR
Output
YES
Input
YES
Output
NO
|
{"inputs": ["Q\n", "Q\n", "P\n", "O\n", "AI\n", "IS\n", "IS\n", "JS\n"], "outputs": ["YES\n", "YES", "YES\n", "YES\n", "YES\n", "NO\n", "NO", "YES\n"]}
| 124
| 68
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case.
# Input/Output
`[input]` string `s`
String of odd length consisting of English letters.
3 ≤ inputString.length ≤ 99.
`[output]` a string
The resulting string.
# Example
For `s = "Aba"`, the output should be `"aba"`
For `s = "ABa"`, the output should be `"ABA"`
Also feel free to reuse/extend the following starter code:
```python
def case_unification(s):
```
|
{"functional": "_inputs = [['asdERvT'], ['oyTYbWQ'], ['bbiIRvbcW'], ['rWTmvcoRWEWQQWR']]\n_outputs = [['asdervt'], ['OYTYBWQ'], ['bbiirvbcw'], ['RWTMVCORWEWQQWR']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(case_unification(*i), o[0])"}
| 150
| 212
|
coding
|
Solve the programming task below in a Python markdown code block.
Have you heard about the myth that [if you fold a paper enough times, you can reach the moon with it](http://scienceblogs.com/startswithabang/2009/08/31/paper-folding-to-the-moon/)? Sure you have, but exactly how many? Maybe it's time to write a program to figure it out.
You know that a piece of paper has a thickness of `0.0001m`. Given `distance` in units of meters, calculate how many times you have to fold the paper to make the paper reach this distance.
(If you're not familiar with the concept of folding a paper: Each fold doubles its total thickness.)
Note: Of course you can't do half a fold. You should know what this means ;P
Also, if somebody is giving you a negative distance, it's clearly bogus and you should yell at them by returning `null` (or whatever equivalent in your language. In Shell please return `None`).
Also feel free to reuse/extend the following starter code:
```python
def fold_to(distance):
```
|
{"functional": "_inputs = [[384000000], [5e-05], [1e-07], [0], [-1]]\n_outputs = [[42], [0], [0], [0], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(fold_to(*i), o[0])"}
| 242
| 196
|
coding
|
Solve the programming task below in a Python markdown code block.
The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.
Nam created a sequence a consisting of n (1 ≤ n ≤ 10^5) elements a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5). A subsequence a_{i}_1, a_{i}_2, ..., a_{i}_{k} where 1 ≤ i_1 < i_2 < ... < i_{k} ≤ n is called increasing if a_{i}_1 < a_{i}_2 < a_{i}_3 < ... < a_{i}_{k}. An increasing subsequence is called longest if it has maximum length among all increasing subsequences.
Nam realizes that a sequence may have several longest increasing subsequences. Hence, he divides all indexes i (1 ≤ i ≤ n), into three groups: group of all i such that a_{i} belongs to no longest increasing subsequences. group of all i such that a_{i} belongs to at least one but not every longest increasing subsequence. group of all i such that a_{i} belongs to every longest increasing subsequence.
Since the number of longest increasing subsequences of a may be very large, categorizing process is very difficult. Your task is to help him finish this job.
-----Input-----
The first line contains the single integer n (1 ≤ n ≤ 10^5) denoting the number of elements of sequence a.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5).
-----Output-----
Print a string consisting of n characters. i-th character should be '1', '2' or '3' depending on which group among listed above index i belongs to.
-----Examples-----
Input
1
4
Output
3
Input
4
1 3 2 5
Output
3223
Input
4
1 5 2 3
Output
3133
-----Note-----
In the second sample, sequence a consists of 4 elements: {a_1, a_2, a_3, a_4} = {1, 3, 2, 5}. Sequence a has exactly 2 longest increasing subsequences of length 3, they are {a_1, a_2, a_4} = {1, 3, 5} and {a_1, a_3, a_4} = {1, 2, 5}.
In the third sample, sequence a consists of 4 elements: {a_1, a_2, a_3, a_4} = {1, 5, 2, 3}. Sequence a have exactly 1 longest increasing subsequence of length 3, that is {a_1, a_3, a_4} = {1, 2, 3}.
|
{"inputs": ["1\n4\n", "1\n7\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n11\n", "2\n5 4\n", "2\n5 4\n"], "outputs": ["3\n", "3", "3", "3", "3", "3", "22\n", "22"]}
| 667
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
Kulyash loves perfect squares and hates perfect cubes.
For any natural number N,
F(N) = \texttt{number of perfect squares smaller than or equal to } N - \texttt{number of positive perfect cubes smaller than or equal to } N.
Kulyash gives you an integer X and asks you to find the minimum value of N, such that F(N) ≥ X.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input.
- The first and only line of each test case contains an integer X.
------ Output Format ------
For each test case, output on a new line, the minimum value of N such that F(N) ≥ X.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ X ≤ 10^{9}$
----- Sample Input 1 ------
3
1
3
3151
----- Sample Output 1 ------
4
25
11397376
----- explanation 1 ------
Test case $1$: There are $2$ perfect squares from $1$ to $4$, and $1$ perfect cube from $1$ to $4$, so $F(4) = 2 - 1 = 1$, as required.
Test case $2$: There are $5$ perfect squares from $1$ to $25$, and $2$ perfect cubes from $1$ to $25$, so $F(25) = 5 - 2 = 3$, as required.
Test case $3$: There are $3376$ perfect squares from $1$ to $11397376$, and $225$ perfect cubes from $1$ to $11397376$, so $F(11397376) = 3376 - 225 = 3151$, as required.
|
{"inputs": ["3\n1\n3\n3151\n"], "outputs": ["4\n25\n11397376\n"]}
| 450
| 35
|
coding
|
Solve the programming task below in a Python markdown code block.
Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.
-----Input-----
The first line contains two integers x_1, y_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9) — the start position of the robot.
The second line contains two integers x_2, y_2 ( - 10^9 ≤ x_2, y_2 ≤ 10^9) — the finish position of the robot.
-----Output-----
Print the only integer d — the minimal number of steps to get the finish position.
-----Examples-----
Input
0 0
4 5
Output
5
Input
3 4
6 1
Output
3
-----Note-----
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.
In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.
|
{"inputs": ["0 0\n4 5\n", "3 4\n6 1\n", "0 0\n4 6\n", "0 0\n2 1\n", "1 5\n6 4\n", "0 0\n5 4\n", "0 0\n4 0\n", "9 1\n1 1\n"], "outputs": ["5\n", "3\n", "6\n", "2\n", "5\n", "5\n", "4\n", "8\n"]}
| 314
| 118
|
coding
|
Solve the programming task below in a Python markdown code block.
Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.
Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 10^9 + 7.
Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.
-----Input-----
The only line contains three integers n, m and k (1 ≤ n, m ≤ 10^18, k is either 1 or -1).
-----Output-----
Print a single number denoting the answer modulo 1000000007.
-----Examples-----
Input
1 1 -1
Output
1
Input
1 3 1
Output
1
Input
3 3 -1
Output
16
-----Note-----
In the first example the only way is to put -1 into the only block.
In the second example the only way is to put 1 into every block.
|
{"inputs": ["1 3 1\n", "2 7 1\n", "1 1 1\n", "2 2 1\n", "1 1 1\n", "2 2 1\n", "2 7 1\n", "1 7 1\n"], "outputs": ["1\n", "64\n", "1\n", "2\n", "1", "2\n", "64\n", "1\n"]}
| 342
| 103
|
coding
|
Solve the programming task below in a Python markdown code block.
Below is a right-angled triangle:
```
|\
| \
| \
| \
o | \ h
| \
| θ \
|_______\
a
```
Your challange is to write a function (```missingAngle``` in C/C#, ```missing_angle``` in Ruby), that calculates the angle θ in degrees to the nearest integer. You will be given three arguments representing each side: o, h and a. One of the arguments equals zero. Use the length of the two other sides to calculate θ. You will not be expected to handle any erronous data in your solution.
Also feel free to reuse/extend the following starter code:
```python
def missing_angle(h, a, o):
```
|
{"functional": "_inputs = [[0, 400, 300], [5, 4, 0], [8, 0, 5], [16.7, 0, 12.3], [7, 5, 0]]\n_outputs = [[37], [37], [39], [47], [44]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(missing_angle(*i), o[0])"}
| 179
| 224
|
coding
|
Solve the programming task below in a Python markdown code block.
Beaches are filled with sand, water, fish, and sun. Given a string, calculate how many times the words `"Sand"`, `"Water"`, `"Fish"`, and `"Sun"` appear without overlapping (regardless of the case).
## Examples
```python
sum_of_a_beach("WAtErSlIde") ==> 1
sum_of_a_beach("GolDeNSanDyWateRyBeaChSuNN") ==> 3
sum_of_a_beach("gOfIshsunesunFiSh") ==> 4
sum_of_a_beach("cItYTowNcARShoW") ==> 0
```
Also feel free to reuse/extend the following starter code:
```python
def sum_of_a_beach(beach):
```
|
{"functional": "_inputs = [['SanD'], ['sunshine'], ['sunsunsunsun'], ['123FISH321'], ['weoqipurpoqwuirpousandiupqwoieurioweuwateruierqpoiweurpouifiShqowieuqpwoeuisUn'], ['sAnDsandwaTerwatErfishFishsunsunsandwater'], ['joifjepiojfoiejfoajoijawoeifjowejfjoiwaefjiaowefjaofjwoj fawojef '], ['jwefjwjfsandsandwaterwaterfishfishsunsunsandwateriojwhefa;jawof;jawio;f'], ['saNdsandwaterwAterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwatersandsandwaterwaterfishfishsunsunsandwater'], ['sununsu'], ['sandandndsansa'], ['wateratertererwatewatwa'], ['fishishshfisfi']]\n_outputs = [[1], [1], [4], [1], [4], [10], [0], [10], [100], [1], [1], [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) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(sum_of_a_beach(*i), o[0])"}
| 188
| 490
|
coding
|
Solve the programming task below in a Python markdown code block.
This semester, Chef took X courses. Each course has Y units and each unit has Z chapters in it.
Find the total number of chapters Chef has to study this semester.
------ Input Format ------
- The first line will contain T, the number of test cases. Then the test cases follow.
- Each test case consists of a single line of input, containing three space-separated integers X, Y, and Z.
------ Output Format ------
For each test case, output in a single line the total number of chapters Chef has to study this semester.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ X, Y, Z ≤ 1000$
----- Sample Input 1 ------
3
1 1 1
2 1 2
1 2 3
----- Sample Output 1 ------
1
4
6
----- explanation 1 ------
Test case $1$: There is only $1$ course with $1$ unit. The unit has $1$ chapter. Thus, the total number of chapters is $1$.
Test case $2$: There are $2$ courses with $1$ unit each. Thus, there are $2$ units. Each unit has $2$ chapters. Thus, the total number of chapters is $4$.
Test case $3$: There is only $1$ course with $2$ units. Each unit has $3$ chapters. Thus, the total number of chapters is $6$.
|
{"inputs": ["3\n1 1 1\n2 1 2\n1 2 3"], "outputs": ["1\n4\n6"]}
| 322
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
D: Is greed the best?
story
In Japan, where there are 1, 5, 10, 50, 100, 500 yen coins, it is known that the number of coins can be minimized by using as many coins as possible when paying a certain amount. ..
If the amount of coins is different from that of Japan, it is not always possible to minimize it by paying greedily.
What are the conditions that the amount of coins must meet in order to be optimally paid greedily?
problem
TAB was curious about the above, so I decided to first consider the case where there are only three types of coins, 1, A and B.
Since A and B are given, output the smallest amount of money that will not minimize the number of sheets if you pay greedily.
Also, if the greedy algorithm is optimal for any amount of money, output -1.
Input format
A B
Constraint
* 1 <A \ leq 10 ^ 5
* A <B \ leq 10 ^ 9
Input example 1
4 6
Output example 1
8
If you greedily pay 8 yen, you will pay 6 + 1 \ times 2 for a total of 3 cards, but you can pay 4 \ times 2 for a total of 2 cards.
Input example 2
2 1000000000
Output example 2
-1
It is best to greedily pay any amount.
Example
Input
4 6
Output
8
|
{"inputs": ["2 6", "6 7", "5 7", "4 5", "7 9", "3 4", "2 7", "2 3"], "outputs": ["-1\n", "12\n", "10\n", "8\n", "14\n", "6\n", "-1\n", "-1\n"]}
| 350
| 82
|
coding
|
Solve the programming task below in a Python markdown code block.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
-----Input-----
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
-----Output-----
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
-----Examples-----
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
-----Note-----
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
|
{"inputs": ["1 1\nR\n", "1 1\nR\n", "1 2\nRB\n", "1 2\nRG\n", "1 2\nRG\n", "1 2\nRB\n", "1 3\nGRB\n", "1 3\nRGG\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n"]}
| 404
| 104
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.
Return the number of connected components in the graph.
Please complete the following python code precisely:
```python
class Solution:
def countComponents(self, n: int, edges: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[0, 1], [1, 2], [3, 4]]) == 2\n assert candidate(n = 5, edges = [[0,1], [1,2], [2,3], [3,4]]) == 1\n\n\ncheck(Solution().countComponents)"}
| 105
| 85
|
coding
|
Solve the programming task below in a Python markdown code block.
A game is played on a strip consisting of N cells consecutively numbered from 1 to N.
Alice has her token on cell A. Borys has his token on a different cell B.
Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once.
The player who can't make a move loses, and the other player wins.
Both players want to win. Who wins if they play optimally?
Constraints
* 2 \leq N \leq 100
* 1 \leq A < B \leq N
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins.
Examples
Input
5 2 4
Output
Alice
Input
2 1 2
Output
Borys
Input
58 23 42
Output
Borys
|
{"inputs": ["8 2 4", "3 1 2", "3 2 2", "8 2 3", "0 2 2", "7 2 3", "0 2 1", "7 2 5"], "outputs": ["Alice\n", "Borys\n", "Alice\n", "Borys\n", "Alice\n", "Borys\n", "Borys\n", "Borys\n"]}
| 297
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.
Given the current ranking in the competition and points distribution for the next race, your task is to calculate the best possible ranking for a given astronaut after the next race. It's guaranteed that given astronaut will have unique number of points before the race.
-----Input-----
The first line contains two integer numbers $N$ ($1 \leq N \leq 200000$) representing number of F1 astronauts, and current position of astronaut $D$ ($1 \leq D \leq N$) you want to calculate best ranking for (no other competitor will have the same number of points before the race).
The second line contains $N$ integer numbers $S_k$ ($0 \leq S_k \leq 10^8$, $k=1...N$), separated by a single space, representing current ranking of astronauts. Points are sorted in non-increasing order.
The third line contains $N$ integer numbers $P_k$ ($0 \leq P_k \leq 10^8$, $k=1...N$), separated by a single space, representing point awards for the next race. Points are sorted in non-increasing order, so winner of the race gets the maximum number of points.
-----Output-----
Output contains one integer number — the best possible ranking for astronaut after the race. If multiple astronauts have the same score after the race, they all share the best ranking.
-----Example-----
Input
4 3
50 30 20 10
15 10 7 3
Output
2
-----Note-----
If the third ranked astronaut wins the race, he will have 35 points. He cannot take the leading position, but he can overtake the second position if the second ranked astronaut finishes the race at the last position.
|
{"inputs": ["1 1\n5\n5\n", "1 1\n5\n5\n", "1 1\n5\n7\n", "1 1\n5\n8\n", "1 1\n1\n5\n", "1 1\n5\n9\n", "1 1\n1\n3\n", "1 1\n5\n0\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 418
| 117
|
coding
|
Solve the programming task below in a Python markdown code block.
In Chefland, everyone who earns strictly more than Y rupees per year, has to pay a tax to Chef. Chef has allowed a special scheme where you can invest any amount of money and claim exemption for it.
You have earned X (X > Y) rupees this year. Find the minimum amount of money you have to invest so that you don't have to pay taxes this year.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input consisting of two space separated integers X and Y denoting the amount you earned and the amount above which you will have to pay taxes.
------ Output Format ------
For each test case, output a single integer, denoting the minimum amount you need to invest.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ Y < X ≤ 100$
----- Sample Input 1 ------
4
4 2
8 7
5 1
2 1
----- Sample Output 1 ------
2
1
4
1
----- explanation 1 ------
Test case $1$: The amount above which you will have to pay taxes is $2$. Since you earn $4$ rupees, you need to invest at least $2$ rupees. After investing $2$ rupees, you will remain with an effective income $4 - 2 = 2$ rupees which will not be taxed.
Test case $2$: The amount above which you will have to pay taxes is $7$. Since you earn $8$ rupees, you need to invest at least $1$ rupees.
Test case $3$: The amount above which you will have to pay taxes is $1$. Since you earn $5$ rupees, you need to invest at least $4$ rupees.
Test case $4$: The amount above which you will have to pay taxes is $1$. Since you earn $2$ rupees, you need to invest at least $1$ rupees.
|
{"inputs": ["4\n4 2\n8 7\n5 1\n2 1\n"], "outputs": ["2\n1\n4\n1\n"]}
| 447
| 36
|
coding
|
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 search tree and an array queries of size n consisting of positive integers.
Find a 2D array answer of size n where answer[i] = [mini, maxi]:
mini is the largest value in the tree that is smaller than or equal to queries[i]. If a such value does not exist, add -1 instead.
maxi is the smallest value in the tree that is greater than or equal to queries[i]. If a such value does not exist, add -1 instead.
Return the array answer.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def closestNodes(self, root: Optional[TreeNode], queries: List[int]) -> List[List[int]]:
```
|
{"functional": "def check(candidate):\n assert candidate(root = tree_node([6,2,13,1,4,9,15,None,None,None,None,None,None,14]), queries = [2,5,16]) == [[2,2],[4,6],[15,-1]]\n assert candidate(root = tree_node([4,None,9]), queries = [3]) == [[-1,4]]\n\n\ncheck(Solution().closestNodes)"}
| 217
| 106
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A wonderful string is a string where at most one letter appears an odd number of times.
For example, "ccjjc" and "abab" are wonderful, but "ab" is not.
Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.
A substring is a contiguous sequence of characters in a string.
Please complete the following python code precisely:
```python
class Solution:
def wonderfulSubstrings(self, word: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(word = \"aba\") == 4\n assert candidate(word = \"aabb\") == 9\n assert candidate(word = \"he\") == 2\n\n\ncheck(Solution().wonderfulSubstrings)"}
| 149
| 59
|
coding
|
Solve the programming task below in a Python markdown code block.
Create a method (**JS**: function) `every` which returns every nth element of an array.
### Usage
With no arguments, `array.every` it returns every element of the array.
With one argument, `array.every(interval)` it returns every `interval`th element.
With two arguments, `array.every(interval, start_index)` it returns every `interval`th element starting at index `start_index`
**Note**: due to fact JS translation ask for a function instead of an Array method the above uses will be :
```
javascript: ruby:
every(array) array.every
every(array, interval) array.every(interval)
every(array, interval, start_index) array.every(interval, start_index)
```
### Examples
### Notes
Test cases:
`interval` will always be a positive integer (but may be larger than the size of the array).
`start_index` will always be within the bounds of the array.
Once you have completed this kata, try the **advanced version** (http://www.codewars.com/kata/every-nth-array-element-advanced) which allows negative intervals and unbounded start\_indexes
### Translator notes
Ruby is the original language for this kata.
Also feel free to reuse/extend the following starter code:
```python
def every(array, interval = 1, start_index = 0):
```
|
{"functional": "_inputs = [[[None, None, None, None, None], 2]]\n_outputs = [[[None, None, None]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(every(*i), o[0])"}
| 299
| 169
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:
You will pick any pizza slice.
Your friend Alice will pick the next slice in the anti-clockwise direction of your pick.
Your friend Bob will pick the next slice in the clockwise direction of your pick.
Repeat until there are no more slices of pizzas.
Given an integer array slices that represent the sizes of the pizza slices in a clockwise direction, return the maximum possible sum of slice sizes that you can pick.
Please complete the following python code precisely:
```python
class Solution:
def maxSizeSlices(self, slices: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(slices = [1,2,3,4,5,6]) == 10\n assert candidate(slices = [8,9,8,6,1,1]) == 16\n\n\ncheck(Solution().maxSizeSlices)"}
| 156
| 69
|
coding
|
Solve the programming task below in a Python markdown code block.
Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this character.
Petya wants to get strings s and t empty and string u lexicographically minimal.
You should write a program that will help Petya win the game.
-----Input-----
First line contains non-empty string s (1 ≤ |s| ≤ 10^5), consisting of lowercase English letters.
-----Output-----
Print resulting string u.
-----Examples-----
Input
cab
Output
abc
Input
acdb
Output
abdc
|
{"inputs": ["a\n", "a\n", "a\n", "a\n", "b\n", "b\n", "a\n", "c\n"], "outputs": ["a\n", "a\n", "a\n", "a\n", "b\n", "b\n", "a\n", "c\n"]}
| 180
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
When working with color values it can sometimes be useful to extract the individual red, green, and blue (RGB) component values for a color. Implement a function that meets these requirements:
+ Accepts a case-insensitive hexadecimal color string as its parameter (ex. `"#FF9933"` or `"#ff9933"`)
+ Returns an object with the structure `{r: 255, g: 153, b: 51}` where *r*, *g*, and *b* range from 0 through 255
**Note:** your implementation does not need to support the shorthand form of hexadecimal notation (ie `"#FFF"`)
## Example
```
"#FF9933" --> {r: 255, g: 153, b: 51}
```
Also feel free to reuse/extend the following starter code:
```python
def hex_string_to_RGB(hex_string):
```
|
{"functional": "_inputs = [['#FF9933'], ['#beaded'], ['#000000'], ['#111111'], ['#Fa3456']]\n_outputs = [[{'r': 255, 'g': 153, 'b': 51}], [{'r': 190, 'g': 173, 'b': 237}], [{'r': 0, 'g': 0, 'b': 0}], [{'r': 17, 'g': 17, 'b': 17}], [{'r': 250, 'g': 52, 'b': 86}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(hex_string_to_RGB(*i), o[0])"}
| 216
| 295
|
coding
|
Solve the programming task below in a Python markdown code block.
Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of partitions. Table A is distributed on the first cluster consisting of m partitions. Partition with index i has a_{i} rows from A. Similarly, second cluster containing table B has n partitions, i-th one having b_{i} rows from B.
In one network operation she can copy one row from any partition to any other partition. At the end, for each row from A and each row from B there should be a partition that has both rows. Determine the minimal number of network operations to achieve this.
-----Input-----
First line contains two integer numbers, m and n (1 ≤ m, n ≤ 10^5). Second line contains description of the first cluster with m space separated integers, a_{i} (1 ≤ a_{i} ≤ 10^9). Similarly, third line describes second cluster with n space separated integers, b_{i} (1 ≤ b_{i} ≤ 10^9).
-----Output-----
Print one integer — minimal number of copy operations.
-----Examples-----
Input
2 2
2 6
3 100
Output
11
Input
2 3
10 10
1 1 1
Output
6
-----Note-----
In the first example it makes sense to move all the rows to the second partition of the second cluster which is achieved in 2 + 6 + 3 = 11 operations
In the second example Piegirl can copy each row from B to the both partitions of the first cluster which needs 2·3 = 6 copy operations.
|
{"inputs": ["2 2\n2 6\n3 100\n", "1 1\n1889\n2867\n", "1 1\n1889\n2867\n", "2 2\n2 6\n3 100\n", "2 3\n10 10\n1 1 1\n", "2 3\n10 10\n1 1 2\n", "2 3\n10 10\n0 1 2\n", "2 3\n10 10\n0 1 0\n"], "outputs": ["11\n", "1889\n", "1889\n", "11\n", "6\n", "8\n", "6\n", "2\n"]}
| 386
| 182
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We are given hours, a list of the number of hours worked per day for a given employee.
A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.
A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.
Return the length of the longest well-performing interval.
Please complete the following python code precisely:
```python
class Solution:
def longestWPI(self, hours: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(hours = [9,9,6,0,6,6,9]) == 3\n assert candidate(hours = [6,6,6]) == 0\n\n\ncheck(Solution().longestWPI)"}
| 139
| 61
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer N. Find if it is possible to represent N as the sum of several(possibly zero) 2's and several(possibly zero) 7's.
Formally, find if there exist two integers X, Y \ (X, Y ≥ 0) such that 2 \cdot X + 7\cdot Y = N.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line containing an integer N.
------ Output Format ------
For each test case, print on a new line YES if it is possible to represent N as the sum of several(possibly zero) 2's and several(possibly zero) 7's and NO otherwise.
You may print each character of the string in either uppercase or lowercase (for example, the strings yEs, yes, Yes, and YES will all be treated as identical).
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{8}$
----- Sample Input 1 ------
4
2
5
7
11
----- Sample Output 1 ------
YES
NO
YES
YES
----- explanation 1 ------
Test case $1$: $2 \cdot 1 + 7\cdot 0 = 2$.
Test case $2$: It is impossible to express $5$ as a sum of several $2$'s and $7$'s.
Test case $3$: $2 \cdot 0 + 7\cdot 1 = 7$.
Test case $4$: $2 \cdot 2 + 7\cdot 1 = 11$.
|
{"inputs": ["4\n2\n5\n7\n11\n"], "outputs": ["YES\nNO\nYES\nYES\n"]}
| 377
| 29
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef and Chefina are at positions X and Y on a number line.
They both love badminton.
It is known that badminton courts are located at every integer point.
They want to find a court such that the *maximum* distance travelled by either of them is minimized.
Formally, suppose they choose the badminton court at position Z. You need to find the minimum value of \max(|X-Z|, |Y-Z|) across all possible choices of Z. Here, |X| denotes absolute value of X.
Report this minimum value.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two space-separated integers X and Y.
------ Output Format ------
For each test case, output the minimum possible value of \max(|X-Z|, |Y-Z|).
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ X, Y ≤ 1000$
$X \neq Y$
----- Sample Input 1 ------
4
3 5
7 6
1 10
63 31
----- Sample Output 1 ------
1
1
5
16
----- explanation 1 ------
Test case $1$: They will choose the court at position $4$ in the optimal case where both have to travel a distance of $1$ unit.
Test case $2$: They can either choose the court at position $6$ or position $7$. In both the cases one person has to travel a distance of $1$ unit.
|
{"inputs": ["4\n3 5\n7 6\n1 10\n63 31\n"], "outputs": ["1\n1\n5\n16\n"]}
| 352
| 40
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and so he wants the race to be close. This can happen only if the horses are comparable on their skill i.e. the difference in their skills is less.
There are N horses in the stable. The skill of the horse i is represented by an integer S[i]. The Chef needs to pick 2 horses for the race such that the difference in their skills is minimum. This way, he would be able to host a very interesting race. Your task is to help him do this and report the minimum difference that is possible between 2 horses in the race.
-----Input:-----
First line of the input file contains a single integer T, the number of test cases.
Every test case starts with a line containing the integer N.
The next line contains N space separated integers where the i-th integer is S[i].
-----Output:-----
For each test case, output a single line containing the minimum difference that is possible.
-----Constraints:-----
1 ≤ T ≤ 10
2 ≤ N ≤ 5000
1 ≤ S[i] ≤ 1000000000
-----Example:-----Input:
1
5
4 9 1 32 13
Output:
3
Explanation: The minimum difference can be achieved if we pick horses with skills 1 and 4 for the race.
|
{"inputs": ["1\n5\n4 9 1 32 13"], "outputs": ["3"]}
| 343
| 26
|
coding
|
Solve the programming task below in a Python markdown code block.
Space Coconut Crab
Space coconut crab
English text is not available in this practice contest.
Ken Marine Blue is a space hunter who travels through the entire galaxy in search of space coconut crabs. The space coconut crab is the largest crustacean in the universe, and it is said that the body length after growth is 400 meters or more, and if you spread your legs, it will reach 1,000 meters or more. Many people have already witnessed the space coconut crab, but none have succeeded in catching it.
Through a long-term study, Ken uncovered important facts about the ecology of space coconut crabs. Surprisingly, the space coconut crab did the same thing as the latest warp technology called phase transition navigation, and lived back and forth between normal space and hyperspace. Furthermore, it was found that it takes a long time for the space coconut crab to warp out from the hyperspace to the normal space, and that it cannot move to the hyperspace for a while after the warp out.
So Ken finally decided to catch the space coconut crab. The strategy is as follows. First, we observe the energy of the space coconut crab as it plunges from normal space into hyperspace. When this energy is e, it is known that the coordinates (x, y, z) at which the space coconut crab warps out of hyperspace satisfy the following conditions.
* x, y, z are all non-negative integers.
* x + y2 + z3 = e.
* Minimize the value of x + y + z under the above conditions.
These conditions alone do not always uniquely determine the coordinates, but it is certain that the coordinates to warp out are on the plane x + y + z = m, where m is the minimum value of x + y + z. Is. Therefore, a barrier of sufficient size is placed on this plane. Then, the space coconut crab will warp out to the place where the barrier is stretched. Space coconut crabs affected by the barrier get stuck. It is a setup to capture it with the weapon breaker, which is a state-of-the-art spacecraft operated by Ken.
The barrier can only be set once, so it cannot fail. So Ken decided to use a calculator to carry out his mission. Your job is to write a program that finds the plane x + y + z = m to which the barrier should be placed when the energy for the space coconut crab to enter the hyperspace is given. Your program will be accepted when it outputs the correct results for all of the prepared test cases.
Input
The input consists of multiple datasets. Each dataset consists of only one row and contains one positive integer e (e ≤ 1,000,000). This represents the energy when the space coconut crab rushes into hyperspace. The input ends when e = 0, which is not included in the dataset.
Output
For each dataset, output the value of m on one line. The output must not contain any other characters.
Sample Input
1
2
Four
27
300
1250
0
Output for the Sample Input
1
2
2
3
18
44
Example
Input
1
2
4
27
300
1250
0
Output
1
2
2
3
18
44
|
{"inputs": ["1\n3\n2\n3\n76\n116\n0", "1\n2\n4\n3\n76\n324\n0", "1\n1\n2\n0\n76\n116\n0", "1\n1\n1\n3\n333\n54\n0", "1\n2\n6\n1\n347\n31\n0", "1\n2\n4\n3\n76\n1250\n0", "1\n2\n3\n3\n76\n1250\n0", "1\n3\n3\n3\n76\n1250\n0"], "outputs": ["1\n3\n2\n3\n10\n14\n", "1\n2\n2\n3\n10\n18\n", "1\n1\n2\n", "1\n1\n1\n3\n21\n10\n", "1\n2\n4\n1\n9\n5\n", "1\n2\n2\n3\n10\n44\n", "1\n2\n3\n3\n10\n44\n", "1\n3\n3\n3\n10\n44\n"]}
| 707
| 271
|
coding
|
Solve the programming task below in a Python markdown code block.
#Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
result: 1
input: 'c'
result: 3
input: 'z'
result: 26
input: 'foo'
result: 3759
input: 'aba'
result: 27
input: 'abb'
result: 28
```
Also feel free to reuse/extend the following starter code:
```python
def permutation_position(perm):
```
|
{"functional": "_inputs = [['a'], ['z'], ['aaa'], ['aaab'], ['foo']]\n_outputs = [[1], [26], [1], [2], [3759]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(permutation_position(*i), o[0])"}
| 154
| 184
|
coding
|
Solve the programming task below in a Python markdown code block.
Notes
Template in C
Constraints
2 ≤ the number of operands in the expression ≤ 100
1 ≤ the number of operators in the expression ≤ 99
-1 × 109 ≤ values in the stack ≤ 109
Input
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.
You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106
Output
Print the computational result in a line.
Examples
Input
1 2 +
Output
3
Input
1 2 + 3 4 - *
Output
-3
|
{"inputs": ["1 3 +", "0 3 +", "0 3 *", "0 5 +", "0 1 +", "6 7 *", "0 4 +", "0 0 *"], "outputs": ["4\n", "3\n", "0\n", "5\n", "1\n", "42\n", "4\n", "0\n"]}
| 162
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
Input Format
N K
a_1 a_2 a_3 ... a_N
Output Format
Print the minimum cost in one line. In the end put a line break.
Constraints
* 1 ≤ K ≤ N ≤ 15
* 1 ≤ a_i ≤ 10^9
Scoring
Subtask 1 [120 points]
* N = K
Subtask 2 [90 points]
* N ≤ 5
* a_i ≤ 7
Subtask 3 [140 points]
* There are no additional constraints.
Output Format
Print the minimum cost in one line. In the end put a line break.
Constraints
* 1 ≤ K ≤ N ≤ 15
* 1 ≤ a_i ≤ 10^9
Scoring
Subtask 1 [120 points]
* N = K
Subtask 2 [90 points]
* N ≤ 5
* a_i ≤ 7
Subtask 3 [140 points]
* There are no additional constraints.
Input Format
N K
a_1 a_2 a_3 ... a_N
Example
Input
5 5
3949 3774 3598 3469 3424
Output
1541
|
{"inputs": ["5 5\n862 3408 1332 53 2597", "5 5\n862 3408 1332 56 2597", "5 5\n862 2044 1332 56 2597", "5 5\n862 3170 3598 192 3424", "5 5\n862 3170 3598 212 3424", "5 5\n862 3170 6376 212 3424", "5 5\n862 3170 6694 212 3424", "5 5\n862 3170 6694 212 3205"], "outputs": ["6248\n", "6245\n", "2703\n", "3583\n", "3563\n", "9119\n", "9755\n", "9974\n"]}
| 296
| 283
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has a stick of length L. Chef wants to break the stick into K parts such that each part has a non-zero length.
Let the lengths of the K parts be A_{1}, A_{2}, \ldots, A_{K} (Note that A_{1} + A_{2} + \ldots + A_{K} = L and A_{i} is a positive integer for all i). Chef wants to minimize the value of \displaystyle \sum_{i = 1}^{K - 1}|A_{i + 1} - A_{i}|. Can you help Chef? (Here |x| denotes the absolute value of x)
Under the given constraints it will always be possible to break the stick into K parts of non-zero lengths.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers L and K — the initial length of the stick and the number of parts Chef wants to break the stick into.
------ Output Format ------
For each test case, output the minimum value of \displaystyle \sum_{i = 1}^{K - 1}|A_{i + 1} - A_{i}|.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$2 ≤K ≤L ≤10^{9}$
----- Sample Input 1 ------
2
4 3
2 2
----- Sample Output 1 ------
1
0
----- explanation 1 ------
Test Case 1: It is optimal to break the stick of length $4$ into $3$ parts in the following manner: $[2, 1, 1]$. The value of $\displaystyle \sum_{i = 1}^{K - 1}|A_{i + 1} - A_{i}| = |1 - 2| + |1 - 1| = 1$.
Test Case 2: It is optimal to break the stick of length $2$ into $2$ parts in the following manner: $[1, 1]$. The value of $\displaystyle \sum_{i = 1}^{K - 1}|A_{i + 1} - A_{i}| = |1 - 1| = 0$.
|
{"inputs": ["2\n4 3\n2 2\n"], "outputs": ["1\n0\n"]}
| 516
| 24
|
coding
|
Solve the programming task below in a Python markdown code block.
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
There are $n$ boxes in front of you. For each $\boldsymbol{i}$, box $\boldsymbol{i}$ contains $r[i]$ red balls, $g[i]$ green balls, and $b[i]$ blue balls.
You want to separate the balls by their color. In each operation, you can pick a single ball from some box and put it into another box. The balls are separated if no box contains balls of more than one color.
Debug the given function min_operations and compute the minimal number of operations required to separate the balls.
Note: In this problem you can modify at most six lines of code and you cannot add any new lines.
To restore the original code, click on the icon to the right of the language selector.
Input Format
The first line contains a single integer $n$.
The next $n$ lines $\boldsymbol{i}$ contain three space-separated integers, $r[i]$, $g[i]$, and $b[i]$, respectively.
Constraints
$1\leq n\leq100$
$0\leq r[i],\ g[i],\ b[i]\leq105$
Output Format
Print the minimal number of operations required to separate the balls. If this is impossible, return $-1$.
Sample Input
3
1 1 1
1 1 1
1 1 1
Sample Output
6
Explanation
Each box contains 1 ball of each color. In this explanation, the goal will be to let the first box contain only red balls, the second box only blue balls, and the third box only green balls.
Move 1 blue ball and 1 green ball from the first box to the second and third boxes.
Move 1 red ball and 1 green ball from the second box to the first and third boxes.
Move 1 red ball and 1 blue ball from the third box to the first and second boxes.
The number of operations is 6.
|
{"inputs": ["3\n1 1 1\n1 1 1\n1 1 1\n"], "outputs": ["6\n"]}
| 449
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N cards placed face down in a row. On each card, an integer 1 or 2 is written.
Let A_i be the integer written on the i-th card.
Your objective is to guess A_1, A_2, ..., A_N correctly.
You know the following facts:
- For each i = 1, 2, ..., M, the value A_{X_i} + A_{Y_i} + Z_i is an even number.
You are a magician and can use the following magic any number of times:
Magic: Choose one card and know the integer A_i written on it. The cost of using this magic is 1.
What is the minimum cost required to determine all of A_1, A_2, ..., A_N?
It is guaranteed that there is no contradiction in given input.
-----Constraints-----
- All values in input are integers.
- 2 \leq N \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq X_i < Y_i \leq N
- 1 \leq Z_i \leq 100
- The pairs (X_i, Y_i) are distinct.
- There is no contradiction in input. (That is, there exist integers A_1, A_2, ..., A_N that satisfy the conditions.)
-----Input-----
Input is given from Standard Input in the following format:
N M
X_1 Y_1 Z_1
X_2 Y_2 Z_2
\vdots
X_M Y_M Z_M
-----Output-----
Print the minimum total cost required to determine all of A_1, A_2, ..., A_N.
-----Sample Input-----
3 1
1 2 1
-----Sample Output-----
2
You can determine all of A_1, A_2, A_3 by using the magic for the first and third cards.
|
{"inputs": ["3 1\n2 2 1", "3 1\n3 2 1", "6 1\n3 2 1", "4 1\n2 2 1", "8 1\n1 2 1", "6 1\n1 1 1", "8 1\n2 2 2", "3 1\n3 3 1"], "outputs": ["3\n", "2\n", "5\n", "4\n", "7\n", "6\n", "8\n", "3\n"]}
| 423
| 126
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.