source
stringclasses 4
values | task_type
stringclasses 1
value | in_source_id
stringlengths 0
138
| problem
stringlengths 219
13.2k
| gold_standard_solution
stringlengths 0
413k
| problem_id
stringlengths 5
10
| metadata
dict | verification_info
dict |
---|---|---|---|---|---|---|---|
apps | verifiable_code | 525 | Solve the following coding problem using the programming language python:
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!
A password is an array $a$ of $n$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index $i$ such that $1 \leq i < n$ and $a_{i} \neq a_{i+1}$, delete both $a_i$ and $a_{i+1}$ from the array and put $a_{i}+a_{i+1}$ in their place.
For example, for array $[7, 4, 3, 7]$ you can choose $i = 2$ and the array will become $[7, 4+3, 7] = [7, 7, 7]$. Note that in this array you can't apply this operation anymore.
Notice that one operation will decrease the size of the password by $1$. What is the shortest possible length of the password after some number (possibly $0$) of operations?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of the password.
The second line of each test case contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ($1 \leq a_{i} \leq 10^9$) — the initial contents of your password.
The sum of $n$ over all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each password, print one integer: the shortest possible length of the password after some number of operations.
-----Example-----
Input
2
4
2 1 3 1
2
420 420
Output
1
2
-----Note-----
In the first test case, you can do the following to achieve a length of $1$:
Pick $i=2$ to get $[2, 4, 1]$
Pick $i=1$ to get $[6, 1]$
Pick $i=1$ to get $[7]$
In the second test case, you can't perform any operations because there is no valid $i$ that satisfies the requirements mentioned above.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# for _ in range(1):
for _ in range(int(input())):
# a, b = map(int, input().split())
n = int(input())
arr = list(map(int, input().split()))
# s = input()
if [arr[0]] * n == arr:
print(n)
else:
print(1)
``` | vfc_11854 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1392/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n2 1 3 1\n2\n420 420\n",
"output": "1\n2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 526 | Solve the following coding problem using the programming language python:
Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.
He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!
Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.
Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$) — the number of rows and the number of columns in the matrix $a$.
Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$).
-----Output-----
If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".
Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds.
If there is more than one possible answer, you may output any.
-----Examples-----
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3
-----Note-----
In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.
In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = [int(i) for i in input().split()]
A = []
C = []
for i in range(n):
B = [int(j) for j in input().split()]
A.append(B)
C.append(sorted(list(set(B))))
xor = 0
ans = []
for i in range(n):
xor ^= A[i][0]
ans.append(1)
if xor==0:
found = 0
for trial in range(n-1, -1, -1):
newxor = xor^A[trial][0]
if found==1:
break
for j in range(m):
if A[trial][j]^newxor!=0:
ans[trial] = j+1
found = 1
break
if found==1:
break
if found:
print('TAK')
print(*ans)
else:
print('NIE')
else:
print('TAK')
print(*ans)
``` | vfc_11858 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1151/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n0 0\n0 0\n0 0\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n7 7 7\n7 7 10\n",
"output": "TAK\n1 3 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 529 | Solve the following coding problem using the programming language python:
[Image]
-----Input-----
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
-----Output-----
Output the required string.
-----Examples-----
Input
AprilFool
14
Output
AprILFooL
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t, p = input().lower(), 'abcdefghijklmnopqrstuvwxyz|'[int(input())]
print(''.join(i.upper() if i < p else i for i in t))
``` | vfc_11870 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/290/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AprilFool\n14\n",
"output": "AprILFooL\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 530 | Solve the following coding problem using the programming language python:
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string.
Let's represent Yaroslav's word as s = s_1s_2... s_2n. Similarly, let's represent Andrey's word as t = t_1t_2... t_2n. Then, if Yaroslav choose number k during his move, then he is going to write out character s_{k} on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character t_{r} on the piece of paper.
The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw.
You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 10^6). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word.
It is guaranteed that both words consist of 2·n characters "0" and "1".
-----Output-----
Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes.
-----Examples-----
Input
2
0111
0001
Output
First
Input
3
110110
001001
Output
First
Input
3
111000
000111
Output
Draw
Input
4
01010110
00101101
Output
First
Input
4
01100000
10010011
Output
Second
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a, b = input(), input()
t = {i + j: 0 for i in '01' for j in '01'}
for i in range(2 * n): t[a[i] + b[i]] += 1
d = t['11'] & 1
d += (t['10'] - t['01'] + 1 - d) // 2
if d > 0: d = 1
elif d < 0: d = 2
print(['Draw', 'First', 'Second'][d])
``` | vfc_11874 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/293/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0111\n0001\n",
"output": "First\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 531 | Solve the following coding problem using the programming language python:
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x_1, x_2, ..., x_{n}. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y_1, y_2, ..., y_{n} in her work, that the following conditions are met: the average value of x_1, x_2, ..., x_{n} is equal to the average value of y_1, y_2, ..., y_{n}; all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x_1, x_2, ..., x_{n} ( - 100 000 ≤ x_{i} ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x_1, x_2, ..., x_{n} does not exceed 2.
-----Output-----
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y_1, y_2, ..., y_{n} — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
-----Examples-----
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
-----Note-----
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
a=list(map(int,input().split()))
mm=max(a)
mmm=min(a)
if mmm!=mm-2:
print(n)
print(*a)
else:
q,w,e=0,0,0
for i in a:
if i==mm:
e+=1
elif i==mmm:
q+=1
else:
w+=1
y=w%2+q+e
p=max(q,e)-min(q,e)
u=p+w
if y<u:
print(y)
print(*([mm]*(e+w//2)+[mmm]*(q+w//2)+[mm-1]*(w%2)))
else:
print(u)
if q>e:
print(*([mmm]*p+(n-p)*[mmm+1]))
else:
print(*([mm]*p+(n-p)*[mm-1]))
``` | vfc_11878 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/931/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n-1 1 1 0 0 -1\n",
"output": "2\n0 0 0 0 0 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n100 100 101\n",
"output": "3\n101 100 100 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n-10 -9 -10 -8 -10 -9 -9\n",
"output": "5\n-10 -10 -9 -9 -9 -9 -9 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 532 | Solve the following coding problem using the programming language python:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: [Image]
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
-----Input-----
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
-----Output-----
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
-----Examples-----
Input
zeus
Output
18
Input
map
Output
35
Input
ares
Output
34
-----Note-----
[Image]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: from 'a' to 'z' (1 rotation counterclockwise), from 'z' to 'e' (5 clockwise rotations), from 'e' to 'u' (10 rotations counterclockwise), from 'u' to 's' (2 counterclockwise rotations). In total, 1 + 5 + 10 + 2 = 18 rotations are required.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
now = "a"
ans = 0
S = input()
for s in S:
x = abs(ord(s) - ord(now))
ans += min(x, 26 - x)
now = s
print(ans)
``` | vfc_11882 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/731/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "zeus\n",
"output": "18\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 533 | Solve the following coding problem using the programming language python:
The final match of the Berland Football Cup has been held recently. The referee has shown $n$ yellow cards throughout the match. At the beginning of the match there were $a_1$ players in the first team and $a_2$ players in the second team.
The rules of sending players off the game are a bit different in Berland football. If a player from the first team receives $k_1$ yellow cards throughout the match, he can no longer participate in the match — he's sent off. And if a player from the second team receives $k_2$ yellow cards, he's sent off. After a player leaves the match, he can no longer receive any yellow cards. Each of $n$ yellow cards was shown to exactly one player. Even if all players from one team (or even from both teams) leave the match, the game still continues.
The referee has lost his records on who has received each yellow card. Help him to determine the minimum and the maximum number of players that could have been thrown out of the game.
-----Input-----
The first line contains one integer $a_1$ $(1 \le a_1 \le 1\,000)$ — the number of players in the first team.
The second line contains one integer $a_2$ $(1 \le a_2 \le 1\,000)$ — the number of players in the second team.
The third line contains one integer $k_1$ $(1 \le k_1 \le 1\,000)$ — the maximum number of yellow cards a player from the first team can receive (after receiving that many yellow cards, he leaves the game).
The fourth line contains one integer $k_2$ $(1 \le k_2 \le 1\,000)$ — the maximum number of yellow cards a player from the second team can receive (after receiving that many yellow cards, he leaves the game).
The fifth line contains one integer $n$ $(1 \le n \le a_1 \cdot k_1 + a_2 \cdot k_2)$ — the number of yellow cards that have been shown during the match.
-----Output-----
Print two integers — the minimum and the maximum number of players that could have been thrown out of the game.
-----Examples-----
Input
2
3
5
1
8
Output
0 4
Input
3
1
6
7
25
Output
4 4
Input
6
4
9
10
89
Output
5 9
-----Note-----
In the first example it could be possible that no player left the game, so the first number in the output is $0$. The maximum possible number of players that could have been forced to leave the game is $4$ — one player from the first team, and three players from the second.
In the second example the maximum possible number of yellow cards has been shown $(3 \cdot 6 + 1 \cdot 7 = 25)$, so in any case all players were sent off.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a1=int(input())
a2=int(input())
k1=int(input())
k2=int(input())
n=int(input())
ans1=0
ans2=0
if k1<k2:
ans1+=min(n//k1,a1)
ans1+=(n-ans1*k1)//k2
else :
ans1+=min(n//k2,a2)
ans1+=(n-ans1*k2)//k1
ans2=max(0,n-(k1-1)*a1-(k2-1)*a2)
print(ans2,ans1)
``` | vfc_11886 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1215/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n5\n1\n8\n",
"output": "0 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n6\n7\n25\n",
"output": "4 4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 534 | Solve the following coding problem using the programming language python:
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.
-----Input-----
The first line contains two integers n and t (1 ≤ n, t ≤ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".
-----Output-----
Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".
-----Examples-----
Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import copy
def process( s ):
res = s[:]
for i in range( 1, len(s) ):
if s[i] == 'G' and s[i - 1] == 'B':
res[i], res[i - 1] = res[i - 1], res[i]
return res
fl = input().split()
n = int( fl[0] )
t = int( fl[1] )
s = input().split()[0]
S = []
for i in range(n):
S.append( s[i] )
for i in range(t):
S = process( S )
ans = ""
for i in range(n):
ans += S[i]
print( ans )
``` | vfc_11890 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/266/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1\nBGGBG\n",
"output": "GBGGB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\nBGGBG\n",
"output": "GGBGB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\nGGGB\n",
"output": "GGGB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\nBB\n",
"output": "BB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\nBG\n",
"output": "GB\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 535 | Solve the following coding problem using the programming language python:
Makoto has a big blackboard with a positive integer $n$ written on it. He will perform the following action exactly $k$ times:
Suppose the number currently written on the blackboard is $v$. He will randomly pick one of the divisors of $v$ (possibly $1$ and $v$) and replace $v$ with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses $58$ as his generator seed, each divisor is guaranteed to be chosen with equal probability.
He now wonders what is the expected value of the number written on the blackboard after $k$ steps.
It can be shown that this value can be represented as $\frac{P}{Q}$ where $P$ and $Q$ are coprime integers and $Q \not\equiv 0 \pmod{10^9+7}$. Print the value of $P \cdot Q^{-1}$ modulo $10^9+7$.
-----Input-----
The only line of the input contains two integers $n$ and $k$ ($1 \leq n \leq 10^{15}$, $1 \leq k \leq 10^4$).
-----Output-----
Print a single integer — the expected value of the number on the blackboard after $k$ steps as $P \cdot Q^{-1} \pmod{10^9+7}$ for $P$, $Q$ defined above.
-----Examples-----
Input
6 1
Output
3
Input
6 2
Output
875000008
Input
60 5
Output
237178099
-----Note-----
In the first example, after one step, the number written on the blackboard is $1$, $2$, $3$ or $6$ — each occurring with equal probability. Hence, the answer is $\frac{1+2+3+6}{4}=3$.
In the second example, the answer is equal to $1 \cdot \frac{9}{16}+2 \cdot \frac{3}{16}+3 \cdot \frac{3}{16}+6 \cdot \frac{1}{16}=\frac{15}{8}$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def primeFactor(N):
i = 2
ret = {}
n = N
mrFlg = 0
if n < 0:
ret[-1] = 1
n = -n
if n == 0:
ret[0] = 1
while i**2 <= n:
k = 0
while n % i == 0:
n //= i
k += 1
ret[i] = k
if i == 2:
i = 3
else:
i += 2
if i == 101 and n >= (2**20):
def findFactorRho(N):
# print("FFF", N)
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
def f(x, c):
return ((x ** 2) + c) % N
semi = [N]
for c in range(1, 11):
x=2
y=2
d=1
while d == 1:
x = f(x, c)
y = f(f(y, c), c)
d = gcd(abs(x-y), N)
if d != N:
if isPrimeMR(d):
return d
elif isPrimeMR(N//d):
return N//d
else:
semi.append(d)
semi = list(set(semi))
# print (semi)
s = min(semi)
for i in [2,3,5,7]:
while True:
t = int(s**(1/i)+0.5)
if t**i == s:
s = t
if isPrimeMR(s):
return s
else:
break
i = 3
while True:
if s % i == 0:
return i
i += 2
while True:
if isPrimeMR(n):
ret[n] = 1
n = 1
break
else:
mrFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n == 1:
break
if n > 1:
ret[n] = 1
if mrFlg > 0:
def dict_sort(X):
Y={}
for x in sorted(X.keys()):
Y[x] = X[x]
return Y
ret = dict_sort(ret)
return ret
def isPrime(N):
if N <= 1:
return False
return sum(primeFactor(N).values()) == 1
def isPrimeMR(n):
# print("MR", n)
if n == 2: return True
if n == 1 or n & 1 == 0: return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
for a in [2, 3, 5, 7, 11, 13, 17, 19]:
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = (y * y) % n
t <<= 1
if y != n - 1 and t & 1 == 0:
# print("not prime")
return False
# print("prime")
return True
def findPrime(N):
if N < 0:
return -1
i = N
while True:
if isPrime(i):
return i
i += 1
def divisors(N):
pf = primeFactor(N)
ret = [1]
for p in pf:
ret_prev = ret
ret = []
for i in range(pf[p]+1):
for r in ret_prev:
ret.append(r * (p ** i))
return sorted(ret)
def mxpow(m, a, e):
if e == 1:
return a
if e % 2 == 0:
tmp = mxpow(m, a, e//2)
return mxprod(m, tmp, tmp)
else:
tmp = mxpow(m, a, e//2)
return mxprod(m, mxprod(m, tmp, tmp), a)
def mxprod(m, a, b):
ret = [[0]*m for _ in range(m)]
for i in range(m):
for j in range(m):
for k in range(m):
ret[i][j] += a[i][k] * b[k][j]
ret[i][j] %= P
return ret
def mxv(m, a, v):
ret = [0]*m
for i in range(m):
for k in range(m):
ret[i] += a[i][k] * v[k]
ret[i] %= P
return ret
def mx(m):
ret = [[0]*m for _ in range(m)]
for i in range(m):
for j in range(i, m):
ret[i][j] = inv(j+1)
return ret
def vc(m):
return [0] * (m-1) + [1]
def inv(a):
return pow(a, P-2, P)
# ----- -----
P = 10**9 + 7
n, k = list(map(int, input().split()))
# n = 6
# k = 2
pf = primeFactor(n)
# print(pf)
ans = 1
for p in pf:
m = pf[p] + 1
vvv = mxv(m, mxpow(m, mx(m), k), vc(m))
t = 0
for i in range(m):
t += (vvv[i] * p ** i) % P
t %= P
ans *= t
ans %= P
print(ans)
``` | vfc_11894 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1097/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 536 | Solve the following coding problem using the programming language python:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one.
Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
-----Input-----
The first line contains two integers: n (1 ≤ n ≤ 10^6) — the number of cards containing number 0; m (1 ≤ m ≤ 10^6) — the number of cards containing number 1.
-----Output-----
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
-----Examples-----
Input
1 2
Output
101
Input
4 8
Output
110110110101
Input
4 10
Output
11011011011011
Input
1 5
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
if m < n - 1: stdout.write('-1')
elif m == n - 1: stdout.write('0' + '10' * m)
elif m == n: stdout.write('10' * m)
elif m == n + 1: stdout.write('10' * n + '1')
else:
k = m - (n + 1)
if k > n + 1: stdout.write('-1')
elif k == n + 1: stdout.write('110' * n + '11')
else: stdout.write('110' * k + '10' * (n - k) + '1')
``` | vfc_11898 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/401/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 8\n",
"output": "110110110101\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 537 | Solve the following coding problem using the programming language python:
There are n students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.
You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
-----Input-----
The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 10^12), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.
-----Output-----
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners.
-----Examples-----
Input
18 2
Output
3 6 9
Input
9 10
Output
0 0 9
Input
1000000000000 5
Output
83333333333 416666666665 500000000002
Input
1000000000000 499999999999
Output
1 499999999999 500000000000
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = list(map(int, input().split()))
p = (n // 2) // (k + 1)
g = p * k
o = n - p - g
print(p, g, o)
``` | vfc_11902 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/818/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "18 2\n",
"output": "3 6 9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 10\n",
"output": "0 0 9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 538 | Solve the following coding problem using the programming language python:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String t is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number x. Check if it's a quasi-palindromic number.
-----Input-----
The first line contains one integer number x (1 ≤ x ≤ 10^9). This number is given without any leading zeroes.
-----Output-----
Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes).
-----Examples-----
Input
131
Output
YES
Input
320
Output
NO
Input
2010200
Output
YES
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = input()
n = n.strip('0')
print('YES' if n == n[::-1] else 'NO')
``` | vfc_11906 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/863/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "131\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "320\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2010200\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999999\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 539 | Solve the following coding problem using the programming language python:
Imp is in a magic forest, where xorangles grow (wut?)
[Image]
A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest.
Formally, for a given integer n you have to find the number of such triples (a, b, c), that:
1 ≤ a ≤ b ≤ c ≤ n; $a \oplus b \oplus c = 0$, where $x \oplus y$ denotes the bitwise xor of integers x and y. (a, b, c) form a non-degenerate (with strictly positive area) triangle.
-----Input-----
The only line contains a single integer n (1 ≤ n ≤ 2500).
-----Output-----
Print the number of xorangles of order n.
-----Examples-----
Input
6
Output
1
Input
10
Output
2
-----Note-----
The only xorangle in the first sample is (3, 5, 6).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
ans = 0
for i in range(1, n + 1):
for j in range(i, n + 1):
if 0 < i ^ j < n + 1 and i ^ j < i + j and i ^ j >= j:
ans += 1
print(ans)
``` | vfc_11910 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/922/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 540 | Solve the following coding problem using the programming language python:
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r_1, c_1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r_2, c_2) since the exit to the next level is there. Can you do this?
-----Input-----
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r_1 and c_1 (1 ≤ r_1 ≤ n, 1 ≤ c_1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r_1, c_1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r_2 and c_2 (1 ≤ r_2 ≤ n, 1 ≤ c_2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
-----Output-----
If you can reach the destination, print 'YES', otherwise print 'NO'.
-----Examples-----
Input
4 6
X...XX
...XX.
.X..X.
......
1 6
2 2
Output
YES
Input
5 4
.X..
...X
X.X.
....
.XX.
5 3
1 1
Output
NO
Input
4 7
..X.XX.
.XX..X.
X...X..
X......
2 2
1 6
Output
YES
-----Note-----
In the first sample test one possible path is:
[Image]
After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def read_data():
n, m = map(int, input().split())
maze = [[False] * (m + 2)]
for i in range(n):
maze.append([False] + [c == '.' for c in input().rstrip()] + [False])
maze.append([False] * (m + 2))
r1, c1 = map(int, input().split())
r2, c2 = map(int, input().split())
return n, m, maze, r1, c1, r2, c2
def solve(n, m, maze, r1, c1, r2, c2):
dots = count_surrounding_intact_ices(maze, r2, c2)
if maze[r2][c2] == False:
if r1 == r2 and c1 == c2:
return dots >= 1
else:
return solve_wfs(n, m, maze, r1, c1, r2, c2)
else:
if dots >= 2:
return solve_wfs(n, m, maze, r1, c1, r2, c2)
if dots == 0:
return False
if dots == 1:
return is_side_by_side(r1, c1, r2, c2)
def is_side_by_side(r1, c1, r2, c2):
if r1 == r2:
return abs(c1 - c2) == 1
if c1 == c2:
return abs(r1 - r2) == 1
return False
def count_surrounding_intact_ices(maze, r, c):
count = 0
for rr, cc in [(r+1, c), (r-1, c), (r, c+1), (r, c-1)]:
if maze[rr][cc]:
count += 1
return count
def solve_wfs(n, m, maze, r1, c1, r2, c2):
frontier = [(r1, c1)]
while frontier:
new_frontier = []
for r, c in frontier:
for nr, nc in [(r+1, c), (r-1, c), (r, c+1), (r, c-1)]:
if nr == r2 and nc == c2:
return True
if not maze[nr][nc]:
continue
maze[nr][nc] = False
new_frontier.append((nr, nc))
frontier = new_frontier
return False
def __starting_point():
n, m, maze, r1, c1, r2, c2 = read_data()
if solve(n, m, maze, r1, c1, r2, c2):
print('YES')
else:
print('NO')
__starting_point()
``` | vfc_11914 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/540/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 542 | Solve the following coding problem using the programming language python:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
-----Input-----
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·10^5).
The following n lines contain integer numbers a_{i} (|a_{i}| ≤ 10^9, a_{i} ≠ 0). If a_{i} is positive, that means that the first wrestler performed the technique that was awarded with a_{i} points. And if a_{i} is negative, that means that the second wrestler performed the technique that was awarded with ( - a_{i}) points.
The techniques are given in chronological order.
-----Output-----
If the first wrestler wins, print string "first", otherwise print "second"
-----Examples-----
Input
5
1
2
-3
-4
3
Output
second
Input
3
-1
-2
3
Output
first
Input
2
4
-4
Output
second
-----Note-----
Sequence x = x_1x_2... x_{|}x| is lexicographically larger than sequence y = y_1y_2... y_{|}y|, if either |x| > |y| and x_1 = y_1, x_2 = y_2, ... , x_{|}y| = y_{|}y|, or there is such number r (r < |x|, r < |y|), that x_1 = y_1, x_2 = y_2, ... , x_{r} = y_{r} and x_{r} + 1 > y_{r} + 1.
We use notation |a| to denote length of sequence a.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Contest 281 Div 2 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
a = []
b = []
last = 0
for i in range(n):
x, = read()
if x < 0:
b.append(-x)
last = 1
else:
a.append(x)
last = 0
if sum(a) > sum(b):
print("first")
elif sum(b) > sum(a):
print("second")
elif a > b:
print("first")
elif b > a:
print("second")
else:
print("second" if last else "first")
################################### NON-SOLUTION STUFF BELOW
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0: return inputs
if mode == 1: return inputs.split()
if mode == 2: return list(map(int, inputs.split()))
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
write(main())
``` | vfc_11922 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/493/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n-3\n-4\n3\n",
"output": "second\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-1\n-2\n3\n",
"output": "first\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n-4\n",
"output": "second\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1\n2\n-3\n4\n5\n-6\n7\n",
"output": "first\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 543 | Solve the following coding problem using the programming language python:
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition.
Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be a_{i} teams on the i-th day.
There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total).
As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days.
Sereja wants to order exactly a_{i} pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10 000) — the number of teams that will be present on each of the days.
-----Output-----
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
-----Examples-----
Input
4
1 2 1 2
Output
YES
Input
3
1 0 1
Output
NO
-----Note-----
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=input()
c=[int(x) for x in input().split()]
p=0
d=True
for i in c:
#print(p,d,i)
if i%2==0:
if p==1:
if i==0:
d=False
else:
p=1-p
print('YES' if d and p==0 else 'NO')
``` | vfc_11926 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/731/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 544 | Solve the following coding problem using the programming language python:
You are given a string $s$ consisting of $n$ lowercase Latin letters. $n$ is even.
For each position $i$ ($1 \le i \le n$) in string $s$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.
For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.
That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $\rightarrow$ 'd', 'o' $\rightarrow$ 'p', 'd' $\rightarrow$ 'e', 'e' $\rightarrow$ 'd', 'f' $\rightarrow$ 'e', 'o' $\rightarrow$ 'p', 'r' $\rightarrow$ 'q', 'c' $\rightarrow$ 'b', 'e' $\rightarrow$ 'f', 's' $\rightarrow$ 't').
String $s$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.
Your goal is to check if it's possible to make string $s$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $s$ can be transformed to a palindrome and "NO" otherwise.
Each testcase contains several strings, for each of them you are required to solve the problem separately.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 50$) — the number of strings in a testcase.
Then $2T$ lines follow — lines $(2i - 1)$ and $2i$ of them describe the $i$-th string. The first line of the pair contains a single integer $n$ ($2 \le n \le 100$, $n$ is even) — the length of the corresponding string. The second line of the pair contains a string $s$, consisting of $n$ lowercase Latin letters.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th string of the input. Print "YES" if it's possible to make the $i$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise.
-----Example-----
Input
5
6
abccba
2
cf
4
adfa
8
abaazaba
2
ml
Output
YES
NO
YES
NO
NO
-----Note-----
The first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.
The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.
The third string can be changed to "beeb" which is a palindrome.
The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def valid(a, b):
d = abs(ord(a) - ord(b))
return d == 0 or d == 2
T = int(input())
for _ in range(T):
n = int(input())
s = input()
val = all(valid(s[i], s[n - i - 1]) for i in range(n))
print('YES' if val else 'NO')
``` | vfc_11930 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1027/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml\n",
"output": "YES\nNO\nYES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\nay\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\nae\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\nya\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\nzb\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 545 | Solve the following coding problem using the programming language python:
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More formally, you are given two strings s_1, s_2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s_3 of length n, such that f(s_1, s_3) = f(s_2, s_3) = t. If there is no such string, print - 1.
-----Input-----
The first line contains two integers n and t (1 ≤ n ≤ 10^5, 0 ≤ t ≤ n).
The second line contains string s_1 of length n, consisting of lowercase English letters.
The third line contain string s_2 of length n, consisting of lowercase English letters.
-----Output-----
Print a string of length n, differing from string s_1 and from s_2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
-----Examples-----
Input
3 2
abc
xyc
Output
ayd
Input
1 0
c
b
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
import sys
n, t, s1, s2 = sys.stdin.read().split()
n, t = int(n), int(t)
result = [-1] * n
rest = n - t
for i in range(n):
if rest == 0: break
if s1[i] == s2[i]:
result[i] = s1[i]
rest -= 1
k = rest
for i in range(n):
if k == 0: break
if result[i] == -1:
result[i] = s1[i]
k -= 1
k = rest
for i in range(n):
if k == 0: break
if result[i] == -1:
result[i] = s2[i]
k -= 1
if k > 0:
print(-1)
return
for i in range(n):
if result[i] == -1:
for j in range(ord('a'), ord('a') + 4):
if chr(j) != s1[i] and chr(j) != s2[i]:
result[i] = chr(j)
break
sys.stdout.write(''.join(result))
main()
``` | vfc_11934 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/584/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\nabc\nxyc\n",
"output": "bac",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 546 | Solve the following coding problem using the programming language python:
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.
Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.
Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.
A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.
The good letters are given to Petya. All the others are bad.
-----Input-----
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.
The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 10^5). It is guaranteed that character "*" occurs in s no more than once.
The third line contains integer n (1 ≤ n ≤ 10^5) — the number of query strings.
n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.
It is guaranteed that the total length of all query strings is not greater than 10^5.
-----Output-----
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary.
-----Examples-----
Input
ab
a?a
2
aaa
aab
Output
YES
NO
Input
abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax
Output
NO
YES
NO
YES
-----Note-----
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.
Explanation of the second example. The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good. The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide. The third query: "NO", because characters "?" can't be replaced with bad letters. The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
g = set(input())
s = input()
n = int(input())
a = s.find("*")
for _ in range(n):
temp = input()
if a == -1:
if len(temp) != len(s):
print("NO")
else:
for i in range(len(s)):
if s[i] == '?':
if temp[i] not in g:
print("NO")
break
elif s[i] != temp[i]:
print("NO")
break
else:
print("YES")
else:
if len(temp) < len(s)-1:
print("NO")
else:
for i in range(a):
if s[i] == '?':
if temp[i] not in g:
print("NO")
break
elif s[i] != temp[i]:
print("NO")
break
else:
for i in range(-(len(s) - a-1), 0):
if s[i] == '?':
if temp[i] not in g:
print("NO")
break
elif s[i] != temp[i]:
print("NO")
break
else:
for i in range(a, len(temp)-(len(s) - a-1)):
if temp[i] in g:
print("NO")
break
else:
print("YES")
``` | vfc_11938 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/832/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ab\na?a\n2\naaa\naab\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax\n",
"output": "NO\nYES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "x\n?aba*\n69\nc\naaacc\nbba\nbabcb\nac\nbccca\nca\nabbaa\nb\naacca\nccc\ncc\na\naabba\nb\na\nbaca\nabb\ncac\ncbbaa\nb\naba\nbccc\nccbbc\nb\ncbab\naaabb\nc\nbbccb\nbaaa\nac\nbaa\nc\nbba\naabab\ncccb\nc\ncb\ncbab\nbb\nb\nb\nc\nbaaca\nbaca\naaa\ncaaa\na\nbcca\na\naac\naa\ncba\naacb\nacbb\nacaca\nc\ncc\nab\ncc\na\naba\nbbbbc\ncbcbc\nacb\nbbcb\nbbbcc\ncaa\ncaaac\n",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "k\n*\n89\nb\ncbbbc\ncabac\nbccbb\nccc\ncabaa\nabbaa\nccbaa\nccccb\ncabbb\nbbcbc\nbac\naaac\nabb\nbcbb\ncb\nbacc\nbbaba\nb\nacc\nbaac\naaba\nbcbba\nbaa\nbc\naaccb\nb\nab\nc\nbbbb\nabbcb\nacbb\ncba\nc\nbac\nc\nac\ncc\nb\nbbc\nbaab\nc\nbbc\nab\nb\nc\naa\naab\nab\naccbc\nacbaa\na\nccc\ncba\nb\nb\nbcccb\nca\nacabb\naa\nba\naaa\nac\ncb\nacb\nbcc\ncbc\nac\nc\nbba\naacb\nbcccb\na\ncbbb\naabc\ncbaab\nbcac\nc\nca\ncc\naccbc\nabab\nbaca\nacca\na\nab\nabb\nb\nac\n",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "t\nabac*\n68\nbcab\nbab\nbc\nab\naa\nac\ncabb\naabcc\nbba\nccbbb\nccaa\nca\nbacc\ncbbaa\na\nbbac\nacb\naba\naaaa\ncbaa\na\nabc\nccaba\nc\nacb\naba\ncacb\ncb\nacb\nabcc\ncaa\nabbb\nbaab\nc\nab\nacac\nabcc\ncc\nccca\nca\nc\nabbb\nccabc\na\ncabab\nb\nac\nbbbc\nb\nbbca\ncaa\nbbc\naa\nbcaca\nbaabc\nbcbb\nbc\nccaa\nab\nabaaa\na\ncbb\nc\nbaa\ncaa\nc\ncc\na\n",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 547 | Solve the following coding problem using the programming language python:
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.
-----Output-----
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
-----Examples-----
Input
5 2
cba
abc
bb1
abC
ABC
abc
Output
1 15
Input
4 100
11
22
1
2
22
Output
3 4
-----Note-----
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = list(map(int, input().split()))
a = []
for i in range(n):
a.append(input())
s = input()
kmn = 1
kmx = 0
for i in range(n):
if (len(a[i]) < len(s)):
kmn += 1
kmx += 1
elif (len(a[i]) == len(s)):
kmx += 1
print((kmn - 1) // k * 5 + kmn, (kmx - 1) // k * 5 + kmx)
``` | vfc_11942 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/721/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"output": "1 15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 100\n11\n22\n1\n2\n22\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\na1\na1\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 100\na1\na1\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\nabc\nAbc\nAbc\n",
"output": "1 7\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 548 | Solve the following coding problem using the programming language python:
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
-----Input-----
First line of input data contains single integer n (1 ≤ n ≤ 10^6) — length of the array.
Next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
-----Examples-----
Input
4
1 3 2 3
Output
First
Input
2
2 2
Output
Second
-----Note-----
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
nechet = 0
for el in a:
if el % 2 == 1:
nechet += 1
if nechet == 0:
print('Second')
else:
print('First')
``` | vfc_11946 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/841/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 2 3\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2\n",
"output": "Second\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 4 6 8\n",
"output": "Second\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 549 | Solve the following coding problem using the programming language python:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:
there are exactly n pixels on the display; the number of rows does not exceed the number of columns, it means a ≤ b; the difference b - a is as small as possible.
-----Input-----
The first line contains the positive integer n (1 ≤ n ≤ 10^6) — the number of pixels display should have.
-----Output-----
Print two integers — the number of rows and columns on the display.
-----Examples-----
Input
8
Output
2 4
Input
64
Output
8 8
Input
5
Output
1 5
Input
999999
Output
999 1001
-----Note-----
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(input())
for a in range(1,n+1)[::-1]:
if n%a: continue
if a>n//a: continue
print("%s %s"%(a,n//a))
break
``` | vfc_11950 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/747/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "64\n",
"output": "8 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "1 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999\n",
"output": "999 1001\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 550 | Solve the following coding problem using the programming language python:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types: transform lowercase letters to uppercase and vice versa; change letter «O» (uppercase latin letter) to digit «0» and vice versa; change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
-----Input-----
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
-----Output-----
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
-----Examples-----
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
-----Note-----
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def normalize(s):
s = s.lower()
s = s.replace("o", "0")
s = s.replace("l", "1")
s = s.replace("i", "1")
return s
query = normalize(next(sys.stdin).strip())
n = int(next(sys.stdin).strip())
for line in sys.stdin:
line = normalize(line.strip())
if query == line:
print("No")
return
print("Yes")
``` | vfc_11954 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/928/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1_wat\n2\n2_wat\nwat_1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "000\n3\n00\nooA\noOo\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "_i_\n3\n__i_\n_1_\nI\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "La0\n3\n2a0\nLa1\n1a0\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 551 | Solve the following coding problem using the programming language python:
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, y_{i}).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
-----Input-----
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≤ y_{i} ≤ 10^9) — the vertical coordinates of each point.
-----Output-----
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
5
7 5 8 6 9
Output
Yes
Input
5
-1 -2 0 0 -5
Output
No
Input
5
5 4 3 2 1
Output
No
Input
5
1000000000 0 0 0 0
Output
Yes
-----Note-----
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n = int(input())
a = list(map(int, input().split()))
if a[1] - a[0] == a[2] - a[1]:
d = a[1] - a[0]
c1 = a[0]
c2 = 'no'
for i in range(3, n):
if i * d + c1 == a[i]:
pass
elif c2 == 'no':
c2 = a[i] - d * i
elif i * d + c2 == a[i]:
pass
else:
print('No')
return
if c2 == 'no':
print('No')
else:
print('Yes')
return
else:
f = True
d = a[1] - a[0]
c1 = a[0]
c2 = a[2] - 2 * d
#print(d, c1, c2)
for i in range(3, n):
if (a[i] == i * d + c1) or (a[i] == i * d + c2):
pass
else:
f = False
break
if f:
print('Yes')
return
f = True
d = a[2] - a[1]
c1 = a[1] - d
c2 = a[0]
#print(d, c1, c2)
for i in range(3, n):
if (a[i] == i * d + c1) or (a[i] == i * d + c2):
pass
else:
f = False
break
if f:
print('Yes')
return
f = True
d = (a[2] - a[0]) / 2
c1 = a[0]
c2 = a[1] - d
#print(d, c1, c2)
for i in range(3, n):
#print(a[i], i * d + c1, i * d + c2)
if (a[i] == i * d + c1) or (a[i] == i * d + c2):
pass
else:
f = False
break
if f:
print('Yes')
else:
print('No')
main()
``` | vfc_11958 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/849/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n7 5 8 6 9\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n-1 -2 0 0 -5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 4 3 2 1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1000000000 0 0 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1000000000 1 0 -999999999 -1000000000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n998 244 353\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 552 | Solve the following coding problem using the programming language python:
Vasya had three strings $a$, $b$ and $s$, which consist of lowercase English letters. The lengths of strings $a$ and $b$ are equal to $n$, the length of the string $s$ is equal to $m$.
Vasya decided to choose a substring of the string $a$, then choose a substring of the string $b$ and concatenate them. Formally, he chooses a segment $[l_1, r_1]$ ($1 \leq l_1 \leq r_1 \leq n$) and a segment $[l_2, r_2]$ ($1 \leq l_2 \leq r_2 \leq n$), and after concatenation he obtains a string $a[l_1, r_1] + b[l_2, r_2] = a_{l_1} a_{l_1 + 1} \ldots a_{r_1} b_{l_2} b_{l_2 + 1} \ldots b_{r_2}$.
Now, Vasya is interested in counting number of ways to choose those segments adhering to the following conditions:
segments $[l_1, r_1]$ and $[l_2, r_2]$ have non-empty intersection, i.e. there exists at least one integer $x$, such that $l_1 \leq x \leq r_1$ and $l_2 \leq x \leq r_2$; the string $a[l_1, r_1] + b[l_2, r_2]$ is equal to the string $s$.
-----Input-----
The first line contains integers $n$ and $m$ ($1 \leq n \leq 500\,000, 2 \leq m \leq 2 \cdot n$) — the length of strings $a$ and $b$ and the length of the string $s$.
The next three lines contain strings $a$, $b$ and $s$, respectively. The length of the strings $a$ and $b$ is $n$, while the length of the string $s$ is $m$.
All strings consist of lowercase English letters.
-----Output-----
Print one integer — the number of ways to choose a pair of segments, which satisfy Vasya's conditions.
-----Examples-----
Input
6 5
aabbaa
baaaab
aaaaa
Output
4
Input
5 4
azaza
zazaz
azaz
Output
11
Input
9 12
abcabcabc
xyzxyzxyz
abcabcayzxyz
Output
2
-----Note-----
Let's list all the pairs of segments that Vasya could choose in the first example:
$[2, 2]$ and $[2, 5]$; $[1, 2]$ and $[2, 4]$; $[5, 5]$ and $[2, 5]$; $[5, 6]$ and $[3, 5]$;
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys, logging
logging.basicConfig(level=logging.INFO)
logging.disable(logging.INFO)
def build(S, n):
Z = [0 for i in range(3 * n + 3)]
#logging.info(S)
n = len(S)
L = 0
R = 0
Z[0] = n
for i in range(1, n):
if(i > R):
L = R = i
while(R < n and S[R] == S[R - L]):
R += 1
Z[i] = R - L
R -= 1
else:
k = i - L
if(Z[k] < R - i + 1):
Z[i] = Z[k]
else:
L = i
while(R < n and S[R] == S[R - L]):
R += 1
Z[i] = R - L
R -= 1
return Z
def update1(n, x, val):
while(x <= n + 1):
bit1[x] += val
x += x & -x
def get1(n, x):
ans = 0
while(x > 0):
ans += bit1[x]
x -= x & -x
return ans
def update2(n, x, val):
while(x <= n + 1):
bit2[x] += val
x += x & -x
def get2(n, x):
ans = 0
while(x > 0):
ans += bit2[x]
x -= x & -x
return ans
def process(n, m, fa, fb):
r2 = int(1)
ans = 0
for l1 in range(1, n + 1):
while(r2 <= min(n, l1 + m - 2)):
update1(n, m - fb[r2] + 1, 1)
update2(n, m - fb[r2] + 1, fb[r2] - m + 1)
r2 += 1
ans += get1(n, fa[l1] + 1) * fa[l1] + get2(n, fa[l1] + 1)
update1(n, m - fb[l1] + 1, -1)
update2(n, m - fb[l1] + 1, m - 1 - fb[l1])
print(ans)
def main():
n, m = map(int, sys.stdin.readline().split())
a = sys.stdin.readline()
b = sys.stdin.readline()
s = sys.stdin.readline()
a = a[:(len(a) - 1)]
b = b[:(len(b) - 1)]
s = s[:(len(s) - 1)]
fa = build(s + a, n)
kb = build(s[::-1] + b[::-1], n)
fb = [0 for k in range(n + 2)]
for i in range(m, m + n):
fa[i - m + 1] = fa[i]
if(fa[i - m + 1] >= m):
fa[i - m + 1] = m - 1
fb[m + n - i] = kb[i]
if(fb[m + n - i] >= m):
fb[m + n - i] = m - 1
logging.info(fa[1:(n + 1)])
logging.info(fb[1:(n + 1)])
process(n, m, fa, fb)
bit1 = [0 for i in range(500004)]
bit2 = [0 for i in range(500004)]
def __starting_point():
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
main()
__starting_point()
``` | vfc_11962 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1313/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 5\naabbaa\nbaaaab\naaaaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\nazaza\nzazaz\nazaz\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 553 | Solve the following coding problem using the programming language python:
During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum k, that the promotional code could be uniquely identified if it was typed with no more than k errors. At that, k = 0 means that the promotional codes must be entered exactly.
A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.
-----Input-----
The first line of the output contains number n (1 ≤ n ≤ 1000) — the number of promocodes.
Each of the next n lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".
-----Output-----
Print the maximum k (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most k mistakes.
-----Examples-----
Input
2
000000
999999
Output
2
Input
6
211111
212111
222111
111111
112111
121111
Output
0
-----Note-----
In the first sample k < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
m = 6
arr = []
for i in range(n):
arr.append(input())
for i in range(n - 1):
for j in range(i + 1, n):
d = 0
for z in range(6):
if arr[i][z] != arr[j][z]:
d += 1
if d == 6:
m = min(m, 2)
elif d == 5:
m = min(m, 2)
elif d == 4:
m = min(m, 1)
elif d == 3:
m = min(m, 1)
else:
m = 0
print(m)
``` | vfc_11966 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/637/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n000000\n999999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n211111\n212111\n222111\n111111\n112111\n121111\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n123456\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n000000\n099999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n000000\n009999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n000000\n000999\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 554 | Solve the following coding problem using the programming language python:
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is a_{i}. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1, - 2, 1, 3, - 4. Suppose the mother suggested subarrays (1, - 2), (3, - 4), (1, 3), (1, - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then: the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays, the second flower adds ( - 2)·1 = - 2, because he is in one of chosen subarrays, the third flower adds 1·2 = 2, because he is in two of chosen subarrays, the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays, the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays.
Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — n integers a_1, a_2, ..., a_{n} ( - 100 ≤ a_{i} ≤ 100).
The next m lines contain the description of the subarrays suggested by the mother. The i-th of these lines contain two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) denoting the subarray a[l_{i}], a[l_{i} + 1], ..., a[r_{i}].
Each subarray can encounter more than once.
-----Output-----
Print single integer — the maximum possible value added to the Alyona's happiness.
-----Examples-----
Input
5 4
1 -2 1 3 -4
1 2
4 5
3 4
1 4
Output
7
Input
4 3
1 2 3 4
1 3
2 4
1 1
Output
16
Input
2 2
-1 -2
1 1
1 2
Output
0
-----Note-----
The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
pr = [0 for i in range(len(a))]
for i in range(1, len(a)):
pr[i] = pr[i - 1] + a[i]
ans = 0
for i in range(m):
l, r = list(map(int, input().split()))
cur = pr[r] - pr[l - 1]
if cur >= 0:
ans += cur
print(ans)
``` | vfc_11970 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/740/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n-1 -2\n1 1\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 555 | Solve the following coding problem using the programming language python:
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.
Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
-----Input-----
The first line contains a single integer x (1 ≤ x ≤ 10^18) — the number that Luke Skywalker gave to Chewbacca.
-----Output-----
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
-----Examples-----
Input
27
Output
22
Input
4545
Output
4444
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x = list(input())
for i in range(len(x)):
if(i==0 and x[i]=='9'):
continue
if(int(x[i])>9-int(x[i])):
x[i] = str(9-int(x[i]))
y=0
for item in x:
y*=10
y+=int(item)
print(y)
``` | vfc_11974 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/514/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "27\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4545\n",
"output": "4444\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 556 | Solve the following coding problem using the programming language python:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)
Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
-----Input-----
The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 10^18, 2 ≤ k ≤ 10^9).
-----Output-----
Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
-----Examples-----
Input
1 10 2
Output
1 2 4 8
Input
2 4 5
Output
-1
-----Note-----
Note to the first sample: numbers 2^0 = 1, 2^1 = 2, 2^2 = 4, 2^3 = 8 lie within the specified range. The number 2^4 = 16 is greater then 10, thus it shouldn't be printed.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
l, r, n = map(int, input().split())
a = n
n = 1
cnt = 0
while n <= r:
if n >= l:
cnt += 1
print(n, end=' ')
n *= a
if cnt == 0:
print(-1)
``` | vfc_11978 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/614/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10 2\n",
"output": "1 2 4 8 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4 5\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "18102 43332383920 28554\n",
"output": "28554 815330916 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "19562 31702689720 17701\n",
"output": "313325401 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11729 55221128400 313\n",
"output": "97969 30664297 9597924961 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 557 | Solve the following coding problem using the programming language python:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point m on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds. [Image]
Determine if Pig can visit the friend using teleports only, or he should use his car.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house.
The next n lines contain information about teleports.
The i-th of these lines contains two integers a_{i} and b_{i} (0 ≤ a_{i} ≤ b_{i} ≤ m), where a_{i} is the location of the i-th teleport, and b_{i} is its limit.
It is guaranteed that a_{i} ≥ a_{i} - 1 for every i (2 ≤ i ≤ n).
-----Output-----
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
-----Examples-----
Input
3 5
0 2
2 4
3 5
Output
YES
Input
3 7
0 4
2 5
6 7
Output
NO
-----Note-----
The first example is shown on the picture below: [Image]
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below: [Image]
You can see that there is no path from Pig's house to his friend's house that uses only teleports.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = map(int, input().split())
d = []
for i in range(n):
d.append(list(map(int, input().split())))
k = 0
for i in d:
if i[0] <= k:
k = max(k, i[1])
if k >= m:
print('YES')
else:
print('NO')
``` | vfc_11982 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/902/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n0 2\n2 4\n3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n0 4\n2 5\n6 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n0 0\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 560 | Solve the following coding problem using the programming language python:
You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows: [Image]
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat.
-----Input-----
The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these: '.' character denotes a cake cell with no evil strawberry; 'S' character denotes a cake cell with an evil strawberry.
-----Output-----
Output the maximum number of cake cells that the cakeminator can eat.
-----Examples-----
Input
3 4
S...
....
..S.
Output
8
-----Note-----
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). [Image] [Image] [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
r, c = list(map(int, input().split()))
cake = [input().strip() for _ in range(r)]
ans = 0
for i in range(r):
for j in range(c):
if cake[i][j] == '.' and ('S' not in cake[i] or 'S' not in list(zip(*cake))[j]):
ans += 1
print(ans)
``` | vfc_11994 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/330/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\nS...\n....\n..S.\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n..\n..\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 561 | Solve the following coding problem using the programming language python:
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a_1, a_2, ..., a_{n} of length n, that the following condition fulfills: a_2 - a_1 = a_3 - a_2 = a_4 - a_3 = ... = a_{i} + 1 - a_{i} = ... = a_{n} - a_{n} - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 10^5) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 10^8.
-----Output-----
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 10^8 or even be negative (see test samples).
-----Examples-----
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
a=list(map(int,input().split()))
if n==1:
print(-1)
return
a.sort()
d=[]
for i in range(1,n):
d.append(a[i]-a[i-1])
if min(d)==max(d)==0:
print(1)
print(a[0])
elif n==2:
if d[0]%2:
print(2)
print(a[0]-d[0],a[1]+d[0])
else:
print(3)
print(a[0]-d[0],a[0]+d[0]//2,a[1]+d[0])
elif min(d)==max(d):
print(2)
print(a[0]-d[0],a[-1]+d[0])
else:
m1=0
m2=0
for i in range(1,n-1):
if d[i]<d[m1]: m1=i
if d[i]>d[m2]: m2=i
c=d.count(d[m1])
if c==n-2 and d[m1]*2==d[m2]:
print(1)
print(a[m2]+d[m1])
else:
print(0)
``` | vfc_11998 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/382/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 1 7\n",
"output": "2\n-2 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 5 9\n",
"output": "1\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 562 | Solve the following coding problem using the programming language python:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment l_{i} and ends at moment r_{i}.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.
Polycarp wants to check out all n shows. Are two TVs enough to do so?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 2·10^5) — the number of shows.
Each of the next n lines contains two integers l_{i} and r_{i} (0 ≤ l_{i} < r_{i} ≤ 10^9) — starting and ending time of i-th show.
-----Output-----
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
-----Examples-----
Input
3
1 2
2 3
4 5
Output
YES
Input
4
1 2
2 3
2 3
1 2
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
shows = []
for i in range(n):
l, r = map(int, input().split())
shows.append((l,r))
shows.sort()
a_endtime, b_endtime = -1, -1
for show in shows:
if show[0] <= a_endtime:
print('NO')
break
else:
a_endtime = show[1]
if a_endtime > b_endtime:
a_endtime, b_endtime = b_endtime, a_endtime
else:
print('YES')
``` | vfc_12002 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/845/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n2 3\n4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2\n2 3\n2 3\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 563 | Solve the following coding problem using the programming language python:
Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r.
More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.
-----Input-----
The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 10^18; r - l ≤ 50).
-----Output-----
Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
-----Examples-----
Input
2 4
Output
2 3 4
Input
10 11
Output
-1
Input
900000000000000009 900000000000000029
Output
900000000000000009 900000000000000010 900000000000000021
-----Note-----
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin
from fractions import gcd
lines = list([_f for _f in stdin.read().split('\n') if _f])
def parseline(line):
return list(map(int, line.split()))
lines = list(map(parseline, lines))
l, r = lines[0]
for a in range(l, r+1):
for b in range(a, r+1):
for c in range(b, r + 1):
if gcd(a, b) == gcd(b, c) == 1 != gcd(a, c):
print(a, b, c)
return
print(-1)
``` | vfc_12006 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/483/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n",
"output": "2 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 11\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 564 | Solve the following coding problem using the programming language python:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.
As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (n - 1) friends. Determine if Sereja's friends can play the game so that nobody loses.
-----Input-----
The first line contains integers n and s (2 ≤ n ≤ 100; 1 ≤ s ≤ 1000) — the number of mugs and the volume of the cup. The next line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10). Number a_{i} means the volume of the i-th mug.
-----Output-----
In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.
-----Examples-----
Input
3 4
1 1 1
Output
YES
Input
3 4
3 1 3
Output
YES
Input
3 4
4 4 4
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,s=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if sum(a[:-1])<=s:
print('YES')
else:
print('NO')
``` | vfc_12010 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/426/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n3 1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 565 | Solve the following coding problem using the programming language python:
Alice and Bob are decorating a Christmas Tree.
Alice wants only $3$ types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have $y$ yellow ornaments, $b$ blue ornaments and $r$ red ornaments.
In Bob's opinion, a Christmas Tree will be beautiful if: the number of blue ornaments used is greater by exactly $1$ than the number of yellow ornaments, and the number of red ornaments used is greater by exactly $1$ than the number of blue ornaments.
That is, if they have $8$ yellow ornaments, $13$ blue ornaments and $9$ red ornaments, we can choose $4$ yellow, $5$ blue and $6$ red ornaments ($5=4+1$ and $6=5+1$).
Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.
In the example two paragraphs above, we would choose $7$ yellow, $8$ blue and $9$ red ornaments. If we do it, we will use $7+8+9=24$ ornaments. That is the maximum number.
Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree!
It is guaranteed that it is possible to choose at least $6$ ($1+2+3=6$) ornaments.
-----Input-----
The only line contains three integers $y$, $b$, $r$ ($1 \leq y \leq 100$, $2 \leq b \leq 100$, $3 \leq r \leq 100$) — the number of yellow, blue and red ornaments.
It is guaranteed that it is possible to choose at least $6$ ($1+2+3=6$) ornaments.
-----Output-----
Print one number — the maximum number of ornaments that can be used.
-----Examples-----
Input
8 13 9
Output
24
Input
13 3 6
Output
9
-----Note-----
In the first example, the answer is $7+8+9=24$.
In the second example, the answer is $2+3+4=9$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
y,b,r=map(int,input().split())
m=min(y,b-1,r-2)
print(3*m+3)
``` | vfc_12014 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1091/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 13 9\n",
"output": "24",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 3 6\n",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 8 20\n",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 3\n",
"output": "6",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 566 | Solve the following coding problem using the programming language python:
You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.
-----Input-----
The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·10^9) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
-----Output-----
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
-----Examples-----
Input
5 4 3
Output
4
Input
1 1 1
Output
1
Input
2 3 3
Output
2
-----Note-----
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
r, g, b = map(int, input().split())
maxi = (r + g + b) // 3
print(min(maxi, r + g, r + b, g + b))
``` | vfc_12018 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/478/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 567 | Solve the following coding problem using the programming language python:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position a_{i}. Positions of all prizes are distinct. You start at position 1, your friend — at position 10^6 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position x to position x + 1 or x - 1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of prizes.
The second line contains n integers a_1, a_2, ..., a_{n} (2 ≤ a_{i} ≤ 10^6 - 1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
-----Output-----
Print one integer — the minimum number of seconds it will take to collect all prizes.
-----Examples-----
Input
3
2 3 9
Output
8
Input
2
2 999995
Output
5
-----Note-----
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
e = 1000000
ans = max(min(x - 1, e - x) for x in a)
print(ans)
``` | vfc_12022 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/938/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 9\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 568 | Solve the following coding problem using the programming language python:
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.
More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have a_{i} coins. If there is an integer i (0 ≤ i < n) such that a_{i} + a_{i} + n + a_{i} + 2n ≠ 6, then Tanya is satisfied.
Count the number of ways to choose a_{i} so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 10^9 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that a_{i} ≠ b_{i} (that is, some gnome got different number of coins in these two ways).
-----Input-----
A single line contains number n (1 ≤ n ≤ 10^5) — the number of the gnomes divided by three.
-----Output-----
Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 10^9 + 7.
-----Examples-----
Input
1
Output
20
Input
2
Output
680
-----Note-----
20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
print((3 ** (3 * n) - 7 ** n) % 1000000007)
``` | vfc_12026 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/584/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "20",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "680",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "19340",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "529040",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "14332100",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 570 | Solve the following coding problem using the programming language python:
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
-----Input-----
Single line of input data contains two space-separated integers a, b (1 ≤ a, b ≤ 10^9) — number of Vladik and Valera candies respectively.
-----Output-----
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
-----Examples-----
Input
1 1
Output
Valera
Input
7 6
Output
Vladik
-----Note-----
Illustration for first test case:
[Image]
Illustration for second test case:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = map(int,input().split())
i = 1
while 1:
if a < i:
print("Vladik")
break
a-= i
i+= 1
if b < i:
print("Valera")
break
b-= i
i+= 1
``` | vfc_12034 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/811/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "Valera\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 6\n",
"output": "Vladik\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25 38\n",
"output": "Vladik\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8311 2468\n",
"output": "Valera\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "250708 857756\n",
"output": "Vladik\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 571 | Solve the following coding problem using the programming language python:
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.
In his favorite math class, the teacher taught him the following interesting definitions.
A parenthesis sequence is a string, containing only characters "(" and ")".
A correct parenthesis sequence is a parenthesis sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, parenthesis sequences "()()", "(())" are correct (the resulting expressions are: "(1+1)+(1+1)", "((1+1)+1)"), while ")(" and ")" are not. Note that the empty string is a correct parenthesis sequence by definition.
We define that $|s|$ as the length of string $s$. A strict prefix $s[1\dots l]$ $(1\leq l< |s|)$ of a string $s = s_1s_2\dots s_{|s|}$ is string $s_1s_2\dots s_l$. Note that the empty string and the whole string are not strict prefixes of any string by the definition.
Having learned these definitions, he comes up with a new problem. He writes down a string $s$ containing only characters "(", ")" and "?". And what he is going to do, is to replace each of the "?" in $s$ independently by one of "(" and ")" to make all strict prefixes of the new sequence not a correct parenthesis sequence, while the new sequence should be a correct parenthesis sequence.
After all, he is just a primary school student so this problem is too hard for him to solve. As his best friend, can you help him to replace the question marks? If there are many solutions, any of them is acceptable.
-----Input-----
The first line contains a single integer $|s|$ ($1\leq |s|\leq 3 \cdot 10^5$), the length of the string.
The second line contains a string $s$, containing only "(", ")" and "?".
-----Output-----
A single line contains a string representing the answer.
If there are many solutions, any of them is acceptable.
If there is no answer, print a single line containing ":(" (without the quotes).
-----Examples-----
Input
6
(?????
Output
(()())
Input
10
(???(???(?
Output
:(
-----Note-----
It can be proved that there is no solution for the second sample, so print ":(".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = q = int(input())
k = list(input())
cntl = k.count('(')
cntr = k.count(')')
cntq = k.count('?')
for i in range(n):
if k[i] == '?':
if cntl < q // 2 and cntr + cntq >= q // 2:
k[i] = '('
cntl += 1
cntq -= 1
else:
k[i] = ')'
cntr += 1
cntq -= 1
def check():
cnt = 0
m = 0
for i in k:
m += 1
if i == '(':
cnt += 1
else:
cnt -= 1
if cnt == 0 and m < n or cnt < 0:
return False
return cnt == 0
print(''.join(k) if check() else ':(')
``` | vfc_12038 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1153/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n(?????\n",
"output": "((()))\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n(???(???(?\n",
"output": ":(\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 572 | Solve the following coding problem using the programming language python:
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally:
Let a_0, a_1, ..., a_{n} denote the coefficients, so $P(x) = \sum_{i = 0}^{n} a_{i} \cdot x^{i}$. Then, a polynomial P(x) is valid if all the following conditions are satisfied: a_{i} is integer for every i; |a_{i}| ≤ k for every i; a_{n} ≠ 0.
Limak has recently got a valid polynomial P with coefficients a_0, a_1, a_2, ..., a_{n}. He noticed that P(2) ≠ 0 and he wants to change it. He is going to change one coefficient to get a valid polynomial Q of degree n that Q(2) = 0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10^9) — the degree of the polynomial and the limit for absolute values of coefficients.
The second line contains n + 1 integers a_0, a_1, ..., a_{n} (|a_{i}| ≤ k, a_{n} ≠ 0) — describing a valid polynomial $P(x) = \sum_{i = 0}^{n} a_{i} \cdot x^{i}$. It's guaranteed that P(2) ≠ 0.
-----Output-----
Print the number of ways to change one coefficient to get a valid polynomial Q that Q(2) = 0.
-----Examples-----
Input
3 1000000000
10 -9 -3 5
Output
3
Input
3 12
10 -9 -3 5
Output
2
Input
2 20
14 -7 19
Output
0
-----Note-----
In the first sample, we are given a polynomial P(x) = 10 - 9x - 3x^2 + 5x^3.
Limak can change one coefficient in three ways: He can set a_0 = - 10. Then he would get Q(x) = - 10 - 9x - 3x^2 + 5x^3 and indeed Q(2) = - 10 - 18 - 12 + 40 = 0. Or he can set a_2 = - 8. Then Q(x) = 10 - 9x - 8x^2 + 5x^3 and indeed Q(2) = 10 - 18 - 32 + 40 = 0. Or he can set a_1 = - 19. Then Q(x) = 10 - 19x - 3x^2 + 5x^3 and indeed Q(2) = 10 - 38 - 12 + 40 = 0.
In the second sample, we are given the same polynomial. This time though, k is equal to 12 instead of 10^9. Two first of ways listed above are still valid but in the third way we would get |a_1| > k what is not allowed. Thus, the answer is 2 this time.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def convert_to_binary(coef):
res = []
n = len(coef)
carry = 0
i = 0
while i < n + 1000:
if i >= n and not carry:
break
cur = carry
if i < n:
cur += coef[i]
mod = cur % 2
div = cur // 2
# print(cur, div, mod)
res.append(mod)
carry = div
i += 1
return res, carry
n, k = list(map(int, input().split()))
coef = list(map(int, input().split()))
b, carry = convert_to_binary(coef)
ref = False
if carry < 0:
b, carry = convert_to_binary(list([-x for x in coef]))
ref = True
last = len(b) - 1
while b[last] != 1:
last -= 1
ans = 0
for i in range(0, n + 1):
if last - i > 40:
continue
cur = 0
for j in range(i, last + 1):
cur += b[j] * (2 ** (j - i))
new_coef = coef[i] - cur
if ref:
new_coef = coef[i] + cur
if abs(new_coef) > k:
if b[i] == 1:
break
continue
if i == n and new_coef == 0:
if b[i] == 1:
break
continue
ans += 1
if b[i] == 1:
break
print(ans)
``` | vfc_12042 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/639/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1000000000\n10 -9 -3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 12\n10 -9 -3 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 20\n14 -7 19\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 573 | Solve the following coding problem using the programming language python:
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 2·10^5) — the number of groups.
The second line contains a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 2), where a_{i} is the number of people in group i.
-----Output-----
Print the maximum number of teams of three people the coach can form.
-----Examples-----
Input
4
1 1 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
-----Note-----
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way: The first group (of two people) and the seventh group (of one person), The second group (of two people) and the sixth group (of one person), The third group (of two people) and the fourth group (of one person).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
d = list(map(int, input().split()))
s = {i:0 for i in [1, 2]}
for i in d:
s[i] += 1
if s[2] >= s[1]:
print(s[1])
else:
print(s[2] + (s[1] - s[2]) // 3)
``` | vfc_12046 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/899/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 574 | Solve the following coding problem using the programming language python:
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.
More formally, if a game designer selected cells having coordinates (x_1, y_1) and (x_2, y_2), where x_1 ≤ x_2 and y_1 ≤ y_2, then all cells having center coordinates (x, y) such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x_2 - x_1 is divisible by 2.
Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.
Help him implement counting of these units before painting.
[Image]
-----Input-----
The only line of input contains four integers x_1, y_1, x_2, y_2 ( - 10^9 ≤ x_1 ≤ x_2 ≤ 10^9, - 10^9 ≤ y_1 ≤ y_2 ≤ 10^9) — the coordinates of the centers of two cells.
-----Output-----
Output one integer — the number of cells to be filled.
-----Examples-----
Input
1 1 5 5
Output
13
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x1, y1, x2, y2 = map(int, input().split())
dx, dy = (x2 - x1) // 2, (y2 - y1) // 2
print(dx + 1 + (2 * dx + 1) * dy)
``` | vfc_12050 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/630/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 5 5\n",
"output": "13",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1 -3 1 3\n",
"output": "11",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 575 | Solve the following coding problem using the programming language python:
Alice and Bob are playing chess on a huge chessboard with dimensions $n \times n$. Alice has a single piece left — a queen, located at $(a_x, a_y)$, while Bob has only the king standing at $(b_x, b_y)$. Alice thinks that as her queen is dominating the chessboard, victory is hers.
But Bob has made a devious plan to seize the victory for himself — he needs to march his king to $(c_x, c_y)$ in order to claim the victory for himself. As Alice is distracted by her sense of superiority, she no longer moves any pieces around, and it is only Bob who makes any turns.
Bob will win if he can move his king from $(b_x, b_y)$ to $(c_x, c_y)$ without ever getting in check. Remember that a king can move to any of the $8$ adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen.
Find whether Bob can win or not.
-----Input-----
The first line contains a single integer $n$ ($3 \leq n \leq 1000$) — the dimensions of the chessboard.
The second line contains two integers $a_x$ and $a_y$ ($1 \leq a_x, a_y \leq n$) — the coordinates of Alice's queen.
The third line contains two integers $b_x$ and $b_y$ ($1 \leq b_x, b_y \leq n$) — the coordinates of Bob's king.
The fourth line contains two integers $c_x$ and $c_y$ ($1 \leq c_x, c_y \leq n$) — the coordinates of the location that Bob wants to get to.
It is guaranteed that Bob's king is currently not in check and the target location is not in check either.
Furthermore, the king is not located on the same square as the queen (i.e. $a_x \neq b_x$ or $a_y \neq b_y$), and the target does coincide neither with the queen's position (i.e. $c_x \neq a_x$ or $c_y \neq a_y$) nor with the king's position (i.e. $c_x \neq b_x$ or $c_y \neq b_y$).
-----Output-----
Print "YES" (without quotes) if Bob can get from $(b_x, b_y)$ to $(c_x, c_y)$ without ever getting in check, otherwise print "NO".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
8
4 4
1 3
3 1
Output
YES
Input
8
4 4
2 3
1 6
Output
NO
Input
8
3 5
1 2
6 1
Output
NO
-----Note-----
In the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.
In the first case, the king can move, for instance, via the squares $(2, 3)$ and $(3, 2)$. Note that the direct route through $(2, 2)$ goes through check.
[Image]
In the second case, the queen watches the fourth rank, and the king has no means of crossing it.
[Image]
In the third case, the queen watches the third file.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
ax, ay = list(map(int, input().split(' ')))
bx, by = list(map(int, input().split(' ')))
cx, cy = list(map(int, input().split(' ')))
if ((cx < ax) == (bx < ax)) and ((cy < ay) == (by < ay)):
print('YES')
else:
print('NO')
``` | vfc_12054 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1033/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n4 4\n1 3\n3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n4 4\n2 3\n1 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n3 5\n1 2\n6 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n500 200\n350 300\n400 401\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 576 | Solve the following coding problem using the programming language python:
Given an array $a$, consisting of $n$ integers, find:
$$\max\limits_{1 \le i < j \le n} LCM(a_i,a_j),$$
where $LCM(x, y)$ is the smallest positive integer that is divisible by both $x$ and $y$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, 3) = 6$.
-----Input-----
The first line contains an integer $n$ ($2 \le n \le 10^5$) — the number of elements in the array $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^5$) — the elements of the array $a$.
-----Output-----
Print one integer, the maximum value of the least common multiple of two elements in the array $a$.
-----Examples-----
Input
3
13 35 77
Output
1001
Input
6
1 2 4 8 16 32
Output
32
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
N = 10**5 + 10
u = [-1]*N
divi = [ [] for i in range(N) ]
pd = [ [] for i in range(N) ]
mark = [0]*N
def precalc():
for i in range(1,N) :
for j in range(i,N,i) :
divi[j].append(i)
for i in range(2,N) :
if mark[i] == 1 :
continue
for j in range(i,N,i) :
pd[j].append(i)
mark[j] = 1
for i in range(1,N) :
for prm in pd[i] :
time = 0
_i = i
while _i % prm == 0 :
time += 1
_i /= prm
if time > 1 :
u[i] = 0
continue
if u[i] == -1 :
if len(pd[i]) & 1 :
u[i] = -1
else :
u[i] = 1
has = [False]*N
cnt = [0]*N
def has_coprime(n):
ret = 0
for d in divi[n] :
ret += u[d] * cnt[d]
return ret
def update(n,val) :
for d in divi[n] :
cnt[d] += val
def solve(n) :
li = list(map(int,input().split()))
ans = 0
for i in range(n) :
if has[li[i]] :
ans = max(ans,li[i])
has[li[i]] = True
for g in range(1,N) :
st = []
for num in reversed(list(range(1,N//g + 1))) :
if num*g > N-1 or not has[num*g] :
continue
how_many = has_coprime(num)
while how_many > 0 :
#print(how_many)
now = st.pop()
if math.gcd(now,num) == 1 :
ans = max(ans,num*now*g)
how_many -= 1
update(now,-1)
st.append(num)
update(num,1)
while st :
update(st.pop(),-1)
print(ans)
precalc()
while True :
try :
n = int(input())
solve(n)
except EOFError:
break
``` | vfc_12058 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1285/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n13 35 77\n",
"output": "1001",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 4 8 16 32\n",
"output": "32",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 5\n",
"output": "10",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 577 | Solve the following coding problem using the programming language python:
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries.
Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with $5$ red and $2$ blue berries in the first shrub and $2$ red and $1$ blue berries in the second shrub then Phoenix can fill $2$ baskets of capacity $4$ completely: the first basket will contain $3$ red and $1$ blue berries from the first shrub; the second basket will contain the $2$ remaining red berries from the first shrub and $2$ red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
-----Input-----
The first line contains two integers $n$ and $k$ ($ 1\le n, k \le 500$) — the number of shrubs and the basket capacity, respectively.
The $i$-th of the next $n$ lines contain two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$) — the number of red and blue berries in the $i$-th shrub, respectively.
-----Output-----
Output one integer — the maximum number of baskets that Phoenix can fill completely.
-----Examples-----
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
-----Note-----
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than $5$ berries in each shrub, less than $5$ total red berries, and less than $5$ total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def check(k, aas, bs, a_rem, b_rem):
if a_rem + b_rem < k:
return False
a_lo = k - b_rem
a_hi = a_rem
rems = set()
rems.add(0)
for a, b in zip(aas, bs):
if a + b < k:
continue
for i in range(max(0, k - b), min(a, k) + 1):
rem = i % k
for j in list(rems):
rems.add((j + rem) % k)
for rem in rems:
if rem >= a_lo and rem <= a_hi:
return True
return False
n, k = [int(x) for x in input().split()]
aas = []
bs = []
a_total = 0
b_total = 0
for i in range(n):
a, b = [int(x) for x in input().split()]
aas.append(a)
bs.append(b)
a_total += a
b_total += b
ans = a_total // k + b_total // k
if check(k, aas, bs, a_total % k, b_total % k):
print(ans + 1)
else:
print(ans)
``` | vfc_12062 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1348/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n5 2\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n2 1\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n1000000000 1\n",
"output": "500000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n999999999 1\n",
"output": "200000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 578 | Solve the following coding problem using the programming language python:
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. [Image]
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10^{B} is true. In our case A is between 0 and 9 and B is non-negative.
Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.
-----Input-----
The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10^100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value.
a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.
-----Output-----
Print the only real number x (the desired distance value) in the only line in its decimal notation.
Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).
-----Examples-----
Input
8.549e2
Output
854.9
Input
8.549e3
Output
8549
Input
0.33e0
Output
0.33
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
a = str()
b = str()
f = False
for i in range(len(s)):
if s[i] == 'e':
f = True
elif f:
b = b + s[i]
else:
a = a + s[i]
pos = a.index('.')
n = int(b)
a = list(a)
for i in range(n):
if pos == len(a) - 1:
a.append('0')
a[pos], a[pos + 1] = a[pos + 1], a[pos]
pos += 1
if a[-1] == '.':
a.pop()
if '.' in a:
while a[-1] == '0':
a.pop()
if a[-1] == '.':
a.pop()
if '.' not in a:
while len(a) > 1 and a[0] == '0':
a.pop(0)
for i in range(len(a)):
print(a[i], end = '')
``` | vfc_12066 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/697/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8.549e2\n",
"output": "854.9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 582 | Solve the following coding problem using the programming language python:
VK news recommendation system daily selects interesting publications of one of $n$ disjoint categories for each user. Each publication belongs to exactly one category. For each category $i$ batch algorithm selects $a_i$ publications.
The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of $i$-th category within $t_i$ seconds.
What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.
-----Input-----
The first line of input consists of single integer $n$ — the number of news categories ($1 \le n \le 200\,000$).
The second line of input consists of $n$ integers $a_i$ — the number of publications of $i$-th category selected by the batch algorithm ($1 \le a_i \le 10^9$).
The third line of input consists of $n$ integers $t_i$ — time it takes for targeted algorithm to find one new publication of category $i$ ($1 \le t_i \le 10^5)$.
-----Output-----
Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.
-----Examples-----
Input
5
3 7 9 7 8
5 2 5 7 5
Output
6
Input
5
1 2 3 4 5
1 1 1 1 1
Output
0
-----Note-----
In the first example, it is possible to find three publications of the second type, which will take 6 seconds.
In the second example, all news categories contain a different number of publications.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
from heapq import heappush, heappop
n = int(input())
a = list(map(int, input().split()))
count = {}
for x in a:
if x in count:
count[x] = count[x] + 1
else:
count[x] = 1
count = sorted(list(count.items()))
#print(count)
cost= list(map(int, input().split()))
max_cost = max(cost)
a = list(zip(a, cost))
a = sorted(a)
priority = list([max_cost - x for x in [x[1] for x in a]])
a = list(zip(priority, a))
i = 0
queue = []
queue_cost = 0
result = 0
#print(a)
for j in range(len(count)):
x, c = count[j]
#print('x = ', x)
while i < len(a) and a[i][1][0] == x:
queue_cost += a[i][1][1]
heappush(queue, a[i])
i += 1
#print('queue = ', queue)
y = x
while len(queue) > 0 and (j == len(count) - 1 or count[j + 1][0] != y):
popped = heappop(queue)
#print(popped, queue)
queue_cost -= popped[1][1]
#print(queue_cost)
result += queue_cost
y += 1
# while len(queue) > 0:
# popped = heappop(queue)
# queue_cost -= popped[1][1]
# result += queue_cost
print(result)
``` | vfc_12082 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1310/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 7 9 7 8\n5 2 5 7 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n12 4 19 18 19\n15467 14873 66248 58962 90842\n",
"output": "66248\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "40\n19 20 8 13 13 17 1 14 15 20 14 17 2 9 9 10 19 16 6 12 9 7 20 5 12 6 4 4 12 5 4 11 8 1 2 8 11 19 18 4\n52258 5648 46847 9200 63940 79328 64407 54479 1788 60107 8234 64215 15419 84411 50307 78075 92548 17867 43456 7970 1390 99373 97297 90662 82950 678 79356 51351 2794 82477 16508 19254 81295 9711 72350 11578 21595 69230 82626 25134\n",
"output": "6113465\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n204\n74562\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n72\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 583 | Solve the following coding problem using the programming language python:
This is an easier version of the problem. In this version, $n \le 500$.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believes, that the beauty of the bracket string is a number of its cyclical shifts, which form a correct bracket sequence.
To digress from his problems, Vasya decided to select two positions of the string (not necessarily distinct) and swap characters located at this positions with each other. Vasya will apply this operation exactly once. He is curious what is the maximum possible beauty he can achieve this way. Please help him.
We remind that bracket sequence $s$ is called correct if: $s$ is empty; $s$ is equal to "($t$)", where $t$ is correct bracket sequence; $s$ is equal to $t_1 t_2$, i.e. concatenation of $t_1$ and $t_2$, where $t_1$ and $t_2$ are correct bracket sequences.
For example, "(()())", "()" are correct, while ")(" and "())" are not.
The cyclical shift of the string $s$ of length $n$ by $k$ ($0 \leq k < n$) is a string formed by a concatenation of the last $k$ symbols of the string $s$ with the first $n - k$ symbols of string $s$. For example, the cyclical shift of string "(())()" by $2$ equals "()(())".
Cyclical shifts $i$ and $j$ are considered different, if $i \ne j$.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 500$), the length of the string.
The second line contains a string, consisting of exactly $n$ characters, where each of the characters is either "(" or ")".
-----Output-----
The first line should contain a single integer — the largest beauty of the string, which can be achieved by swapping some two characters.
The second line should contain integers $l$ and $r$ ($1 \leq l, r \leq n$) — the indices of two characters, which should be swapped in order to maximize the string's beauty.
In case there are several possible swaps, print any of them.
-----Examples-----
Input
10
()()())(()
Output
5
8 7
Input
12
)(()(()())()
Output
4
5 10
Input
6
)))(()
Output
0
1 1
-----Note-----
In the first example, we can swap $7$-th and $8$-th character, obtaining a string "()()()()()". The cyclical shifts by $0, 2, 4, 6, 8$ of this string form a correct bracket sequence.
In the second example, after swapping $5$-th and $10$-th character, we obtain a string ")(())()()(()". The cyclical shifts by $11, 7, 5, 3$ of this string form a correct bracket sequence.
In the third example, swap of any two brackets results in $0$ cyclical shifts being correct bracket sequences.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
st = input()
s = [0 if c == "(" else 1 for c in st]
if n % 2 != 0 or sum(s) != n//2:
print(0)
print(1,1)
return
maxx = 0
ind = (0,0)
maxshift = 0
for shift in range(n):
stack = 0
x1 = -1
x2 = -1
sumzero = 0
for i,c in enumerate(s):
if s[(i+shift)%n] == 0:
stack+=1
else:
stack-=1
if stack == 0:
sumzero+=1
if stack < 0:
x1 = i
break
stack = 0
for i in range(n-1, -1, -1):
if s[(i+shift)%n] == 1:
stack+=1
else:
stack-=1
if stack < 0:
x2 = i
break
if x1 == -1 and x2 == -1 and stack == 0:
if sumzero > maxx:
maxx=sumzero
ind = (0,0)
if x1 == -1 or x2 == -1 or x1 == x2:
continue
stack = 0
corr = True
ans = 0
for i in range(n):
c = s[(i+shift)%n]
if i == x1 or i == x2:
c = 1-c
if c == 0:
stack += 1
else:
stack -= 1
if stack == 0:
ans+=1
if stack == -1:
corr = False
break
if not corr or stack > 0:
continue
if ans > maxx:
maxshift = shift
maxx = ans
ind = ((x1+shift)%n, (x2+shift)%n)
print(maxx)
print(ind[0]+1,ind[1]+1)
``` | vfc_12086 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1248/D1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n()()())(()\n",
"output": "5\n8 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n)(()(()())()\n",
"output": "4\n5 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n)))(()\n",
"output": "0\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n(()(()))()\n",
"output": "4\n4 7\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 584 | Solve the following coding problem using the programming language python:
Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are given a string which only consists of: uppercase and lowercase English letters, underscore symbols (they are used as separators), parentheses (both opening and closing).
It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested.
For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".
Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.
-----Output-----
Print two space-separated integers: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
-----Examples-----
Input
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
Output
5 4
Input
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
Output
2 6
Input
27
(LoooonG)__shOrt__(LoooonG)
Output
5 2
Input
5
(___)
Output
0 0
-----Note-----
In the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
len_out, count_in = 0, 0
balance, cur = 0, 0
for c in input():
if not (('a' <= c <= 'z') or ('A' <= c <= 'Z')) and cur:
if balance:
count_in += 1
else:
len_out = max(len_out, cur)
cur = 0
if c == '(':
balance += 1
elif c == ')':
balance -= 1
elif ('a' <= c <= 'z') or ('A' <= c <= 'Z'):
cur += 1
if cur:
len_out = max(len_out, cur)
print(len_out, count_in)
``` | vfc_12090 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/723/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "37\n_Hello_Vasya(and_Petya)__bye_(and_OK)\n",
"output": "5 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__\n",
"output": "2 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "27\n(LoooonG)__shOrt__(LoooonG)\n",
"output": "5 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n(___)\n",
"output": "0 0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 585 | Solve the following coding problem using the programming language python:
You are given two arrays $a_1, a_2, \dots , a_n$ and $b_1, b_2, \dots , b_m$. Array $b$ is sorted in ascending order ($b_i < b_{i + 1}$ for each $i$ from $1$ to $m - 1$).
You have to divide the array $a$ into $m$ consecutive subarrays so that, for each $i$ from $1$ to $m$, the minimum on the $i$-th subarray is equal to $b_i$. Note that each element belongs to exactly one subarray, and they are formed in such a way: the first several elements of $a$ compose the first subarray, the next several elements of $a$ compose the second subarray, and so on.
For example, if $a = [12, 10, 20, 20, 25, 30]$ and $b = [10, 20, 30]$ then there are two good partitions of array $a$: $[12, 10, 20], [20, 25], [30]$; $[12, 10], [20, 20, 25], [30]$.
You have to calculate the number of ways to divide the array $a$. Since the number can be pretty large print it modulo 998244353.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the length of arrays $a$ and $b$ respectively.
The second line contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$) — the array $a$.
The third line contains $m$ integers $b_1, b_2, \dots , b_m$ ($1 \le b_i \le 10^9; b_i < b_{i+1}$) — the array $b$.
-----Output-----
In only line print one integer — the number of ways to divide the array $a$ modulo 998244353.
-----Examples-----
Input
6 3
12 10 20 20 25 30
10 20 30
Output
2
Input
4 2
1 3 3 7
3 7
Output
0
Input
8 2
1 2 2 2 2 2 2 2
1 2
Output
7
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mod=998244353
sol=1
i=n-1
j=m-1
while sol>0 and j>=0:
goal=b[j]
s=0
r=False
while i>=0 and a[i]>=goal:
if r:
s+=1
else:
if a[i]==goal:
r=True
s=1
i-=1
if j==0:
s=min(s,1)
if i>=0:
s=0
sol*=s
sol%=mod
j-=1
print(sol)
``` | vfc_12094 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1366/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n12 10 20 20 25 30\n10 20 30\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 3 3 7\n3 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 2\n1 2 2 2 2 2 2 2\n1 2\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 586 | Solve the following coding problem using the programming language python:
You are given a square board, consisting of $n$ rows and $n$ columns. Each tile in it should be colored either white or black.
Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.
Let's call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least $k$ tiles.
Your task is to count the number of suitable colorings of the board of the given size.
Since the answer can be very large, print it modulo $998244353$.
-----Input-----
A single line contains two integers $n$ and $k$ ($1 \le n \le 500$, $1 \le k \le n^2$) — the number of rows and columns of the board and the maximum number of tiles inside the rectangle of the single color, respectively.
-----Output-----
Print a single integer — the number of suitable colorings of the board of the given size modulo $998244353$.
-----Examples-----
Input
1 1
Output
0
Input
2 3
Output
6
Input
49 1808
Output
359087121
-----Note-----
Board of size $1 \times 1$ is either a single black tile or a single white tile. Both of them include a rectangle of a single color, consisting of $1$ tile.
Here are the beautiful colorings of a board of size $2 \times 2$ that don't include rectangles of a single color, consisting of at least $3$ tiles: [Image]
The rest of beautiful colorings of a board of size $2 \times 2$ are the following: [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def norm(x):
return (x % 998244353 + 998244353) % 998244353
n, k = map(int, input().split())
dp1 = [0]
dp2 = [0]
for i in range(n):
l = [1]
cur = 0
for j in range(n + 1):
cur += l[j]
if(j > i):
cur -= l[j - i - 1]
cur = norm(cur)
l.append(cur)
dp1.append(l[n])
dp2.append(norm(dp1[i + 1] - dp1[i]))
ans = 0
for i in range(n + 1):
for j in range(n + 1):
if(i * j < k):
ans = norm(ans + dp2[i] * dp2[j])
ans = norm(ans * 2)
print(ans)
``` | vfc_12098 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1027/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "49 1808\n",
"output": "359087121\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 589 | Solve the following coding problem using the programming language python:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
if s_{i} = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively); if s_{i} is a digit (between 0 to 9, inclusively), then it means that there is digit s_{i} on position i in code; if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
-----Input-----
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1): 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2): 1 ≤ |s| ≤ 10^5.
Here |s| means the length of string s.
-----Output-----
Print the number of codes that match the given hint.
-----Examples-----
Input
AJ
Output
81
Input
1?AA
Output
100
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
res = 1
started = False
seen = set()
codes = set(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])
for ch in input():
if ch == '?':
if started:
res *= 10
else:
res *= 9
elif (ch in codes) and (ch not in seen):
if not started:
res *= len(codes) - len(seen) - 1
else:
res *= len(codes) - len(seen)
seen.add(ch)
started = True
print(res)
``` | vfc_12110 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/316/A1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AJ\n",
"output": "81\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 590 | Solve the following coding problem using the programming language python:
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n.
Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers from 1 to n was encountered in his array exactly once). If there are multiple ways to do it he wants to find the lexicographically minimal permutation among them.
Thus minimizing the number of changes has the first priority, lexicographical minimizing has the second priority.
In order to determine which of the two permutations is lexicographically smaller, we compare their first elements. If they are equal — compare the second, and so on. If we have two permutations x and y, then x is lexicographically smaller if x_{i} < y_{i}, where i is the first index in which the permutations x and y differ.
Determine the array Ivan will obtain after performing all the changes.
-----Input-----
The first line contains an single integer n (2 ≤ n ≤ 200 000) — the number of elements in Ivan's array.
The second line contains a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) — the description of Ivan's array.
-----Output-----
In the first line print q — the minimum number of elements that need to be changed in Ivan's array in order to make his array a permutation. In the second line, print the lexicographically minimal permutation which can be obtained from array with q changes.
-----Examples-----
Input
4
3 2 2 3
Output
2
1 2 4 3
Input
6
4 5 6 3 2 1
Output
0
4 5 6 3 2 1
Input
10
6 8 4 6 7 1 6 3 4 5
Output
3
2 8 4 6 7 1 9 3 10 5
-----Note-----
In the first example Ivan needs to replace number three in position 1 with number one, and number two in position 3 with number four. Then he will get a permutation [1, 2, 4, 3] with only two changed numbers — this permutation is lexicographically minimal among all suitable.
In the second example Ivan does not need to change anything because his array already is a permutation.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
nums = [False for i in range(200010)]
must = [False for i in range(200010)]
counter = dict()
now_num = 0
def inc():
nonlocal now_num
now_num += 1
while nums[now_num - 1]:
now_num += 1
for el in a:
if nums[el - 1]:
counter[el] += 1
else:
counter[el] = 1
nums[el - 1] = True
inc()
ans = []
c = 0
for el in a:
if counter[el] > 1:
counter[el] -= 1
if now_num < el:
ans.append(now_num)
c += 1
inc()
else:
if must[el - 1] == False:
ans.append(el)
must[el - 1] = True
else:
ans.append(now_num)
c += 1
inc()
else:
if must[el - 1] == False:
ans.append(el)
else:
ans.append(now_num)
c += 1
inc()
print(c)
print(' '.join(str(el) for el in ans))
``` | vfc_12114 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/864/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 2 2 3\n",
"output": "2\n1 2 4 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4 5 6 3 2 1\n",
"output": "0\n4 5 6 3 2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n6 8 4 6 7 1 6 3 4 5\n",
"output": "3\n2 8 4 6 7 1 9 3 10 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n5 5 5 6 4 6\n",
"output": "3\n1 2 5 3 4 6 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 591 | Solve the following coding problem using the programming language python:
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed k hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.
Vasya has a train lighting schedule for all n hours of the trip — n numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose k hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours.
-----Input-----
The first input line contains two integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ n) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains n space-separated integers a_{i} (0 ≤ a_{i} ≤ 100), a_{i} is the light level at the i-th hour.
-----Output-----
In the first output line print the minimum light level Vasya will read at. In the second line print k distinct space-separated integers b_1, b_2, ..., b_{k}, — the indexes of hours Vasya will read at (1 ≤ b_{i} ≤ n). The hours are indexed starting from 1. If there are multiple optimal solutions, print any of them. Print the numbers b_{i} in an arbitrary order.
-----Examples-----
Input
5 3
20 10 30 40 10
Output
20
1 3 4
Input
6 5
90 20 35 40 60 100
Output
35
1 3 4 5 6
-----Note-----
In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def readln(): return tuple(map(int, input().split()))
import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n, k = readln()
lst = [(v, i + 1) for i, v in enumerate(readln())]
lst.sort()
lst.reverse()
print(lst[k - 1][0])
print(*list(zip(*lst[:k]))[1])
``` | vfc_12118 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/234/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n20 10 30 40 10\n",
"output": "20\n1 3 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n90 20 35 40 60 100\n",
"output": "35\n1 3 4 5 6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 29 88 63 89 47 7 52 47 55 87 77 9 81 44 13 30 43 66 74 9 42 9 72 97 61 9 94 92 29 18 7 92 68 76 43 35 71 54 49 77 50 77 68 57 24 84 73 32 85 24 37\n",
"output": "94\n11 14 15 21 34 73 76 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n10\n",
"output": "10\n1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n86\n",
"output": "86\n1 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 593 | Solve the following coding problem using the programming language python:
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
-----Input-----
The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively.
Each of the next m lines contains n non-negative integers, the j-th number in the i-th line a_{ij} (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ a_{ij} ≤ 10^9) denotes the number of votes for candidate j in city i.
It is guaranteed that the total number of people in all the cities does not exceed 10^9.
-----Output-----
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
-----Examples-----
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
-----Note-----
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = (int(x) for x in input().split())
winners = [0] * n
for i in range(m):
a = [int(x) for x in input().split()]
winners[a.index(max(a))] += 1
print(winners.index(max(winners)) + 1)
``` | vfc_12126 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/570/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n1 2 3\n2 3 1\n1 2 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n5\n3\n2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 2 3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n100 100 100\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 594 | Solve the following coding problem using the programming language python:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.
As a result, Valera decided to set v seconds TL, that the following conditions are met: v is a positive integer; all correct solutions pass the system testing; at least one correct solution passes the system testing with some "extra" time; all wrong solutions do not pass the system testing; value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
-----Input-----
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b_1, b_2, ..., b_{m} (1 ≤ b_{i} ≤ 100) — the running time of each of m wrong solutions in seconds.
-----Output-----
If there is a valid TL value, print it. Otherwise, print -1.
-----Examples-----
Input
3 6
4 5 2
8 9 6 10 7 11
Output
5
Input
3 1
3 4 5
6
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = max(max(A), min(A) * 2)
if min(B) <= ans:
print(-1)
else:
print(ans)
``` | vfc_12130 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/350/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\n4 5 2\n8 9 6 10 7 11\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n3 4 5\n6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 5\n45 99\n49 41 77 83 45\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 595 | Solve the following coding problem using the programming language python:
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.
Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).
-----Input-----
The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.
-----Output-----
Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.
-----Examples-----
Input
2016
Output
2044
Input
2000
Output
2028
Input
50501
Output
50507
-----Note-----
Today is Monday, the 13th of June, 2016.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def iswis(a):
return a % 400 == 0 or (a%100!= 0 and a %4==0)
n = int(input())
wis = iswis(n)
fr = 0;
n += 1
if (wis):
fr += 1
fr += 1
while (iswis(n) != wis or fr != 0):
if (iswis(n)):
fr += 1
fr += 1
fr %= 7
n += 1
print(n)
``` | vfc_12134 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/678/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2016\n",
"output": "2044\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2000\n",
"output": "2028\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50501\n",
"output": "50507\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 596 | Solve the following coding problem using the programming language python:
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. [Image]
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
-----Input-----
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 ≤ yyyy ≤ 2038 and yyyy:mm:dd is a legal date).
-----Output-----
Print a single integer — the answer to the problem.
-----Examples-----
Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import datetime
from pprint import pprint
year, month, day = (int(i) for i in input().split(':'))
x = datetime.date(year, month, day)
year, month, day = (int(i) for i in input().split(':'))
y = datetime.date(year, month, day)
pprint(abs(int((x - y).days)))
``` | vfc_12138 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/304/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1900:01:01\n2038:12:31\n",
"output": "50768\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 597 | Solve the following coding problem using the programming language python:
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go from any city to any other city using only the given roads. There are m cities being attacked by humans. So Ari... we meant Super M have to immediately go to each of the cities being attacked to scare those bad humans. Super M can pass from one city to another only using the given roads. Moreover, passing through one road takes her exactly one kron - the time unit used in Byteforces. [Image]
However, Super M is not on Byteforces now - she is attending a training camp located in a nearby country Codeforces. Fortunately, there is a special device in Codeforces that allows her to instantly teleport from Codeforces to any city of Byteforces. The way back is too long, so for the purpose of this problem teleportation is used exactly once.
You are to help Super M, by calculating the city in which she should teleport at the beginning in order to end her job in the minimum time (measured in krons). Also, provide her with this time so she can plan her way back to Codeforces.
-----Input-----
The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 123456) - the number of cities in Byteforces, and the number of cities being attacked respectively.
Then follow n - 1 lines, describing the road system. Each line contains two city numbers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n) - the ends of the road i.
The last line contains m distinct integers - numbers of cities being attacked. These numbers are given in no particular order.
-----Output-----
First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number.
Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons.
Note that the correct answer is always unique.
-----Examples-----
Input
7 2
1 2
1 3
1 4
3 5
3 6
3 7
2 7
Output
2
3
Input
6 4
1 2
2 3
2 4
4 5
4 6
2 4 5 6
Output
2
4
-----Note-----
In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are:
$2 \rightarrow 1 \rightarrow 3 \rightarrow 7$ and $7 \rightarrow 3 \rightarrow 1 \rightarrow 2$.
However, you should choose the first one as it starts in the city with the lower number.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import deque
n,m = [int(x) for x in input().split()]
adj = [[] for x in range(n+1)]
for _ in range(1,n):
a,b = [int(x) for x in input().split()]
adj[a].append(b)
adj[b].append(a)
chaos = [int(x) for x in input().split()]
s = chaos[0]
chaos = set(chaos)
cc = [0]*(n+1)
st = deque()
st.append((s,-1))
while len(st):
u,e = st.pop()
if u<0:
if e>=0:
cc[e] += cc[-u]
continue
if u in chaos:
cc[u] +=1
st.append((-u,e))
for v in adj[u]:
if v!=e:
st.append((v,u))
#dfs(s,-1)
adj = [list([v for v in u if cc[v]>0]) for u in adj]
a = (s,0)
st = deque()
st.append((a[0],-1,0))
while len(st):
u,e,h = st.pop()
if h>a[1]:
a = (u,h)
elif h==a[1] and u<a[0]:
a = (u,h)
for v in adj[u]:
if v!=e:
st.append((v,u,h+1))
b = a
a = (a[0],0)
st = deque()
st.append((a[0],-1,0))
while len(st):
u,e,h = st.pop()
if h>a[1]:
a = (u,h)
elif h==a[1] and u<a[0]:
a = (u,h)
for v in adj[u]:
if v!=e:
st.append((v,u,h+1))
print(min(a[0],b[0]))
print(2*(n-cc.count(0))-a[1])
``` | vfc_12142 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/592/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7\n",
"output": "2\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6\n",
"output": "2\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n2 1\n1\n",
"output": "1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "1\n0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 598 | Solve the following coding problem using the programming language python:
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import bisect
import collections
def solve(inp, *args):
n, x = list(map(int, inp.split(" ", 1)))
travels_by_len = collections.defaultdict(list)
travels_by_len_processed = {}
for travel in args:
l, r, cost = list(map(int, travel.split(" ", 2)))
travels_by_len[r - l + 1].append((l, r, cost))
for travel_len, travels in list(travels_by_len.items()):
travels.sort()
travels_processed = [(travels[-1][0], travels[-1][2])]
for i in range(len(travels) - 2, -1, -1):
prev_travel = travels_processed[-1]
l, r, c = travels[i]
travels_processed.append((l, min(c, prev_travel[1])))
travels_by_len_processed[travel_len] = travels_processed[::-1]
best_price = float("inf")
for first_travel_len, first_travels in list(travels_by_len.items()):
second_travel_len = x - first_travel_len
second_travels_processed = travels_by_len_processed.get(second_travel_len, [])
for first_travel in first_travels:
l1, r1, c1 = first_travel
# now we look for cheapest travels which have l2 > r1
idx = bisect.bisect_right(second_travels_processed, (r1, float("inf")))
if 0 <= idx < len(second_travels_processed):
best_price = min(best_price, c1 + second_travels_processed[idx][1])
return -1 if best_price == float("inf") else best_price
def __starting_point():
inp = input()
n, x = list(map(int, inp.split(" ", 1)))
print(solve(inp, *(input() for i in range(n))))
__starting_point()
``` | vfc_12146 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/822/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n4 6 3\n2 4 1\n3 5 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1855\n159106 161198 437057705\n149039 158409 889963913\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 17\n1 10 8\n5 19 1\n12 14 6\n9 19 8\n6 7 3\n5 11 9\n7 12 5\n17 20 8\n6 12 6\n11 19 4\n3 14 1\n15 19 10\n3 20 5\n5 19 9\n10 18 10\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 600 | Solve the following coding problem using the programming language python:
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x_1 = a, another one is in the point x_2 = b.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
-----Input-----
The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend.
The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend.
It is guaranteed that a ≠ b.
-----Output-----
Print the minimum possible total tiredness if the friends meet in the same point.
-----Examples-----
Input
3
4
Output
1
Input
101
99
Output
2
Input
5
10
Output
9
-----Note-----
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a=int(input())
b=int(input())
c=(a+b)//2
def f(x):
x=abs(x)
return x*(x+1)//2
print(f(c-a)+f(b-c))
``` | vfc_12154 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/931/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n99\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n10\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000\n",
"output": "250000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999\n1000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 601 | Solve the following coding problem using the programming language python:
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course.
You decided to rob a town's blacksmith and you take a follower with you. You can carry at most $p$ units and your follower — at most $f$ units.
In the blacksmith shop, you found $cnt_s$ swords and $cnt_w$ war axes. Each sword weights $s$ units and each war axe — $w$ units. You don't care what to take, since each of them will melt into one steel ingot.
What is the maximum number of weapons (both swords and war axes) you and your follower can carry out from the shop?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains two integers $p$ and $f$ ($1 \le p, f \le 10^9$) — yours and your follower's capacities.
The second line of each test case contains two integers $cnt_s$ and $cnt_w$ ($1 \le cnt_s, cnt_w \le 2 \cdot 10^5$) — the number of swords and war axes in the shop.
The third line of each test case contains two integers $s$ and $w$ ($1 \le s, w \le 10^9$) — the weights of each sword and each war axe.
It's guaranteed that the total number of swords and the total number of war axes in all test cases don't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print the maximum number of weapons (both swords and war axes) you and your follower can carry.
-----Example-----
Input
3
33 27
6 10
5 6
100 200
10 10
5 5
1 19
1 3
19 5
Output
11
20
3
-----Note-----
In the first test case: you should take $3$ swords and $3$ war axes: $3 \cdot 5 + 3 \cdot 6 = 33 \le 33$ and your follower — $3$ swords and $2$ war axes: $3 \cdot 5 + 2 \cdot 6 = 27 \le 27$. $3 + 3 + 3 + 2 = 11$ weapons in total.
In the second test case, you can take all available weapons even without your follower's help, since $5 \cdot 10 + 5 \cdot 10 \le 100$.
In the third test case, you can't take anything, but your follower can take $3$ war axes: $3 \cdot 5 \le 19$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for _ in range(t):
p, f = [int(x) for x in input().split()]
cs, cw = [int(x) for x in input().split()]
s, w = [int(x) for x in input().split()]
if s > w:
s, w = w, s
cs, cw = cw, cs
best = 0
for i in range(cs + 1):
if s*i <= p:
war_me = min((p - s*i)//w, cw)
tb = i + war_me
sword_him = min(cs - i, f//s)
tb += sword_him
war_him = min((f - s*sword_him)//w, cw - war_me)
tb += war_him
best = max(best, tb)
print(best)
``` | vfc_12158 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1400/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n33 27\n6 10\n5 6\n100 200\n10 10\n5 5\n1 19\n1 3\n19 5\n",
"output": "11\n20\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1\n1 1\n1 1\n5 5\n1 1\n1 1\n978671046 946619174\n26305 31241\n33456 33457\n780000000 800041032\n172000 168000\n4989 5206\n",
"output": "2\n2\n57546\n310673\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n15 10\n200000 4\n15 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100000 10\n200000 4\n100000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000000000 10\n3 3\n1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 602 | Solve the following coding problem using the programming language python:
-----Input-----
The input contains a single integer a (1 ≤ a ≤ 40).
-----Output-----
Output a single string.
-----Examples-----
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
a = int(input())
lst = 'Washington,Adams,Jefferson,Madison,Monroe,Adams,Jackson,Van Buren,Harrison,Tyler,Polk,Taylor,Fillmore,Pierce,Buchanan,Lincoln,Johnson,Grant,Hayes,Garfield,Arthur,Cleveland,Harrison,Cleveland,McKinley,Roosevelt,Taft,Wilson,Harding,Coolidge,Hoover,Roosevelt,Truman,Eisenhower,Kennedy,Johnson,Nixon,Ford,Carter,Reagan'.split(',')
print(lst[a - 1])
``` | vfc_12162 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/290/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "Adams\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
"output": "Van Buren\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "29\n",
"output": "Harding\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "Washington\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "Jefferson\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 603 | Solve the following coding problem using the programming language python:
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
To make a "red bouquet", it needs 3 red flowers. To make a "green bouquet", it needs 3 green flowers. To make a "blue bouquet", it needs 3 blue flowers. To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
-----Input-----
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 10^9) — the number of red, green and blue flowers.
-----Output-----
Print the maximal number of bouquets Fox Ciel can make.
-----Examples-----
Input
3 6 9
Output
6
Input
4 4 4
Output
4
Input
0 0 0
Output
0
-----Note-----
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s=input().split()
for i in range(3):
s[i]=int(s[i])
s.sort()
ans=s[0]//3 +s[1]//3 +s[2]//3
x=s[0]%3
y=s[1]%3
z=s[2]%3
if(x==0 and y==z==2 and s[0]!=0):
ans+=1
if(y==0 and x==z==2 and s[1]!=0):
ans+=1
if(z==0 and y==x==2 and s[2]!=0):
ans+=1
ans+=min(x,y,z)
print(ans)
``` | vfc_12166 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/322/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 3 6\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 604 | Solve the following coding problem using the programming language python:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. When all elements of the array become equal to zero, the array explodes.
Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the size of the array.
The second line contains n integers a_1, a_2, ..., a_{n} ( - 10^5 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
-----Examples-----
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
-----Note-----
In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = set(map(int, input().split()))
if 0 in a: a.remove(0)
print(len(a))
``` | vfc_12170 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/992/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 0 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 -6 -5 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n21794 -79194\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 605 | Solve the following coding problem using the programming language python:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points t minutes after the contest started, you get $\operatorname{max}(\frac{3p}{10}, p - \frac{p}{250} \times t)$ points.
Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.
-----Input-----
The first line contains four integers a, b, c, d (250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).
It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).
-----Output-----
Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points.
-----Examples-----
Input
500 1000 20 30
Output
Vasya
Input
1000 1000 1 1
Output
Tie
Input
1500 1000 176 177
Output
Misha
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a,b,c,d=list(map(int,input().split()))
misha=max(3*a/10,a-a/250*c)
vasya=max(3*b/10,b-b/250*d)
if misha > vasya:
print("Misha")
elif vasya > misha:
print("Vasya")
else:
print("Tie")
``` | vfc_12174 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/501/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "500 1000 20 30\n",
"output": "Vasya\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 1000 1 1\n",
"output": "Tie\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1500 1000 176 177\n",
"output": "Misha\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1500 1000 74 177\n",
"output": "Misha\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "750 2500 175 178\n",
"output": "Vasya\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "750 1000 54 103\n",
"output": "Tie\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 606 | Solve the following coding problem using the programming language python:
Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.
The world is represented as an infinite 2D plane. The flat is centered at (x_1, y_1) and has radius R and Fafa's laptop is located at (x_2, y_2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.
-----Input-----
The single line of the input contains 5 space-separated integers R, x_1, y_1, x_2, y_2 (1 ≤ R ≤ 10^5, |x_1|, |y_1|, |x_2|, |y_2| ≤ 10^5).
-----Output-----
Print three space-separated numbers x_{ap}, y_{ap}, r where (x_{ap}, y_{ap}) is the position which Fifa chose for the access point and r is the radius of its range.
Your answer will be considered correct if the radius does not differ from optimal more than 10^{ - 6} absolutely or relatively, and also the radius you printed can be changed by no more than 10^{ - 6} (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range.
-----Examples-----
Input
5 3 3 1 1
Output
3.7677669529663684 3.7677669529663684 3.914213562373095
Input
10 5 5 5 15
Output
5.0 5.0 10.0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
R,x,y,s,t = list(map(int,input().split()))
if (s-x)**2 + (t-y)**2 > R*R:
print(x,y,R)
return
dx = x - s
dy = y - t
r = (dx**2 + dy**2)**.5
if abs(r)<1e-9:
dx = 1
dy = 0
else:
dx /= r
dy /= r
a = s + dx*(R + r)/2
b = t + dy*(R + r)/2
print(a,b,(R+r)/2)
``` | vfc_12178 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/935/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 3 1 1\n",
"output": "3.7677669529663684 3.7677669529663684 3.914213562373095\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5 5 5 15\n",
"output": "5.0 5.0 10.0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0 0 0 7\n",
"output": "0 0 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 0 0 0 0\n",
"output": "5.0 0.0 5.0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100000 100000 100000 10000 10000\n",
"output": "100000 100000 100000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 607 | Solve the following coding problem using the programming language python:
Recall that the permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).
A sequence $a$ is a subsegment of a sequence $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as $[l, r]$, where $l, r$ are two integers with $1 \le l \le r \le n$. This indicates the subsegment where $l-1$ elements from the beginning and $n-r$ elements from the end are deleted from the sequence.
For a permutation $p_1, p_2, \ldots, p_n$, we define a framed segment as a subsegment $[l,r]$ where $\max\{p_l, p_{l+1}, \dots, p_r\} - \min\{p_l, p_{l+1}, \dots, p_r\} = r - l$. For example, for the permutation $(6, 7, 1, 8, 5, 3, 2, 4)$ some of its framed segments are: $[1, 2], [5, 8], [6, 7], [3, 3], [8, 8]$. In particular, a subsegment $[i,i]$ is always a framed segments for any $i$ between $1$ and $n$, inclusive.
We define the happiness of a permutation $p$ as the number of pairs $(l, r)$ such that $1 \le l \le r \le n$, and $[l, r]$ is a framed segment. For example, the permutation $[3, 1, 2]$ has happiness $5$: all segments except $[1, 2]$ are framed segments.
Given integers $n$ and $m$, Jongwon wants to compute the sum of happiness for all permutations of length $n$, modulo the prime number $m$. Note that there exist $n!$ (factorial of $n$) different permutations of length $n$.
-----Input-----
The only line contains two integers $n$ and $m$ ($1 \le n \le 250\,000$, $10^8 \le m \le 10^9$, $m$ is prime).
-----Output-----
Print $r$ ($0 \le r < m$), the sum of happiness for all permutations of length $n$, modulo a prime number $m$.
-----Examples-----
Input
1 993244853
Output
1
Input
2 993244853
Output
6
Input
3 993244853
Output
32
Input
2019 993244853
Output
923958830
Input
2020 437122297
Output
265955509
-----Note-----
For sample input $n=3$, let's consider all permutations of length $3$: $[1, 2, 3]$, all subsegments are framed segment. Happiness is $6$. $[1, 3, 2]$, all subsegments except $[1, 2]$ are framed segment. Happiness is $5$. $[2, 1, 3]$, all subsegments except $[2, 3]$ are framed segment. Happiness is $5$. $[2, 3, 1]$, all subsegments except $[2, 3]$ are framed segment. Happiness is $5$. $[3, 1, 2]$, all subsegments except $[1, 2]$ are framed segment. Happiness is $5$. $[3, 2, 1]$, all subsegments are framed segment. Happiness is $6$.
Thus, the sum of happiness is $6+5+5+5+5+6 = 32$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = list(map(int, input().split()))
fact = [1]
for i in range(1, n + 1):
fact.append((fact[-1] * i) % m)
out = 0
for size in range(1, n + 1):
out += fact[size] * (n - size + 1) ** 2 * fact[n - size]
out %= m
print(out)
``` | vfc_12182 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1284/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 993244853\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 993244853\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 993244853\n",
"output": "32\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 608 | Solve the following coding problem using the programming language python:
Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок, но для того, чтобы получить ещё один подарок, ему вновь надо получить подряд ещё три хорошие оценки.
Например, если Вася получит подряд пять «четвёрок» оценок, а потом «двойку», то ему дадут только один подарок, а вот если бы «четвёрок» было уже шесть, то подарков было бы два.
За месяц Вася получил n оценок. Вам предстоит посчитать количество подарков, которые получил Вася. Оценки будут даны именно в том порядке, в котором Вася их получал.
-----Входные данные-----
В первой строке входных данных следует целое положительное число n (3 ≤ n ≤ 1000) — количество оценок, полученных Васей.
Во второй строке входных данных следует последовательность из n чисел a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вася их получил.
-----Выходные данные-----
Выведите одно целое число — количество подарков, полученных Васей.
-----Примеры-----
Входные данные
6
4 5 4 5 4 4
Выходные данные
2
Входные данные
14
1 5 4 5 2 4 4 5 5 4 3 4 5 5
Выходные данные
3
-----Примечание-----
В первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
cnt, good = 0, 0
for i in range(0, n):
if a[i] == 4 or a[i] == 5:
good = good + 1
else:
good = 0
if good == 3:
cnt = cnt + 1
good = 0
print(cnt)
``` | vfc_12186 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/647/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n4 5 4 5 4 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 5 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 609 | Solve the following coding problem using the programming language python:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: on both diagonals of the square paper all letters are the same; all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
-----Input-----
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
-----Output-----
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
-----Examples-----
Input
5
xooox
oxoxo
soxoo
oxoxo
xooox
Output
NO
Input
3
wsw
sws
wsw
Output
YES
Input
3
xpx
pxp
xpe
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
L=[]
for i in range(n):
L.append(input())
valid=True
x=0
y=0
E=[]
p=L[0][0]
while(x<n and y<n):
if(L[x][y]!=p):
valid=False
x+=1
y+=1
x=0
y=n-1
while(x<n and y>=0):
if(L[x][y]!=p):
valid=False
x+=1
y-=1
K={}
for i in range(n):
for j in range(n):
if(L[i][j] in K):
K[L[i][j]]+=1
else:
K[L[i][j]]=1
if(not valid or K[p]!=2*n-1 or len(K)!=2):
print("NO")
else:
print("YES")
``` | vfc_12190 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/404/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nwsw\nsws\nwsw\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nxpx\npxp\nxpe\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nliiil\nilili\niilii\nilili\nliiil\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 610 | Solve the following coding problem using the programming language python:
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cubes). Petya moves first. Petya's task is to get as many pairs of neighbouring cubes of the same color as possible. Vasya's task is to get as many pairs of neighbouring cubes of different colors as possible.
The number of Petya's points in the game is the number of pairs of neighboring cubes of the same color in the line, the number of Vasya's points in the game is the number of neighbouring cubes of the different color in the line. Your task is to calculate the score at the end of the game (Petya's and Vasya's points, correspondingly), if both boys are playing optimally well. To "play optimally well" first of all means to maximize the number of one's points, and second — to minimize the number of the opponent's points.
-----Input-----
The only line contains two space-separated integers n and m (1 ≤ n, m ≤ 10^5) — the number of red and blue cubes, correspondingly.
-----Output-----
On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.
-----Examples-----
Input
3 1
Output
2 1
Input
2 4
Output
3 2
-----Note-----
In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cube during his first move, then, provided that both boys play optimally well, Petya would get 1 point and Vasya would get 2 points.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import re
import itertools
from collections import Counter
class Task:
n, m = 0, 0
petyaScore = 0
vasyaScore = 0
def getData(self):
self.n, self.m = [int(x) for x in input().split(" ")]
def solve(self):
n = self.n
m = self.m
if n != m:
self.vasyaScore = min(n, m)
else:
self.vasyaScore = min(n, m)
self.petyaScore = self.n + self.m - 1 - self.vasyaScore
def printAnswer(self):
print(self.petyaScore, self.vasyaScore)
task = Task();
task.getData();
task.solve();
task.printAnswer();
``` | vfc_12194 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/257/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "1 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 612 | Solve the following coding problem using the programming language python:
Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?
Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts such that p of the parts have even sum (each of them must have even sum) and remaining k - p have odd sum? (note that parts need not to be continuous).
If it is possible to partition the array, also give any possible way of valid partitioning.
-----Input-----
The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 10^5; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
-----Output-----
In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes).
If the required partition exists, print k lines after the first line. The i^{th} of them should contain the content of the i^{th} part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly p parts with even sum, each of the remaining k - p parts must have odd sum.
As there can be multiple partitions, you are allowed to print any valid partition.
-----Examples-----
Input
5 5 3
2 6 10 5 9
Output
YES
1 9
1 5
1 10
1 6
1 2
Input
5 5 3
7 14 2 9 5
Output
NO
Input
5 3 1
1 2 3 7 5
Output
YES
3 5 1 3
1 7
1 2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k, p = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
nech= []
ch = []
for i in range(len(a)):
if a[i] % 2 == 0:
ch.append(a[i])
else:
nech.append(a[i])
needed_nech = k - p
free_nech = len(nech) - needed_nech
av_ch = len(ch) + (free_nech // 2)
sets = []
if free_nech < 0 or free_nech % 2 != 0 or av_ch < p:
print('NO')
else:
print('YES')
while needed_nech > 0:
sets.append([nech.pop()])
needed_nech -= 1
while p > 0:
if len(ch) > 0:
sets.append([ch.pop()])
else:
sets.append([nech.pop(), nech.pop()])
p -= 1
sets[0] = sets[0] + nech + ch
for i in range(len(sets)):
print(len(sets[i]),' '.join(map(str,sets[i])))
``` | vfc_12202 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/439/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 3\n2 6 10 5 9\n",
"output": "YES\n1 9\n1 5\n1 10\n1 6\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 3\n7 14 2 9 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 1\n1 2 3 7 5\n",
"output": "YES\n3 5 1 3\n1 7\n1 2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 613 | Solve the following coding problem using the programming language python:
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a_0 + a_1x^1 + ... + a_{n}x^{n}. Numbers a_{i} are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial.
Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials P(x) exist with integer non-negative coefficients so that $P(t) = a$, and $P(P(t)) = b$, where $t, a$ and b are given positive integers"?
Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem.
-----Input-----
The input contains three integer positive numbers $t, a, b$ no greater than 10^18.
-----Output-----
If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 10^9 + 7.
-----Examples-----
Input
2 2 2
Output
2
Input
2 3 3
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t,a,b=map(int,input().split())
if t==2 and a==3 and b>10000: res=0
elif a==t: res=('inf' if a==1 else 2) if a==b else 0
else: res=0 if (a-b)%(t-a) else (1 if t != b else 0)
print(res)
``` | vfc_12206 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/493/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 614 | Solve the following coding problem using the programming language python:
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as usual, Petya will come to the market. Petya has n different souvenirs to sell; ith souvenir is characterised by its weight w_{i} and cost c_{i}. Petya knows that he might not be able to carry all the souvenirs to the market. So Petya wants to choose a subset of souvenirs such that its total weight is not greater than m, and total cost is maximum possible.
Help Petya to determine maximum possible total cost.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 300000) — the number of Petya's souvenirs and total weight that he can carry to the market.
Then n lines follow. ith line contains two integers w_{i} and c_{i} (1 ≤ w_{i} ≤ 3, 1 ≤ c_{i} ≤ 10^9) — the weight and the cost of ith souvenir.
-----Output-----
Print one number — maximum possible total cost of souvenirs that Petya can carry to the market.
-----Examples-----
Input
1 1
2 1
Output
0
Input
2 2
1 3
2 2
Output
3
Input
4 3
3 10
2 7
2 8
1 1
Output
10
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n, m = list(map(int, input().split()))
cost1 = []
cost2 = []
cost3 = []
for i in range(n):
w, c = list(map(int, input().split()))
if w == 1:
cost1.append(c)
elif w == 2:
cost2.append(c)
else:
cost3.append(c)
cost1 = sorted(cost1)[::-1]
cost2 = sorted(cost2)[::-1]
cost3 = sorted(cost3)[::-1]
cost3_prefix = [0]
for c in cost3:
cost3_prefix.append(cost3_prefix[-1] + c)
dp = [(0, 0, 0)] * (m + 1)
dp[0] = (0, 0, 0)
for i in range(0, m):
cost, n1, n2 = dp[i]
if i + 1 <= m and n1 < len(cost1):
new_cost = cost + cost1[n1]
if dp[i + 1][0] < new_cost:
dp[i + 1] = (new_cost, n1 + 1, n2)
if i + 2 <= m and n2 < len(cost2):
new_cost = cost + cost2[n2]
if dp[i + 2][0] < new_cost:
dp[i + 2] = (new_cost, n1, n2 + 1)
if n1 == len(cost1) and n2 == len(cost2):
break
dp_prefix = [0]
for x in dp[1:]:
dp_prefix.append(max(dp_prefix[-1], x[0]))
ans = 0
for k in range(len(cost3) + 1):
l = m - 3 * k
if l < 0:
continue
new_ans = cost3_prefix[k] + dp_prefix[l]
ans = max(new_ans, ans)
print(ans)
def __starting_point():
main()
__starting_point()
``` | vfc_12210 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/808/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 3\n2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n3 10\n2 7\n2 8\n1 1\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 617 | Solve the following coding problem using the programming language python:
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
-----Input-----
The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * .
The number of signs * doesn't exceed 15.
-----Output-----
In the first line print the maximum possible value of an expression.
-----Examples-----
Input
3+5*7+8*4
Output
303
Input
2+3*5
Output
25
Input
3*4*5
Output
60
-----Note-----
Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
res = eval(s)
n = len(s)
for i in range(-1, n):
if i == -1 or s[i] == '*':
for j in range(i + 1, n + 1):
if j == n or s[j] == '*':
new_s = s[0:i + 1] + "(" + s[i + 1:j] + ")" + s[j:n]
res = max(res, eval(new_s))
print(res)
``` | vfc_12222 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/552/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3+5*7+8*4\n",
"output": "303\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 618 | Solve the following coding problem using the programming language python:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
-----Input-----
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
-----Output-----
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
-----Examples-----
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x = input()
z = input()
a, b = -1, -1
p, q ='', ''
p = x[:x.find('|')]
q = x[x.find('|') + 1:]
n = 0
while n < len(z):
if len(p) < len(q):
p += z[n]
else:
q += z[n]
n += 1
if len(p) == len(q):
print(p, '|', q, sep = '')
else:
print('Impossible')
``` | vfc_12226 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/382/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "AC|T\nL\n",
"output": "AC|TL\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "|ABC\nXYZ\n",
"output": "XYZ|ABC\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 619 | Solve the following coding problem using the programming language python:
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price $z$ chizhiks per coconut. Sasha has $x$ chizhiks, Masha has $y$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has $5$ chizhiks, Masha has $4$ chizhiks, and the price for one coconut be $3$ chizhiks. If the girls don't exchange with chizhiks, they will buy $1 + 1 = 2$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $6$ chizhiks, Masha will have $3$ chizhiks, and the girls will buy $2 + 1 = 3$ coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
-----Input-----
The first line contains three integers $x$, $y$ and $z$ ($0 \le x, y \le 10^{18}$, $1 \le z \le 10^{18}$) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
-----Output-----
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
-----Examples-----
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
-----Note-----
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $3 + 4 = 7$ coconuts.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x, y, z = list(map(int, input().split()))
c = x // z + y // z
rx = x % z
ry = y % z
if rx + ry < z:
print(f'{c} 0')
else:
if rx > ry:
print(f'{c + 1} {z - rx}')
else:
print(f'{c + 1} {z - ry}')
``` | vfc_12230 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1181/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 3\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 8 2\n",
"output": "7 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5673 9835 437\n",
"output": "35 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 1\n",
"output": "0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1 1\n",
"output": "1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 1\n",
"output": "1 0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 620 | Solve the following coding problem using the programming language python:
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.
Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.
-----Input-----
The input consists of three lines, each containing a pair of integer coordinates x_{i} and y_{i} ( - 1000 ≤ x_{i}, y_{i} ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.
-----Output-----
First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.
Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.
-----Example-----
Input
0 0
1 0
0 1
Output
3
1 -1
-1 1
1 1
-----Note-----
If you need clarification of what parallelogram is, please check Wikipedia page:
https://en.wikipedia.org/wiki/Parallelogram
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x1, y1 = list(map(int, input().split()))
x2, y2 = list(map(int, input().split()))
x3, y3 = list(map(int, input().split()))
a = set()
a.add(((x1 + x2) - x3, y1 + y2 - y3))
a.add(((x1 + x3) - x2, y1 + y3 - y2))
a.add(((x2 + x3) - x1, y2 + y3 - y1))
print(len(a))
for i in a:
print(*i)
``` | vfc_12234 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/749/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0\n1 0\n0 1\n",
"output": "3\n1 -1\n-1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 -1\n-1 0\n1 1\n",
"output": "3\n-2 -2\n2 0\n0 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1 -1\n0 1\n1 1\n",
"output": "3\n-2 -1\n0 -1\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 1000\n-1000 -1000\n-1000 1000\n",
"output": "3\n1000 -1000\n1000 3000\n-3000 -1000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1000 1000\n1000 -1000\n-1000 -1000\n",
"output": "3\n1000 1000\n-3000 1000\n1000 -3000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-4 -5\n7 10\n3 -10\n",
"output": "3\n0 15\n-8 -25\n14 5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 621 | Solve the following coding problem using the programming language python:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value a_{i}, the company's profit on the i-th day. If a_{i} is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (a_{i} < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence a_{i}, will print the minimum number of folders.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a_1, a_2, ..., a_{n} (|a_{i}| ≤ 100), where a_{i} means the company profit on the i-th day. It is possible that the company has no days with the negative a_{i}.
-----Output-----
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b_1, b_2, ..., b_{k}, where b_{j} is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
-----Examples-----
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
-----Note-----
Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import re
import itertools
from collections import Counter
class Task:
a = []
answer = []
def getData(self):
input()
self.a = [int(x) for x in input().split(" ")]
def solve(self):
currentFolderCounter = 0
badDaysCounter = 0
for x in self.a:
if x >= 0:
currentFolderCounter += 1
elif badDaysCounter <= 1:
currentFolderCounter += 1
badDaysCounter += 1
else:
self.answer += [currentFolderCounter]
currentFolderCounter = 1
badDaysCounter = 1
if currentFolderCounter > 0:
self.answer += [currentFolderCounter]
def printAnswer(self):
print(len(self.answer))
print(re.sub('[\[\],]', '', str(self.answer)))
task = Task();
task.getData();
task.solve();
task.printAnswer();
``` | vfc_12238 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/250/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"output": "3\n5 3 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 -1 100 -1 0\n",
"output": "1\n5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n",
"output": "1\n1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n-1\n",
"output": "1\n1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0\n",
"output": "1\n2 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 622 | Solve the following coding problem using the programming language python:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n - 1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1, 2, 1] after the first step, the sequence [1, 2, 1, 3, 1, 2, 1] after the second step.
The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i. e. after (n - 1) steps.
Please help Chloe to solve the problem!
-----Input-----
The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2^{n} - 1).
-----Output-----
Print single integer — the integer at the k-th position in the obtained sequence.
-----Examples-----
Input
3 2
Output
2
Input
4 8
Output
4
-----Note-----
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = map(int, input().split())
res = 1
while (k % 2 == 0):
res += 1
k //= 2
print(res)
``` | vfc_12242 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/743/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 8\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 27\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 44\n",
"output": "3",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 623 | Solve the following coding problem using the programming language python:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a_1 percent and second one is charged at a_2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
-----Input-----
The first line of the input contains two positive integers a_1 and a_2 (1 ≤ a_1, a_2 ≤ 100), the initial charge level of first and second joystick respectively.
-----Output-----
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
-----Examples-----
Input
3 5
Output
6
Input
4 4
Output
5
-----Note-----
In the first sample game lasts for 6 minute by using the following algorithm: at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a,b=map(int,input().split())
ans=0
while a>0 and b>0:
if max(a,b)>1: ans+=1
if a<b: a+=3
else: b+=3
a-=2;b-=2
print(ans)
``` | vfc_12246 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/651/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100\n",
"output": "197\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 625 | Solve the following coding problem using the programming language python:
For a positive integer n let's define a function f:
f(n) = - 1 + 2 - 3 + .. + ( - 1)^{n}n
Your task is to calculate f(n) for a given integer n.
-----Input-----
The single line contains the positive integer n (1 ≤ n ≤ 10^15).
-----Output-----
Print f(n) in a single line.
-----Examples-----
Input
4
Output
2
Input
5
Output
-3
-----Note-----
f(4) = - 1 + 2 - 3 + 4 = 2
f(5) = - 1 + 2 - 3 + 4 - 5 = - 3
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
x=n//2
if(n%2==0):
print(x)
else:
print(x-n)
``` | vfc_12254 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/486/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "-3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 626 | Solve the following coding problem using the programming language python:
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least a_{i} any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
-----Input-----
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
-----Output-----
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
-----Examples-----
Input
3
0 2 0
Output
1
Input
5
4 2 3 0 1
Output
3
Input
7
0 3 1 0 5 2 6
Output
2
-----Note-----
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
info = 0
i = 0
dir = 1
result = 0
while True:
if info >= a[i]:
info += 1
a[i] = n + 1
if info == n:
break
i += dir
if i < 0 or i == n:
dir = -dir
i += dir
result += 1
print(result)
``` | vfc_12258 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/583/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 2 0\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 627 | Solve the following coding problem using the programming language python:
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.
String $s = s_1 s_2 \dots s_n$ is lexicographically smaller than string $t = t_1 t_2 \dots t_m$ if $n < m$ and $s_1 = t_1, s_2 = t_2, \dots, s_n = t_n$ or there exists a number $p$ such that $p \le min(n, m)$ and $s_1 = t_1, s_2 = t_2, \dots, s_{p-1} = t_{p-1}$ and $s_p < t_p$.
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".
-----Input-----
The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of $s$.
The second line of the input contains exactly $n$ lowercase Latin letters — the string $s$.
-----Output-----
Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string $s$.
-----Examples-----
Input
3
aaa
Output
aa
Input
5
abcda
Output
abca
-----Note-----
In the first example you can remove any character of $s$ to obtain the string "aa".
In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
s = input()
for i in range(len(s) - 1):
if s[i] > s[i + 1]:
print(s[:i] + s[i + 1:len(s)])
return
print(s[:len(s) - 1])
``` | vfc_12262 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1076/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\naaa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nabcda\n",
"output": "abca\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nzz\n",
"output": "z\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nok\n",
"output": "k\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nabcd\n",
"output": "abc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naabbb\n",
"output": "aabb\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 628 | Solve the following coding problem using the programming language python:
Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was promoted and now he is moving into a new office.
He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the bitwise AND of the values of all the shelves.
He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office.
The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 < a_i < 2^{50}$) — the prices of the books in the order they stand on the old shelf.
-----Output-----
Print the maximum possible beauty of $k$ shelves in the new office.
-----Examples-----
Input
10 4
9 14 28 1 7 13 15 29 2 31
Output
24
Input
7 3
3 14 15 92 65 35 89
Output
64
-----Note-----
In the first example you can split the books as follows:
$$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$
In the second example you can split the books as follows:
$$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/usr/bin/env python3
[n, k] = list(map(int, input().strip().split()))
ais = list(map(int, input().strip().split()))
iais = [0 for _ in range(n + 1)]
for i in range(n):
iais[i + 1] = iais[i] + ais[i]
def calc(k, split):
res = 0
for i in range(k):
res &= iais[split[i + 1]] - iais[split[i]]
return res
def check_mask(mask):
dp = [[False for j in range(n + 1)] for i in range(k + 1)]
for j in range(1, n - k + 1 + 1):
dp[1][j] = (iais[j] & mask == mask)
if not any(dp[1]):
return False
for i in range(2, k + 1):
for j in range(i, n - (k - i) + 1):
dp[i][j] = any(dp[i - 1][r] and ((iais[j] - iais[r]) & mask == mask) for r in range(i - 1, j - 1 + 1))
if not any(dp[i]):
return False
return dp[k][n]
mask = 0
for i in range(55, -1, -1):
if check_mask(mask | (1 << i)):
mask |= 1 << i
print (mask)
``` | vfc_12266 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/981/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 4\n9 14 28 1 7 13 15 29 2 31\n",
"output": "24\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 629 | Solve the following coding problem using the programming language python:
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in is not large. The houses in it are located in two rows, n houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row.
The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets.
Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time.
The traffic light on the crosswalk from the j-th house of the i-th row to the (j + 1)-th house of the same row has waiting time equal to a_{ij} (1 ≤ i ≤ 2, 1 ≤ j ≤ n - 1). For the traffic light on the crossing from the j-th house of one row to the j-th house of another row the waiting time equals b_{j} (1 ≤ j ≤ n). The city doesn't have any other crossings.
The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing. [Image] Figure to the first sample.
Help Laurenty determine the minimum total time he needs to wait at the crossroads.
-----Input-----
The first line of the input contains integer n (2 ≤ n ≤ 50) — the number of houses in each row.
Each of the next two lines contains n - 1 space-separated integer — values a_{ij} (1 ≤ a_{ij} ≤ 100).
The last line contains n space-separated integers b_{j} (1 ≤ b_{j} ≤ 100).
-----Output-----
Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.
-----Examples-----
Input
4
1 2 3
3 2 1
3 2 2 3
Output
12
Input
3
1 2
3 3
2 1 3
Output
11
Input
2
1
1
1 1
Output
4
-----Note-----
The first sample is shown on the figure above.
In the second sample, Laurenty's path can look as follows: Laurenty crosses the avenue, the waiting time is 3; Laurenty uses the second crossing in the first row, the waiting time is 2; Laurenty uses the first crossing in the first row, the waiting time is 1; Laurenty uses the first crossing in the first row, the waiting time is 1; Laurenty crosses the avenue, the waiting time is 1; Laurenty uses the second crossing in the second row, the waiting time is 3. In total we get that the answer equals 11.
In the last sample Laurenty visits all the crossings, so the answer is 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = [[], []]
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = float('+inf')
for i in range(n):
for j in range(n):
if i == j:
continue
cur = sum(a[1][i:]) + sum(a[0][:i]) + sum(a[0][:j]) + sum(a[1][j:]) + b[i] + b[j]
ans = min(ans, cur)
print(ans)
``` | vfc_12270 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/586/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3\n3 2 1\n3 2 2 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2\n3 3\n2 1 3\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n1\n1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n1\n2 1\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 630 | Solve the following coding problem using the programming language python:
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to n where n is the total number of messages in the chat.
Each message might contain a link to an earlier message which it is a reply to. When opening a message x or getting a link to it, the dialogue is shown in such a way that k previous messages, message x and k next messages are visible (with respect to message x). In case there are less than k messages somewhere, they are yet all shown.
Digging deep into your message history, you always read all visible messages and then go by the link in the current message x (if there is one) and continue reading in the same manner.
Determine the number of messages you'll read if your start from message number t for all t from 1 to n. Calculate these numbers independently. If you start with message x, the initial configuration is x itself, k previous and k next messages. Messages read multiple times are considered as one.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 10^5, 0 ≤ k ≤ n) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < i), where a_{i} denotes the i-th message link destination or zero, if there's no link from i. All messages are listed in chronological order. It's guaranteed that the link from message x goes to message with number strictly less than x.
-----Output-----
Print n integers with i-th denoting the number of distinct messages you can read starting from message i and traversing the links while possible.
-----Examples-----
Input
6 0
0 1 1 2 3 2
Output
1 2 2 3 3 3
Input
10 1
0 1 0 3 4 5 2 3 7 0
Output
2 3 3 4 5 6 6 6 8 2
Input
2 2
0 1
Output
2 2
-----Note-----
Consider i = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case i = 6 gives you messages 5, 6, 7 since k = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# python3
def readline(): return tuple(map(int, input().split()))
def main():
n, k = readline()
a = readline()
answer = list()
for (i, link) in enumerate(a):
bottom = max(0, i - k)
top = min(n, i + k + 1)
if link == 0:
answer.append(top - bottom)
else:
bottom = max(bottom, link + k)
answer.append(max(0, top - bottom) + answer[link - 1])
print(" ".join(map(str, answer)))
main()
``` | vfc_12274 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/928/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 0\n0 1 1 2 3 2\n",
"output": "1 2 2 3 3 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n0 1 0 3 4 5 2 3 7 0\n",
"output": "2 3 3 4 5 6 6 6 8 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n0 1\n",
"output": "2 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n0\n",
"output": "1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n0 1 2 3 1\n",
"output": "3 4 5 5 5 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 631 | Solve the following coding problem using the programming language python:
For a given array $a$ consisting of $n$ integers and a given integer $m$ find if it is possible to reorder elements of the array $a$ in such a way that $\sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}}$ equals $m$? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, $\frac{5}{2}=2.5$.
-----Input-----
The first line contains a single integer $t$ — the number of test cases ($1 \le t \le 100$). The test cases follow, each in two lines.
The first line of a test case contains two integers $n$ and $m$ ($1 \le n \le 100$, $0 \le m \le 10^6$). The second line contains integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^6$) — the elements of the array.
-----Output-----
For each test case print "YES", if it is possible to reorder the elements of the array in such a way that the given formula gives the given value, and "NO" otherwise.
-----Example-----
Input
2
3 8
2 5 1
4 4
0 1 2 3
Output
YES
NO
-----Note-----
In the first test case one of the reorders could be $[1, 2, 5]$. The sum is equal to $(\frac{1}{1} + \frac{2}{2} + \frac{5}{3}) + (\frac{2}{2} + \frac{5}{3}) + (\frac{5}{3}) = 8$. The brackets denote the inner sum $\sum_{j=i}^{n}{\frac{a_j}{j}}$, while the summation of brackets corresponds to the sum over $i$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input=sys.stdin.readline
T=int(input())
for _ in range(T):
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
s=sum(A)
if (s==m):
print("YES")
else:
print("NO")
``` | vfc_12278 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1436/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 8\n2 5 1\n4 4\n0 1 2 3\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 633 | Solve the following coding problem using the programming language python:
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$ $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to $|V|$.
Construct a relatively prime graph with $n$ vertices and $m$ edges such that it is connected and it contains neither self-loops nor multiple edges.
If there exists no valid graph with the given number of vertices and edges then output "Impossible".
If there are multiple answers then print any of them.
-----Input-----
The only line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of vertices and the number of edges.
-----Output-----
If there exists no valid graph with the given number of vertices and edges then output "Impossible".
Otherwise print the answer in the following format:
The first line should contain the word "Possible".
The $i$-th of the next $m$ lines should contain the $i$-th edge $(v_i, u_i)$ of the resulting graph ($1 \le v_i, u_i \le n, v_i \neq u_i$). For each pair $(v, u)$ there can be no more pairs $(v, u)$ or $(u, v)$. The vertices are numbered from $1$ to $n$.
If there are multiple answers then print any of them.
-----Examples-----
Input
5 6
Output
Possible
2 5
3 2
5 1
3 4
4 1
5 4
Input
6 12
Output
Impossible
-----Note-----
Here is the representation of the graph from the first example: [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import *
n, m = list(map(int, input().split()))
if m < n - 1:
print('Impossible')
return
r = [(i + 1, i + 2) for i in range(n - 1)]
k = n - 1
if k >= m:
print('Possible')
for x in r:
print(*x)
return
for i in range(1, n + 1):
for j in range(i + 2, n + 1):
if gcd(i, j) == 1:
r.append((i, j))
k += 1
if k >= m:
print('Possible')
for x in r:
print(*x)
return
print('Impossible')
``` | vfc_12286 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1009/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n",
"output": "Possible\n1 2\n2 3\n3 4\n4 5\n1 3\n1 4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 634 | Solve the following coding problem using the programming language python:
In a far away land, there are two cities near a river. One day, the cities decide that they have too little space and would like to reclaim some of the river area into land.
The river area can be represented by a grid with r rows and exactly two columns — each cell represents a rectangular area. The rows are numbered 1 through r from top to bottom, while the columns are numbered 1 and 2.
Initially, all of the cells are occupied by the river. The plan is to turn some of those cells into land one by one, with the cities alternately choosing a cell to reclaim, and continuing until no more cells can be reclaimed.
However, the river is also used as a major trade route. The cities need to make sure that ships will still be able to sail from one end of the river to the other. More formally, if a cell (r, c) has been reclaimed, it is not allowed to reclaim any of the cells (r - 1, 3 - c), (r, 3 - c), or (r + 1, 3 - c).
The cities are not on friendly terms, and each city wants to be the last city to reclaim a cell (they don't care about how many cells they reclaim, just who reclaims a cell last). The cities have already reclaimed n cells. Your job is to determine which city will be the last to reclaim a cell, assuming both choose cells optimally from current moment.
-----Input-----
The first line consists of two integers r and n (1 ≤ r ≤ 100, 0 ≤ n ≤ r). Then n lines follow, describing the cells that were already reclaimed. Each line consists of two integers: r_{i} and c_{i} (1 ≤ r_{i} ≤ r, 1 ≤ c_{i} ≤ 2), which represent the cell located at row r_{i} and column c_{i}. All of the lines describing the cells will be distinct, and the reclaimed cells will not violate the constraints above.
-----Output-----
Output "WIN" if the city whose turn it is to choose a cell can guarantee that they will be the last to choose a cell. Otherwise print "LOSE".
-----Examples-----
Input
3 1
1 1
Output
WIN
Input
12 2
4 1
8 1
Output
WIN
Input
1 1
1 2
Output
LOSE
-----Note-----
In the first example, there are 3 possible cells for the first city to reclaim: (2, 1), (3, 1), or (3, 2). The first two possibilities both lose, as they leave exactly one cell for the other city. [Image]
However, reclaiming the cell at (3, 2) leaves no more cells that can be reclaimed, and therefore the first city wins. $\text{-}$
In the third example, there are no cells that can be reclaimed.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
r,n = [int(x) for x in input().split()]
cells = [[int(x) for x in input().split()] for i in range(n)]
cells.sort()
#print(cells)
out = False
res = {True:"WIN",False:"LOSE"}
if len(cells) == 0: print(res[r%2 == 1])
else:
out = False
#print(cells[0][0] > 1)
#print(cells[-1][0] < r)
for i in range(1,n):
out ^= ((cells[i][0]-cells[i-1][0]-1)%2) ^ (cells[i][1] != cells[i-1][1])
dif = abs((cells[0][0]-1)-(r-cells[-1][0]))
#print(out,dif)
hi,lo = max(cells[0][0]-1,r-cells[-1][0]),min(cells[0][0]-1,r-cells[-1][0])
#print(out,dif,lo,hi)
if lo > 1:
if dif == 0:
print(res[out])
elif dif == 1 and lo % 2 == 0:
print(res[not out])
else:
print(res[True])
elif lo == 0:
if hi == 0: print(res[out])
elif hi == 1:
print(res[not out])
else:
print(res[True])
elif lo == 1:
if hi == 1:
print(res[out])
else:
print(res[True])
``` | vfc_12290 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/335/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n1 1\n",
"output": "WIN\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12 2\n4 1\n8 1\n",
"output": "WIN\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1 2\n",
"output": "LOSE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 0\n",
"output": "LOSE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 44\n41 1\n13 1\n52 1\n83 1\n64 2\n86 2\n12 1\n77 1\n100 2\n97 2\n58 1\n33 2\n8 1\n72 2\n2 1\n88 1\n50 2\n4 1\n18 1\n36 2\n46 2\n57 1\n29 2\n22 1\n75 2\n44 2\n80 2\n84 1\n62 1\n42 1\n94 1\n96 2\n31 2\n45 2\n10 2\n17 1\n5 1\n53 1\n98 2\n21 1\n82 1\n15 1\n68 2\n91 1\n",
"output": "WIN\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 636 | Solve the following coding problem using the programming language python:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes a_{i} days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
-----Input-----
The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 100), representing number of days required to learn the i-th instrument.
-----Output-----
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
-----Examples-----
Input
4 10
4 3 1 2
Output
4
1 2 3 4
Input
5 6
4 3 1 1 2
Output
3
1 3 4
Input
1 3
4
Output
0
-----Note-----
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = map(int, input().split())
arr = [int(i) for i in input().split()]
arr2 = []
for i in range(n):
arr2.append((arr[i], i))
arr2.sort()
ans = []
for i in arr2:
if k >= i[0]:
k -= i[0]
ans.append(i[1])
print(len(ans))
for i in ans:
print(i + 1, end = ' ')
``` | vfc_12298 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/507/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 10\n4 3 1 2\n",
"output": "4\n1 2 3 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n4 3 1 1 2\n",
"output": "3\n3 4 5",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 638 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of $n$ students. Students will take the exam one-by-one in order from $1$-th to $n$-th. Rules of the exam are following: The $i$-th student randomly chooses a ticket. if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam. if the student finds the ticket easy, he spends exactly $t_i$ minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is $M$ minutes ($\max t_i \le M$), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student $i$, you should count the minimum possible number of students who need to fail the exam so the $i$-th student has enough time to pass the exam.
For each student $i$, find the answer independently. That is, if when finding the answer for the student $i_1$ some student $j$ should leave, then while finding the answer for $i_2$ ($i_2>i_1$) the student $j$ student does not have to go home.
-----Input-----
The first line of the input contains two integers $n$ and $M$ ($1 \le n \le 100$, $1 \le M \le 100$) — the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains $n$ integers $t_i$ ($1 \le t_i \le 100$) — time in minutes that $i$-th student spends to answer to a ticket.
It's guaranteed that all values of $t_i$ are not greater than $M$.
-----Output-----
Print $n$ numbers: the $i$-th number must be equal to the minimum number of students who have to leave the exam in order to $i$-th student has enough time to pass the exam.
-----Examples-----
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
-----Note-----
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed $M=15$ (the sum is $1+2+3+4+5=15$). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are $0$.
In order for the $6$-th student to pass the exam, it is necessary that at least $2$ students must fail it before (for example, the $3$-rd and $4$-th, then the $6$-th will finish its exam in $1+2+5+6=14$ minutes, which does not exceed $M$).
In order for the $7$-th student to pass the exam, it is necessary that at least $3$ students must fail it before (for example, the $2$-nd, $5$-th and $6$-th, then the $7$-th will finish its exam in $1+3+4+7=15$ minutes, which does not exceed $M$).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin
n,m=list(map(int,stdin.readline().strip().split()))
s=list(map(int,stdin.readline().strip().split()))
ans=[0 for i in range(n)]
sm=[0 for i in range(n)]
sm1=[0 for i in range(n)]
for i in range(n):
if i==0:
sm[i]=s[i]
else:
sm[i]=sm[i-1]+s[i]
for i in range(n-1,-1,-1):
if i==n-1:
sm1[i]=s[i]
else:
sm1[i]=sm1[i+1]+s[i]
for i in range(n):
if sm[i]<=m:
continue
x=sm[i]
s2=s[0:i]
s2.sort()
r=0
while x>m:
x-=s2[-1]
s2.pop()
r+=1
ans[i]=r
print(*ans)
``` | vfc_12306 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1185/C1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 15\n1 2 3 4 5 6 7\n",
"output": "0 0 0 0 0 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 100\n80 40 40 40 60\n",
"output": "0 1 1 2 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 100\n99\n",
"output": "0 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 639 | Solve the following coding problem using the programming language python:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
-----Input-----
The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains n distinct non-negative integers not exceeding 100 that represent the set.
-----Output-----
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
-----Examples-----
Input
5 3
0 4 5 6 7
Output
2
Input
1 0
0
Output
1
Input
5 0
1 2 3 4 5
Output
0
-----Note-----
For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
R=lambda:list(map(int,input().split()))
n,x=R()
a=R()
print(x-len([i for i in a if i<x])+(1 if x in a else 0))
``` | vfc_12310 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/862/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n0 4 5 6 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n1 2 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n57 1 47 9 93 37 76 70 78 15\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 640 | Solve the following coding problem using the programming language python:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number a, the second player wrote number b. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
-----Input-----
The single line contains two integers a and b (1 ≤ a, b ≤ 6) — the numbers written on the paper by the first and second player, correspondingly.
-----Output-----
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
-----Examples-----
Input
2 5
Output
3 0 3
Input
2 4
Output
2 1 3
-----Note-----
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number a is closer to number x than number b, if |a - x| < |b - x|.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = list(map(int, input().split()))
res = [0,0,0]
for i in range(1, 7):
if abs(a - i) < abs(b - i):
res[0] += 1
elif abs(a - i) == abs(b - i):
res[1] += 1
else:
res[2] += 1
print(' '.join(map(str, res)))
``` | vfc_12314 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/378/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5\n",
"output": "3 0 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n",
"output": "2 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n",
"output": "2 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 6\n",
"output": "3 0 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n",
"output": "3 1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n",
"output": "2 0 4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 642 | Solve the following coding problem using the programming language python:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 10^9, 0 ≤ m ≤ 3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d_1, d_2, ..., d_{m} (1 ≤ d_{i} ≤ n) — the numbers of the dirty stairs (in an arbitrary order).
-----Output-----
Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO".
-----Examples-----
Input
10 5
2 4 8 3 6
Output
NO
Input
10 5
2 4 5 7 9
Output
YES
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,m=list(map(int,input().split()))
if(m!=0):
L=list(map(int,input().split()))
else:
L=[]
L.sort()
valid=True
for i in range(2,m):
if(L[i]-L[i-2]==2):
valid=False
if(m==0 or(valid and L[0]!=1 and L[-1]!=n)):
print("YES")
else:
print("NO")
``` | vfc_12322 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/362/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n2 4 8 3 6\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n2 4 5 7 9\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9\n2 3 4 5 6 7 8 9 10\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n4 5\n",
"output": "NO",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 644 | Solve the following coding problem using the programming language python:
You are given a function $f$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $x$. $x$ is an integer variable and can be assigned values from $0$ to $2^{32}-1$. The function contains three types of commands:
for $n$ — for loop; end — every command between "for $n$" and corresponding "end" is executed $n$ times; add — adds 1 to $x$.
After the execution of these commands, value of $x$ is returned.
Every "for $n$" is matched with "end", thus the function is guaranteed to be valid. "for $n$" can be immediately followed by "end"."add" command can be outside of any for loops.
Notice that "add" commands might overflow the value of $x$! It means that the value of $x$ becomes greater than $2^{32}-1$ after some "add" command.
Now you run $f(0)$ and wonder if the resulting value of $x$ is correct or some overflow made it incorrect.
If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of $x$.
-----Input-----
The first line contains a single integer $l$ ($1 \le l \le 10^5$) — the number of lines in the function.
Each of the next $l$ lines contains a single command of one of three types:
for $n$ ($1 \le n \le 100$) — for loop; end — every command between "for $n$" and corresponding "end" is executed $n$ times; add — adds 1 to $x$.
-----Output-----
If overflow happened during execution of $f(0)$, then output "OVERFLOW!!!", otherwise print the resulting value of $x$.
-----Examples-----
Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!
-----Note-----
In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for $n$" can be immediately followed by "end" and that "add" can be outside of any for loops.
In the second example there are no commands "add", thus the returning value is 0.
In the third example "add" command is executed too many times, which causes $x$ to go over $2^{32}-1$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
l = int(input())
a = [0] * (l+1)
b = [1] * (l+1)
st = 0
en = 1
cur = 0
for i in range(l):
x = input()
if x == 'add':
a[en-1] += 1
elif x[0] == 'f':
d = x.split()
v = int(d[1])
a[en] = 0
b[en] = v
en += 1
else:
en -= 1
a[en-1] += a[en] * b[en]
if a[en-1] >= 2 ** 32:
cur = 1
break
if cur == 1 or a[0] >= 2 ** 32:
print('OVERFLOW!!!')
else:
print(a[0])
``` | vfc_12330 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1175/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\nadd\nfor 43\nend\nfor 10\nfor 15\nadd\nend\nadd\nend\n",
"output": "161\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nfor 62\nend\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 645 | Solve the following coding problem using the programming language python:
Your friend has n cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
-----Input-----
The first and only line of input will contain a string s (1 ≤ |s| ≤ 50), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.
-----Output-----
Print a single integer, the minimum number of cards you must turn over to verify your claim.
-----Examples-----
Input
ee
Output
2
Input
z
Output
0
Input
0ay1
Output
2
-----Note-----
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x = input()
c = 0
for i in x:
if i in "aeiou13579":
c+=1
print(c)
``` | vfc_12334 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/908/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ee\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "z\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0ay1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0abcdefghijklmnopqrstuvwxyz1234567896\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "01234567890123456789012345678901234567890123456789\n",
"output": "25\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 646 | Solve the following coding problem using the programming language python:
There are $n$ detachments on the surface, numbered from $1$ to $n$, the $i$-th detachment is placed in a point with coordinates $(x_i, y_i)$. All detachments are placed in different points.
Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts.
To move from one detachment to another he should first choose one of four directions of movement (up, right, left or down) and then start moving with the constant speed of one unit interval in a second until he comes to a detachment. After he reaches an arbitrary detachment, he can repeat the same process.
Each $t$ seconds an orbital strike covers the whole surface, so at that moment Brimstone should be in a point where some detachment is located. He can stay with any detachment as long as needed.
Brimstone is a good commander, that's why he can create at most one detachment and place it in any empty point with integer coordinates he wants before his trip. Keep in mind that Brimstone will need to visit this detachment, too.
Help Brimstone and find such minimal $t$ that it is possible to check each detachment. If there is no such $t$ report about it.
-----Input-----
The first line contains a single integer $n$ $(2 \le n \le 1000)$ — the number of detachments.
In each of the next $n$ lines there is a pair of integers $x_i$, $y_i$ $(|x_i|, |y_i| \le 10^9)$ — the coordinates of $i$-th detachment.
It is guaranteed that all points are different.
-----Output-----
Output such minimal integer $t$ that it is possible to check all the detachments adding at most one new detachment.
If there is no such $t$, print $-1$.
-----Examples-----
Input
4
100 0
0 100
-100 0
0 -100
Output
100
Input
7
0 2
1 0
-3 0
0 -2
-1 -1
-1 -3
-2 -3
Output
-1
Input
5
0 0
0 -1
3 0
-2 0
-2 1
Output
2
Input
5
0 0
2 0
0 -1
-2 0
-2 1
Output
2
-----Note-----
In the first test it is possible to place a detachment in $(0, 0)$, so that it is possible to check all the detachments for $t = 100$. It can be proven that it is impossible to check all detachments for $t < 100$; thus the answer is $100$.
In the second test, there is no such $t$ that it is possible to check all detachments, even with adding at most one new detachment, so the answer is $-1$.
In the third test, it is possible to place a detachment in $(1, 0)$, so that Brimstone can check all the detachments for $t = 2$. It can be proven that it is the minimal such $t$.
In the fourth test, there is no need to add any detachments, because the answer will not get better ($t = 2$). It can be proven that it is the minimal such $t$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# import numpy as npy
import functools
import math
n=int(input())
x=[0 for i in range(n+2)]
y=[0 for i in range(n+2)]
adj=[[] for i in range(n+2)]
idx=[]
idy=[]
for i in range(n):
x[i],y[i]=map(int,input().split())
idx.append(i)
idy.append(i)
def cmpx(a,b):
if x[a]!=x[b]:
if x[a]<x[b]:
return -1
else:
return 1
if y[a]!=y[b]:
if y[a]<y[b]:
return -1
else:
return 1
return 0
def cmpy(a,b):
if y[a]!=y[b]:
if y[a]<y[b]:
return -1
else:
return 1
if x[a]!=x[b]:
if x[a]<x[b]:
return -1
else:
return 1
return 0
idx=sorted(idx,key=functools.cmp_to_key(cmpx))
idy=sorted(idy,key=functools.cmp_to_key(cmpy))
# print(idx)
# print(idy)
def disx(a,b):
if x[a]!=x[b]:
return 1e18
return y[b]-y[a]
def disy(a,b):
if y[a]!=y[b]:
return 1e18
return x[b]-x[a]
l=0
r=2000000000
ans=-1
while l<=r:
# print(l,r)
mid=(l+r)//2
for i in range(n):
adj[i]=[]
for i in range(n-1):
if disx(idx[i],idx[i+1])<=mid:
adj[idx[i]].append(idx[i+1])
adj[idx[i+1]].append(idx[i])
# print(idx[i],idx[i+1])
if disy(idy[i],idy[i+1])<=mid:
adj[idy[i]].append(idy[i+1])
adj[idy[i+1]].append(idy[i])
# print(idy[i],idy[i+1])
col=[0 for i in range(n)]
cur=0
def dfs(x):
col[x]=cur
for i in range(len(adj[x])):
if col[adj[x][i]]==0:
dfs(adj[x][i])
for i in range(n):
if col[i]==0:
cur=cur+1
dfs(i)
ok=0
if cur>4:
ok=0
if cur==1:
ok=1
if cur==2:
for i in range(n):
for j in range(i+1,n):
if (col[i]!=col[j]):
d1=abs(x[i]-x[j])
d2=abs(y[i]-y[j])
if d1==0 or d2==0:
if d1+d2<=2*mid:
ok=1
if d1<=mid and d2<=mid:
ok=1
if cur==3:
for i in range(n-1):
px=idx[i]
py=idx[i+1]
if x[px]==x[py] and col[px]!=col[py]:
for j in range(n):
if col[px]!=col[j] and col[py]!=col[j]:
d1=abs(y[px]-y[j])
d2=abs(y[py]-y[j])
d3=abs(x[px]-x[j])
if d1<=mid and d2<=mid and d3<=mid:
ok=1
for i in range(n-1):
px=idy[i]
py=idy[i+1]
if y[px]==y[py] and col[px]!=col[py]:
for j in range(n):
if col[px]!=col[j] and col[py]!=col[j]:
d1=abs(x[px]-x[j])
d2=abs(x[py]-x[j])
d3=abs(y[px]-y[j])
if d1<=mid and d2<=mid and d3<=mid:
ok=1
if cur==4:
for i in range(n-1):
px=idx[i]
py=idx[i+1]
if x[px]==x[py] and col[px]!=col[py]:
for j in range(n-1):
pz=idy[j]
pw=idy[j+1]
if y[pz]==y[pw] and col[pz]!=col[pw]:
if col[pz]!=col[px] and col[pz]!=col[py]:
if col[pw]!=col[px] and col[pw]!=col[py]:
d1=abs(y[px]-y[pz])
d2=abs(y[py]-y[pz])
d3=abs(x[pz]-x[px])
d4=abs(x[pw]-x[px])
if d1<=mid and d2<=mid and d3<=mid and d4<=mid:
ok=1
if ok:
ans=mid
r=mid-1
else:
l=mid+1
print(ans)
``` | vfc_12338 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1419/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n100 0\n0 100\n-100 0\n0 -100\n",
"output": "100",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n0 2\n1 0\n-3 0\n0 -2\n-1 -1\n-1 -3\n-2 -3\n",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.