task_type
stringclasses 1
value | problem
stringlengths 209
3.39k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 60
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Solve the programming task below in a Python markdown code block.
One day, Vogons wanted to build a new hyperspace highway through a distant system with $n$ planets. The $i$-th planet is on the orbit $a_i$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.
Vogons have two machines to do that.
The first machine in one operation can destroy any planet at cost of $1$ Triganic Pu.
The second machine in one operation can destroy all planets on a single orbit in this system at the cost of $c$ Triganic Pus.
Vogons can use each machine as many times as they want.
Vogons are very greedy, so they want to destroy all planets with minimum amount of money spent. Can you help them to know the minimum cost of this project?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. Then the test cases follow.
Each test case consists of two lines.
The first line contains two integers $n$ and $c$ ($1 \le n, c \le 100$) — the number of planets and the cost of the second machine usage.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the orbit of the $i$-th planet.
-----Output-----
For each test case print a single integer — the minimum cost of destroying all planets.
-----Examples-----
Input
4
10 1
2 1 4 5 2 4 5 5 1 2
5 2
3 2 1 2 2
2 2
1 1
2 2
1 2
Output
4
4
2
2
Input
1
1 100
1
Output
1
-----Note-----
In the first test case, the cost of using both machines is the same, so you can always use the second one and destroy all planets in orbit $1$, all planets in orbit $2$, all planets in orbit $4$, all planets in orbit $5$.
In the second test case, it is advantageous to use the second machine for $2$ Triganic Pus to destroy all the planets in orbit $2$, then destroy the remaining two planets using the first machine.
In the third test case, you can use the first machine twice or the second machine once.
In the fourth test case, it is advantageous to use the first machine twice.
|
{"inputs": ["1\n1 100\n1\n", "4\n10 1\n2 1 4 5 2 4 5 5 1 2\n5 2\n3 2 1 2 2\n2 2\n1 1\n2 2\n1 2\n", "1\n49 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"], "outputs": ["1\n", "4\n4\n2\n2\n", "2\n"]}
| 577
| 202
|
coding
|
Solve the programming task below in a Python markdown code block.
Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times:
* Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order.
* Let S' be some contiguous substring of U with length N, and replace S with S'.
Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
Constraints
* 1 \leq N \leq 5000
* 1 \leq K \leq 10^9
* |S|=N
* S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N K
S
Output
Print the lexicographically smallest possible string that can be the string S after the K operations.
Examples
Input
5 1
bacba
Output
aabca
Input
10 2
bbaabbbaab
Output
aaaabbaabb
|
{"inputs": ["5 2\nbacba", "5 2\nbacaa", "5 1\nbabba", "5 1\nbabbb", "5 1\nbabbc", "5 2\nbabbc", "5 2\ncabab", "5 1\nbacaa"], "outputs": ["aaaab\n", "aaaaa\n", "aabba\n", "abbbb\n", "abbcc\n", "aabbc\n", "aabab\n", "aaaac\n"]}
| 235
| 111
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array [10, 20, 30, 40], we can permute it so that it becomes [20, 40, 10, 30]. Then on the first and the second positions the integers became larger (20>10, 40>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 2. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the length of the array.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
Output
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
Examples
Input
7
10 1 1 1 5 5 3
Output
4
Input
5
1 1 1 1 1
Output
0
Note
In the first sample, one of the best permutations is [1, 5, 5, 3, 10, 1, 1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
|
{"inputs": ["1\n1\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n5\n", "1\n3\n", "1\n0\n", "1\n-1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 449
| 87
|
coding
|
Solve the programming task below in a Python markdown code block.
Johnny is a farmer and he annually holds a beet farmers convention "Drop the beet".
Every year he takes photos of farmers handshaking. Johnny knows that no two farmers handshake more than once. He also knows that some of the possible handshake combinations may not happen.
However, Johnny would like to know the minimal amount of people that participated this year just by counting all the handshakes.
Help Johnny by writing a function, that takes the amount of handshakes and returns the minimal amount of people needed to perform these handshakes (a pair of farmers handshake only once).
Also feel free to reuse/extend the following starter code:
```python
def get_participants(h):
```
|
{"functional": "_inputs = [[0], [1], [3], [6], [7]]\n_outputs = [[1], [2], [3], [4], [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(get_participants(*i), o[0])"}
| 151
| 179
|
coding
|
Solve the programming task below in a Python markdown code block.
Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number.
For example: If ```arr``` contains [4, 8, 6] then the output should be 2 because two numbers need to be added to the array (5 and 7) to make it a consecutive array of numbers from 4 to 8. Numbers in ```arr``` will be unique.
Also feel free to reuse/extend the following starter code:
```python
def consecutive(arr):
```
|
{"functional": "_inputs = [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]]\n_outputs = [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]\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(consecutive(*i), o[0])"}
| 139
| 245
|
coding
|
Solve the programming task below in a Python markdown code block.
Given two arrays, the purpose of this Kata is to check if these two arrays are the same. "The same" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,2], [3,6]] or [[6,3], [5,2]] or [[6,3], [2,5]] etc
[[2,5], [3,6]] is NOT the same as [[2,3], [5,6]]
Two empty arrays [] are the same
[[2,5], [5,2]] is the same as [[2,5], [2,5]] but NOT the same as [[2,5]]
[[2,5], [3,5], [6,2]] is the same as [[2,6], [5,3], [2,5]] or [[3,5], [6,2], [5,2]], etc
An array can be empty or contain a minimun of one array of 2 integers and up to 100 array of 2 integers
Note:
1. [[]] is not applicable because if the array of array are to contain anything, there have to be two numbers.
2. 100 randomly generated tests that can contains either "same" or "not same" arrays.
Also feel free to reuse/extend the following starter code:
```python
def same(arr_a, arr_b):
```
|
{"functional": "_inputs = [[[[2, 5], [3, 6]], [[5, 2], [3, 6]]], [[[2, 5], [3, 6]], [[6, 3], [5, 2]]], [[[2, 5], [3, 6]], [[6, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[2, 6], [5, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[3, 5], [6, 2], [5, 2]]], [[], []], [[[2, 3], [3, 4]], [[4, 3], [2, 4]]], [[[2, 3], [3, 2]], [[2, 3]]]]\n_outputs = [[True], [True], [True], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=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(same(*i), o[0])"}
| 334
| 370
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.
You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.
Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
-----Constraints-----
- 2 ≤ N ≤ 10^5
- 0 ≤ x_i,y_i ≤ 10^9
- All input values are integers.
-----Input-----
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
-----Output-----
Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.
-----Sample Input-----
3
1 5
3 9
7 8
-----Sample Output-----
3
Build a road between Towns 1 and 2, and another between Towns 2 and 3. The total cost is 2+1=3 yen.
|
{"inputs": ["3\n1 5\n3 9\n7 8\n", "6\n8 3\n4 9\n12 19\n18 1\n13 5\n7 6\n"], "outputs": ["3\n", "8\n"]}
| 300
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently
they can be guessed due to common cultural references.
You can get your passphrases stronger by different means. One is the following:
choose a text in capital letters including or not digits and non alphabetic characters,
1. shift each letter by a given number but the transformed letter must be a letter (circular shift),
2. replace each digit by its complement to 9,
3. keep such as non alphabetic and non digit characters,
4. downcase each letter in odd position, upcase each letter in even position (the first character is in position 0),
5. reverse the whole result.
#Example:
your text: "BORN IN 2015!", shift 1
1 + 2 + 3 -> "CPSO JO 7984!"
4 "CpSo jO 7984!"
5 "!4897 Oj oSpC"
With longer passphrases it's better to have a small and easy program.
Would you write it?
https://en.wikipedia.org/wiki/Passphrase
Also feel free to reuse/extend the following starter code:
```python
def play_pass(s, n):
```
|
{"functional": "_inputs = [['I LOVE YOU!!!', 1], ['I LOVE YOU!!!', 0], ['AAABBCCY', 1], ['MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015', 2], [\"TO BE HONEST WITH YOU I DON'T USE THIS TEXT TOOL TOO OFTEN BUT HEY... MAYBE YOUR NEEDS ARE DIFFERENT.\", 5], ['IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED PASSPHRASES FROM THE AMAZON PAY SYSTEM...', 20], ['IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED PASSPHRASES FROM THE AMAZON PAY SYSTEM...', 10], ['1ONE2TWO3THREE4FOUR5FIVE6SIX7SEVEN8EIGHT9NINE', 5], ['AZ12345678ZA', 1], ['!!!VPZ FWPM J', 25], [\"BOY! YOU WANTED TO SEE HIM? IT'S YOUR FATHER:-)\", 15], ['FOR THIS REASON IT IS RECOMMENDED THAT PASSPHRASES NOT BE REUSED ACROSS DIFFERENT OR UNIQUE SITES AND SERVICES.', 15], ['ONCE UPON A TIME YOU DRESSED SO FINE (1968)', 12], [\"AH, YOU'VE GONE TO THE FINEST SCHOOL ALL RIGHT, MISS LONELY\", 12], ['THE SPECIES, NAMED AFTER THE GREEK GOD OF THE UNDERWORLD, LIVES SOME 3,600 FEET UNDERGROUND.', 8]]\n_outputs = [['!!!vPz fWpM J'], ['!!!uOy eVoL I'], ['zDdCcBbB'], ['4897 NkTrC Hq fT67 GjV Pq aP OqTh gOcE CoPcTi aO'], [\".ySjWjKkNi jWf xIjJs wZtD JgDfR ...dJm yZg sJyKt tTy qTtY YcJy xNmY JxZ Y'StI N ZtD MyNb yXjStM Jg tY\"], ['...gYnMsM SuJ HiTuGu yBn gIlZ MyMuLbJmMuJ XyMsFuHu mLyBwLuYmYl sNcMlYpChO YaXcLvGuW IqN 7897 hC'], ['...wOdCiC IkZ XyJkWk oRd wYbP CoCkBrZcCkZ NoCiVkXk cBoRmBkOcOb iDsCbOfSxE OqNsBlWkM YgD 7897 xS'], ['JsNs0yMlNj1sJaJx2cNx3jAnK4WzTk5jJwMy6tBy7jSt8'], ['bA12345678aB'], ['I LoVe yOu!!!'], [\")-:gTwIpU GjDn h'iX ?bXw tTh dI StIcPl jDn !NdQ\"], ['.hTrXkGtH ScP HtIxH TjFxCj gD IcTgTuUxS HhDgRp sThJtG Tq iDc hThPgWeHhPe iPwI StScTbBdRtG Hx iX CdHpTg hXwI GdU'], [')1308( qZuR Ae pQeEqDp gAk qYuF M ZaBg qOzA'], [\"KxQzAx eEuY ,fTsUd xXm xAaToE FeQzUr qTf aF QzAs qH'GaK ,tM\"], ['.LvCwZoZmLvC BmMn 993,6 mUwA AmDqT ,lTzWeZmLvC MpB Nw lWo sMmZo mPb zMbNi lMuIv ,AmQkMxA MpB']]\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(play_pass(*i), o[0])"}
| 286
| 1,106
|
coding
|
Solve the programming task below in a Python markdown code block.
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car: - 1: if this pair of cars never collided. - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision.
Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.
Each of the next n lines contains n space-separated integers that determine matrix A.
It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix.
It is guaranteed that the input is correct, that is, if A_{ij} = 1, then A_{ji} = 2, if A_{ij} = 3, then A_{ji} = 3, and if A_{ij} = 0, then A_{ji} = 0.
-----Output-----
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
-----Examples-----
Input
3
-1 0 0
0 -1 1
0 2 -1
Output
2
1 3
Input
4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1
Output
0
|
{"inputs": ["1\n-1\n", "1\n-1\n", "2\n-1 0\n0 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 2\n1 -1\n", "2\n-1 3\n3 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 0\n0 -1\n"], "outputs": ["1\n1 ", "1\n1\n", "2\n1 2 ", "1\n2 ", "1\n1 ", "0\n", "1\n2\n", "2\n1 2\n"]}
| 497
| 144
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.
Return the number of steps performed until nums becomes a non-decreasing array.
Please complete the following python code precisely:
```python
class Solution:
def totalSteps(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [5,3,4,4,7,3,6,11,8,5,11]) == 3\n assert candidate(nums = [4,5,7,7,13]) == 0\n\n\ncheck(Solution().totalSteps)"}
| 106
| 74
|
coding
|
Solve the programming task below in a Python markdown code block.
The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it.
However, one day, the members somehow entered the sequence into the document at the same time, creating a jumbled mess. Therefore, it is Suguru Doujima's task to figure out whether the document has malfunctioned. Specifically, he is given a string of length $n$ whose characters are all either T or M, and he wants to figure out if it is possible to partition it into some number of disjoint subsequences, all of which are equal to TMT. That is, each character of the string should belong to exactly one of the subsequences.
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero) characters.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 5000$) — the number of test cases.
The first line of each test case contains an integer $n$ ($3 \le n < 10^5$), the number of characters in the string entered in the document. It is guaranteed that $n$ is divisible by $3$.
The second line of each test case contains a string of length $n$ consisting of only the characters T and M.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print a single line containing YES if the described partition exists, and a single line containing NO otherwise.
-----Examples-----
Input
5
3
TMT
3
MTT
6
TMTMTT
6
TMTTTT
6
TTMMTT
Output
YES
NO
YES
NO
YES
-----Note-----
In the first test case, the string itself is already a sequence equal to TMT.
In the third test case, we may partition the string into the subsequences TMTMTT. Both the bolded and the non-bolded subsequences are equal to TMT.
|
{"inputs": ["5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMTTM\n", "5\n3\nTMT\n3\nMTT\n6\nTTTMMT\n6\nTMTTTT\n6\nTTMMTT\n", "5\n3\nTTM\n3\nTTM\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTTM\n3\nTMT\n6\nTMTMTT\n6\nMTTTTT\n6\nTTMMTT\n", "5\n3\nTMT\n3\nTMT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMTTM\n", "5\n3\nTMT\n3\nMTT\n6\nTMTTTM\n6\nMTTTTT\n6\nTTMTTM\n"], "outputs": ["YES\nNO\nYES\nNO\nYES\n", "YES\nNO\nYES\nNO\nYES\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nNO\nNO\nYES\n", "NO\nNO\nYES\nNO\nYES\n", "NO\nYES\nYES\nNO\nYES\n", "YES\nYES\nYES\nNO\nNO\n", "YES\nNO\nNO\nNO\nNO\n"]}
| 471
| 369
|
coding
|
Solve the programming task below in a Python markdown code block.
Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is an edge connecting Vertex i and j; otherwise, there is no such edge.
Determine whether it is possible to divide the vertices into non-empty sets V_1, \dots, V_k such that the following condition is satisfied. If the answer is yes, find the maximum possible number of sets, k, in such a division.
* Every edge connects two vertices belonging to two "adjacent" sets. More formally, for every edge (i,j), there exists 1\leq t\leq k-1 such that i\in V_t,j\in V_{t+1} or i\in V_{t+1},j\in V_t holds.
Constraints
* 2 \leq N \leq 200
* S_{i,j} is `0` or `1`.
* S_{i,i} is `0`.
* S_{i,j}=S_{j,i}
* The given graph is connected.
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
S_{1,1}...S_{1,N}
:
S_{N,1}...S_{N,N}
Output
If it is impossible to divide the vertices into sets so that the condition is satisfied, print -1. Otherwise, print the maximum possible number of sets, k, in a division that satisfies the condition.
Examples
Input
2
01
10
Output
2
Input
3
011
101
110
Output
-1
Input
6
010110
101001
010100
101000
100000
010000
Output
4
|
{"inputs": ["2\n01\n10", "3\n011\n111\n110", "3\n010\n101\n010", "3\n011\n111\n111", "3\n011\n110\n111", "3\n010\n101\n110", "3\n011\n011\n110", "3\n011\n111\n011"], "outputs": ["2", "-1\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 434
| 151
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0").
Find the number of unique good subsequences of binary.
For example, if binary = "001", then all the good subsequences are ["0", "0", "1"], so the unique good subsequences are "0" and "1". Note that subsequences "00", "01", and "001" are not good because they have leading zeros.
Return the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 109 + 7.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Please complete the following python code precisely:
```python
class Solution:
def numberOfUniqueGoodSubsequences(self, binary: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(binary = \"001\") == 2\n assert candidate(binary = \"11\") == 2\n assert candidate(binary = \"101\") == 5\n\n\ncheck(Solution().numberOfUniqueGoodSubsequences)"}
| 221
| 63
|
coding
|
Solve the programming task below in a Python markdown code block.
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?
Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.
Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly.
The second line contains n lowercase English letters — string s.
The third line contains m lowercase English letters — string t.
-----Output-----
In the first line print single integer k — the minimal number of symbols that need to be replaced.
In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.
-----Examples-----
Input
3 5
abc
xaybz
Output
2
2 3
Input
4 10
abcd
ebceabazcd
Output
1
2
|
{"inputs": ["1 1\na\na\n", "1 1\na\nz\n", "1 1\nz\nz\n", "1 1\na\nz\n", "1 1\nz\nz\n", "1 1\na\na\n", "1 1\n{\nz\n", "1 1\n|\nz\n"], "outputs": ["0\n\n", "1\n1 \n", "0\n\n", "1\n1 \n", "0\n\n", "0\n\n", "1\n1\n", "1\n1\n"]}
| 449
| 130
|
coding
|
Solve the programming task below in a Python markdown code block.
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
-----Input-----
First line of input data contains single integer n (1 ≤ n ≤ 10^6) — length of the array.
Next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
-----Examples-----
Input
4
1 3 2 3
Output
First
Input
2
2 2
Output
Second
-----Note-----
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
|
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n"], "outputs": ["Second\n", "First\n", "Second\n", "First\n", "Second\n", "Second\n", "First\n", "Second\n"]}
| 282
| 86
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have n dice, and each dice has k faces numbered from 1 to k.
Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 109 + 7.
Please complete the following python code precisely:
```python
class Solution:
def numRollsToTarget(self, n: int, k: int, target: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 6, target = 3) == 1\n assert candidate(n = 2, k = 6, target = 7) == 6\n assert candidate(n = 30, k = 30, target = 500) == 222616187\n\n\ncheck(Solution().numRollsToTarget)"}
| 135
| 100
|
coding
|
Solve the programming task below in a Python markdown code block.
problem
Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1).
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing two zeros.
On the first line, the positive integer n (1 ≤ n ≤ 100000) and the positive integer k (1 ≤ k ≤ n) are written in this order, separated by blanks. The first + i lines after the second line. (1 ≤ i ≤ n) contains the i-th term ai (-10000 ≤ ai ≤ 10000) in the sequence. Of the scoring data, 60% of the points are n ≤ 5000, k ≤ 1000. Meet.
The number of datasets does not exceed 5.
output
The maximum value of Si is output to one line for each data set.
Examples
Input
5 3
2
5
-4
10
3
0 0
Output
11
Input
None
Output
None
|
{"inputs": ["5 3\n2\n5\n0\n5\n3\n0 0", "5 1\n0\n0\n0\n3\n1\n0 0", "5 3\n2\n5\n0\n8\n0\n0 0", "5 3\n2\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n2\n8\n0\n0 0", "5 3\n2\n5\n-4\n8\n3\n0 0", "5 3\n1\n9\n-4\n2\n1\n0 0"], "outputs": ["10\n", "3\n", "13\n", "14\n", "14\n", "15\n", "9\n", "7\n"]}
| 294
| 197
|
coding
|
Solve the programming task below in a Python markdown code block.
Mark loves eating chocolates and also likes to be fit. Given the calorie count for every chocolate he eats, find what he has to do to burn the calories.
The name of the chocolates along with its calorie count are given as follows:
Calories per one whole bar:
Dairy milk (D)
238
Twix (T)
244
Milky Bar (M)
138
Bounty (B)
279
Crunchie (C)
186
The exercises preferred by him and the calories burnt are as follows:
Calories burnt per km:
Running
50
Cycling
5
Walking
0.5
Find the number of kilometers he has to run, cycle or walk to burn all of the calories.
Priority given to the exercises is as follows:
Running > Cycling > Walking
-----Input:-----
- It is a one line string consisting of the names(initial letter) of all the chocolates he has eaten.
-----Output:-----
Print three lines. First line representing how much he ran(in km), second line representing how much he cycled(in km), third line representing how much he walked(in km).
-----Constraints-----
- 1 <= length of input string <= 10.
-----Sample Input:-----
DDTM
-----Sample Output:-----
17
1
6
-----EXPLANATION:-----
Calorie intake = 238 + 238 + 244 + 138 = 858
( 17km x 50 ) + ( 1km x 5 ) + ( 6km x 0.5 ) = 858.
|
{"inputs": ["DDTM"], "outputs": ["17\n1\n6"]}
| 361
| 18
|
coding
|
Solve the programming task below in a Python markdown code block.
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
-----Input-----
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
-----Output-----
Print a single number — the number of distinct letters in Anton's set.
-----Examples-----
Input
{a, b, c}
Output
3
Input
{b, a, b, a}
Output
2
Input
{}
Output
0
|
{"inputs": ["{}\n", "{}\n", "{a}\n", "{y}\n", "{x}\n", "{z}\n", "{a}\n", "{x}\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 232
| 76
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Consider the following ciphering algorithm:
```
For each character replace it with its code.
Concatenate all of the obtained numbers.
```
Given a ciphered string, return the initial one if it is known that it consists only of lowercase letters.
Note: here the character's code means its `decimal ASCII code`, the numerical representation of a character used by most modern programming languages.
# Example
For `cipher = "10197115121"`, the output should be `"easy"`.
Explanation:
```
charCode('e') = 101,
charCode('a') = 97,
charCode('s') = 115
charCode('y') = 121.
```
# Input/Output
- `[input]` string `cipher`
A non-empty string which is guaranteed to be a cipher for some other string of lowercase letters.
- `[output]` a string
Also feel free to reuse/extend the following starter code:
```python
def decipher(cipher):
```
|
{"functional": "_inputs = [['10197115121'], ['98'], ['122']]\n_outputs = [['easy'], ['b'], ['z']]\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(decipher(*i), o[0])"}
| 236
| 179
|
coding
|
Solve the programming task below in a Python markdown code block.
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.
Constraints
* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$
Input
A sequence is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
Output
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
Examples
Input
3
2 1 3
Output
1 3 2
2 1 3
2 3 1
Input
3
3 2 1
Output
3 1 2
3 2 1
|
{"inputs": ["3\n3 3 1", "3\n3 1 3", "3\n3 3 2", "3\n6 1 3", "3\n3 5 2", "3\n0 5 2", "3\n6 1 4", "3\n6 1 6"], "outputs": ["3 1 3\n3 3 1\n", "1 3 3\n3 1 3\n3 3 1\n", "3 2 3\n3 3 2\n", "3 6 1\n6 1 3\n6 3 1\n", "3 2 5\n3 5 2\n5 2 3\n", "0 2 5\n0 5 2\n2 0 5\n", "4 6 1\n6 1 4\n6 4 1\n", "1 6 6\n6 1 6\n6 6 1\n"]}
| 225
| 226
|
coding
|
Solve the programming task below in a Python markdown code block.
Hello! Your are given x and y and 2D array size tuple (width, height) and you have to:
Calculate the according index in 1D space (zero-based).
Do reverse operation.
Implement:
to_1D(x, y, size):
--returns index in 1D space
to_2D(n, size)
--returns x and y in 2D space
1D array: [0, 1, 2, 3, 4, 5, 6, 7, 8]
2D array: [[0 -> (0,0), 1 -> (1,0), 2 -> (2,0)],
[3 -> (0,1), 4 -> (1,1), 5 -> (2,1)],
[6 -> (0,2), 7 -> (1,2), 8 -> (2,2)]]
to_1D(0, 0, (3,3)) returns 0
to_1D(1, 1, (3,3)) returns 4
to_1D(2, 2, (3,3)) returns 8
to_2D(5, (3,3)) returns (2,1)
to_2D(3, (3,3)) returns (0,1)
Assume all input are valid:
1 < width < 500;
1 < height < 500
Also feel free to reuse/extend the following starter code:
```python
def to_1D(x, y, size):
```
|
{"functional": "_inputs = [[0, 0, [3, 3]], [1, 1, [3, 3]], [2, 2, [3, 3]], [0, 0, [1, 1]], [1, 5, [4, 6]], [2, 3, [4, 6]]]\n_outputs = [[0], [4], [8], [0], [21], [14]]\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(to_1D(*i), o[0])"}
| 358
| 242
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and an integer threshold.
Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:
nums[l] % 2 == 0
For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2
For all indices i in the range [l, r], nums[i] <= threshold
Return an integer denoting the length of the longest such subarray.
Note: A subarray is a contiguous non-empty sequence of elements within an array.
Please complete the following python code precisely:
```python
class Solution:
def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,5,4], threshold = 5) == 3\n assert candidate(nums = [1,2], threshold = 2) == 1\n assert candidate(nums = [2,3,4,5], threshold = 4) == 3\n\n\ncheck(Solution().longestAlternatingSubarray)"}
| 197
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest.
There are $N$ submissions, numbered $1$ through $N$. For each valid $i$, the $i$-th submission was submitted at time $S_i$ and judged at time $J_i$ (in minutes). Submitting and judging both take zero time. Please determine how many submissions received their verdicts after a delay of more than $5$ minutes.
-----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.
- The first line of the input contains a single integer $N$.
- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $S_i$ and $J_i$.
-----Output-----
For each test case, print a single line containing one integer — the number of submissions for which the judging was delayed by more than 5 minutes.
-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 100$
- $1 \le S_i \le J_i \le 300$ for each valid $i$
-----Subtasks-----
Subtask #1 (100 points): original constraints
-----Example Input-----
1
5
1 3
4 4
4 10
1 11
2 7
-----Example Output-----
2
-----Explanation-----
Example case 1: The delays of the respective submissions are $2$ minutes, $0$ minutes, $6$ minutes, $10$ minutes and $5$ minutes. Only submissions $3$ and $4$ are delayed by more than $5$ minutes, hence the answer is $2$.
|
{"inputs": ["1\n5\n1 3\n4 4\n4 10\n1 11\n2 7"], "outputs": ["2"]}
| 418
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has recently been playing a lot of chess in preparation for the ICCT (International Chef Chess Tournament).
Since putting in long hours is not an easy task, Chef's mind wanders elsewhere. He starts counting the number of squares with odd side length on his chessboard..
However, Chef is not satisfied. He wants to know the number of squares of odd side length on a generic $N*N$ chessboard.
-----Input:-----
- The first line will contain a single integer $T$, the number of test cases.
- The next $T$ lines will have a single integer $N$, the size of the chess board.
-----Output:-----
For each test case, print a integer denoting the number of squares with odd length.
-----Constraints-----
- $1 \leq T \leq 100$
- $1 \leq N \leq 1000$
-----Sample Input:-----
2
3
8
-----Sample Output:-----
10
120
|
{"inputs": ["2\n3\n8"], "outputs": ["10\n120"]}
| 219
| 21
|
coding
|
Solve the programming task below in a Python markdown code block.
### The Story:
Bob is working as a bus driver. However, he has become extremely popular amongst the city's residents. With so many passengers wanting to get aboard his bus, he sometimes has to face the problem of not enough space left on the bus! He wants you to write a simple program telling him if he will be able to fit all the passengers.
### Task Overview:
You have to write a function that accepts three parameters:
* `cap` is the amount of people the bus can hold excluding the driver.
* `on` is the number of people on the bus.
* `wait` is the number of people waiting to get on to the bus.
If there is enough space, return 0, and if there isn't, return the number of passengers he can't take.
### Usage Examples:
```python
enough(10, 5, 5)
0 # He can fit all 5 passengers
enough(100, 60, 50)
10 # He can't fit 10 out of 50 waiting
```
```if:csharp
Documentation:
Kata.Enough Method (Int32, Int32, Int32)
Returns the number of passengers the bus cannot fit, or 0 if the bus can fit every passenger.
Syntax
public
static
int Enough(
int cap,
int on,
int wait
)
Parameters
cap
Type: System.Int32
The amount of people that can fit on the bus excluding the driver.
on
Type: System.Int32
The amount of people on the bus excluding the driver.
wait
Type: System.Int32
The amount of people waiting to enter the bus.
Return Value
Type: System.Int32
An integer representing how many passengers cannot fit on the bus, or 0 if every passenger can fit on the bus.
```
Also feel free to reuse/extend the following starter code:
```python
def enough(cap, on, wait):
```
|
{"functional": "_inputs = [[10, 5, 5], [100, 60, 50], [20, 5, 5]]\n_outputs = [[0], [10], [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(enough(*i), o[0])"}
| 437
| 191
|
coding
|
Solve the programming task below in a Python markdown code block.
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 10^9.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
-----Input-----
The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·10^9, n·(n + 1) / 2).
The second line contains the sequence id_1, id_2, ..., id_{n} (1 ≤ id_{i} ≤ 10^9) — identifiers of roborts. It is guaranteed that all identifiers are different.
-----Output-----
Print the k-th pronounced identifier (assume that the numeration starts from 1).
-----Examples-----
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
-----Note-----
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
|
{"inputs": ["1 1\n4\n", "1 1\n4\n", "2 2\n1 2\n", "2 1\n5 1\n", "2 2\n1 4\n", "2 3\n6 7\n", "2 3\n6 7\n", "2 1\n5 1\n"], "outputs": ["4\n", "4", "1\n", "5\n", "1\n", "7\n", "7", "5"]}
| 426
| 111
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Round the given number `n` to the nearest multiple of `m`.
If `n` is exactly in the middle of 2 multiples of m, return `n` instead.
# Example
For `n = 20, m = 3`, the output should be `21`.
For `n = 19, m = 3`, the output should be `18`.
For `n = 50, m = 100`, the output should be `50`.
# Input/Output
- `[input]` integer `n`
`1 ≤ n < 10^9.`
- `[input]` integer `m`
`3 ≤ m < 109`.
- `[output]` an integer
Also feel free to reuse/extend the following starter code:
```python
def rounding(n, m):
```
|
{"functional": "_inputs = [[20, 3], [19, 3], [1, 10], [50, 100], [123, 456]]\n_outputs = [[21], [18], [0], [50], [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(rounding(*i), o[0])"}
| 197
| 206
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed string s, permute s to get a new string t such that:
All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].
The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].
Return the resulting string.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.
Please complete the following python code precisely:
```python
class Solution:
def sortVowels(self, s: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"lEetcOde\") == \"lEOtcede\"\n assert candidate(s = \"lYmpH\") == \"lYmpH\"\n\n\ncheck(Solution().sortVowels)"}
| 221
| 60
|
coding
|
Solve the programming task below in a Python markdown code block.
Given $\mbox{1}$ friendly number and $n$ unfriendly numbers, determine how many numbers are divisors of the friendly number but not the unfriendly numbers.
Input Format
The first line contains $2$ space-separated integers, $n$ (the number of unfriendly numbers) and $\mbox{f}$ (the friendly number), respectively.
The second line contains $n$ space-separated unfriendly numbers.
Constraints
$1\leq n\leq10^{6}$
$1\leq f\leq10^{13}$
$1\leq\textit{unfriendly numbers}\leq10^{18}$
Output Format
Print the the number of unique divisors of $\mbox{f}$ (i.e.: divisors that are not shared with those of the unfriendly numbers) as a single integer.
Sample Input
8 16
2 5 7 4 3 8 3 18
Sample Output
1
Explanation
There are $n=8$ unfriendly numbers: $2,5,7,4,3,8,3,18$.
Our friendly number, $\mbox{f}$, is $\mbox{16}$, and its even divisors are $1,2,4,8,16$.
Let $\textit{count}$ be the number of friendly divisors that are not also unfriendly divisors. Let's determine which divisors of $\mbox{f}$ are not also divisors of the unfriendly numbers:
$\mbox{1}$ is a divisor of all unfriendly numbers, so we disregard it.
$2$ is a divisor of unfriendly numbers $2$, $\begin{array}{c}4\end{array}$, and $8$, so we disregard it.
$\begin{array}{c}4\end{array}$ is a divisor of unfriendly numbers $\begin{array}{c}4\end{array}$ and $8$, so we disregard it.
$8$ is a divisor of unfriendly number $8$, so we disregard it.
$\mbox{16}$ is not a divisor of any unfriendly number, so we increment $\textit{count}$ to $\mbox{1}$.
As there are no more friendly divisors to check, we print the value of $\textit{count}$ (which is $\mbox{1}$) on a new line.
|
{"inputs": ["8 16\n2 5 7 4 3 8 3 18\n"], "outputs": ["1\n"]}
| 534
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
-----Input-----
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
-----Output-----
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
-----Examples-----
Input
intellect
tell
Output
1
Input
google
apple
Output
0
Input
sirisiri
sir
Output
2
-----Note-----
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri".
|
{"inputs": ["bbbbbb\nbb\n", "aaaaa\naaa\n", "bbbbbb\nbb\n", "aaaaa\naaa\n", "bbbbbb\nbc\n", "aabaa\naaa\n", "bbbbba\nbc\n", "aabaa\naab\n"], "outputs": ["3", "1", "3", "1", "0\n", "0\n", "0\n", "1\n"]}
| 469
| 90
|
coding
|
Solve the programming task below in a Python markdown code block.
The $String$ Family gave birth to a new $Tripartite$ $trio$ $sisters$ and named them $Hema$, $Rekha$ and $Sushma$. Hema and Rekha are very fond of parties whereas Sushma hates them. One day Hema and Rekha asked their parents to buy them candies to distribute to people in their birthday party. (Remember Hema, Rekha and Sushma were born on the same day). But Sushma was uninterested in the party and only wanted candies for herself.
You will be given a list $P$ of possible number of candidates coming to the party. Were $P[i]$ denotes the count of people coming in the i th possibility. In each case every person should get maximum possible equal number of candies such that after distributing the candies, there are always $R$ candies remaining for Sushma. You have to calculate the minimum number of candies required to buy so that, in any possible situation of the given array, each person coming to party gets equal number of candies (at least 1 and maximum possible out of total) and there are always $R$ candies remaining for Sushma.
-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- First line of each test case contain $N$, number of possible count of people coming to party
- Next line contain $N$ spaced integers denoting the count of people
- Next line contain $R$ the number of candies always remaining after maximum equal distribution
-----Output:-----
For each testcase, output in a single line answer, the minimum number of candies required to buy.
-----Constraints-----
- $1 \leq T \leq 100$
- $1 \leq N \leq 10^4$
- $1 \leq P[i] \leq 41$
- $0 \leq R < min(P[i])$
-----Sample Input:-----
1
2
2 3
1
-----Sample Output:-----
7
|
{"inputs": ["1\n2\n2 3\n1"], "outputs": ["7"]}
| 450
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
A hostel has N rooms in a straight line. It has to accommodate X people. Unfortunately, out of these X people, Y of them are infected with chickenpox. Due to safety norms, the following precaution must be taken:
No person should occupy a room directly adjacent to a room occupied by a chickenpox-infected person. In particular, two chickenpox-infected people cannot occupy adjacent rooms.
For example, if room 4 has a chickenpox-infected person, then nobody should occupy rooms 3 and 5. Similarly, if room 1 has a chickenpox-infected person then nobody should occupy room 2.
What's the minimum value of N for which all the people can be accommodated in the hostel, following the above condition?
------ Input Format ------
- The first line of input contains a single integer T — the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains two integers X and Y — the total number of people and the number of chickenpox-infected people.
------ Output Format ------
For each test case, output on a new line a single integer — the minimum value of N for which all the people can be accommodated in the hostel.
------ Constraints ------
$1 ≤ T ≤ 200$
$1 ≤ X ≤ 1000$
$0 ≤ Y ≤ X$
----- Sample Input 1 ------
3
4 0
5 3
3 3
----- Sample Output 1 ------
4
8
5
----- explanation 1 ------
Note: Below, $C$ represents a room occupied by a chickenpox-infected person, $N$ represents a room occupied by an uninfected person, and $\_$ represents an empty room.
Test case $1$: One of the possible ways to accommodate the people in $4$ rooms is:
$N$ $N$ $N$ $N$
Test case $2$: One of the possible ways to accommodate the people in $8$ rooms is:
$C$ $\_$ $C$ $\_$ $N$ $N$ $\_$ $C$
Test case $3$: One of the possible ways to accommodate the people in $5$ rooms is:
$C$ $\_$ $C$ $\_$ $C$
|
{"inputs": ["3\n4 0\n5 3\n3 3\n"], "outputs": ["4\n8\n5\n"]}
| 497
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a matrix A that consists of N rows and M columns. Every number in the matrix is either zero or one. Calculate the number of such triples (i, j, h) where for all the pairs (x, y), where both x and y belong to [1; h] if y ≥ x, A[i+x-1][j+y-1] equals to one. Of course, the square (i, j, i+h-1, j+h-1) should be inside of this matrix. In other words, we're asking you to calculate the amount of square submatrices of a given matrix which have ones on and above their main diagonal.
------ Input ------
The first line of the input consists of two integers - N and M.
The following N lines describe the matrix. Each line consists of M characters that are either zero or one.
------ Output ------
Output should consist of a single integer - the answer to the problem.
------ Example ------
Input:
2 3
011
111
Output:
6
------ Scoring ------
Subtask 1 (9 points): 1 ≤ N,M ≤ 2000, All the numbers in the matrix are equal to one.
Subtask 2 (12 points): 1 ≤ N,M ≤ 10.
Subtask 3 (34 points): 1 ≤ N,M ≤ 30.
Subtask 4 (17 points): 1 ≤ N,M ≤ 150.
Subtask 5 (28 points): 1 ≤ N,M ≤ 2000.
|
{"inputs": ["2 3\n011\n111"], "outputs": ["6"]}
| 350
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
Petya is preparing a problem for a local contest in his school. The problem is to find a longest increasing subsequence in a given permutation. A permutation of size n$n$ is a sequence of n$n$ numbers a1,…,an$a_1, \ldots, a_n$ such that every number from 1$1$ to n$n$ occurs in the sequence exactly once. An increasing subsequence of length k$k$ of the sequence a1,…,an$a_1, \ldots, a_n$ is a sequence of indices i1,…,ik$i_1, \ldots, i_k$ such that 1≤i1<…<ik≤n$1 \leq i_1 < \ldots < i_k \leq n$ and ai1<…<aik$a_{i_1} < \ldots < a_{i_k}$. A longest increasing subsequence is an increasing subsequences with the largest length. Note that in general there may be several longest increasing subsequences.
Petya had some tests prepared, but then lost the input part for some of them. He now has a test for a certain value of n$n$, and a sequence i1,…,ik$i_1, \ldots, i_k$ that is supposed to be a longest increasing subsequence. Petya now has to reconstruct a permutation of size n$n$ with this sequence being an answer. Petya doesn't want to take any risks, so he additionally wants this sequence to be the only longest increasing subsequence, that is, all other increasing subsequences have to have strictly smaller length. Help Petya determine if this is possible, and if so, construct any such permutation.
-----Input:-----
The first line contains an integer T$T$, denoting number of test cases.
The first line of every test case contains two integers n$n$ and k−$k-$ the size of the permutation and the length of the longest increasing subsequence (1≤k≤n≤105$1 \leq k \leq n \leq 10^5$).
The second line contains k$k$ integers i1,…,ik−$i_1, \ldots, i_k-$ the longest increasing subsequence (1≤i1<…<ik≤n$1 \leq i_1 < \ldots < i_k \leq n$).
-----Output:-----
If there is no permutation with the sequence i1,…,ik$i_1, \ldots, i_k$ being the only longest increasing subsequence, print NO . Otherwise, print YES on the first line, followed by n$n$ numbers describing any suitable permutation on the second line.
-----Constraints-----
- 1≤T≤10$1 \leq T \leq 10$
- 1≤k≤n≤105$1 \leq k \leq n \leq 10^5$
- 1≤i1<…<ik≤n$1 \leq i_1 < \ldots < i_k \leq n$
-----Sample Input:-----
2
3 2
1 2
2 1
1
-----Sample Output:-----
YES
2 3 1
NO
|
{"inputs": ["2\n3 2\n1 2\n2 1\n1"], "outputs": ["YES\n2 3 1\nNO"]}
| 707
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
You are given a string consisting of `"D", "P" and "C"`. A positive integer N is called DPC of this string if it satisfies the following properties:
```
For each i = 1, 2, ... , size of the string:
If i-th character is "D", then N can be divided by i
If i-th character is "P", then N and i should be relatively prime
If i-th character is "C", then N should neither be divided by i
nor be relatively prime with i```
Your task is to find the smallest DPC of a given string, or return `-1` if there is no such. The result is guaranteed to be `<= 10^9`.
# Example
For `s = "DDPDD"`, the result should be `20`.
`"DDPDD"` means `N` should `divided by 1,2,4,5`, and `N,3` should be relatively prime. The smallest N should be `20`.
# Input/Output
- `[input]` string `s`
The given string
- `[output]` an integer
The smallest DPC of `s` or `-1` if it doesn't exist.
Also feel free to reuse/extend the following starter code:
```python
def DPC_sequence(s):
```
|
{"functional": "_inputs = [['DDPDD'], ['DDDDPDDCCCDDPDCCPCDCDDPCPCCDDCD'], ['DPCPDPPPDCPDPDPC'], ['DDDDDDCD'], ['CDDDPDDD'], ['DDDDDDPCCDPDPP']]\n_outputs = [[20], [15782844], [-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(DPC_sequence(*i), o[0])"}
| 302
| 231
|
coding
|
Solve the programming task below in a Python markdown code block.
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i.
Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:
* For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.
Find the intensity of each bulb after the K operations.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 1 \leq K \leq 2 \times 10^5
* 0 \leq A_i \leq N
Input
Input is given from Standard Input in the following format:
N K
A_1 A_2 \ldots A_N
Output
Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:
A{'}_1 A{'}_2 \ldots A{'}_N
Output
Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:
A{'}_1 A{'}_2 \ldots A{'}_N
Examples
Input
5 1
1 0 0 1 0
Output
1 2 2 1 2
Input
5 2
1 0 0 1 0
Output
3 3 4 4 3
|
{"inputs": ["5 1\n0 0 0 1 0", "5 2\n0 0 0 1 0", "5 2\n0 0 0 0 0", "5 2\n1 0 0 0 0", "5 2\n0 0 0 0 1", "5 0\n0 0 0 0 1", "5 2\n1 0 0 2 0", "5 2\n0 0 0 2 0"], "outputs": ["1 1 2 1 2\n", "3 3 4 3 3\n", "2 3 3 3 2\n", "2 3 3 4 2\n", "2 4 3 3 2\n", "0 0 0 0 1\n", "3 3 4 4 4\n", "3 3 4 4 3\n"]}
| 391
| 222
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $m$. Calculate the number of pairs of arrays $(a, b)$ such that:
the length of both arrays is equal to $m$; each element of each array is an integer between $1$ and $n$ (inclusive); $a_i \le b_i$ for any index $i$ from $1$ to $m$; array $a$ is sorted in non-descending order; array $b$ is sorted in non-ascending order.
As the result can be very large, you should print it modulo $10^9+7$.
-----Input-----
The only line contains two integers $n$ and $m$ ($1 \le n \le 1000$, $1 \le m \le 10$).
-----Output-----
Print one integer – the number of arrays $a$ and $b$ satisfying the conditions described above modulo $10^9+7$.
-----Examples-----
Input
2 2
Output
5
Input
10 1
Output
55
Input
723 9
Output
157557417
-----Note-----
In the first test there are $5$ suitable arrays: $a = [1, 1], b = [2, 2]$; $a = [1, 2], b = [2, 2]$; $a = [2, 2], b = [2, 2]$; $a = [1, 1], b = [2, 1]$; $a = [1, 1], b = [1, 1]$.
|
{"inputs": ["2 2\n", "1 1\n", "1 2\n", "1 2\n", "1 1\n", "7 7\n", "2 3\n", "9 1\n"], "outputs": ["5\n", "1\n", "1\n", "1\n", "1\n", "38760\n", "7\n", "45\n"]}
| 375
| 91
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef wants to gift his girlfriend a necklace made of beads. The beads can be made of either Stone, Glass, Quartz, Ruby or Diamond (he need not use all five types of beads) .
Each bead has a value associated with its beauty as follows
-2 for Stone
-1 for Glass
0 for Quartz
1 for Ruby
2 for Diamond
Each bead also has a cost given by S, G, Q, R and D for the respective bead.
There are q queries for you. In each query chef wants to know the minimum cost for creating a necklace using exactly X beads and overall beauty of Y.
Overall beauty Y is defined as the sum of beauty of each bead used in the necklace.
Since you’re a great programmer, he wants you to answer each query as soon as possible.
------ Input ------
First line contains 5 space separated integers S, G, Q, R, D, the respective cost of beads.
Next line contains q the number of queries
next q lines had two integers X and Y , the number of beads to be used and the overall beauty
------ Output ------
for each query output the answer in a new line
output the minimum cost if it exists otherwise print -1
------ Constrains ------
$1 ≤ q ≤ 5*10^{5}$
$0 ≤ S, G, Q, R, D ≤ 10^{6}$
$0 ≤ X ≤ 100$
$-200 ≤ Y ≤ 200$
------ Subtasks ------
10 points : $0 ≤ X ≤ 2$
20 points : $ q=1 $
70 points : original constrains
------ Sample Input ------
1 2 2 3 4
3
2 0
1 -2
3 6
------ Sample Output ------
4
1
12
------ Explanation ------
in the first query we can take (stone,diamond), (glass,ruby), (quarts,quarts)
but the minimum cost would be if we took quarts and quarts which is 4
second query there is only one way that is to take one stone and the cost is 1
third query also there is only one way to take three diamonds and the cost is 12
|
{"inputs": ["1 2 2 3 4\n3\n2 0\n1 -2\n3 6"], "outputs": ["4\n1\n12"]}
| 487
| 39
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array.
# Example
For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]`
The result should be `6`.
```
[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9] -->
2+2+6 0+2+0 5+5+7+7 3+3+9
[2, 1, 10, 5, 2, 24, 4, 15 ] -->
2+24+4
[2, 1, 10, 5, 30, 15 ]
The length of final array is 6
```
# Input/Output
- `[input]` integer array `arr`
A non-empty array,
`1 ≤ arr.length ≤ 1000`
`0 ≤ arr[i] ≤ 1000`
- `[output]` an integer
The length of the final array
Also feel free to reuse/extend the following starter code:
```python
def sum_groups(arr):
```
|
{"functional": "_inputs = [[[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], [[2]], [[1, 2]], [[1, 1, 2, 2]]]\n_outputs = [[6], [5], [1], [2], [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_groups(*i), o[0])"}
| 369
| 277
|
coding
|
Solve the programming task below in a Python markdown code block.
There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing integers into all remaining cells. The grid must meet the following conditions to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing integers into all remaining cells.
Constraints
* 2≤R,C≤10^5
* 1≤N≤10^5
* 1≤r_i≤R
* 1≤c_i≤C
* (r_i,c_i) ≠ (r_j,c_j) (i≠j)
* a_i is an integer.
* 0≤a_i≤10^9
Input
The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N
Output
Print `Yes` if it is possible to meet the conditions by properly writing integers into all remaining cells. Otherwise, print `No`.
Examples
Input
2 2
3
1 1 0
1 2 10
2 1 20
Output
Yes
Input
2 3
5
1 1 0
1 2 10
1 3 20
2 1 30
2 3 40
Output
No
Input
2 2
3
1 1 20
1 2 10
2 1 0
Output
No
Input
3 3
4
1 1 0
1 3 10
3 1 10
3 3 20
Output
Yes
Input
2 2
4
1 1 0
1 2 10
2 1 30
2 2 20
Output
No
|
{"inputs": ["2 2\n3\n1 1 0\n1 2 10\n2 1 22", "2 2\n3\n2 1 20\n1 2 10\n2 1 0", "2 2\n3\n1 1 0\n1 2 10\n2 1 14", "2 4\n3\n1 1 0\n1 2 10\n2 1 22", "2 2\n3\n1 1 0\n1 2 10\n1 1 14", "2 4\n3\n1 1 1\n1 2 10\n2 1 22", "2 2\n3\n1 1 0\n2 2 10\n2 1 22", "2 2\n3\n1 2 20\n1 2 10\n2 1 0"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n"]}
| 557
| 254
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer $n$. Pair the integers $1$ to $2n$ (i.e. each integer should be in exactly one pair) so that each sum of matched pairs is consecutive and distinct.
Formally, let $(a_i, b_i)$ be the pairs that you matched. $\{a_1, b_1, a_2, b_2, \ldots, a_n, b_n\}$ should be a permutation of $\{1, 2, \ldots, 2n\}$. Let the sorted list of $\{a_1+b_1, a_2+b_2, \ldots, a_n+b_n\}$ be $s_1 < s_2 < \ldots < s_n$. We must have $s_{i+1}-s_i = 1$ for $1 \le i \le n - 1$.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.
For each test case, a single integer $n$ ($1 \leq n \leq 10^5$) is given.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$.
-----Output-----
For each test case, if it is impossible to make such a pairing, print "No".
Otherwise, print "Yes" followed by $n$ lines.
At each line, print two integers that are paired.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
If there are multiple solutions, print any.
-----Examples-----
Input
4
1
2
3
4
Output
Yes
1 2
No
Yes
1 6
3 5
4 2
No
-----Note-----
For the third test case, each integer from $1$ to $6$ appears once. The sums of matched pairs are $4+2=6$, $1+6=7$, and $3+5=8$, which are consecutive and distinct.
|
{"inputs": ["1\n99988\n", "1\n99990\n", "1\n99992\n", "1\n99994\n", "1\n99996\n", "1\n99998\n", "1\n31704\n", "1\n100000\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 492
| 119
|
coding
|
Solve the programming task below in a Python markdown code block.
You're given a tree with $n$ vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 10^5$) denoting the size of the tree.
The next $n - 1$ lines contain two integers $u$, $v$ ($1 \le u, v \le n$) each, describing the vertices connected by the $i$-th edge.
It's guaranteed that the given edges form a tree.
-----Output-----
Output a single integer $k$ — the maximum number of edges that can be removed to leave all connected components with even size, or $-1$ if it is impossible to remove edges in order to satisfy this property.
-----Examples-----
Input
4
2 4
4 1
3 1
Output
1
Input
3
1 2
1 3
Output
-1
Input
10
7 1
8 4
8 10
4 7
6 5
9 3
3 5
2 10
2 5
Output
4
Input
2
1 2
Output
0
-----Note-----
In the first example you can remove the edge between vertices $1$ and $4$. The graph after that will have two connected components with two vertices in each.
In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $-1$.
|
{"inputs": ["1\n", "1\n", "2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "3\n1 2\n1 3\n", "3\n1 2\n2 3\n", "3\n1 3\n2 3\n"], "outputs": ["-1", "-1\n", "0", "0\n", "0\n", "-1", "-1\n", "-1\n"]}
| 358
| 104
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums and an integer k.
A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
Return the length of the longest possible equal subarray after deleting at most k elements from nums.
A subarray is a contiguous, possibly empty sequence of elements within an array.
Please complete the following python code precisely:
```python
class Solution:
def longestEqualSubarray(self, nums: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,3,1,3], k = 3) == 3\n assert candidate(nums = [1,1,2,2,1,1], k = 2) == 4\n\n\ncheck(Solution().longestEqualSubarray)"}
| 131
| 76
|
coding
|
Solve the programming task below in a Python markdown code block.
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists of n integers a_1, a_2, ..., a_{n}. Let's denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r and a_{k} = x. His task is to calculate the number of pairs of indicies i, j (1 ≤ i < j ≤ n) such that f(1, i, a_{i}) > f(j, n, a_{j}).
Help Pashmak with the test.
-----Input-----
The first line of the input contains an integer n (1 ≤ n ≤ 10^6). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
-----Output-----
Print a single integer — the answer to the problem.
-----Examples-----
Input
7
1 2 1 1 2 2 1
Output
8
Input
3
1 1 1
Output
1
Input
5
1 2 3 4 5
Output
0
|
{"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n-1\n", "1\n-2\n", "1\n-4\n", "1\n-5\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 298
| 90
|
coding
|
Solve the programming task below in a Python markdown code block.
Let's call a string good if its length is at least $2$ and all of its characters are ${A}$ except for the last character which is ${B}$. The good strings are ${AB},{AAB},{AAAB},\ldots$. Note that ${B}$ is not a good string.
You are given an initially empty string $s_1$.
You can perform the following operation any number of times:
Choose any position of $s_1$ and insert some good string in that position.
Given a string $s_2$, can we turn $s_1$ into $s_2$ after some number of operations?
-----Input-----
Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single string $s_2$ ($1 \leq |s_2| \leq 2 \cdot 10^5$).
It is guaranteed that $s_2$ consists of only the characters ${A}$ and ${B}$.
It is guaranteed that the sum of $|s_2|$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print "YES" (without quotes) if we can turn $s_1$ into $s_2$ after some number of operations, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
-----Examples-----
Input
4
AABAB
ABB
AAAAAAAAB
A
Output
YES
NO
YES
NO
-----Note-----
In the first test case, we transform $s_1$ as such: $\varnothing \to {{AAB}} \to {A}{{AB}}{AB}$.
In the third test case, we transform $s_1$ as such: $\varnothing \to {{AAAAAAAAB}}$.
In the second and fourth test case, it can be shown that it is impossible to turn $s_1$ into $s_2$.
|
{"inputs": ["4\nAABAB\nABB\nAAAAAAAAB\nA\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
| 500
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
Let’s get to know our hero: Agent #134 - Mr. Slayer.
He was sent by his CSV agency to Ancient Rome in order to resolve some important national issues. However, something incredible has happened - the enemies have taken Julius Caesar as a prisoner!!!
Caesar, not a simple man as you know, managed to send cryptic message with coordinates of his location hoping that somebody would break the code. Here our agent of the secret service comes to the stage.
But he needs your help!
**Mission:**
You have to implement the function “Encode” of CaesarCrypto class that codes or decodes text based on Caesar’s algorithm.the function receives 2 parameters: an original text of any length of type “string” and a number of type “int” that represents shifts;only letters in both cases must be encrypted;alphabet contains only letters in this range: a-zA-Z;by encryption the letter can change the case;shift could be either positive or negative (for left shift);If the input text is empty, null or includes only whitespaces, return an empty string.
Time's ticking away. The life of Caesar is on the chopping block! Go for it!
Also feel free to reuse/extend the following starter code:
```python
def caesar_crypto_encode(text, shift):
```
|
{"functional": "_inputs = [['123,.)(!?', 10], ['', 10], [None, 10], [' ', 10], ['Hello world!', 127], ['eBIIL TLOIA!', -127], ['ksdjai8983hdk?}{', 15], ['Hello world!', 0]]\n_outputs = [['123,.)(!?'], [''], [''], [''], ['eBIIL TLOIA!'], ['Hello world!'], ['zHsypx8983wsz?}{'], ['Hello world!']]\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(caesar_crypto_encode(*i), o[0])"}
| 278
| 275
|
coding
|
Solve the programming task below in a Python markdown code block.
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti:
* If Petya has visited this room before, he writes down the minute he was in this room last time;
* Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?
Input
The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook.
The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook.
Output
In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.
Examples
Input
2
0 0
Output
2
Input
5
0 1 0 1 3
Output
3
Note
In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.
|
{"inputs": ["1\n0\n", "2\n0 1\n", "2\n0 0\n", "5\n0 0 0 1 3\n", "5\n0 0 0 2 3\n", "5\n0 1 0 1 3\n", "7\n0 1 0 0 0 0 0\n", "7\n0 1 0 0 0 0 1\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "3\n", "3\n", "6\n", "6\n"]}
| 478
| 138
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi]. This means that on the ith day you need to paint the area between starti and endi.
Painting the same area multiple times will create an uneven painting so you only want to paint each area of the painting at most once.
Return an integer array worklog of length n, where worklog[i] is the amount of new area that you painted on the ith day.
Please complete the following python code precisely:
```python
class Solution:
def amountPainted(self, paint: List[List[int]]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(paint = [[1,4],[4,7],[5,8]]) == [3,3,1]\n assert candidate(paint = [[1,4],[5,8],[4,7]]) == [3,3,1]\n assert candidate(paint = [[1,5],[2,4]]) == [4,0]\n\n\ncheck(Solution().amountPainted)"}
| 173
| 98
|
coding
|
Solve the programming task below in a Python markdown code block.
Consider some set of distinct characters $A$ and some string $S$, consisting of exactly $n$ characters, where each character is present in $A$.
You are given an array of $m$ integers $b$ ($b_1 < b_2 < \dots < b_m$).
You are allowed to perform the following move on the string $S$:
Choose some valid $i$ and set $k = b_i$; Take the first $k$ characters of $S = Pr_k$; Take the last $k$ characters of $S = Su_k$; Substitute the first $k$ characters of $S$ with the reversed $Su_k$; Substitute the last $k$ characters of $S$ with the reversed $Pr_k$.
For example, let's take a look at $S =$ "abcdefghi" and $k = 2$. $Pr_2 =$ "ab", $Su_2 =$ "hi". Reversed $Pr_2 =$ "ba", $Su_2 =$ "ih". Thus, the resulting $S$ is "ihcdefgba".
The move can be performed arbitrary number of times (possibly zero). Any $i$ can be selected multiple times over these moves.
Let's call some strings $S$ and $T$ equal if and only if there exists such a sequence of moves to transmute string $S$ to string $T$. For the above example strings "abcdefghi" and "ihcdefgba" are equal. Also note that this implies $S = S$.
The task is simple. Count the number of distinct strings.
The answer can be huge enough, so calculate it modulo $998244353$.
-----Input-----
The first line contains three integers $n$, $m$ and $|A|$ ($2 \le n \le 10^9$, $1 \le m \le min(\frac n 2, 2 \cdot 10^5)$, $1 \le |A| \le 10^9$) — the length of the strings, the size of the array $b$ and the size of the set $A$, respectively.
The second line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_i \le \frac n 2$, $b_1 < b_2 < \dots < b_m$).
-----Output-----
Print a single integer — the number of distinct strings of length $n$ with characters from set $A$ modulo $998244353$.
-----Examples-----
Input
3 1 2
1
Output
6
Input
9 2 26
2 3
Output
150352234
Input
12 3 1
2 5 6
Output
1
-----Note-----
Here are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in $A$ are different.
"aaa" "aab" = "baa" "aba" "abb" = "bba" "bab" "bbb"
|
{"inputs": ["3 1 2\n1\n", "2 1 1\n1\n", "8 1 8\n2\n", "8 1 8\n2\n", "2 1 1\n1\n", "3 1 3\n1\n", "3 1 5\n1\n", "3 1 4\n1\n"], "outputs": ["6\n", "1\n", "8519680\n", "8519680\n", "1\n", "18\n", "75\n", "40\n"]}
| 703
| 133
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one.
At least how many operations are necessary to satisfy the following conditions?
* For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.
* For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
Constraints
* 2 ≤ n ≤ 10^5
* |a_i| ≤ 10^9
* Each a_i is an integer.
Input
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n
Output
Print the minimum necessary count of operations.
Examples
Input
4
1 -3 1 0
Output
4
Input
5
3 -6 4 -5 7
Output
0
Input
6
-1 4 3 2 -5 4
Output
8
|
{"inputs": ["4\n1 0 1 0", "4\n0 0 1 0", "4\n0 0 0 0", "4\n0 0 0 1", "4\n0 0 1 1", "4\n0 1 1 1", "4\n0 0 1 2", "4\n0 1 1 2"], "outputs": ["5\n", "6\n", "7\n", "6\n", "7\n", "6\n", "6\n", "5\n"]}
| 275
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
## Description:
Remove all exclamation marks from the end of words. Words are separated by spaces in the sentence.
### Examples
```
remove("Hi!") === "Hi"
remove("Hi!!!") === "Hi"
remove("!Hi") === "!Hi"
remove("!Hi!") === "!Hi"
remove("Hi! Hi!") === "Hi Hi"
remove("!!!Hi !!hi!!! !hi") === "!!!Hi !!hi !hi"
```
Also feel free to reuse/extend the following starter code:
```python
def remove(s):
```
|
{"functional": "_inputs = [['Hi!'], ['Hi!!!'], ['!Hi'], ['!Hi!'], ['Hi! Hi!']]\n_outputs = [['Hi'], ['Hi'], ['!Hi'], ['!Hi'], ['Hi Hi']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (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(remove(*i), o[0])"}
| 126
| 188
|
coding
|
Solve the programming task below in a Python markdown code block.
You will be given two numbers `m,n`. The numbers could span from `0` to `10000`. We can get their product by using binary reduction as show in the table below.
Example (to understand the table please read the description below it)
real value of m(r)
m
n
(r*n)
0
100
15
0
0
50
30
0
1
25
60
60
0
12
120
0
0
6
240
0
1
3
480
480
1
1
960
960
Above, we are given two numbers `100` and `15`. we keep reducing the bigger number by dividing it by `2` and hold the integer part of the division till it is no more divisible by `2`. Then we assign the real values to these reduced parts of `m`. Any reduced number `[1,m]` has real value of `0` if it is even, and it will have real value of `1` if it is odd. On the other hand the smaller number in this case `n` keeps on doubling itself the same amount of times `m` reduces itself. The idea of this method is to change multiplication of two big number to a sequence of multiplication by `0` or `1` and perform addition to get the final product. You can see that from the last column `(r*n)` above.
if we sum the last column we get `0+60+0+0+480+960=1500=100*15`
Now your task for this kata will be to get those non-zero number in the last column in an array and return it sorted in descending order.so for the above example the return will be `[960,480,60]`.
_Beware: _`m,n`_ are not necessarily ordered._
Also feel free to reuse/extend the following starter code:
```python
def bin_mul(m,n):
```
|
{"functional": "_inputs = [[100, 15], [15, 0], [0, 0]]\n_outputs = [[[960, 480, 60]], [[]], [[]]]\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(bin_mul(*i), o[0])"}
| 459
| 188
|
coding
|
Solve the programming task below in a Python markdown code block.
Your task is to convert a given number into a string with commas added for easier readability. The number should be rounded to 3 decimal places and the commas should be added at intervals of three digits before the decimal point. There does not need to be a comma at the end of the number.
You will receive both positive and negative numbers.
## Examples
```python
commas(1) == "1"
commas(1000) == "1,000"
commas(100.2346) == "100.235"
commas(1000000000.23) == "1,000,000,000.23"
commas(-1) == "-1"
commas(-1000000.123) == "-1,000,000.123"
```
Also feel free to reuse/extend the following starter code:
```python
def commas(num):
```
|
{"functional": "_inputs = [[1], [1000], [100.2346], [1000000000.23], [9123.212], [-1], [-1000000.123], [-2000.0], [-999.9999], [-1234567.0001236]]\n_outputs = [['1'], ['1,000'], ['100.235'], ['1,000,000,000.23'], ['9,123.212'], ['-1'], ['-1,000,000.123'], ['-2,000'], ['-1,000'], ['-1,234,567']]\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(commas(*i), o[0])"}
| 233
| 334
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.
Formally, we choose a subsequence of indices 1 ≤ i_1 < i_2 < ... < i_{t} ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j, j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ i_{k} ≤ j + m - 1.
Then we take any permutation p of the selected indices and form a new string s_{i}_{p}_1s_{i}_{p}_2... s_{i}_{p}_{t}.
Find the lexicographically smallest string, that can be obtained using this procedure.
-----Input-----
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).
The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.
-----Output-----
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
-----Examples-----
Input
3
cbabc
Output
a
Input
2
abcab
Output
aab
Input
3
bcabcbaccba
Output
aaabb
-----Note-----
In the first sample, one can choose the subsequence {3} and form a string "a".
In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".
|
{"inputs": ["1\nbaaa\n", "1\nbaaa\n", "3\ncbabc\n", "2\nabcab\n", "3\nbbabc\n", "2\nabbab\n", "3\ncbabc\n", "2\nabcab\n"], "outputs": ["aaab\n", "aaab", "a\n", "aab\n", "a\n", "aab\n", "a", "aab"]}
| 494
| 95
|
coding
|
Solve the programming task below in a Python markdown code block.
Shivam owns a gambling house, which has a special wheel called The Wheel of Fortune.
This wheel is meant for giving free coins to people coming in the house.
The wheel of fortune is a game of chance. It uses a spinning wheel with exactly N numbered pockets and a coin is placed in between every consecutive pocket. The wheel is spun in either of the two ways.
Before the wheel is turned, all the coins are restored and players bet on a number K.
Then a needle is made to point to any one of the pocket which has number K written on it.
Wheel is then spun till the needle encounters number K again and the player gets all the coins the needle has encountered.
Shivam being the owner of the gambling house, has the authority to place the needle on any of the K numbered pockets and also he could rotate the wheel in either of the two ways.
Shivam has to figure out a way to minimize number of coins that he has to spend on every given bet.
You are given a wheel having N elements and Q players. Each player bets on a number K from the wheel. For each player you have to print minimum number of coins Shivam has to spend.
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases . The description of T testcases follow.
- The first line of each test case contains single integer N .
- The second line of each test case contains N space seperated integers denoting the numbers on the wheel.
- The third line of each test case contains a single integer Q denoting the number of players.
- Then, Q lines follow a single integer K from the N numbers of the wheel
-----Output-----
For each player, output the minimum number of coins Shivam has to spend.
-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 100000
- 1 ≤ Number written on the Wheel ≤ 1000
- 1 ≤ Q ≤ 10000
- 1 ≤ K ≤ 1000
- It is guaranteed that K belongs to the N numbers written on the wheel.
-----Example-----
Input:
2
3
1 2 3
3
1
2
3
6
2 1 5 3 2 1
4
1
2
3
5
Output:
3
3
3
2
2
6
6
|
{"inputs": ["2\n3\n1 2 3\n3\n1\n2\n3\n6\n2 1 5 3 2 1\n4\n1\n2\n3\n5"], "outputs": ["3\n3\n3\n2\n2\n6\n6"]}
| 526
| 64
|
coding
|
Solve the programming task below in a Python markdown code block.
You were given a string of integer temperature values. Create a function `close_to_zero(t)` and return the closest value to 0 or `0` if the string is empty. If two numbers are equally close to zero, return the positive integer.
Also feel free to reuse/extend the following starter code:
```python
def close_to_zero(t):
```
|
{"functional": "_inputs = [[''], ['-1 50 -4 20 22 -7 0 10 -8'], ['28 35 -21 17 38 -17']]\n_outputs = [[0], [0], [17]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n 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(close_to_zero(*i), o[0])"}
| 86
| 203
|
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.
Given two strings consisting of digits 0 and 1 only, find the XOR of the two strings.
To know more about XOR Click Here
Debug the given function strings_xor to find the XOR of the two given strings appropriately.
Note: You can modify at most three lines in the given code and you cannot add or remove lines to the code.
To restore the original code, click on the icon to the right of the language selector.
Input Format
The input consists of two lines. The first line of the input contains the first string, $\boldsymbol{s}$, and the second line contains the second string, $\boldsymbol{\boldsymbol{t}}$.
Constraints
$1\leq|s|\leq10^4$
$|s|=|t|$
Output Format
Print the string obtained by the XOR of the two input strings in a single line.
Sample Input
10101
00101
Sample Output
10000
Explanation
The XOR of the two strings $\textbf{10101}$ and $\textbf{00101}$ is $1\oplus0,\:\textbf{0}\oplus0,\:\textbf{1}\oplus1,\:\textbf{0}\oplus0,\:\textbf{1}\oplus1=10000$.
|
{"inputs": ["10101\n00101\n"], "outputs": ["10000\n"]}
| 322
| 28
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.
-----Input-----
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1 ≤ n ≤ 90) — the number of fouls.
Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.
-----Output-----
For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card.
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards).
-----Examples-----
Input
MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r
Output
MC 25 70
MC 42 82
CSKA 13 90
|
{"inputs": ["A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "A\nAA\n2\n1 a 1 y\n2 h 1 y\n", "TANB\nXNCPR\n1\n15 h 6 r\n9 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 27 r\n6 h 27 r\n", "AB\nBC\n3\n1 h 1 y\n2 h 2 y\n3 h 1 r\n", "TANC\nXNCOR\n2\n15 h 54 r\n6 h 27 r\n"], "outputs": ["", "\n", "TANB 6 15\n", "AB 1 2\n", "AB 1 2\n", "TANC 27 15\n", "AB 1 3\n", "TANC 54 15\nTANC 27 6\n"]}
| 597
| 272
|
coding
|
Solve the programming task below in a Python markdown code block.
Create a method `sayHello`/`say_hello`/`SayHello` that takes as input a name, city, and state to welcome a person. Note that `name` will be an array consisting of one or more values that should be joined together with one space between each, and the length of the `name` array in test cases will vary.
Example:
```python
say_hello(['John', 'Smith'], 'Phoenix', 'Arizona')
```
This example will return the string `Hello, John Smith! Welcome to Phoenix, Arizona!`
Also feel free to reuse/extend the following starter code:
```python
def say_hello(name, city, state):
```
|
{"functional": "_inputs = [[['John', 'Smith'], 'Phoenix', 'Arizona'], [['Franklin', 'Delano', 'Roosevelt'], 'Chicago', 'Illinois'], [['Wallace', 'Russel', 'Osbourne'], 'Albany', 'New York'], [['Lupin', 'the', 'Third'], 'Los Angeles', 'California'], [['Marlo', 'Stanfield'], 'Baltimore', 'Maryland']]\n_outputs = [['Hello, John Smith! Welcome to Phoenix, Arizona!'], ['Hello, Franklin Delano Roosevelt! Welcome to Chicago, Illinois!'], ['Hello, Wallace Russel Osbourne! Welcome to Albany, New York!'], ['Hello, Lupin the Third! Welcome to Los Angeles, California!'], ['Hello, Marlo Stanfield! Welcome to Baltimore, Maryland!']]\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(say_hello(*i), o[0])"}
| 152
| 313
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has invented 1-minute Instant Noodles. As the name suggests, each packet takes exactly 1 minute to cook.
Chef's restaurant has X stoves and only 1 packet can be cooked in a single pan.
How many customers can Chef serve in Y minutes if each customer orders exactly 1 packet of noodles?
------ Input Format ------
- The first and only line of input contains two space-separated integers X and Y — the number of stoves and the number of minutes, respectively.
------ Output Format ------
- Print a single integer, the maximum number of customers Chef can serve in Y minutes
------ Constraints ------
$1 ≤ X, Y ≤ 1000$
----- Sample Input 1 ------
3 7
----- Sample Output 1 ------
21
----- explanation 1 ------
Chef cooks for $Y = 7$ minutes and can cook $X = 3$ packets per minute, one on each stove.
So, the total number of packets that can be cooked is $X \cdot Y = 3 \cdot 7 = 21$.
Each person orders one packet, so the maximum number of customers that can be served is $21$.
----- Sample Input 2 ------
7 8
----- Sample Output 2 ------
56
----- explanation 2 ------
Chef cooks for $Y = 8$ minutes and can cook $X = 7$ packets per minute, one on each stove.
So, the total number of packets that can be cooked is $X \cdot Y = 7 \cdot 8 = 56$.
Each person orders one packet, so the maximum number of customers that can be served is $56$.
|
{"inputs": ["3 7", "7 8"], "outputs": ["21", "56"]}
| 367
| 24
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if:
nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the range i < k < j, or
nums[i] > nums[j] and nums[k] >= nums[i] for all indexes k in the range i < k < j.
You are also given an integer array costs of length n where costs[i] denotes the cost of jumping to index i.
Return the minimum cost to jump to the index n - 1.
Please complete the following python code precisely:
```python
class Solution:
def minCost(self, nums: List[int], costs: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,4,1], costs = [3,7,6,4,2]) == 8\n assert candidate(nums = [0,1,2], costs = [1,1,1]) == 2\n\n\ncheck(Solution().minCost)"}
| 188
| 77
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :
let x be the sum of all elements currently in your array.
choose index i, such that 0 <= i < n and set the value of arr at index i to x.
You may repeat this procedure as many times as needed.
Return true if it is possible to construct the target array from arr, otherwise, return false.
Please complete the following python code precisely:
```python
class Solution:
def isPossible(self, target: List[int]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(target = [9,3,5]) == True\n assert candidate(target = [1,1,1,2]) == False\n assert candidate(target = [8,5]) == True\n\n\ncheck(Solution().isPossible)"}
| 144
| 64
|
coding
|
Solve the programming task below in a Python markdown code block.
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level.
Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level.
-----Input-----
The first line of the input consists of two integers, the number of robots n (2 ≤ n ≤ 100 000) and the number of rap battles m ($1 \leq m \leq \operatorname{min}(100000, \frac{n(n - 1)}{2})$).
The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}), indicating that robot u_{i} beat robot v_{i} in the i-th rap battle. No two rap battles involve the same pair of robots.
It is guaranteed that at least one ordering of the robots satisfies all m relations.
-----Output-----
Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1.
-----Examples-----
Input
4 5
2 1
1 3
2 3
4 2
4 3
Output
4
Input
3 2
1 2
3 2
Output
-1
-----Note-----
In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles.
In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
|
{"inputs": ["2 1\n1 2\n", "2 1\n2 1\n", "2 1\n2 1\n", "2 1\n2 1\n", "2 1\n1 2\n", "4 1\n2 1\n", "4 1\n4 1\n", "3 1\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1", "1", "-1\n", "-1\n", "-1\n"]}
| 556
| 116
|
coding
|
Solve the programming task below in a Python markdown code block.
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.
The current state of the wall can be respresented by a sequence $a$ of $n$ integers, with $a_i$ being the height of the $i$-th part of the wall.
Vova can only use $2 \times 1$ bricks to put in the wall (he has infinite supply of them, however).
Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some $i$ the current height of part $i$ is the same as for part $i + 1$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $1$ of the wall or to the right of part $n$ of it).
Note that Vova can't put bricks vertically.
Vova is a perfectionist, so he considers the wall completed when: all parts of the wall has the same height; the wall has no empty spaces inside it.
Can Vova complete the wall using any amount of bricks (possibly zero)?
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of parts in the wall.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the initial heights of the parts of the wall.
-----Output-----
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
-----Examples-----
Input
5
2 1 1 2 5
Output
YES
Input
3
4 5 3
Output
NO
Input
2
10 10
Output
YES
-----Note-----
In the first example Vova can put a brick on parts 2 and 3 to make the wall $[2, 2, 2, 2, 5]$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $[5, 5, 5, 5, 5]$.
In the second example Vova can put no bricks in the wall.
In the third example the wall is already complete.
|
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "2\n1 2\n", "2\n3 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 578
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains $a$ stones, the second of them contains $b$ stones and the third of them contains $c$ stones.
Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $0$ stones. Can you help her?
-----Input-----
The first line contains one integer $t$ ($1 \leq t \leq 100$) — the number of test cases. Next $t$ lines describe test cases in the following format:
Line contains three non-negative integers $a$, $b$ and $c$, separated by spaces ($0 \leq a,b,c \leq 100$) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so $t = 1$ should be satisfied.
-----Output-----
Print $t$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
-----Example-----
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
-----Note-----
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $9$. It is impossible to make some operations to take more than $9$ stones, so the answer is $9$.
|
{"inputs": ["3\n3 4 5\n1 0 5\n5 3 2\n", "3\n3 4 5\n1 0 5\n7 3 2\n", "3\n0 4 5\n1 0 5\n7 3 2\n", "3\n0 8 5\n1 0 5\n7 3 2\n", "3\n0 8 5\n0 0 5\n7 3 2\n", "3\n3 4 5\n1 0 5\n5 3 2\n", "3\n0 8 5\n0 0 5\n12 3 1\n", "3\n0 8 5\n0 0 5\n12 3 2\n"], "outputs": ["9\n0\n6\n", "9\n0\n6\n", "6\n0\n6\n", "6\n0\n6\n", "6\n0\n6\n", "9\n0\n6\n", "6\n0\n3\n", "6\n0\n6\n"]}
| 499
| 248
|
coding
|
Solve the programming task below in a Python markdown code block.
There is an empty grid (all cells are colored white) of N rows and M columns.
Chef can fill each cell with either RED or GREEN color.
Chef defines a *valid* path as a path of cells starting from (1,1) and ending at (N,M), where, Chef moves either right or down by 1 cell each time.
For a particular grid, Chef defines the *score* of the grid as the number of *valid* paths containing equal number of RED and GREEN cells.
Find the sum of *scores* of all possible colored grids containing N rows and M columns.
Since the answer can be large, output it modulo 998244353.
------ 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 integers N and M - denoting the dimensions of the grid.
------ Output Format ------
For each test case, output the sum of *scores* of all possible colored grids containing N rows and M columns, modulo 998244353.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N, M ≤ 1000$
----- Sample Input 1 ------
3
1 1
1 2
2 3
----- Sample Output 1 ------
0
2
72
----- explanation 1 ------
Test case $1$: There are $2$ possible coloured grids of size $1 \times 1$. In the first grid, the one and only cell is colored RED. In the second grid, the one and only cell is colored GREEN. Neither of the grids have a *valid* path with equal number of red and green cells. Thus, score of each grid is $0$.
Test case $2$: There are $4$ possible coloured grids of the given dimension:
For grids $1$ and $4$, the scores are $0$ as there are no valid paths with equal red and green cells. Grids $2$ and $3$ have score $1$ each. The valid path with equal red and green cells is $(1,1) \rightarrow (1,2)$ in both the grids.
Thus, the sum of scores of all possible coloured grids is $2$.
|
{"inputs": ["3\n1 1\n1 2\n2 3\n"], "outputs": ["0\n2\n72\n"]}
| 498
| 31
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a.
-----Output-----
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a_{j} — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
-----Examples-----
Input
7 1
1 0 0 1 1 0 1
Output
4
1 0 0 1 1 1 1
Input
10 2
1 0 0 1 0 1 0 1 0 1
Output
5
1 0 0 1 1 1 1 1 0 1
|
{"inputs": ["1 0\n0\n", "1 0\n0\n", "1 0\n1\n", "1 1\n0\n", "1 1\n1\n", "1 0\n0\n", "1 0\n1\n", "1 1\n0\n"], "outputs": ["0\n0\n", "0\n0\n", "1\n1\n", "1\n1\n", "1\n1\n", "0\n0 ", "1\n1 ", "1\n1 "]}
| 306
| 116
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a binary string S of length N and an integer K. You can perform the following operation on the string:
Select a *prefix* of the string S and flip all the characters of the prefix. A flip corresponds to changing 0 to 1 and vice-versa.
Find the minimum number of operations required to obtain a substring of length K such that all characters of the substring are 1.
Note:
A prefix is obtained by deleting some (possibly zero) characters from the end of the string.
A substring is obtained by deleting some (possibly zero) characters from the beginning of the string and some (possibly zero) characters from the end of the string.
------ 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 two space-separated integers N and K — the length of the string and the length length of substring containing all 1s we want to achieve.
- The next line contains the binary string S.
------ Output Format ------
For each test case, output on a new line, the minimum number of operations required to obtain a substring of length K such that all characters of the substring are 1.
------ Constraints ------
$1 ≤ T ≤ 2000$
$1 ≤ K ≤N ≤ 3\cdot 10^{5}$
$S$ consists of $0$ and $1$ only.
- The sum of $N$ over all test cases won't exceed $3\cdot 10^{5}$.
----- Sample Input 1 ------
3
3 3
000
4 2
0110
5 3
10101
----- Sample Output 1 ------
1
0
2
----- explanation 1 ------
Test case $1$: We need to obtain a substring containing three $1$s. Using one operation, we can select the prefix $S[1,3]$ and flip all the characters in the prefix. Thus, the string becomes $111$.
Test case $2$: The string already contains a substring having two $1$s. Thus, we do not need any operation.
Test case $3$: We need to obtain a substring containing three $1$s. We can do so using $2$ operations:
- Operation $1$: Select the prefix $S[1, 4]$ and flip all characters in the prefix. Thus, the string becomes $01011$.
- Operation $2$: Select the prefix $S[1, 3]$ and flip all characters in the prefix. Thus, the string becomes $10111$.
Thus, we have a substring $S[3,5]$ of length $3$ where all characters of the substring are $1$. It can be shown that we cannot obtain such substring using less than $2$ operations.
|
{"inputs": ["3\n3 3\n000\n4 2\n0110\n5 3\n10101\n"], "outputs": ["1\n0\n2\n"]}
| 627
| 45
|
coding
|
Solve the programming task below in a Python markdown code block.
Problem
There are n vertices that are not connected to any of the vertices.
An undirected side is stretched between each vertex.
Find out how many sides can be stretched when the diameter is set to d.
The diameter represents the largest of the shortest distances between two vertices.
Here, the shortest distance is the minimum value of the number of sides required to move between vertices.
Multiple edges and self-loops are not allowed.
Constraints
* 2 ≤ n ≤ 109
* 1 ≤ d ≤ n−1
Input
n d
Two integers n and d are given on one line, separated by blanks.
Output
Output the maximum number of sides that can be stretched on one line.
Examples
Input
4 3
Output
3
Input
5 1
Output
10
Input
4 2
Output
5
|
{"inputs": ["0 1", "4 5", "6 5", "0 2", "4 1", "6 9", "0 8", "8 1"], "outputs": ["0\n", "2\n", "5\n", "-1\n", "6\n", "7\n", "26\n", "28\n"]}
| 189
| 80
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick.
You can connect any two sticks of lengths x and y into one stick by paying a cost of x + y. You must connect all the sticks until there is only one stick remaining.
Return the minimum cost of connecting all the given sticks into one stick in this way.
Please complete the following python code precisely:
```python
class Solution:
def connectSticks(self, sticks: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(sticks = [2,4,3]) == 14\n assert candidate(sticks = [1,8,3,5]) == 30\n assert candidate(sticks = [5]) == 0\n\n\ncheck(Solution().connectSticks)"}
| 143
| 71
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 106) — the number of segments and the value of k.
The next n lines contain two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109) each — the endpoints of the i-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.
Output
First line contains integer m — the smallest number of segments.
Next m lines contain two integers aj, bj (aj ≤ bj) — the ends of j-th segment in the answer. The segments should be listed in the order from left to right.
Examples
Input
3 2
0 5
-3 2
3 8
Output
2
0 2
3 5
Input
3 2
0 5
-3 3
3 8
Output
1
0 5
|
{"inputs": ["1 1\n2 2\n", "1 1\n0 1\n", "1 1\n1 1\n", "1 1\n-1 1\n", "2 1\n0 2\n0 0\n", "2 1\n0 2\n-1 0\n", "2 2\n-3 1\n-4 -1\n", "3 2\n0 5\n-3 2\n1 8\n"], "outputs": ["1\n2 2\n", "1\n0 1\n", "1\n1 1\n", "1\n-1 1\n", "1\n0 2\n", "1\n-1 2\n", "1\n-3 -1\n", "1\n0 5\n"]}
| 267
| 178
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is playing a videogame, and is getting close to the end. He decides to finish the rest of the game in a single session.
There are X levels remaining in the game, and each level takes Chef Y minutes to complete. To protect against eye strain, Chef also decides that every time he completes 3 levels, he will take a Z minute break from playing. Note that there is no need to take this break if the game has been completed.
How much time (in minutes) will it take Chef to complete the game?
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- The first and only line of input will contain three space-separated integers X, Y, and Z.
------ Output Format ------
For each test case, output on a new line the answer — the length of Chef's gaming session.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ X ≤ 100$
$5 ≤ Y ≤ 100$
$5 ≤ Z ≤ 15$
----- Sample Input 1 ------
4
2 12 10
3 12 10
7 20 8
24 45 15
----- Sample Output 1 ------
24
36
156
1185
|
{"inputs": ["4\n2 12 10\n3 12 10\n7 20 8\n24 45 15\n"], "outputs": ["24\n36\n156\n1185"]}
| 300
| 58
|
coding
|
Solve the programming task below in a Python markdown code block.
For a pole vaulter, it is very important to begin the approach run at the best possible starting mark. This is affected by numerous factors and requires fine-tuning in practice. But there is a guideline that will help a beginning vaulter start at approximately the right location for the so-called "three-step approach," based on the vaulter's body height.
This guideline was taught to me in feet and inches, but due to the international nature of Codewars, I am creating this kata to use metric units instead.
You are given the following two guidelines to begin with:
(1) A vaulter with a height of 1.52 meters should start at 9.45 meters on the runway.
(2) A vaulter with a height of 1.83 meters should start at 10.67 meters on the runway.
You will receive a vaulter's height in meters (which will always lie in a range between a minimum of 1.22 meters and a maximum of 2.13 meters). Your job is to return the best starting mark in meters, rounded to two decimal places.
Hint: Based on the two guidelines given above, you will want to account for the change in starting mark per change in body height. This involves a linear relationship. But there is also a constant offset involved. If you can determine the rate of change described above, you should be able to determine that constant offset.
Also feel free to reuse/extend the following starter code:
```python
def starting_mark(height):
```
|
{"functional": "_inputs = [[1.52], [1.83], [1.22], [2.13], [1.75]]\n_outputs = [[9.45], [10.67], [8.27], [11.85], [10.36]]\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(starting_mark(*i), o[0])"}
| 335
| 212
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums consisting of 2 * n integers.
You need to divide nums into n pairs such that:
Each element belongs to exactly one pair.
The elements present in a pair are equal.
Return true if nums can be divided into n pairs, otherwise return false.
Please complete the following python code precisely:
```python
class Solution:
def divideArray(self, nums: List[int]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,3,2,2,2]) == True\n assert candidate(nums = [1,2,3,4]) == False\n\n\ncheck(Solution().divideArray)"}
| 106
| 57
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i.
Taro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order. Here, the tower must satisfy the following condition:
* For each Block i contained in the tower, the sum of the weights of the blocks stacked above it is not greater than s_i.
Find the maximum possible sum of the values of the blocks contained in the tower.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^3
* 1 \leq w_i, s_i \leq 10^4
* 1 \leq v_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
w_1 s_1 v_1
w_2 s_2 v_2
:
w_N s_N v_N
Output
Print the maximum possible sum of the values of the blocks contained in the tower.
Examples
Input
3
2 2 20
2 1 30
3 1 40
Output
50
Input
4
1 2 10
3 1 10
2 4 10
1 6 10
Output
40
Input
5
1 10000 1000000000
1 10000 1000000000
1 10000 1000000000
1 10000 1000000000
1 10000 1000000000
Output
5000000000
Input
8
9 5 7
6 2 7
5 7 3
7 8 8
1 9 6
3 3 3
4 1 7
4 5 5
Output
22
|
{"inputs": ["3\n2 2 20\n2 1 7\n3 1 40", "3\n2 3 20\n2 1 7\n3 1 40", "3\n3 5 20\n1 1 7\n3 1 40", "3\n2 2 20\n2 1 30\n3 1 47", "3\n2 2 20\n2 1 30\n3 2 47", "3\n2 2 20\n2 1 29\n3 2 47", "3\n2 2 20\n2 1 29\n3 4 47", "3\n4 2 20\n2 1 35\n3 0 71"], "outputs": ["40\n", "60\n", "67\n", "50\n", "77\n", "76\n", "96\n", "71\n"]}
| 505
| 235
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
John won the championship of a TV show. He can get some bonuses.
He needs to play a game to determine the amount of his bonus.
Here are some cards in a row. A number is written on each card.
In each turn, John can take a card, but only from the beginning or the end of the row. Then multiply the number on the card by an coefficient 2^(i)(i means the ith turn). The product is John's bonus of current turn.
After all the cards are taken away, the game is over. John's final bonus is the sum of all rounds of bonuses.
Obviously, the order in which John takes the cards will affect the amount of John's final bonus.
Your task is to help John calculate the maximum amount of bonuses he can get.
# Input
- `cards`: An integer array. Each element represents the number on the card.
- `1 <= cards.length <= 30`
- `1 <= cards[i] <= 100`
- All inputs are valid.
# Output
An integer. the maximum amount of bonuses John can get.
# Eaxmple
For `cards=[1,2,5]`, the output should be `50`.
```
All possible orders are:
1->2->5 bonus:1x2+2*4+5*8=50
1->5->2 bonus:1x2+5*4+2*8=38
5->1->2 bonus:5*2+1*4+2*8=30
5->2->1 bonus:5*2+2*4+1*8=26
The maximum amount of bonus is 50.
```
Also feel free to reuse/extend the following starter code:
```python
def calc(cards):
```
|
{"functional": "_inputs = [[[1, 2, 5]], [[1]], [[1, 1]], [[1, 2, 1]], [[4, 10, 2, 3, 1, 3, 1, 6, 9]]]\n_outputs = [[50], [2], [6], [22], [6722]]\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(calc(*i), o[0])"}
| 400
| 222
|
coding
|
Solve the programming task below in a Python markdown code block.
An array A of size N is called *good* if the following conditions hold:
For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].)
JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times:
Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}.
Find the minimum number of operations required to convert A into a *good* array.
------ Input Format ------
- The first line contains 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 minimum number of operations required to convert the array A into a good array.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ A_{i} < 2^{30}$
- Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
----- Sample Input 1 ------
3
5
1 2 3 4 4
3
0 0 0
6
2 3 5 7 11 13
----- Sample Output 1 ------
2
3
0
----- explanation 1 ------
Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations.
Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations.
Test Case 3: The given array $A$ is already *good*.
|
{"inputs": ["3\n5\n1 2 3 4 4\n3\n0 0 0\n6\n2 3 5 7 11 13\n"], "outputs": ["2\n3\n0\n"]}
| 590
| 54
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is currently standing at stair 0 and he wants to reach stair numbered X.
Chef can climb either Y steps or 1 step in one move.
Find the minimum number of moves required by him to reach exactly the stair numbered 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 containing two space separated integers X and Y denoting the number of stair Chef wants to reach and the number of stairs he can climb in one move.
------ Output Format ------
For each test case, output the minimum number of moves required by him to reach exactly the stair numbered X.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ X, Y ≤ 100$
----- Sample Input 1 ------
4
4 2
8 3
3 4
2 1
----- Sample Output 1 ------
2
4
3
2
----- explanation 1 ------
Test case $1$: Chef can make $2$ moves and climb $2$ steps in each move to reach stair numbered $4$.
Test case $2$: Chef can make a minimum of $4$ moves. He can climb $3$ steps in $2$ of those moves and $1$ step each in remaining $2$ moves to reach stair numbered $8$.
Test case $3$: Chef can make $3$ moves and climb $1$ step in each move to reach stair numbered $3$.
Test case $4$: Chef can make $2$ moves and climb $1$ step in each move to reach stair numbered $2$.
|
{"inputs": ["4\n4 2\n8 3\n3 4\n2 1\n"], "outputs": ["2\n4\n3\n2\n"]}
| 364
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the $n$ days of summer. On the $i$-th day, $a_i$ millimeters of rain will fall. All values $a_i$ are distinct.
The mayor knows that citizens will watch the weather $x$ days before the celebration and $y$ days after. Because of that, he says that a day $d$ is not-so-rainy if $a_d$ is smaller than rain amounts at each of $x$ days before day $d$ and and each of $y$ days after day $d$. In other words, $a_d < a_j$ should hold for all $d - x \le j < d$ and $d < j \le d + y$. Citizens only watch the weather during summer, so we only consider such $j$ that $1 \le j \le n$.
Help mayor find the earliest not-so-rainy day of summer.
-----Input-----
The first line contains three integers $n$, $x$ and $y$ ($1 \le n \le 100\,000$, $0 \le x, y \le 7$) — the number of days in summer, the number of days citizens watch the weather before the celebration and the number of days they do that after.
The second line contains $n$ distinct integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 10^9$), where $a_i$ denotes the rain amount on the $i$-th day.
-----Output-----
Print a single integer — the index of the earliest not-so-rainy day of summer. We can show that the answer always exists.
-----Examples-----
Input
10 2 2
10 9 6 7 8 3 2 1 4 5
Output
3
Input
10 2 3
10 9 6 7 8 3 2 1 4 5
Output
8
Input
5 5 5
100000 10000 1000 100 10
Output
5
-----Note-----
In the first example days $3$ and $8$ are not-so-rainy. The $3$-rd day is earlier.
In the second example day $3$ is not not-so-rainy, because $3 + y = 6$ and $a_3 > a_6$. Thus, day $8$ is the answer. Note that $8 + y = 11$, but we don't consider day $11$, because it is not summer.
|
{"inputs": ["1 0 0\n7\n", "1 0 1\n7\n", "1 0 0\n10\n", "1 0 0\n10\n", "1 0 1\n10\n", "2 1 0\n2 1\n", "2 0 1\n2 1\n", "2 2 2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
| 628
| 127
|
coding
|
Solve the programming task below in a Python markdown code block.
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university.
The second line contains n numbers a_{i} (0 ≤ a_{i} ≤ 1). Number a_{i} equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a_1, a_2, ..., a_{n} are separated by spaces.
-----Output-----
Print a single number — the number of pairs during which Alena stays at the university.
-----Examples-----
Input
5
0 1 0 1 1
Output
4
Input
7
1 0 1 0 0 1 0
Output
4
Input
1
0
Output
0
-----Note-----
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home.
|
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "2\n1 1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "1\n", "1\n", "2\n"]}
| 572
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
One of the built-in functions of Python is divmod, which takes two arguments $\boldsymbol{\alpha}$ and $\boldsymbol{b}$ and returns a tuple containing the quotient of $a/b$ first and then the remainder $\boldsymbol{a}$.
For example:
>>> print divmod(177,10)
(17, 7)
Here, the integer division is 177/10 => 17 and the modulo operator is 177%10 => 7.
Task
Read in two integers, $\boldsymbol{a}$ and $\boldsymbol{b}$, and print three lines.
The first line is the integer division $\boldsymbol{a}//b$ (While using Python2 remember to import division from __future__).
The second line is the result of the modulo operator: $a\%b$.
The third line prints the divmod of $\boldsymbol{a}$ and $\boldsymbol{b}$.
Input Format
The first line contains the first integer, $\boldsymbol{a}$, and the second line contains the second integer, $\boldsymbol{b}$.
Output Format
Print the result as described above.
Sample Input
177
10
Sample Output
17
7
(17, 7)
|
{"inputs": ["177\n10\n"], "outputs": ["17\n7\n(17, 7)\n"]}
| 291
| 30
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.
You are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can take at most one pile of candies and some piles of candies may go unused.
Return the maximum number of candies each child can get.
Please complete the following python code precisely:
```python
class Solution:
def maximumCandies(self, candies: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(candies = [5,8,6], k = 3) == 5\n assert candidate(candies = [2,5], k = 11) == 0\n\n\ncheck(Solution().maximumCandies)"}
| 159
| 66
|
coding
|
Solve the programming task below in a Python markdown code block.
Mario was going to gift Princess Peach a string S of even length N.
Mario was clumsy and thus, broke the string in the middle. He now has two strings A and B such that A = S[1, \frac{N}{2}] and B = S[\frac{N}{2} + 1, N].
Mario is not sure about the order in which he should join the strings A and B to get the string S. Thus, he joins the strings in any random order. Find whether it is guaranteed that Mario will get the same string S if he joins the strings A and B in any order.
Note that S[L, R] denotes a substring of string S starting at index L and having a length (R - L + 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 two lines of input:
- The first line of each test case contains N - the length of the initial string S.
- The second line contains the string S.
------ Output Format ------
For each test case, print YES if it is guaranteed that Mario will get the same string S irrespective of the order in which he joins the strings A and B and NO otherwise.
You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).
------ Constraints ------
$1 ≤ T ≤ 3000$
$1 ≤ N ≤ 1000$
$N$ is even.
$S$ consists of lowercase english alphabets.
----- Sample Input 1 ------
4
6
abcabc
6
abcdef
4
aaaa
4
baab
----- Sample Output 1 ------
YES
NO
YES
NO
----- explanation 1 ------
Test case $1$: On breaking, the string $S$ gives $A = abc$ and $B = abc$. Thus, joining it in either way $(AB$ or $BA)$, would give the same string $S$.
Test case $2$: On breaking, the string $S$ gives $A = abc$ and $B = def$. Joining it as $BA$ would give the string $defabc$ which is not equal to string $S$.
Test case $3$: On breaking, the string $S$ gives $A = aa$ and $B = aa$. Thus, joining it in either way $(AB$ or $BA)$, would give the same string $S$.
Test case $4$: On breaking, the string $S$ gives $A = ba$ and $B = ab$. Joining it as $BA$ would give the string $abba$ which is not equal to string $S$.
|
{"inputs": ["4\n6\nabcabc\n6\nabcdef\n4\naaaa\n4\nbaab"], "outputs": ["YES\nNO\nYES\nNO\n"]}
| 601
| 37
|
coding
|
Solve the programming task below in a Python markdown code block.
There are 32 letters in the Polish alphabet: 9 vowels and 23 consonants.
Your task is to change the letters with diacritics:
```
ą -> a,
ć -> c,
ę -> e,
ł -> l,
ń -> n,
ó -> o,
ś -> s,
ź -> z,
ż -> z
```
and print out the string without the use of the Polish letters.
For example:
```
"Jędrzej Błądziński" --> "Jedrzej Bladzinski"
```
Also feel free to reuse/extend the following starter code:
```python
def correct_polish_letters(st):
```
|
{"functional": "_inputs = [['J\u0119drzej B\u0142\u0105dzi\u0144ski'], ['Lech Wa\u0142\u0119sa'], ['Maria Sk\u0142odowska-Curie'], ['W\u0142adys\u0142aw Reymont'], ['Miko\u0142aj Kopernik'], ['J\u00f3zef Pi\u0142sudski'], ['Czes\u0142aw Mi\u0142osz'], ['Agnieszka Radwa\u0144ska'], ['Wojciech Szcz\u0119sny'], ['Za\u017c\u00f3\u0142\u0107 g\u0119\u015bl\u0105 ja\u017a\u0144'], [\"W\u00f3\u0142 go pyta: 'Panie chrz\u0105szczu,Po co pan tak brz\u0119czy w g\u0105szczu?'\"]]\n_outputs = [['Jedrzej Bladzinski'], ['Lech Walesa'], ['Maria Sklodowska-Curie'], ['Wladyslaw Reymont'], ['Mikolaj Kopernik'], ['Jozef Pilsudski'], ['Czeslaw Milosz'], ['Agnieszka Radwanska'], ['Wojciech Szczesny'], ['Zazolc gesla jazn'], [\"Wol go pyta: 'Panie chrzaszczu,Po co pan tak brzeczy w gaszczu?'\"]]\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(correct_polish_letters(*i), o[0])"}
| 154
| 539
|
coding
|
Solve the programming task below in a Python markdown code block.
Write
```python
function combine()
```
that combines arrays by alternatingly taking elements passed to it.
E.g
```python
combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) == ['a', 1, 6, 8, 'b', 2, 7, 'c', 3, 4, 5]
```
Arrays can have different lengths.
Also feel free to reuse/extend the following starter code:
```python
def combine(*args):
```
|
{"functional": "_inputs = [[['a', 'b', 'c'], [1, 2, 3]], [['a', 'b', 'c'], [1, 2, 3, 4, 5]], [['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]], [[{'a': 1}, {'b': 2}], [1, 2]], [[{'a': 2, 'b': 1}, {'a': 1, 'b': 2}], [1, 2, 3, 4], [5, 6], [7]]]\n_outputs = [[['a', 1, 'b', 2, 'c', 3]], [['a', 1, 'b', 2, 'c', 3, 4, 5]], [['a', 1, 6, 8, 'b', 2, 7, 'c', 3, 4, 5]], [[{'a': 1}, 1, {'b': 2}, 2]], [[{'a': 2, 'b': 1}, 1, 5, 7, {'a': 1, 'b': 2}, 2, 6, 3, 4]]]\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(combine(*i), o[0])"}
| 226
| 430
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:
i < j < k,
nums[j] - nums[i] == diff, and
nums[k] - nums[j] == diff.
Return the number of unique arithmetic triplets.
Please complete the following python code precisely:
```python
class Solution:
def arithmeticTriplets(self, nums: List[int], diff: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,4,6,7,10], diff = 3) == 2\n assert candidate(nums = [4,5,6,7,8,9], diff = 2) == 2\n\n\ncheck(Solution().arithmeticTriplets)"}
| 130
| 76
|
coding
|
Solve the programming task below in a Python markdown code block.
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance c_{i} and width w_{i}.
Stepan decided to expose some of his cups on a shelf with width d in such a way, that: there is at least one Physics cup and at least one Informatics cup on the shelf, the total width of the exposed cups does not exceed d, from each subjects (Physics and Informatics) some of the most significant cups are exposed (i. e. if a cup for some subject with significance x is exposed, then all the cups for this subject with significance greater than x must be exposed too).
Your task is to determine the maximum possible total significance, which Stepan can get when he exposes cups on the shelf with width d, considering all the rules described above. The total significance is the sum of significances of all the exposed cups.
-----Input-----
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100 000, 1 ≤ d ≤ 10^9) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf.
Each of the following n lines contains two integers c_{i} and w_{i} (1 ≤ c_{i}, w_{i} ≤ 10^9) — significance and width of the i-th cup for Physics olympiads.
Each of the following m lines contains two integers c_{j} and w_{j} (1 ≤ c_{j}, w_{j} ≤ 10^9) — significance and width of the j-th cup for Informatics olympiads.
-----Output-----
Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement.
If there is no way to expose cups on the shelf, then print 0.
-----Examples-----
Input
3 1 8
4 2
5 5
4 2
3 2
Output
8
Input
4 3 12
3 4
2 4
3 5
3 4
3 5
5 2
3 4
Output
11
Input
2 2 2
5 3
6 3
4 2
8 1
Output
0
-----Note-----
In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most significant cup for Physics (its significance equals 5). After that Stepan can not expose more cups on the shelf, because there is no enough free space. Thus, the maximum total significance of exposed cups equals to 8.
|
{"inputs": ["1 1 1\n1 1\n1 1\n", "1 1 1\n1 1\n1 1\n", "1 1 1\n1 0\n1 1\n", "3 1 8\n4 2\n5 5\n4 2\n3 2\n", "2 2 2\n5 3\n6 3\n4 2\n8 1\n", "3 1 8\n0 2\n5 5\n4 2\n3 2\n", "2 2 2\n5 3\n6 3\n4 2\n8 2\n", "3 1 6\n0 2\n5 5\n4 2\n3 2\n"], "outputs": ["0\n", "0\n", "2\n", "8\n", "0\n", "8\n", "0\n", "0\n"]}
| 672
| 206
|
coding
|
Solve the programming task below in a Python markdown code block.
You're fed up about changing the version of your software manually. Instead, you will create a little script that will make it for you.
# Exercice
Create a function `nextVersion`, that will take a string in parameter, and will return a string containing the next version number.
For example:
# Rules
All numbers, except the first one, must be lower than 10: if there are, you have to set them to 0 and increment the next number in sequence.
You can assume all tests inputs to be valid.
Also feel free to reuse/extend the following starter code:
```python
def next_version(version):
```
|
{"functional": "_inputs = [['1.2.3'], ['0.9.9'], ['1'], ['1.2.3.4.5.6.7.8'], ['9.9']]\n_outputs = [['1.2.4'], ['1.0.0'], ['2'], ['1.2.3.4.5.6.7.9'], ['10.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(next_version(*i), o[0])"}
| 145
| 227
|
coding
|
Solve the programming task below in a Python markdown code block.
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s_1s_2... s_{n} (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers l_{i}, r_{i} (1 ≤ l_{i} < r_{i} ≤ n). The answer to the query l_{i}, r_{i} is the number of such integers i (l_{i} ≤ i < r_{i}), that s_{i} = s_{i} + 1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
-----Input-----
The first line contains string s of length n (2 ≤ n ≤ 10^5). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer m (1 ≤ m ≤ 10^5) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers l_{i}, r_{i} (1 ≤ l_{i} < r_{i} ≤ n).
-----Output-----
Print m integers — the answers to the queries in the order in which they are given in the input.
-----Examples-----
Input
......
4
3 4
2 3
1 6
2 6
Output
1
1
5
4
Input
#..###
5
1 3
5 6
1 5
3 6
3 4
Output
1
1
2
2
0
|
{"inputs": ["..\n1\n1 2\n", "##\n1\n1 2\n", ".#\n1\n1 2\n", "#.\n1\n1 2\n", "#.\n1\n1 2\n", "##\n1\n1 2\n", "..\n1\n1 2\n", ".#\n1\n1 2\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n"]}
| 381
| 120
|
coding
|
Solve the programming task below in a Python markdown code block.
Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2.
One day he played a game in his class. He brought some number plates on each of which a digit from 0 to 9 is written. He made students stand in a row and gave a number plate to each of the student. Now turn by turn, he called for some students who are standing continuously in the row say from index i to index j (i<=j) and asked them to find their strength.
The strength of the group of students from i to j is defined as:
strength(i , j)
{
if a[i] = 0
return 0; //If first child has value 0 in the group, strength of group is zero
value = 0;
for k from i to j
value = value*10 + a[k]
return value;
}
Prof called for all possible combinations of i and j and noted down the strength of each group. Now being interested in powers of 2, he wants to find out how many strengths are powers of two. Now its your responsibility to get the answer for prof.
Input Format
First line contains number of test cases T
Next T line contains the numbers of number plates the students were having when standing in the row in the form of a string A.
Constraints
1 ≤ T ≤ 100
1 ≤ len(A) ≤ $10^{5}$
0 ≤ A[i] ≤ 9
Output Format
Output the total number of strengths of the form 2^{x} such that 0 ≤ x ≤ 800.
Sample Input 0
5
2222222
24256
65536
023223
33579
Sample Output 0
7
4
1
4
0
Explanation 0
In following explanations group i-j is group of student from index i to index j (1-based indexing)
In first case only 2 is of form power of two. It is present seven times for groups 1-1,2-2,3-3,4-4,5-5,6-6,7-7
In second case 2,4 and 256 are of required form. 2 is strength of group 1-1 and 3-3, 4 is strength of group 2-2 and 256 is strength of group 3-5.
In third case 65536 is only number in required form. It is strength of group 1-5
In fourth case 2 and 32 are of forms power of 2. Group 1-2 has values 0,2 but its strength is 0, as first value is 0.
In fifth case, None of the group has strength of required form.
|
{"inputs": ["5\n2222222\n24256\n65536\n023223\n33579\n"], "outputs": ["7\n4\n1\n4\n0\n"]}
| 647
| 55
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries are as follows:
She gives you the first few characters of a recipe; you have to print the complete recipe with the highest priority.
Note:
Every recipe has a unique priority
-----Input-----
First line contains an integer N - the number of recipes.
Followed by N strings Si along with an integer each Vi.
Si stands for the recipe and Vi for the priority.
It is followed by an integer Q - the number of queries.
Followed by Q strings Qi.
Each string Si, Qi contain only lowercase Latin alphabets ('a' - 'z') and '-'.
-----Output-----
Q – lines, each contain the answer for each of the query.
If for a query no recipe matches print "NO". (Without quotes)
Constraints:
0 <= N <= 1000
0 <= Q <= 1000
-10^9 <= Vi <= 10^9
1 <= |Si| <= 1000 (length of Si)
1 <= |Qi| <= 1000 (length of Qi)
-----Example-----
Input:
4
flour-with-eggs 100
chicken-ham -10
flour-without-eggs 200
fish-with-pepper 1100
6
f
flour-with
flour-with-
c
fl
chik
Output:
fish-with-pepper
flour-without-eggs
flour-with-eggs
chicken-ham
flour-without-eggs
NO
|
{"inputs": ["4\nflovr-with-eggs 010\nchadken-him -26\nflotrswithout-efg- 7\nriwpep--tdpsghif 0001\n3\nf\nilour.wfth\n.huix-ruokf\na\nld\nkicj", "4\nflovr-with-eggs 000\nchbdken-him -26\nflotrswithouu-efg- 7\nriwpep--tdpsghif 0001\n3\nf\nitour.wflh\n.huix-rupkf\na\nkd\nkibj", "4\nflovr-with-eggs 010\nchbdken-him -26\nflotrswithouu-efg- 9\nriwpep--tdpsghif 0011\n2\nf\nitour.wfmh\n.huix-supkf\na\njd\nbikj", "4\nflour-with-eggs 010\nchicken-ham -10\nflourswithout-egg- 13\nfisg-with-pepper 1100\n6\nf\nflour-xith\nflour-with-\nb\nfl\niibk", "4\nsgge-htiw-ruolf 010\nchjcken-ham -7\nsgge-tuohtiw-ruolf 200\ngisg-with-pepper 1000\n6\ng\nflour-with\nflour-with-\nb\nfl\nkiic", "4\nsgge-htiw-ruolg 011\nchicken-ham -2\nflour-without-dggs 200\nfisg-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nb\nfl\nkbii", "4\nsgge-htiw-ruolg 011\nchicken-ham -2\nflour-without-dggs 200\nfisg-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nb\ngl\nkbii", "4\nsgge-htix,ruolf 011\nmch-nemciha -2\n-gge-tuohtiwsruomf 604\nfisg-with-peppeq 1100\n2\nf\nflour-whth\n-htiu-rxokf\nb\nfl\nkcij"], "outputs": ["flovr-with-eggs\nNO\nNO\n", "flotrswithouu-efg-\nNO\nNO\n", "flovr-with-eggs\nNO\n", "fisg-with-pepper\nNO\nflour-with-eggs\nNO\nflourswithout-egg-\nNO\n", "gisg-with-pepper\nNO\nNO\nNO\nNO\nNO\n", "fisg-with-pepper\nflour-without-dggs\nNO\nNO\nflour-without-dggs\nNO\n", "fisg-with-pepper\nflour-without-dggs\nNO\nNO\nNO\nNO\n", "fisg-with-peppeq\nNO\n"]}
| 397
| 727
|
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.
You have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.
Return the number of distinct integers in the final array.
Please complete the following python code precisely:
```python
class Solution:
def countDistinctIntegers(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,13,10,12,31]) == 6\n assert candidate(nums = [2,2,2]) == 1\n\n\ncheck(Solution().countDistinctIntegers)"}
| 108
| 61
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given two integers $a$ and $b$. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by $1$; during the second operation you choose one of these numbers and increase it by $2$, and so on. You choose the number of these operations yourself.
For example, if $a = 1$ and $b = 3$, you can perform the following sequence of three operations: add $1$ to $a$, then $a = 2$ and $b = 3$; add $2$ to $b$, then $a = 2$ and $b = 5$; add $3$ to $a$, then $a = 5$ and $b = 5$.
Calculate the minimum number of operations required to make $a$ and $b$ equal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases.
The only line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
For each test case print one integer — the minimum numbers of operations required to make $a$ and $b$ equal.
-----Example-----
Input
3
1 3
11 11
30 20
Output
3
0
4
-----Note-----
First test case considered in the statement.
In the second test case integers $a$ and $b$ are already equal, so you don't need to perform any operations.
In the third test case you have to apply the first, the second, the third and the fourth operation to $b$ ($b$ turns into $20 + 1 + 2 + 3 + 4 = 30$).
|
{"inputs": ["1\n0 2\n", "1\n0 0\n", "1\n1 0\n", "1\n1 1\n", "1\n1 2\n", "1\n0 79\n", "1\n0 10\n", "1\n0 -1\n"], "outputs": ["3\n", "0\n", "1\n", "0\n", "1\n", "13\n", "4\n", "1\n"]}
| 413
| 105
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a string, return the minimal number of parenthesis reversals needed to make balanced parenthesis.
For example:
```Javascript
solve(")(") = 2 Because we need to reverse ")" to "(" and "(" to ")". These are 2 reversals.
solve("(((())") = 1 We need to reverse just one "(" parenthesis to make it balanced.
solve("(((") = -1 Not possible to form balanced parenthesis. Return -1.
```
Parenthesis will be either `"("` or `")"`.
More examples in the test cases.
Good luck.
Also feel free to reuse/extend the following starter code:
```python
def solve(s):
```
|
{"functional": "_inputs = [[')()('], ['((()'], ['((('], ['())((('], ['())()))))()()(']]\n_outputs = [[2], [1], [-1], [3], [4]]\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(solve(*i), o[0])"}
| 152
| 189
|
coding
|
Solve the programming task below in a Python markdown code block.
Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity.
Input
The input is given in the following format:
Sales unit price, sales quantity
Sales unit price, sales quantity
::
::
A comma-separated pair of unit price and quantity is given across multiple lines. All values entered are greater than or equal to 0 and less than or equal to 1,000, and the number of unit price and quantity pairs does not exceed 100.
Output
Please output the total sales amount (integer) on the first line and the average sales quantity (integer) on the second line. If the average sales volume has a fraction (number after the decimal point), round off to the first decimal place.
Example
Input
100,20
50,10
70,35
Output
4950
22
|
{"inputs": ["100,20\n50,10\n80,35", "100,20\n01,05\n80,35", "100,20\n01,05\n80,36", "100,20\n01,05\n81,35", "000,20\n01,05\n80,36", "100,20\n50,10\n81,35", "000,10\n01,05\n80,36", "100,20\n50,01\n81,35"], "outputs": ["5300\n22\n", "4805\n20\n", "4885\n20\n", "4840\n20\n", "2885\n20\n", "5335\n22\n", "2885\n17\n", "4885\n19\n"]}
| 205
| 246
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 109 + 7.
Note:
A string is palindromic if it reads the same forward and backward.
A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
Please complete the following python code precisely:
```python
class Solution:
def countPalindromes(self, s: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"103301\") == 2\n assert candidate(s = \"0000000\") == 21\n assert candidate(s = \"9999900000\") == 2\n\n\ncheck(Solution().countPalindromes)"}
| 139
| 79
|
coding
|
Solve the programming task below in a Python markdown code block.
Transpose
We can generate the transposition of an array using the tool numpy.transpose.
It will not affect the original array, but it will create a new array.
import numpy
my_array = numpy.array([[1,2,3],
[4,5,6]])
print numpy.transpose(my_array)
#Output
[[1 4]
[2 5]
[3 6]]
Flatten
The tool flatten creates a copy of the input array flattened to one dimension.
import numpy
my_array = numpy.array([[1,2,3],
[4,5,6]])
print my_array.flatten()
#Output
[1 2 3 4 5 6]
Task
You are given a $N$X$\mbox{M}$ integer array matrix with space separated elements ($N$ = rows and $\mbox{M}$ = columns).
Your task is to print the transpose and flatten results.
Input Format
The first line contains the space separated values of $N$ and $\mbox{M}$.
The next $N$ lines contains the space separated elements of $\mbox{M}$ columns.
Output Format
First, print the transpose array and then print the flatten.
Sample Input
2 2
1 2
3 4
Sample Output
[[1 3]
[2 4]]
[1 2 3 4]
|
{"inputs": ["2 2\n1 2\n3 4\n"], "outputs": ["[[1 3]\n [2 4]]\n[1 2 3 4]\n"]}
| 302
| 45
|
coding
|
Solve the programming task below in a Python markdown code block.
Luntik has decided to try singing. He has $a$ one-minute songs, $b$ two-minute songs and $c$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert.
He wants to make the absolute difference of durations of the concerts as small as possible. The duration of the concert is the sum of durations of all songs in that concert.
Please help Luntik and find the minimal possible difference in minutes between the concerts durations.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.
Each test case consists of one line containing three integers $a, b, c$ $(1 \le a, b, c \le 10^9)$ — the number of one-minute, two-minute and three-minute songs.
-----Output-----
For each test case print the minimal possible difference in minutes between the concerts durations.
-----Examples-----
Input
4
1 1 1
2 1 3
5 5 5
1 1 2
Output
0
1
0
1
-----Note-----
In the first test case, Luntik can include a one-minute song and a two-minute song into the first concert, and a three-minute song into the second concert. Then the difference will be equal to $0$.
In the second test case, Luntik can include two one-minute songs and a two-minute song and a three-minute song into the first concert, and two three-minute songs into the second concert. The duration of the first concert will be $1 + 1 + 2 + 3 = 7$, the duration of the second concert will be $6$. The difference of them is $|7-6| = 1$.
|
{"inputs": ["4\n1 1 1\n2 1 3\n5 5 5\n1 1 2\n", "4\n1 1 1\n2 1 3\n5 2 5\n1 1 2\n", "4\n1 2 2\n2 1 1\n3 2 5\n1 1 2\n", "4\n1 2 2\n2 2 1\n3 2 2\n1 1 2\n", "4\n1 1 2\n2 2 1\n3 2 2\n2 1 2\n", "4\n2 2 0\n4 2 1\n6 4 5\n1 1 2\n", "4\n1 1 2\n2 2 1\n4 2 2\n2 1 2\n", "4\n2 2 0\n4 2 0\n6 4 5\n1 1 2\n"], "outputs": ["0\n1\n0\n1\n", "0\n1\n0\n1\n", "1\n1\n0\n1\n", "1\n1\n1\n1\n", "1\n1\n1\n0\n", "0\n1\n1\n1\n", "1\n1\n0\n0\n", "0\n0\n1\n1\n"]}
| 398
| 310
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given two integers $n$ and $k$.
Your task is to construct such a string $s$ of length $n$ that for each $i$ from $1$ to $k$ there is at least one $i$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.
You have to answer $t$ independent queries.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 100$) — the number of queries.
The next $t$ lines are contain queries, one per line. The $i$-th line contains two integers $n_i$ and $k_i$ ($1 \le n_i \le 100, 1 \le k_i \le min(n_i, 26)$) — the length of the string in the $i$-th query and the number of characters in the $i$-th query.
-----Output-----
Print $t$ lines. In the $i$-th line print the answer to the $i$-th query: any string $s_i$ satisfying the conditions in the problem statement with constraints from the $i$-th query.
-----Example-----
Input
3
7 3
4 4
6 2
Output
cbcacab
abcd
baabab
-----Note-----
In the first example query the maximum possible minimal frequency is $2$, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).
In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is $1$).
In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is $3$).
|
{"inputs": ["3\n7 3\n4 4\n6 2\n", "3\n7 3\n4 4\n6 2\n", "3\n3 3\n4 4\n6 2\n", "3\n7 3\n4 2\n6 2\n", "3\n7 2\n4 4\n6 2\n", "3\n7 3\n4 2\n5 2\n", "3\n7 3\n4 2\n5 1\n", "3\n7 3\n4 4\n5 1\n"], "outputs": ["abcabca\nabcd\nababab\n", "abcabca\nabcd\nababab\n", "abc\nabcd\nababab\n", "abcabca\nabab\nababab\n", "abababa\nabcd\nababab\n", "abcabca\nabab\nababa\n", "abcabca\nabab\naaaaa\n", "abcabca\nabcd\naaaaa\n"]}
| 462
| 228
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.