task_type
stringclasses 1
value | problem
stringlengths 261
3.34k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 62
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Solve the programming task below in a Python markdown code block.
We have two integers: A and B.
Print the largest number among A + B, A - B, and A \times B.
-----Constraints-----
- All values in input are integers.
- -100 \leq A,\ B \leq 100
-----Input-----
Input is given from Standard Input in the following format:
A B
-----Output-----
Print the largest number among A + B, A - B, and A \times B.
-----Sample Input-----
-13 3
-----Sample Output-----
-10
The largest number among A + B = -10, A - B = -16, and A \times B = -39 is -10.
|
{"inputs": ["0 0\n", "13 3\n", "91 0\n", "0 15\n", "10 1\n", "-13 3\n", "1 -33\n", "36 80\n"], "outputs": ["0\n", "39\n", "91\n", "15\n", "11\n", "-10\n", "34\n", "2880\n"]}
| 162
| 103
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a set of elements (integers or string characters) that may occur more than once, we need to know the amount of subsets that none of their values have repetitions.
Let's see with an example:
```
set numbers = {1, 2, 3, 4}
```
The subsets are:
```
{{1}, {2}, {3}, {4}, {1,2}, {1,3}, {1,4}, {2,3}, {2,4},{3,4}, {1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}, {1,2,3,4}} (15 subsets, as you can see the empty set, {}, is not counted)
```
Let's see an example with repetitions of an element:
```
set letters= {a, b, c, d, d}
```
The subsets for this case will be:
```
{{a}, {b}, {c}, {d}, {a,b}, {a,c}, {a,d}, {b,c}, {b,d},{c,d}, {a,b,c}, {a,b,d}, {a,c,d}, {b,c,d}, {a,b,c,d}} (15 subsets, only the ones that have no repeated elements inside)
```
The function ```est_subsets()``` (javascript: ``estSubsets()```) will calculate the number of these subsets.
It will receive the array as an argument and according to its features will output the amount of different subsets without repetitions of its elements.
```python
est_subsets([1, 2, 3, 4]) == 15
est_subsets(['a', 'b', 'c', 'd', 'd']) == 15
```
Features of the random tests:
```
Low Performance Tests: 40
Length of the arrays between 6 and 15
High Performance Tests: 80
Length of the arrays between 15 and 100 (Python an Ruby) and between 15 and 50 javascript)
```
Just do it!
Also feel free to reuse/extend the following starter code:
```python
def est_subsets(arr):
```
|
{"functional": "_inputs = [[[1, 2, 3, 4]], [['a', 'b', 'c', 'd', 'd']]]\n_outputs = [[15], [15]]\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(est_subsets(*i), o[0])"}
| 488
| 185
|
coding
|
Solve the programming task below in a Python markdown code block.
Your Goal is to create a function that takes two strings, a guess and a phone number.
Based on the guess, the function should display a portion of the phone number:
guess_my_number('052', '123-451-2345')
would return the string: '#2#-#5#-2##5'
or
guess_my_number('142', '123-451-2345')
would return the string: '12#-4#1-2#4#'
Order of the guess string should not matter, and should not have duplicates of the ten digitis 0-9. Guess will never be an empty string or contains any other charachters. The phone number will always bea ten digit number in the format ###-###-####.
The default number of 123-451-2345 should be included, but can be overwriten by a different number if supplied at the time of execution.
Also feel free to reuse/extend the following starter code:
```python
def guess_my_number(guess, number = '123-451-2345'):
```
|
{"functional": "_inputs = [['0'], ['01'], ['012'], ['0123'], ['01234'], ['012345']]\n_outputs = [['###-###-####'], ['1##-##1-####'], ['12#-##1-2###'], ['123-##1-23##'], ['123-4#1-234#'], ['123-451-2345']]\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(guess_my_number(*i), o[0])"}
| 275
| 249
|
coding
|
Solve the programming task below in a Python markdown code block.
You have invented a time-machine which has taken you back to ancient Rome. Caeser is impressed with your programming skills and has appointed you to be the new information security officer.
Caeser has ordered you to write a Caeser cipher to prevent Asterix and Obelix from reading his emails.
A Caeser cipher shifts the letters in a message by the value dictated by the encryption key. Since Caeser's emails are very important, he wants all encryptions to have upper-case output, for example:
If key = 3
"hello" -> KHOOR
If key = 7
"hello" -> OLSSV
Input will consist of the message to be encrypted and the encryption key.
Also feel free to reuse/extend the following starter code:
```python
def caeser(message, key):
```
|
{"functional": "_inputs = [['This is a message', 0], ['who are you?', 18], ['..5tyu..', 25], ['..#$%^..', 0], ['..#$%^..', 26], ['final one', 9]]\n_outputs = [['THIS IS A MESSAGE'], ['OZG SJW QGM?'], ['..5SXT..'], ['..#$%^..'], ['..#$%^..'], ['ORWJU XWN']]\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(caeser(*i), o[0])"}
| 185
| 247
|
coding
|
Solve the programming task below in a Python markdown code block.
Zombies have placed themselves at every junction in Bucharest. Each junction 'i' initially has a presence of ai number of zombies. Every timestep, each zombie randomly chooses one of its neighboring junctions and walks towards it. Each neighboring junction is choosen by the zombie with an equal probability. In order to safegaurd the citizens of Bucharest we need to find out the expected number of zombies at every junction after 'k' timesteps.
The network of Bucharest is given as an edge list.
Input Format
t - the number of test cases. 't' cases follow.
n, m, k - 'n' junctions (nodes) in Bucharest, 'm' roads (edges) and 'k' time steps.
This is followed by m lines containing 1 edge on each line. Each edge is denoted by 2 integers representing the nodes it connects, which can range from 0 to n-1. All the edges are bidirectional. A node cannot connect itself.
This is followed by n lines, where the i^{th} line contains the initial number of Zombies at the location ai.
Output Format
Output the number of zombies (rounded of to its nearest integer) in the 5 most highly populated junctions after 'k' timesteps.
Constraints
1<=t<=5
5<=n<=100000
1<=m<= 200000
1<=k<=10000000
1<=ai<=1000
Sample Input
1
10 18 100
0 8
0 5
1 2
1 5
2 8
2 4
2 5
2 6
3 5
4 8
4 6
4 7
5 8
5 9
6 8
6 9
7 9
8 9
1
1
1
1
1
1
1
1
1
1
Sample Output
2 2 1 1 1
|
{"inputs": ["1\n10 18 100\n0 8\n0 5\n1 2\n1 5\n2 8\n2 4\n2 5\n2 6\n3 5\n4 8\n4 6\n4 7\n5 8\n5 9\n6 8\n6 9\n7 9\n8 9\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"], "outputs": ["2 2 1 1 1\n"]}
| 451
| 124
|
coding
|
Solve the programming task below in a Python markdown code block.
Watson gives a circle and a triangle in a 2-dimensional plane to Sherlock. Sherlock has to tell if they intersect/touch each other.
The circle is centered at $(x_c,y_c)$ and has radius $\mbox{R}$.
Input Format
The first line contains $\mathbf{T}$, the number of test cases.
Each test case consists of $x_c$, $\boldsymbol{y}_{c}$ and $\mbox{R}$ in one line.
The next three lines each contains $x_i,y_i$ denoting the vertices of the triangle.
Output Format
For each test case, print YES if the triangle touches or intersects the circle; otherwise, print NO.
Constraints
$1\leq T\leq30000$
$1\leq R\leq2000$
$-2000\leq x_c,y_c\leq2000$
$-5000\leq x_i,y_i\leq5000$
Note: There will be no degenerate triangles (i.e. triangles with area 0)
Sample Input
2
0 0 10
10 0
15 0
15 5
0 0 10
0 0
5 0
5 5
Sample Output
YES
NO
Explanation
In the first case, the triangle is touching the circle. In the second case, it neither touches nor intersects the circle.
|
{"inputs": ["2\n0 0 10\n10 0\n15 0\n15 5\n0 0 10\n0 0\n5 0\n5 5\n"], "outputs": ["YES\nNO\n"]}
| 337
| 57
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.
Please complete the following python code precisely:
```python
class Solution:
def tilingRectangle(self, n: int, m: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 2, m = 3) == 3\n assert candidate(n = 5, m = 8) == 5\n assert candidate(n = 11, m = 13) == 6\n\n\ncheck(Solution().tilingRectangle)"}
| 74
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
We have an integer array with unique elements and we want to do the permutations that have an element fixed, in other words, these permutations should have a certain element at the same position than the original.
These permutations will be called: **permutations with one fixed point**.
Let's see an example with an array of four elements and we want the permutations that have a coincidence **only at index 0**, so these permutations are (the permutations between parenthesis):
```
arr = [1, 2, 3, 4]
(1, 3, 4, 2)
(1, 4, 2, 3)
Two permutations matching with arr only at index 0
```
Let's see the permutations of the same array with only one coincidence at index **1**:
```
arr = [1, 2, 3, 4]
(3, 2, 4, 1)
(4, 2, 1, 3)
Two permutations matching with arr only at index 1
```
Once again, let's see the permutations of the same array with only one coincidence at index **2**:
```
arr = [1, 2, 3, 4]
(2, 4, 3, 1)
(4, 1, 3, 2)
Two permutations matching with arr only at index 2
```
Finally, let's see the permutations of the same array with only one coincidence at index **3**:
```
arr = [1, 2, 3, 4]
(2, 3, 1, 4)
(3, 1, 2, 4)
Two permutations matching with arr only at index 3
```
For this array given above (arr) :
- We conclude that we have 8 permutations with one fixed point (two at each index of arr).
- We may do the same development for our array, `arr`, with two fixed points and we will get `6` permutations.
- There are no permutations with coincidences only at three indexes.
- It's good to know that the amount of permutations with no coincidences at all are `9`. See the kata Shuffle It Up!!
In general:
- When the amount of fixed points is equal to the array length, there is only one permutation, the original array.
- When the amount of fixed points surpasses the length of the array, obvously, there are no permutations at all.
Create a function that receives the length of the array and the number of fixed points and may output the total amount of permutations for these constraints.
Features of the random tests:
```
length of the array = l
number of fixed points = k
10 ≤ k ≤ l ≤ 9000
```
See the example tests!
Enjoy it!!
Ruby versin will be released soon.
#Note: This kata was published previously but in a version not well optimized.
Also feel free to reuse/extend the following starter code:
```python
def fixed_points_perms(n,k):
```
|
{"functional": "_inputs = [[4, 1], [4, 2], [4, 3], [10, 3], [10, 4], [20, 2], [4, 0], [4, 4], [4, 5]]\n_outputs = [[8], [6], [0], [222480], [55650], [447507315596451070], [9], [1], [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(fixed_points_perms(*i), o[0])"}
| 659
| 260
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving in for some time and finally he decided to build the house. The rest is simple: he should choose in which part of the garden to build the house. In the evening he sat at his table and drew the garden’s plan. On the plan the garden is represented as a rectangular checkered field n × m in size divided into squares whose side length is 1. In some squares Vasya marked the trees growing there (one shouldn’t plant the trees too close to each other that’s why one square contains no more than one tree). Vasya wants to find a rectangular land lot a × b squares in size to build a house on, at that the land lot border should go along the lines of the grid that separates the squares. All the trees that grow on the building lot will have to be chopped off. Vasya loves his garden very much, so help him choose the building land lot location so that the number of chopped trees would be as little as possible.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 50) which represent the garden location. The next n lines contain m numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contains two integers a and b (1 ≤ a, b ≤ 50). Note that Vasya can choose for building an a × b rectangle as well a b × a one, i.e. the side of the lot with the length of a can be located as parallel to the garden side with the length of n, as well as parallel to the garden side with the length of m.
Output
Print the minimum number of trees that needs to be chopped off to select a land lot a × b in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either a ≤ n and b ≤ m, or a ≤ m и b ≤ n.
Examples
Input
2 2
1 0
1 1
1 1
Output
0
Input
4 5
0 0 1 0 1
0 1 1 1 0
1 0 1 0 1
1 1 1 1 1
2 3
Output
2
Note
In the second example the upper left square is (1,1) and the lower right is (3,2).
|
{"inputs": ["1 1\n1\n1 1\n", "1 1\n0\n1 1\n", "2 2\n1 1\n1 1\n1 1\n", "2 2\n1 0\n1 1\n1 1\n", "2 3\n1 0 1\n0 1 0\n3 2\n", "3 2\n1 1\n1 1\n1 0\n2 1\n", "2 3\n0 0 1\n0 1 0\n3 2\n", "2 3\n0 0 1\n1 1 0\n3 2\n"], "outputs": ["1", "0", "1\n", "0", "3", "1", "2\n", "3\n"]}
| 606
| 181
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Danya gave integers $a$, $b$ and $n$ to Archi. Archi wants to compare $a^{n}$ and $b^{n}$. Help Archi with this task.
------ 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 and only line of each test case contains three space-separated integers $a$, $b$ and $n$.
------ Output ------
For each test case, print a single line containing one integer: $1$ if $a^{n} > b^{n}$, $2$ if $a^{n} < b^{n}$ or $0$ if $a^{n} = b^{n}$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$|a|, |b| ≤ 10^{9}$
$1 ≤ n ≤ 10^{9}$
----- Sample Input 1 ------
2
3 4 5
-3 2 4
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: $a^{n} = 243$ and $b^{n} = 1024$.
Example case 2: $a^{n} = 81$ and $b^{n} = 16$.
|
{"inputs": ["2\n3 4 5\n-3 2 4"], "outputs": ["2\n1"]}
| 335
| 27
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an equilateral triangle ΔABC with the side BC being the base. Each side of the triangle is of length L. There are L-1 additional points on each of the sides dividing the sides into equal parts of unit lengths. Points on the sides of the triangle are called major points. Joining these points with lines parallel to the sides of ΔABC will produce some more equilateral triangles. The intersection points of these parallel lines are called minor points.
Look at the picture below. It contains
- Major points: A, B, C, P1, P2, Q1, Q3, R1, R4, S1, S2, S3 (note that we consider A, B, C as major points as well)
- Minor points: Q2, R2, R3
- Equilateral triangles ΔP1Q1Q2, ΔQ2S1S3, etc
We consider an equilateral triangle to be valid if
- Each of its vertices is either a major or a minor point, and
- The distance from its base (the base of a triangle is the side parallel to BC) to BC is less than the distance from the other vertex of the triangle (i.e. opposite vertex that doesn't lie on the base of triangle) to BC.
In the figure above, ΔQ2P1P2 is not a valid triangle but ΔQ2R2R3 is a valid triangle.
You will be given L, the length of the original triangle ΔABC. You need to find out the number of valid equilateral triangles with side length exactly K.
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. The description of each testcase follows.
- Each test case has one line containing two space-separated integers: L and K.
-----Output-----
For each testcase, print "Case i: ", and then the answer, where i is the testcase number, 1-indexed.
-----Constraints-----
- 1 ≤ T ≤ 500
- 1 ≤ L, K ≤ 5000
-----Example-----
Input:
2
4 3
4 4
Output:
Case 1: 3
Case 2: 1
-----Explanation-----
The figure presented in the problem description is a triangle with side length 4.
In testcase 1, the valid triangles are ΔAR1R4, ΔP1BS3, ΔP2S1C
In testcase 2, the only valid triangle is ΔABC
|
{"inputs": ["2\n4 3\n4 4"], "outputs": ["Case 1: 3\nCase 2: 1"]}
| 541
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
|
{"inputs": ["1 0\na\n", "1 1\nb\n", "1 0\nb\n", "1 1\na\n", "1 1\na\n", "1 1\nb\n", "1 0\nb\n", "1 0\na\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 276
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Alex is attending a Halloween party with his girlfriend, Silvia. At the party, Silvia spots the corner of an infinite chocolate bar (two dimensional, infinitely long in width and length).
If the chocolate can be served only as 1 x 1 sized pieces and Alex can cut the chocolate bar exactly ${K}$ times, what is the maximum number of chocolate pieces Alex can cut and give Silvia?
Input Format
The first line contains an integer ${T}$, the number of test cases. ${T}$ lines follow.
Each line contains an integer ${K}$.
Output Format
${T}$ lines; each line should contain an integer that denotes the maximum number of pieces that can be obtained for each test case.
Constraints
$1\leq T\leq10$
$2\leq K\leq10^{7}$
Note: Chocolate must be served in 1 x 1 sized pieces. Alex can't relocate any of the pieces, nor can he place any piece on top of another.
Sample Input #00
4
5
6
7
8
Sample Output #00
6
9
12
16
Explanation
The explanation below is for the first two test cases. The rest of them follow a similar logic.
For the first test-case where $K=5$, you need $3$ horizontal and $2$ vertical cuts.
For the second test case, where $K=6$, you need $3$ horizontal and $3$ vertical cuts.
|
{"inputs": ["4\n5\n6\n7\n8\n"], "outputs": ["6\n9\n12\n16\n"]}
| 329
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
Laura really hates people using acronyms in her office and wants to force her colleagues to remove all acronyms before emailing her. She wants you to build a system that will edit out all known acronyms or else will notify the sender if unknown acronyms are present.
Any combination of three or more letters in upper case will be considered an acronym. Acronyms will not be combined with lowercase letters, such as in the case of 'KPIs'. They will be kept isolated as a word/words within a string.
For any string:
All instances of 'KPI' must become "key performance indicators"
All instances of 'EOD' must become "the end of the day"
All instances of 'TBD' must become "to be decided"
All instances of 'WAH' must become "work at home"
All instances of 'IAM' must become "in a meeting"
All instances of 'OOO' must become "out of office"
All instances of 'NRN' must become "no reply necessary"
All instances of 'CTA' must become "call to action"
All instances of 'SWOT' must become "strengths, weaknesses, opportunities and threats"
If there are any unknown acronyms in the string, Laura wants you to return only the message:
'[acronym] is an acronym. I do not like acronyms. Please remove them from your email.'
So if the acronym in question was 'BRB', you would return the string:
'BRB is an acronym. I do not like acronyms. Please remove them from your email.'
If there is more than one unknown acronym in the string, return only the first in your answer.
If all acronyms can be replaced with full words according to the above, however, return only the altered string.
If this is the case, ensure that sentences still start with capital letters. '!' or '?' will not be used.
Also feel free to reuse/extend the following starter code:
```python
def acronym_buster(message):
```
|
{"functional": "_inputs = [['BRB I need to go into a KPI meeting before EOD'], ['I am IAM so will be OOO until EOD'], ['Going to WAH today. NRN. OOO'], [\"We're looking at SMB on SM DMs today\"], ['OOO'], ['KPI'], ['EOD'], ['TBD'], ['TBD by EOD'], ['BRB I am OOO'], ['WAH'], ['IAM'], ['NRN'], ['CTA'], ['Hi PAB'], ['HATDBEA'], ['LDS'], ['PB'], ['FA'], ['CTA and HTTP'], ['SWOT.'], ['HTTP'], ['Please WAH today. KPI on track'], ['The advert needs a CTA. NRN before EOD.'], ['I sent you a RFP yesterday.'], ['My SM account needs some work.']]\n_outputs = [['BRB is an acronym. I do not like acronyms. Please remove them from your email.'], ['I am in a meeting so will be out of office until the end of the day'], ['Going to work at home today. No reply necessary. Out of office'], ['SMB is an acronym. I do not like acronyms. Please remove them from your email.'], ['Out of office'], ['Key performance indicators'], ['The end of the day'], ['To be decided'], ['To be decided by the end of the day'], ['BRB is an acronym. I do not like acronyms. Please remove them from your email.'], ['Work at home'], ['In a meeting'], ['No reply necessary'], ['Call to action'], ['PAB is an acronym. I do not like acronyms. Please remove them from your email.'], ['HATDBEA is an acronym. I do not like acronyms. Please remove them from your email.'], ['LDS is an acronym. I do not like acronyms. Please remove them from your email.'], ['PB'], ['FA'], ['HTTP is an acronym. I do not like acronyms. Please remove them from your email.'], ['Strengths, weaknesses, opportunities and threats.'], ['HTTP is an acronym. I do not like acronyms. Please remove them from your email.'], ['Please work at home today. Key performance indicators on track'], ['The advert needs a call to action. No reply necessary before the end of the day.'], ['RFP is an acronym. I do not like acronyms. Please remove them from your email.'], ['My SM account needs some work.']]\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(acronym_buster(*i), o[0])"}
| 434
| 684
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.
Return true if the circle and rectangle are overlapped otherwise return false. In other words, check if there is any point (xi, yi) that belongs to the circle and the rectangle at the same time.
Please complete the following python code precisely:
```python
class Solution:
def checkOverlap(self, radius: int, xCenter: int, yCenter: int, x1: int, y1: int, x2: int, y2: int) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(radius = 1, xCenter = 0, yCenter = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1) == True\n assert candidate(radius = 1, xCenter = 1, yCenter = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1) == False\n assert candidate(radius = 1, xCenter = 0, yCenter = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1) == True\n\n\ncheck(Solution().checkOverlap)"}
| 192
| 160
|
coding
|
Solve the programming task below in a Python markdown code block.
In 17th century our Chef was a Wizard. He asked his small son "Anshu" to bring him the secret of the Magical Mountain. The boy after travelling a lot reached the Mountain.
The description of the Mountain was as follows:
- Mountain contains N magical stones. Each of them has a unique number.
- Mountain was divided into many levels, where at ith level atmost 2^i stones can be found.
- Between stones there exist a magical path containing lava.
- A stone can be connected with maximum of three stones.
- Peak of the mountain contains stone with number 1.
- If Stone 1 is first connected to stone 2 and then to 3. Assume 2 is to the left of 3.
Now, to get the secret of the mountain, Anshu started climbing from the left. On the way he used his magical wand to protect him from lava. But, while climbing he came to know that he is able to see only the one stone at each level. After reaching the peak he slided down and did the the same process. These stones that he saw shows the secret of the mountain, if they are placed in a non decreasing order on a sunny day. Anshu doesn't remember the stones number that he saw. Help him in recollecting them and getting the secret to his father.
The mountain looks like this
-----Input-----
- First line contains T the number of test cases.
- First line of each test test case contains N.
- Next N-1 lines contains X and Y the stones which are connected.
-----Output-----
- Output the required non decreasing sequence.
-----Constraints and Subtasks-----
- 1 <= T <= 10
- 1 <= X, Y <= N
Subtask 1: 20 points
- 3<=N<=100
Subtask 2: 30 points
- 3<=N<=10000
Subtask 3: 50 points
- 3<=N<=100000
-----Example-----
Input:
1
5
1 2
1 3
2 4
2 5
Output:
1 2 3 4 5
|
{"inputs": ["1\n5\n1 2\n1 3\n2 4\n2 5"], "outputs": ["1 2 3 4 5"]}
| 475
| 38
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a positive integer $N$.
Your task is to print a palindromic triangle of size $N$.
For example, a palindromic triangle of size $5$ is:
1
121
12321
1234321
123454321
You can't take more than two lines. The first line (a for-statement) is already written for you.
You have to complete the code using exactly one print statement.
Note:
Using anything related to strings will give a score of $\mbox{0}$.
Using more than one for-statement will give a score of $\mbox{0}$.
Input Format
A single line of input containing the integer $N$.
Constraints
$0<N<10$
Output Format
Print the palindromic triangle of size $N$ as explained above.
Sample Input
5
Sample Output
1
121
12321
1234321
123454321
|
{"inputs": ["5\n"], "outputs": ["1\n121\n12321\n1234321\n123454321\n"]}
| 245
| 42
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given $n$ one-dimensional segments (each segment is denoted by two integers — its endpoints).
Let's define the function $f(x)$ as the number of segments covering point $x$ (a segment covers the point $x$ if $l \le x \le r$, where $l$ is the left endpoint and $r$ is the right endpoint of the segment).
An integer point $x$ is called ideal if it belongs to more segments than any other integer point, i. e. $f(y) < f(x)$ is true for any other integer point $y$.
You are given an integer $k$. Your task is to determine whether it is possible to remove some (possibly zero) segments, so that the given point $k$ becomes ideal.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le n, k \le 50$).
Then $n$ lines follow, $i$-th line of them contains two integers $l_i$ and $r_i$ ($1 \le l_i, r_i \le 50$; $l_i \le r_i$) — the endpoints of the $i$-th segment.
-----Output-----
For each test case, print YES if it is possible to remove some (possibly zero) segments, so that the given point $k$ becomes ideal, otherwise print NO.
You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
-----Examples-----
Input
4
4 3
1 3
7 9
2 5
3 6
2 9
1 4
3 7
1 3
2 4
3 5
1 4
6 7
5 5
Output
YES
NO
NO
YES
-----Note-----
In the first example, the point $3$ is already ideal (it is covered by three segments), so you don't have to delete anything.
In the fourth example, you can delete everything except the segment $[5, 5]$.
|
{"inputs": ["1\n2 9\n1 4\n3 7\n", "5\n1 4\n5 6\n1 4\n4 4\n1 2\n2 2\n1 1\n1 7\n1 4\n3 4\n", "5\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "5\n1 2\n1 1\n1 3\n2 4\n1 5\n2 6\n2 7\n3 5\n3 6\n1 1\n1 1\n", "4\n4 3\n1 3\n7 9\n2 5\n3 6\n2 9\n1 4\n3 7\n1 3\n2 4\n3 5\n1 4\n6 7\n5 5\n", "9\n4 3\n1 3\n7 9\n2 5\n3 6\n2 9\n1 4\n3 7\n1 3\n2 4\n3 5\n1 4\n6 7\n5 5\n4 3\n1 3\n7 9\n2 5\n3 6\n2 9\n1 4\n3 7\n1 3\n2 4\n3 5\n1 4\n6 7\n5 5\n1 4\n3 7\n"], "outputs": ["NO\n", "NO\nYES\nYES\nNO\nNO\n", "YES\nYES\nYES\nYES\nYES\n", "NO\nNO\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nNO\n"]}
| 502
| 412
|
coding
|
Solve the programming task below in a Python markdown code block.
Find the greatest common divisor of two positive integers. The integers can be large, so you need to find a clever solution.
The inputs `x` and `y` are always greater or equal to 1, so the greatest common divisor will always be an integer that is also greater or equal to 1.
Also feel free to reuse/extend the following starter code:
```python
def mygcd(x,y):
```
|
{"functional": "_inputs = [[1, 3], [60, 12], [2672, 5678], [10927782, 6902514], [1590771464, 1590771620]]\n_outputs = [[1], [12], [334], [846], [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(mygcd(*i), o[0])"}
| 99
| 237
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$.
Chef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink:
- if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour
- otherwise, Chef must sell this customer a drink, but he may choose its flavour
Chef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit.
-----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 each test case contains two space-separated integers $N$ and $M$.
- The second line contains $M$ space-separated integers $C_1, C_2, \ldots, C_M$.
- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$.
-----Output-----
For each test case, print two lines:
- The first of these lines should contain a single integer — the maximum profit.
- The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order.
If there are multiple solutions, you may find any one.
-----Constraints-----
- $1 \le T \le 1,000$
- $2 \le N, M \le 10^5$
- $1 \le D_i \le M$ for each valid $i$
- $1 \le C_i \le N$ for each valid $i$
- $1 \le B_i < F_i \le 10^9$ for each valid $i$
- $C_1+C_2+\ldots+C_M \ge N$
- the sum of $N$ over all test cases does not exceed $10^6$
- the sum of $M$ over all test cases does not exceed $10^6$
-----Example Input-----
1
5 3
1 2 3
2 6 3
2 10 7
2 50 3
1 10 5
1 7 4
-----Example Output-----
33
2 2 3 1 3
|
{"inputs": ["1\n5 3\n1 2 3\n2 6 3\n2 10 7\n2 50 3\n1 10 5\n1 7 4"], "outputs": ["33\n2 2 3 1 3"]}
| 660
| 66
|
coding
|
Solve the programming task below in a Python markdown code block.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
|
{"inputs": ["1\n0\n0\n", "1\n1\n0\n", "1\n1\n1\n", "1\n0\n1\n", "1\n0\n2\n", "1\n0\n4\n", "1\n0\n3\n", "1\n0\n-1\n"], "outputs": ["0\n", "1\n1\n", "0\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n"]}
| 477
| 115
|
coding
|
Solve the programming task below in a Python markdown code block.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer $n$ ($2 \le n \le 10^5$): the number of patty-cakes in it. The second line of the bag description contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of $n$ over all bags does not exceed $10^5$.
-----Output-----
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
-----Example-----
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
-----Note-----
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): $1$, $6$, $4$, $7$, $1$, $6$, $4$ (in this way, the minimum distance is equal to $3$).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): $1$, $4$, $6$, $7$, $4$, $1$, $6$, $4$ (in this way, the minimum distance is equal to $2$).
|
{"inputs": ["1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n", "1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n", "1\n15\n1 2 3 4 5 1 2 3 4 5 2 2 3 4 5\n", "1\n15\n1 2 3 4 5 1 2 3 4 5 2 1 3 4 5\n", "1\n15\n2 2 3 4 5 1 2 3 4 5 2 2 3 4 5\n", "1\n15\n1 2 3 7 5 1 2 3 4 5 1 2 3 4 9\n", "1\n15\n1 2 3 3 3 1 2 3 3 5 2 1 3 6 5\n", "1\n15\n1 2 3 7 5 1 2 3 4 5 1 2 3 4 5\n"], "outputs": ["4\n", "4\n", "3\n", "4\n", "2\n", "5\n", "1\n", "4\n"]}
| 666
| 334
|
coding
|
Solve the programming task below in a Python markdown code block.
Consider integer coordinates x, y in the Cartesian plan and three functions f, g, h
defined by:
```
f: 1 <= x <= n, 1 <= y <= n --> f(x, y) = min(x, y)
g: 1 <= x <= n, 1 <= y <= n --> g(x, y) = max(x, y)
h: 1 <= x <= n, 1 <= y <= n --> h(x, y) = x + y
```
where n is a given integer (n >= 1, guaranteed) and x, y are integers.
In the table below you can see the value of the function f with n = 6.
---|*0* |*1*|*2*|*3*|*4*|*5*|*6*|
-- |--|--|--|--|--|--|--|
*6*|- |1 |2 |3 |4 |5 |6 |
*5*|- |1 |2 |3 |4 |5 |5 |
*4*|- |1 |2 |3 |4 |4 |4 |
*3*|- |1 |2 |3 |3 |3 |3 |
*2*|- |1 |2 |2 |2 |2 |2 |
*1*|- |1 |1 |1 |1 |1 |1 |
*0*|- |- |- |- |- |- |- |
The task is to calculate the sum of f(x, y), g(x, y) and h(x, y) for all integers x and y such that (1 <= x <= n, 1 <= y <= n).
The function sumin (sum of f) will take n as a parameter and return the sum of min(x, y) in the domain 1 <= x <= n, 1 <= y <= n.
The function sumax (sum of g) will take n as a parameter and return the sum of max(x, y) in the same domain.
The function sumsum (sum of h) will take n as a parameter and return the sum of x + y in the same domain.
#Examples:
```
sumin(6) --> 91
sumin(45) --> 31395
sumin(999) --> 332833500
sumin(5000) --> 41679167500
sumax(6) --> 161
sumax(45) --> 61755
sumax(999) --> 665167500
sumax(5000) --> 83345832500
sumsum(6) --> 252
sumsum(45) --> 93150
sumsum(999) --> 998001000
sumsum(5000) --> 125025000000
```
#Hint:
1. Try to avoid nested loops
2. Note that h = f + g
Also feel free to reuse/extend the following starter code:
```python
def sumin(n):
```
|
{"functional": "_inputs = [[5], [6], [8], [15], [100], [365], [730], [4000]]\n_outputs = [[55], [91], [204], [1240], [338350], [16275715], [129938905], [21341334000]]\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(sumin(*i), o[0])"}
| 713
| 243
|
coding
|
Solve the programming task below in a Python markdown code block.
Say hello!
Write a function to greet a person. Function will take name as input and greet the person by saying hello.
Return null/nil/None if input is empty string or null/nil/None.
Example:
```python
greet("Niks") --> "hello Niks!"
greet("") --> None # Return None if input is empty string
greet(None) --> None # Return None if input is None
```
Also feel free to reuse/extend the following starter code:
```python
def greet(name):
```
|
{"functional": "_inputs = [['Niks'], ['Nick'], [''], [None]]\n_outputs = [['hello Niks!'], ['hello Nick!'], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(greet(*i), o[0])"}
| 126
| 177
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree, return the lowest common ancestor of its deepest leaves.
Recall that:
The node of a binary tree is a leaf if and only if it has no children
The depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1.
The lowest common ancestor of a set S of nodes, is the node A with the largest depth such that every node in S is in the subtree with root A.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def lcaDeepestLeaves(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
```
|
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([3,5,1,6,2,0,8,None,None,7,4])), tree_node([2,7,4]))\n assert is_same_tree(candidate(root = tree_node([1])), tree_node([1]))\n assert is_same_tree(candidate(root = tree_node([0,1,3,None,2])), tree_node([2]))\n\n\ncheck(Solution().lcaDeepestLeaves)"}
| 214
| 113
|
coding
|
Solve the programming task below in a Python markdown code block.
Aiz Onsen has a bathhouse and a pool. To use the bathhouse, you need to buy a bathing ticket, and to use the pool, you need to buy a pool ticket. Prices for these tickets may vary from day to day. In addition, Aiz Onsen has the following rules.
* Tickets are valid only once on the day of purchase.
* If you buy 5 or more bathing tickets and 2 or more pool tickets at once, you will get a 20% discount on all tickets.
Sadayoshi, who loves hot springs, and his friends go to Aiz Onsen almost every day. They are all capricious and use different numbers from day to day. Aiz Onsen has discount rules, so if you work together as a group and buy well, you may be able to reduce the total price.
Create a program that outputs the cheapest total price when the bathing ticket and pool ticket charges, the number of bathing tickets to be used and the number of pool tickets are given as inputs. However, if buying more tickets than you use will reduce the total price, you do not have to use all the tickets you bought.
input
The input is given in the following format.
N
x1 y1 b1 p1
x2 y2 b2 p2
::
xN yN bN pN
N (1 ≤ N ≤ 365) on the first line is the number of days for which you want to calculate the charge. In the next N lines, the bathing ticket fee xi (100 ≤ xi ≤ 1000) for the i-day day, the pool ticket fee yi (100 ≤ yi ≤ 1000), the number of bathing tickets used bi (0 ≤ bi ≤ 6), The number of pool tickets to use pi (0 ≤ pi ≤ 6) is given. Both bathing tickets and pool tickets are charged in increments of 50 yen.
output
Print the cheapest total price on one line for each day.
Example
Input
2
100 100 1 1
1000 500 5 2
Output
200
4800
|
{"inputs": ["2\n100 000 1 1\n1000 500 5 2", "2\n100 000 1 1\n1010 500 5 2", "2\n110 000 1 1\n1010 500 5 2", "2\n100 100 1 1\n1000 500 5 2", "2\n110 000 1 2\n1010 500 10 2", "2\n110 000 1 2\n1010 500 17 2", "2\n110 000 2 4\n1010 500 17 2", "2\n110 000 2 4\n0010 500 17 2"], "outputs": ["100\n4800\n", "100\n4840\n", "110\n4840\n", "200\n4800", "110\n8880\n", "110\n14536\n", "220\n14536\n", "220\n936\n"]}
| 475
| 322
|
coding
|
Solve the programming task below in a Python markdown code block.
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Examples
Input
4 2
Output
1/2
Note
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
|
{"inputs": ["6 6\n", "1 4\n", "4 4\n", "3 3\n", "6 4\n", "6 3\n", "5 4\n", "5 6\n"], "outputs": ["1/6\n", "1/2\n", "1/2\n", "2/3\n", "1/6\n", "1/6\n", "1/3\n", "1/6\n"]}
| 386
| 102
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a binary string s and a positive integer k.
You can apply the following operation on the string any number of times:
Choose any substring of size k from s and flip all its characters, that is, turn all 1's into 0's, and all 0's into 1's.
Return the number of distinct strings you can obtain. Since the answer may be too large, return it modulo 109 + 7.
Note that:
A binary string is a string that consists only of the characters 0 and 1.
A substring is a contiguous part of a string.
Please complete the following python code precisely:
```python
class Solution:
def countDistinctStrings(self, s: str, k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"1001\", k = 3) == 4\n assert candidate(s = \"10110\", k = 5) == 2\n\n\ncheck(Solution().countDistinctStrings)"}
| 176
| 61
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Two strings, X and Y, are considered similar if either they are identical or we can make them equivalent by swapping at most two letters (in distinct positions) within the string X.
For example, "tars" and "rats" are similar (swapping at positions 0 and 2), and "rats" and "arts" are similar, but "star" is not similar to "tars", "rats", or "arts".
Together, these form two connected groups by similarity: {"tars", "rats", "arts"} and {"star"}. Notice that "tars" and "arts" are in the same group even though they are not similar. Formally, each group is such that a word is in the group if and only if it is similar to at least one other word in the group.
We are given a list strs of strings where every string in strs is an anagram of every other string in strs. How many groups are there?
Please complete the following python code precisely:
```python
class Solution:
def numSimilarGroups(self, strs: List[str]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(strs = [\"tars\",\"rats\",\"arts\",\"star\"]) == 2\n assert candidate(strs = [\"omv\",\"ovm\"]) == 1\n\n\ncheck(Solution().numSimilarGroups)"}
| 252
| 61
|
coding
|
Solve the programming task below in a Python markdown code block.
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are n warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.
Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
-----Input-----
The first line contains two space-separated integers, n and m (3 ≤ n ≤ 4000, 0 ≤ m ≤ 4000) — respectively number of warriors and number of pairs of warriors knowing each other.
i-th of the following m lines contains two space-separated integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}). Warriors a_{i} and b_{i} know each other. Each pair of warriors will be listed at most once.
-----Output-----
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
-----Examples-----
Input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
Output
2
Input
7 4
2 1
3 6
5 1
1 7
Output
-1
-----Note-----
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other.
|
{"inputs": ["5 0\n", "3 0\n", "3 0\n", "5 0\n", "9 0\n", "10 0\n", "4000 0\n", "4000 0\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 567
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has $N$ dishes of different types arranged in a row: $A_1, A_2, \ldots, A_N$, where $A_i$ denotes the type of the $i^{th}$ dish. He wants to choose as many dishes as possible from the given list but while satisfying two conditions:
- He can choose only one type of dish.
- No two chosen dishes should be adjacent to each other.
Chef wants to know which type of dish he should choose from, so that he can pick the maximum number of dishes.
Example:
Given $N$=$9$ and $A$=$[1, 2, 2, 1, 2, 1, 1, 1, 1]$.
For type 1, Chef can choose at most four dishes. One of the ways to choose four dishes of type 1 is $A_1$, $A_4$, $A_7$ and $A_9$.
For type 2, Chef can choose at most two dishes. One way is to choose $A_3$ and $A_5$.
So in this case, Chef should go for type 1, in which he can pick more dishes.
-----Input:-----
- The first line contains $T$, the number of test cases. Then the test cases follow.
- For each test case, the first line contains a single integer $N$.
- The second line contains $N$ integers $A_1, A_2, \ldots, A_N$.
-----Output:-----
For each test case, print a single line containing one integer ― the type of the dish that Chef should choose from. If there are multiple answers, print the smallest one.
-----Constraints-----
- $1 \le T \le 10^3$
- $1 \le N \le 10^3$
- $1 \le A_i \le 10^3$
- Sum of $N$ over all test cases doesn't exceed $10^4$
-----Sample Input:-----
3
5
1 2 2 1 2
6
1 1 1 1 1 1
8
1 2 2 2 3 4 2 1
-----Sample Output:-----
1
1
2
-----Explanation:-----
Test case 1:
For both type 1 and type 2, Chef can pick at most two dishes. In the case of multiple answers, we pick the smallest one. Hence the answer will be $1$.
Test case 2:
There are only dishes of type 1. So the answer is $1$.
Test case 3:
For type 1, Chef can choose at most two dishes. For type 2, he can choose three dishes. For type 3 and type 4, Chef can choose the only dish available. Hence the maximum is in type 2 and so the answer is $2$.
|
{"inputs": ["3\n5\n1 2 2 1 2\n6\n1 1 1 1 1 1\n8\n1 2 2 2 3 4 2 1"], "outputs": ["1\n1\n2"]}
| 635
| 60
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:
t is a subsequence of the string s.
The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.
Return the length of the longest ideal string.
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.
Note that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.
Please complete the following python code precisely:
```python
class Solution:
def longestIdealString(self, s: str, k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"acfgbd\", k = 2) == 4\n assert candidate(s = \"abcd\", k = 3) == 4\n\n\ncheck(Solution().longestIdealString)"}
| 185
| 57
|
coding
|
Solve the programming task below in a Python markdown code block.
Kabir likes Tara's smile and wants to look at her smile. They are sitting in the class and you are friends with Kabir. You have to place a mirror (point size) in the front wall of the class so that Kabir can have a glimpse of Tara's smile.
Consider the front wall as x-axis . You are given the coordinates of position of Kabir (x1,y1)$(x1,y1)$ and Tara (x2,y2)$(x2,y2)$. Find the position where the mirror should be placed.
-----Input:-----
- First line will contain T$T$, number of testcases. Then the testcases follow.
- First line of each testcase contains two integers x1,y1$x1, y1$.
- Second line of each testcase contains two integers x2,y2$x2, y2$.
-----Output:-----
For each testcase, print the x-coordinate of the mirror. Absolute error of 10−2$10^{−2}$ is allowed.
-----Constraints:-----
- 1≤T≤1000$1 \leq T \leq 1000$
- 1≤x1,y1,x2,y2≤105$1 \leq x1,y1,x2,y2 \leq 10^5 $
-----Sample Input:-----
1
1 1
4 4
-----Sample Output:-----
1.60
|
{"inputs": ["1\n1 1\n4 4"], "outputs": ["1.60"]}
| 321
| 23
|
coding
|
Solve the programming task below in a Python markdown code block.
### Task
King Arthur and his knights are having a New Years party. Last year Lancelot was jealous of Arthur, because Arthur had a date and Lancelot did not, and they started a duel.
To prevent this from happening again, Arthur wants to make sure that there are at least as many women as men at this year's party. He gave you a list of integers of all the party goers.
Arthur needs you to return true if he needs to invite more women or false if he is all set.
### Input/Output
- `[input]` integer array `L` (`$a` in PHP)
An array (guaranteed non-associative in PHP) representing the genders of the attendees, where `-1` represents `women` and `1` represents `men`.
`2 <= L.length <= 50`
- `[output]` a boolean value
`true` if Arthur need to invite more women, `false` otherwise.
Also feel free to reuse/extend the following starter code:
```python
def invite_more_women(arr):
```
|
{"functional": "_inputs = [[[1, -1, 1]], [[-1, -1, -1]], [[1, -1]], [[1, 1, 1]], [[]]]\n_outputs = [[True], [False], [False], [True], [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(invite_more_women(*i), o[0])"}
| 241
| 202
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the ith person.
A Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:
age[y] <= 0.5 * age[x] + 7
age[y] > age[x]
age[y] > 100 && age[x] < 100
Otherwise, x will send a friend request to y.
Note that if x sends a request to y, y will not necessarily send a request to x. Also, a person will not send a friend request to themself.
Return the total number of friend requests made.
Please complete the following python code precisely:
```python
class Solution:
def numFriendRequests(self, ages: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(ages = [16,16]) == 2\n assert candidate(ages = [16,17,18]) == 2\n assert candidate(ages = [20,30,100,110,120]) == 3\n\n\ncheck(Solution().numFriendRequests)"}
| 200
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter long.
#Examples:
````
*Example 1*
SubstringTest("Something","Fun"); //Returns false
*Example 2*
SubstringTest("Something","Home"); //Returns true
````
In the above example, example 2 returns true because both of the inputs contain the substring "me". (so**ME**thing and ho**ME**)
In example 1, the method will return false because something and fun contain no common substrings. (We do not count the 'n' as a substring in this Kata because it is only 1 character long)
#Rules:
Lowercase and uppercase letters are the same. So 'A' == 'a'.
We only count substrings that are > 1 in length.
#Input:
Two strings with both lower and upper cases.
#Output:
A boolean value determining if there is a common substring between the two inputs.
Also feel free to reuse/extend the following starter code:
```python
def substring_test(str1, str2):
```
|
{"functional": "_inputs = [['Something', 'Home'], ['Something', 'Fun'], ['Something', ''], ['', 'Something'], ['BANANA', 'banana'], ['test', 'lllt'], ['', ''], ['1234567', '541265'], ['supercalifragilisticexpialidocious', 'SoundOfItIsAtrocious'], ['LoremipsumdolorsitametconsecteturadipiscingelitAeneannonaliquetligulautplaceratorciSuspendissepotentiMorbivolutpatauctoripsumegetaliquamPhasellusidmagnaelitNullamerostellustemporquismolestieaornarevitaediamNullaaliquamrisusnonviverrasagittisInlaoreetultricespretiumVestibulumegetnullatinciduntsempersemacrutrumfelisPraesentpurusarcutempusnecvariusidultricesaduiPellentesqueultriciesjustolobortisrhoncusdignissimNuncviverraconsequatblanditUtbibendumatlacusactristiqueAliquamimperdietnuncsempertortorefficiturviverra', 'thisisalongstringtest'], ['Codewars is sweet!', 'is']]\n_outputs = [[True], [False], [False], [False], [True], [False], [False], [True], [True], [True], [True]]\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(substring_test(*i), o[0])"}
| 277
| 467
|
coding
|
Solve the programming task below in a Python markdown code block.
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following: if the current length is at least $2$, divide the base into $2$ equal halves and destroy them separately, or burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base. Output the minimum power needed by Thanos to destroy the avengers' base.
-----Input-----
The first line contains four integers $n$, $k$, $A$ and $B$ ($1 \leq n \leq 30$, $1 \leq k \leq 10^5$, $1 \leq A,B \leq 10^4$), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ($1 \leq a_{i} \leq 2^n$), where $a_{i}$ represents the position of avenger in the base.
-----Output-----
Output one integer — the minimum power needed to destroy the avengers base.
-----Examples-----
Input
2 2 1 2
1 3
Output
6
Input
3 2 1 2
1 7
Output
8
-----Note-----
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$.
Otherwise he can divide the base into two parts $1-2$ and $3-4$.
For base $1-2$, he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$.
For base $1-1$, he can burn it with power $2 \cdot 1 \cdot 1 = 2$. For $2-2$, he can destroy it with power $1$, as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$, which is less than $4$.
Similarly, he needs $3$ power to destroy $3-4$. The total minimum power needed is $6$.
|
{"inputs": ["1 1 5 6\n1\n", "1 1 5 6\n1\n", "1 1 7 6\n1\n", "1 1 5 2\n1\n", "1 1 7 0\n1\n", "2 1 5 2\n1\n", "1 1 7 -1\n1\n", "1 1 7 -2\n2\n"], "outputs": ["11\n", "11", "12\n", "4\n", "0\n", "8\n", "-2\n", "-4\n"]}
| 650
| 136
|
coding
|
Solve the programming task below in a Python markdown code block.
Byteburg Senate elections are coming. Usually "United Byteland", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candidate in one of the constituencies. Even one opposition member can disturb the stability in the Senate, so the head of the Party asks you to ensure that the opposition candidate will not be elected.
There are n candidates, numbered from 1 to n. Candidate n is the opposition candidate. There are m polling stations in the constituency, numbered from 1 to m. You know the number of votes cast for each candidate at each polling station. The only thing you can do to prevent the election of the opposition candidate is to cancel the election results at some polling stations. The opposition candidate will be elected if the sum of the votes cast in their favor at all non-canceled stations will be strictly greater than the analogous sum for every other candidate.
Your task is to prevent the election of the opposition candidate by canceling the election results at the minimal possible number of polling stations. Notice that solution always exists, because if you cancel the elections at all polling stations, the number of votes for each candidate will be 0, and the opposition candidate will not be elected.
Input
The first line of the input contains two integers n and m (2≤ n≤ 100; 1≤ m ≤ 100) — the number of candidates and the number of polling stations. The next m lines contain the election results at each polling station with n numbers on each line. In the i-th line the j-th number is a_{i,j} — the number of votes cast for the candidate j at the station i (0≤ a_{i,j} ≤ 1 000).
Output
In the first line output integer k — the minimal number of the polling stations in which you need to cancel the election results. In the second line output k integers — the indices of canceled polling stations, in any order. If there are multiple ways to cancel results at k stations, output any one of them.
Examples
Input
5 3
6 3 4 2 8
3 7 5 6 7
5 2 4 7 9
Output
2
3 1
Input
2 1
1 1
Output
0
Input
3 3
2 3 8
4 2 9
3 1 7
Output
3
1 2 3
Note
In the first example, the candidates from 1 to 5 received 14, 12, 13, 15, and 24 votes correspondingly. The opposition candidate has the most votes. However, if you cancel the election results at the first and the third polling stations, then only the result from the second polling station remains and the vote sums become 3, 7, 5, 6, and 7, without the opposition candidate being in the lead anymore.
|
{"inputs": ["2 1\n0 0\n", "2 1\n1 0\n", "2 1\n2 1\n", "2 1\n1 1\n", "2 1\n1000 1000\n", "2 1\n1000 0000\n", "2 1\n0000 1000\n", "2 1\n0000 0000\n"], "outputs": ["0\n", "0\n\n", "0\n\n", "0\n", "0\n", "0\n\n", "1\n1\n", "0\n\n"]}
| 643
| 148
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef and Chefina are competing against each other in a programming contest. They were both able to solve all the problems in the contest, so the winner between them must be decided by time penalty. Chef solved all the problems in X minutes and made P wrong submissions, while Chefina solved all the problems in Y minutes and made Q wrong submissions. Who won the competition (or was it a draw)?
Note: The time penalty is calculated as follows:
The base time penalty is the time at which the final problem was solved (so, X for Chef and Y for Chefina)
Each wrong submission adds a penalty of 10 minutes
The winner is the person with less penalty time. If they both have the same penalty, it is considered a draw.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains four space-separated integers — X,Y,P, and Q respectively.
------ Output Format ------
For each test case, output a single line containing one string — the name of the winner ("Chef" or "Chefina"), or "Draw" if the match was a draw. Print each string without the quotes.
Each character of the answer can be printed in either uppercase or lowercase, i.e, the strings "Chef", "chEf", "cHeF", etc. are treated as equivalent.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ X,Y ≤ 100$
$0 ≤ P,Q ≤ 100$
----- Sample Input 1 ------
3
10 8 2 3
10 10 10 10
40 21 2 0
----- Sample Output 1 ------
Chef
Draw
Chefina
----- explanation 1 ------
Test Case $1$:
- Chef solved the problems in $10$ minutes and made $2$ wrong submissions, thus his total penalty is $10 + 2 \cdot 10 = 30$ minutes.
- Chefina solved the problems in $8$ minutes and made $3$ wrong submissions, thus her total penalty is $8 + 3 \cdot 10 = 38$ minutes.
Chef took less time, so he is the winner.
Test Case $2$:
- Chef solved the problems in $10$ minutes and made $10$ wrong submissions, thus his total penalty is $10 + 10 \cdot 10 = 110$ minutes.
- Chefina solved the problems in $10$ minutes and made $3$ wrong submissions, thus her total penalty is $10 + 10 \cdot 10 = 110$ minutes.
Chef and Chefina took the same time, so the match is a draw.
Test Case $3$:
- Chef solved the problems in $40$ minutes and made $2$ wrong submissions, thus his total penalty is $40 + 2 \cdot 10 = 60$ minutes.
- Chefina solved the problems in $21$ minutes and made $0$ wrong submissions, thus her total penalty is $21 + 0 \cdot 10 = 21$ minutes.
Chefina took less time, so she is the winner.
|
{"inputs": ["3\n10 8 2 3\n10 10 10 10\n40 21 2 0\n"], "outputs": ["Chef\nDraw\nChefina"]}
| 721
| 49
|
coding
|
Solve the programming task below in a Python markdown code block.
A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.
This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.
- F : Move in the current direction by distance 1.
- T : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.
-----Constraints-----
- s consists of F and T.
- 1 \leq |s| \leq 8 000
- x and y are integers.
- |x|, |y| \leq |s|
-----Input-----
Input is given from Standard Input in the following format:
s
x y
-----Output-----
If the objective is achievable, print Yes; if it is not, print No.
-----Sample Input-----
FTFFTFFF
4 2
-----Sample Output-----
Yes
The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.
|
{"inputs": ["UF\n1 0", "FT\n1 0", "FF\n2 0", "UF\n0 0", "TF\n1 0", "FF\n1 0", "FF\n1 0\n", "TF\n1 0\n"], "outputs": ["No\n", "Yes\n", "Yes\n", "No\n", "No", "No", "No\n", "No\n"]}
| 265
| 94
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
On a campus represented as a 2D grid, there are n workers and m bikes, with n <= m. Each worker and bike is a 2D coordinate on this grid.
We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.
Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.
The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.
Please complete the following python code precisely:
```python
class Solution:
def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]) == 6\n assert candidate(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]) == 4\n assert candidate(workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]]) == 4995\n\n\ncheck(Solution().assignBikes)"}
| 175
| 155
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.
-----Input-----
First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.
Second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — the numbers in the multiset.
-----Output-----
If it is not possible to select k numbers in the desired way, output «No» (without the quotes).
Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b_1, b_2, ..., b_{k} — the selected numbers. If there are multiple possible solutions, print any of them.
-----Examples-----
Input
3 2 3
1 8 4
Output
Yes
1 4
Input
3 3 3
1 8 4
Output
No
Input
4 3 5
2 7 7 7
Output
Yes
2 7 7
|
{"inputs": ["3 2 3\n1 8 4\n", "3 3 3\n1 8 4\n", "3 2 3\n1 2 3\n", "3 2 2\n1 2 4\n", "3 2 4\n1 2 3\n", "3 3 3\n1 3 6\n", "3 2 3\n1 2 3\n", "3 2 4\n1 2 3\n"], "outputs": ["Yes\n1 4 ", "No", "No", "Yes\n2 4 ", "No", "No", "No\n", "No\n"]}
| 361
| 152
|
coding
|
Solve the programming task below in a Python markdown code block.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer b_{i}.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a_1, at least one with complexity exactly a_2, ..., and at least one with complexity exactly a_{n}. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_1 < a_2 < ... < a_{n} ≤ 10^6) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b_1, b_2, ..., b_{m} (1 ≤ b_1 ≤ b_2... ≤ b_{m} ≤ 10^6) — the complexities of the problems prepared by George.
-----Output-----
Print a single integer — the answer to the problem.
-----Examples-----
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
-----Note-----
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
|
{"inputs": ["3 1\n2 3 4\n1\n", "3 1\n2 3 4\n0\n", "3 1\n2 6 4\n0\n", "3 1\n2 3 4\n1\n", "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 5\n1 0 3\n1 1 1 1 1\n", "3 5\n1 2 3\n1 2 1 3 3\n"], "outputs": ["3\n", "3\n", "3\n", "3\n", "0\n", "2\n", "1\n", "0\n"]}
| 600
| 182
|
coding
|
Solve the programming task below in a Python markdown code block.
Program a function `sumAverage(arr)` where `arr` is an array containing arrays full of numbers, for example:
```python
sum_average([[1, 2, 2, 1], [2, 2, 2, 1]])
```
First, determine the average of each array. Then, return the sum of all the averages.
- All numbers will be less than 100 and greater than -100.
- `arr` will contain a maximum of 50 arrays.
- After calculating all the averages, add them **all** together, **then** round down, as shown in the example below:
The example given: `sumAverage([[3, 4, 1, 3, 5, 1, 4], [21, 54, 33, 21, 77]])`, the answer being 44.
1. Calculate the average of each individual array:
```
[3, 4, 1, 3, 5, 1, 4] = (3 + 4 + 1 + 3 + 5 + 1 + 4) / 7 = 3
[21, 54, 33, 21, 77] = (21 + 54 + 33 + 21 + 77) / 5 = 41.2
```
2. Add the average of each array together:
```
3 + 41.2 = 44.2
```
3. Round the final average down:
~~~if:julia
In Julia, the `Statistics` package is preloaded.
~~~
```python
import math
math.floor(44.2) = 44
```
Also feel free to reuse/extend the following starter code:
```python
def sum_average(arr):
```
|
{"functional": "_inputs = [[[[1, 2, 2, 1], [2, 2, 2, 1]]], [[[52, 64, 84, 21, 54], [44, 87, 46, 90, 43]]], [[[44, 76, 12], [96, 12, 34, 53, 76, 34, 56, 86, 21], [34, 65, 34, 76, 34, 87, 34]]], [[[41, 16, 99, 93, 59, 18, 35, 23, 55, 45, 38, 39, 74, 60, 95, 44, 59, 70, 44, 89, 90, 19, 23, 67, 65, 66, 41, 89, 49, 22, 23, 47, 60, 12, 59, 58, 25, 69, 66, 82, 53, 41, 51, 69, 78, 18, 17, 44, 74, 96, 46, 73, 22, 37, 95, 32, 62, 49, 8, 88, 59, 66, 23, 10, 61, 28, 11, 99, 27, 98, 8, 18, 73, 18, 61, 25, 60, 38, 81, 13, 36, 63, 12, 83, 57, 11, 19, 51, 41, 20, 37, 63, 79, 94, 25, 45, 24, 73, 67, 42]]], [[[3, 4, 1, 3, 5, 1, 4], [21, 54, 33, 21, 76]]], [[[-4, 3, -8, -2], [2, 9, 1, -5], [-7, -2, -6, -4]]]]\n_outputs = [[3], [117], [148], [50], [44], [-6]]\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_average(*i), o[0])"}
| 416
| 795
|
coding
|
Solve the programming task below in a Python markdown code block.
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.
Iahub asks Iahubina: can you build a rooted tree, such that
* each internal node (a node with at least one son) has at least two sons;
* node i has ci nodes in its subtree?
Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain n nodes.
Input
The first line of the input contains integer n (1 ≤ n ≤ 24). Next line contains n positive integers: the i-th number represents ci (1 ≤ ci ≤ n).
Output
Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).
Examples
Input
4
1 1 1 4
Output
YES
Input
5
1 1 5 2 1
Output
NO
|
{"inputs": ["1\n1\n", "2\n1 2\n", "2\n2 2\n", "2\n2 3\n", "2\n2 1\n", "4\n1 1 1 3\n", "4\n1 2 1 4\n", "4\n1 1 1 2\n"], "outputs": ["YES", "NO", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 318
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length $n$ consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard; otherwise the statement is easy. For example, hard, hzazrzd, haaaaard can be considered hard statements, while har, hart and drah are easy statements.
Vasya doesn't want the statement to be hard. He may remove some characters from the statement in order to make it easy. But, of course, some parts of the statement can be crucial to understanding. Initially the ambiguity of the statement is $0$, and removing $i$-th character increases the ambiguity by $a_i$ (the index of each character is considered as it was in the original statement, so, for example, if you delete character r from hard, and then character d, the index of d is still $4$ even though you delete it from the string had).
Vasya wants to calculate the minimum ambiguity of the statement, if he removes some characters (possibly zero) so that the statement is easy. Help him to do it!
Recall that subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 10^5$) — the length of the statement.
The second line contains one string $s$ of length $n$, consisting of lowercase Latin letters — the statement written by Vasya.
The third line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 998244353$).
-----Output-----
Print minimum possible ambiguity of the statement after Vasya deletes some (possibly zero) characters so the resulting statement is easy.
-----Examples-----
Input
6
hhardh
3 2 9 11 7 1
Output
5
Input
8
hhzarwde
3 2 6 9 4 8 7 1
Output
4
Input
6
hhaarr
1 2 3 4 5 6
Output
0
-----Note-----
In the first example, first two characters are removed so the result is ardh.
In the second example, $5$-th character is removed so the result is hhzawde.
In the third example there's no need to remove anything.
|
{"inputs": ["3\nxdd\n1 2 3\n", "3\nxdd\n1 2 3\n", "3\nxdd\n2 2 3\n", "3\nxdd\n2 3 3\n", "3\nxdd\n1 3 3\n", "3\nxdd\n1 4 3\n", "3\nxdd\n1 8 3\n", "3\nxdd\n1 8 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 559
| 134
|
coding
|
Solve the programming task below in a Python markdown code block.
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforces^{ω} that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
-----Input-----
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
-----Output-----
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
-----Examples-----
Input
CODEWAITFORITFORCES
Output
YES
Input
BOTTOMCODER
Output
NO
Input
DECODEFORCES
Output
YES
Input
DOGEFORCES
Output
NO
|
{"inputs": ["C\n", "C\n", "D\n", "B\n", "ABACABA\n", "ABACABA\n", "AABCABA\n", "CODEFORCE\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 427
| 77
|
coding
|
Solve the programming task below in a Python markdown code block.
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only one programmer — Alex — managed to decode them. The code was so complicated that Alex needed four weeks to decode it. Right after the decoding process was finished, all the files were deleted. But after the files deletion, Alex noticed that he saved the recordings in format «[time]: message». So, information about the dates was lost. However, as the lines were added into the log in chronological order, it's not difficult to say if the recordings could appear during one day or not. It is possible also to find the minimum amount of days during which the log was written.
So, to make up for his mistake Alex has to find the minimum amount of days covered by the log. Note that Alex doesn't have to find the minimum amount of days between the beginning and the end of the logging, he has to find the minimum amount of dates in which records could be done. (See Sample test 2 for further clarifications).
We should remind you that the process made not more than 10 recordings in a minute. Consider that a midnight belongs to coming day.
Input
The first input line contains number n (1 ≤ n ≤ 100). The following n lines contain recordings in format «[time]: message», where time is given in format «hh:mm x.m.». For hh two-digit numbers from 01 to 12 are used, for mm two-digit numbers from 00 to 59 are used, and x is either character «a» or character «p». A message is a non-empty sequence of Latin letters and/or spaces, it doesn't start or end with a space. The length of each message doesn't exceed 20.
Output
Output one number — the minimum amount of days covered by the log.
Examples
Input
5
[05:00 a.m.]: Server is started
[05:00 a.m.]: Rescan initialized
[01:13 p.m.]: Request processed
[01:10 p.m.]: Request processed
[11:40 p.m.]: Rescan completed
Output
2
Input
3
[09:00 a.m.]: User logged in
[08:00 a.m.]: User logged in
[07:00 a.m.]: User logged in
Output
3
Note
Formally the 12-hour time format is described at:
* http://en.wikipedia.org/wiki/12-hour_clock.
The problem authors recommend you to look through these descriptions before you start with the problem.
|
{"inputs": ["1\n[12:00 a.m.]: asZv MF\n", "1\n[10:41 a.m.]: apppmama\n", "1\n[10:41 a.m.]9 apppmama\n", "2\n[06:00 p.m.]: uNzO VN Nz h\n[06:00 a.m.]: bTJv\n", "2\n[11:35 a.m.]: ampapaammaamamaam\n[11:35 a.m.]: ppammpmmppmam\n", "3\n[05:33 p.m.]: apm\n[05:24 p.m.]: mapammmapaaa\n[06:01 p.m.]: mpmmmpa\n", "3\n[05:33 p.m.]: mpa\n[05:24 p.m.]: mapammmapaaa\n[06:01 p.m.]: mpmmmpa\n", "3\n[05:33 p.m.]: apm\n[05:24 p.m.]: aaapammmapam\n[06:01 p.m.]: mpmmmpa\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "2\n"]}
| 625
| 311
|
coding
|
Solve the programming task below in a Python markdown code block.
Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consisting entirely of broken pixels. She knows that q pixels are already broken, and for each of them she knows the moment when it stopped working. Help Luba to determine when the monitor became broken (or tell that it's still not broken even after all q pixels stopped working).
-----Input-----
The first line contains four integer numbers n, m, k, q (1 ≤ n, m ≤ 500, 1 ≤ k ≤ min(n, m), 0 ≤ q ≤ n·m) — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels.
Each of next q lines contain three integer numbers x_{i}, y_{i}, t_{i} (1 ≤ x_{i} ≤ n, 1 ≤ y_{i} ≤ m, 0 ≤ t_{ ≤ 10}^9) — coordinates of i-th broken pixel (its row and column in matrix) and the moment it stopped working. Each pixel is listed at most once.
We consider that pixel is already broken at moment t_{i}.
-----Output-----
Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these q pixels stopped working.
-----Examples-----
Input
2 3 2 5
2 1 8
2 2 8
1 2 1
1 3 4
2 3 2
Output
8
Input
3 3 2 5
1 2 2
2 2 1
2 3 5
3 2 10
2 1 100
Output
-1
|
{"inputs": ["1 1 1 0\n", "1 1 1 0\n", "1 2 1 0\n", "1 2 2 0\n", "1 4 1 0\n", "1 4 2 0\n", "500 24 2 0\n", "500 24 4 0\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 432
| 125
|
coding
|
Solve the programming task below in a Python markdown code block.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
-----Input-----
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens p_{i} and c_{i} (p_{i} is an integer, 1 ≤ p_{i} ≤ 10^9, c_{i} is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
-----Output-----
Print a single integer, the minimum cost way to solve the problem.
-----Examples-----
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
-----Note-----
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
|
{"inputs": ["1\n3 R\n", "1\n3 R\n", "1\n2 R\n", "1\n4 R\n", "1\n5 R\n", "1\n1 R\n", "1\n6 R\n", "1\n0 R\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 453
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
|
{"inputs": ["1\n2\n1 7\n", "1\n2\n2 7\n", "1\n2\n3 7\n", "1\n2\n2 3\n", "1\n2\n4 7\n", "1\n2\n5 7\n", "1\n2\n3 3\n", "1\n2\n3 6\n"], "outputs": ["T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "HL\n", "T\n"]}
| 362
| 118
|
coding
|
Solve the programming task below in a Python markdown code block.
Story
Jumbo Juice makes a fresh juice out of fruits of your choice.Jumbo Juice charges $5 for regular fruits and $7 for special ones. Regular fruits are Banana, Orange, Apple, Lemon and Grapes. Special ones are Avocado, Strawberry and Mango. Others fruits that are not listed are also available upon request. Those extra special fruits cost $9 per each. There is no limit on how many fruits she/he picks.The price of a cup of juice is the mean of price of chosen fruits. In case of decimal number (ex. $5.99), output should be the nearest integer (use the standard rounding function of your language of choice).
Input
The function will receive an array of strings, each with the name of a fruit. The recognition of names should be case insensitive. There is no case of an enmpty array input.
Example
```
['Mango', 'Banana', 'Avocado'] //the price of this juice bottle is (7+5+7)/3 = $6($6.333333...)
```
Also feel free to reuse/extend the following starter code:
```python
def mix_fruit(arr):
```
|
{"functional": "_inputs = [[['banana', 'mango', 'avocado']], [['melon', 'Mango', 'kiwi']], [['watermelon', 'cherry', 'avocado']], [['watermelon', 'lime', 'tomato']], [['blackBerry', 'coconut', 'avocado']], [['waterMelon', 'mango']], [['watermelon', 'pEach']], [['watermelon', 'Orange', 'grapes']], [['watermelon']], [['BlACKbeRrY', 'cOcONuT', 'avoCaDo']]]\n_outputs = [[6], [8], [8], [9], [8], [8], [9], [6], [9], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\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(mix_fruit(*i), o[0])"}
| 260
| 292
|
coding
|
Solve the programming task below in a Python markdown code block.
The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1101_2, so it has 3 bits set and 13 will be reduced to 3 in one operation.
He calls a number special if the minimum number of operations to reduce it to 1 is k.
He wants to find out how many special numbers exist which are not greater than n. Please help the Travelling Salesman, as he is about to reach his destination!
Since the answer can be large, output it modulo 10^9 + 7.
-----Input-----
The first line contains integer n (1 ≤ n < 2^1000).
The second line contains integer k (0 ≤ k ≤ 1000).
Note that n is given in its binary representation without any leading zeros.
-----Output-----
Output a single integer — the number of special numbers not greater than n, modulo 10^9 + 7.
-----Examples-----
Input
110
2
Output
3
Input
111111011
2
Output
169
-----Note-----
In the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).
|
{"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "10\n0\n", "11\n1\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "1\n"]}
| 380
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. Then T test cases follow.
Each test case is described with a single line containing a string S, the alphanumeric string.
------ Output ------
For each test case, output a single line containing the sum of all the digit characters in that string.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ |S| ≤ 1000, where |S| is the length of the string S.$
----- Sample Input 1 ------
1
ab1231da
----- Sample Output 1 ------
7
----- explanation 1 ------
The digits in this string are 1, 2, 3 and 1. Hence, the sum of all of them is 7.
|
{"inputs": ["1\nab1231da\n"], "outputs": ["7"]}
| 213
| 20
|
coding
|
Solve the programming task below in a Python markdown code block.
We ask you to select some number of positive integers, and calculate the sum of them.
It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.
Your objective is to make the sum congruent to C modulo B.
Determine whether this is possible.
If the objective is achievable, print YES. Otherwise, print NO.
-----Constraints-----
- 1 ≤ A ≤ 100
- 1 ≤ B ≤ 100
- 0 ≤ C < B
-----Input-----
Input is given from Standard Input in the following format:
A B C
-----Output-----
Print YES or NO.
-----Sample Input-----
7 5 1
-----Sample Output-----
YES
For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.
|
{"inputs": ["7 5 0", "2 2 0", "2 4 0", "4 5 1", "2 3 0", "4 4 0", "0 9 0", "4 5 0"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
| 218
| 94
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an array $A$ of size $N$ , count number of pairs of index $i,j$ such that $A_i$ is even, $A_j$ is odd and $i < j$
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases.
- The first line of each test case contains integer $N$.
- The second line of each test case contains $N$ space separated integers $A_i$.
-----Output-----
For each test case, print a single line containing an integer denoting number of pairs.
-----Constraints-----
- $1 \le T \le 100$
- $2 \le N \le 10^5$
- $1 \le A_i \le 10^9$
- Sum of $N$ over all test cases doesn't exceed $10^6 $
-----Subtasks-----
Subtask #1 (30 points):
- $2 \le N \le 100$
Subtask #2 (70 points): original constraints
-----Example Input-----
2
4
1 2 1 3
5
5 4 1 2 3
-----Example Output-----
2
3
-----Explanation-----
Example case 1:$(A_2,A_3)$ and $(A_2,A_4)$ .
Example case 2:$(A_2,A_3)$ , $(A_2,A_5)$ and $(A_4,A_5)$ .
|
{"inputs": ["2\n4\n1 2 1 3\n5\n5 4 1 2 3"], "outputs": ["2\n3"]}
| 338
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
The weight of a sequence is defined as the number of unordered pairs of indexes $(i,j)$ (here $i \lt j$) with same value ($a_{i} = a_{j}$). For example, the weight of sequence $a = [1, 1, 2, 2, 1]$ is $4$. The set of unordered pairs of indexes with same value are $(1, 2)$, $(1, 5)$, $(2, 5)$, and $(3, 4)$.
You are given a sequence $a$ of $n$ integers. Print the sum of the weight of all subsegments of $a$.
A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$).
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
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 integer — the sum of the weight of all subsegments of $a$.
-----Examples-----
Input
2
4
1 2 1 1
4
1 2 3 4
Output
6
0
-----Note-----
In test case $1$, all possible subsegments of sequence $[1, 2, 1, 1]$ having size more than $1$ are:
$[1, 2]$ having $0$ valid unordered pairs;
$[2, 1]$ having $0$ valid unordered pairs;
$[1, 1]$ having $1$ valid unordered pair;
$[1, 2, 1]$ having $1$ valid unordered pairs;
$[2, 1, 1]$ having $1$ valid unordered pair;
$[1, 2, 1, 1]$ having $3$ valid unordered pairs.
Answer is $6$.
In test case $2$, all elements of the sequence are distinct. So, there is no valid unordered pair with the same value for any subarray. Answer is $0$.
|
{"inputs": ["2\n4\n1 2 1 1\n4\n1 2 3 4\n", "2\n4\n1 2 2 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 1\n4\n1 2 3 4\n", "2\n4\n2 2 1 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 1\n4\n1 3 3 4\n", "2\n4\n1 2 2 1\n4\n1 4 3 4\n", "2\n4\n2 2 4 1\n4\n1 2 3 4\n", "2\n4\n2 2 2 2\n4\n1 3 3 4\n"], "outputs": ["6\n0\n", "5\n0\n", "9\n0\n", "6\n0\n", "9\n4\n", "5\n2\n", "3\n0\n", "15\n4\n"]}
| 587
| 247
|
coding
|
Solve the programming task below in a Python markdown code block.
Find the length between 2 co-ordinates. The co-ordinates are made of integers between -20 and 20 and will be given in the form of a 2D array:
(0,0) and (5,-7) would be [ [ 0 , 0 ] , [ 5, -7 ] ]
The function must return the answer rounded to 2 decimal places in the form of a string.
```python
length_of_line([[0, 0], [5, -7]]) => "8.60"
```
If the 2 given co-ordinates are the same, the returned length should be "0.00"
Also feel free to reuse/extend the following starter code:
```python
def length_of_line(array):
```
|
{"functional": "_inputs = [[[[0, 0], [1, 1]]], [[[0, 0], [-5, -6]]], [[[0, 0], [10, 15]]], [[[0, 0], [5, 1]]], [[[0, 0], [5, 4]]], [[[0, 0], [-7, 4]]], [[[0, 0], [0, 0]]], [[[-3, 4], [10, 5]]]]\n_outputs = [['1.41'], ['7.81'], ['18.03'], ['5.10'], ['6.40'], ['8.06'], ['0.00'], ['13.04']]\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(length_of_line(*i), o[0])"}
| 175
| 308
|
coding
|
Solve the programming task below in a Python markdown code block.
Omy and Ish were learning the pattern printing. In order to learn they give themselves a task. In this task they are given a string and they have to form a pyramid with the pattern as follows:
RowNumber are one based indexed.
-
If (RowNumber % 3 == 0) then string is written in left to right while in other cases it is written in right to left order.
-
if the string end it will be started again and end of the pyramid need not to be the end of string.
For eg: string is “$CODING$” and height of pyramid is “$5$”
C
D O
I N G
I D O C
D O C G N
Omi will be asked $Q$ queries and he has to tell the frequency of a character C in that particular row $R$ of pyramid.
-----Input:-----
- First line will contain $N$, height of pyramid.
- Next line contain a string consists only of Uppercase English Alphabets, length not exceed $10^6$
- Third line contain a single integer $Q$, the number of queries to be asked.
- Each query contain two space separated integers, $R$ and $C$, where $R$ is the row number and $C$ is the character.
-----Output:-----
- For each query, output in a single line the frequency of the alphabet in the given row.
-----Constraints:-----
- $1$ $\leq$ $N$ $\leq$ $10$^$18$
- $1$ $\leq$ $Q$ $\leq$ $50000$
- $1 \leq R \leq N$
- $A \leq C \leq Z$
-----Sample Input:-----
5
CODING
2
1 C
2 D
-----Sample Output:-----
1
1
|
{"inputs": ["5\nCODING\n2\n1 C\n2 D"], "outputs": ["1\n1"]}
| 410
| 25
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Russian here
Polo, the Penguin, likes the XOR operation. Please read NOTE if you are not familiar with XOR operation.
XOR-sum of a list of numbers is the result of XOR-ing all of them. XOR-sum of (A[1] XOR A[2] XOR ... XOR A[N]) is defined as A[1] XOR (A[2] XOR (A[3] XOR ( ... XOR A[N]))).
Apart of that, Polo, the Penguin, likes trees. He has a weighted tree consisting of N vertices.
He also likes to choose some pair of vertices U and V and find XOR-sum of all weights on the simple path from U to V. Help him to find the maximal number he can get .
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of vertices in the tree. The next N-1 lines contain description of edges of the tree, one edge per line in format U[i] V[i] W[i], where U[i] and V[i] are the indices of the vertices of edge and W[i] is the weight of the edge. Vertices are numbered from 1 to N, inclusive.
------ Output ------
For each test case, output a single line containing the answer to the corresponding test case.
------ Constraints ------
$1 ≤ T ≤ 7$
$1 ≤ N ≤ 100,000$
$0 ≤ W[i] ≤ 1,000,000,000 $
------ Example ------
Input:
2
3
1 2 3
3 1 2
4
1 2 2
1 3 2
4 3 1
Output:
3
3
------ Explanation ------
Example case 1. In this case there are tree ways to choose pair of vertices:
$(1, 2): The only edge you path is edge (1, 2) with weight 3. The XOR-sum is simply 3.$
$(1, 3): The only edge you path is edge (1, 3) with weight 2. The XOR-sum is simply 2.$
$(2, 3): There are two edges on the path in this case: (2, 1) and (1, 3) with weights 3 and 2, respectively. The XOR-sum is 3 XOR 2 = 1.$
So the maximal value Polo can get is 3.
Example case 2. If Polo chooses vertices 1 and 4, then the XOR-sum is equal to 2 XOR 1 = 3. This is the maximal value he can get in this case.
------ NOTE ------
XOR operation is a bitwise "Exclusive OR" operation performed on two integers in binary representation. First, the shorter number is prepended with leading zeroes until the numbers have equal size in binary. Then the resulting number (also in binary) contains 0 in all positions where the corresponding bits coincide, and 1 on the rest of the positions.
For example, 3 XOR 5 = 011_{2} XOR 101_{2} = 110_{2} = 6.
|
{"inputs": ["2\n3\n1 2 3\n3 1 2\n4\n1 2 2\n1 3 2\n4 3 1"], "outputs": ["3\n3"]}
| 716
| 48
|
coding
|
Solve the programming task below in a Python markdown code block.
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with the $r$-th character as $s[l \dots r]$. The characters of each string are numbered from $1$.
We can perform several operations on the strings we consider. Each operation is to choose a substring of our string and replace it with another string. There are two possible types of operations: replace 011 with 110, or replace 110 with 011. For example, if we apply exactly one operation to the string 110011110, it can be transformed into 011011110, 110110110, or 110011011.
Binary string $a$ is considered reachable from binary string $b$ if there exists a sequence $s_1$, $s_2$, ..., $s_k$ such that $s_1 = a$, $s_k = b$, and for every $i \in [1, k - 1]$, $s_i$ can be transformed into $s_{i + 1}$ using exactly one operation. Note that $k$ can be equal to $1$, i. e., every string is reachable from itself.
You are given a string $t$ and $q$ queries to it. Each query consists of three integers $l_1$, $l_2$ and $len$. To answer each query, you have to determine whether $t[l_1 \dots l_1 + len - 1]$ is reachable from $t[l_2 \dots l_2 + len - 1]$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of string $t$.
The second line contains one string $t$ ($|t| = n$). Each character of $t$ is either 0 or 1.
The third line contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries.
Then $q$ lines follow, each line represents a query. The $i$-th line contains three integers $l_1$, $l_2$ and $len$ ($1 \le l_1, l_2 \le |t|$, $1 \le len \le |t| - \max(l_1, l_2) + 1$) for the $i$-th query.
-----Output-----
For each query, print either YES if $t[l_1 \dots l_1 + len - 1]$ is reachable from $t[l_2 \dots l_2 + len - 1]$, or NO otherwise. You may print each letter in any register.
-----Example-----
Input
5
11011
3
1 3 3
1 4 2
1 2 3
Output
Yes
Yes
No
|
{"inputs": ["1\n0\n1\n1 1 1\n", "1\n0\n1\n1 1 1\n", "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n", "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n", "5\n00010\n5\n5 3 1\n2 1 2\n4 1 1\n3 1 3\n2 1 3\n", "5\n11010\n5\n2 1 4\n3 5 1\n4 2 1\n4 5 1\n2 4 2\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nYes\nNo\n", "Yes\nYes\nNo\n", "Yes\nYes\nNo\n", "Yes\nYes\nNo\n", "Yes\nYes\nNo\nNo\nNo\n", "No\nYes\nYes\nNo\nYes\n"]}
| 714
| 298
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.
The square room has walls of length p and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor.
Given the two integers p and q, return the number of the receptor that the ray meets first.
The test cases are guaranteed so that the ray will meet a receptor eventually.
Please complete the following python code precisely:
```python
class Solution:
def mirrorReflection(self, p: int, q: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(p = 2, q = 1) == 2\n\n\ncheck(Solution().mirrorReflection)"}
| 161
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored A·B·C hay blocks and stored them in a barn as a rectangular parallelepiped A layers high. Each layer had B rows and each row had C blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (A - 1) × (B - 2) × (C - 2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1 × 1 × 1 blocks and scattered them around the barn. After the theft Sam counted n hay blocks in the barn but he forgot numbers A, B и C.
Given number n, find the minimally possible and maximally possible number of stolen hay blocks.
Input
The only line contains integer n from the problem's statement (1 ≤ n ≤ 109).
Output
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
4
Output
28 41
Input
7
Output
47 65
Input
12
Output
48 105
Note
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks.
|
{"inputs": ["1\n", "6\n", "8\n", "9\n", "2\n", "4\n", "7\n", "96\n"], "outputs": ["17 17\n", "34 57\n", "40 73\n", "41 81\n", "22 25\n", "28 41\n", "47 65\n", "144 777\n"]}
| 728
| 105
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Given the birthdates of two people, find the date when the younger one is exactly half the age of the other.
# Notes
* The dates are given in the format YYYY-MM-DD and are not sorted in any particular order
* Round **down** to the nearest day
* Return the result as a string, like the input dates
Also feel free to reuse/extend the following starter code:
```python
def half_life(person1, person2):
```
|
{"functional": "_inputs = [['1990-12-06', '2000-02-29'], ['2012-03-31', '1990-06-09'], ['1984-08-14', '1990-04-17'], ['2000-06-30', '1978-03-17'], ['1969-12-20', '2000-10-07']]\n_outputs = [['2009-05-24'], ['2034-01-21'], ['1995-12-19'], ['2022-10-14'], ['2031-07-26']]\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(half_life(*i), o[0])"}
| 111
| 329
|
coding
|
Solve the programming task below in a Python markdown code block.
You've got a bunch of textual data with embedded phone numbers. Write a function `area_code()` that finds and returns just the area code portion of the phone number.
```python
>>> message = "The supplier's phone number is (555) 867-5309"
>>> area_code(message)
'555'
```
The returned area code should be a string, not a number.
Every phone number is formatted like in the example, and the only non-alphanumeric characters in the string are apostrophes `'` or the punctuation used in the phone number.
Also feel free to reuse/extend the following starter code:
```python
def area_code(text):
```
|
{"functional": "_inputs = [[\"The supplier's phone number is (555) 867-5309\"], [\"Grae's cell number used to be (123) 456-7890\"], [\"The 102nd district court's fax line is (124) 816-3264\"]]\n_outputs = [['555'], ['123'], ['124']]\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(area_code(*i), o[0])"}
| 156
| 243
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
It’s Chef's birthday. He and his twin have received $N$ gifts in total. The $i$-th gift has a price of $A_{i}$. Each twin wants to keep the most expensive gifts for himself.
The twins take $K$ turns alternately (each has $K$ turns, for $2\cdot K$ turns in total). It is given that $2\cdot K+1 ≤ N$. In a turn, a person may choose one gift. The only exception is the last turn of the twin who moves second, where he gets to choose two gifts instead of one. Assuming they both choose gifts optimally and you can choose who takes the first turn, find the maximum total cost of the gifts that Chef keeps.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains two space-separated integers $N$, $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$, the price of the gifts.
------ Output ------
For each test case, output in a single line the answer to the problem.
------ Constraints ------
$1 ≤ T ≤ 100$
$3 ≤ N ≤ 10^{3}$
$1 ≤ K ≤ \frac{N - 1}{2}$
$1 ≤ A_{i} ≤ 10^{9}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
3 1
1 3 2
3 1
3 1 3
5 2
5 1 3 2 4
----- Sample Output 1 ------
3
4
8
----- explanation 1 ------
Test Case $1$: Chef moves first and he chooses the gift with cost $3$. His twin then chooses the gifts of costs $1$ and $2$.
Test Case $2$: Chef allows his brother to choose first and his brother chooses a gift with cost $3$. Then Chef chooses the remaining gift with cost $3$. Since Chef moves second, he is allowed to choose one more gift, so he chooses gift with cost $1$. The total cost of Chef's gifts is $3 + 1 = 4$.
Test Case $3$: Chef moves first and at the end he will have the gifts with costs $5$ and $3$. Hence, the total cost of gifts with Chef = $5 + 3 = 8$.
|
{"inputs": ["3\n3 1\n1 3 2\n3 1\n3 1 3\n5 2\n5 1 3 2 4"], "outputs": ["3\n4\n8"]}
| 592
| 50
|
coding
|
Solve the programming task below in a Python markdown code block.
n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a_1, a_2, ..., a_{n} of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.
The game consists of m steps. On each step the current leader with index i counts out a_{i} people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers l_1, l_2, ..., l_{m} — indices of leaders in the beginning of each step. Child with number l_1 is the first leader in the game.
Write a program which will restore a possible permutation a_1, a_2, ..., a_{n}. If there are multiple solutions then print any of them. If there is no solution then print -1.
-----Input-----
The first line contains two integer numbers n, m (1 ≤ n, m ≤ 100).
The second line contains m integer numbers l_1, l_2, ..., l_{m} (1 ≤ l_{i} ≤ n) — indices of leaders in the beginning of each step.
-----Output-----
Print such permutation of n numbers a_1, a_2, ..., a_{n} that leaders in the game will be exactly l_1, l_2, ..., l_{m} if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1.
-----Examples-----
Input
4 5
2 3 1 4 4
Output
3 1 2 4
Input
3 3
3 1 2
Output
-1
-----Note-----
Let's follow leadership in the first example: Child 2 starts. Leadership goes from 2 to 2 + a_2 = 3. Leadership goes from 3 to 3 + a_3 = 5. As it's greater than 4, it's going in a circle to 1. Leadership goes from 1 to 1 + a_1 = 4. Leadership goes from 4 to 4 + a_4 = 8. Thus in circle it still remains at 4.
|
{"inputs": ["100 1\n6\n", "2 2\n2 2\n", "2 2\n2 2\n", "100 1\n6\n", "3 3\n3 1 2\n", "3 3\n2 2 3\n", "2 3\n1 1 2\n", "3 3\n1 1 3\n"], "outputs": ["1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n", "1 2 \n", "1 2 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 506
| 710
|
coding
|
Solve the programming task below in a Python markdown code block.
You have two arrays in this kata, every array contain only unique elements. Your task is to calculate number of elements in first array which also are in second array.
Also feel free to reuse/extend the following starter code:
```python
def match_arrays(v, r):
```
|
{"functional": "_inputs = [[['Perl', 'Closure', 'JavaScript'], ['Go', 'C++', 'Erlang']], [['Erlang', 'JavaScript'], ['Go', 'C++', 'Python']], [[True, 3, 9, 11, 15], [True, 3, 11]]]\n_outputs = [[0], [0], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_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(match_arrays(*i), o[0])"}
| 69
| 224
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef's pizza is the tastiest pizza to exist, and the reason for that is his special, juicy homegrown tomatoes.
Tomatoes can be grown in rectangular patches of any side lengths. However, Chef only has a limited amount of land.
Consider the entire town of Chefville to be consisting of cells in a rectangular grid of positive coordinates.
Chef own all cells (x,y)$(x, y)$ that satisfy x∗y≤N$x*y \leq N$
As an example if N=4$N = 4$, Chef owns the following cells:
(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(3,1),(4,1)$(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (3, 1), (4, 1) $
Chef can only grow tomatoes in rectangular patches consisting only of cells which belong to him. Also, if he uses a cell, he must use it entirely. He cannot use only a portion of it.
Help Chef find the number of unique patches of rectangular land that he can grow tomatoes in! Since this number can be very large, output it modulo 1000000007$1000000007$.
-----Input:-----
- The first line of the input contains T$T$, the number of test cases.
- The next T$T$ lines of input contains one integer N$N$.
-----Output:-----
For each testcase, output the number of ways modulo 1000000007$1000000007$.
-----Constraints-----
- 1≤T≤5$1 \leq T \leq 5$
- 1≤N≤1010$1 \leq N \leq 10^{10}$
-----Sample Input:-----
2
4
10000000000
-----Sample Output:-----
23
227374950
|
{"inputs": ["2\n4\n10000000000"], "outputs": ["23\n227374950"]}
| 473
| 37
|
coding
|
Solve the programming task below in a Python markdown code block.
Task
=======
Make a custom esolang interpreter for the language Tick. Tick is a descendant of [Ticker](https://www.codewars.com/kata/esolang-ticker) but also very different data and command-wise.
Syntax/Info
========
Commands are given in character format. Non-command characters should be ignored. Tick has an potentially infinite memory as opposed to Ticker(which you have a special command to add a new cell) and only has 4 commands(as opposed to 7). Read about this esolang [here](https://esolangs.org/wiki/Tick).
Commands
========
`>`: Move data selector right
`<`: Move data selector left(infinite in both directions)
`+`: Increment memory cell by 1. 255+1=0
`*`: Add ascii value of memory cell to the output tape.
Examples
========
**Hello world!**
```
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*<<*>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*<<<<*>>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++*'
```
Also feel free to reuse/extend the following starter code:
```python
def interpreter(tape):
```
|
{"functional": "_inputs = [['++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*<<*>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*<<<<*>>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++*']]\n_outputs = [['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(interpreter(*i), o[0])"}
| 280
| 209
|
coding
|
Solve the programming task below in a Python markdown code block.
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times.
What is the minimum number of essays that Vanya needs to write to get scholarship?
-----Input-----
The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively.
Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6).
-----Output-----
In the first line print the minimum number of essays.
-----Examples-----
Input
5 5 4
5 2
4 7
3 1
3 2
2 5
Output
4
Input
2 5 4
5 2
5 2
Output
0
-----Note-----
In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.
In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
|
{"inputs": ["1 1 1\n1 1\n", "1 2 1\n2 2\n", "1 1 1\n1 1\n", "1 2 1\n2 2\n", "1 3 1\n2 2\n", "1 1 1\n0 1\n", "1 5 1\n2 2\n", "1 5 1\n2 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n"]}
| 373
| 134
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given $n$ integers $a_1, a_2, \ldots, a_n$. Is it possible to arrange them on a circle so that each number is strictly greater than both its neighbors or strictly smaller than both its neighbors?
In other words, check if there exists a rearrangement $b_1, b_2, \ldots, b_n$ of the integers $a_1, a_2, \ldots, a_n$ such that for each $i$ from $1$ to $n$ at least one of the following conditions holds:
$b_{i-1} < b_i > b_{i+1}$
$b_{i-1} > b_i < b_{i+1}$
To make sense of the previous formulas for $i=1$ and $i=n$, one shall define $b_0=b_n$ and $b_{n+1}=b_1$.
-----Input-----
The first line of the input contains a single integer $t$ ($1 \le t \le 3\cdot 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($3 \le n \le 10^5$) — the number of integers.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$).
The sum of $n$ over all test cases doesn't exceed $2\cdot 10^5$.
-----Output-----
For each test case, if it is not possible to arrange the numbers on the circle satisfying the conditions from the statement, output ${NO}$. You can output each letter in any case.
Otherwise, output ${YES}$. In the second line, output $n$ integers $b_1, b_2, \ldots, b_n$, which are a rearrangement of $a_1, a_2, \ldots, a_n$ and satisfy the conditions from the statement. If there are multiple valid ways to arrange the numbers, you can output any of them.
-----Examples-----
Input
4
3
1 1 2
4
1 9 8 4
4
2 0 2 2
6
1 1 1 11 111 1111
Output
NO
YES
1 8 4 9
NO
YES
1 11 1 111 1 1111
-----Note-----
It can be shown that there are no valid arrangements for the first and the third test cases.
In the second test case, the arrangement $[1, 8, 4, 9]$ works. In this arrangement, $1$ and $4$ are both smaller than their neighbors, and $8, 9$ are larger.
In the fourth test case, the arrangement $[1, 11, 1, 111, 1, 1111]$ works. In this arrangement, the three elements equal to $1$ are smaller than their neighbors, while all other elements are larger than their neighbors.
|
{"inputs": ["4\n3\n1 1 2\n4\n1 9 8 4\n4\n2 0 2 2\n6\n1 1 1 11 111 1111\n"], "outputs": ["NO\nYES\n1 8 4 9 \nNO\nYES\n1 11 1 111 1 1111 \n"]}
| 710
| 96
|
coding
|
Solve the programming task below in a Python markdown code block.
Xander Cage has a list of cities he can visit on his new top-secret mission. He represents each city as a tuple of $(latitude,longitude,height,points)$. The values of $latitude$, $longitude$, and $height$ are distinct across all cities.
We define a mission as a sequence of cities, $c_1,c_2,c_3,\ldots,c_k$, that he visits. We define the total $\text{points}$ of such a mission to be the sum of the $\text{points}$ of all the cities in his mission list.
Being eccentric, he abides by the following rules on any mission:
He can choose the number of cities he will visit (if any).
He can start the mission from any city.
He visits cities in order of strictly increasing $height$.
The absolute difference in $latitude$ between adjacent visited cities in his mission must be at most $d_l\textbf{at}$.
The absolute difference in $longitude$ between adjacent visited cities in his mission must be at most $d_long$.
Given $\boldsymbol{d\text{_lat}}$, $d\text{_long}$, and the definitions for $n$ cities, find and print the maximum possible total $\text{points}$ that Xander can earn on a mission.
Input Format
The first line contains three space-separated integers describing the respective values of $n$, $\boldsymbol{d\text{_lat}}$, and $d\text{_long}$.
Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains four space-separated integers denoting the respective $latitude$, $longitude$, $height$, and $\text{points}$ for a city.
Constraints
$1\leq n\leq2\times10^5$
$1\leq d\_\textit{lat},d\textit{long}\leq2\times10^5$
$1\leq latitude,longitude,height\leq2\times10^5$
$-2\times10^5\leq\textit{points}\leq2\times10^5$
Output Format
Print a single integer denoting the maximum possible $\text{points}$ that Xander can earn on a mission.
Sample Input 0
3 1 1
1 1 1 3
2 2 2 -1
3 3 3 3
Sample Output 0
5
Explanation 0
Xander can start at city $1$, then go to city $2$, and then go to city $3$ for a maximum value of total $points=3+-1+3=5$
Note that he cannot go directly from city $1$ to city $3$ as that would violate his rules that the absolute difference in $latitude$ between adjacent visited cities be $\leq d\text{_lat}$ and the absolute difference in $longitude$ between adjacent visited cities be $\leq d\text{_long}$. Because $d\textit{_lat}=1$ and $d\textit{_long}=1$, he cannot directly travel between those cities.
|
{"inputs": ["3 1 1\n1 1 1 3\n2 2 2 -1\n3 3 3 3\n"], "outputs": ["5\n"]}
| 673
| 42
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an Integer N, write a program to reverse it.
-----Input-----
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For each test case, display the reverse of the given number N, in a new line.
-----Constraints-----
- 1 ≤ T ≤ 1000
- 1 ≤ N ≤ 1000000
-----Example-----
Input
4
12345
31203
2123
2300
Output
54321
30213
3212
32
|
{"inputs": ["4\n12345\n31203\n2123\n2300"], "outputs": ["54321\n30213\n3212\n32"]}
| 157
| 52
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chefina is playing with ranges. There are $N$ ranges $[l_{1}, r_{1}], [l_{2}, r_{2}], \ldots, [l_{N}, r_{N}]$. Chefina wants to divide the ranges into two non-empty subsets in such a way that each range is in exactly one subset and whenever two ranges have a common point, they are in the same subset.
Since this could be difficult to achieve, Chefina can delete any number of ranges (possibly zero) and then divide the remaining ranges into such non-empty subsets. She wants to know whether it is possible to achieve her task after deleting some ranges and if it is possible, she also wants to know the minimum number of ranges she needs to delete to achieve it.
------ 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 each test case contains a single integer $N$.
$N$ lines follow. For each $i$ ($1 ≤ i ≤ N$), the $i$-th of these lines contains two space-separated integers $l_{i}$ and $r_{i}$.
------ Output ------
For each test case, print a single line containing one integer ― the minimum number of ranges to delete, or $-1$ if it is impossible to delete some ranges and divide the remaining ranges into two non-empty subsets.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{5}$
$1 ≤ l_{i} ≤ r_{i} ≤ 10^{9}$ for each valid $i$
------ Subtasks ------
Subtask #1 (10 points): $N = 16$
Subtask #2 (15 points): $N = 1,000$
Subtask #3 (15 points): $r_{i} ≤ 10^{6}$ for each valid $i$
Subtask #4 (60 points): original constraints
----- Sample Input 1 ------
3
3
1 4
2 6
5 7
2
1 4
4 6
2
3 7
8 9
----- Sample Output 1 ------
1
-1
0
----- explanation 1 ------
Example case 1: It is enough to delete the range $[2, 6]$.
Example case 2: There is no way to divide these two ranges into two suitable non-empty subsets and deleting any range obviously makes it impossible too.
Example case 3: There is no need to delete any ranges, we can just put one range into one subset and the other range into the other subset.
|
{"inputs": ["3\n3\n1 4\n2 6\n5 7\n2\n1 4\n4 6\n2\n3 7\n8 9"], "outputs": ["1\n-1\n0"]}
| 623
| 51
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
Notes
Constraints
* Elements in S is sorted in ascending order
* n ≤ 100000
* q ≤ 50000
* 0 ≤ an element in S ≤ 109
* 0 ≤ an element in T ≤ 109
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.
Output
Print C in a line.
Examples
Input
5
1 2 3 4 5
3
3 4 1
Output
3
Input
3
1 2 3
1
5
Output
0
Input
5
1 1 2 2 3
2
1 2
Output
2
|
{"inputs": ["3\n2 2 3\n1\n5", "3\n1 2 3\n1\n4", "3\n1 2 4\n1\n4", "3\n2 2 4\n1\n4", "3\n2 2 5\n1\n4", "3\n0 2 5\n1\n4", "3\n1 2 5\n1\n4", "3\n1 4 5\n1\n4"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]}
| 232
| 142
|
coding
|
Solve the programming task below in a Python markdown code block.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print Yes; otherwise, print No.
-----Constraints-----
- 1 \leq M \leq N \leq 100
- 1 \leq A_i \leq 1000
- A_i are distinct.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
-----Output-----
If M popular items can be selected, print Yes; otherwise, print No.
-----Sample Input-----
4 1
5 4 2 1
-----Sample Output-----
Yes
There were 12 votes in total. The most popular item received 5 votes, and we can select it.
|
{"inputs": ["3 3\n39 4 1", "4 1\n5 4 0 1", "3 1\n5 4 0 1", "3 2\n39 19 1", "3 2\n39 14 1", "3 2\n39 18 1", "3 1\n39 18 1", "3 1\n39 16 1"], "outputs": ["No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
| 229
| 141
|
coding
|
Solve the programming task below in a Python markdown code block.
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.
-----Input-----
The single line contains integers n, m and k (1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m).
-----Output-----
Print the k-th largest number in a n × m multiplication table.
-----Examples-----
Input
2 2 2
Output
2
Input
2 3 4
Output
3
Input
1 10 5
Output
5
-----Note-----
A 2 × 3 multiplication table looks like this:
1 2 3
2 4 6
|
{"inputs": ["2 2 2\n", "2 3 4\n", "1 1 1\n", "3 3 1\n", "3 3 2\n", "3 3 3\n", "3 3 5\n", "3 3 8\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "2\n", "2\n", "3\n", "6\n"]}
| 289
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Mirko has been moving up in the world of basketball. He started as a mere spectator, but has already reached the coveted position of the national team coach!
Mirco is now facing a difficult task: selecting five primary players for the upcoming match against Tajikistan. Since Mirko is incredibly lazy, he doesn't bother remembering players' names, let alone their actual skills. That's why he has settled on selecting five players who share the same first letter of their surnames, so that he can remember them easier. If there are no five players sharing the first letter of their surnames, Mirko will simply forfeit the game!
Your task is to find the first letters Mirko's players' surnames can begin with(In alphabetical order), or return `"forfeit"` if Mirko can't gather a team.
# Input/Output
- `[input]` string array `players`
Array of players' surnames, consisting only of lowercase English letters.
- `[output]` a string
A **sorted** string of possible first letters, or "forfeit" if it's impossible to gather a team.
# Example
For `players = ["michael","jordan","lebron","james","kobe","bryant"]`, the output should be `"forfeit"`.
For
```
players = ["babic","keksic","boric","bukic",
"sarmic","balic","kruzic","hrenovkic",
"beslic","boksic","krafnic","pecivic",
"klavirkovic","kukumaric","sunkic","kolacic",
"kovacic","prijestolonasljednikovic"]
```
the output should be "bk".
Also feel free to reuse/extend the following starter code:
```python
def strange_coach(players):
```
|
{"functional": "_inputs = [[['michael', 'jordan', 'lebron', 'james', 'kobe', 'bryant']], [['babic', 'keksic', 'boric', 'bukic', 'sarmic', 'balic', 'kruzic', 'hrenovkic', 'beslic', 'boksic', 'krafnic', 'pecivic', 'klavirkovic', 'kukumaric', 'sunkic', 'kolacic', 'kovacic', 'prijestolonasljednikovic']], [['jgztazpytubijfsmjz', 'bokvgratzzdibku', 'qineboilzoqdqivc', 'bfctyltibtkbxq', 'vioxcuhqhikxeqwekqkjo', 'nrvsdhttr', 'eiaoajuwxpwmyliqikzcchid', 'bxrwawgor', 'gbsqaxotzmblxttj', 'kwchrcaconuwaivhvnyf', 'neiemapiica', 'bppao', 'bxujiwivsjfbqrzygpdgkyz', 'jnzrhhmcgcpffflpzwmqib', 'jhozlevckrrwimdmyzc', 'bomojotkqqditelsk', 'ywmbheywzfyqjjs', 'snwrclyjkbspysjftcmyak', 'eelrsgkuhu', 'dnyzsvqjjuqoc']]]\n_outputs = [['forfeit'], ['bk'], ['b']]\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(strange_coach(*i), o[0])"}
| 408
| 499
|
coding
|
Solve the programming task below in a Python markdown code block.
Batman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less than that of the standard model.
After carrying out this process, he wishes to know how many of his prototypes are faster than his standard Batmobile?
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow:
- The first line of each test case contains a single integer N denoting the number of copies of the standard Batmobile.
- The second line contains a sequence of N+1 space-separated integers, S0 to SN, sorted in non-decreasing order separated by space. S0 is the maximum speed of the standard Batmobile. S1 to SN denote the maximum speeds of the prototypes.
-----Output-----
- For each test case, output a single line containing an integer denoting the answer.
-----Constraints-----
- 1 ≤ T ≤ 1000
- 1 ≤ N ≤ 1000
- 1 ≤ Si ≤ 109
-----Example-----
Input:
2
4
1 2 3 4 5
5
1 10 100 1000 10000 100000
Output:
4
5
|
{"inputs": ["2\n4\n1 2 3 4 5\n5\n1 10 100 1000 10000 100000"], "outputs": ["4\n5"]}
| 310
| 55
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums of n integers, and an integer k.
The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If there are less than k elements before or after the index i, then the k-radius average is -1.
Build and return an array avgs of length n where avgs[i] is the k-radius average for the subarray centered at index i.
The average of x elements is the sum of the x elements divided by x, using integer division. The integer division truncates toward zero, which means losing its fractional part.
For example, the average of four elements 2, 3, 1, and 5 is (2 + 3 + 1 + 5) / 4 = 11 / 4 = 2.75, which truncates to 2.
Please complete the following python code precisely:
```python
class Solution:
def getAverages(self, nums: List[int], k: int) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [7,4,3,9,1,8,5,2,6], k = 3) == [-1,-1,-1,5,4,4,-1,-1,-1]\n assert candidate(nums = [100000], k = 0) == [100000]\n assert candidate(nums = [8], k = 100000) == [-1]\n\n\ncheck(Solution().getAverages)"}
| 257
| 121
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp has prepared $n$ competitive programming problems. The topic of the $i$-th problem is $a_i$, and some problems' topics may coincide.
Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and all contests should have pairwise distinct topics. He may not use all the problems. It is possible that there are no contests for some topics.
Polycarp wants to host competitions on consecutive days, one contest per day. Polycarp wants to host a set of contests in such a way that: number of problems in each contest is exactly twice as much as in the previous contest (one day ago), the first contest can contain arbitrary number of problems; the total number of problems in all the contests should be maximized.
Your task is to calculate the maximum number of problems in the set of thematic contests. Note, that you should not maximize the number of contests.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of problems Polycarp has prepared.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) where $a_i$ is the topic of the $i$-th problem.
-----Output-----
Print one integer — the maximum number of problems in the set of thematic contests.
-----Examples-----
Input
18
2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10
Output
14
Input
10
6 6 6 3 6 1000000000 3 3 6 6
Output
9
Input
3
1337 1337 1337
Output
3
-----Note-----
In the first example the optimal sequence of contests is: $2$ problems of the topic $1$, $4$ problems of the topic $2$, $8$ problems of the topic $10$.
In the second example the optimal sequence of contests is: $3$ problems of the topic $3$, $6$ problems of the topic $6$.
In the third example you can take all the problems with the topic $1337$ (the number of such problems is $3$ so the answer is $3$) and host a single contest.
|
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n4 1\n", "2\n5 1\n", "2\n5 0\n", "2\n1 0\n", "2\n5 -1\n"], "outputs": ["2\n", "2", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 568
| 101
|
coding
|
Solve the programming task below in a Python markdown code block.
Given the schedule of Chef for 30 days (A binary string of length 30 where '0' denotes that Chef was on leave and '1' denotes Chef was working on that day). Chef gets X- Rs for every day he worked. As working continuously for a long time is hectic so Company introduced the following policy to give a bonus to its employees.
The company will check the longest streak for which an employee has worked and will award Y- Rs for every day of that streak as a bonus. Calculate the salary received by Chef (including the bonus).
Note: Rs represents the currency of Chefland, and if there are two or more longest streaks of the same length, only one is counted for the bonus.
------ Input Format ------
- The first line contains an integer T denoting the number of test cases. The T test cases then follow.
- The first line of each test case contains X and Y.
- Second line contains a binary string (i.e it contains only ‘0’ / ‘1’), where '0' denotes that Chef was on leave and '1' denotes Chef was working on that day.
------ Output Format ------
- For each testcase, output in a single line answer to the problem. i.e The salary received by Chef (including the bonus).
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ X ≤ 999$
$1 ≤ Y ≤ 999$
$|S| = 30$
----- Sample Input 1 ------
3
6 3
111100110101100000101100011111
8 2
111010111101001010100100111101
5 6
011101010100101000001101000010
----- Sample Output 1 ------
117
152
78
----- explanation 1 ------
Testcase $1$: Chef's actual pay comes out $17 \cdot 6 = 102-$ Rs and the length of longest continuous working streak comes out $5$ (the last $5$ working days), so bonus reward becomes $5 \cdot 3 = 15-$ Rs. Hence Chef's salary comes out to be $102 + 15 = 117-$ Rs.
Testcase $2$: Chef's actual pay comes out $144-$ Rs and the length of longest continuous working streak comes out $4$ (here there are multiple occurrences of the longest working streak, so company selects any one of them), so bonus reward becomes $8-$ Rs. Hence Chef's salary comes out to be $152-$ Rs.
|
{"inputs": ["3\n6 3\n111100110101100000101100011111\n8 2\n111010111101001010100100111101\n5 6\n011101010100101000001101000010"], "outputs": ["117\n152\n78"]}
| 624
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other!
Let's use the Hofstadter Female and Male sequences to demonstrate this technique. You'll want to create two functions `F` and `M` such that the following equations are true:
```
F(0) = 1
M(0) = 0
F(n) = n - M(F(n - 1))
M(n) = n - F(M(n - 1))
```
Don't worry about negative numbers, `n` will always be greater than or equal to zero.
~~~if:php,csharp
You *do* have to worry about performance though, mutual recursion uses up a lot of stack space (and is highly inefficient) so you may have to find a way to make your solution consume less stack space (and time). Good luck :)
~~~
Hofstadter Wikipedia Reference http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Female_and_Male_sequences
Also feel free to reuse/extend the following starter code:
```python
def f(n):
```
|
{"functional": "_inputs = [[0], [5], [10], [15], [25]]\n_outputs = [[1], [3], [6], [9], [16]]\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(f(*i), o[0])"}
| 262
| 181
|
coding
|
Solve the programming task below in a Python markdown code block.
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants.
Each of the next n lines contains two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
-----Output-----
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
-----Examples-----
Input
6
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884
Output
rated
Input
4
1500 1500
1300 1300
1200 1200
1400 1400
Output
unrated
Input
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
Output
maybe
-----Note-----
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
|
{"inputs": ["2\n1 1\n1 1\n", "2\n1 1\n2 2\n", "2\n2 2\n1 1\n", "2\n2 1\n1 2\n", "2\n3 2\n3 2\n", "2\n1 2\n2 1\n", "2\n3 1\n9 8\n", "2\n2 1\n1 1\n"], "outputs": ["maybe\n", "unrated\n", "maybe\n", "rated\n", "rated\n", "rated\n", "rated\n", "rated\n"]}
| 630
| 135
|
coding
|
Solve the programming task below in a Python markdown code block.
Вася купил стол, у которого n ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2n частей возможно составить n ножек одинаковой длины. При составлении ножки любые две части могут быть соединены друг с другом. Изначально все ножки стола разобраны, а вам заданы длины 2n частей в произвольном порядке.
Помогите Васе собрать все ножки стола так, чтобы все они были одинаковой длины, разбив заданные 2n части на пары правильным образом. Каждая ножка обязательно должна быть составлена ровно из двух частей, не разрешается использовать как ножку только одну часть.
-----Входные данные-----
В первой строке задано число n (1 ≤ n ≤ 1000) — количество ножек у стола, купленного Васей.
Во второй строке следует последовательность из 2n целых положительных чисел a_1, a_2, ..., a_2n (1 ≤ a_{i} ≤ 100 000) — длины частей ножек стола в произвольном порядке.
-----Выходные данные-----
Выведите n строк по два целых числа в каждой — длины частей ножек, которые надо соединить друг с другом. Гарантируется, что всегда возможно собрать n ножек одинаковой длины. Если ответов несколько, разрешается вывести любой из них.
-----Примеры-----
Входные данные
3
1 3 2 4 5 3
Выходные данные
1 5
2 4
3 3
Входные данные
3
1 1 1 2 2 2
Выходные данные
1 2
2 1
1 2
|
{"inputs": ["1\n3 7\n", "1\n7 7\n", "3\n1 3 2 4 5 3\n", "3\n1 1 1 2 2 2\n", "10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15\n", "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15\n", "10\n759 82 475 841 46 461 288 525 918 241 789 847 58 954 712 159 942 211 153 539\n"], "outputs": ["3 7\n", "7 7\n", "1 5\n2 4\n3 3\n", "1 2\n1 2\n1 2\n", "1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5 15\n7 13\n7 13\n9 11\n", "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5 15\n7 13\n7 13\n9 11\n", "46 954\n58 942\n82 918\n153 847\n159 841\n211 789\n241 759\n288 712\n461 539\n475 525\n"]}
| 493
| 556
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a program to obtain 2 numbers $($ $A$ $and$ $B$ $)$ and an arithmetic operator $(C)$ and then design a $calculator$ depending upon the operator entered by the user.
So for example if C="+", you have to sum the two numbers.
If C="-", you have to subtract the two numbers.
If C=" * ", you have to print the product.
If C=" / ", you have to divide the two numbers.
-----Input:-----
- First line will contain the first number $A$.
- Second line will contain the second number $B$.
- Third line will contain the operator $C$, that is to be performed on A and B.
-----Output:-----
Output a single line containing the answer, obtained by, performing the operator on the numbers. Your output will be considered to be correct if the difference between your output and the actual answer is not more than $10^{-6}$.
-----Constraints-----
- $-1000 \leq A \leq 1000$
- $-1000 \leq B \leq 1000$ $and$ $B \neq 0$
- $C$ $can$ $only$ $be$ $one$ $of$ $these$ $4$ $operators$ {" + ", " - ", " * ", " / "}
-----Sample Input:-----
8
2
/
-----Sample Output:-----
4.0
-----Sample Input:-----
5
3
+
-----Sample Output:-----
8
|
{"inputs": ["8\n2\n/", "5\n3\n+"], "outputs": ["4.0", "8"]}
| 337
| 27
|
coding
|
Solve the programming task below in a Python markdown code block.
Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}).
Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements.
Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a').
Find the maximum possible score of a'.
-----Constraints-----
- 1 ≤ N ≤ 10^5
- a_i is an integer.
- 1 ≤ a_i ≤ 10^9
-----Partial Score-----
- In the test set worth 300 points, N ≤ 1000.
-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{3N}
-----Output-----
Print the maximum possible score of a'.
-----Sample Input-----
2
3 1 4 1 5 9
-----Sample Output-----
1
When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1.
|
{"inputs": ["1\n1 0 5", "1\n0 0 5", "1\n1 3 5", "1\n1 2 5", "1\n0 0 8", "1\n0 0 0", "1\n0 1 0", "1\n1 2 3"], "outputs": ["1\n", "0\n", "-2\n", "-1\n", "0\n", "0\n", "1\n", "-1"]}
| 299
| 109
|
coding
|
Solve the programming task below in a Python markdown code block.
Once, a genius guy Cristo visited NASA where he met many scientists. A young intern Mark at NASA asked Cristo to observe the strange behaviour of two
independent particles (say Alpha and Beta) moving in the free space.Cristo was astonished to see the movement of Alpha and Beta. However, he formulated a procedure
to evaluate the distance covered by the particles in given time.
The procedure calculates the distance covered by Alpha and Beta for a given time. Mark, however struggles
to evaluate the procedure manually and asks you to help him.
Cristo's Procedure :-
alpha = 0
beta = 0
Procedure CristoSutra( Ti ) :
if Ti <= 0 :
alpha = alpha + 1
else if Ti == 1 :
beta = beta + 1
else :
CristoSutra(Ti-1)
CristoSutra(Ti-2)
CristoSutra(Ti-3)
end procedure
Note: Print the answer by taking mod from 109+7 .
-----Constraints:-----
- 1<=T<=105
- 1<=Ti<=105
-----Input Format:-----
First line consists an integer t, number of Test cases.For each test case, there is an integer denoting time Ti.
-----Output Format:-----
For each test case, a single output line contains two space seperated numbers ,distance covered by alpha and beta in the given time.
-----Subtasks:-----
Subtask 1 (30 points)
- 1<=T<=10
- 1<=Ti<=1000
Subtask 2 (70 points)
original contraints
Sample Input:
2
1
2
Sample Output:
0 1
2 1
|
{"inputs": ["2\n1\n2"], "outputs": ["0 1\n2 1"]}
| 379
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct. He is sorting this sequence in increasing order. With supernatural power, he can perform the following two operations on the sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9
* If i ≠ j, then A_i ≠ A_j.
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the minimum number of times Operation 1 that Snuke has to perform.
Examples
Input
4
2
4
3
1
Output
1
Input
5
10
8
5
3
2
Output
0
|
{"inputs": ["4\n2\n4\n2\n1", "4\n2\n4\n6\n1", "4\n2\n4\n2\n0", "4\n2\n4\n8\n1", "4\n2\n4\n5\n1", "4\n2\n4\n9\n1", "4\n2\n4\n3\n0", "4\n0\n4\n8\n1"], "outputs": ["1\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n"]}
| 290
| 126
|
coding
|
Solve the programming task below in a Python markdown code block.
Tashizan Hikizan (Calculation Training)
square1001 You gave E869120 two numbers, $ A $ and $ B $, as birthday presents.
E869120 You decided to use these two numbers for calculation training.
Specifically, E869120 does the following for these numbers exactly $ N $ times:
* Replace $ A $ with $ A-B $ on odd-numbered operations
* Replace $ B $ with $ A + B $ on even-numbered operations
E869120 Find out what the values of $ A $ and $ B $ are after you have operated $ N $ times.
input
Input is given from standard input in the following format.
$ N $
$ A $ $ B $
output
E869120 Please output the values of $ A $ and $ B $ after you have operated $ N $ times in this order, separated by blanks.
However, insert a line break at the end.
Constraint
* $ 1 \ leq N \ leq 1000000000000000000 \ (= 10 ^ {18}) $
* $ 1 \ leq A \ leq 1000000000 \ (= 10 ^ 9) $
* $ 1 \ leq B \ leq 1000000000 \ (= 10 ^ 9) $
* All inputs are integers.
Input example 1
3
3 4
Output example 1
-4 3
The value of $ (A, B) $ changes as $ (3,4) → (-1,4) → (-1,3) → (-4,3) $.
Input example 2
8
6 9
Output example 2
3 -6
Example
Input
3
3 4
Output
-4 3
|
{"inputs": ["3\n4 4", "3\n4 3", "3\n5 3", "3\n9 3", "3\n7 3", "3\n0 3", "3\n0 5", "3\n0 6"], "outputs": ["-4 4\n", "-3 4\n", "-3 5\n", "-3 9\n", "-3 7\n", "-3 0\n", "-5 0\n", "-6 0\n"]}
| 439
| 111
|
coding
|
Solve the programming task below in a Python markdown code block.
In a recent [breakthrough] in mathematics, the proof utilized a concept called Height.
Consider a fraction \frac{a}{b}. Its Height is defined as the maximum of its numerator and denominator. So, for example, the Height of \frac{3}{19} would be 19, and the Height of \frac{27}{4} would be 27.
Given a and b, find the Height of \frac{a}{b}.
------ Input Format ------
The only line of input contains two integers, a and b.
------ Output Format ------
Output a single integer, which is the Height of \frac{a}{b}.
------ Constraints ------
$1 ≤ a, b ≤ 100$
$a$ and $b$ do not have any common factors.
----- Sample Input 1 ------
3 19
----- Sample Output 1 ------
19
----- explanation 1 ------
The maximum of $\{3, 19\}$ is $19$. Hence the Height of $\frac{3}{19}$ is $19$.
----- Sample Input 2 ------
27 4
----- Sample Output 2 ------
27
----- explanation 2 ------
The maximum of $\{27, 4\}$ is $27$. Hence the Height of $\frac{27}{4}$ is $27$.
|
{"inputs": ["3 19\n", "27 4\n"], "outputs": ["19\n", "27\n"]}
| 306
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
-----Input-----
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.
-----Output-----
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
-----Examples-----
Input
6 60
0 0
1 20
3 21
5 0
19 30
23 40
Output
6 1
Input
16 50
0 30
1 20
3 0
4 30
6 10
7 50
9 30
11 10
12 50
14 30
16 10
17 50
19 30
21 10
22 50
23 59
Output
24 50
Input
3 17
0 30
1 0
12 0
Output
0 0
-----Note-----
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing.
|
{"inputs": ["1 1\n0 0\n", "1 5\n1 0\n", "1 2\n3 0\n", "1 5\n0 6\n", "1 2\n2 3\n", "1 2\n2 3\n", "1 1\n0 0\n", "1 2\n3 0\n"], "outputs": ["0 2\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 2\n", "0 0\n"]}
| 597
| 134
|
coding
|
Solve the programming task below in a Python markdown code block.
# Two samurai generals are discussing dinner plans after a battle, but they can't seem to agree.
The discussion gets heated and you are cannot risk favoring either of them as this might damage your political standing with either of the two clans the samurai generals belong to. Thus, the only thing left to do is find what the common ground of what they are saying is.
Compare the proposals with the following function:
```python
def common_ground(s1,s2)
```
The parameters ```s1``` and ```s2``` are the strings representing what each of the generals said. You should output a string containing the words in ```s1``` that also occur in ```s2```.
Each word in the resulting string shall occur once, and the order of the words need to follow the order of the first occurence of each word in ```s2```.
If they are saying nothing in common, kill both samurai and blame a ninja. (output "death")
Also feel free to reuse/extend the following starter code:
```python
def common_ground(s1,s2):
```
|
{"functional": "_inputs = [['eat chicken', 'eat chicken and rice'], ['eat a burger and drink a coke', 'drink a coke'], ['i like turtles', 'what are you talking about'], ['aa bb', 'aa bb cc'], ['aa bb cc', 'bb cc'], ['aa bb cc', 'bb cc bb aa'], ['aa bb', 'cc dd'], ['aa bb', ''], ['', 'cc dd'], ['', '']]\n_outputs = [['eat chicken'], ['drink a coke'], ['death'], ['aa bb'], ['bb cc'], ['bb cc aa'], ['death'], ['death'], ['death'], ['death']]\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(common_ground(*i), o[0])"}
| 236
| 272
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].
A message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note that a sender may send more than one message.
Return the sender with the largest word count. If there is more than one sender with the largest word count, return the one with the lexicographically largest name.
Note:
Uppercase letters come before lowercase letters in lexicographical order.
"Alice" and "alice" are distinct.
Please complete the following python code precisely:
```python
class Solution:
def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(messages = [\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"], senders = [\"Alice\",\"userTwo\",\"userThree\",\"Alice\"]) == \"Alice\"\n assert candidate(messages = [\"How is leetcode for everyone\",\"Leetcode is useful for practice\"], senders = [\"Bob\",\"Charlie\"]) == \"Charlie\"\n\n\ncheck(Solution().largestWordCount)"}
| 195
| 106
|
coding
|
Solve the programming task below in a Python markdown code block.
Takahashi has N blue cards and M red cards.
A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.
Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.
Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)
At most how much can he earn on balance?
Note that the same string may be written on multiple cards.
-----Constraints-----
- N and M are integers.
- 1 \leq N, M \leq 100
- s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.
-----Input-----
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M
-----Output-----
If Takahashi can earn at most X yen on balance, print X.
-----Sample Input-----
3
apple
orange
apple
1
grape
-----Sample Output-----
2
He can earn 2 yen by announcing apple.
|
{"inputs": ["3\nappme\norange\napple\n1\ngrape", "3\nappme\norange\napple\n0\ngrape", "3\nappme\nprange\napple\n0\ngrape", "3\nappme\nprange\napple\n0\ngrepa", "3\nappme\nprangd\napple\n0\ngrepa", "3\nappme\nprangd\napple\n0\ngreqa", "3\nappme\nprangd\napple\n0\naqerg", "3\nappme\ndgnarp\napple\n0\naqerg"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 391
| 171
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).
You are given a string answerKey, where answerKey[i] is the original answer to the ith question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:
Change the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').
Return the maximum number of consecutive 'T's or 'F's in the answer key after performing the operation at most k times.
Please complete the following python code precisely:
```python
class Solution:
def maxConsecutiveAnswers(self, answerKey: str, k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(answerKey = \"TTFF\", k = 2) == 4\n assert candidate(answerKey = \"TFFT\", k = 1) == 3\n assert candidate(answerKey = \"TTFTTFTT\", k = 1) == 5\n\n\ncheck(Solution().maxConsecutiveAnswers)"}
| 213
| 81
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [directioni, amounti]:
directioni can be 0 (for left shift) or 1 (for right shift).
amounti is the amount by which string s is to be shifted.
A left shift by 1 means remove the first character of s and append it to the end.
Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.
Return the final string after all operations.
Please complete the following python code precisely:
```python
class Solution:
def stringShift(self, s: str, shift: List[List[int]]) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"abc\", shift = [[0,1],[1,2]]) == \"cab\"\n assert candidate(s = \"abcdefg\", shift = [[1,1],[1,1],[0,2],[1,3]]) == \"efgabcd\"\n\n\ncheck(Solution().stringShift)"}
| 164
| 78
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.
Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.
Please complete the following python code precisely:
```python
class Solution:
def twoCitySchedCost(self, costs: List[List[int]]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(costs = [[10,20],[30,200],[400,50],[30,20]]) == 110\n assert candidate(costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]) == 1859\n assert candidate(costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]) == 3086\n\n\ncheck(Solution().twoCitySchedCost)"}
| 134
| 198
|
coding
|
Solve the programming task below in a Python markdown code block.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
|
{"inputs": ["0\n", "1\n", "01\n", "00\n", "100\n", "101\n", "001\n", "000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
| 326
| 80
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.