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 | 293 | Solve the following coding problem using the programming language python:
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 × 5 table is 15 + 8 + 3 = 26.
-----Input-----
The first line of the input contains a single integer x (1 ≤ x ≤ 10^18) — the number of squares inside the tables Spongebob is interested in.
-----Output-----
First print a single integer k — the number of tables with exactly x distinct squares inside.
Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equality — in the order of increasing m.
-----Examples-----
Input
26
Output
6
1 26
2 9
3 5
5 3
9 2
26 1
Input
2
Output
2
1 2
2 1
Input
8
Output
4
1 8
2 3
3 2
8 1
-----Note-----
In a 1 × 2 table there are 2 1 × 1 squares. So, 2 distinct squares in total. [Image]
In a 2 × 3 table there are 6 1 × 1 squares and 2 2 × 2 squares. That is equal to 8 squares in total. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x = int(input())
def solve(x):
count = 0
lst = []
x6 = x * 6
for n in range(1, x + 1):
t, r = divmod(x6, n*(n+1))
if t < 2*n + 1:
break
if r:
continue
m, r = divmod(t + n - 1, 3)
if r:
continue
count += 2
lst.append((n, m))
nn, mm = lst[-1]
if nn == mm:
count -= 1
print(count)
for n, m in lst:
print(n, m)
if nn != mm:
print(mm, nn)
lst.reverse()
for n, m in lst[1:]:
print(m, n)
solve(x)
``` | vfc_10926 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/599/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "26\n",
"output": "6\n1 26\n2 9\n3 5\n5 3\n9 2\n26 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2\n1 2\n2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
"output": "4\n1 8\n2 3\n3 2\n8 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 294 | Solve the following coding problem using the programming language python:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.
In this problem you are given n (1 ≤ n ≤ 24) integers a_1, a_2, ..., a_{n}, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a_1 days, duration of the next month is a_2 days, and so on.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers.
The second line contains n integers a_1, a_2, ..., a_{n} (28 ≤ a_{i} ≤ 31) — the numbers you are to check.
-----Output-----
If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large).
-----Examples-----
Input
4
31 31 30 31
Output
Yes
Input
2
30 30
Output
No
Input
5
29 31 30 31 30
Output
Yes
Input
3
31 28 30
Output
No
Input
3
31 31 28
Output
Yes
-----Note-----
In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.
In the fifth example the months are: December — January — February (non-leap year).
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().split()
a = [0] * n
m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(n):
a[i] = int(s[i])
ans = "No"
for i in range(len(m) - n):
if a == m[i:i+n]:
ans = "Yes"
break
print(ans)
``` | vfc_10930 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/899/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n31 31 30 31\n",
"output": "Yes\n\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 295 | Solve the following coding problem using the programming language python:
You are given a positive integer $n$.
Find a sequence of fractions $\frac{a_i}{b_i}$, $i = 1 \ldots k$ (where $a_i$ and $b_i$ are positive integers) for some $k$ such that:
$$ \begin{cases} \text{$b_i$ divides $n$, $1 < b_i < n$ for $i = 1 \ldots k$} \\ \text{$1 \le a_i < b_i$ for $i = 1 \ldots k$} \\ \text{$\sum\limits_{i=1}^k \frac{a_i}{b_i} = 1 - \frac{1}{n}$} \end{cases} $$
-----Input-----
The input consists of a single integer $n$ ($2 \le n \le 10^9$).
-----Output-----
In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise.
If there exists such a sequence, next lines should contain a description of the sequence in the following format.
The second line should contain integer $k$ ($1 \le k \le 100\,000$) — the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most $100\,000$.
Next $k$ lines should contain fractions of the sequence with two integers $a_i$ and $b_i$ on each line.
-----Examples-----
Input
2
Output
NO
Input
6
Output
YES
2
1 2
1 3
-----Note-----
In the second example there is a sequence $\frac{1}{2}, \frac{1}{3}$ such that $\frac{1}{2} + \frac{1}{3} = 1 - \frac{1}{6}$.
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 sqrt
def phi(u):
ans = u
for i in range(2, int(sqrt(n)) + 1):
if u % i == 0:
while u % i == 0:
u = u / i
ans = ans - int(ans / i)
if n > 1:
ans = ans - int(ans / n)
return ans
def binpow(u, a, mod):
ans = 1
if a == 0:
return 1;
while a > 0:
if a % 2 == 0:
u = (u ** 2) % mod
a = int(a / 2)
else :
ans = (ans * u) % mod
a = a - 1
return int(ans)
n = int(input())
b1 = 1
b2 = 0
nn = n
for i in range(2, int(sqrt(n)) + 1):
if n%i == 0 :
while nn % i == 0:
b1 = b1 * i
nn = nn / i
b2 = int(n / b1)
break
if b2 < 2:
print("NO")
return
a1 = b1 - binpow(b2, phi(b1) - 1, b1)
a2 = b2 - int((a1*b2+1)/b1)
print("YES")
print(2)
print(a1, b1)
print(a2, b2)
``` | vfc_10934 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1089/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"output": "YES\n2\n1 2\n1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 296 | Solve the following coding problem using the programming language python:
Vasya should paint a fence in front of his own cottage. The fence is a sequence of n wooden boards arranged in a single row. Each board is a 1 centimeter wide rectangle. Let's number the board fence using numbers 1, 2, ..., n from left to right. The height of the i-th board is h_{i} centimeters.
Vasya has a 1 centimeter wide brush and the paint of two colors, red and green. Of course, the amount of the paint is limited. Vasya counted the area he can paint each of the colors. It turned out that he can not paint over a square centimeters of the fence red, and he can not paint over b square centimeters green. Each board of the fence should be painted exactly one of the two colors. Perhaps Vasya won't need one of the colors.
In addition, Vasya wants his fence to look smart. To do this, he should paint the fence so as to minimize the value that Vasya called the fence unattractiveness value. Vasya believes that two consecutive fence boards, painted different colors, look unattractive. The unattractiveness value of a fence is the total length of contact between the neighboring boards of various colors. To make the fence look nice, you need to minimize the value as low as possible. Your task is to find what is the minimum unattractiveness Vasya can get, if he paints his fence completely. $1$
The picture shows the fence, where the heights of boards (from left to right) are 2,3,2,4,3,1. The first and the fifth boards are painted red, the others are painted green. The first and the second boards have contact length 2, the fourth and fifth boards have contact length 3, the fifth and the sixth have contact length 1. Therefore, the unattractiveness of the given painted fence is 2+3+1=6.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 200) — the number of boards in Vasya's fence.
The second line contains two integers a and b (0 ≤ a, b ≤ 4·10^4) — the area that can be painted red and the area that can be painted green, correspondingly.
The third line contains a sequence of n integers h_1, h_2, ..., h_{n} (1 ≤ h_{i} ≤ 200) — the heights of the fence boards.
All numbers in the lines are separated by single spaces.
-----Output-----
Print a single number — the minimum unattractiveness value Vasya can get if he paints his fence completely. If it is impossible to do, print - 1.
-----Examples-----
Input
4
5 7
3 3 4 1
Output
3
Input
3
2 3
1 3 1
Output
2
Input
3
3 3
2 2 2
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
r = open('input.txt')
w = open('output.txt', mode='w')
f = lambda: map(int, r.readline().split())
f()
a, b = f()
if a > b: a, b = b, a
n = 40001
u, v = [n] * n, [n] * n
x = s = 0
u[0] = v[0] = 0
for y in f():
s += y
p = []
h = min(x, y)
for d in range(min(s, a), max(0, s - b - y) - 1, -1):
t = v[d]
if u[d] != n:
u[d + y] = min(u[d], u[d + y])
v[d] = min(t, u[d] + h)
u[d] = n
if t != n:
u[d + y] = min(u[d + y], t + h)
x = y
i = max(s - b, 0)
j = min(s, a) + 1
d = min(u[i:j] + v[i:j]) if i < j else n
w.write(str(d if d < n else -1))
w.close()
r.close()
``` | vfc_10938 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/234/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5 7\n3 3 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 297 | Solve the following coding problem using the programming language python:
Vasya has got three integers $n$, $m$ and $k$. He'd like to find three integer points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, such that $0 \le x_1, x_2, x_3 \le n$, $0 \le y_1, y_2, y_3 \le m$ and the area of the triangle formed by these points is equal to $\frac{nm}{k}$.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
-----Input-----
The single line contains three integers $n$, $m$, $k$ ($1\le n, m \le 10^9$, $2 \le k \le 10^9$).
-----Output-----
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers $x_i, y_i$ — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
-----Note-----
In the first example area of the triangle should be equal to $\frac{nm}{k} = 4$. The triangle mentioned in the output is pictured below: [Image]
In the second example there is no triangle with area $\frac{nm}{k} = \frac{16}{7}$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def gcd(a, b):
a, b = max(a, b), min(a, b)
while b:
a, b = b, a % b
return a
n, m, k = list(map(int, input().split()))
_n, _m = n, m
n, k = n // gcd(n, k), k // gcd(n, k)
m, k = m // gcd(m, k), k // gcd(m, k)
a = 2
a, k = a // gcd(a, k), k // gcd(a, k)
if k != 1:
print("NO")
elif a * n <= _n:
print("YES")
print("0 0")
print(a * n, 0)
print(0, m)
elif a * m <= _m:
print("YES")
print("0 0")
print(n, 0)
print(0, m * a)
else:
print("NO")
``` | vfc_10942 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1030/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 3\n",
"output": "YES\n0 0\n0 2\n4 0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 298 | Solve the following coding problem using the programming language python:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
-----Input-----
The first line contains two integers n and k (1 ≤ n, k ≤ 10^18, k ≤ n) — the number of sticks drawn by Sasha and the number k — the number of sticks to be crossed out on each turn.
-----Output-----
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
-----Examples-----
Input
1 1
Output
YES
Input
10 4
Output
NO
-----Note-----
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
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()))
n=(n//k)%2
print('YES' if n==1 else 'NO')
``` | vfc_10946 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/832/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 299 | Solve the following coding problem using the programming language python:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise a_{i} times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the n-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 20). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 25) — the number of times Greg repeats the exercises.
-----Output-----
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
-----Examples-----
Input
2
2 8
Output
biceps
Input
3
5 1 10
Output
back
Input
7
3 3 2 7 9 6 8
Output
chest
-----Note-----
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
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().split()
A=[0,0,0]
for i in range(n):
A[i%3]+=int(s[i])
m=max(A)
if(m==A[0]):
print("chest")
elif(m==A[1]):
print("biceps")
else:
print("back")
``` | vfc_10950 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/255/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 8\n",
"output": "biceps\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 1 10\n",
"output": "back\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n3 3 2 7 9 6 8\n",
"output": "chest\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 6 6 2\n",
"output": "chest\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n8 2 2 6 3\n",
"output": "chest\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 300 | Solve the following coding problem using the programming language python:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
-----Input-----
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
-----Output-----
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
-----Examples-----
Input
3
4 4 4
Output
2
Input
4
5 4 5 5
Output
0
Input
4
5 3 3 5
Output
1
-----Note-----
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def read_input():
return map(int, input().split())
n = int(input())
a = sorted(read_input())
s = sum(a)
i = 0
while 2 * s < 9 * n:
delta = 5 - a[i]
s += delta
i += 1
print(i)
``` | vfc_10954 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/991/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 4 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5 4 5 5\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 301 | Solve the following coding problem using the programming language python:
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
u, v = list(map(int, input().split()))
if v < u or (v - u) % 2 != 0:
print(-1)
else:
if u == v:
if u == 0:
print(0)
else:
print("1\n" + str(u))
else:
w = (v - u) // 2
if (w | u) == (w + u):
print("2\n" + str(w|u) + ' ' + str(w))
else:
print("3\n" + str(u) + ' ' + str(w) + ' ' + str(w))
``` | vfc_10958 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1325/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n",
"output": "2\n3 1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 302 | Solve the following coding problem using the programming language python:
Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.
-----Input-----
The first line of the input contains integer n (1 ≤ n < 10^15).
-----Output-----
Print expected minimal number of digits 1.
-----Examples-----
Input
121
Output
6
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Testing Round 10 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
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 [int(x) for x in inputs.split()]
def write(s="\n"):
if isinstance(s, list): s = " ".join(s)
s = str(s)
print(s, end="")
################################################### SOLUTION
def g(n):
return (10**n-1)//9
def solve(n):
if n <= 6: return n
if 7 <= n <= 11: return 13-n
l = 1
while g(l) < n: l += 1
l -= 1
gl = g(l)
a = n
res1 = 0
res1 += (a // gl) * l
a %= gl
res1 += solve(a)
b = g(l+1) - n
res2 = l+1
res2 += (b // gl) * l
b %= gl
res2 += solve(b)
return min(res1, res2)
n, = read()
print(solve(n))
``` | vfc_10962 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/440/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "121\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 303 | Solve the following coding problem using the programming language python:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion:
$(a, b) \rightarrow(a + x, b + y)$ $(a, b) \rightarrow(a + x, b - y)$ $(a, b) \rightarrow(a - x, b + y)$ $(a, b) \rightarrow(a - x, b - y)$
Map shows that the position of Captain Bill the Hummingbird is (x_1, y_1) and the position of the treasure is (x_2, y_2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times.
-----Input-----
The first line contains four integer numbers x_1, y_1, x_2, y_2 ( - 10^5 ≤ x_1, y_1, x_2, y_2 ≤ 10^5) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers x, y (1 ≤ x, y ≤ 10^5) — values on the potion bottle.
-----Output-----
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
-----Examples-----
Input
0 0 0 6
2 3
Output
YES
Input
1 1 3 6
1 5
Output
NO
-----Note-----
In the first example there exists such sequence of moves:
$(0,0) \rightarrow(2,3)$ — the first type of move $(2,3) \rightarrow(0,6)$ — the third type of move
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 = list(map(int, input().split()))
x, y = list(map(int, input().split()))
x, y = abs(x), abs(y)
x_ = abs(x2 - x1)
y_ = abs(y2 - y1)
if x_ % x == 0 and y_ % y == 0:
if (x_ // x + y_ // y) % 2 == 0:
print("YES")
else:
print("NO")
else:
print("NO")
``` | vfc_10966 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/817/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 0 6\n2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 3 6\n1 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 6 -10\n1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 -3 -7 -7\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 -5 -8 8\n2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "70 -81 -17 80\n87 23\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 304 | Solve the following coding problem using the programming language python:
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all.
In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $n$.
In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too.
Given $n$, determine the total number of possible bus number variants.
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$.
-----Output-----
Output a single integer — the amount of possible variants of the real bus number.
-----Examples-----
Input
97
Output
2
Input
2028
Output
13
-----Note-----
In the first sample, only variants $97$ and $79$ are possible.
In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=input()
rg=[0]*10
for i in n: rg[int(i)]+=1
rl=[]
ff=0
for i in range(len(rg)):
if rg[i]!=0:
rl.append(rg[i])
if i==0: ff=1
fact=[1]
fc=1
for i in range(1,20):
fc*=i
fact.append(fc)
rt=[]
t=0
def cfs(d):
if d==len(rl):
nonlocal t,ff
jj=fact[sum(rt)]
for i in rt: jj=jj/fact[i]
if ff:
jjj=fact[sum(rt)-1]
jjj=jjj/fact[rt[0]-1]
for i in range(1,len(rt)): jjj=jjj/fact[rt[i]]
jj-=jjj
t+=jj
return
for i in range(1,rl[d]+1):
rt.append(i)
cfs(d+1)
rt.pop(-1)
cfs(0)
print(int(t))
'''
//////////////// ////// /////// // /////// // // //
//// // /// /// /// /// // /// /// //// //
//// //// /// /// /// /// // ///////// //// ///////
//// ///// /// /// /// /// // /// /// //// // //
////////////// /////////// /////////// ////// /// /// // // // //
'''
``` | vfc_10970 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/991/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "97\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2028\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "168\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 305 | Solve the following coding problem using the programming language python:
A new delivery of clothing has arrived today to the clothing store. This delivery consists of $a$ ties, $b$ scarves, $c$ vests and $d$ jackets.
The store does not sell single clothing items — instead, it sells suits of two types: a suit of the first type consists of one tie and one jacket; a suit of the second type consists of one scarf, one vest and one jacket.
Each suit of the first type costs $e$ coins, and each suit of the second type costs $f$ coins.
Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).
-----Input-----
The first line contains one integer $a$ $(1 \le a \le 100\,000)$ — the number of ties.
The second line contains one integer $b$ $(1 \le b \le 100\,000)$ — the number of scarves.
The third line contains one integer $c$ $(1 \le c \le 100\,000)$ — the number of vests.
The fourth line contains one integer $d$ $(1 \le d \le 100\,000)$ — the number of jackets.
The fifth line contains one integer $e$ $(1 \le e \le 1\,000)$ — the cost of one suit of the first type.
The sixth line contains one integer $f$ $(1 \le f \le 1\,000)$ — the cost of one suit of the second type.
-----Output-----
Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.
-----Examples-----
Input
4
5
6
3
1
2
Output
6
Input
12
11
13
20
4
6
Output
102
Input
17
14
5
21
15
17
Output
325
-----Note-----
It is possible to compose three suits of the second type in the first example, and their total cost will be $6$. Since all jackets will be used, it's impossible to add anything to this set.
The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $9 \cdot 4 + 11 \cdot 6 = 102$.
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=int(input())
d=int(input())
e=int(input())
f=int(input())
if e>=f:
ans=min(a,d)
d-=ans
a-=ans
ans*=e
ans+=min(d,b,c)*f
else:
ans=min(d,b,c)
d-=ans
ans*=f
ans+=min(a,d)*e
print(ans)
``` | vfc_10974 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1271/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n6\n3\n1\n2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n11\n13\n20\n4\n6\n",
"output": "102\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17\n14\n5\n21\n15\n17\n",
"output": "325\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "43475\n48103\n50473\n97918\n991\n974\n",
"output": "89936047\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35361\n35182\n68078\n30077\n870\n907\n",
"output": "27279839\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "84205\n15736\n30259\n79331\n647\n378\n",
"output": "51327157\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 306 | Solve the following coding problem using the programming language python:
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants.
-----Input-----
The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b < p$, $1 \leq x \leq 10^{12}$). It is guaranteed that $p$ is a prime.
-----Output-----
Print a single integer: the number of possible answers $n$.
-----Examples-----
Input
2 3 5 8
Output
2
Input
4 6 7 13
Output
1
Input
233 233 10007 1
Output
1
-----Note-----
In the first sample, we can see that $n=2$ and $n=8$ are possible answers.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b, p, x = [int(x) for x in input().split()]
powers = [a]
while powers[-1] != 1:
powers.append(powers[-1] * a % p)
order = len(powers)
powers = [powers[-1]] + powers
inverse = pow(order, p-2, p)
def f(sol):
return (x // (p * order)) + (1 if sol <= x % (p * order) else 0)
def chinese(a, n, b, m):
k = inverse * (b - a + m) % m
x = k * n + a
return x % (n * m)
res = 0
for i in range(len(powers)-1):
inv = powers[order - i]
val = inv * b % p
sol = chinese(i, order, val, p)
res += f(sol)
print(res)
``` | vfc_10978 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/919/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 5 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6 7 13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "233 233 10007 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "338792 190248 339821 152634074578\n",
"output": "449263\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "629260 663548 739463 321804928248\n",
"output": "434818\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "656229 20757 818339 523535590429\n",
"output": "639482\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 307 | Solve the following coding problem using the programming language python:
Recently Anton found a box with digits in his room. There are k_2 digits 2, k_3 digits 3, k_5 digits 5 and k_6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k_2 digits 2, k_3 digits 3 and so on. Of course, unused digits are not counted in the sum.
-----Input-----
The only line of the input contains four integers k_2, k_3, k_5 and k_6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k_2, k_3, k_5, k_6 ≤ 5·10^6).
-----Output-----
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
-----Examples-----
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
-----Note-----
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
k2, k3, k5, k6 = list(map(int, input().split()))
c = min(k2, k5, k6)
k2 -= c
ans = 256 * c
ans += 32 * min(k3, k2)
print(ans)
``` | vfc_10982 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/734/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 3 4\n",
"output": "800\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 308 | Solve the following coding problem using the programming language python:
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.
For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).
In how many seconds will Mr. Bender get happy?
-----Input-----
The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 10^9; 1 ≤ x, y ≤ n; c ≤ n^2).
-----Output-----
In a single line print a single integer — the answer to the problem.
-----Examples-----
Input
6 4 3 1
Output
0
Input
9 3 8 10
Output
2
-----Note-----
Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. [Image].
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x, y, n, c = 0, 0, 0, 0
def suma_impares(m):
return m * m
def suma_n(m):
return m * (m - 1) // 2
def cnt(t):
u, d, l, r = x + t, x - t, y - t, y + t
suma = t ** 2 + (t + 1) ** 2
if u > n: suma -= suma_impares(u - n)
if d < 1: suma -= suma_impares(1 - d)
if l < 1: suma -= suma_impares(1 - l)
if r > n: suma -= suma_impares(r - n)
if 1 - l > x - 1 and 1 - d > y - 1:
suma += suma_n(2 - l - x)
if r - n > x - 1 and 1 - d > n - y:
suma += suma_n(r - n - x + 1)
if 1 - l > n - x and u - n > y - 1:
suma += suma_n(1 - l - n + x)
if u - n > n - y and r - n > n - x:
suma += suma_n(u - n - n + y)
return suma
n, x, y, c = input().split()
n, x, y, c = int(n), int(x), int(y), int(c)
#for i in range(10):
# print(i, cnt(i))
ini, fin = 0, int(1e9)
cont = int(1e9)
while cont > 0:
m = ini
paso = cont // 2
m += paso
if cnt(m) < c:
ini = m + 1
cont -= paso + 1
else:
cont = paso
print(ini)
``` | vfc_10986 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/255/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 4 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 309 | Solve the following coding problem using the programming language python:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of $a \oplus b$ for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all considered ones.
Expression $x \oplus y$ means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal — as «xor».
-----Input-----
The single line contains space-separated integers l and r (1 ≤ l ≤ r ≤ 10^18).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
-----Output-----
In a single line print a single integer — the maximum value of $a \oplus b$ for all pairs of integers a, b (l ≤ a ≤ b ≤ r).
-----Examples-----
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
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
l,r=map(int,(sys.stdin.readline().split()))
i=64
while i>=0:
if ((1<<i)&l!=0 and (1<<i)&r!=0) or ((1<<i)&l==0 and (1<<i)&r==0):i-=1
else:break
print((1<<(i+1))-1)
``` | vfc_10990 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/276/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 16\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "506 677\n",
"output": "1023\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 310 | Solve the following coding problem using the programming language python:
You are given a set of $2n+1$ integer points on a Cartesian plane. Points are numbered from $0$ to $2n$ inclusive. Let $P_i$ be the $i$-th point. The $x$-coordinate of the point $P_i$ equals $i$. The $y$-coordinate of the point $P_i$ equals zero (initially). Thus, initially $P_i=(i,0)$.
The given points are vertices of a plot of a piecewise function. The $j$-th piece of the function is the segment $P_{j}P_{j + 1}$.
In one move you can increase the $y$-coordinate of any point with odd $x$-coordinate (i.e. such points are $P_1, P_3, \dots, P_{2n-1}$) by $1$. Note that the corresponding segments also change.
For example, the following plot shows a function for $n=3$ (i.e. number of points is $2\cdot3+1=7$) in which we increased the $y$-coordinate of the point $P_1$ three times and $y$-coordinate of the point $P_5$ one time: [Image]
Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).
Let the height of the plot be the maximum $y$-coordinate among all initial points in the plot (i.e. points $P_0, P_1, \dots, P_{2n}$). The height of the plot on the picture above is 3.
Your problem is to say which minimum possible height can have the plot consisting of $2n+1$ vertices and having an area equal to $k$. Note that it is unnecessary to minimize the number of moves.
It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $10^{18}$.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 10^{18}$) — the number of vertices in a plot of a piecewise function and the area we need to obtain.
-----Output-----
Print one integer — the minimum possible height of a plot consisting of $2n+1$ vertices and with an area equals $k$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $10^{18}$.
-----Examples-----
Input
4 3
Output
1
Input
4 12
Output
3
Input
999999999999999999 999999999999999986
Output
1
-----Note-----
One of the possible answers to the first example: [Image]
The area of this plot is 3, the height of this plot is 1.
There is only one possible answer to the second example: $M M$
The area of this plot is 12, the height of this plot is 3.
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()))
print((K+N-1)//N)
``` | vfc_10994 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1036/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 12\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999999999999999 999999999999999986\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 999999999999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999999999999999 1000000000000000000\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 311 | Solve the following coding problem using the programming language python:
Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor $x$, Egor on the floor $y$ (not on the same floor with Masha).
The house has a staircase and an elevator. If Masha uses the stairs, it takes $t_1$ seconds for her to walk between adjacent floors (in each direction). The elevator passes between adjacent floors (in each way) in $t_2$ seconds. The elevator moves with doors closed. The elevator spends $t_3$ seconds to open or close the doors. We can assume that time is not spent on any action except moving between adjacent floors and waiting for the doors to open or close. If Masha uses the elevator, it immediately goes directly to the desired floor.
Coming out of the apartment on her floor, Masha noticed that the elevator is now on the floor $z$ and has closed doors. Now she has to choose whether to use the stairs or use the elevator.
If the time that Masha needs to get to the Egor's floor by the stairs is strictly less than the time it will take her using the elevator, then she will use the stairs, otherwise she will choose the elevator.
Help Mary to understand whether to use the elevator or the stairs.
-----Input-----
The only line contains six integers $x$, $y$, $z$, $t_1$, $t_2$, $t_3$ ($1 \leq x, y, z, t_1, t_2, t_3 \leq 1000$) — the floor Masha is at, the floor Masha wants to get to, the floor the elevator is located on, the time it takes Masha to pass between two floors by stairs, the time it takes the elevator to pass between two floors and the time it takes for the elevator to close or open the doors.
It is guaranteed that $x \ne y$.
-----Output-----
If the time it will take to use the elevator is not greater than the time it will take to use the stairs, print «YES» (without quotes), otherwise print «NO> (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
5 1 4 4 2 1
Output
YES
Input
1 6 6 2 1 1
Output
NO
Input
4 1 7 4 1 2
Output
YES
-----Note-----
In the first example:
If Masha goes by the stairs, the time she spends is $4 \cdot 4 = 16$, because she has to go $4$ times between adjacent floors and each time she spends $4$ seconds.
If she chooses the elevator, she will have to wait $2$ seconds while the elevator leaves the $4$-th floor and goes to the $5$-th. After that the doors will be opening for another $1$ second. Then Masha will enter the elevator, and she will have to wait for $1$ second for the doors closing. Next, the elevator will spend $4 \cdot 2 = 8$ seconds going from the $5$-th floor to the $1$-st, because the elevator has to pass $4$ times between adjacent floors and spends $2$ seconds each time. And finally, it will take another $1$ second before the doors are open and Masha can come out.
Thus, all the way by elevator will take $2 + 1 + 1 + 8 + 1 = 13$ seconds, which is less than $16$ seconds, so Masha has to choose the elevator.
In the second example, it is more profitable for Masha to use the stairs, because it will take $13$ seconds to use the elevator, that is more than the $10$ seconds it will takes to go by foot.
In the third example, the time it takes to use the elevator is equal to the time it takes to walk up by the stairs, and is equal to $12$ seconds. That means Masha will take the elevator.
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, t1, t2, t3 = map(int, input().split())
ladder = abs(x - y) * t1
elevator = abs(x - z) * t2 + 3 * t3 + abs(x - y) * t2
if elevator > ladder:
print("NO")
else:
print("YES")
``` | vfc_10998 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1054/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 4 4 2 1\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 6 6 2 1 1\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1 7 4 1 2\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 312 | Solve the following coding problem using the programming language python:
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.
Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.
Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.
More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that $|c - a|<|c - m|$ is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).
-----Input-----
The first line contains two integers n and m (1 ≤ m ≤ n ≤ 10^9) — the range of numbers in the game, and the number selected by Misha respectively.
-----Output-----
Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.
-----Examples-----
Input
3 1
Output
2
Input
4 3
Output
2
-----Note-----
In the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3, the probability of winning will be 1 / 3. If a = 1, the probability of winning is 0.
In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of a the probability of winning is less.
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 n == 1:
print(1)
elif m - 1 >= n - m:
print(m - 1)
else:
print(m + 1)
``` | vfc_11002 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/570/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 313 | Solve the following coding problem using the programming language python:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university.
The second line contains n numbers a_{i} (0 ≤ a_{i} ≤ 1). Number a_{i} equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a_1, a_2, ..., a_{n} are separated by spaces.
-----Output-----
Print a single number — the number of pairs during which Alena stays at the university.
-----Examples-----
Input
5
0 1 0 1 1
Output
4
Input
7
1 0 1 0 0 1 0
Output
4
Input
1
0
Output
0
-----Note-----
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home.
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()))
c = 0
l = 0
b = 0
while c < len(a) and a[c] == 0:
c += 1
b += 1
if c == len(a):
print(0)
return
d = len(a) - 1
while a[d] != 1:
d -= 1
b += 1
while c <= d:
if a[c] == 0:
l += 1
else:
if l > 1:
b += l
l = 0
c += 1
print(n - b)
``` | vfc_11006 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/586/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 1 0 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 0 1 0 0 1 0\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 314 | Solve the following coding problem using the programming language python:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds a_{i} candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a_1, a_2, a_3, ..., a_{n} (1 ≤ a_{i} ≤ 100).
-----Output-----
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
-----Examples-----
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
-----Note-----
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/bin/python
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
a, b = 0, 0
for i in range(n):
a += p[i]
x = min(8, a)
b += x
a -= x
if b >= k:
print(i+1)
break
else:
print(-1)
``` | vfc_11010 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/839/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n1 2\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 315 | Solve the following coding problem using the programming language python:
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times.
Polycarp analysed all his affairs over the next n days and made a sequence of n integers a_1, a_2, ..., a_{n}, where a_{i} is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).
Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times.
Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers b_1, b_2, ..., b_{n} (b_{i} ≥ a_{i}), where b_{i} means the total number of walks with the dog on the i-th day.
-----Input-----
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
-----Output-----
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b_1, b_2, ..., b_{n}, where b_{i} — the total number of walks on the i-th day according to the found solutions (a_{i} ≤ b_{i} for all i from 1 to n). If there are multiple solutions, print any of them.
-----Examples-----
Input
3 5
2 0 1
Output
4
2 3 2
Input
3 1
0 0 0
Output
1
0 1 0
Input
4 6
2 4 3 5
Output
0
2 4 3 5
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 = list(map(int, input().split()))
ans = 0
for i in range(1, n):
diff = k - (a[i] + a[i - 1])
if diff > 0:
a[i] += diff
ans += diff
print(ans)
print(' '.join(map(str, a)))
``` | vfc_11014 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/732/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n2 0 1\n",
"output": "4\n2 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n0 0 0\n",
"output": "1\n0 1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6\n2 4 3 5\n",
"output": "0\n2 4 3 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n0 0 0 0 1\n",
"output": "2\n0 1 0 1 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 316 | Solve the following coding problem using the programming language python:
While playing with geometric figures Alex has accidentally invented a concept of a $n$-th order rhombus in a cell grid.
A $1$-st order rhombus is just a square $1 \times 1$ (i.e just a cell).
A $n$-th order rhombus for all $n \geq 2$ one obtains from a $n-1$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).
[Image]
Alex asks you to compute the number of cells in a $n$-th order rhombus.
-----Input-----
The first and only input line contains integer $n$ ($1 \leq n \leq 100$) — order of a rhombus whose numbers of cells should be computed.
-----Output-----
Print exactly one integer — the number of cells in a $n$-th order rhombus.
-----Examples-----
Input
1
Output
1
Input
2
Output
5
Input
3
Output
13
-----Note-----
Images of rhombus corresponding to the examples are given in the statement.
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 = n * (n + 1) // 2
print(4 * a - 4 * n + 1)
``` | vfc_11018 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1180/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 317 | Solve the following coding problem using the programming language python:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
-----Output-----
Output "YES", if the string is a pangram and "NO" otherwise.
-----Examples-----
Input
12
toosmallword
Output
NO
Input
35
TheQuickBrownFoxJumpsOverTheLazyDog
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 = int(input())
s = input()
a = [False for i in range(26)]
for x in s:
a[ord(x.lower()) - ord('a')] = True
for x in a:
if not x:
print('NO')
return
print('YES')
``` | vfc_11022 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/520/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\ntoosmallword\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\na\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26\nqwertyuiopasdfghjklzxcvbnm\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 318 | Solve the following coding problem using the programming language python:
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.
Note that you should find only the time after a minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock.
-----Input-----
The first line contains the current time in the format hh:mm (0 ≤ hh < 24, 0 ≤ mm < 60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer a (0 ≤ a ≤ 10^4) — the number of the minutes passed.
-----Output-----
The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format.
-----Examples-----
Input
23:59
10
Output
00:09
Input
20:20
121
Output
22:21
Input
10:10
0
Output
10: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():
a, b = map(int, input().split(":"))
c = int(input())
a += c // 60
b += c % 60
if b > 59:
b %= 60
a += 1
aa = str(a % 24)
if len(aa) < 2:
aa = "0" + aa
bb = str(b % 60)
if len(bb) < 2:
bb = "0" + bb
print(aa + ":" + bb)
def __starting_point():
main()
__starting_point()
``` | vfc_11026 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/622/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "23:59\n10\n",
"output": "00:09\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20:20\n121\n",
"output": "22:21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10:10\n0\n",
"output": "10:10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12:34\n10000\n",
"output": "11:14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "00:00\n10000\n",
"output": "22:40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "00:00\n1440\n",
"output": "00:00\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 319 | Solve the following coding problem using the programming language python:
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where a_{i}, j = 1 if the i-th switch turns on the j-th lamp and a_{i}, j = 0 if the i-th switch is not connected to the j-th lamp.
Initially all m lamps are turned off.
Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards.
It is guaranteed that if you push all n switches then all m lamps will be turned on.
Your think that you have too many switches and you would like to ignore one of them.
Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on.
-----Input-----
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.
The following n lines contain m characters each. The character a_{i}, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.
It is guaranteed that if you press all n switches all m lamps will be turned on.
-----Output-----
Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.
-----Examples-----
Input
4 5
10101
01000
00111
10000
Output
YES
Input
4 5
10100
01000
00110
00101
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, m = list(map(int, input().split()))
a = [list(map(int, input())) for i in range(n)]
ignorable = [True] * n
for i in range(m):
cnt = 0
for j in range(n):
cnt += a[j][i]
if cnt == 1:
for j in range(n):
if a[j][i]:
ignorable[j] = False
if any(ignorable):
print('YES')
else:
print('NO')
``` | vfc_11030 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/985/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n10101\n01000\n00111\n10000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n10100\n01000\n00110\n00101\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n11111\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 320 | Solve the following coding problem using the programming language python:
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers x_{i}, y_{i} (1 ≤ x_{i}, y_{i} ≤ 6). Number x_{i} is initially written on the upper half of the i-th domino, y_{i} is initially written on the lower half.
-----Output-----
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
-----Examples-----
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
-----Note-----
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
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())
Check = False
Sum = 0
Sum_l, Sum_r = 0, 0
for i in range(N):
x, y = list(map(int, input().split()))
Sum_l += x
Sum_r += y
Sum += x + y
if (x % 2 + y % 2) % 2:
Check = True
if Sum % 2:
print(-1)
elif Sum_l % 2:
if not Check:
print(-1)
else:
print(1)
elif Sum_l % 2 == 0:
print(0)
``` | vfc_11034 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/353/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 2\n6 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 321 | Solve the following coding problem using the programming language python:
Alice has a lovely piece of cloth. It has the shape of a square with a side of length $a$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $b$ centimeters (where $b < a$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).
Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?
-----Input-----
The first line contains a number $t$ ($1 \leq t \leq 5$) — the number of test cases.
Each of the next $t$ lines describes the $i$-th test case. It contains two integers $a$ and $b~(1 \leq b < a \leq 10^{11})$ — the side length of Alice's square and the side length of the square that Bob wants.
-----Output-----
Print $t$ lines, where the $i$-th line is the answer to the $i$-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".
You can print each letter in an arbitrary case (upper or lower).
-----Example-----
Input
4
6 5
16 13
61690850361 24777622630
34 33
Output
YES
NO
NO
YES
-----Note-----
The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $6^2 - 5^2 = 36 - 25 = 11$, which is prime, so the answer is "YES". [Image]
In the second case, the area is $16^2 - 13^2 = 87$, which is divisible by $3$. [Image]
In the third case, the area of the remaining piece is $61690850361^2 - 24777622630^2 = 3191830435068605713421$. This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $.
In the last case, the area is $34^2 - 33^2 = 67$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
t=int(input())
for yes in range(t):
a,b=map(int,input().split())
xx=a-b
yy=a+b
if xx==1 and isPrime(yy)==True:
print("YES")
else:
print("NO")
``` | vfc_11038 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1033/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6 5\n16 13\n61690850361 24777622630\n34 33\n",
"output": "YES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n160 159\n223 222\n480 479\n357 356\n345 344\n",
"output": "NO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n631 582\n201 106\n780 735\n608 528\n470 452\n",
"output": "NO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 1\n3 1\n4 1\n5 1\n8 7\n",
"output": "YES\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 322 | Solve the following coding problem using the programming language python:
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
-----Input-----
The first line contains a single positive integer n (2 ≤ n ≤ 10^5).
The following n lines contain coordinates of the points. The i-th of these lines contains two single integers x_{i} and y_{i} (|x_{i}|, |y_{i}| ≤ 10^9, x_{i} ≠ 0). No two points coincide.
-----Output-----
Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower).
-----Examples-----
Input
3
1 1
-1 -1
2 -1
Output
Yes
Input
4
1 1
2 2
-1 1
-2 2
Output
No
Input
3
1 2
2 1
4 60
Output
Yes
-----Note-----
In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed.
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())
lcnt = 0
rcnt = 0
for i in range(n):
x, y = map(int, input().split())
if x < 0:
lcnt += 1
else:
rcnt += 1
if (lcnt <= 1 or rcnt <= 1):
print("Yes")
else:
print("No")
``` | vfc_11042 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/900/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n-1 -1\n2 -1\n",
"output": "Yes",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 323 | Solve the following coding problem using the programming language python:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers "A factorial" and "B factorial". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·...·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
-----Input-----
The first and single line contains two integers A and B (1 ≤ A, B ≤ 10^9, min(A, B) ≤ 12).
-----Output-----
Print a single integer denoting the greatest common divisor of integers A! and B!.
-----Example-----
Input
4 3
Output
6
-----Note-----
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
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())
a = min(a, b)
ans = 1
for i in range(1, a + 1):
ans *= i
print(ans)
``` | vfc_11046 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/822/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 324 | Solve the following coding problem using the programming language python:
Let's call a positive integer composite if it has at least one divisor other than $1$ and itself. For example:
the following numbers are composite: $1024$, $4$, $6$, $9$; the following numbers are not composite: $13$, $1$, $2$, $3$, $37$.
You are given a positive integer $n$. Find two composite integers $a,b$ such that $a-b=n$.
It can be proven that solution always exists.
-----Input-----
The input contains one integer $n$ ($1 \leq n \leq 10^7$): the given integer.
-----Output-----
Print two composite integers $a,b$ ($2 \leq a, b \leq 10^9, a-b=n$).
It can be proven, that solution always exists.
If there are several possible solutions, you can print any.
-----Examples-----
Input
1
Output
9 8
Input
512
Output
4608 4096
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 (9 * n, 8 * n)
``` | vfc_11050 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1269/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "9 8\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 327 | Solve the following coding problem using the programming language python:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers a_1, a_2, ..., a_{m} is defined as the bitwise XOR of all its elements: $a_{1} \oplus a_{2} \oplus \ldots \oplus a_{m}$, here $\oplus$ denotes the bitwise XOR operation; more about bitwise XOR can be found here.
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
-----Input-----
The sole string contains two integers n and k (1 ≤ k ≤ n ≤ 10^18).
-----Output-----
Output one number — the largest possible xor-sum.
-----Examples-----
Input
4 3
Output
7
Input
6 6
Output
7
-----Note-----
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
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,k=R()
if k==1:print(n)
else:
i=0
while (1<<i)<=n:i+=1
print((1<<i)-1)
``` | vfc_11062 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/912/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1022 10\n",
"output": "1023\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 329 | Solve the following coding problem using the programming language python:
Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string.
-----Input-----
The first line contains a non-empty string s, consisting only of lowercase English letters. The length of string s doesn't exceed 100.
-----Output-----
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
-----Examples-----
Input
nniinneetteeeenn
Output
2
Input
nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii
Output
2
Input
nineteenineteen
Output
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = {i: 0 for i in 'qwertyuiopasdfghjklzxcvbnm'}
for i in input(): t[i] += 1
print(min([t['i'], t['t'], t['e'] // 3, max(0, (t['n'] - 1)) // 2]))
``` | vfc_11070 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/393/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "nniinneetteeeenn\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 330 | Solve the following coding problem using the programming language python:
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches $2 \cdot x, 3 \cdot x, \ldots, \lfloor \frac{y}{x} \rfloor \cdot x$.
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.
-----Input-----
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 10^9).
-----Output-----
Output the number of the highest suitable branch. If there are none, print -1 instead.
-----Examples-----
Input
3 6
Output
5
Input
3 4
Output
-1
-----Note-----
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys, math
#f = open('input_0', 'r')
f = sys.stdin
P, Y = list(map(int, f.readline().split()))
is_ok = False
for t in range(Y, P, -1):
is_ok = True
for x in range(2, P+1):
if t%x == 0:
is_ok = False
break
if x*x > t:
break
if is_ok:
print(t)
break
if not is_ok:
print(-1)
``` | vfc_11074 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/937/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 50\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "944192806 944193066\n",
"output": "944192807\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 333 | Solve the following coding problem using the programming language python:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
-----Input-----
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 10^5 characters.
-----Output-----
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
-----Examples-----
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
-----Note-----
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
a = input()
b = input()
if a != b:
print(max(len(a), len(b)))
else:
print(-1)
``` | vfc_11086 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/766/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abcd\ndefgh\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a\na\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abcde\nfghij\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 334 | Solve the following coding problem using the programming language python:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... [Image]
The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.
-----Input-----
The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).
The second line contains two integers c and d (1 ≤ c, d ≤ 100).
-----Output-----
Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time.
-----Examples-----
Input
20 2
9 19
Output
82
Input
2 1
16 12
Output
-1
-----Note-----
In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream 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
a, b = map(int,input().split())
c, d = map(int,input().split())
ONE = set()
TWO = set()
for i in range(b, 50000, a):
ONE.add(i)
for i in range(d, 50000, c):
TWO.add(i)
opt = 99999
for i in ONE:
if i in TWO:
opt = min(opt, i)
if opt == 99999:
print(-1)
else:
print(opt)
``` | vfc_11090 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/787/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 2\n9 19\n",
"output": "82\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n16 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "39 52\n88 78\n",
"output": "1222\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 335 | Solve the following coding problem using the programming language python:
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer $n$. He wants to split $n$ into $3$ positive integers $a,b,c$, such that $a+b+c=n$ and none of the $3$ integers is a multiple of $3$. Help him to find a solution.
-----Input-----
A single line containing one integer $n$ ($3 \leq n \leq 10^9$) — the integer Little C has.
-----Output-----
Print $3$ positive integers $a,b,c$ in a single line, such that $a+b+c=n$ and none of them is a multiple of $3$.
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
-----Examples-----
Input
3
Output
1 1 1
Input
233
Output
77 77 79
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())
if n%3 == 0: print(1, 1, n-2)
elif n%3 == 1: print(1, 1, n-2)
else: print(1, 2, n-3)
``` | vfc_11094 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1047/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1 1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "233\n",
"output": "1 2 230",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "1 1 2",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 336 | Solve the following coding problem using the programming language python:
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers. The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2. Four elements a, b, c and d are known and are located as shown on the picture below. $\left. \begin{array}{|c|c|c|} \hline ? & {a} & {?} \\ \hline b & {?} & {c} \\ \hline ? & {d} & {?} \\ \hline \end{array} \right.$
Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
-----Input-----
The first line of the input contains five integers n, a, b, c and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
-----Output-----
Print one integer — the number of distinct valid squares.
-----Examples-----
Input
2 1 1 1 2
Output
2
Input
3 3 1 2 3
Output
6
-----Note-----
Below are all the possible paintings for the first sample. $\left. \begin{array}{|l|l|l|} \hline 2 & {1} & {2} \\ \hline 1 & {1} & {1} \\ \hline 1 & {2} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|l|l|l|} \hline 2 & {1} & {2} \\ \hline 1 & {2} & {1} \\ \hline 1 & {2} & {1} \\ \hline \end{array} \right.$
In the second sample, only paintings displayed below satisfy all the rules. $\left. \begin{array}{|c|c|c|} \hline 2 & {3} & {1} \\ \hline 1 & {1} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 2 & {3} & {1} \\ \hline 1 & {2} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|l|l|l|} \hline 2 & {3} & {1} \\ \hline 1 & {3} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {1} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {2} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {3} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, a, b, c, d= [int(i) for i in input().split()]
o = 0
for i in range(1, n+1):
if i+b-c>0 and i+b-c<=n:
if i+a-d>0 and i+a-d<=n:
if i+a+b-c-d>0 and i+a+b-c-d<=n:
o+=1
print(o*n)
``` | vfc_11098 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/675/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 1 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 1 2 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 522 575 426 445\n",
"output": "774000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "99000 52853 14347 64237 88869\n",
"output": "1296306000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100000 2 2 2 2\n",
"output": "10000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 337 | Solve the following coding problem using the programming language python:
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height $h$ and it has weight $w$. Each second the following sequence of events happens: snowball's weights increases by $i$, where $i$ — is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight $u_1$ and is located at height $d_1$, the second one — $u_2$ and $d_2$ respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before. [Image]
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
-----Input-----
First line contains two integers $w$ and $h$ — initial weight and height of the snowball ($0 \le w \le 100$; $1 \le h \le 100$).
Second line contains two integers $u_1$ and $d_1$ — weight and height of the first stone ($0 \le u_1 \le 100$; $1 \le d_1 \le h$).
Third line contains two integers $u_2$ and $d_2$ — weight and heigth of the second stone ($0 \le u_2 \le 100$; $1 \le d_2 \le h$; $d_1 \ne d_2$). Notice that stones always have different heights.
-----Output-----
Output a single integer — final weight of the snowball after it reaches height 0.
-----Examples-----
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
-----Note-----
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially: The weight of the snowball increases by 3 (current height), becomes equal to 7. The snowball moves one meter down, the current height becomes equal to 2. The weight of the snowball increases by 2 (current height), becomes equal to 9. The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8. The snowball moves one meter down, the current height becomes equal to 1. The weight of the snowball increases by 1 (current height), becomes equal to 9. The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8. The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
w, h = map(int, input().split())
u1, d1 = map(int, input().split())
u2, d2 = map(int, input().split())
for i in range(h, -1, -1):
w += i
if i == d1:
w = max(w - u1, 0)
elif i == d2:
w = max(w - u2, 0)
print(w)
``` | vfc_11102 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1099/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 1\n1 2\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n9 2\n0 1\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 338 | Solve the following coding problem using the programming language python:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c_1 schoolchildren got 1 point, c_2 children got 2 points, ..., c_{m} children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
-----Input-----
The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c_1, c_2, ..., c_{m}, separated by single spaces (0 ≤ c_{i} ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one c_{i} is greater than 0.
-----Output-----
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
-----Examples-----
Input
5
3 4 3 2 1
6 8
Output
3
Input
5
0 3 3 4 2
3 10
Output
4
Input
2
2 5
3 6
Output
0
-----Note-----
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
m = int(input())
c = list(map(int,input().split()))
x, y = list(map(int,input().split()))
for i in range(m):
sb = sum(c[:-i-1])
si = sum(c[-i-1:])
if x <= sb <= y:
if x <= si <= y:
print(m-i)
break
else:
print(0)
``` | vfc_11106 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/357/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 4 3 2 1\n6 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 3 3 4 2\n3 10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 5\n3 6\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 339 | Solve the following coding problem using the programming language python:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 2·10^9).
The second line contains a single integer k (1 ≤ k ≤ 2·10^9).
The third line contains a single integer A (1 ≤ A ≤ 2·10^9).
The fourth line contains a single integer B (1 ≤ B ≤ 2·10^9).
-----Output-----
Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.
-----Examples-----
Input
9
2
3
1
Output
6
Input
5
5
2
20
Output
8
Input
19
3
4
2
Output
12
-----Note-----
In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total.
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 read_int():
return int(input())
def read_ints():
return [int(x) for x in input().split()]
n = read_int()
k = read_int()
a = read_int()
b = read_int()
cost = 0
if k == 1:
cost = (n - 1) * a
else:
while n != 1:
if n % k == 0:
if b < (n - n // k) * a:
cost += b
else:
cost += (n - n // k) * a
n = n // k
else:
cost += (n % k) * a
n -= n % k
if n == 0:
n += 1
cost -= a
print(cost)
``` | vfc_11110 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/940/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n2\n3\n1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5\n2\n20\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "19\n3\n4\n2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1845999546\n999435865\n1234234\n2323423\n",
"output": "1044857680578777\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1604353664\n1604353665\n9993432\n1\n",
"output": "16032999235141416\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 340 | Solve the following coding problem using the programming language python:
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $n$, you can perform the following operations zero or more times: mul $x$: multiplies $n$ by $x$ (where $x$ is an arbitrary positive integer). sqrt: replaces $n$ with $\sqrt{n}$ (to apply this operation, $\sqrt{n}$ must be an integer).
You can perform these operations as many times as you like. What is the minimum value of $n$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?
Apparently, no one in the class knows the answer to this problem, maybe you can help them?
-----Input-----
The only line of the input contains a single integer $n$ ($1 \le n \le 10^6$) — the initial number.
-----Output-----
Print two integers: the minimum integer $n$ that can be achieved using the described operations and the minimum number of operations required.
-----Examples-----
Input
20
Output
10 2
Input
5184
Output
6 4
-----Note-----
In the first example, you can apply the operation mul $5$ to get $100$ and then sqrt to get $10$.
In the second example, you can first apply sqrt to get $72$, then mul $18$ to get $1296$ and finally two more sqrt and you get $6$.
Note, that even if the initial value of $n$ is less or equal $10^6$, it can still become greater than $10^6$ after applying one or more operations.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def ii():
return int(input())
def mi():
return list(map(int, input().split()))
def li():
return list(mi())
MX = 10 ** 5
n = ii()
fac = 2
pr = []
while fac * fac <= n:
c = 0
while n % fac == 0:
c += 1
n //= fac
if c:
pr.append((fac, c))
fac += 1
if n > 1:
pr.append((n, 1))
if pr:
mx = max(e for p, e in pr)
mn = min(e for p, e in pr)
mx2 = 1
cnt = 0
while mx2 < mx:
mx2 *= 2
cnt += 1
ans = cnt + int(mn != mx2)
pdt = 1
for p, e in pr:
pdt *= p
else:
pdt, ans = 1, 0
print(pdt, ans)
``` | vfc_11114 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1062/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20\n",
"output": "10 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5184\n",
"output": "6 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000\n",
"output": "10 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999979\n",
"output": "999979 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "559872\n",
"output": "6 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "256\n",
"output": "2 3",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 342 | Solve the following coding problem using the programming language python:
Let's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string.
You have $a$ strings "a", $b$ strings "b" and $c$ strings "ab". You want to choose some subset of these strings and concatenate them in any arbitrarily order.
What is the length of the longest good string you can obtain this way?
-----Input-----
The first line contains three positive integers $a$, $b$, $c$ ($1 \leq a, b, c \leq 10^9$) — the number of strings "a", "b" and "ab" respectively.
-----Output-----
Print a single number — the maximum possible length of the good string you can obtain.
-----Examples-----
Input
1 1 1
Output
4
Input
2 1 2
Output
7
Input
3 5 2
Output
11
Input
2 2 1
Output
6
Input
1000000000 1000000000 1000000000
Output
4000000000
-----Note-----
In the first example the optimal string is "baba".
In the second example the optimal string is "abababa".
In the third example the optimal string is "bababababab".
In the fourth example the optimal string is "ababab".
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 = list(map(int, input().split()))
x = 2 * (c + min(a, b))
if a != b:
x += 1
print(x)
``` | vfc_11122 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1148/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 2\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000 1000000000 1000000000\n",
"output": "4000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 3\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 343 | Solve the following coding problem using the programming language python:
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a_1, ..., a_{k}. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
-----Input-----
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a_1, ..., a_{k} (1 ≤ a_{i} ≤ p) — the marks that Vova got for the tests he has already written.
-----Output-----
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
-----Examples-----
Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1
-----Note-----
The median of sequence a_1, ..., a_{n} where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of a_{i}.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
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, k, p, x, y = map(int, input().split())
As = list(map(int, input().split()))
return n, k, p, x, y, As
def solve(n, k, p, x, y, As):
'''median (As + Bs) >= y
sum(As + Bs) <= x
1 <= Bi <= p
'''
middle = n // 2
As.sort(reverse=True)
sumA = sum(As)
minSum = sumA + 1 * (n - k)
if minSum > x:
return ['-1']
num_a_over_y = len([1 for a in As if a >= y])
if num_a_over_y > middle:
return ['1'] * (n - k)
min_num_y = middle + 1 - num_a_over_y
if min_num_y > n - k:
return ['-1']
minSum2 = sumA + min_num_y * y + (n - k - min_num_y) * 1
if minSum2 > x:
return ['-1']
return [str(y)] * min_num_y + ['1'] * (n - k - min_num_y)
def __starting_point():
n, k, p, x, y, As = read_data()
seq = solve(n, k, p, x, y, As)
print(' '.join(seq))
__starting_point()
``` | vfc_11126 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/540/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 5 18 4\n3 5 4\n",
"output": "4 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 16 4\n5 5 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 17 4\n5 5 5\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 12 1\n5 5 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 13 1\n5 5 1\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 4 5 26 5\n5 2 4 5\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 344 | Solve the following coding problem using the programming language python:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese.
-----Input-----
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
-----Output-----
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
sumimasen
Output
YES
Input
ninja
Output
YES
Input
codeforces
Output
NO
-----Note-----
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
ok = 1
n = len(s)
def is_vowel(c):
return c in "aouie"
for i, x in enumerate(s):
if not is_vowel(x) and x != 'n':
ok &= ((i + 1 < n) and is_vowel(s[i + 1]))
print("YES" if ok else "NO")
``` | vfc_11130 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1008/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "sumimasen\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ninja\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "codeforces\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 346 | Solve the following coding problem using the programming language python:
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is a_{i} points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price.
The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again.
All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve.
-----Input-----
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^7) — the prices of the questions. The third line contains m distinct integers b_{i} (1 ≤ b_{i} ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n.
-----Output-----
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
-----Examples-----
Input
4 1
1 3 7 5
3
Output
18
Input
3 2
10 3 8
2 3
Output
40
Input
2 2
100 200
1 2
Output
400
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()))
prices = list(map(int, input().split()))
auci = list(map(int, input().split()))
scores = 0
# m auc
# n - m default
for i in range(len(prices)):
if (i+1) not in auci:
scores += prices[i]
prices[i] = 0
ra = []
for i in prices:
if i != 0:
ra.append(i)
ra.sort()
ra = ra[::-1]
for i in ra:
if i > scores:
scores += i
else:
scores *= 2
print(scores)
#print(ra)
``` | vfc_11138 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/413/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n1 3 7 5\n3\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n10 3 8\n2 3\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n100 200\n1 2\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 5\n1 2\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n5 8 7 1 9\n2 5 3\n",
"output": "60\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 347 | Solve the following coding problem using the programming language python:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is $\operatorname{max}(0.3 x,(1 - \frac{m}{250}) x - 50 w)$. His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
-----Input-----
The first line of the input contains five space-separated integers m_1, m_2, m_3, m_4, m_5, where m_{i} (0 ≤ m_{i} ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted.
The second line contains five space-separated integers w_1, w_2, w_3, w_4, w_5, where w_{i} (0 ≤ w_{i} ≤ 10) is Kevin's number of wrong submissions on problem i.
The last line contains two space-separated integers h_{s} and h_{u} (0 ≤ h_{s}, h_{u} ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
-----Output-----
Print a single integer, the value of Kevin's final score.
-----Examples-----
Input
20 40 60 80 100
0 1 2 3 4
1 0
Output
4900
Input
119 119 119 119 119
0 0 0 0 0
10 0
Output
4930
-----Note-----
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets $(1 - \frac{119}{250}) = \frac{131}{250}$ of the points on each problem. So his score from solving problems is $\frac{131}{250}(500 + 1000 + 1500 + 2000 + 2500) = 3930$. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
m = list(map(int, input().split()))
w = list(map(int, input().split()))
a = [500, 1000, 1500, 2000, 2500]
v = list(map(int, input().split()))
ans = 0
for i in range(len(m)):
ans += max(0.3 * a[i], (1 - m[i] / 250) * a[i] - 50 * w[i])
ans += v[0] * 100
ans -= v[1] * 50
print(int(ans))
``` | vfc_11142 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/604/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"output": "4900\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 348 | Solve the following coding problem using the programming language python:
Alice has got addicted to a game called Sirtet recently.
In Sirtet, player is given an $n \times m$ grid. Initially $a_{i,j}$ cubes are stacked up in the cell $(i,j)$. Two cells are called adjacent if they share a side. Player can perform the following operations: stack up one cube in two adjacent cells; stack up two cubes in one cell.
Cubes mentioned above are identical in height.
Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. [Image]
Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations.
Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that $L \le a_{i,j} \le R$ for all $1 \le i \le n$, $1 \le j \le m$; player can reach the goal using above operations.
Please help Alice with it. Notice that the answer might be large, please output the desired value modulo $998,244,353$.
-----Input-----
The only line contains four integers $n$, $m$, $L$ and $R$ ($1\le n,m,L,R \le 10^9$, $L \le R$, $n \cdot m \ge 2$).
-----Output-----
Output one integer, representing the desired answer modulo $998,244,353$.
-----Examples-----
Input
2 2 1 1
Output
1
Input
1 2 1 2
Output
2
-----Note-----
In the first sample, the only initial grid that satisfies the requirements is $a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1$. Thus the answer should be $1$.
In the second sample, initial grids that satisfy the requirements are $a_{1,1}=a_{1,2}=1$ and $a_{1,1}=a_{1,2}=2$. Thus the answer should be $2$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,m,L,R = list(map(int,input().split()))
p = 998244353*2
pp = p//2
#liczba pokryc n x m ze jest parzyscie wiele zer albo parzyscie wiele jedynek
def pow(a,w):
wyn = 1
mn = a
while w > 0:
if w%2 == 1:
wyn = (wyn * mn)%p
mn = (mn*mn)%p
w //= 2
return wyn
dupsko = pow((R-L+1), m*n)
if L == R:
print(1)
else:
if (m*n)%2 == 1:
print(dupsko%pp)
else:
print((dupsko - dupsko//2)%pp)
``` | vfc_11146 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1332/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "485 117 386829368 748204956\n",
"output": "735420370\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 349 | Solve the following coding problem using the programming language python:
You are given two $n \times m$ matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly increasing. A matrix is increasing if all rows are strictly increasing and all columns are strictly increasing.
For example, the matrix $\begin{bmatrix} 9&10&11\\ 11&12&14\\ \end{bmatrix}$ is increasing because each individual row and column is strictly increasing. On the other hand, the matrix $\begin{bmatrix} 1&1\\ 2&3\\ \end{bmatrix}$ is not increasing because the first row is not strictly increasing.
Let a position in the $i$-th row (from top) and $j$-th column (from left) in a matrix be denoted as $(i, j)$.
In one operation, you can choose any two numbers $i$ and $j$ and swap the number located in $(i, j)$ in the first matrix with the number in $(i, j)$ in the second matrix. In other words, you can swap two numbers in different matrices if they are located in the corresponding positions.
You would like to make both matrices increasing by performing some number of operations (possibly none). Determine if it is possible to do this. If it is, print "Possible", otherwise, print "Impossible".
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \leq n,m \leq 50$) — the dimensions of each matrix.
Each of the next $n$ lines contains $m$ integers $a_{i1}, a_{i2}, \ldots, a_{im}$ ($1 \leq a_{ij} \leq 10^9$) — the number located in position $(i, j)$ in the first matrix.
Each of the next $n$ lines contains $m$ integers $b_{i1}, b_{i2}, \ldots, b_{im}$ ($1 \leq b_{ij} \leq 10^9$) — the number located in position $(i, j)$ in the second matrix.
-----Output-----
Print a string "Impossible" or "Possible".
-----Examples-----
Input
2 2
2 10
11 5
9 4
3 12
Output
Possible
Input
2 3
2 4 5
4 5 6
3 6 7
8 10 11
Output
Possible
Input
3 2
1 3
2 4
5 10
3 1
3 6
4 8
Output
Impossible
-----Note-----
The first example, we can do an operation on the top left and bottom right cells of the matrices. The resulting matrices will be $\begin{bmatrix} 9&10\\ 11&12\\ \end{bmatrix}$ and $\begin{bmatrix} 2&4\\ 3&5\\ \end{bmatrix}$.
In the second example, we don't need to do any operations.
In the third example, no matter what we swap, we can't fix the first row to be strictly increasing in both matrices.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
from sys import stdin, stdout
def read():
return stdin.readline().rstrip('\n')
def read_array(sep=None, maxsplit=-1):
return read().split(sep, maxsplit)
def read_int():
return int(read())
def read_int_array(sep=None, maxsplit=-1):
return [int(a) for a in read_array(sep, maxsplit)]
def write(*args, **kwargs):
sep = kwargs.get('sep', ' ')
end = kwargs.get('end', '\n')
stdout.write(sep.join(str(a) for a in args) + end)
def write_array(array, **kwargs):
sep = kwargs.get('sep', ' ')
end = kwargs.get('end', '\n')
stdout.write(sep.join(str(a) for a in array) + end)
n, m = read_int_array()
minm, maxm = [], []
for _ in range(n):
minm.append(read_int_array())
for _ in range(n):
maxm.append(read_int_array())
for r in range(n):
for c in range(m):
minx = min(minm[r][c], maxm[r][c])
maxx = max(minm[r][c], maxm[r][c])
if r:
if minx <= minm[r-1][c] or maxx <= maxm[r-1][c]:
write("Impossible")
return
if c:
if minx <= minm[r][c-1] or maxx <= maxm[r][c-1]:
write("Impossible")
return
minm[r][c] = minx
maxm[r][c] = maxx
write("Possible")
main()
``` | vfc_11150 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1162/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n2 10\n11 5\n9 4\n3 12\n",
"output": "Possible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n2 4 5\n4 5 6\n3 6 7\n8 10 11\n",
"output": "Possible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 3\n2 4\n5 10\n3 1\n3 6\n4 8\n",
"output": "Impossible\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 350 | Solve the following coding problem using the programming language python:
You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than a_{i} times; the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 26) — the number of letters in the alphabet.
The next line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.
-----Output-----
Print a single integer — the maximum length of the string that meets all the requirements.
-----Examples-----
Input
3
2 5 5
Output
11
Input
3
1 1 2
Output
3
-----Note-----
For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".
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())
arr = list(map(int, input().split()))
arr.sort()
arr = arr[::-1]
ans = [arr[0]]
for i in range(1, n):
if(arr[i] < ans[-1]):
ans.append(arr[i])
else:
ans.append(max(0, ans[-1] - 1))
print(sum(ans))
``` | vfc_11154 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/624/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 5 5\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 351 | Solve the following coding problem using the programming language python:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).
Makes has chosen n problems to solve on Decoforces with difficulties a_1, a_2, ..., a_{n}. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty a_{i} only if he had already solved some problem with difficulty $d \geq \frac{a_{i}}{2}$ (no matter on what online judge was it).
Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.
With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.
For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.
Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.
Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
-----Input-----
The first line contains two integer numbers n, k (1 ≤ n ≤ 10^3, 1 ≤ k ≤ 10^9).
The second line contains n space-separated integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
-----Output-----
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
-----Examples-----
Input
3 3
2 1 9
Output
1
Input
4 20
10 3 6 3
Output
0
-----Note-----
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second example he can solve every problem right from the start.
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,k=R()
a=sorted(R())
b=0
for i in a:
while i>k+k:
k+=k
b+=1
k=max(k,i)
print(b)
``` | vfc_11158 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/825/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n2 1 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 20\n10 3 6 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1000000000\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 352 | Solve the following coding problem using the programming language python:
Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
They also decided that there must be given at least min_1 and at most max_1 diplomas of the first degree, at least min_2 and at most max_2 diplomas of the second degree, and at least min_3 and at most max_3 diplomas of the third degree.
After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.
It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.
-----Input-----
The first line of the input contains a single integer n (3 ≤ n ≤ 3·10^6) — the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers min_1 and max_1 (1 ≤ min_1 ≤ max_1 ≤ 10^6) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
The third line of the input contains two integers min_2 and max_2 (1 ≤ min_2 ≤ max_2 ≤ 10^6) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
The next line of the input contains two integers min_3 and max_3 (1 ≤ min_3 ≤ max_3 ≤ 10^6) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
It is guaranteed that min_1 + min_2 + min_3 ≤ n ≤ max_1 + max_2 + max_3.
-----Output-----
In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
-----Examples-----
Input
6
1 5
2 6
3 7
Output
1 2 3
Input
10
1 2
1 3
1 5
Output
2 3 5
Input
6
1 3
2 2
2 2
Output
2 2 2
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())
min1, max1 = map(int, input().split())
min2, max2 = map(int, input().split())
min3, max3 = map(int, input().split())
d1 = min(n - min2 - min3, max1)
d2 = min(n - d1 - min3, max2)
d3 = n - d1 - d2
print(d1,d2,d3)
``` | vfc_11162 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/557/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 5\n2 6\n3 7\n",
"output": "1 2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 2\n1 3\n1 5\n",
"output": "2 3 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 3\n2 2\n2 2\n",
"output": "2 2 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "55\n1 1000000\n40 50\n10 200\n",
"output": "5 40 10 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n1 1\n1 1\n",
"output": "1 1 1 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 354 | Solve the following coding problem using the programming language python:
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name $s$ can transform to another superhero with name $t$ if $s$ can be made equal to $t$ by changing any vowel in $s$ to any other vowel and any consonant in $s$ to any other consonant. Multiple changes can be made.
In this problem, we consider the letters 'a', 'e', 'i', 'o' and 'u' to be vowels and all the other letters to be consonants.
Given the names of two superheroes, determine if the superhero with name $s$ can be transformed to the Superhero with name $t$.
-----Input-----
The first line contains the string $s$ having length between $1$ and $1000$, inclusive.
The second line contains the string $t$ having length between $1$ and $1000$, inclusive.
Both strings $s$ and $t$ are guaranteed to be different and consist of lowercase English letters only.
-----Output-----
Output "Yes" (without quotes) if the superhero with name $s$ can be transformed to the superhero with name $t$ and "No" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
a
u
Output
Yes
Input
abc
ukm
Output
Yes
Input
akm
ua
Output
No
-----Note-----
In the first sample, since both 'a' and 'u' are vowels, it is possible to convert string $s$ to $t$.
In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string $s$ to $t$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
v = list('aeiou')
s = [c in v for c in input()]
t = [c in v for c in input()]
if s == t:
print('Yes')
else:
print('No')
``` | vfc_11170 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1111/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "a\nu\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 355 | Solve the following coding problem using the programming language python:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed. $8$
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
-----Input-----
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
-----Output-----
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
-----Examples-----
Input
........
........
.B....B.
....W...
........
..W.....
........
........
Output
A
Input
..B.....
..W.....
......B.
........
.....W..
......B.
........
........
Output
B
-----Note-----
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
grid = [list(input()) for i in range(8)]
b = 9
w = 9
tblock = False
bblock = False
for r in range(8):
for c in range(8):
for ri in range(r):
if grid[ri][c] == 'B':
tblock = True
for ri in range(r+1, 8):
if grid[ri][c] == 'W':
bblock = True
if grid[r][c] == 'B' and not bblock:
b = min([abs(7-r), b])
elif grid[r][c] == 'W' and not tblock:
w = min([w, r])
tblock = False
bblock = False
if b < w:
print('B')
else:
print('A')
``` | vfc_11174 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/592/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"output": "A\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n",
"output": "B\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 356 | Solve the following coding problem using the programming language python:
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively.
He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array $[1, 10, 100, 1000, 10000]$ Vasya can obtain array $[1, 1110, 10000]$, and from array $[1, 2, 3]$ Vasya can obtain array $[6]$.
Two arrays $A$ and $B$ are considered equal if and only if they have the same length and for each valid $i$ $A_i = B_i$.
Vasya wants to perform some of these operations on array $A$, some on array $B$, in such a way that arrays $A$ and $B$ become equal. Moreover, the lengths of the resulting arrays should be maximal possible.
Help Vasya to determine the maximum length of the arrays that he can achieve or output that it is impossible to make arrays $A$ and $B$ equal.
-----Input-----
The first line contains a single integer $n~(1 \le n \le 3 \cdot 10^5)$ — the length of the first array.
The second line contains $n$ integers $a_1, a_2, \cdots, a_n~(1 \le a_i \le 10^9)$ — elements of the array $A$.
The third line contains a single integer $m~(1 \le m \le 3 \cdot 10^5)$ — the length of the second array.
The fourth line contains $m$ integers $b_1, b_2, \cdots, b_m~(1 \le b_i \le 10^9)$ - elements of the array $B$.
-----Output-----
Print a single integer — the maximum length of the resulting arrays after some operations were performed on arrays $A$ and $B$ in such a way that they became equal.
If there is no way to make array equal, print "-1".
-----Examples-----
Input
5
11 2 3 5 7
4
11 7 3 7
Output
3
Input
2
1 2
1
100
Output
-1
Input
3
1 2 3
3
1 2 3
Output
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()))
m = int(input())
b = list(map(int, input().split()))
ptra = 1
ptrb = 1
sa = a[0]
sb = b[0]
ans = 0
while ptra != n and ptrb != m:
if sa == sb:
ans += 1
sa = a[ptra]
sb = b[ptrb]
ptra += 1
ptrb += 1
continue
if sa < sb:
sa += a[ptra]
ptra += 1
else:
sb += b[ptrb]
ptrb += 1
while ptra != n:
sa += a[ptra]
ptra += 1
while ptrb != m:
sb += b[ptrb]
ptrb += 1
if sa != sb:
print(-1)
return
print(ans + 1)
``` | vfc_11178 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1036/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11 2 3 5 7\n4\n11 7 3 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n1\n100\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n3\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "49\n18 1 7 2 1 1 50 22 8 2 2 1 30 2 46 10 1 4 5 18 25 21 38 11 2 15 29 8 7 2 45 12 14 16 16 23 11 1 1 4 48 18 3 1 1 23 4 10 7\n50\n5 25 34 22 19 4 4 2 40 52 1 4 1 3 47 9 4 1 8 47 4 5 1 1 9 22 9 2 2 1 1 48 7 2 8 16 4 2 41 12 3 30 21 10 2 2 5 1 31 13\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "42\n16 6 12 20 1 1 16 48 4 2 88 1 1 10 46 21 2 37 7 15 27 17 9 28 7 12 1 1 1 3 1 1 2 2 2 1 58 16 2 6 3 14\n46\n9 11 35 46 3 15 5 1 1 79 2 2 4 2 1 43 6 2 2 1 2 50 9 2 5 1 47 5 7 13 9 30 4 2 3 2 1 1 6 35 29 5 6 1 19 4\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "49\n63 13 6 1 50 37 1 1 1 6 34 9 4 2 1 2 3 46 11 1 2 3 4 1 6 74 7 3 1 1 31 18 20 15 1 74 6 2 1 1 6 46 13 29 2 20 44 1 1\n45\n54 19 5 1 1 3 81 1 4 3 1 5 1 28 18 3 5 1 23 33 9 3 31 47 5 7 2 76 1 4 1 2 1 48 4 31 1 74 12 2 3 4 1 32 34\n",
"output": "15\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 357 | Solve the following coding problem using the programming language python:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive.
-----Input-----
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
-----Output-----
Print "YES", if problem is from this contest, and "NO" otherwise.
-----Examples-----
Input
Alex_and_broken_contest
Output
NO
Input
NikitaAndString
Output
YES
Input
Danil_and_Olya
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
if (s.count('Danil') + s.count('Olya') + s.count('Slava') + s.count('Ann') + s.count('Nikita') == 1):
print('YES')
else:
print('NO')
``` | vfc_11182 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/877/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Alex_and_broken_contest\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "NikitaAndString\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Danil_and_Olya\n",
"output": "NO",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 358 | Solve the following coding problem using the programming language python:
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any integer x (a ≤ x ≤ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
-----Input-----
A single line contains three space-separated integers a, b, k (1 ≤ a, b, k ≤ 10^6; a ≤ b).
-----Output-----
In a single line print a single integer — the required minimum l. If there's no solution, print -1.
-----Examples-----
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 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
def f(n):
m = int(n ** 0.5) + 1
t = [1] * (n + 1)
for i in range(3, m):
if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)
return [2] + [i for i in range(3, n + 1, 2) if t[i]]
a, b, k = map(int, input().split())
n = 2000001
t, p, x = [-1] * n, f(n), -1
k -= 1; b += 1
for i in range(len(p) - k):
t[p[i]] = p[i + k] - p[i]
t.reverse()
for i in range(1, n):
if t[i] < 0: t[i] = t[i - 1] + 1
t.reverse()
for i in range(a + 1, b):
t[i] = max(t[i], t[i - 1])
for l in range(1, b - a + 1):
if t[b - l] < l:
x = l
break
print(x)
``` | vfc_11186 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/237/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 13 1\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 359 | Solve the following coding problem using the programming language python:
Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w.
The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and horizontally photos and also the distances between outside rows and columns of photos to the nearest bound of the wall must be equal to x, where x is some non-negative real number. Look on the picture below for better understanding of the statement.
[Image]
Arkadiy haven't chosen yet how many photos he would put on the wall, however, he want to put at least one photo. Your task is to determine the minimum value of x which can be obtained after putting photos, or report that there is no way to put positive number of photos and satisfy all the constraints. Suppose that Arkadiy has enough photos to make any valid arrangement according to the constraints.
Note that Arkadiy wants to put at least one photo on the wall. The photos should not overlap, should completely lie inside the wall bounds and should have sides parallel to the wall sides.
-----Input-----
The first line contains three integers a, h and w (1 ≤ a, h, w ≤ 10^9) — the size of photos and the height and the width of the wall.
-----Output-----
Print one non-negative real number — the minimum value of x which can be obtained after putting the photos on the wall. The absolute or the relative error of the answer must not exceed 10^{ - 6}.
Print -1 if there is no way to put positive number of photos and satisfy the constraints.
-----Examples-----
Input
2 18 13
Output
0.5
Input
4 4 4
Output
0
Input
3 4 3
Output
-1
-----Note-----
In the first example Arkadiy can put 7 rows of photos with 5 photos in each row, so the minimum value of x equals to 0.5.
In the second example Arkadiy can put only 1 photo which will take the whole wall, so the minimum value of x equals to 0.
In the third example there is no way to put positive number of photos and satisfy the constraints described in the statement, so the answer is -1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a,h,w=(int(x) for x in input().split())
if h==w:
if a<h:
n=w//a
x=(w-a*n)/(n+1)
print(x)
elif a==h:
print(0)
else:
print(-1)
else:
for i in range(100):
if h>w:
w,h=h,w
if w>h+a*2:
w=w-h-a
if h>w:
w,h=h,w
m=h//a
s=(w-h)//a
r=0
if m<s or s==0:
for i in range(m,0,-1):
x=(h-a*i)/(i+1)
w1=w-x
a1=a+x
q=w1%a1
if q<0.00000001 or a1-q<0.0000001:
r=1
break
if r==0:
print(-1)
else:
print(x)
else:
for i in range(s,0,-1):
x=(w-h-i*a)/i
w1=w-x
a1=a+x
q=w1%a1
if q<0.00000001:
r=1
break
if r==0:
print(-1)
else:
print(x)
``` | vfc_11190 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/774/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 18 13\n",
"output": "0.50000000000000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 360 | Solve the following coding problem using the programming language python:
After lessons Nastya decided to read a book. The book contains $n$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.
Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $k$ as the first page which was not read (i.e. she read all pages from the $1$-st to the $(k-1)$-th).
The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle).
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 100$) — the number of chapters in the book.
There are $n$ lines then. The $i$-th of these lines contains two integers $l_i$, $r_i$ separated by space ($l_1 = 1$, $l_i \leq r_i$) — numbers of the first and the last pages of the $i$-th chapter. It's guaranteed that $l_{i+1} = r_i + 1$ for all $1 \leq i \leq n-1$, and also that every chapter contains at most $100$ pages.
The $(n+2)$-th line contains a single integer $k$ ($1 \leq k \leq r_n$) — the index of the marked page.
-----Output-----
Print a single integer — the number of chapters which has not been completely read so far.
-----Examples-----
Input
3
1 3
4 7
8 11
2
Output
3
Input
3
1 4
5 9
10 12
9
Output
2
Input
1
1 7
4
Output
1
-----Note-----
In the first example the book contains $11$ pages and $3$ chapters — $[1;3]$, $[4;7]$ and $[8;11]$. Nastya marked the $2$-nd page, so she finished in the middle of the $1$-st chapter. So, all chapters has not been read so far, so the answer is $3$.
The book in the second example contains $12$ pages and $3$ chapters too, but Nastya finished reading in the middle of the $2$-nd chapter, so that the answer is $2$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
n = ii()
a = [li() for _ in range(n)]
k = ii()
ans = 0
for l, r in a:
ans += k <= r
print(ans)
``` | vfc_11194 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1136/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3\n4 7\n8 11\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 4\n5 9\n10 12\n9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 7\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 6\n7 16\n17 20\n4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 6\n7 13\n14 17\n16\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 361 | Solve the following coding problem using the programming language python:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforces^{ω} that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
-----Input-----
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
-----Output-----
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
-----Examples-----
Input
CODEWAITFORITFORCES
Output
YES
Input
BOTTOMCODER
Output
NO
Input
DECODEFORCES
Output
YES
Input
DOGEFORCES
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
fin = sys.stdin
fout = sys.stdout
#fin = open("input.txt", 'r')
#fout = open("output.txt", 'w')
s = fin.readline().strip()
n = len(s)
for L in range(n):
for R in range(L + 1, n + 1):
s1 = s[:L]
s2 = s[L:R]
s3 = s[R:]
if (s1 + s3 == "CODEFORCES"):
print("YES")
return
print("NO")
``` | vfc_11198 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/538/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "CODEWAITFORITFORCES\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BOTTOMCODER\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "DECODEFORCES\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "DOGEFORCES\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ABACABA\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 362 | Solve the following coding problem using the programming language python:
You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.
Calculate the minimum weight among all triangulations of the polygon.
-----Input-----
The first line contains single integer $n$ ($3 \le n \le 500$) — the number of vertices in the regular polygon.
-----Output-----
Print one integer — the minimum weight among all triangulations of the given polygon.
-----Examples-----
Input
3
Output
6
Input
4
Output
18
-----Note-----
According to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $P$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $P$.
In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $1 \cdot 2 \cdot 3 = 6$.
In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $1-3$ so answer is $1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$.
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):
ans += (i + 1) * (i + 2)
print(ans)
``` | vfc_11202 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1140/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 364 | Solve the following coding problem using the programming language python:
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color A, then Bob chooses some color B (A ≠ B). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after i-th car cnt_{A}(i) and cnt_{B}(i).
If cnt_{A}(i) > cnt_{B}(i) for every i then the winner is Alice. If cnt_{B}(i) ≥ cnt_{A}(i) for every i then the winner is Bob. Otherwise it's a draw.
Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color A and Bob now wants to choose such color B that he will win the game (draw is not a win). Help him find this color.
If there are multiple solutions, print any of them. If there is no such color then print -1.
-----Input-----
The first line contains two integer numbers n and A (1 ≤ n ≤ 10^5, 1 ≤ A ≤ 10^6) – number of cars and the color chosen by Alice.
The second line contains n integer numbers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^6) — colors of the cars that Alice and Bob will encounter in the order of their appearance.
-----Output-----
Output such color B (1 ≤ B ≤ 10^6) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1 ≤ B ≤ 10^6).
-----Examples-----
Input
4 1
2 1 4 2
Output
2
Input
5 2
2 2 4 5 3
Output
-1
Input
3 10
1 2 3
Output
4
-----Note-----
Let's consider availability of colors in the first example: cnt_2(i) ≥ cnt_1(i) for every i, and color 2 can be the answer. cnt_4(2) < cnt_1(2), so color 4 isn't the winning one for Bob. All the other colors also have cnt_{j}(2) < cnt_1(2), thus they are not available.
In the third example every color is acceptable except for 10.
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, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
sze = max(values)
used = [0 for i in range(sze + 1)]
challengers = [[] for i in range(n + 1)]
i = 0
cnt = 0
for i in range(n):
if values[i] == k:
cnt += 1
elif used[values[i]] >= cnt:
used[values[i]] += 1
challengers[used[values[i]]].append(values[i])
for i in range(n, cnt - 1, -1):
if len(challengers[i]):
stdout.write(str(challengers[i][0]))
break
else:
stdout.write('-1')
``` | vfc_11210 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/818/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n2 1 4 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 365 | Solve the following coding problem using the programming language python:
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and a_{i} is the length of i-th segment. No two segments touch or intersect.
For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
-----Input-----
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 10^9) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains n integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10000) — the encoding.
-----Output-----
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
-----Examples-----
Input
2 4
1 3
Output
NO
Input
3 10
3 3 2
Output
YES
Input
2 10
1 3
Output
NO
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()
print('YES'if sum(R())+n-1==x else'NO')
``` | vfc_11214 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/884/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 366 | Solve the following coding problem using the programming language python:
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$.
It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$?
-----Input-----
The only line of the input contains two integers $n$ and $S$ ($1 \le n \le 100\,000$, $1 \le S \le 10^9$)
-----Output-----
Print exactly one integer — the minimum number of coins required to obtain sum $S$.
-----Examples-----
Input
5 11
Output
3
Input
6 16
Output
3
-----Note-----
In the first example, some of the possible ways to get sum $11$ with $3$ coins are:
$(3, 4, 4)$
$(2, 4, 5)$
$(1, 5, 5)$
$(3, 3, 5)$
It is impossible to get sum $11$ with less than $3$ coins.
In the second example, some of the possible ways to get sum $16$ with $3$ coins are:
$(5, 5, 6)$
$(4, 6, 6)$
It is impossible to get sum $16$ with less than $3$ coins.
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 % n != 0:
print( m // n + 1)
else:
print(m // n)
``` | vfc_11218 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1061/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 11\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 16\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 28\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 367 | Solve the following coding problem using the programming language python:
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes.
You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically.
-----Input-----
The only line contains string s (1 ≤ |s| ≤ 2·10^5) consisting of only lowercase Latin letters.
-----Output-----
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
-----Examples-----
Input
aabc
Output
abba
Input
aabcd
Output
abcba
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
possible=[0]*26
for i in input().strip():
possible[ord(i)-97]+=1
# make changes
temp=[]
for i in range(26):
if possible[i]%2: temp.append(i)
while len(temp)>1:
possible[temp[0]]+=1
possible[temp[-1]]-=1
temp.pop(0)
temp.pop(-1)
# print stuff
for i in range(26):
print(chr(97+i)*(possible[i]//2),end="")
if temp: print(chr(97+temp[0]),end="")
for i in range(26)[::-1]:
print(chr(97+i)*(possible[i]//2),end="")
``` | vfc_11222 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/600/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aabc\n",
"output": "abba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aabcd\n",
"output": "abcba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "u\n",
"output": "u\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ttttt\n",
"output": "ttttt\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 368 | Solve the following coding problem using the programming language python:
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight: the queen's weight is 9, the rook's weight is 5, the bishop's weight is 3, the knight's weight is 3, the pawn's weight is 1, the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
-----Input-----
The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.
The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.
-----Output-----
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
-----Examples-----
Input
...QK...
........
........
........
........
........
........
...rk...
Output
White
Input
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Output
Draw
Input
rppppppr
...k....
........
........
........
........
K...Q...
........
Output
Black
-----Note-----
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = 0
b = 0
x = {'Q': 9, 'q':9, 'R':5, 'r':5, 'B':3, 'b':3, 'N':3, 'n':3, 'P': 1, 'p': 1}
for i in range(8):
t = [i for i in input()]
for i in t:
if ord(i) >= 97 and i in x:
a += x[i]
elif i in x:
b += x[i]
if a == b:
print("Draw")
elif a < b:
print("White")
else:
print("Black")
``` | vfc_11226 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/519/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n",
"output": "White\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 371 | Solve the following coding problem using the programming language python:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
-----Input-----
The single line of input contains the integer m (1 ≤ m ≤ 10^15) — the number of ways the thieves might steal the chocolates, as rumours say.
-----Output-----
Print the only integer n — the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
-----Examples-----
Input
1
Output
8
Input
8
Output
54
Input
10
Output
-1
-----Note-----
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, 20, 40), (6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
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, r = 0, 10**16
D = [x ** 3.0 for x in range(2, 170417)]
DD = [x*x*x for x in range(2, 170417)]
while l < r:
m = (l+r) // 2
if sum(int(m/d) for d in D) < n:
l = m + 1
else:
r = m;
if sum(l//d for d in DD) == n:
print(l);
else :
print((-1));
``` | vfc_11238 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/689/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "27\n",
"output": "152\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "28206\n",
"output": "139840\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "32\n",
"output": "184\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 373 | Solve the following coding problem using the programming language python:
Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.
He came up with the following game. The player has a positive integer $n$. Initially the value of $n$ equals to $v$ and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer $x$ that $x<n$ and $x$ is not a divisor of $n$, then subtract $x$ from $n$. The goal of the player is to minimize the value of $n$ in the end.
Soon, Chouti found the game trivial. Can you also beat the game?
-----Input-----
The input contains only one integer in the first line: $v$ ($1 \le v \le 10^9$), the initial value of $n$.
-----Output-----
Output a single integer, the minimum value of $n$ the player can get.
-----Examples-----
Input
8
Output
1
Input
1
Output
1
-----Note-----
In the first example, the player can choose $x=3$ in the first turn, then $n$ becomes $5$. He can then choose $x=4$ in the second turn to get $n=1$ as the result. There are other ways to get this minimum. However, for example, he cannot choose $x=2$ in the first turn because $2$ is a divisor of $8$.
In the second example, since $n=1$ initially, the player can do nothing.
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())
if n==2:
print(2)
else:
print(1)
``` | vfc_11246 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1081/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 374 | Solve the following coding problem using the programming language python:
Bandits appeared in the city! One of them is trying to catch as many citizens as he can.
The city consists of $n$ squares connected by $n-1$ roads in such a way that it is possible to reach any square from any other square. The square number $1$ is the main square.
After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square.
At the moment when the bandit appeared on the main square there were $a_i$ citizens on the $i$-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square.
The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught?
-----Input-----
The first line contains a single integer $n$ — the number of squares in the city ($2 \le n \le 2\cdot10^5$).
The second line contains $n-1$ integers $p_2, p_3 \dots p_n$ meaning that there is a one-way road from the square $p_i$ to the square $i$ ($1 \le p_i < i$).
The third line contains $n$ integers $a_1, a_2, \dots, a_n$ — the number of citizens on each square initially ($0 \le a_i \le 10^9$).
-----Output-----
Print a single integer — the number of citizens the bandit will catch if both sides act optimally.
-----Examples-----
Input
3
1 1
3 1 2
Output
3
Input
3
1 1
3 1 3
Output
4
-----Note-----
In the first example the citizens on the square $1$ can split into two groups $2 + 1$, so that the second and on the third squares will have $3$ citizens each.
In the second example no matter how citizens act the bandit can catch at least $4$ citizens.
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 = int(input())
p = list(map(int,input().split()))
a = list(map(int,input().split()))
edge = [[] for i in range(n)]
for i in range(n-1):
edge[p[i]-1].append(i+1)
dp = [0 for i in range(n)]
size = [not edge[v] for v in range(n)]
res = []
deq = deque([0])
while deq:
v = deq.popleft()
res.append(v)
for nv in edge[v]:
deq.append(nv)
res = res[::-1]
for v in res:
tmp = -1
S = 0
for nv in edge[v]:
tmp = max(tmp,dp[nv])
size[v] += size[nv]
S += a[nv]
if not edge[v]:
dp[v] = a[v]
continue
rest = tmp*size[v] - S
if a[v]<=rest:
dp[v] = tmp
else:
q = (a[v]-rest)//size[v]
r = (a[v]-rest)%size[v]
if r:
dp[v] = tmp + q + 1
else:
dp[v] = tmp + q
a[v] += S
print(dp[0])
``` | vfc_11250 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1436/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n3 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n3 1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n2 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 375 | Solve the following coding problem using the programming language python:
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word.
Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T.
The second line contains word S.
The third line contains word T.
Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words.
-----Output-----
Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.
-----Examples-----
Input
7
reading
trading
Output
1
Input
5
sweet
sheep
Output
0
Input
3
toy
try
Output
2
-----Note-----
In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).
In the second sample test the two given words couldn't be obtained from the same word by removing one letter.
In the third sample test the two given words could be obtained from either word "tory" or word "troy".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def check(w, s):
j = 0
for i in range(len(s)):
while j < len(w) and s[i] != w[j]:
j += 1
if j >= len(w) or s[i] != w[j]:
return False
j += 1
return True
n = int(input())
s = input()
t = input()
st = []
i = 0
while i < n and s[i] == t[i]:
st.append(s[i])
i += 1
w1 = st[:]
w2 = st[:]
w3 = st[:]
w4 = st[:]
w1.append(s[i])
w1.append(t[i])
w3.append(s[i])
w3.append(t[i])
w2.append(t[i])
w2.append(s[i])
w4.append(t[i])
w4.append(s[i])
for j in range(i + 1, n):
w1.append(s[j])
w2.append(t[j])
w3.append(t[j])
w4.append(s[j])
res = set()
for ww in (w1, w2, w3, w4):
www = ''.join(ww)
if check(www, s) and check(www, t):
res.add(www)
print(len(res))
``` | vfc_11254 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/532/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\nreading\ntrading\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nsweet\nsheep\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 377 | Solve the following coding problem using the programming language python:
The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...
What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $n$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.
Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $m$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?
Could you help her with this curiosity?
You can see the examples and their descriptions with pictures in the "Note" section.
-----Input-----
The only line contains two integers $n$ and $m$ ($2 \leq n \leq 1000$, $0 \leq m \leq n$) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.
-----Output-----
Print a single integer — the maximum number of groups of cats at the moment Katie observes.
-----Examples-----
Input
7 4
Output
3
Input
6 2
Output
2
Input
3 0
Output
1
Input
2 2
Output
0
-----Note-----
In the first example, originally there are $7$ cats sitting as shown below, creating a single group: [Image]
At the observed moment, $4$ cats have left the table. Suppose the cats $2$, $3$, $5$ and $7$ have left, then there are $3$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining. [Image]
In the second example, there are $6$ cats sitting as shown below: [Image]
At the observed moment, $2$ cats have left the table. Suppose the cats numbered $3$ and $6$ left, then there will be $2$ groups remaining ($\{1, 2\}$ and $\{4, 5\}$). It is impossible to have more than $2$ groups of cats remaining. [Image]
In the third example, no cats have left, so there is $1$ group consisting of all cats.
In the fourth example, all cats have left the circle, so there are $0$ groups.
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())
if m <= 1:
print(1)
return
print(min(m, n - m))
``` | vfc_11262 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1163/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 378 | Solve the following coding problem using the programming language python:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ≤ 9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
-----Input-----
The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
-----Output-----
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
-----Examples-----
Input
117 3
Output
9
Input
237 7
Output
1
Input
15 2
Output
2
-----Note-----
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
k, r = list(map(int, input().split()))
ans = 10
for x in range(1, 11):
mod = k * x % 10
if mod == 0 or mod == r:
ans = x
break
print(ans)
``` | vfc_11266 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/732/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "117 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "237 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 380 | Solve the following coding problem using the programming language python:
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.
-----Input-----
Each of the three lines of the input contains two integers. The i-th line contains integers x_{i} and y_{i} ( - 10^9 ≤ x_{i}, y_{i} ≤ 10^9) — the coordinates of the i-th point. It is guaranteed that all points are distinct.
-----Output-----
Print a single number — the minimum possible number of segments of the polyline.
-----Examples-----
Input
1 -1
1 1
1 2
Output
1
Input
-1 -1
-1 3
4 3
Output
2
Input
1 1
2 3
3 2
Output
3
-----Note-----
The variant of the polyline in the first sample: [Image] The variant of the polyline in the second sample: $1$ The variant of the polyline in the third sample: $\because$
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(' ')))
c, d = list(map(int, input().split(' ')))
e, f = list(map(int, input().split(' ')))
x=[[a, b],[c,d],[e,f]]
x.sort()
a, b, c, d, e, f = x[0][0], x[0][1], x[1][0], x[1][1], x[2][0], x[2][1]
if (a==c==e or b==d==f):
print(1)
quit()
if a == c:
if b<f<d:
print(3)
quit()
print(2)
quit()
if c == e:
if (d<b<f):
print(3)
quit()
print(2)
quit()
if b == d:
print(2)
quit()
if d == f:
print(2)
quit()
if b == f:
if a<c<e:
print(3)
quit()
print(2)
quit()
print(3)
quit()
``` | vfc_11274 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/617/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 -1\n1 1\n1 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 381 | Solve the following coding problem using the programming language python:
An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.
Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph doesn't exist.
-----Input-----
The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.
-----Output-----
Print "NO" (without quotes), if such graph doesn't exist.
Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines.
The description of the made graph must start with numbers n and m — the number of vertices and edges respectively.
Each of the next m lines must contain two integers, a and b (1 ≤ a, b ≤ n, a ≠ b), that mean that there is an edge connecting the vertices a and b. A graph shouldn't contain multiple edges and edges that lead from a vertex to itself. A graph must be connected, the degrees of all vertices of the graph must be equal k. At least one edge of the graph must be a bridge. You can print the edges of the graph in any order. You can print the ends of each edge in any order.
The constructed graph must contain at most 10^6 vertices and 10^6 edges (it is guaranteed that if at least one graph that meets the requirements exists, then there also exists the graph with at most 10^6 vertices and at most 10^6 edges).
-----Examples-----
Input
1
Output
YES
2 1
1 2
-----Note-----
In the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
def VI(): return list(map(int,input().split()))
def main1(k):
# works correctly, but too slow and generates many more vertices than necessary.
# doesn't pass the time constraint with this implementation. (prints 10^5 lines)
# ==> use the editorial solution below.
if k%2==0:
print("NO")
return
print("YES")
n = 2*(k**2-k+1)
m = n*k//2
print(n, m)
i = 0
g = [[] for i in range(n+1)]
print(1,n//2+1)
off = 1
for j in range(0,k-1,2):
j1 = off + j+1
j2 = off + j+2
print(off,j1)
print(off,j2)
l1 = off + k + j*(k-1)
l2 = off + k + (j+1)*(k-1)
for l in range(k-1):
print(j1, l1+l)
print(j2, l2+l)
for m in range(k-1):
print(l1+l,l2+m)
off = n//2+1
for j in range(0,k-1,2):
j1 = off + j+1
j2 = off + j+2
print(off,j1)
print(off,j2)
l1 = off + k + j*(k-1)
l2 = off + k + (j+1)*(k-1)
for l in range(k-1):
print(j1, l1+l)
print(j2, l2+l)
for m in range(k-1):
print(l1+l,l2+m)
def main(k):
# following the editorial algo
if k%2==0:
print("NO")
return
print("YES")
if k==1:
print("2 1")
print("1 2")
return
n = 2*k+4
m = n*k//2
e = []
e.extend([(1,n//2+1)])
off = 1
for j in range(off+1,off+k):
e.extend([(off, j)])
for j in range(off+1,off+k):
for i in range(j+1,off+k):
if (i==j+1 and (j-off)%2==1):# or (j==off+1 and i==off+k-1):
#if (i==j+1 and i%2==0) or (j==off+1 and i==off+k-1):
continue
e.extend([(j,i)])
e.extend([(j,off+k),(j,off+k+1)])
e.extend([(off+k,off+k+1)])
off = n//2+1
for j in range(off+1,off+k):
e.extend([(off, j)])
for j in range(off+1,off+k):
for i in range(j+1,off+k):
if (i==j+1 and (j-off)%2==1):# or (j==off+1 and i==off+k-1):
continue
e.extend([(j,i)])
e.extend([(j,off+k),(j,off+k+1)])
e.extend([(off+k,off+k+1)])
print(n, m)
for x in e:
print(*x)
def main_input(info=0):
k = int(input())
main(k)
def __starting_point():
main_input()
__starting_point()
``` | vfc_11278 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/550/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "YES\n2 1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "YES\n10 15\n1 6\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "YES\n14 35\n1 8\n1 2\n1 3\n1 4\n1 5\n2 6\n2 7\n2 4\n2 5\n3 6\n3 7\n3 4\n3 5\n4 6\n4 7\n5 6\n5 7\n6 7\n8 9\n8 10\n8 11\n8 12\n9 13\n9 14\n9 11\n9 12\n10 13\n10 14\n10 11\n10 12\n11 13\n11 14\n12 13\n12 14\n13 14\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 382 | Solve the following coding problem using the programming language python:
You are given two strings $s$ and $t$, both consisting only of lowercase Latin letters.
The substring $s[l..r]$ is the string which is obtained by taking characters $s_l, s_{l + 1}, \dots, s_r$ without changing the order.
Each of the occurrences of string $a$ in a string $b$ is a position $i$ ($1 \le i \le |b| - |a| + 1$) such that $b[i..i + |a| - 1] = a$ ($|a|$ is the length of string $a$).
You are asked $q$ queries: for the $i$-th query you are required to calculate the number of occurrences of string $t$ in a substring $s[l_i..r_i]$.
-----Input-----
The first line contains three integer numbers $n$, $m$ and $q$ ($1 \le n, m \le 10^3$, $1 \le q \le 10^5$) — the length of string $s$, the length of string $t$ and the number of queries, respectively.
The second line is a string $s$ ($|s| = n$), consisting only of lowercase Latin letters.
The third line is a string $t$ ($|t| = m$), consisting only of lowercase Latin letters.
Each of the next $q$ lines contains two integer numbers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the arguments for the $i$-th query.
-----Output-----
Print $q$ lines — the $i$-th line should contain the answer to the $i$-th query, that is the number of occurrences of string $t$ in a substring $s[l_i..r_i]$.
-----Examples-----
Input
10 3 4
codeforces
for
1 3
3 10
5 6
5 7
Output
0
1
0
1
Input
15 2 3
abacabadabacaba
ba
1 15
3 4
2 14
Output
4
0
3
Input
3 5 2
aaa
baaab
1 3
1 1
Output
0
0
-----Note-----
In the first example the queries are substrings: "cod", "deforces", "fo" and "for", respectively.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#
import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
def getIntList():
return list(map(int, input().split()))
try :
#raise ModuleNotFoundError
import numpy
def dprint(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
dprint('debug mode')
except ModuleNotFoundError:
def dprint(*args, **kwargs):
pass
inId = 0
outId = 0
if inId>0:
dprint('use input', inId)
sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
dprint('use output', outId)
sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit
N, M, Q = getIntList()
s1 = input()
s2 = input()
tot = 0
zt = [0]
for i in range(N):
if s1[i:i+M] == s2:
tot+=1
zt.append(tot)
dprint(zt)
for i in range(Q):
a,b = getIntList()
b0 = b- M+1
if b0<a:
print(0)
else:
print(zt[b0] - zt[a-1])
``` | vfc_11282 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1016/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3 4\ncodeforces\nfor\n1 3\n3 10\n5 6\n5 7\n",
"output": "0\n1\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 2 3\nabacabadabacaba\nba\n1 15\n3 4\n2 14\n",
"output": "4\n0\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 2\naaa\nbaaab\n1 3\n1 1\n",
"output": "0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 3 66\nssszzzzsssz\nsss\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n1 5\n2 5\n3 5\n4 5\n5 5\n1 6\n2 6\n3 6\n4 6\n5 6\n6 6\n1 7\n2 7\n3 7\n4 7\n5 7\n6 7\n7 7\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n8 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n7 9\n8 9\n9 9\n1 10\n2 10\n3 10\n4 10\n5 10\n6 10\n7 10\n8 10\n9 10\n10 10\n1 11\n2 11\n3 11\n4 11\n5 11\n6 11\n7 11\n8 11\n9 11\n10 11\n11 11\n",
"output": "0\n0\n0\n1\n0\n0\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n2\n1\n1\n1\n1\n1\n1\n1\n0\n0\n2\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 15\nabaca\nabaca\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n1 5\n2 5\n3 5\n4 5\n5 5\n",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1\naaa\na\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 383 | Solve the following coding problem using the programming language python:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
[Image]
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10^9 + 7).
-----Input-----
A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).
-----Output-----
Print a single integer — the answer to the problem modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 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
ans = {}
def gen(n, k, d, used = False):
if not ans.get((n, k, d, used)):
if not n and used:
ans[(n, k, d, used)] = 1
else:
ans[(n, k, d, used)] = sum(gen(n - x, k, d, used or x >= d) for x in range(1, min(n, k) + 1) if max(x, n - x) >= d or used)
return ans[(n, k, d, used)]
n, k, d = list(map(int, input().split()))
print(gen(n, k, d) % 1000000007)
``` | vfc_11286 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/431/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "28 6 3\n",
"output": "110682188\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 384 | Solve the following coding problem using the programming language python:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword. [Image] The example of encrypting of a single row of japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
-----Output-----
The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
-----Examples-----
Input
3
BBW
Output
1
2
Input
5
BWBWB
Output
3
1 1 1
Input
4
WWWW
Output
0
Input
4
BBBB
Output
1
4
Input
13
WBBBBWWBWBBBW
Output
3
4 1 3
-----Note-----
The last sample case correspond to the picture in the statement.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# You lost the game.
n = int(input())
s = str(input())
R = []
b = 0
for i in range(n):
if s[i] == "B":
b += 1
elif b > 0:
R += [b]
b = 0
if b > 0:
R += [b]
print(len(R))
for i in range(len(R)):
print(R[i],end=" ")
``` | vfc_11290 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/721/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nBBW\n",
"output": "1\n2 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 385 | Solve the following coding problem using the programming language python:
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS).
Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. Each bracket in CBS has a pair. For example, in "(()(()))": 1st bracket is paired with 8th, 2d bracket is paired with 3d, 3d bracket is paired with 2d, 4th bracket is paired with 7th, 5th bracket is paired with 6th, 6th bracket is paired with 5th, 7th bracket is paired with 4th, 8th bracket is paired with 1st.
Polycarp's editor currently supports only three operations during the use of CBS. The cursor in the editor takes the whole position of one of the brackets (not the position between the brackets!). There are three operations being supported: «L» — move the cursor one position to the left, «R» — move the cursor one position to the right, «D» — delete the bracket in which the cursor is located, delete the bracket it's paired to and all brackets between them (that is, delete a substring between the bracket in which the cursor is located and the one it's paired to).
After the operation "D" the cursor moves to the nearest bracket to the right (of course, among the non-deleted). If there is no such bracket (that is, the suffix of the CBS was deleted), then the cursor moves to the nearest bracket to the left (of course, among the non-deleted).
There are pictures illustrated several usages of operation "D" below. [Image]
All incorrect operations (shift cursor over the end of CBS, delete the whole CBS, etc.) are not supported by Polycarp's editor.
Polycarp is very proud of his development, can you implement the functionality of his editor?
-----Input-----
The first line contains three positive integers n, m and p (2 ≤ n ≤ 500 000, 1 ≤ m ≤ 500 000, 1 ≤ p ≤ n) — the number of brackets in the correct bracket sequence, the number of operations and the initial position of cursor. Positions in the sequence are numbered from left to right, starting from one. It is guaranteed that n is even.
It is followed by the string of n characters "(" and ")" forming the correct bracket sequence.
Then follow a string of m characters "L", "R" and "D" — a sequence of the operations. Operations are carried out one by one from the first to the last. It is guaranteed that the given operations never move the cursor outside the bracket sequence, as well as the fact that after all operations a bracket sequence will be non-empty.
-----Output-----
Print the correct bracket sequence, obtained as a result of applying all operations to the initial sequence.
-----Examples-----
Input
8 4 5
(())()()
RDLD
Output
()
Input
12 5 3
((()())(()))
RRDLD
Output
(()(()))
Input
8 8 8
(())()()
LLLLLLDD
Output
()()
-----Note-----
In the first sample the cursor is initially at position 5. Consider actions of the editor: command "R" — the cursor moves to the position 6 on the right; command "D" — the deletion of brackets from the position 5 to the position 6. After that CBS takes the form (())(), the cursor is at the position 5; command "L" — the cursor moves to the position 4 on the left; command "D" — the deletion of brackets from the position 1 to the position 4. After that CBS takes the form (), the cursor is at the position 1.
Thus, the answer is equal to ().
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m, p = [int(x) for x in input().split()]
A = input().rstrip()
B = input().rstrip()
pair = [0] * n
stack = []
for (i, c) in enumerate(A):
if c == '(':
stack.append(i)
else:
j = stack.pop()
pair[i] = j
pair[j] = i
start = 0
pointer = p - 1
left = list(range(-1, n-1))
right = list(range(1, n+1))
left[0] = None
right[-1] = None
for c in B:
if c == 'R':
pointer = right[pointer]
elif c == 'L':
pointer = left[pointer]
else:
if pair[pointer] < pointer:
if right[pointer] is not None:
left[right[pointer]] = left[pair[pointer]]
if left[pair[pointer]] is not None:
right[left[pair[pointer]]] = right[pointer]
else:
start = right[pointer]
if right[pointer] is None:
pointer = left[pair[pointer]]
else:
pointer = right[pointer]
else:
if right[pair[pointer]] is not None:
left[right[pair[pointer]]] = left[pointer]
if left[pointer] is not None:
right[left[pointer]] = right[pair[pointer]]
else:
start = right[pair[pointer]]
if right[pair[pointer]] is None:
pointer = left[pointer]
else:
pointer = right[pair[pointer]]
i = start
while right[i] is not None:
print(A[i], end = '')
i = right[i]
print(A[i])
``` | vfc_11294 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/670/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 4 5\n(())()()\nRDLD\n",
"output": "()\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12 5 3\n((()())(()))\nRRDLD\n",
"output": "(()(()))\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 8 8\n(())()()\nLLLLLLDD\n",
"output": "()()\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 2\n()()\nLD\n",
"output": "()\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4 1\n()()()\nDRRD\n",
"output": "()\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 386 | Solve the following coding problem using the programming language python:
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: Is it true that y is strictly larger than number x? Is it true that y is strictly smaller than number x? Is it true that y is larger than or equal to number x? Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: ">" (for the first type queries), "<" (for the second type queries), ">=" (for the third type queries), "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 10^9 ≤ x ≤ 10^9. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
-----Output-----
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·10^9 ≤ y ≤ 2·10^9. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
-----Examples-----
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Round 241 Div 1 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
res = inputs[:]
inputs[:] = []
while n > len(inputs):
inputs.extend(input().split(" "))
if n > 0:
res = inputs[:n]
inputs[:n] = []
return res
InputHandler = InputHandlerObject()
g = InputHandler.getInput
############################## SOLUTION ##############################
n = int(input().strip())
mn = -2*10**9
mx = 2*10**9
repl = [(">", "<="), (">=", "<"), ("<=", ">"), ("<", ">=")]
for i in range(n):
a = g()
a[1] = int(a[1])
if a[2] == "N":
for qq,qqq in repl:
if qq == a[0]:
a[0] = qqq
break
if a[0] == ">": a[1] += 1
if a[0] == "<": a[1] -= 1
if a[0][0] == ">": mn = max(mn, a[1])
if a[0][0] == "<": mx = min(mx, a[1])
if mn <= mx:
print(mn)
else:
print("Impossible")
``` | vfc_11298 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/416/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n> 100 Y\n< -100 Y\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 387 | Solve the following coding problem using the programming language python:
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$.
For example, the period of string "ABAABAA" is $3$, the period of "AAAA" is $1$, and the period of "AABBB" is $5$.
Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
-----Input-----
The first line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of letters 'A' and 'B', respectively.
-----Output-----
Print the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
-----Examples-----
Input
2 4
Output
4
Input
5 3
Output
5
-----Note-----
All the possible periods for the first example: $3$ "BBABBA" $4$ "BBAABB" $5$ "BBBAAB" $6$ "AABBBB"
All the possible periods for the second example: $3$ "BAABAABA" $5$ "BAABABAA" $6$ "BABAAABA" $7$ "BAABAAAB" $8$ "AAAAABBB"
Note that these are not the only possible strings for the given periods.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
a,b= list(map(int,input().split()))
n=a+b
ans,l=0,1
while l<=n:
g= n//l
if a<g or b<g:
l= (n//g) +1
continue
r= n//g
a_low = (a+g)//(g+1)
a_high = a//g
b_low=(b+g)//(g+1)
b_high = b//g
if (a_low <= a_high and b_low <= b_high):
ans += max(0,min(r,a_high+b_high)- max(l,a_low +b_low)+1)
l=r+1
print(ans)
``` | vfc_11302 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1202/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 389 | Solve the following coding problem using the programming language python:
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
-----Input-----
The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 10^9).
-----Output-----
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
-----Examples-----
Input
15 20
Output
3
Input
14 8
Output
-1
Input
6 6
Output
0
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()))
def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
def burn(n):
c=0
while(n%2==0):
c+=1
n=n//2
while(n%3==0):
c+=1
n=n//3
while(n%5==0):
c+=1
n=n//5
return [c,n]
if(a==b):
print(0)
else:
g=gcd(a,b)
c=a//g
d=b//g
l1=burn(c)
l2=burn(d)
if(l1[1]==1 and l2[1]==1):
print(l1[0]+l2[0])
else:
print(-1)
``` | vfc_11310 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/371/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "15 20\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1024\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 390 | Solve the following coding problem using the programming language python:
A group of $n$ dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.
On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer's suit is the same as the color of the rightmost dancer's suit, the 2nd left is the same as 2nd right, and so on.
The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it's possible, what's the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.
-----Input-----
The first line contains three integers $n$, $a$, and $b$ ($1 \leq n \leq 20$, $1 \leq a, b \leq 100$) — the number of dancers, the cost of a white suit, and the cost of a black suit.
The next line contains $n$ numbers $c_i$, $i$-th of which denotes the color of the suit of the $i$-th dancer. Number $0$ denotes the white color, $1$ — the black color, and $2$ denotes that a suit for this dancer is still to be bought.
-----Output-----
If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.
-----Examples-----
Input
5 100 1
0 1 2 1 2
Output
101
Input
3 10 12
1 2 0
Output
-1
Input
3 12 1
0 1 0
Output
0
-----Note-----
In the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.
In the second sample, the leftmost dancer's suit already differs from the rightmost dancer's suit so there is no way to obtain the desired coloring.
In the third sample, all suits are already bought and their colors form a palindrome.
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("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
n , a , b = I()
l = I()
cost = 0
m = min(a,b)
for i in range(n//2):
if l[i] + l[n-i-1] == 1:
print(-1)
return
if l[i] == 2 and l[n - i - 1] == 2:
cost += 2*m
elif l[i] == 2 or l[n - i - 1] == 2:
if l[i] == 1 or l[n - i - 1] == 1:
cost += b
else:
cost += a
if n%2 and l[n//2] == 2:
cost += m
print(cost)
``` | vfc_11314 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1040/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 100 1\n0 1 2 1 2\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10 12\n1 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 12 1\n0 1 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1 9\n1 2 1 0 1 0 1 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 16 16\n1 1 2 2 0 2 1\n",
"output": "48\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 391 | Solve the following coding problem using the programming language python:
You are given a cube of size k × k × k, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face.
Your task is to paint each of k^3 unit cubes one of two colours (black or white), so that the following conditions must be satisfied: each white cube has exactly 2 neighbouring cubes of white color; each black cube has exactly 2 neighbouring cubes of black color.
-----Input-----
The first line contains integer k (1 ≤ k ≤ 100), which is size of the cube.
-----Output-----
Print -1 if there is no solution. Otherwise, print the required painting of the cube consequently by layers. Print a k × k matrix in the first k lines, showing how the first layer of the cube should be painted. In the following k lines print a k × k matrix — the way the second layer should be painted. And so on to the last k-th layer. Note that orientation of the cube in the space does not matter.
Mark a white unit cube with symbol "w" and a black one with "b". Use the format of output data, given in the test samples. You may print extra empty lines, they will be ignored.
-----Examples-----
Input
1
Output
-1
Input
2
Output
bb
ww
bb
ww
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
K = int(input())
print(("-1" if K & 1 else "".join(["wb\n"[2 if k == K else (min(j, k, K - 1 - j,
K - 1 - k) ^ i) & 1] for i in range(2) for j in range(K) for k in range(K +
1)]) * (K >> 1)))
``` | vfc_11318 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/323/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 392 | Solve the following coding problem using the programming language python:
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a^2 is a divisor of x. [Image]
Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.
-----Input-----
The first and only line of input contains one integer, n (1 ≤ n ≤ 10^12).
-----Output-----
Print the answer in one line.
-----Examples-----
Input
10
Output
10
Input
12
Output
6
-----Note-----
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2^2, so 12 is not lovely, while 6 is indeed lovely.
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 = 1
i = 2
while i * i <= n:
if n % i == 0:
ans *= i
while n % i == 0:
n //= i
i += 1
ans *= n
print(ans)
``` | vfc_11322 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/588/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 393 | Solve the following coding problem using the programming language python:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: There are no neighbors adjacent to anyone seated. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$).
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
-----Output-----
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
-----Examples-----
Input
3
101
Output
Yes
Input
4
1011
Output
No
Input
5
10001
Output
No
-----Note-----
In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three.
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 = '0'+input()+'0'
if '000' in a or '11' in a:print('No')
else:print('Yes')
``` | vfc_11326 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/982/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n101\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1011\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n10001\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 394 | Solve the following coding problem using the programming language python:
Bajtek, known for his unusual gifts, recently got an integer array $x_0, x_1, \ldots, x_{k-1}$.
Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website another array $a$ of length $n + 1$. As a formal description of $a$ says, $a_0 = 0$ and for all other $i$ ($1 \le i \le n$) $a_i = x_{(i-1)\bmod k} + a_{i-1}$, where $p \bmod q$ denotes the remainder of division $p$ by $q$.
For example, if the $x = [1, 2, 3]$ and $n = 5$, then: $a_0 = 0$, $a_1 = x_{0\bmod 3}+a_0=x_0+0=1$, $a_2 = x_{1\bmod 3}+a_1=x_1+1=3$, $a_3 = x_{2\bmod 3}+a_2=x_2+3=6$, $a_4 = x_{3\bmod 3}+a_3=x_0+6=7$, $a_5 = x_{4\bmod 3}+a_4=x_1+7=9$.
So, if the $x = [1, 2, 3]$ and $n = 5$, then $a = [0, 1, 3, 6, 7, 9]$.
Now the boy hopes that he will be able to restore $x$ from $a$! Knowing that $1 \le k \le n$, help him and find all possible values of $k$ — possible lengths of the lost array.
-----Input-----
The first line contains exactly one integer $n$ ($1 \le n \le 1000$) — the length of the array $a$, excluding the element $a_0$.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Note that $a_0$ is always $0$ and is not given in the input.
-----Output-----
The first line of the output should contain one integer $l$ denoting the number of correct lengths of the lost array.
The second line of the output should contain $l$ integers — possible lengths of the lost array in increasing order.
-----Examples-----
Input
5
1 2 3 4 5
Output
5
1 2 3 4 5
Input
5
1 3 5 6 8
Output
2
3 5
Input
3
1 5 3
Output
1
3
-----Note-----
In the first example, any $k$ is suitable, since $a$ is an arithmetic progression.
Possible arrays $x$: $[1]$ $[1, 1]$ $[1, 1, 1]$ $[1, 1, 1, 1]$ $[1, 1, 1, 1, 1]$
In the second example, Bajtek's array can have three or five elements.
Possible arrays $x$: $[1, 2, 2]$ $[1, 2, 2, 1, 2]$
For example, $k = 4$ is bad, since it leads to $6 + x_0 = 8$ and $0 + x_0 = 1$, which is an obvious contradiction.
In the third example, only $k = n$ is good.
Array $[1, 4, -2]$ satisfies the requirements.
Note that $x_i$ may be negative.
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()))
ans = []
for k in range(1, n + 1):
x = [0] * k
x[0] = a[0]
for i in range(1, k):
x[i] = a[i] - a[i - 1]
ok = True
for i in range(k, n):
if x[i % k] != a[i] - a[i - 1]:
ok = False
break
if ok:
ans.append(k)
print(len(ans))
print(*ans)
``` | vfc_11330 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1043/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "5\n1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 3 5 6 8\n",
"output": "2\n3 5 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 5 3\n",
"output": "1\n3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n",
"output": "1\n1 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 395 | Solve the following coding problem using the programming language python:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number i got a score of a_{i}. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
-----Input-----
The single line contains six integers a_1, ..., a_6 (0 ≤ a_{i} ≤ 1000) — scores of the participants
-----Output-----
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
-----Examples-----
Input
1 3 2 1 2 1
Output
YES
Input
1 1 1 1 1 99
Output
NO
-----Note-----
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = list(map(int, input().split()))
s = sum(a)
for i in range(6):
for j in range(i):
for k in range(j):
ss = a[i] + a[j] + a[k]
if ss == s - ss:
print('YES')
return
print('NO')
``` | vfc_11334 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/886/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3 2 1 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1 1 99\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 396 | Solve the following coding problem using the programming language python:
A positive integer is called a 2-3-integer, if it is equal to 2^{x}·3^{y} for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
-----Input-----
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·10^9).
-----Output-----
Print a single integer the number of 2-3-integers on the segment [l, r].
-----Examples-----
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
-----Note-----
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
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
for i in range(0,40):
for j in range(0,40):
if (2**i)*(3**j)>=a and (2**i)*(3**j)<=b:
ans+=1
print(ans)
``` | vfc_11338 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/926/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 200\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 397 | Solve the following coding problem using the programming language python:
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.
For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $n$ actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options:
the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by $1$; the second option is to put candies in the box. In this case, Alya will put $1$ more candy, than she put in the previous time.
Thus, if the box is empty, then it can only use the second option.
For example, one possible sequence of Alya's actions look as follows:
put one candy into the box; put two candies into the box; eat one candy from the box; eat one candy from the box; put three candies into the box; eat one candy from the box; put four candies into the box; eat one candy from the box; put five candies into the box;
This way she will perform $9$ actions, the number of candies at the end will be $11$, while Alya will eat $4$ candies in total.
You know the total number of actions $n$ and the number of candies at the end $k$. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given $n$ and $k$ the answer always exists.
Please note, that during an action of the first option, Alya takes out and eats exactly one candy.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 10^9$; $0 \le k \le 10^9$) — the total number of moves and the number of candies in the box at the end.
It's guaranteed, that for the given $n$ and $k$ the answer exists.
-----Output-----
Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data.
-----Examples-----
Input
1 1
Output
0
Input
9 11
Output
4
Input
5 0
Output
3
Input
3 2
Output
1
-----Note-----
In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate $0$ candies.
In the second example the possible sequence of Alya's actions looks as follows: put $1$ candy, put $2$ candies, eat a candy, eat a candy, put $3$ candies, eat a candy, put $4$ candies, eat a candy, put $5$ candies.
This way, she will make exactly $n=9$ actions and in the end the box will contain $1+2-1-1+3-1+4-1+5=11$ candies. The answer is $4$, since she ate $4$ candies in total.
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())
low=1
high=n
import sys
while low<=high:
mid=(low+high)//2
if mid*(mid+1)//2 -(n-mid)>k:
high=mid-1
elif mid*(mid+1)//2-(n-mid)==k:
print(n-mid)
return
else :
low=mid+1
``` | vfc_11342 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1195/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 11\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7\n",
"output": "3",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 398 | Solve the following coding problem using the programming language python:
Mahmoud has n line segments, the i-th of them has length a_{i}. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
-----Input-----
The first line contains single integer n (3 ≤ n ≤ 10^5) — the number of line segments Mahmoud has.
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the lengths of line segments Mahmoud has.
-----Output-----
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
-----Examples-----
Input
5
1 5 3 2 4
Output
YES
Input
3
4 1 2
Output
NO
-----Note-----
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
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()))
a.sort()
ok = False
for i in range(n - 2):
if a[i] + a[i + 1] > a[i + 2]:
ok = True
print(("NO", "YES")[ok])
``` | vfc_11346 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/766/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 5 3 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 399 | Solve the following coding problem using the programming language python:
Imp likes his plush toy a lot.
[Image]
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
-----Input-----
The only line contains two integers x and y (0 ≤ x, y ≤ 10^9) — the number of copies and the number of original toys Imp wants to get (including the initial one).
-----Output-----
Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower).
-----Examples-----
Input
6 3
Output
Yes
Input
4 2
Output
No
Input
1000 1001
Output
Yes
-----Note-----
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x, y = map(int, input().split())
if y == 0:
print('No')
return
else:
y -= 1
if y == 0 and x:
print('No')
return
if y > x or (x - y) & 1:
print('No')
else:
print('Yes')
``` | vfc_11350 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/922/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 1001\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 400 | Solve the following coding problem using the programming language python:
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer a_{i} from 0 to 100. The higher the number a_{i} is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of $\lfloor \frac{a_{i}}{10} \rfloor$ for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a_4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
-----Input-----
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 10^5, 0 ≤ k ≤ 10^7) — the number of skills of the character and the number of units of improvements at Petya's disposal.
The second line of the input contains a sequence of n integers a_{i} (0 ≤ a_{i} ≤ 100), where a_{i} characterizes the level of the i-th skill of the character.
-----Output-----
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
-----Examples-----
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
-----Note-----
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is $\lfloor \frac{20}{10} \rfloor + \lfloor \frac{19}{10} \rfloor + \lfloor \frac{20}{10} \rfloor = 2 + 1 + 2 = 5$.
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to $\lfloor \frac{100}{10} \rfloor + \lfloor \frac{100}{10} \rfloor = 10 + 10 = 20$.
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 solve():
n,k, = rv()
a, = rl(1)
res = 0
count = [0] * 10
for i in range(n):
if a[i] < 100:
count[10 - (a[i] % 10) - 1] += 1
res += a[i] // 10
for i in range(10):
while count[i] > 0 and k >= i + 1:
res += 1
count[i] -= 1
k -= i + 1
already = res * 10
possible = n * 100
diff = possible - already
if diff > 0:
actual = min(diff, k)
res += actual // 10
print(res)
def prt(l): return print(' '.join(map(str, l)))
def rs(): return map(str, input().split())
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
``` | vfc_11354 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/581/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n7 9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 8\n17 15 19\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 402 | Solve the following coding problem using the programming language python:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
-----Input-----
The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
-----Output-----
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
-----Examples-----
Input
3 222
Output
2
Input
4 190
Output
4
Input
7 1
Output
7
-----Note-----
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Good Bye 2016 Contest Problem A
Author : chaotic_iak
Language: Python 3.5.2
"""
################################################### SOLUTION
def main():
n,k = read()
avail = 240-k
i = 1
while i <= n and avail >= 5*i:
avail -= 5*i
i += 1
print(i-1)
#################################################### HELPERS
def read(callback=int):
return list(map(callback, input().strip().split()))
def write(value, end="\n"):
if value is None: return
try:
value = " ".join(map(str, value))
except:
pass
print(value, end=end)
write(main())
``` | vfc_11362 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/750/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 222\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 190\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 135\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 136\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 403 | Solve the following coding problem using the programming language python:
На тренировку по подготовке к соревнованиям по программированию пришли n команд. Тренер для каждой команды подобрал тренировку, комплект задач для i-й команды занимает a_{i} страниц. В распоряжении тренера есть x листов бумаги, у которых обе стороны чистые, и y листов, у которых только одна сторона чистая. При печати условия на листе первого типа можно напечатать две страницы из условий задач, а при печати на листе второго типа — только одну. Конечно, на листе нельзя печатать условия из двух разных комплектов задач. Обратите внимание, что при использовании листов, у которых обе стороны чистые, не обязательно печатать условие на обеих сторонах, одна из них может остаться чистой.
Вам предстоит определить максимальное количество команд, которым тренер сможет напечатать комплекты задач целиком.
-----Входные данные-----
В первой строке входных данных следуют три целых числа n, x и y (1 ≤ n ≤ 200 000, 0 ≤ x, y ≤ 10^9) — количество команд, количество листов бумаги с двумя чистыми сторонами и количество листов бумаги с одной чистой стороной.
Во второй строке входных данных следует последовательность из n целых чисел a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), где i-е число равно количеству страниц в комплекте задач для i-й команды.
-----Выходные данные-----
Выведите единственное целое число — максимальное количество команд, которым тренер сможет напечатать комплекты задач целиком.
-----Примеры-----
Входные данные
2 3 5
4 6
Выходные данные
2
Входные данные
2 3 5
4 7
Выходные данные
2
Входные данные
6 3 5
12 11 12 11 12 11
Выходные данные
1
-----Примечание-----
В первом тестовом примере можно напечатать оба комплекта задач. Один из возможных ответов — напечатать весь первый комплект задач на листах с одной чистой стороной (после этого останется 3 листа с двумя чистыми сторонами и 1 лист с одной чистой стороной), а второй комплект напечатать на трех листах с двумя чистыми сторонами.
Во втором тестовом примере можно напечатать оба комплекта задач. Один из возможных ответов — напечатать первый комплект задач на двух листах с двумя чистыми сторонами (после этого останется 1 лист с двумя чистыми сторонами и 5 листов с одной чистой стороной), а второй комплект напечатать на одном листе с двумя чистыми сторонами и на пяти листах с одной чистой стороной. Таким образом, тренер использует все листы для печати.
В третьем тестовом примере можно напечатать только один комплект задач (любой из трёх 11-страничных). Для печати 11-страничного комплекта задач будет израсходована вся бумага.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys,math
n,x,y=list(map(int,input().split()))
z=list(map(int,input().split()))
z.sort()
ans=0
for i in range(n):
if z[i]%2==0:
if x>=z[i]//2:
x-=z[i]//2
ans+=1
else:
z[i]-=x*2
x=0
y-=z[i]
if y>=0:
ans+=1
else:
break
else:
if x>=z[i]//2 and y>=1:
x-=z[i]//2
ans+=1
y-=1
elif x>=z[i]//2+1:
x-=z[i]//2+1
ans+=1
else:
z[i]-=x*2
x=0
y-=z[i]
if y>=0:
ans+=1
else:
break
print(ans)
``` | vfc_11366 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/649/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 5\n4 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 5\n4 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3 5\n12 11 12 11 12 11\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 404 | Solve the following coding problem using the programming language python:
Ivan has number $b$. He is sorting through the numbers $a$ from $1$ to $10^{18}$, and for every $a$ writes $\frac{[a, \,\, b]}{a}$ on blackboard. Here $[a, \,\, b]$ stands for least common multiple of $a$ and $b$. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.
-----Input-----
The only line contains one integer — $b$ $(1 \le b \le 10^{10})$.
-----Output-----
Print one number — answer for the problem.
-----Examples-----
Input
1
Output
1
Input
2
Output
2
-----Note-----
In the first example $[a, \,\, 1] = a$, therefore $\frac{[a, \,\, b]}{a}$ is always equal to $1$.
In the second example $[a, \,\, 2]$ can be equal to $a$ or $2 \cdot a$ depending on parity of $a$. $\frac{[a, \,\, b]}{a}$ can be equal to $1$ and $2$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#JMD
#Nagendra Jha-4096
import sys
import math
#import fractions
#import numpy
###File Operations###
fileoperation=0
if(fileoperation):
orig_stdout = sys.stdout
orig_stdin = sys.stdin
inputfile = open('W:/Competitive Programming/input.txt', 'r')
outputfile = open('W:/Competitive Programming/output.txt', 'w')
sys.stdin = inputfile
sys.stdout = outputfile
###Defines...###
mod=1000000007
###FUF's...###
def nospace(l):
ans=''.join(str(i) for i in l)
return ans
ans=[]
def printDivisors(n) :
# Note that this loop runs till square root
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n / i == i) :
ans.append(i)
else :
# Otherwise print both
ans.append(i)
ans.append(n//i)
i = i + 1
##### Main ####
t=1
for tt in range(t):
n=int(input())
printDivisors(n)
s=set(ans)
print(len(s))
#a=list(map(int,sys.stdin.readline().split(' ')))
#n,k,s= map(int, sys.stdin.readline().split(' '))
#####File Operations#####
if(fileoperation):
sys.stdout = orig_stdout
sys.stdin = orig_stdin
inputfile.close()
outputfile.close()
``` | vfc_11370 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1068/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "433494437\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000000000\n",
"output": "121",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "169\n",
"output": "3",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 405 | Solve the following coding problem using the programming language python:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.
Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
-----Output-----
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
-----Examples-----
Input
4
<<><
Output
2
Input
5
>>>>>
Output
5
Input
4
>><<
Output
0
-----Note-----
In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field.
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()
l = 0
ans = 0
while l < len(s) and s[l] == '<':
ans += 1
l += 1
r = n - 1
while r >= 0 and s[r] == '>':
ans += 1
r -= 1
print(ans)
``` | vfc_11374 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/725/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n<<><\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n>>>>>\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n>><<\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 406 | Solve the following coding problem using the programming language python:
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length l_{i}.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths a_1, a_2, a_3 and a_4 can make a rectangle if the following properties are observed: a_1 ≤ a_2 ≤ a_3 ≤ a_4 a_1 = a_2 a_3 = a_4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 10^5) — the number of the available sticks.
The second line of the input contains n positive integers l_{i} (2 ≤ l_{i} ≤ 10^6) — the lengths of the sticks.
-----Output-----
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
-----Examples-----
Input
4
2 4 4 2
Output
8
Input
4
2 2 3 5
Output
0
Input
4
100003 100004 100005 100006
Output
10000800015
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
arr = [0] * (10 ** 6 + 1)
n = int(input())
for i in input().split():
arr[int(i)] += 1
i = 10 ** 6
j = i
k = i
c = 0
while j > 0:
if arr[j] % 2 == 1 and (arr[j] > 1 or c == 0):
arr[j - 1] += 1
c = 1
else:
c = 0
j -= 1
r = 0
while i > 0 and k > 0:
if arr[i] < 2:
if i == k:
k -= 1
i -= 1
elif i == k and arr[i] < 4:
k -= 1
elif arr[k] < 2:
k -= 1
else:
r += i * k
arr[i] -= 2
arr[k] -= 2
print(r)
``` | vfc_11378 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/525/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 4 4 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 2 3 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n100003 100004 100005 100006\n",
"output": "10000800015\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n5 3 3 3 3 4 4 4\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n123 124 123 124 2 2 2 2 9 9\n",
"output": "15270\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 407 | Solve the following coding problem using the programming language python:
Petya has n positive integers a_1, a_2, ..., a_{n}.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.
Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of Petya's numbers.
Each of the following lines contains non-empty string s_{i} consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.
-----Output-----
Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.
-----Examples-----
Input
3
ab
de
aj
Output
47
Input
5
abcdef
ghij
bdef
accbd
g
Output
136542
Input
3
aa
jj
aa
Output
44
-----Note-----
In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.
In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3].
In the second example the numbers after the restoration can look like: [11, 22, 11].
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
'''input
3
aa
jj
aa
'''
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
n = int(input())
d = {}
pos = {}
for _ in range(n):
s = list(input())
s = s[::-1]
for i in range(len(s)):
try:
d[s[i]] += 10**i
except:
d[s[i]] = 10**i
pos[s[i]] = True
if i == len(s)-1:
pos[s[i]] = False
a = []
b = []
for i in d:
a.append(d[i])
if pos[i]:
b.append(d[i])
if len(b):a.remove(max(b))
a.sort(reverse = True)
# print(a)
ans = 0
for i in range(len(a)):
ans += (i+1)*a[i]
print(ans)
``` | vfc_11382 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/910/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nab\nde\naj\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nabcdef\nghij\nbdef\naccbd\ng\n",
"output": "136542\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\naa\njj\naa\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\na\nb\nc\nd\nf\ng\nh\ni\nj\n",
"output": "45\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 408 | Solve the following coding problem using the programming language python:
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants.
A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.
However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.
As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.
There are n experienced members and m newbies on the training session. Can you calculate what maximum number of teams can be formed?
-----Input-----
The first line contains two integers n and m (0 ≤ n, m ≤ 5·10^5) — the number of experienced participants and newbies that are present at the training session.
-----Output-----
Print the maximum number of teams that can be formed.
-----Examples-----
Input
2 6
Output
2
Input
4 5
Output
3
-----Note-----
Let's represent the experienced players as XP and newbies as NB.
In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).
In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).
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(' ')))
print(min([a, b, (a+b)//3]))
``` | vfc_11386 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/519/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits