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 | 409 | Solve the following coding problem using the programming language python:
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
-----Input-----
The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters.
-----Output-----
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
-----Examples-----
Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO
-----Note-----
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = []
b = []
x = input()
for i in range(len(x)-1):
if x[i]+x[i+1] == 'AB':
a.append(i)
elif x[i]+x[i+1] == 'BA':
b.append(i)
if a == [] or b == []:
print("NO")
quit()
if abs(min(a)-max(b))>1 or abs(max(a)-min(b))>1:
print("YES")
quit()
print("NO")
``` | vfc_11390 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/550/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ABA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BACFAB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "AXBYBXA\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 410 | Solve the following coding problem using the programming language python:
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.
Soon, monsters became hungry and began to eat each other.
One monster can eat other monster if its weight is strictly greater than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster A eats the monster B, the weight of the monster A increases by the weight of the eaten monster B. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were n monsters in the queue, the i-th of which had weight a_{i}.
For example, if weights are [1, 2, 2, 2, 1, 2] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are: the first monster can't eat the second monster because a_1 = 1 is not greater than a_2 = 2; the second monster can't eat the third monster because a_2 = 2 is not greater than a_3 = 2; the second monster can't eat the fifth monster because they are not neighbors; the second monster can eat the first monster, the queue will be transformed to [3, 2, 2, 1, 2].
After some time, someone said a good joke and all monsters recovered. At that moment there were k (k ≤ n) monsters in the queue, the j-th of which had weight b_{j}. Both sequences (a and b) contain the weights of the monsters in the order from the first to the last.
You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn't make any appointments while monsters were eating each other.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue.
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) — the initial weights of the monsters.
The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke.
The fourth line contains k integers b_1, b_2, ..., b_{k} (1 ≤ b_{j} ≤ 5·10^8) — the weights of the monsters after the joke.
Monsters are listed in the order from the beginning of the queue to the end.
-----Output-----
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line.
Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, separated by space, the symbol 'L' if the monster which stays the x-th in the queue eats the monster in front of him, or 'R' if the monster which stays the x-th in the queue eats the monster behind him. After each eating the queue is enumerated again.
When one monster eats another the queue decreases. If there are several answers, print any of them.
-----Examples-----
Input
6
1 2 2 2 1 2
2
5 5
Output
YES
2 L
1 R
4 L
3 L
Input
5
1 2 3 4 5
1
15
Output
YES
5 L
4 L
3 L
2 L
Input
5
1 1 1 3 3
3
2 1 6
Output
NO
-----Note-----
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue: the second monster eats the monster to the left (i.e. the first monster), queue becomes [3, 2, 2, 1, 2]; the first monster (note, it was the second on the previous step) eats the monster to the right (i.e. the second monster), queue becomes [5, 2, 1, 2]; the fourth monster eats the mosnter to the left (i.e. the third monster), queue becomes [5, 2, 3]; the finally, the third monster eats the monster to the left (i.e. the second monster), queue becomes [5, 5].
Note that for each step the output contains numbers of the monsters in their current order in the queue.
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 = [0,]
b = [0,]
ans1 = []
ans2 = []
n = int(input())
s = input()
nums = s.split()
for i in range(0, n):
a.append(int(nums[i]))
k = int(input())
s = input()
nums = s.split()
for i in range(0, k):
b.append(int(nums[i]))
def f(x, y, z):
#print(x,y,z)
pos1 = x
pos2 = x
if x == y:
return 1
for i in range(x, y + 1):
if a[i] > a[pos1]:
pos1 = i
if a[i] >= a[pos2]:
pos2 = i
for i in range(x, y):
if a[i] == a[pos2]:
if a[i + 1] < a[i]:
pos2 = i
for i in range(x + 1, y + 1):
if a[i] == a[pos1]:
if a[i - 1] < a[i]:
pos1 = i
if pos1 != x or a[pos1] > a[pos1 + 1]:
for i in range(0, pos1 - x):
ans1.append(pos1 - x + z - i)
ans2.append('L')
for i in range(0, y - pos1):
ans1.append(z)
ans2.append('R')
elif pos2 != y or a[pos2] > a[pos2 - 1]:
for i in range(0, y - pos2):
ans1.append(pos2 - x + z)
ans2.append('R')
for i in range(0, pos2 - x):
ans1.append(pos2 - x + z - i)
ans2.append('L')
else:
return 0
return 1
lasti = 0
j = 1
sum = 0
for i in range(1, n+1):
if j > k:
print('NO')
return
sum += a[i]
#print(i, sum, j)
if sum > b[j]:
print('NO')
return
if sum == b[j]:
if f(lasti + 1, i, j) == 0:
print('NO')
return
lasti = i
j += 1
sum = 0
if j <= k:
print('NO')
return
print('YES')
for i in range(0, len(ans1)):
print(ans1[i], ans2[i])
``` | vfc_11394 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/733/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 2 2 2 1 2\n2\n5 5\n",
"output": "YES\n2 L\n1 R\n4 L\n3 L\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n1\n15\n",
"output": "YES\n5 L\n4 L\n3 L\n2 L\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 3 3\n3\n2 1 6\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 1 2\n3\n1 1 4\n",
"output": "YES\n5 L\n4 L\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n4\n1 1 2 1\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 1 2 2 1 2\n2\n5 5\n",
"output": "YES\n3 L\n2 L\n4 L\n3 L\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 411 | Solve the following coding problem using the programming language python:
The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Since she knows how reckless her pilots are, she wants to be sure that any two (straight) paths – from a base to its assigned spaceship – do not intersect in the galaxy plane (that is, in 2D), and so there is no risk of collision.
-----Input-----
The first line contains two space-separated integers R, B(1 ≤ R, B ≤ 10). For 1 ≤ i ≤ R, the i + 1-th line contains two space-separated integers x_{i} and y_{i} (|x_{i}|, |y_{i}| ≤ 10000) denoting the coordinates of the i-th Rebel spaceship. The following B lines have the same format, denoting the position of bases. It is guaranteed that no two points coincide and that no three points are on the same line.
-----Output-----
If it is possible to connect Rebel spaceships and bases so as satisfy the constraint, output Yes, otherwise output No (without quote).
-----Examples-----
Input
3 3
0 0
2 0
3 1
-2 1
0 3
2 2
Output
Yes
Input
2 1
1 0
2 2
3 1
Output
No
-----Note-----
For the first example, one possible way is to connect the Rebels and bases in order.
For the second example, there is no perfect matching between Rebels and bases.
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()))
if a==b: print("Yes")
else: print("No")
``` | vfc_11398 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/958/E1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 0\n2 2\n3 1\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 412 | Solve the following coding problem using the programming language python:
Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2.
По заданной последовательности целых положительных чисел a_1, a_2, ..., a_{n} требуется найти r — максимальную степень числа 2, на которую делится хотя бы одно из чисел последовательности. Кроме того, требуется вывести количество чисел a_{i}, которые делятся на r.
-----Входные данные-----
В первой строке записано целое число n (1 ≤ n ≤ 100) — длина последовательности a.
Во второй строке записана последовательность целых чисел a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
-----Выходные данные-----
Выведите два числа:
r — максимальную степень двойки, на которую делится хотя бы одно из чисел заданной последовательности, количество элементов последовательности, которые делятся на r.
-----Примеры-----
Входные данные
5
80 7 16 4 48
Выходные данные
16 3
Входные данные
4
21 5 3 33
Выходные данные
1 4
-----Примечание-----
В первом тестовом примере максимальная степень двойки, на которую делится хотя бы одно число, равна 16 = 2^4, на неё делятся числа 80, 16 и 48.
Во втором тестовом примере все четыре числа нечётные, поэтому делятся только на 1 = 2^0. Это и будет максимальной степенью двойки для данного примера.
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 = list(map(int, input().split()))
max1 = 1
for i in l:
k = 1
x = i
while x % 2 == 0:
k *= 2
x //= 2
max1 = max(max1, k)
c = 0
for i in l:
if i % max1 == 0:
c += 1
print(max1, c)
``` | vfc_11402 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/649/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n80 7 16 4 48\n",
"output": "16 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n21 5 3 33\n",
"output": "1 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n8 112 52 86 93 102 24 24 100 826791168\n",
"output": "256 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n458297759 18 104\n",
"output": "8 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n12 14 40 8 74 104 11\n",
"output": "8 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n35 16 664311776 46 48 52 63 82 84 80 23\n",
"output": "32 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 413 | Solve the following coding problem using the programming language python:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
-----Input-----
The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 10^4), separated by a space .
-----Output-----
Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.
-----Examples-----
Input
4 6
Output
2
Input
10 1
Output
9
-----Note-----
In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n, m = map(int, input().split())
res, delta = 0, 1
while n < m:
res += 1
n *= 2
delta *= 2
while n > m:
while n - delta >= m:
res += 1
n -= delta
delta //= 2
print(res)
def __starting_point():
main()
__starting_point()
``` | vfc_11406 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/520/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 414 | Solve the following coding problem using the programming language python:
As the name of the task implies, you are asked to do some work with segments and trees.
Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices.
You are given $n$ segments $[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$, $l_i < r_i$ for every $i$. It is guaranteed that all segments' endpoints are integers, and all endpoints are unique — there is no pair of segments such that they start in the same point, end in the same point or one starts in the same point the other one ends.
Let's generate a graph with $n$ vertices from these segments. Vertices $v$ and $u$ are connected by an edge if and only if segments $[l_v, r_v]$ and $[l_u, r_u]$ intersect and neither of it lies fully inside the other one.
For example, pairs $([1, 3], [2, 4])$ and $([5, 10], [3, 7])$ will induce the edges but pairs $([1, 2], [3, 4])$ and $([5, 7], [3, 10])$ will not.
Determine if the resulting graph is a tree or not.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 5 \cdot 10^5$) — the number of segments.
The $i$-th of the next $n$ lines contain the description of the $i$-th segment — two integers $l_i$ and $r_i$ ($1 \le l_i < r_i \le 2n$).
It is guaranteed that all segments borders are pairwise distinct.
-----Output-----
Print "YES" if the resulting graph is a tree and "NO" otherwise.
-----Examples-----
Input
6
9 12
2 11
1 3
6 10
5 7
4 8
Output
YES
Input
5
1 3
2 4
5 9
6 8
7 10
Output
NO
Input
5
5 8
3 6
2 9
7 10
1 4
Output
NO
-----Note-----
The graph corresponding to the first example:
[Image]
The graph corresponding to the second example:
[Image]
The graph corresponding to the third example:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
class BIT_RSQ():
def __init__(self, n):
self.n = n
self.data = [0]*(n+2)
def add(self, i, v):
while i <= self.n:
self.data[i] += v
i += i & -i
def sum(self, i):
ret = 0
while(i > 0):
ret += self.data[i]
i -= i & -i
return ret
def query(self, l, r):
return self.sum(r) - self.sum(l-1)
def lowerBound(self, w):
if w <= 0: return 0
x, k = 0, 2**self.n.bit_length()
while k:
if x+k <= self.n and self.data[x+k] < w:
w -= self.data[x+k]
x += k
k >>= 1
return x + 1
n = int(input())
edges = [0]*(2*n)
c = [0]*(2*n)
BIT = BIT_RSQ(2*n)
uf = [-1]*n
def root(x):
if uf[x] < 0:
return x
uf[x] = root(uf[x])
return uf[x]
def unite(x,y):
rx, ry = root(x), root(y)
if rx == ry:
return False
if uf[rx] > uf[ry]:
rx, ry = ry, rx
uf[rx] += uf[ry]
uf[ry] = rx
return True
for i in range(n):
a,b = list(map(int, input().split()))
a,b = a-1,b-1
c[a] = c[b] = i
edges[a] = b
edges[b] = b
for i in reversed(list(range(2*n))):
j = edges[i]
if j == i:
BIT.add(j+1, 1)
else:
BIT.add(j+1, -1)
cnt = BIT.sum(j+1)
while cnt:
k = BIT.lowerBound(cnt)
if not unite(c[j], c[k-1]):
print("NO")
return
cnt -= 1
if sum(i<0 for i in uf) == 1:
print("YES")
else:
print("NO")
``` | vfc_11410 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1278/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n9 12\n2 11\n1 3\n6 10\n5 7\n4 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 3\n2 4\n5 9\n6 8\n7 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 8\n3 6\n2 9\n7 10\n1 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n20 22\n9 11\n32 36\n8 12\n14 16\n4 6\n28 30\n29 37\n15 18\n33 35\n27 31\n21 25\n2 7\n19 23\n10 39\n34 40\n5 13\n24 38\n17 26\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 415 | Solve the following coding problem using the programming language python:
We get more and more news about DDoS-attacks of popular websites.
Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds in this time segment.
Arseny knows statistics on the number of requests per second since the server is booted. He knows the sequence $r_1, r_2, \dots, r_n$, where $r_i$ — the number of requests in the $i$-th second after boot.
Determine the length of the longest continuous period of time, which Arseny considers to be a DDoS-attack. A seeking time period should not go beyond the boundaries of the segment $[1, n]$.
-----Input-----
The first line contains $n$ ($1 \le n \le 5000$) — number of seconds since server has been booted. The second line contains sequence of integers $r_1, r_2, \dots, r_n$ ($0 \le r_i \le 5000$), $r_i$ — number of requests in the $i$-th second.
-----Output-----
Print the only integer number — the length of the longest time period which is considered to be a DDoS-attack by Arseny. If it doesn't exist print 0.
-----Examples-----
Input
5
100 200 1 1 1
Output
3
Input
5
1 2 3 4 5
Output
0
Input
2
101 99
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 prog():
n = int(input())
inp = list(map(int,input().split()))
ans = 0
for i in range(len(inp)):
x,y = 0 ,0
for j in range(i,len(inp)):
x+=inp[j]
y+=100
if(x>y):
ans = max(ans,(j-i)+1)
print(ans)
prog()
``` | vfc_11414 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1057/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n100 200 1 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n101 99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n41\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 416 | Solve the following coding problem using the programming language python:
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not.
Stepan's dissatisfaction is the maximum number of consecutive series that Stepan did not watch.
Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to k.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ n) — the number of episodes in the series and the dissatisfaction which should be checked.
The second line contains the sequence which consists of n symbols "Y", "N" and "?". If the i-th symbol equals "Y", Stepan remembers that he has watched the episode number i. If the i-th symbol equals "N", Stepan remembers that he hasn't watched the epizode number i. If the i-th symbol equals "?", Stepan doesn't exactly remember if he has watched the episode number i or not.
-----Output-----
If Stepan's dissatisfaction can be exactly equal to k, then print "YES" (without qoutes). Otherwise print "NO" (without qoutes).
-----Examples-----
Input
5 2
NYNNY
Output
YES
Input
6 1
????NN
Output
NO
-----Note-----
In the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row — the episode number 3 and the episode number 4. The answer is "YES", because k = 2.
In the second test k = 1, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row — number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
n, k = list(map(int, input().split(' ')))
s = input()
def max_streak(s):
result = 0
for i in range(len(s)):
j = i
while j < len(s) and s[j] == 'N':
j += 1
result = max(result, j - i)
return result
for i in range(n - k + 1):
cur = list(s)
for j in range(i, i + k):
if cur[j] == '?':
cur[j] = 'N'
for j in range(i):
if cur[j] == '?':
cur[j] = 'Y'
for j in range(i + k, n):
if cur[j] == '?':
cur[j] = 'Y'
if max_streak(cur) == k:
print('YES')
return
print('NO')
``` | vfc_11418 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/774/J",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\nNYNNY\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 1\n????NN\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 8\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 418 | Solve the following coding problem using the programming language python:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest .
The next n lines describe participants results: the i-th of them consists of a participant handle name_{i} and two integers before_{i} and after_{i} ( - 4000 ≤ before_{i}, after_{i} ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
-----Output-----
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
-----Examples-----
Input
3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749
Output
YES
Input
3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450
Output
NO
-----Note-----
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
read = lambda: map(int, input().split())
n = int(input())
for i in range(n):
name, x, y = input().split()
x, y = int(x), int(y)
if x >= 2400 and y > x:
print('YES')
return
print('NO')
``` | vfc_11426 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/681/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 419 | Solve the following coding problem using the programming language python:
In the city of Saint Petersburg, a day lasts for $2^{100}$ minutes. From the main station of Saint Petersburg, a train departs after $1$ minute, $4$ minutes, $16$ minutes, and so on; in other words, the train departs at time $4^k$ for each integer $k \geq 0$. Team BowWow has arrived at the station at the time $s$ and it is trying to count how many trains have they missed; in other words, the number of trains that have departed strictly before time $s$. For example if $s = 20$, then they missed trains which have departed at $1$, $4$ and $16$. As you are the only one who knows the time, help them!
Note that the number $s$ will be given you in a binary representation without leading zeroes.
-----Input-----
The first line contains a single binary number $s$ ($0 \leq s < 2^{100}$) without leading zeroes.
-----Output-----
Output a single number — the number of trains which have departed strictly before the time $s$.
-----Examples-----
Input
100000000
Output
4
Input
101
Output
2
Input
10100
Output
3
-----Note-----
In the first example $100000000_2 = 256_{10}$, missed trains have departed at $1$, $4$, $16$ and $64$.
In the second example $101_2 = 5_{10}$, trains have departed at $1$ and $4$.
The third example is explained in the statements.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = int(input(), 2)
t, ans = 1, 0
while t < s:
ans += 1
t *= 4
print(ans)
``` | vfc_11430 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1204/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100000000\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10100\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 422 | Solve the following coding problem using the programming language python:
Vova has taken his summer practice this year and now he should write a report on how it went.
Vova has already drawn all the tables and wrote down all the formulas. Moreover, he has already decided that the report will consist of exactly $n$ pages and the $i$-th page will include $x_i$ tables and $y_i$ formulas. The pages are numbered from $1$ to $n$.
Vova fills the pages one after another, he can't go filling page $i + 1$ before finishing page $i$ and he can't skip pages.
However, if he draws strictly more than $k$ tables in a row or writes strictly more than $k$ formulas in a row then he will get bored. Vova wants to rearrange tables and formulas in each page in such a way that he doesn't get bored in the process. Vova can't move some table or some formula to another page.
Note that the count doesn't reset on the start of the new page. For example, if the page ends with $3$ tables and the next page starts with $5$ tables, then it's counted as $8$ tables in a row.
Help Vova to determine if he can rearrange tables and formulas on each page in such a way that there is no more than $k$ tables in a row and no more than $k$ formulas in a row.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 3 \cdot 10^5$, $1 \le k \le 10^6$).
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^6$) — the number of tables on the $i$-th page.
The third line contains $n$ integers $y_1, y_2, \dots, y_n$ ($1 \le y_i \le 10^6$) — the number of formulas on the $i$-th page.
-----Output-----
Print "YES" if Vova can rearrange tables and formulas on each page in such a way that there is no more than $k$ tables in a row and no more than $k$ formulas in a row.
Otherwise print "NO".
-----Examples-----
Input
2 2
5 5
2 2
Output
YES
Input
2 2
5 6
2 2
Output
NO
Input
4 1
4 1 10 1
3 2 10 1
Output
YES
-----Note-----
In the first example the only option to rearrange everything is the following (let table be 'T' and formula be 'F'): page $1$: "TTFTTFT" page $2$: "TFTTFTT"
That way all blocks of tables have length $2$.
In the second example there is no way to fit everything in such a way that there are no more than $2$ tables in a row and $2$ formulas in a row.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def max(a, b):
if a > b:
return a
else:
return b
n, k = map(int, input().split())
x = [int(t) for t in input().split()]
y = [int(t) for t in input().split()]
f, s = 0, 0
for i in range(n):
f = max(0, x[i] + f - k * y[i])
s = max(0, y[i] + s - k * x[i])
if f > k or s > k:
print('NO')
return
print('YES')
``` | vfc_11442 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1076/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n5 5\n2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n5 6\n2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n4 1 10 1\n3 2 10 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "53 3\n2 3 1 2 2 6 1 5 6 1 5 3 1 1 6 4 3 2 4 1 1 4 4 3 5 6 1 2 2 1 2 2 2 5 4 2 1 4 2 5 3 1 3 6 6 4 4 5 2 1 2 2 1\n5 2 6 3 5 5 1 1 2 4 6 1 4 2 4 1 4 4 5 3 6 4 6 5 6 3 4 4 3 1 1 5 5 1 1 2 4 4 3 1 2 2 3 2 3 2 2 4 5 1 5 2 6\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 423 | Solve the following coding problem using the programming language python:
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial P(x) = a_{n}x^{n} + a_{n} - 1x^{n} - 1 + ... + a_1x + a_0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient a_{j} that stay near x^{j} is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near x^{i} - 1 is yet undefined or the integer value a_{i}, if the coefficient is already known ( - 10 000 ≤ a_{i} ≤ 10 000). Each of integers a_{i} (and even a_{n}) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
-----Output-----
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
-----Examples-----
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
-----Note-----
In the first sample, computer set a_0 to - 1 on the first move, so if human can set coefficient a_1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
p=1048583
q=1048589
modd=p*q*p*q
n,k=tuple(map(int,input().split()))
a=[0]
wenhao=0
gai=0
for i in range(n+1):
m=input()
if m[0]=='?':
a.append('?')
wenhao+=1
else:
a.append(int(m))
gai+=1
if k==0:
if (a[1]=='?' and gai&1==1) or a[1]==0:
print('Yes')
else:
print('No')
else:
if wenhao!=0:
if n&1==1:
print('Yes')
else:
print('No')
else:
m=a[n+1]
nn=a[n]
for i in range(n,0,-1):
m,nn=(nn+k*m)%modd,a[i-1]
if m==0:
print('Yes')
else:
print('No')
``` | vfc_11446 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/676/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n-1\n?\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 424 | Solve the following coding problem using the programming language python:
Alice and Bob begin their day with a quick game. They first choose a starting number X_0 ≥ 3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime p < X_{i} - 1 and then finds the minimum X_{i} ≥ X_{i} - 1 such that p divides X_{i}. Note that if the selected prime p already divides X_{i} - 1, then the number does not change.
Eve has witnessed the state of the game after two turns. Given X_2, help her determine what is the smallest possible starting number X_0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
-----Input-----
The input contains a single integer X_2 (4 ≤ X_2 ≤ 10^6). It is guaranteed that the integer X_2 is composite, that is, is not prime.
-----Output-----
Output a single integer — the minimum possible X_0.
-----Examples-----
Input
14
Output
6
Input
20
Output
15
Input
8192
Output
8191
-----Note-----
In the first test, the smallest possible starting number is X_0 = 6. One possible course of the game is as follows: Alice picks prime 5 and announces X_1 = 10 Bob picks prime 7 and announces X_2 = 14.
In the second case, let X_0 = 15. Alice picks prime 2 and announces X_1 = 16 Bob picks prime 5 and announces X_2 = 20.
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 floor, sqrt
import bisect
import math
def rwh_primes2(n):
# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
""" Input n>=6, Returns a list of primes, 2 <= p < n """
correction = (n%6>1)
n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
sieve = [True] * (n//3)
sieve[0] = False
for i in range(int(n**0.5)//3+1):
if sieve[i]:
k=3*i+1|1
sieve[ ((k*k)//3) ::2*k]=[False]*((n//6-(k*k)//6-1)//k+1)
sieve[(k*k+4*k-2*k*(i&1))//3::2*k]=[False]*((n//6-(k*k+4*k-2*k*(i&1))//6-1)//k+1)
return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]
k = int(input())
primes = rwh_primes2(k)
a = 1
p2 = 2
for i in primes[::-1]:
if k%i == 0:
p2 = i
break
xx = range(k-p2+1, k+1)
#print(list(xx))
if p2>240:
p1 = primes[bisect.bisect_left(primes, int(math.ceil(xx[0]/2)))]
print(p1+1)
else:
ans = k
p1 = 1
for x1 in xx:
for i in primes[::-1]:
if i >= x1:
continue
if x1 % i == 0:
p1 = i
break
ans = min(ans, x1-p1+1)
print(ans)
``` | vfc_11450 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/923/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 425 | Solve the following coding problem using the programming language python:
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer $p$ (which may be positive, negative, or zero). To combine their tastes, they invented $p$-binary numbers of the form $2^x + p$, where $x$ is a non-negative integer.
For example, some $-9$-binary ("minus nine" binary) numbers are: $-8$ (minus eight), $7$ and $1015$ ($-8=2^0-9$, $7=2^4-9$, $1015=2^{10}-9$).
The boys now use $p$-binary numbers to represent everything. They now face a problem: given a positive integer $n$, what's the smallest number of $p$-binary numbers (not necessarily distinct) they need to represent $n$ as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.
For example, if $p=0$ we can represent $7$ as $2^0 + 2^1 + 2^2$.
And if $p=-9$ we can represent $7$ as one number $(2^4-9)$.
Note that negative $p$-binary numbers are allowed to be in the sum (see the Notes section for an example).
-----Input-----
The only line contains two integers $n$ and $p$ ($1 \leq n \leq 10^9$, $-1000 \leq p \leq 1000$).
-----Output-----
If it is impossible to represent $n$ as the sum of any number of $p$-binary numbers, print a single integer $-1$. Otherwise, print the smallest possible number of summands.
-----Examples-----
Input
24 0
Output
2
Input
24 1
Output
3
Input
24 -1
Output
4
Input
4 -7
Output
2
Input
1 1
Output
-1
-----Note-----
$0$-binary numbers are just regular binary powers, thus in the first sample case we can represent $24 = (2^4 + 0) + (2^3 + 0)$.
In the second sample case, we can represent $24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1)$.
In the third sample case, we can represent $24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1)$. Note that repeated summands are allowed.
In the fourth sample case, we can represent $4 = (2^4 - 7) + (2^1 - 7)$. Note that the second summand is negative, which is allowed.
In the fifth sample case, no representation is possible.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, p = list(map(int, input().split()))
for q in range(5757):
s = bin(n)
if n >= q >= s.count('1'):
print(q)
break
n -= p
else:
print(-1)
``` | vfc_11454 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1225/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "24 0\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 426 | Solve the following coding problem using the programming language python:
Ania has a large integer $S$. Its decimal representation has length $n$ and doesn't contain any leading zeroes. Ania is allowed to change at most $k$ digits of $S$. She wants to do it in such a way that $S$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \leq n \leq 200\,000$, $0 \leq k \leq n$) — the number of digits in the decimal representation of $S$ and the maximum allowed number of changed digits.
The second line contains the integer $S$. It's guaranteed that $S$ has exactly $n$ digits and doesn't contain any leading zeroes.
-----Output-----
Output the minimal possible value of $S$ which Ania can end with. Note that the resulting integer should also have $n$ digits.
-----Examples-----
Input
5 3
51528
Output
10028
Input
3 2
102
Output
100
Input
1 1
1
Output
0
-----Note-----
A number has leading zeroes if it consists of at least two digits and its first digit is $0$. For example, numbers $00$, $00069$ and $0101$ have leading zeroes, while $0$, $3000$ and $1010$ don't have leading zeroes.
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()))
s = list(input())
if len(s) == 1 and k:
print(0)
return
if s[0] != '1' and k:
k -= 1
s[0] = '1'
for i in range(1, len(s)):
if s[i] != '0' and k:
s[i] = '0'
k -= 1
if not k:
break
print(''.join(s))
``` | vfc_11458 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1230/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n51528\n",
"output": "10028\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n102\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 3\n76185080\n",
"output": "10085080\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9\n6605076924\n",
"output": "1000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 427 | Solve the following coding problem using the programming language python:
You have two friends. You want to present each of them several positive integers. You want to present cnt_1 numbers to the first friend and cnt_2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.
Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.
A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
-----Input-----
The only line contains four positive integers cnt_1, cnt_2, x, y (1 ≤ cnt_1, cnt_2 < 10^9; cnt_1 + cnt_2 ≤ 10^9; 2 ≤ x < y ≤ 3·10^4) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.
-----Output-----
Print a single integer — the answer to the problem.
-----Examples-----
Input
3 1 2 3
Output
5
Input
1 3 2 3
Output
4
-----Note-----
In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n0, n1, x, y = list(map(int, input().split()))
def f(m, n, x, y):
return max(0, n - (m // y - m // (x * y)))
lo = -1
hi = x * y * (n0 + n1)
while lo + 1 < hi:
mid = lo + (hi - lo) // 2
if f(mid, n0, x, y) + f(mid, n1, y, x) <= mid - mid // x - mid // y + mid // (x * y):
hi = mid
else:
lo = mid
print(hi)
``` | vfc_11462 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/483/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "916200 69682 2 3\n",
"output": "1832399\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "808351 17767 433 509\n",
"output": "826121\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8851 901 20897 26183\n",
"output": "9752\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5099 2895 16273 29473\n",
"output": "7994\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 428 | Solve the following coding problem using the programming language python:
Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x and column y by record (x, y). Each cell of the field contains growing raspberry, at that, the cell (x, y) of the field contains x + y raspberry bushes.
The bear came out to walk across the field. At the beginning of the walk his speed is (dx, dy). Then the bear spends exactly t seconds on the field. Each second the following takes place: Let's suppose that at the current moment the bear is in cell (x, y). First the bear eats the raspberry from all the bushes he has in the current cell. After the bear eats the raspberry from k bushes, he increases each component of his speed by k. In other words, if before eating the k bushes of raspberry his speed was (dx, dy), then after eating the berry his speed equals (dx + k, dy + k). Let's denote the current speed of the bear (dx, dy) (it was increased after the previous step). Then the bear moves from cell (x, y) to cell (((x + dx - 1) mod n) + 1, ((y + dy - 1) mod n) + 1). Then one additional raspberry bush grows in each cell of the field.
You task is to predict the bear's actions. Find the cell he ends up in if he starts from cell (sx, sy). Assume that each bush has infinitely much raspberry and the bear will never eat all of it.
-----Input-----
The first line of the input contains six space-separated integers: n, sx, sy, dx, dy, t (1 ≤ n ≤ 10^9; 1 ≤ sx, sy ≤ n; - 100 ≤ dx, dy ≤ 100; 0 ≤ t ≤ 10^18).
-----Output-----
Print two integers — the coordinates of the cell the bear will end up in after t seconds.
-----Examples-----
Input
5 1 2 0 1 2
Output
3 1
Input
1 1 1 -1 -1 2
Output
1 1
-----Note-----
Operation a mod b means taking the remainder after dividing a by b. Note that the result of the operation is always non-negative. For example, ( - 1) mod 3 = 2.
In the first sample before the first move the speed vector will equal (3,4) and the bear will get to cell (4,1). Before the second move the speed vector will equal (9,10) and he bear will get to cell (3,1). Don't forget that at the second move, the number of berry bushes increased by 1.
In the second sample before the first move the speed vector will equal (1,1) and the bear will get to cell (1,1). Before the second move, the speed vector will equal (4,4) and the bear will get to cell (1,1). Don't forget that at the second move, the number of berry bushes increased by 1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#Simple non-optimized class of matrices. Used with small dense matrices.
import functools
import itertools
import math
class NotAMatrixError(Exception):
pass
class MatrixSizeError(Exception):
def __init__(self, s1, s2):
print('sizes do not match : ', s1, ', ', s2)
class NotSquareError(Exception):
pass
class Matrix(list):
def __init__(self, L):
if type(L) == type(self):
self = L
return
n = len(L)
m = len(L[0])
for i in range(n):
if len(L[i]) != m:
raise NotAMatrixError()
list.__init__(self, L)
self.n = n
self.m = m
self.degrees = []
def check_size(self, M, mode):
n, m = len(M), len(M[0])
for i in range(n):
if len(M[i]) != m:
raise NotAMatrixError()
if mode == 'add' and (self.n != n or self.m != m):
raise MatrixSizeError((self.n, self.m), (n,m))
if mode == 'lul' and self.m != n:
print(self.m, n, self.m != n)
raise MatrixSizeError((self.n, self.m), (n,m))
def __add__(self, M):
self.check_size(M, mode = 'add')
return Matrix([[self[i][j]+M[i][j] for j in range(self.m)]for i in range(self.n)])
def __iadd__(self, M):
self.check_size(M, mode = 'add')
for i in range(self.n):
for j in range(self,m):
self[i][j] += M[i][j]
def __mul__(self, M):
self.check_size(M, mode = 'mul')
l = len(M[0])
return Matrix([[sum(self[i][k]*M[k][j] for k in range(self.m))
for j in range(l)] for i in range(self.n)])
def issquare(self):
return self.n == self.m
def primary(self):
if self.n != self.m:
raise NotSquareError()
return Matrix([[int(i==j) for j in range(self.m)] for i in range(self.n)])
def __pow__(self, n):
if self.n != self.m:
raise NotSquareError()
if n == 0:
return self.primary()
elif n == 1:
return self
if len(self.degrees) == 0:
self.degrees.append(self*self)
for i in range(n.bit_length() - len(self.degrees) - 1):
self.degrees.append(self.degrees[-1] * self.degrees[-1])
s = [(n>>i)&1 for i in range(1,n.bit_length())]
res = functools.reduce(lambda x,y:x*y, itertools.compress(self.degrees, s))
return res*self if n%2 else res
def drop_degrees(self):
self.degrees.clear()
class Remainder(int):
def __new__(self, n, p):
obj = int.__new__(self, n%p)
obj.p = p
return obj
def __mul__(self, m): return Remainder(int.__mul__(self, m), self.p)
def __add__(self, m): return Remainder(int.__add__(self, m), self.p)
def __sub__(self, m): return Remainder(int.__sub__(self, m), self.p)
def __rmul__(self, m): return Remainder(int.__rmul__(self, m), self.p)
def __radd__(self, m): return Remainder(int.__radd__(self, m), self.p)
def __rsub__(self, m): return Remainder(int.__rsub__(self, m), self.p)
def __neg__(self): return Remainder(int.__neg__(self), self.p)
def __pow__(self, m): return Remainder(int.__pow__(self, m, self.p), self.p)
def solve(n, sx, sy, dx, dy, t):
o, l, j = Remainder(0, n), Remainder(1, n), Remainder(2, n)
N = [[j, l, l, o, l, o],
[l, j, o, l, l, o],
[l, l, l, o, l, o],
[l, l, o, l, l, o],
[o, o, o, o, l, l],
[o, o, o, o, o, l]]
M = Matrix(N)
sx, sy, dx, dy = [Remainder(x, n) for x in [sx, sy, dx, dy]]
v = Matrix([[sx], [sy], [dx], [dy], [o], [l]])
return M ** t * v
n, sx, sy, dx, dy, t = [int(x) for x in input().split()]
ans = solve(n, sx, sy, dx, dy, t)
print(int(ans[0][0] - 1) + 1, int(ans[1][0] - 1) + 1)
``` | vfc_11466 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/385/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 2 0 1 2\n",
"output": "3 1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 430 | Solve the following coding problem using the programming language python:
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w_1, w_2, ..., w_{n} (w_{i} = 100 or w_{i} = 200), where w_{i} is the weight of the i-th apple.
-----Output-----
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
-----Examples-----
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
-----Note-----
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Round 248 Div 2 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())
a = [int(x) for x in g()]
c100 = a.count(100)
if sum(a) % 200:
print("NO")
elif n % 2 and not c100:
print("NO")
else:
print("YES")
``` | vfc_11474 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/433/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n100 200 100\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n100 100 100 200\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n200\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 431 | Solve the following coding problem using the programming language python:
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of n floors with stairs at the left and the right sides. Each floor has m rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with n rows and m + 2 columns, where the first and the last columns represent the stairs, and the m columns in the middle represent rooms.
Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights.
Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively.
The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor.
The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.
-----Output-----
Print a single integer — the minimum total time needed to turn off all the lights.
-----Examples-----
Input
2 2
0010
0100
Output
5
Input
3 4
001000
000010
000010
Output
12
Input
4 3
01110
01110
01110
01110
Output
18
-----Note-----
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.
In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor.
In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
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()))
m += 2
l = []
do = False
for i in range(n):
s = input().strip()
if s.find('1') != -1 or do:
do = True
l.append(s)
n = len(l)
if n == 0:
print(0)
return
dp = []
for i in range(n):
dp.append([None] * 2)
for i in range(n):
R = 0
for j in range(m):
if l[i][j] == '1':
R = j
L = m - 1
for j in range(m - 1, -1, -1):
if l[i][j] == '1':
L = j
if i == 0:
dp[0][0] = R
dp[0][1] = (m - 1 - L)
else:
dp[i][0] = min(dp[i - 1][0] + 2 * R, dp[i - 1][1] + (m - 1)) + 1
dp[i][1] = min(dp[i - 1][0] + (m - 1), dp[i - 1][1] + 2 * (m - 1 - L)) + 1
# print(dp)
print(dp[-1][0])
``` | vfc_11478 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/812/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n0010\n0100\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 433 | Solve the following coding problem using the programming language python:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance. [Image] Illustration for n = 6, a = 2, b = - 5.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
-----Input-----
The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n, - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
-----Output-----
Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.
-----Examples-----
Input
6 2 -5
Output
3
Input
5 1 3
Output
4
Input
3 2 7
Output
3
-----Note-----
The first example is illustrated by the picture in the statements.
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 = list(map(int, input().split()))
ans = a + b
while ans < 0:
ans += n
ans %= n
if ans == 0:
print(n)
else:
print(ans)
``` | vfc_11486 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/659/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2 -5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 434 | Solve the following coding problem using the programming language python:
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.
Polycarpus believes that if he writes out the population of the capital for several consecutive years in the sequence a_1, a_2, ..., a_{n}, then it is convenient to consider the array as several arithmetic progressions, written one after the other. For example, sequence (8, 6, 4, 2, 1, 4, 7, 10, 2) can be considered as a sequence of three arithmetic progressions (8, 6, 4, 2), (1, 4, 7, 10) and (2), which are written one after another.
Unfortunately, Polycarpus may not have all the data for the n consecutive years (a census of the population doesn't occur every year, after all). For this reason, some values of a_{i} may be unknown. Such values are represented by number -1.
For a given sequence a = (a_1, a_2, ..., a_{n}), which consists of positive integers and values -1, find the minimum number of arithmetic progressions Polycarpus needs to get a. To get a, the progressions need to be written down one after the other. Values -1 may correspond to an arbitrary positive integer and the values a_{i} > 0 must be equal to the corresponding elements of sought consecutive record of the progressions.
Let us remind you that a finite sequence c is called an arithmetic progression if the difference c_{i} + 1 - c_{i} of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression.
-----Input-----
The first line of the input contains integer n (1 ≤ n ≤ 2·10^5) — the number of elements in the sequence. The second line contains integer values a_1, a_2, ..., a_{n} separated by a space (1 ≤ a_{i} ≤ 10^9 or a_{i} = - 1).
-----Output-----
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
-----Examples-----
Input
9
8 6 4 2 1 4 7 10 2
Output
3
Input
9
-1 6 -1 2 -1 4 7 -1 2
Output
3
Input
5
-1 -1 -1 -1 -1
Output
1
Input
7
-1 -1 4 5 1 2 3
Output
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
import math
n = int(sys.stdin.readline())
if n <= 2:
print(1)
return
a = [int(s) for s in sys.stdin.readline().split()]
st = -1 # index of first positive number in current subset of a
ed = -1 # index last positive number in current subset of a
# differation is (a[ed] - a[st])/(ed - st)
leading_zeros = 0 # -1 before a[st]
seg_count = 1
for (i, v) in enumerate(a):
if v == -1:
if st == -1:
leading_zeros += 1
else:
if ed != -1:
# check if v should be a non-positive number
if a[ed] + (i-ed) * (a[ed] - a[st])/(ed-st) <= 0:
st = -1
ed = -1
leading_zeros = 1
seg_count += 1
else:
pass
else:
pass
else:
if st == -1:
st = i # find first positive number
else:
if ed == -1:
ed = i
#print(i)
if (v - a[st]) % (i-st) != 0 or a[st] - (v-a[st])/(i-st) * leading_zeros <= 0:
# a[st..i] can't be an arithmetic progression
st = i
ed = -1
seg_count += 1
leading_zeros = 0
else:
ed = i
else:
if (v-a[ed])%(i-ed) != 0 or (v-a[ed]) * (ed - st) != (a[ed] - a[st]) * (i-ed):
st = i
ed = -1
seg_count += 1
leading_zeros = 0
else:
ed = i #leave ed the first positive number after a[st] is also ok
#print( "[" +str(st) + " " + str(ed) + "] " + str(seg_count) + " " + str(leading_zeros) )
print(seg_count)
``` | vfc_11490 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/416/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n8 6 4 2 1 4 7 10 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n-1 6 -1 2 -1 4 7 -1 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 435 | Solve the following coding problem using the programming language python:
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. What is the maximum beauty of the string he can achieve?
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
-----Output-----
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
-----Examples-----
Input
4 2
abba
Output
4
Input
8 1
aabaabaa
Output
5
-----Note-----
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
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())
s = input()
maxi = 0
a = 0
b = 0
st = 0
for i in range(0, n):
if s[i] == 'a': a += 1
else: b+=1
if min(a, b) > k:
if s[st] == 'a': a-=1
else: b-=1
st += 1
else: maxi += 1
print(maxi)
``` | vfc_11494 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/676/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\nabba\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 1\naabaabaa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\na\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\nb\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\nb\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\na\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 437 | Solve the following coding problem using the programming language python:
3R2 - Standby for Action
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. $n$"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).
For each question JOE answers, if there are $s$ ($s > 0$) opponents remaining and $t$ ($0 \le t \le s$) of them make a mistake on it, JOE receives $\displaystyle\frac{t}{s}$ dollars, and consequently there will be $s - t$ opponents left for the next question.
JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?
-----Input-----
The first and single line contains a single integer $n$ ($1 \le n \le 10^5$), denoting the number of JOE's opponents in the show.
-----Output-----
Print a number denoting the maximum prize (in dollars) JOE could have.
Your answer will be considered correct if it's absolute or relative error won't exceed $10^{-4}$. In other words, if your answer is $a$ and the jury answer is $b$, then it must hold that $\frac{|a - b|}{max(1, b)} \le 10^{-4}$.
-----Examples-----
Input
1
Output
1.000000000000
Input
2
Output
1.500000000000
-----Note-----
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be $\displaystyle \frac{1}{2} + \frac{1}{1} = 1.5$ dollars.
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())
tot=0
for i in range(n):
tot+=1/(i+1)
print(tot)
``` | vfc_11502 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1293/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1.000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "1.500000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100000\n",
"output": "12.090146129863\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "1.833333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2.083333333333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "2.283333333333\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 438 | Solve the following coding problem using the programming language python:
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has.
-----Input-----
The only line contains positive integer number n (1 ≤ n ≤ 1000) — number of candies Santa Claus has.
-----Output-----
Print to the first line integer number k — maximal number of kids which can get candies.
Print to the second line k distinct integer numbers: number of candies for each of k kid. The sum of k printed numbers should be exactly n.
If there are many solutions, print any of them.
-----Examples-----
Input
5
Output
2
2 3
Input
9
Output
3
3 5 1
Input
2
Output
1
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
ans = []
nxt = 1
while n > 0:
x = nxt
n -= nxt
nxt += 1
if n < nxt:
x += n
n = 0
ans.append(str(x))
print(len(ans))
print(" ".join(ans))
``` | vfc_11506 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/753/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "2\n1 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n",
"output": "3\n1 2 6 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 439 | Solve the following coding problem using the programming language python:
The following problem is well-known: given integers n and m, calculate $2^{n} \operatorname{mod} m$,
where 2^{n} = 2·2·...·2 (n factors), and $x \operatorname{mod} y$ denotes the remainder of division of x by y.
You are asked to solve the "reverse" problem. Given integers n and m, calculate $m \operatorname{mod} 2^{n}$.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^8).
The second line contains a single integer m (1 ≤ m ≤ 10^8).
-----Output-----
Output a single integer — the value of $m \operatorname{mod} 2^{n}$.
-----Examples-----
Input
4
42
Output
10
Input
1
58
Output
0
Input
98765432
23456789
Output
23456789
-----Note-----
In the first example, the remainder of division of 42 by 2^4 = 16 is equal to 10.
In the second example, 58 is divisible by 2^1 = 2 without remainder, and the answer is 0.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
m = int(input())
print(m % (1 << n))
``` | vfc_11510 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/913/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n42\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n58\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "98765432\n23456789\n",
"output": "23456789\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n88127381\n",
"output": "149\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "32\n92831989\n",
"output": "92831989\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "92831989\n25\n",
"output": "25\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 440 | Solve the following coding problem using the programming language python:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.
You are given a word s. Can you predict what will it become after correction?
In this problem letters a, e, i, o, u and y are considered to be vowels.
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 100) — the number of letters in word s before the correction.
The second line contains a string s consisting of exactly n lowercase Latin letters — the word before the correction.
-----Output-----
Output the word s after the correction.
-----Examples-----
Input
5
weird
Output
werd
Input
4
word
Output
word
Input
5
aaeaa
Output
a
-----Note-----
Explanations of the examples: There is only one replace: weird $\rightarrow$ werd; No replace needed since there are no two consecutive vowels; aaeaa $\rightarrow$ aeaa $\rightarrow$ aaa $\rightarrow$ aa $\rightarrow$ a.
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()
t = []
vowels = 'aeiouy'
for c in s:
if t and t[-1] in vowels and c in vowels:
continue
else:
t.append(c)
print(''.join(t))
``` | vfc_11514 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/938/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nweird\n",
"output": "werd\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nword\n",
"output": "word\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naaeaa\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw\n",
"output": "abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 441 | Solve the following coding problem using the programming language python:
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carriage so that: no student-programmer is sitting next to the student-programmer; and no student-athlete is sitting next to the student-athlete.
In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.
Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).
-----Input-----
The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b > 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length $n$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.
-----Output-----
Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.
-----Examples-----
Input
5 1 1
*...*
Output
2
Input
6 2 3
*...*.
Output
4
Input
11 3 10
.*....**.*.
Output
7
Input
3 2 3
***
Output
0
-----Note-----
In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, and the letter B — student-athlete.
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 = list(map(int, input().split()))
s = input()
s += '*'
n += 1
m = []
i = 0
i1 = -1
while i < len(s):
if s[i] == '*':
if i - i1 > 1:
m.append(i - i1 - 1)
i1 = i
i += 1
sm = a + b
for c in m:
if c % 2 == 0:
a = max(0, a - c // 2)
b = max(0, b - c // 2)
else:
if a > b:
a = max(0, a - (c + 1) // 2)
b = max(0, b - c // 2)
else:
b = max(0, b - (c + 1) // 2)
a = max(0, a - c // 2)
print(sm - a - b)
``` | vfc_11518 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/962/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 1\n*...*\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2 3\n*...*.\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 3 10\n.*....**.*.\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 3\n***\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 5 3\n*...*...*\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 442 | Solve the following coding problem using the programming language python:
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor.
Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques.
The first hashing function she designed is as follows.
Given two positive integers $(x, y)$ she defines $H(x,y):=x^2+2xy+x+1$.
Now, Heidi wonders if the function is reversible. That is, given a positive integer $r$, can you find a pair $(x, y)$ (of positive integers) such that $H(x, y) = r$?
If multiple such pairs exist, output the one with smallest possible $x$. If there is no such pair, output "NO".
-----Input-----
The first and only line contains an integer $r$ ($1 \le r \le 10^{12}$).
-----Output-----
Output integers $x, y$ such that $H(x,y) = r$ and $x$ is smallest possible, or "NO" if no such pair exists.
-----Examples-----
Input
19
Output
1 8
Input
16
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=int(input())
if r<=4:
print("NO")
elif r%2==0:
print("NO")
else :
print(1, (r-3)//2)
``` | vfc_11522 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1184/A1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "19\n",
"output": "1 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 443 | Solve the following coding problem using the programming language python:
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
Do not rip the packets (both Grigory and Andrew should get unbroken packets); Distribute all packets (every packet should be given to someone); Give both Grigory and Andrew at least one packet; To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
-----Input-----
The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet.
-----Output-----
If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
-----Examples-----
Input
3
1 2 1
Output
2
1 2
Input
2
5 5
Output
-1
Input
1
10
Output
-1
-----Note-----
In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
tab = [int(x) for x in input().split()]
if n < 2 or (n == 2 and tab[0] == tab[1]):
print(-1)
else:
print(1)
print(tab.index(min(tab)) + 1)
``` | vfc_11526 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/998/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 1 1 1 1 1 1 1 1 1\n",
"output": "1\n1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 444 | Solve the following coding problem using the programming language python:
Vasya has his favourite number $n$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $d_1, d_2, \ldots, d_k$, such that $1 \leq d_i \leq 9$ for all $i$ and $d_1 + d_2 + \ldots + d_k = n$.
Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among $d_1, d_2, \ldots, d_k$. Help him!
-----Input-----
The first line contains a single integer $n$ — the number that Vasya wants to split ($1 \leq n \leq 1000$).
-----Output-----
In the first line print one integer $k$ — the number of digits in the partition. Note that $k$ must satisfy the inequality $1 \leq k \leq n$. In the next line print $k$ digits $d_1, d_2, \ldots, d_k$ separated by spaces. All digits must satisfy the inequalities $1 \leq d_i \leq 9$.
You should find a partition of $n$ in which the number of different digits among $d_1, d_2, \ldots, d_k$ will be minimal possible among all partitions of $n$ into non-zero digits. Among such partitions, it is allowed to find any. It is guaranteed that there exists at least one partition of the number $n$ into digits.
-----Examples-----
Input
1
Output
1
1
Input
4
Output
2
2 2
Input
27
Output
3
9 9 9
-----Note-----
In the first test, the number $1$ can be divided into $1$ digit equal to $1$.
In the second test, there are $3$ partitions of the number $4$ into digits in which the number of different digits is $1$. This partitions are $[1, 1, 1, 1]$, $[2, 2]$ and $[4]$. Any of these partitions can be found. And, for example, dividing the number $4$ to the digits $[1, 1, 2]$ isn't an answer, because it has $2$ different digits, that isn't the minimum possible number.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import getpass
import sys
def ria():
return [int(i) for i in input().split()]
if getpass.getuser() != 'frohenk':
filename = 'half'
# sys.stdin = open('input.txt')
# sys.stdout = open('output.txt', 'w')
else:
sys.stdin = open('input.txt')
# sys.stdin.close()
n = ria()[0]
print(n)
print('1 '*n)
``` | vfc_11530 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1104/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1\n1 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 445 | Solve the following coding problem using the programming language python:
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^6) — the elements of the array a.
-----Output-----
On the first line print integer m — the maximum possible size of simple subset of a.
On the second line print m integers b_{l} — the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n = int(input())
l = list(map(int, input().split()))
seive = [False, True] * max(l)
a = len(seive)
for i in range(3, int(a ** .5) + 1, 2):
if seive[i]:
for j in range(i * i, a, i):
seive[j] = False
i = l.count(1)
if i:
res = [1] * i
for a in l:
if a > 1 and seive[a + 1]:
res.append(a)
break
if len(res) > 1:
print(len(res))
print(*res)
return
l0, l1 = [], []
for a in l:
if a != 1:
if a & 1:
for b in l0:
if seive[a + b]:
print(2)
print(a, b)
return
l1.append(a)
else:
for b in l1:
if seive[a + b]:
print(2)
print(a, b)
return
l0.append(a)
print(1)
print(l[0])
def __starting_point():
main()
__starting_point()
``` | vfc_11534 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/665/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n",
"output": "2\n3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2\n",
"output": "1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 1 1\n",
"output": "3\n1 1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n83 14\n",
"output": "2\n14 83\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 446 | Solve the following coding problem using the programming language python:
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.
Some examples of beautiful numbers: 1_2 (1_10); 110_2 (6_10); 1111000_2 (120_10); 111110000_2 (496_10).
More formally, the number is beautiful iff there exists some positive integer k such that the number is equal to (2^{k} - 1) * (2^{k} - 1).
Luba has got an integer number n, and she wants to find its greatest beautiful divisor. Help her to find it!
-----Input-----
The only line of input contains one number n (1 ≤ n ≤ 10^5) — the number Luba has got.
-----Output-----
Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.
-----Examples-----
Input
3
Output
1
Input
992
Output
496
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 Counter, defaultdict
import itertools
import sys
def main():
n = int(input())
ans = 1
for k in range(1, 10):
v = ((1 << k) - 1) * (1 << (k - 1))
if n % v == 0:
ans = v
print(ans)
main()
``` | vfc_11538 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/893/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "992\n",
"output": "496\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "81142\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 447 | Solve the following coding problem using the programming language python:
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 10^9 + 7 (so you should find the remainder after dividing by 10^9 + 7).
-----Input-----
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
-----Output-----
Print the only integer a — the remainder after dividing by 10^9 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
-----Examples-----
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
-----Note-----
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/usr/bin/env python3
def addmod(left, right, modulo=1000000007):
res = left + right
if res >= modulo:
res -= modulo
return res
def counter(a, m, d):
res = [0, ] * (2*m)
res[0] = 1
shift = 1
for pos in range(len(a), 0, -1):
ptype = pos & 1
cur = int(a[pos-1])
tres = [0, ] * (2*m)
for i in range(10):
if ptype==1 and i == d:
continue
if ptype==0 and i != d:
continue
k = (i * shift) % m
for j in range(m):
k2 = k*2
j2 = j*2
if i < cur:
tres[k2+0] = addmod(tres[k2+0], addmod(res[j2+0], res[j2+1]))
elif i == cur:
tres[k2+0] = addmod(tres[k2+0], res[j2+0])
tres[k2+1] = addmod(tres[k2+1], res[j2+1])
else:
tres[k2+1] = addmod(tres[k2+1], addmod(res[j2+0], res[j2+1]))
k = k+1 if k+1<m else 0
res = tres
shift = (shift * 10) % m
return res[0]
def solver(ifs):
m, d = list(map(int, ifs.readline().split()))
a = ifs.readline().strip()
b = ifs.readline().strip()
res = counter(b, m, d)
if a != '0':
a = str(int(a) - 1)
if len(a) < len(b):
a = '0' + a
modulo = 1000000007
res = addmod(res, modulo - counter(a, m, d))
print(res)
def main():
import sys
if sys.version_info.major == 3:
from io import StringIO as StreamIO
else:
from io import BytesIO as StreamIO
with StreamIO(sys.stdin.read()) as ifs, StreamIO() as ofs:
_stdout = sys.stdout
sys.stdout = ofs
solver(ifs)
sys.stdout = _stdout
sys.stdout.write(ofs.getvalue())
return 0
def __starting_point():
main()
__starting_point()
``` | vfc_11542 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/628/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 6\n10\n99\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 448 | Solve the following coding problem using the programming language python:
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least a_{i} candies.
Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
Give m candies to the first child of the line. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
-----Input-----
The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100).
-----Output-----
Output a single integer, representing the number of the last child.
-----Examples-----
Input
5 2
1 3 1 4 2
Output
4
Input
6 4
1 1 2 2 3 3
Output
6
-----Note-----
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home.
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 collections import deque
n, m = [int(i) for i in input().split()]
children = deque([0, int(v), i + 1] for i, v in enumerate(input().split()))
while len(children) > 1:
tmp = children.popleft()
tmp[0] += m
if tmp[1] > tmp[0]:
children.append(tmp)
print(children.popleft()[2])
main()
``` | vfc_11546 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/450/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 3 1 4 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n1 1 2 2 3 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n6 1 5 4 2 3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n2 7 3 6 2 5 1 3 4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"output": "100\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 449 | Solve the following coding problem using the programming language python:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
-----Input-----
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
-----Output-----
Output the minimum number of bills that Allen could receive.
-----Examples-----
Input
125
Output
3
Input
43
Output
5
Input
1000000000
Output
10000000
-----Note-----
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills.
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
ans+=n//100
n%=100
ans+=n//20
n%=20
ans+=n//10
n%=10
ans+=n//5
n%=5
ans+=n
print(ans)
``` | vfc_11550 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/996/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "125\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "43\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000\n",
"output": "10000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 450 | Solve the following coding problem using the programming language python:
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1, p_2, ..., p_{n}.
We'll call position i (1 ≤ i ≤ n) in permutation p_1, p_2, ..., p_{n} good, if |p[i] - i| = 1. Count the number of permutations of size n with exactly k good positions. Print the answer modulo 1000000007 (10^9 + 7).
-----Input-----
The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 0 ≤ k ≤ n).
-----Output-----
Print the number of permutations of length n with exactly k good positions modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
1 0
Output
1
Input
2 1
Output
0
Input
3 2
Output
4
Input
4 1
Output
6
Input
7 4
Output
328
-----Note-----
The only permutation of size 1 has 0 good positions.
Permutation (1, 2) has 0 good positions, and permutation (2, 1) has 2 positions.
Permutations of size 3:
(1, 2, 3) — 0 positions
$(1,3,2)$ — 2 positions
$(2,1,3)$ — 2 positions
$(2,3,1)$ — 2 positions
$(3,1,2)$ — 2 positions
(3, 2, 1) — 0 positions
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
mod=10**9+7
n,k=list(map(int,input().split()))
A=[0]*(n+1)
B=[0]*(n+1)
C=[0]*(n+1)
F=[0]*(n+1)
G=[0]*(n+1)
F[0]=G[0]=1
for i in range(1,n+1):
G[i]=F[i]=F[i-1]*i%mod
G[i]=pow(F[i],(mod-2),mod)
for i in range(0,n):
if i*2>n:
break
B[i]=(F[n-i]*G[i]*G[n-i*2])%mod
for i in range(0,n//2+1):
for j in range(0,n//2+1):
A[i+j]=(A[i+j]+B[i]*B[j])%mod
for i in range(0,n+1):
A[i]=A[i]*F[n-i]%mod
for i in range(0,n+1):
for j in range(0,i+1):
C[j]=(C[j]+A[i]*F[i]*G[j]*G[i-j]*(1-(i-j)%2*2))%mod
print(C[k]%mod)
``` | vfc_11554 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/285/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 451 | Solve the following coding problem using the programming language python:
Arkady decided to buy roses for his girlfriend.
A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and white roses. Also, Arkady won't buy a bouquet where all roses have the same color.
Arkady wants to buy exactly k roses. For each rose in the shop he knows its beauty and color: the beauty of the i-th rose is b_{i}, and its color is c_{i} ('W' for a white rose, 'O' for an orange rose and 'R' for a red rose).
Compute the maximum possible total beauty of a bouquet of k roses satisfying the constraints above or determine that it is not possible to make such a bouquet.
-----Input-----
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of roses in the show and the number of roses Arkady wants to buy.
The second line contains a sequence of integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 10 000), where b_{i} equals the beauty of the i-th rose.
The third line contains a string c of length n, consisting of uppercase English letters 'W', 'O' and 'R', where c_{i} denotes the color of the i-th rose: 'W' denotes white, 'O' — orange, 'R' — red.
-----Output-----
Print the maximum possible total beauty of a bouquet of k roses that satisfies the constraints above. If it is not possible to make a single such bouquet, print -1.
-----Examples-----
Input
5 3
4 3 4 1 6
RROWW
Output
11
Input
5 2
10 20 14 20 11
RRRRR
Output
-1
Input
11 5
5 6 3 2 3 4 7 5 4 5 6
RWOORWORROW
Output
28
-----Note-----
In the first example Arkady wants to buy 3 roses. He can, for example, buy both red roses (their indices are 1 and 2, and their total beauty is 7) and the only orange rose (its index is 3, its beauty is 4). This way the total beauty of the bouquet is 11.
In the second example Arkady can not buy a bouquet because all roses have the same color.
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()))
b = list(map(int,input().split()))
SSSSSSSSSS = input()
INF = 1000*1000*1000+123
RRRR = [];
WWWWWWW = [];
OOOOOOOOO = [];
for i in range(n):
if SSSSSSSSSS[i] == 'R':
RRRR.append(b[i])
elif SSSSSSSSSS[i] == 'W':
WWWWWWW.append(b[i])
else:
OOOOOOOOO.append(b[i])
WWWWWWW.sort()
RRRR.sort()
WWWWWWW.reverse()
RRRR.reverse()
OOOOOOOOO.sort()
OOOOOOOOO.reverse()
if k == 1:
print(-1)
return
def cccmcmc(A, B):
qanakA = len(A);
qanakB = len(B);
pA = [0 for i in range(qanakA)]
pB = [0 for i in range(qanakB)]
pB[0] = B[0]
pA[0] = A[0]
for i in range(1,qanakA):
pA[i] = pA[i-1] + A[i];
for i in range(1,qanakB):
pB[i] = pB[i-1] + B[i];
res = -1
for i in range(1,min(qanakA+1,k)):
aic = pA[i-1]
bepetk = k-i
if bepetk <= 0 or bepetk > qanakB: continue
bic = pB[bepetk-1]
res = max(res,aic+bic)
return res
res = -1
if len(WWWWWWW) > 0 and len(OOOOOOOOO)> 0:
res = max(res, cccmcmc(WWWWWWW, OOOOOOOOO))
if len(RRRR) > 0 and len(OOOOOOOOO)> 0:
res = max(res, cccmcmc(RRRR, OOOOOOOOO))
print(res)
``` | vfc_11558 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/926/H",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n4 3 4 1 6\nRROWW\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n10 20 14 20 11\nRRRRR\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 452 | Solve the following coding problem using the programming language python:
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal.
-----Input-----
The first line contains two space-separated integers p, q (1 ≤ q ≤ p ≤ 10^18) — the numerator and the denominator of the first fraction.
The second line contains integer n (1 ≤ n ≤ 90) — the height of the second fraction. The third line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^18) — the continued fraction.
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-----
Print "YES" if these fractions are equal and "NO" otherwise.
-----Examples-----
Input
9 4
2
2 4
Output
YES
Input
9 4
3
2 3 1
Output
YES
Input
9 4
3
1 2 4
Output
NO
-----Note-----
In the first sample $2 + \frac{1}{4} = \frac{9}{4}$.
In the second sample $2 + \frac{1}{3 + \frac{1}{1}} = 2 + \frac{1}{4} = \frac{9}{4}$.
In the third sample $1 + \frac{1}{2 + \frac{1}{4}} = \frac{13}{9}$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/usr/bin/env python3
from fractions import Fraction
def __starting_point():
p, q = list(map(int, input().split()))
n = int(input())
l = list(map(int, input().split()))
f = Fraction(l[-1], 1)
for x in l[-2::-1]:
f = 1 / f
f += x
print(["NO", "YES"][f == Fraction(p, q)])
__starting_point()
``` | vfc_11562 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/305/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 4\n2\n2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 4\n3\n2 3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 453 | Solve the following coding problem using the programming language python:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:[ A sticks][sign +][B sticks][sign =][C sticks] (1 ≤ A, B, C).
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.
We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
-----Input-----
The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 ≤ A, B, C ≤ 100.
-----Output-----
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
-----Examples-----
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
-----Note-----
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = input()
k = t.find('=')
n = 2 * k - len(t)
if n == 2:
if t[1] != '+': t = t[1: ] + '|'
else: t = t[: k - 1] + t[k: ] + '|'
elif n == -2: t = '|' + t[: -1]
elif n != 0: t = 'Impossible'
print(t)
``` | vfc_11566 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/394/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "||+|=|||||\n",
"output": "|||+|=||||\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "|||||+||=||\n",
"output": "Impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "|+|=||||||\n",
"output": "Impossible\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 456 | Solve the following coding problem using the programming language python:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!
-----Input-----
The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview.
The second line contains the string s of length n, consisting of lowercase English letters.
-----Output-----
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
-----Examples-----
Input
7
aogogob
Output
a***b
Input
13
ogogmgogogogo
Output
***gmg***
Input
9
ogoogoogo
Output
*********
-----Note-----
The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
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 *
n = int(input())
a = input()
s = 0
i = 0
while i <= n-1:
if s == 0:
if a[i:i+3] == 'ogo':
s = 1
print('***', end = '')
i+=3
else:
print(a[i], end = '')
i += 1
else:
if a[i:i+2] == 'go':
i += 2
else:
s = 0
``` | vfc_11578 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/729/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\naogogob\n",
"output": "a***b\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\nogogmgogogogo\n",
"output": "***gmg***\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\nogoogoogo\n",
"output": "*********\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz\n",
"output": "abcdef***ghijklmn***opqrstuvwxyz\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 457 | Solve the following coding problem using the programming language python:
Let's introduce some definitions that will be needed later.
Let $prime(x)$ be the set of prime divisors of $x$. For example, $prime(140) = \{ 2, 5, 7 \}$, $prime(169) = \{ 13 \}$.
Let $g(x, p)$ be the maximum possible integer $p^k$ where $k$ is an integer such that $x$ is divisible by $p^k$. For example: $g(45, 3) = 9$ ($45$ is divisible by $3^2=9$ but not divisible by $3^3=27$), $g(63, 7) = 7$ ($63$ is divisible by $7^1=7$ but not divisible by $7^2=49$).
Let $f(x, y)$ be the product of $g(y, p)$ for all $p$ in $prime(x)$. For example: $f(30, 70) = g(70, 2) \cdot g(70, 3) \cdot g(70, 5) = 2^1 \cdot 3^0 \cdot 5^1 = 10$, $f(525, 63) = g(63, 3) \cdot g(63, 5) \cdot g(63, 7) = 3^2 \cdot 5^0 \cdot 7^1 = 63$.
You have integers $x$ and $n$. Calculate $f(x, 1) \cdot f(x, 2) \cdot \ldots \cdot f(x, n) \bmod{(10^{9} + 7)}$.
-----Input-----
The only line contains integers $x$ and $n$ ($2 \le x \le 10^{9}$, $1 \le n \le 10^{18}$) — the numbers used in formula.
-----Output-----
Print the answer.
-----Examples-----
Input
10 2
Output
2
Input
20190929 1605
Output
363165664
Input
947 987654321987654321
Output
593574252
-----Note-----
In the first example, $f(10, 1) = g(1, 2) \cdot g(1, 5) = 1$, $f(10, 2) = g(2, 2) \cdot g(2, 5) = 2$.
In the second example, actual value of formula is approximately $1.597 \cdot 10^{171}$. Make sure you print the answer modulo $(10^{9} + 7)$.
In the third example, be careful about overflow issue.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x, n = list(map(int, input().split()))
def primeFactor(N):
i, n, ret, d, sq = 2, N, {}, 2, 99
while i <= sq:
k = 0
while n % i == 0: n, k, ret[i] = n//i, k+1, k+1
if k > 0 or i == 97: sq = int(n**(1/2)+0.5)
if i < 4: i = i * 2 - 1
else: i, d = i+d, d^6
if n > 1: ret[n] = 1
return ret
pf = primeFactor(x)
mod = 10 ** 9 + 7
def calc(p):
s = 0
a = n//p
while a:
s += a
a //= p
return pow(p, s, mod)
ans = 1
for p in pf:
ans = ans * calc(p) % mod
print(ans)
``` | vfc_11582 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1228/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20190929 1605\n",
"output": "363165664\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 458 | Solve the following coding problem using the programming language python:
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions x (0 < x < 10^9) of the equation:x = b·s(x)^{a} + c,
where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.
-----Input-----
The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000; - 10000 ≤ c ≤ 10000).
-----Output-----
Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 10^9.
-----Examples-----
Input
3 2 8
Output
3
10 2008 13726
Input
1 2 -18
Output
0
Input
2 2 -1
Output
4
1 31 337 967
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()))
ans = []
for sum in range(1, 200):
x = b * sum ** a + c
if x <= 0 or x >= 10 ** 9:
continue
summ = 0
for aa in str(x):
summ += int(aa)
if sum == summ:
ans.append(x)
print(len(ans))
print(*ans)
``` | vfc_11586 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/460/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2 8\n",
"output": "3\n10 2008 13726 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 -18\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 459 | Solve the following coding problem using the programming language python:
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
l=list(map(int,input().split()))
l.insert(0,0)
c1=[1,6,3,8,5,10,7,12,9,23,11,21,13,14,15,16,17,18,19,20,4,22,2,24]
c2=[1,23,3,21,5,2,7,4,9,6,11,8,13,14,15,16,17,18,19,20,12,22,10,24]
c3=[1,2,3,4,5,6,15,16,9,10,11,12,13,14,23,24,17,18,7,8,21,22,19,20]
c4=[1,2,3,4,5,6,19,20,9,10,11,12,13,14,7,8,17,18,23,24,21,22,15,16]
c5=[1,2,16,14,5,6,7,8,19,17,11,12,13,9,15,10,3,18,4,20,21,22,23,24]
c6=[1,2,17,19,5,6,7,8,14,16,11,12,13,4,15,3,10,18,9,20,21,22,23,24]
flag=0
mark=0
for i in range(6):
if(l[c1[4*i]] == l[c1[4*i+1]] == l[c1[4*i+2]] == l[c1[4*i+3]]):
mark=1
else:
mark=0
break
if(mark):
flag=1
mark=0
for i in range(6):
if(l[c2[4*i]] == l[c2[4*i+1]] == l[c2[4*i+2]] == l[c2[4*i+3]]):
mark=1
else:
mark=0
break
if(mark):
flag=1
mark=0
for i in range(6):
if(l[c3[4*i]] == l[c3[4*i+1]] == l[c3[4*i+2]] == l[c3[4*i+3]]):
mark=1
else:
mark=0
break
if(mark):
flag=1
mark=0
for i in range(6):
if(l[c4[4*i]] == l[c4[4*i+1]] == l[c4[4*i+2]] == l[c4[4*i+3]]):
mark=1
else:
mark=0
break
if(mark):
flag=1
mark=0
for i in range(6):
if(l[c5[4*i]] == l[c5[4*i+1]] == l[c5[4*i+2]] == l[c5[4*i+3]]):
mark=1
else:
mark=0
break
if(mark):
flag=1
mark=0
for i in range(6):
if(l[c6[4*i]] == l[c6[4*i+1]] == l[c6[4*i+2]] == l[c6[4*i+3]]):
mark=1
else:
mark=0
break
if(mark):
flag=1
if(flag):
print("YES")
else:
print("NO")
``` | vfc_11590 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/887/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 460 | Solve the following coding problem using the programming language python:
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.
Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.
Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:
i := (s div 50) mod 475
repeat 25 times:
i := (i * 96 + 42) mod 475
print (26 + i)
Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.
As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.
You're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.
To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.
You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?
-----Input-----
The only line contains three integers p, x and y (26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.
-----Output-----
Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.
It's guaranteed that your goal is achievable for any valid input data.
-----Examples-----
Input
239 10880 9889
Output
0
Input
26 7258 6123
Output
2
Input
493 8000 8000
Output
24
Input
101 6800 6500
Output
0
Input
329 19913 19900
Output
8
-----Note-----
In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places:
475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343
In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.
In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.
In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.
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 ceil
p,x,y = map(int, input().split())
h = x
while h >=y:
h-=50
h+=50
for i in range(h, 10000000000, 50):
u = (i//50)%475
d = []
for j in range(25):
u = (u * 96 + 42)%475
d.append(26 + u)
if p in d:
k = i
break
if k-x>0:
print(ceil((k-x)/100))
else:
print(0)
``` | vfc_11594 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/807/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "239 10880 9889\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26 7258 6123\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "493 8000 8000\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101 6800 6500\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "329 19913 19900\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 461 | Solve the following coding problem using the programming language python:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is c meters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.
-----Input-----
First line contains an integer n (1 ≤ n ≤ 100) — number of visits.
Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.
Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.
-----Output-----
Output one number — minimum distance in meters Winnie must go through to have a meal n times.
-----Examples-----
Input
3
2
3
1
Output
3
Input
1
2
3
5
Output
0
-----Note-----
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
'''input
1
2
3
5
'''
n = int(input())
a = int(input())
b = int(input())
c = int(input())
cur = 0
pos = 0
for i in range(n-1):
if pos == 0:
if a < b:
pos = 1
cur += a
else:
pos = 2
cur += b
elif pos == 1:
if a < c:
pos = 1
cur += a
else:
pos = 3
cur += c
else:
if b < c:
pos = 2
cur += b
else:
pos = 3
cur += c
print(cur)
``` | vfc_11598 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/876/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n3\n1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n3\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1\n8\n3\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 462 | Solve the following coding problem using the programming language python:
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x_1, the second friend lives at the point x_2, and the third friend lives at the point x_3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
-----Input-----
The first line of the input contains three distinct integers x_1, x_2 and x_3 (1 ≤ x_1, x_2, x_3 ≤ 100) — the coordinates of the houses of the first, the second and the third friends respectively.
-----Output-----
Print one integer — the minimum total distance the friends need to travel in order to meet together.
-----Examples-----
Input
7 1 4
Output
6
Input
30 20 10
Output
20
-----Note-----
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
l = list(map(int, input().split()))
print(max(l) - min(l))
``` | vfc_11602 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/723/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 1 4\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 463 | Solve the following coding problem using the programming language python:
There is an array with n elements a_1, a_2, ..., a_{n} and the number x.
In one operation you can select some i (1 ≤ i ≤ n) and replace element a_{i} with a_{i} & x, where & denotes the bitwise and operation.
You want the array to have at least two equal elements after applying some operations (possibly, none). In other words, there should be at least two distinct indices i ≠ j such that a_{i} = a_{j}. Determine whether it is possible to achieve and, if possible, the minimal number of operations to apply.
-----Input-----
The first line contains integers n and x (2 ≤ n ≤ 100 000, 1 ≤ x ≤ 100 000), number of elements in the array and the number to and with.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 100 000), the elements of the array.
-----Output-----
Print a single integer denoting the minimal number of operations to do, or -1, if it is impossible.
-----Examples-----
Input
4 3
1 2 3 7
Output
1
Input
2 228
1 1
Output
0
Input
3 7
1 2 3
Output
-1
-----Note-----
In the first example one can apply the operation to the last element of the array. That replaces 7 with 3, so we achieve the goal in one move.
In the second example the array already has two equal elements.
In the third example applying the operation won't change the array at all, so it is impossible to make some pair of elements equal.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0] * 1000000
ans = 0
go = False
for i in a:
b[i] += 1
if b[i] > 1:
go = True
if go:
print(ans)
else:
for i in a:
b[i] -= 1
if b[i & x] + 1 > 1:
go = True
ans = 1
break
b[i] += 1
if go:
print(ans)
else:
c = [i & x for i in a]
b = [0] * 1000000
for i in c:
b[i] += 1
if (b[i] > 1):
ans = 2
go = True
break
if go:
print(ans)
else:
print(-1)
``` | vfc_11606 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1013/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 3 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 228\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n1 2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 464 | Solve the following coding problem using the programming language python:
You have a given picture with size $w \times h$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty.
Find out if the given picture has single "+" shape.
-----Input-----
The first line contains two integers $h$ and $w$ ($1 \le h$, $w \le 500$) — the height and width of the picture.
The $i$-th of the next $h$ lines contains string $s_{i}$ of length $w$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
-----Output-----
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
-----Examples-----
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
-----Note-----
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is $2$.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
hh = -1
tmp = -1
for k,i in enumerate(s):
a = i.count('*')
if tmp < a:
tmp = a
hh = k
t = [list(i) for i in list(zip(*s))]
ww = -1
tmp = -1
for k,i in enumerate(t):
a = i.count('*')
if tmp < a:
tmp = a
ww = k
if s[hh][ww] != '*':
print('NO')
return
if hh in (0, h - 1) or ww in (0, w - 1):
print('NO')
return
if '.' in (s[hh-1][ww], s[hh+1][ww], s[hh][ww-1], s[hh][ww+1]):
print('NO')
return
cnt = 1
for i in range(hh - 1, -1, -1):
if s[i][ww] == '.':
break
cnt += 1
for i in range(ww - 1, -1, -1):
if s[hh][i] == '.':
break
cnt += 1
for i in range(hh + 1, h):
if s[i][ww] == '.':
break
cnt += 1
for i in range(ww + 1, w):
if s[hh][i] == '.':
break
cnt += 1
for i in range(h):
for j in range(w):
cnt -= (s[i][j] == '*')
if cnt != 0:
print('NO')
else:
print('YES')
``` | vfc_11610 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1182/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n......\n..*...\n.****.\n..*...\n..*...\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n..*..\n****.\n.*...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n..**..\n..**..\n******\n..**..\n..**..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n.*...*.\n***.***\n.*...*.\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 465 | Solve the following coding problem using the programming language python:
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edges from a vertex to itself) are not allowed. It can be at most one edge between a pair of vertices.
The adjacency matrix of an undirected graph is a square matrix of size $n$ consisting only of "0" and "1", where $n$ is the number of vertices of the graph and the $i$-th row and the $i$-th column correspond to the $i$-th vertex of the graph. The cell $(i,j)$ of the adjacency matrix contains $1$ if and only if the $i$-th and $j$-th vertices in the graph are connected by an edge.
A connected component is a set of vertices $X$ such that for every two vertices from this set there exists at least one path in the graph connecting this pair of vertices, but adding any other vertex to $X$ violates this rule.
The complement or inverse of a graph $G$ is a graph $H$ on the same vertices such that two distinct vertices of $H$ are adjacent if and only if they are not adjacent in $G$.
-----Input-----
In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement.
-----Output-----
If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$ in $G$ (and $0$ otherwise). Note that the matrix must be symmetric, and all digits on the main diagonal must be zeroes.
If there are several matrices that satisfy the conditions — output any of them.
-----Examples-----
Input
3 1 2
Output
YES
001
001
110
Input
3 3 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
n, a, b = map(int,input().split())
if a>1 and b>1: print("NO"); return
if 2<=n<=3 and a == b == 1: print("NO"); return
print("YES")
if b == 1:
adj = [[0]*n for i in range(n)]
conn = n
for i in range(n):
if conn == a: break
adj[i][i+1] = adj[i+1][i] = 1
conn-= 1
if conn == a: break
elif a == 1:
adj = [[1]*n for i in range(n)]
conn = n
for i in range(n): adj[i][i] = 0
for i in range(n):
if conn == b: break
adj[i][i+1] = adj[i+1][i] = 0
conn-= 1
if conn == b: break
for row in adj:
print(*row, sep='')
``` | vfc_11614 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/990/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 2\n",
"output": "YES\n001\n001\n110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 1\n",
"output": "YES\n01000\n10100\n01010\n00101\n00010\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n",
"output": "YES\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 466 | Solve the following coding problem using the programming language python:
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.
-----Input-----
The first line contains two integers c and d (1 ≤ c, d ≤ 100) — the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100). Finally, the third line contains an integer k (1 ≤ k ≤ 100) — the number of the pre-chosen winners.
-----Output-----
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
-----Examples-----
Input
1 10
7 2
1
Output
2
Input
2 2
2 1
2
Output
0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
c,d=list(map(int,input().split()))
n,m=list(map(int,input().split()))
k=int(input())
z=0
best=10**10
while(1):
x=n*m-k
x-=z*n
best=min(best,z*c+(max(x,0)*d))
if(x<0):
break
z+=1
print(best)
``` | vfc_11618 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/417/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\n7 2\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n2 1\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 9\n2 2\n3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n8 8\n7\n",
"output": "40\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 467 | Solve the following coding problem using the programming language python:
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLM
NOPQRSTUVWXYZ
We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.
A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).
You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).
-----Input-----
The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.
-----Output-----
Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".
-----Examples-----
Input
ABCDEFGHIJKLMNOPQRSGTUVWXYZ
Output
YXWVUTGHIJKLM
ZABCDEFSRQPON
Input
BUVTYZFQSNRIWOXXGJLKACPEMDH
Output
Impossible
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
s = input()
n = len(s)
a, b = 0, 0
d = dict()
for i in range(len(s)):
if s[i] in d:
a = d[s[i]]
b = i
d[s[i]] = i
if a == b - 1:
print("Impossible")
else:
ans = [[' '] * 13 for i in range(2)]
if (b - a) % 2 == 1:
for i in range((b - a) // 2):
ans[0][-(b - a) // 2 + i + 1] = s[a + i + 1]
ans[1][-i - 1] = s[a + i + (b - a) // 2 + 1]
x = -(b - a) // 2
y = 0
for i in range(b, n):
ans[y][x] = s[i]
if y == 0:
x -= 1
else:
x += 1
if x == -14:
y = 1
x = 0
for i in range(a):
ans[y][x] = s[i]
if y == 0:
x -= 1
else:
x += 1
if x == -14:
y = 1
x = 0
print("".join(ans[0]))
print("".join(ans[1]))
else:
for i in range((b - a) // 2):
ans[0][-(b - a) // 2 + i + 1] = s[a + i + 1]
ans[1][-i - 1] = s[a + i + (b - a) // 2]
x = -(b - a) // 2
y = 0
for i in range(b, n):
ans[y][x] = s[i]
if y == 0:
x -= 1
else:
x += 1
if x == -14:
y = 1
x = 0
for i in range(a):
ans[y][x] = s[i]
if y == 0:
x -= 1
else:
x += 1
if x == -14:
y = 1
x = 0
print("".join(ans[0]))
print("".join(ans[1]))
``` | vfc_11622 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/725/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ABCDEFGHIJKLMNOPQRSGTUVWXYZ\n",
"output": "YXWVUTGHIJKLM\nZABCDEFSRQPON\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BUVTYZFQSNRIWOXXGJLKACPEMDH\n",
"output": "Impossible\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 468 | Solve the following coding problem using the programming language python:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him.
-----Input-----
On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$).
-----Output-----
If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes).
-----Examples-----
Input
5 8
Output
>
Input
10 3
Output
<
Input
6 6
Output
=
-----Note-----
In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
x, y = [int(v) for v in input().split()]
xly = x * math.log(y)
ylx = y * math.log(x)
if abs(xly - ylx) < 1e-8:
print('=')
elif ylx < xly:
print('<')
else:
print('>')
``` | vfc_11626 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/987/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 8\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 1\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "987654321 123456987\n",
"output": "<\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 469 | Solve the following coding problem using the programming language python:
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + r from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right). [Image]
Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius $\frac{r}{2}$. Help Xenia calculate the maximum number of balloons she can put in her cupboard.
You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.
-----Input-----
The single line contains two integers r, h (1 ≤ r, h ≤ 10^7).
-----Output-----
Print a single integer — the maximum number of balloons Xenia can put in the cupboard.
-----Examples-----
Input
1 1
Output
3
Input
1 2
Output
5
Input
2 1
Output
2
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 *
r, h = list(map(int, input().split()))
d = h % r
if d * 2 < r:
print(h // r * 2 + 1)
elif sqrt(3) * (r / 2) + r - 1e-6 <= d + r:
print(h // r * 2 + 3)
else:
print(h // r * 2 + 2)
``` | vfc_11630 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/342/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 471 | Solve the following coding problem using the programming language python:
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x_1, x_2, ..., x_{n}. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.
Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.
-----Input-----
The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000, - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively.
The second line contains n integers x_1, x_2, ..., x_{n} ( - 1 000 000 ≤ x_{i} ≤ 1 000 000) — coordinates of the checkpoints.
-----Output-----
Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.
-----Examples-----
Input
3 10
1 7 12
Output
7
Input
2 0
11 -10
Output
10
Input
5 0
0 0 1000 0 0
Output
0
-----Note-----
In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7.
In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point - 10.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import *
n, a = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
if n == 1:
print(0)
else:
if a > A[-1]:
print(abs(a - A[1]))
elif a < A[0]:
print(abs(a - A[-2]))
else:
per1 = abs(A[0] - A[-2])
per2 = abs(A[1] - A[-1])
ans1 = abs(A[0] - a) + per1
ans2 = per1 + abs(A[-2] - a)
ans3 = per2 + abs(a - A[-1])
ans4 = per2 + abs(a - A[1])
print(min(ans1, ans2, ans3, ans4))
``` | vfc_11638 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/709/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\n1 7 12\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n11 -10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n0 0 1000 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n4 -8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n4 2 4\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 472 | Solve the following coding problem using the programming language python:
Let's consider equation:x^2 + s(x)·x - n = 0,
where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.
You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.
-----Input-----
A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
-----Output-----
Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds.
-----Examples-----
Input
2
Output
1
Input
110
Output
10
Input
4
Output
-1
-----Note-----
In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0.
In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0.
In the third test case the equation has no roots.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import re
import itertools
from collections import Counter, deque
class Task:
maxDigitSum = 18 * 9
n = 0
answer = ""
def getData(self):
self.n = int(input())
#inFile = open('input.txt', 'r')
#inFile.readline().rstrip()
#self.childs = inFile.readline().rstrip()
def solve(self):
if self.n == 1:
self.answer = '-1'
return
xL, xR = 0, self.n
while xL + self.maxDigitSum < xR:
xM = (xL + xR) // 2
if xM**2 + self.digitSum(xM) * xM < self.n:
for x in range(xM - 1, max(xL, xM - self.maxDigitSum) - 1, -1):
if x**2 + self.digitSum(x) * x == self.n:
self.answer = x
return
xL = xM
else:
for x in range(xM + 1, min(xR, xM + self.maxDigitSum) + 1):
if x**2 + self.digitSum(x) * x == self.n:
self.answer = x
return
xR = xM
for x in range(xL, xR + 1):
if x**2 + self.digitSum(x) * x == self.n:
self.answer = x
return
self.answer = -1
def digitSum(self, n):
return sum([int(x) for x in str(n)])
def printAnswer(self):
print(self.answer)
#outFile = open('output.txt', 'w')
#outFile.write(self.answer)
task = Task()
task.getData()
task.solve()
task.printAnswer()
``` | vfc_11642 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/233/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "110\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 473 | Solve the following coding problem using the programming language python:
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).
-----Input-----
The first line contains current time s as a string in the format "hh:mm". The second line contains time t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.
-----Output-----
In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.
-----Examples-----
Input
05:50
05:44
Output
00:06
Input
00:00
01:00
Output
23:00
Input
00:01
00:00
Output
00:01
-----Note-----
In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
t = input()
a, b = int(s[:2]), int(s[3:])
c, d = int(t[:2]), int(t[3:])
a -= c
b -= d
if b < 0:
a -= 1
b = 60 + b
if a < 0:
a = 24 + a
if a < 10:
print(0, end = '')
print(a, ':', end = '', sep = '')
if b < 10:
print(0, end = '')
print(b)
``` | vfc_11646 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/387/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "05:50\n05:44\n",
"output": "00:06\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "00:00\n01:00\n",
"output": "23:00\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 474 | Solve the following coding problem using the programming language python:
You are given array $a_1, a_2, \dots, a_n$. Find the subsegment $a_l, a_{l+1}, \dots, a_r$ ($1 \le l \le r \le n$) with maximum arithmetic mean $\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$ (in floating-point numbers, i.e. without any rounding).
If there are many such subsegments find the longest one.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^5$) — length of the array $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$) — the array $a$.
-----Output-----
Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.
-----Example-----
Input
5
6 1 6 6 0
Output
2
-----Note-----
The subsegment $[3, 4]$ is the longest among all subsegments with maximum arithmetic mean.
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 = max(a)
current = 0
longest = 0
for x in a:
if x == m:
current +=1
else:
longest = max(current,longest)
current = 0
longest = max(current,longest)
print (longest)
``` | vfc_11650 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1117/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n6 1 6 6 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 1 0 1 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 2 2 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3 3 2 2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 475 | Solve the following coding problem using the programming language python:
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti was satisfied. He stood back and decided to find something fun with these bricks. After some counting, he found there are $k$ bricks with a color different from the color of the brick on its left (the first brick is not counted, for sure).
So as usual, he needs your help in counting how many ways could he paint the bricks. Two ways of painting bricks are different if there is at least one brick painted in different colors in these two ways. Because the answer might be quite big, you only need to output the number of ways modulo $998\,244\,353$.
-----Input-----
The first and only line contains three integers $n$, $m$ and $k$ ($1 \leq n,m \leq 2000, 0 \leq k \leq n-1$) — the number of bricks, the number of colors, and the number of bricks, such that its color differs from the color of brick to the left of it.
-----Output-----
Print one integer — the number of ways to color bricks modulo $998\,244\,353$.
-----Examples-----
Input
3 3 0
Output
3
Input
3 2 1
Output
4
-----Note-----
In the first example, since $k=0$, the color of every brick should be the same, so there will be exactly $m=3$ ways to color the bricks.
In the second example, suppose the two colors in the buckets are yellow and lime, the following image shows all $4$ possible colorings. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
n,m,k=map(int,input().split())
out=1
for i in range(k):
out*=(m-1)
out%=998244353
out*=m
out%=998244353
out*=(math.factorial(n-1)//math.factorial(k)//math.factorial(n-1-k))
out%=998244353
print(out)
``` | vfc_11654 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1081/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 476 | Solve the following coding problem using the programming language python:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
-----Input-----
The first line of input contains an integer n, (1 ≤ n ≤ 10^9). This number doesn't contain leading zeros.
-----Output-----
Print "YES" if n is a magic number or print "NO" if it's not.
-----Examples-----
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
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 = input()
good = True
while n != '' and good:
if n.endswith('144'):
n = n[:-3]
elif n.endswith('14'):
n = n[:-2]
elif n.endswith('1'):
n = n[:-1]
else:
good = False
print('YES' if good else 'NO')
``` | vfc_11658 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/320/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "114114\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "441231\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "114\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 477 | Solve the following coding problem using the programming language python:
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.
Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types:
move the candy from position (x, y) on the board to position (x - a, y - b); move the candy from position (x, y) on the board to position (x + a, y - b); move the candy from position (x, y) on the board to position (x - a, y + b); move the candy from position (x, y) on the board to position (x + a, y + b).
Naturally, Dima doesn't allow to move the candy beyond the chessboard borders.
Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position (i, j) to one of the chessboard corners. Help them cope with the task!
-----Input-----
The first line of the input contains six integers n, m, i, j, a, b (1 ≤ n, m ≤ 10^6; 1 ≤ i ≤ n; 1 ≤ j ≤ m; 1 ≤ a, b ≤ 10^6).
You can assume that the chessboard rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. Position (i, j) in the statement is a chessboard cell on the intersection of the i-th row and the j-th column. You can consider that the corners are: (1, m), (n, 1), (n, m), (1, 1).
-----Output-----
In a single line print a single integer — the minimum number of moves needed to get the candy.
If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes.
-----Examples-----
Input
5 7 1 3 2 2
Output
2
Input
5 5 2 3 1 1
Output
Poor Inna and pony!
-----Note-----
Note to sample 1:
Inna and the pony can move the candy to position (1 + 2, 3 + 2) = (3, 5), from there they can move it to positions (3 - 2, 5 + 2) = (1, 7) and (3 + 2, 5 + 2) = (5, 7). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,m,i,j,a,b=list(map(int,input().split()))
ans=100000000000
if((i,j)==(n,1) or (i,j)==(1,1) or (i,j)==(1,m) or (i,j)==(n,m)):
print(0)
else:
#Corner (1,1)
hor=i-1
ver=j-1
if(hor%a==0 and ver%b==0):
x=hor//a
y=ver//b
if(x%2==y%2 and a<=n-1 and b<=m-1):
ans=min(ans,max(x,y))
#Corner (n,m)
hor=abs(i-n)
ver=abs(j-m)
if(hor%a==0 and ver%b==0):
x=hor//a
y=ver//b
if(x%2==y%2 and a<=n-1 and b<=m-1):
ans=min(ans,max(x,y))
#Corner (1,m)
hor=i-1
ver=abs(j-m)
if(hor%a==0 and ver%b==0):
x=hor//a
y=ver//b
if(x%2==y%2 and a<=n-1 and b<=m-1):
ans=min(ans,max(x,y))
#Corner (n,1)
hor=abs(n-i)
ver=j-1
if(hor%a==0 and ver%b==0):
x=hor//a
y=ver//b
if(x%2==y%2 and a<=n-1 and b<=m-1):
ans=min(ans,max(x,y))
if(ans!=100000000000):
print(ans)
else:
print("Poor Inna and pony!")
``` | vfc_11662 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/374/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7 1 3 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 2 3 1 1\n",
"output": "Poor Inna and pony!\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 478 | Solve the following coding problem using the programming language python:
You are given a string $s$ consisting of lowercase Latin letters. Let the length of $s$ be $|s|$. You may perform several operations on this string.
In one operation, you can choose some index $i$ and remove the $i$-th character of $s$ ($s_i$) if at least one of its adjacent characters is the previous letter in the Latin alphabet for $s_i$. For example, the previous letter for b is a, the previous letter for s is r, the letter a has no previous letters. Note that after each removal the length of the string decreases by one. So, the index $i$ should satisfy the condition $1 \le i \le |s|$ during each operation.
For the character $s_i$ adjacent characters are $s_{i-1}$ and $s_{i+1}$. The first and the last characters of $s$ both have only one adjacent character (unless $|s| = 1$).
Consider the following example. Let $s=$ bacabcab. During the first move, you can remove the first character $s_1=$ b because $s_2=$ a. Then the string becomes $s=$ acabcab. During the second move, you can remove the fifth character $s_5=$ c because $s_4=$ b. Then the string becomes $s=$ acabab. During the third move, you can remove the sixth character $s_6=$'b' because $s_5=$ a. Then the string becomes $s=$ acaba. During the fourth move, the only character you can remove is $s_4=$ b, because $s_3=$ a (or $s_5=$ a). The string becomes $s=$ acaa and you cannot do anything with it.
Your task is to find the maximum possible number of characters you can remove if you choose the sequence of operations optimally.
-----Input-----
The first line of the input contains one integer $|s|$ ($1 \le |s| \le 100$) — the length of $s$.
The second line of the input contains one string $s$ consisting of $|s|$ lowercase Latin letters.
-----Output-----
Print one integer — the maximum possible number of characters you can remove if you choose the sequence of moves optimally.
-----Examples-----
Input
8
bacabcab
Output
4
Input
4
bcda
Output
3
Input
6
abbbbb
Output
5
-----Note-----
The first example is described in the problem statement. Note that the sequence of moves provided in the statement is not the only, but it can be shown that the maximum possible answer to this test is $4$.
In the second example, you can remove all but one character of $s$. The only possible answer follows. During the first move, remove the third character $s_3=$ d, $s$ becomes bca. During the second move, remove the second character $s_2=$ c, $s$ becomes ba. And during the third move, remove the first character $s_1=$ b, $s$ becomes a.
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
input = stdin.readline
n = int(input())
s = list(input().strip())
for i in range(26):
char = chr(ord('z') - i)
prev = chr(ord('z') - i - 1)
updated = True
while updated:
updated = False
for idx in range(len(s)-1, -1, -1):
if s[idx] == char:
if idx < len(s)-1 and s[idx+1] == prev:
s.pop(idx)
updated = True
elif idx > 0 and s[idx-1] == prev:
s.pop(idx)
updated = True
print( n - len(s))
``` | vfc_11666 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1321/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\nbacabcab\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 479 | Solve the following coding problem using the programming language python:
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.
Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.
-----Input-----
The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20).
The next line contains n space-separated integers a_{i} (1 ≤ a_{i} ≤ 10^7) — the denominations of the bills that are used in the country. Numbers a_{i} follow in the strictly increasing order.
The next line contains integer q (1 ≤ q ≤ 20) — the number of requests for cash withdrawal that you will make.
The next q lines contain numbers x_{i} (1 ≤ x_{i} ≤ 2·10^8) — the sums of money in burles that you are going to withdraw from the ATM.
-----Output-----
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum.
-----Examples-----
Input
6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
Output
6
20
19
20
-1
3
-1
-1
Input
5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Output
1
1
1
2
2
2
2
-1
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())
a = set(map(int, input().split()))
q = int(input())
# def isIn(x, fm, to):
# if fm >= to:
# return a[fm] == x
# t = a[(fm+to) // 2]
# if t > x:
# return isIn(x, fm, (fm+to) // 2 - 1)
# elif t < x:
# return isIn(x, (fm+to) // 2 + 1, to)
# else:
# return True
for _ in range(q):
x = int(input())
if x in a:
print(1)
continue
found = False
for i in range(2, k + 1):
for j in range(1, i // 2 + 1):
for l in a:
t = x - l * j
if t % (i - j) != 0:
continue
# if isIn(t // (i - j), 0, n - 1):
if t // (i - j) in a:
print(i)
found = True
break
if found:
break
if found:
break
if not found:
print(-1)
``` | vfc_11670 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/524/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 20\n10 50 100 500 1000 5000\n8\n4200\n100000\n95000\n96000\n99000\n10100\n2015\n9950\n",
"output": "6\n20\n19\n20\n-1\n3\n-1\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n1 2 3 5 8\n8\n1\n3\n5\n7\n9\n11\n13\n15\n",
"output": "1\n1\n1\n2\n2\n2\n2\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n1 2 3 6 102\n10\n1\n4\n30\n1\n76\n114\n10\n13\n13\n4\n",
"output": "1\n2\n5\n1\n-1\n3\n3\n3\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n1 36 95\n10\n3\n1\n4212\n144\n4\n109\n6\n5\n2\n24\n",
"output": "3\n1\n-1\n4\n4\n4\n-1\n5\n2\n-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 481 | Solve the following coding problem using the programming language python:
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.
-----Input-----
The single line contains numbers n and x (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9) — the size of the table and the number that we are looking for in the table.
-----Output-----
Print a single number: the number of times x occurs in the table.
-----Examples-----
Input
10 5
Output
2
Input
6 12
Output
4
Input
5 13
Output
0
-----Note-----
A table for the second sample test is given below. The occurrences of number 12 are marked bold. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, x = map(int, input().split())
ans = 0
for i in range(n, 0, -1):
if x % i == 0 and x//i <= n:
ans += 1
print(ans)
``` | vfc_11678 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/577/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 12\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 482 | Solve the following coding problem using the programming language python:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions: the length of the password must be equal to n, the password should consist only of lowercase Latin letters, the number of distinct symbols in the password must be equal to k, any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
-----Input-----
The first line contains two positive integers n and k (2 ≤ n ≤ 100, 2 ≤ k ≤ min(n, 26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
-----Output-----
Print any password which satisfies all conditions given by Innokentiy.
-----Examples-----
Input
4 3
Output
java
Input
6 6
Output
python
Input
5 2
Output
phphp
-----Note-----
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
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())
print(('abcdefghijklmnopqrstuvwxyz'[:k] * n)[:n])
``` | vfc_11682 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/770/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n",
"output": "abca\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n",
"output": "abcdef\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n",
"output": "ababa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "aba\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n",
"output": "ababababab\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 483 | Solve the following coding problem using the programming language python:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, x_{i} is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
-----Input-----
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} ≤ 10^9) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
-----Output-----
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
-----Examples-----
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
-----Note-----
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
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=int(input())
s=input()
z=list(map(int,input().split()))
best = 10**9
for i in range(len(s)-1):
if s[i]=='R' and s[i+1]=='L':
best=min(best, z[i+1]-(z[i]+z[i+1])//2)
if best != 10**9:
print(best)
else:
print(-1)
``` | vfc_11686 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/699/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nRLRL\n2 4 6 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nLLR\n40 50 60\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nRLLR\n46 230 264 470\n",
"output": "92\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 484 | Solve the following coding problem using the programming language python:
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size x_{i} × y_{i}. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
-----Input-----
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers x_{i}, y_{i} (1 ≤ x_{i}, y_{i} ≤ 100).
-----Output-----
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
-----Examples-----
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
-----Note-----
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
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,a,b=R()
xy = [R() for _ in range(n)]
ans = 0
def f(xy1, xy2):
tans = 0
for _ in range(2):
for __ in range(2):
if (xy1[0]+xy2[0]<=a and max(xy1[1], xy2[1])<=b) or\
(max(xy1[0], xy2[0])<=a and xy1[1]+xy2[1]<=b):
tans=max(tans, xy1[0]*xy1[1] + xy2[0]*xy2[1])
xy2[0], xy2[1] = xy2[1], xy2[0]
xy1[0], xy1[1] = xy1[1], xy1[0]
return tans
for i in range(n):
for j in range(i+1,n):
ans=max(ans, f(xy[i], xy[j]))
print(ans)
``` | vfc_11690 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/837/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 2\n1 2\n2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10 9\n2 3\n1 1\n5 10\n9 11\n",
"output": "56\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10 10\n6 6\n7 7\n20 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n1 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 2\n1 1\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 100 100\n100 100\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 486 | Solve the following coding problem using the programming language python:
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.
Help Kurt find the maximum possible product of digits among all integers from $1$ to $n$.
-----Input-----
The only input line contains the integer $n$ ($1 \le n \le 2\cdot10^9$).
-----Output-----
Print the maximum product of digits among all integers from $1$ to $n$.
-----Examples-----
Input
390
Output
216
Input
7
Output
7
Input
1000000000
Output
387420489
-----Note-----
In the first example the maximum product is achieved for $389$ (the product of digits is $3\cdot8\cdot9=216$).
In the second example the maximum product is achieved for $7$ (the product of digits is $7$).
In the third example the maximum product is achieved for $999999999$ (the product of digits is $9^9=387420489$).
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())
def p(x):
ans = 1
while x > 0:
ans *= x % 10
x //= 10
return ans
ans = p(n)
for i in range(len(str(n))):
cans = 9 ** i * p((n // 10 ** i) - 1)
ans = max(ans, cans)
print(ans)
``` | vfc_11698 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1143/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "390\n",
"output": "216\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 487 | Solve the following coding problem using the programming language python:
Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are $n$ students in the school. Each student has exactly $k$ votes and is obligated to use all of them. So Awruk knows that if a person gives $a_i$ votes for Elodreip, than he will get exactly $k - a_i$ votes from this person. Of course $0 \le k - a_i$ holds.
Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows $a_1, a_2, \dots, a_n$ — how many votes for Elodreip each student wants to give. Now he wants to change the number $k$ to win the elections. Of course he knows that bigger $k$ means bigger chance that somebody may notice that he has changed something and then he will be disqualified.
So, Awruk knows $a_1, a_2, \dots, a_n$ — how many votes each student will give to his opponent. Help him select the smallest winning number $k$. In order to win, Awruk needs to get strictly more votes than Elodreip.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 100$) — the number of students in the school.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 100$) — the number of votes each student gives to Elodreip.
-----Output-----
Output the smallest integer $k$ ($k \ge \max a_i$) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.
-----Examples-----
Input
5
1 1 1 5 1
Output
5
Input
5
2 2 3 2 2
Output
5
-----Note-----
In the first example, Elodreip gets $1 + 1 + 1 + 5 + 1 = 9$ votes. The smallest possible $k$ is $5$ (it surely can't be less due to the fourth person), and it leads to $4 + 4 + 4 + 0 + 4 = 16$ votes for Awruk, which is enough to win.
In the second example, Elodreip gets $11$ votes. If $k = 4$, Awruk gets $9$ votes and loses to Elodreip.
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()))
s = sum(a)
for k in range(max(a), 999999):
vote = sum(k-x for x in a)
if vote > s: print(k); break
``` | vfc_11702 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1043/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 1 5 1\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 2 3 2 2\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100\n",
"output": "201",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n15 5\n",
"output": "21",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n12 5 4 3 4 4 9 2 14 13 1 6 6 6 6 3 1 14 1 10 4 9 12 3 1 6 5 6 9 14 4 1 10 5 15 8 5 11 13 2 10 11 8 12 8 15 2 8 6 3\n",
"output": "15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50\n",
"output": "101",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 488 | Solve the following coding problem using the programming language python:
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.
You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.
How many operations will you need to perform until the next operation does not have any points to delete?
-----Input-----
Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.
The number of the points is between 1 and 10^6.
-----Output-----
Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.
-----Examples-----
Input
aabb
Output
2
Input
aabcaa
Output
1
-----Note-----
In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.
In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
cur_len = 1
a = []
char = []
for i in range(1, len(s)):
if s[i] == s[i-1]: cur_len += 1
else:
a.append(cur_len)
char.append(s[i-1])
cur_len = 1
a.append(cur_len)
char.append(s[len(s)-1])
ans = 0
while len(a) > 1:
n = len(a)
inner_min = 100000000
for i in range(1,n-1):
if a[i] < inner_min: inner_min = a[i]
k = min(a[0], a[n-1],(inner_min + 1)//2)
#print("a: ", a, "; k = ", k)
b = []
new_char = []
for i in range(n):
if i == 0 or i == n-1:
if a[i] > k:
b.append(a[i]-k)
new_char.append(char[i])
else:
if a[i] > 2*k:
b.append(a[i] - 2*k)
new_char.append(char[i])
## print(b)
ans += k
if len(b) > 1:
c = [0]*n
newnew_char = [new_char[0]]
count = 0
for i in range(0,len(b)-1):
c[count] += b[i]
if new_char[i] == new_char[i+1]: continue
else:
count += 1
newnew_char.append(new_char[i+1])
if new_char[len(b)-2] == new_char[len(b) - 1]: c[count] += b[len(b)-1]
else:
#count += 1
newnew_char.append(new_char[i+1])
c[count] = b[len(b)-1]
a = c[:count+1]
char = newnew_char[:]
else:
a = b[:]
print(ans)
``` | vfc_11706 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/909/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aabb\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 489 | Solve the following coding problem using the programming language python:
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that a_{i}·a_{j}·a_{k} is minimum possible, are there in the array? Help him with it!
-----Input-----
The first line of input contains a positive integer number n (3 ≤ n ≤ 10^5) — the number of elements in array a. The second line contains n positive integer numbers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of a given array.
-----Output-----
Print one number — the quantity of triples (i, j, k) such that i, j and k are pairwise distinct and a_{i}·a_{j}·a_{k} is minimum possible.
-----Examples-----
Input
4
1 1 1 1
Output
4
Input
5
1 3 2 3 4
Output
2
Input
6
1 3 3 1 3 2
Output
1
-----Note-----
In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) is chosen, and there's only one way to choose indices.
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())
inp=input().split()
l=[]
for val in inp:
l.append(int(val))
l.sort()
count=3
while(count<n and l[count]==l[count-1]):
count+=1
if(l[2]!=l[1]):
print(count-2)
elif(l[2]!=l[0]):
print(((count-1)*(count-2))//2)
else:
print((count*(count-1)*(count-2))//6)
``` | vfc_11710 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/817/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 3 2 3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 3 3 1 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 490 | Solve the following coding problem using the programming language python:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
-----Input-----
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
-----Output-----
A single integer — the number of straight cuts Shiro needs.
-----Examples-----
Input
3
Output
2
Input
4
Output
5
-----Note-----
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts.
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())+1
if n==1: print(0)
else: print(n if n%2==1 else n//2)
``` | vfc_11714 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/979/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "5",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 491 | Solve the following coding problem using the programming language python:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
-----Input-----
The single line contains integer n (10 ≤ |n| ≤ 10^9) — the state of Ilya's bank account.
-----Output-----
In a single line print an integer — the maximum state of the bank account that Ilya can get.
-----Examples-----
Input
2230
Output
2230
Input
-10
Output
0
Input
-100003
Output
-10000
-----Note-----
In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0.
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 >= 0:
print(n)
else:
n = str(n)
print(max(int(n[:-1]), int(n[:-2] + n[-1])))
``` | vfc_11718 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/313/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2230\n",
"output": "2230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-100003\n",
"output": "-10000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "544883178\n",
"output": "544883178\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 492 | Solve the following coding problem using the programming language python:
[Image]
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
[Image]
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
-----Input-----
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 ≤ n ≤ 10^9) – the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
-----Output-----
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
-----Examples-----
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = input().split(' ')
n = int(input())
d = {'v': 0, '>': 1, '^': 2, '<': 3}
a, b = d[a], d[b]
ccw = bool((a + n) % 4 == b)
cw = bool((a - n) % 4 == b)
if cw and not ccw:
print('cw')
elif ccw and not cw:
print('ccw')
else:
print('undefined')
``` | vfc_11722 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/834/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "^ >\n1\n",
"output": "cw\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "< ^\n3\n",
"output": "ccw\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 493 | Solve the following coding problem using the programming language python:
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. [Image]
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string s_{i} is equal to "L", if the i-th domino has been pushed to the left; "R", if the i-th domino has been pushed to the right; ".", if the i-th domino has not been pushed.
It is guaranteed that if s_{i} = s_{j} = "L" and i < j, then there exists such k that i < k < j and s_{k} = "R"; if s_{i} = s_{j} = "R" and i < j, then there exists such k that i < k < j and s_{k} = "L".
-----Output-----
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
-----Examples-----
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
-----Note-----
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
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 = input().strip()
nextl = [-1] * n
lastr = [-1] * n
ll = -1
for i in range(n):
if a[i] == "R":
ll = i
if a[i] == "L":
ll = -1
lastr[i] = ll
nl = -1
for i in range(n - 1, -1, -1):
if a[i] == "L":
nl = i
if a[i] == "R":
nl = -1
nextl[i] = nl
ans = 0
#print(lastr)
#print(nextl)
for i in range(n):
if nextl[i] == lastr[i] == -1:
ans += 1
if nextl[i] == -1 or lastr[i] == -1:
continue
d1 = nextl[i] - i
d2 = i - lastr[i]
if d1 == d2:
ans += 1
print(ans)
``` | vfc_11726 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/405/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "14\n.L.R...LR..L..\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nR....\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n.\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nL\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nR\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 495 | Solve the following coding problem using the programming language python:
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
-----Input-----
The single line contains two integers a and k (1 ≤ a ≤ 10^18; 0 ≤ k ≤ 100).
-----Output-----
Print the maximum number that Pasha can get if he makes at most k swaps.
-----Examples-----
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, k = input().split()
k = int(k)
a = [i for i in a]
i = 0
while k > 0 and i < len(a):
m = a[i : i + k + 1].index(max(a[i : i + k + 1]))
if a[i + m] > a[i]:
k -= m
for j in range(i + m, i, -1):
a[j], a[j - 1] = a[j - 1], a[j]
i += 1
print("".join(a))
``` | vfc_11734 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/435/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1990 1\n",
"output": "9190\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "300 0\n",
"output": "300\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 496 | Solve the following coding problem using the programming language python:
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progression is a sequence a_1, a_1 + d, a_1 + 2d, ..., a_1 + (n - 1)d, where a_1 and d are any numbers.
Geometric progression is a sequence b_1, b_2 = b_1q, ..., b_{n} = b_{n} - 1q, where b_1 ≠ 0, q ≠ 0, q ≠ 1.
Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.
-----Input-----
The first line contains exactly four integer numbers between 1 and 1000, inclusively.
-----Output-----
Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.
Print 42 if the given sequence is not an arithmetic or geometric progression.
-----Examples-----
Input
836 624 412 200
Output
-12
Input
1 334 667 1000
Output
1333
-----Note-----
This problem contains very weak pretests!
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def isZ(a):
return a == int(a)
def geom(a,b,c,d):
if 0 in (a,b,c,d) and not (a==b==c==d==0):
return False
if(b/a==c/b==d/c):
nxt = d * (d/c)
if not isZ(nxt): return False
print(int(nxt))
return True
return False
def ar(a,b,c,d):
if(b-a==c-b==d-c):
print(int(2*d-c))
return True
return False
a,b,c,d = map(float,input().split())
if not geom(a,b,c,d) and not ar(a,b,c,d):
print(42)
``` | vfc_11738 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/328/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "836 624 412 200\n",
"output": "-12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 334 667 1000\n",
"output": "1333\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "501 451 400 350\n",
"output": "42\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 497 | Solve the following coding problem using the programming language python:
Ilya lives in a beautiful city of Chordalsk.
There are $n$ houses on the street Ilya lives, they are numerated from $1$ to $n$ from left to right; the distance between every two neighboring houses is equal to $1$ unit. The neighboring houses are $1$ and $2$, $2$ and $3$, ..., $n-1$ and $n$. The houses $n$ and $1$ are not neighboring.
The houses are colored in colors $c_1, c_2, \ldots, c_n$ so that the $i$-th house is colored in the color $c_i$. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.
Ilya wants to select two houses $i$ and $j$ so that $1 \leq i < j \leq n$, and they have different colors: $c_i \neq c_j$. He will then walk from the house $i$ to the house $j$ the distance of $(j-i)$ units.
Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.
Help Ilya, find this maximum possible distance.
-----Input-----
The first line contains a single integer $n$ ($3 \leq n \leq 300\,000$) — the number of cities on the street.
The second line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq n$) — the colors of the houses.
It is guaranteed that there is at least one pair of indices $i$ and $j$ so that $1 \leq i < j \leq n$ and $c_i \neq c_j$.
-----Output-----
Print a single integer — the maximum possible distance Ilya can walk.
-----Examples-----
Input
5
1 2 3 2 3
Output
4
Input
3
1 2 1
Output
1
Input
7
1 1 3 1 1 1 1
Output
4
-----Note-----
In the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of $5-1 = 4$ units.
In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of $1$ unit.
In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of $7-3 = 4$ units.
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,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return tuple(map(int, sys.stdin.readline().split()))
def LLI(): return [tuple(map(int, l.split())) for l in sys.stdin]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n = I()
a = LI()
b = a[0]
c = a[-1]
r = 0
for i in range(n-1,-1,-1):
if a[i] != b:
r = i
break
for i in range(n):
if a[i] != b:
t = n-1 - i
if r < t:
r = t
return r
print(main())
``` | vfc_11742 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1119/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 1 3 1 1 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 5 2 10 9 3 3 2 9 5\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 498 | Solve the following coding problem using the programming language python:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).
The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. [Image] The picture illustrates the first and the second samples.
Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
-----Input-----
The only line contains three integers n, m and k (1 ≤ n, m ≤ 10 000, 1 ≤ k ≤ 2nm) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
-----Output-----
Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
-----Examples-----
Input
4 3 9
Output
2 2 L
Input
4 3 24
Output
4 3 R
Input
2 4 4
Output
1 2 R
-----Note-----
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m, k = list(map(int, input().split()))
print((k - 1) // (2 * m) + 1, end=" ")
print((k - 1) % (2 * m) // 2 + 1, end=" ")
if ((k - 1) % (2 * m) % 2 == 0):
print("L")
else:
print("R")
``` | vfc_11746 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/748/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 9\n",
"output": "2 2 L\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 499 | Solve the following coding problem using the programming language python:
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card?
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.
The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
-----Output-----
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
-----Examples-----
Input
2
RB
Output
G
Input
3
GRG
Output
BR
Input
5
BBBBB
Output
B
-----Note-----
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n = int(input())
s = input()
b, g, r = [s.count(i) for i in "BGR"]
if min(b, g, r) > 0:
print("BGR")
return
if max(b, g, r) == n:
if b == n: print("B")
if g == n: print("G")
if r == n: print("R")
return
if max(b, g, r) == 1:
if b == 0: print("B")
if g == 0: print("G")
if r == 0: print("R")
return
if max(b, g, r) == n - 1:
if b == n - 1: print("GR")
if g == n - 1: print("BR")
if r == n - 1: print("BG")
return
print("BGR")
main()
``` | vfc_11750 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/626/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nRB\n",
"output": "G\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nGRG\n",
"output": "BR\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nBBBBB\n",
"output": "B\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 501 | Solve the following coding problem using the programming language python:
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.
Consider two infinite sets of numbers. The first set consists of odd positive numbers ($1, 3, 5, 7, \ldots$), and the second set consists of even positive numbers ($2, 4, 6, 8, \ldots$). At the first stage, the teacher writes the first number on the endless blackboard from the first set, in the second stage — the first two numbers from the second set, on the third stage — the next four numbers from the first set, on the fourth — the next eight numbers from the second set and so on. In other words, at each stage, starting from the second, he writes out two times more numbers than at the previous one, and also changes the set from which these numbers are written out to another.
The ten first written numbers: $1, 2, 4, 3, 5, 7, 9, 6, 8, 10$. Let's number the numbers written, starting with one.
The task is to find the sum of numbers with numbers from $l$ to $r$ for given integers $l$ and $r$. The answer may be big, so you need to find the remainder of the division by $1000000007$ ($10^9+7$).
Nazar thought about this problem for a long time, but didn't come up with a solution. Help him solve this problem.
-----Input-----
The first line contains two integers $l$ and $r$ ($1 \leq l \leq r \leq 10^{18}$) — the range in which you need to find the sum.
-----Output-----
Print a single integer — the answer modulo $1000000007$ ($10^9+7$).
-----Examples-----
Input
1 3
Output
7
Input
5 14
Output
105
Input
88005553535 99999999999
Output
761141116
-----Note-----
In the first example, the answer is the sum of the first three numbers written out ($1 + 2 + 4 = 7$).
In the second example, the numbers with numbers from $5$ to $14$: $5, 7, 9, 6, 8, 10, 12, 14, 16, 18$. Their sum is $105$.
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, mod):
res = 0
n1 = 1
n2 = 2
k = 1
now = 0
while n >= k:
if now == 0:
now = 1
res = (res + n1 * k + (k * (k - 1))) % mod
n -= k
k *= 2
n1 = n1 + k
else:
now = 0
res = (res + n2 * k + (k * (k - 1))) % mod
n -= k
k *= 2
n2 = n2 + k
if n == 0:
return res
if now == 0:
return (res + n1 * n + (n * (n - 1))) % mod
return (res + n2 * n + (n * (n - 1))) % mod
l, r = list(map(int, input().split()))
mod = 10 ** 9 + 7
print((f(r, mod) - f(l - 1, mod)) % mod)
``` | vfc_11758 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1151/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 14\n",
"output": "105",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "88005553535 99999999999\n",
"output": "761141116",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 502 | Solve the following coding problem using the programming language python:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
-----Input-----
The only line contains six integers a_{x}, a_{y}, b_{x}, b_{y}, c_{x}, c_{y} (|a_{x}|, |a_{y}|, |b_{x}|, |b_{y}|, |c_{x}|, |c_{y}| ≤ 10^9). It's guaranteed that the points are distinct.
-----Output-----
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
-----Note-----
In the first sample test, rotate the page around (0.5, 0.5) by $90^{\circ}$.
In the second sample test, you can't find any solution.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def read_ints():
return [int(i) for i in input().split()]
coords = read_ints()
a, b, c = [(coords[i], coords[i + 1]) for i in range(0, len(coords), 2)]
def length_sqr(a, b):
return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2
if length_sqr(a, b) != length_sqr(b, c):
print('No')
elif (c[0] - b[0]) * (b[1] - a[1]) == (c[1] - b[1]) * (b[0] - a[0]):
print('No')
else:
print('Yes')
``` | vfc_11762 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/851/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 1 1 1 1 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 0 0 1000 1000\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 2 0 3 0\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 0 0 4 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 503 | Solve the following coding problem using the programming language python:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.
He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.
A subsequence of length three is a combination of three such indexes i_1, i_2, i_3, that 1 ≤ i_1 < i_2 < i_3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.
A geometric progression with common ratio k is a sequence of numbers of the form b·k^0, b·k^1, ..., b·k^{r} - 1.
Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.
-----Input-----
The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·10^5), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains n integers a_1, a_2, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9) — elements of the sequence.
-----Output-----
Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.
-----Examples-----
Input
5 2
1 1 2 2 4
Output
4
Input
3 1
1 1 1
Output
1
Input
10 3
1 2 6 2 3 6 9 18 3 9
Output
6
-----Note-----
In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
import sys
from collections import defaultdict
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n, k = tokens.pop(), tokens.pop()
d1 = defaultdict(int)
d2 = defaultdict(int)
result = 0
for i in tokens:
result += d2[i * k]
d2[i] += d1[i * k]
d1[i] += 1
print(result)
main()
``` | vfc_11766 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/567/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 1 2 2 4\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n1 2 6 2 3 6 9 18 3 9\n",
"output": "6",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 504 | Solve the following coding problem using the programming language python:
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two numbers — its health hp_{i} and its damage dmg_{i}. Max also has two types of spells in stock: Doubles health of the creature (hp_{i} := hp_{i}·2); Assigns value of health of the creature to its damage (dmg_{i} := hp_{i}).
Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.
Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.
-----Input-----
The first line contains three integers n, a, b (1 ≤ n ≤ 2·10^5, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·10^5) — the number of creatures, spells of the first type and spells of the second type, respectively.
The i-th of the next n lines contain two number hp_{i} and dmg_{i} (1 ≤ hp_{i}, dmg_{i} ≤ 10^9) — description of the i-th creature.
-----Output-----
Print single integer — maximum total damage creatures can deal.
-----Examples-----
Input
2 1 1
10 15
6 1
Output
27
Input
3 0 3
10 8
7 11
5 2
Output
26
-----Note-----
In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27.
In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# python3
from sys import stdin
from collections import namedtuple
def readline(): return tuple(map(int, input().split()))
n, a, b = readline()
hand = [tuple(map(int, line.split())) for line in stdin.readlines()]
if not b:
print(sum(creature[1] for creature in hand))
else:
hand.sort(key=lambda self: self[0] - self[1])
best = 0
if n > b:
l = hand[n - b]
lost = max(0, l[0] - l[1])
for creature in hand[:n-b]:
best = max(best, (creature[0] << a) - creature[1] - lost)
for creature in hand[max(0,n-b):]:
best = max(best, (creature[0] << a) - max(creature))
print((sum(creature[1] for creature in hand)
+ sum(max(0, creature[0] - creature[1]) for creature in hand[max(0,n-b):])
+ best))
``` | vfc_11770 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/976/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 1\n10 15\n6 1\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0 3\n10 8\n7 11\n5 2\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 0\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 200000\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88\n",
"output": "3533\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 6 7\n11 75\n61 90\n22 14\n100 36\n29 48\n69 52\n16 3\n",
"output": "6720\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 505 | Solve the following coding problem using the programming language python:
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. Initially, the Robot is in the empty cell.
Your task is to find lexicographically minimal Robot's cycle with length exactly k, which begins and ends in the cell where the Robot was initially. It is allowed to the Robot to visit any cell many times (including starting).
Consider that Robot's way is given as a line which consists of symbols "L", "R", "U" and "D". For example, if firstly the Robot goes down, then left, then right and up, it means that his way is written as "DLRU".
In this task you don't need to minimize the length of the way. Find the minimum lexicographical (in alphabet order as in the dictionary) line which satisfies requirements above.
-----Input-----
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 10^6) — the size of the maze and the length of the cycle.
Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occupied by an obstacle. If the symbol equals to "X" then initially the Robot is in this cell and it is empty. It is guaranteed that the symbol "X" is found in the maze exactly once.
-----Output-----
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
-----Examples-----
Input
2 3 2
.**
X..
Output
RL
Input
5 6 14
..***.
*...X.
..*...
..*.**
....*.
Output
DLDDLLLRRRUURU
Input
3 3 4
***
*X*
***
Output
IMPOSSIBLE
-----Note-----
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less.
In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up.
In the third sample the Robot can't move to the neighboring cells, because they are occupied by obstacles.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
from collections import deque
def main():
n, m, k = list(map(int, input().split()))
grid = ["" for _ in range(n)]
x, y = 0, 0
for i in range(n):
grid[i] = input()
if 'X' in grid[i]:
x, y = i, grid[i].index('X')
if k % 2 == 1:
print("IMPOSSIBLE")
return
dx = [1, 0, 0, -1]
dy = [0, -1, 1, 0]
names = {(x1, y1): sym for x1, y1, sym in zip(dx, dy, "DLRU")}
rev_names = {x1: y1 for x1, y1 in zip("DLRU", "URLD")}
def ok(x, y):
return (0 <= x < n) and (0 <= y < m) and grid[x][y] != '*'
def bfs(x, y):
MAX_DIST = (1 << 20)
dist = [[MAX_DIST for y in range(m)] for x in range(n)]
dist[x][y] = 0
q = deque()
q.append((x, y))
while len(q) > 0:
x, y = q.popleft()
for x0, y0 in zip(dx, dy):
if ok(x + x0, y + y0) and dist[x][y] + 1 < dist[x + x0][y + y0]:
dist[x + x0][y + y0] = dist[x][y] + 1
q.append((x + x0, y + y0))
return dist
path = []
x_start, y_start = x, y
dist = bfs(x_start, y_start)
for i in range(k // 2):
for x1, y1 in zip(dx, dy):
if ok(x + x1, y + y1):
path.append(names.get((x1, y1)))
x += x1
y += y1
break
else:
print("IMPOSSIBLE")
return
moves = k // 2
for i in range(k // 2):
for x1, y1 in zip(dx, dy):
if ok(x + x1, y + y1) and dist[x + x1][y + y1] <= moves:
path.append(names.get((x1, y1)))
x += x1
y += y1
moves -= 1
break
print("".join(x for x in path))
def __starting_point():
main()
__starting_point()
``` | vfc_11774 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/769/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 2\n.**\nX..\n",
"output": "RL\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.\n",
"output": "DLDDLLLRRRUURU\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 506 | Solve the following coding problem using the programming language python:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
[Image]
After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm × b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
-----Input-----
The first line of the input contains two integers a, b (1 ≤ b < a ≤ 10^12) — the sizes of the original sheet of paper.
-----Output-----
Print a single integer — the number of ships that Vasya will make.
-----Examples-----
Input
2 1
Output
2
Input
10 7
Output
6
Input
1000000000000 1
Output
1000000000000
-----Note-----
Pictures to the first and second sample test.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = list(map(int, input().split()))
ans = 0
while a and b:
if a > b:
ans += a // b
a = a % b
else:
ans += b // a
b = b % a
print(ans)
``` | vfc_11778 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/527/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 507 | Solve the following coding problem using the programming language python:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation p_1, p_2, ..., p_{n} of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences a_1, a_2, ..., a_{n} and b_1, b_2, ..., b_{n} respectively. Meteoroids' colours were also between 1 and n inclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that a_{i} ≠ b_{i} holds.
Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that a_{i} ≠ p_{i}, and exactly one j (1 ≤ j ≤ n) such that b_{j} ≠ p_{j}.
For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.
-----Input-----
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) — the sequence of colours in the first meteor outburst.
The third line contains n space-separated integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that a_{i} ≠ b_{i} holds.
-----Output-----
Output n space-separated integers p_1, p_2, ..., p_{n}, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists.
-----Examples-----
Input
5
1 2 3 4 3
1 2 5 4 5
Output
1 2 5 4 3
Input
5
4 4 2 3 1
5 4 5 3 1
Output
5 4 2 3 1
Input
4
1 1 3 4
1 4 3 4
Output
1 2 3 4
-----Note-----
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
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()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
if a[i] != b[i]:
cnt += 1
if cnt == 1:
done = list(range(1,n+1))
x = 0
for i in range(n):
if a[i] == b[i]:
try:
done.remove(a[i])
except:
pass
else:
x = i
try:
done.remove(a[i])
except:
pass
try:
done.remove(b[i])
except:
pass
arr = a[::]
arr[x] = done[0]
for i in arr:
print(i,end = ' ')
else:
arr = a[::]
x = -1
y = -1
for i in range(n):
if a[i] == b[i]:
pass
else:
if x == -1:
x = i
else:
y = i
br = arr[::]
arr[x] = b[x]
br[y] = b[y]
if len(set(br)) == n:
arr = br[::]
for i in arr:
print(i,end = ' ')
``` | vfc_11782 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/814/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 3\n1 2 5 4 5\n",
"output": "1 2 5 4 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n4 4 2 3 1\n5 4 5 3 1\n",
"output": "5 4 2 3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 3 4\n1 4 3 4\n",
"output": "1 2 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10\n",
"output": "1 2 3 4 5 6 7 8 9 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 2 3 4 5 6 7 8 7 10\n1 2 3 4 5 6 7 8 9 9\n",
"output": "1 2 3 4 5 6 7 8 9 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 2 3 4 5 6 7 8 4 10\n1 2 3 4 5 6 7 6 9 10\n",
"output": "1 2 3 4 5 6 7 8 9 10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 508 | Solve the following coding problem using the programming language python:
On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v_1, v_2, v_3 such that the angle $\angle v_{1} v_{2} v_{3}$ (where v_2 is the vertex of the angle, and v_1 and v_3 lie on its sides) is as close as possible to a. In other words, the value $|\angle v_{1} v_{2} v_{3} - a|$ should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them.
-----Input-----
First and only line contains two space-separated integers n and a (3 ≤ n ≤ 10^5, 1 ≤ a ≤ 180) — the number of vertices in the polygon and the needed angle, in degrees.
-----Output-----
Print three space-separated integers: the vertices v_1, v_2, v_3, which form $\angle v_{1} v_{2} v_{3}$. If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order.
-----Examples-----
Input
3 15
Output
1 2 3
Input
4 67
Output
2 1 3
Input
4 68
Output
4 1 2
-----Note-----
In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
def read_ints():
return [int(i) for i in input().split()]
n, a = read_ints()
res = 1
for i in range(2, n - 1):
if abs(a - res * 180 / n) > abs(a - i * 180 / n):
res = i
print(2, 1, res + 2)
``` | vfc_11786 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/820/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 15\n",
"output": "2 1 3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 509 | Solve the following coding problem using the programming language python:
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $360$ degrees and a pointer which initially points at zero:
[Image]
Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $n$ times. The $i$-th rotation should be $a_i$ degrees, either clockwise or counterclockwise, and after all $n$ rotations the pointer should again point at zero.
This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $n$ rotations the pointer will point at zero again.
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 15$) — the number of rotations.
Each of the following $n$ lines contains one integer $a_i$ ($1 \leq a_i \leq 180$) — the angle of the $i$-th rotation in degrees.
-----Output-----
If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
10
20
30
Output
YES
Input
3
10
10
10
Output
NO
Input
3
120
120
120
Output
YES
-----Note-----
In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.
In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.
In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $360$ degrees clockwise and the pointer will point at zero again.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import getpass
import sys
def ria():
return [int(i) for i in input().split()]
if getpass.getuser() != 'frohenk':
filename = 'half'
# sys.stdin = open('input.txt')
# sys.stdout = open('output.txt', 'w')
else:
sys.stdin = open('input.txt')
# sys.stdin.close()
n = ria()[0]
ar = []
for i in range(n):
ar.append(ria()[0])
sm = sum(ar) / 2
for i in range(2 ** n):
c = 0
for j in range(n):
if i & (1 << j):
c += ar[j]
else:
c -= ar[j]
if c % 360 == 0:
print('YES')
return
print('NO')
``` | vfc_11790 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1097/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10\n20\n30\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n10\n10\n10\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 510 | Solve the following coding problem using the programming language python:
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.
The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $a$, $b$ and $c$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $d$.
Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $1$ (i. e. shift by $1$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".
You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $d$.
Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.
-----Input-----
The only line of the input contains four integers $a$, $b$, $c$, $d$ ($1 \le a, b, c, d \le 10^9$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.
-----Output-----
Output one integer — the minimum duration (in seconds) of the performance.
-----Examples-----
Input
5 2 6 3
Output
2
Input
3 1 5 6
Output
8
Input
8 3 3 2
Output
2
Input
2 3 10 4
Output
3
-----Note-----
In the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $8$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $|5 - 2| = 3$, the distance between Boniface and Konrad will be $|2 - 8| = 6$ and the distance between Agafon and Konrad will be $|5 - 8| = 3$. Therefore, all three pairwise distances will be at least $d=3$, so the performance could be finished within 2 seconds.
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: list(map(int, input().split()))
li = lambda: list(mi())
a, b, c, d = mi()
a, b, c = sorted([a, b, c])
ans = max(0, d - (b - a)) + max(0, d - (c - b))
print(ans)
``` | vfc_11794 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1185/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 6 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 5 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 3 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 10 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000 1000000000 1000000000 1000000000\n",
"output": "2000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "500000000 250000000 750000000 1000000000\n",
"output": "1500000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 513 | Solve the following coding problem using the programming language python:
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≤ i, j ≤ 3), except for point (x_2, y_2).
You have a set of eight points. Find out if Gerald can use this set?
-----Input-----
The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≤ x_{i}, y_{i} ≤ 10^6). You do not have any other conditions for these points.
-----Output-----
In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise.
-----Examples-----
Input
0 0
0 1
0 2
1 0
1 2
2 0
2 1
2 2
Output
respectable
Input
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
Output
ugly
Input
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
Output
ugly
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
X=[]
Y=[]
Points=[]
k=False
for i in range(8):
x,y=list(map(int,input().split()))
X.append(x)
Y.append(y)
if([x,y] in Points):
k=True
Points.append([x,y])
X.sort()
Y.sort()
if(len(set(X))!=3 or len(set(Y))!=3 or k):
print("ugly")
elif(X.count(X[0])!=3 or X.count(X[3])!=2 or X.count(X[5])!=3):
print("ugly")
elif(Y.count(Y[0])!=3 or Y.count(Y[3])!=2 or Y.count(Y[5])!=3):
print("ugly")
elif([X[3],Y[3]] in Points):
print("ugly")
else:
print("respectable")
``` | vfc_11806 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/334/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n",
"output": "respectable\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n",
"output": "ugly\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n",
"output": "ugly\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n",
"output": "ugly\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000 1000000\n1000000 999999\n1000000 999998\n999999 1000000\n999999 999998\n999998 1000000\n999998 999999\n999998 999998\n",
"output": "respectable\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n1 0\n0 1\n1 1\n0 2\n1 2\n0 3\n1 3\n",
"output": "ugly\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 514 | Solve the following coding problem using the programming language python:
Adilbek was assigned to a special project. For Adilbek it means that he has $n$ days to run a special program and provide its results. But there is a problem: the program needs to run for $d$ days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends $x$ ($x$ is a non-negative integer) days optimizing the program, he will make the program run in $\left\lceil \frac{d}{x + 1} \right\rceil$ days ($\left\lceil a \right\rceil$ is the ceiling function: $\left\lceil 2.4 \right\rceil = 3$, $\left\lceil 2 \right\rceil = 2$). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to $x + \left\lceil \frac{d}{x + 1} \right\rceil$.
Will Adilbek be able to provide the generated results in no more than $n$ days?
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 50$) — the number of test cases.
The next $T$ lines contain test cases – one per line. Each line contains two integers $n$ and $d$ ($1 \le n \le 10^9$, $1 \le d \le 10^9$) — the number of days before the deadline and the number of days the program runs.
-----Output-----
Print $T$ answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in $n$ days or NO (case insensitive) otherwise.
-----Example-----
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
-----Note-----
In the first test case, Adilbek decides not to optimize the program at all, since $d \le n$.
In the second test case, Adilbek can spend $1$ day optimizing the program and it will run $\left\lceil \frac{5}{2} \right\rceil = 3$ days. In total, he will spend $4$ days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program $2$ days, it'll still work $\left\lceil \frac{11}{2+1} \right\rceil = 4$ days.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for _ in range(t):
n, d = list(map(int, input().split()))
if (1 - n) ** 2 - 4 * (d - n) >= 0:
print('YES')
else:
print('NO')
``` | vfc_11810 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1288/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n4 5\n5 11\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 1\n3 2\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 1\n4 2\n4 3\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 1\n5 2\n5 3\n5 4\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n",
"output": "YES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n99999999 1000000000\n99999999 1000000000\n99999999 1000000000\n",
"output": "YES\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n17 81\n19 100\n23 144\n25 169\n29 225\n31 256\n32 271\n32 272\n33 289\n35 324\n37 361\n39 400\n41 441\n43 484\n46 551\n47 576\n49 625\n50 649\n50 650\n51 676\n53 729\n55 784\n57 841\n59 900\n65 1089\n67 1156\n68 1189\n68 1190\n69 1225\n70 1259\n70 1260\n71 1296\n73 1369\n77 1521\n79 1600\n83 1764\n85 1849\n86 1891\n86 1892\n87 1936\n89 2025\n91 2116\n95 2304\n97 2401\n98 2449\n98 2450\n99 2500\n100 2549\n100 2550\n101 2601\n",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000000000 99000000\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 515 | Solve the following coding problem using the programming language python:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.
He would like to find a positive integer n not greater than 10^18, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.
A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
$0123456789$
-----Input-----
The first and only line contains an integer k (1 ≤ k ≤ 10^6) — the desired number of loops.
-----Output-----
Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 10^18.
-----Examples-----
Input
2
Output
462
Input
6
Output
8080
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())
if k // 2 + k % 2 > 18:
print(-1)
else:
print('8' * (k // 2) + ('6' if k % 2 else ''))
``` | vfc_11814 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/934/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"output": "888\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "86\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "88\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "886\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 516 | Solve the following coding problem using the programming language python:
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?
Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.
Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly.
The second line contains n lowercase English letters — string s.
The third line contains m lowercase English letters — string t.
-----Output-----
In the first line print single integer k — the minimal number of symbols that need to be replaced.
In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.
-----Examples-----
Input
3 5
abc
xaybz
Output
2
2 3
Input
4 10
abcd
ebceabazcd
Output
1
2
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())
mi = 100000000000000
ts = ""
def num_d(a, b):
t = 0
for x in range(len(a)):
if a[x] != b[x]:
t += 1
return t
s, t = input(), input()
for x in range(m-n+1):
d = num_d(s, t[x:x+n])
if d < mi:
mi = d
ts = t[x:x+n]
print(mi)
for x in range(n):
if s[x] != ts[x]:
print(x+1, end=" ")
``` | vfc_11818 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/822/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\nabc\nxaybz\n",
"output": "2\n2 3 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 517 | Solve the following coding problem using the programming language python:
A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n.
Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values n, d and h:
The tree had exactly n vertices. The tree had diameter d. In other words, d was the biggest distance between two vertices. Limak also remembers that he once rooted the tree in vertex 1 and after that its height was h. In other words, h was the biggest distance between vertex 1 and some other vertex.
The distance between two vertices of the tree is the number of edges on the simple path between them.
Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".
-----Input-----
The first line contains three integers n, d and h (2 ≤ n ≤ 100 000, 1 ≤ h ≤ d ≤ n - 1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.
-----Output-----
If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).
Otherwise, describe any tree matching Limak's description. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.
-----Examples-----
Input
5 3 2
Output
1 2
1 3
3 4
3 5
Input
8 5 2
Output
-1
Input
8 4 2
Output
4 8
5 7
2 3
8 1
2 1
5 6
1 5
-----Note-----
Below you can see trees printed to the output in the first sample and the third sample.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import string
i = input()
i = i.split(' ')
n, d, h = list([int(x) for x in i])
def check(n, d, h):
if d > 2 * h:
print(-1)
return
if d < h:
print(-1)
return
if n < d + 1 or n < h + 1:
print(-1)
return
if d == 1 and n > 2:
print(-1)
return
out = []
#h
check(n, d, h)
c = 0
# print('h')
for i in range(h):
out.append(str(c + 1) + ' ' + str(c + 2))
# print(out[-1])
c += 1
c += 1
c1 = 0
# print('d')
for i in range(d - h):
out.append(str(c1 + 1) + ' ' + str(c + 1))
# print(out[-1])
c1 = c
c += 1
c += 1
# print('n')
if d == h:
s = 2
else:
s = 1
for i in range(n - c + 1):
out.append(str(s) + ' ' + str(c))
# print(out[-1])
c += 1
for el in out:
print(el)
``` | vfc_11822 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/639/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 2\n",
"output": "1 2\n2 3\n1 4\n5 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 5 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4 2\n",
"output": "4 8\n5 7\n2 3\n8 1\n2 1\n5 6\n1 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n",
"output": "1 2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 518 | Solve the following coding problem using the programming language python:
NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles: [Image]
It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar picture himself.
He managed to calculate the number of outer circles $n$ and the radius of the inner circle $r$. NN thinks that, using this information, you can exactly determine the radius of the outer circles $R$ so that the inner circle touches all of the outer ones externally and each pair of neighboring outer circles also touches each other. While NN tried very hard to guess the required radius, he didn't manage to do that.
Help NN find the required radius for building the required picture.
-----Input-----
The first and the only line of the input file contains two numbers $n$ and $r$ ($3 \leq n \leq 100$, $1 \leq r \leq 100$) — the number of the outer circles and the radius of the inner circle respectively.
-----Output-----
Output a single number $R$ — the radius of the outer circle required for building the required picture.
Your answer will be accepted if its relative or absolute error does not exceed $10^{-6}$.
Formally, if your answer is $a$ and the jury's answer is $b$. Your answer is accepted if and only when $\frac{|a-b|}{max(1, |b|)} \le 10^{-6}$.
-----Examples-----
Input
3 1
Output
6.4641016
Input
6 1
Output
1.0000000
Input
100 100
Output
3.2429391
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 sin
pi = 3.141592653589793238462643383279502884197
n, r = map(int,input().split())
theta = 2*pi / n
R = r / (1-sin(theta/2))
print(R-r)
``` | vfc_11826 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1100/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n",
"output": "6.4641016\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 1\n",
"output": "1.0000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 520 | Solve the following coding problem using the programming language python:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.
-----Input-----
The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined.
The next line contains n distinct integers a_1, a_2, ..., a_{n} (2010 ≤ a_{i} ≤ 2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.
-----Output-----
Print the year of Igor's university entrance.
-----Examples-----
Input
3
2014 2016 2015
Output
2015
Input
1
2050
Output
2050
-----Note-----
In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
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()))
print(sum(arr) // n)
``` | vfc_11834 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/769/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2014 2016 2015\n",
"output": "2015\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2050\n",
"output": "2050\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2010\n",
"output": "2010\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2011\n",
"output": "2011\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2010 2011 2012\n",
"output": "2011\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2049 2047 2048\n",
"output": "2048\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 521 | Solve the following coding problem using the programming language python:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into n consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
-----Input-----
The first line contains a single positive integer n (1 ≤ n ≤ 100) — the length of the canvas.
The second line contains a string s of n characters, the i-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
-----Output-----
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
-----Examples-----
Input
5
CY??Y
Output
Yes
Input
5
C?C?Y
Output
Yes
Input
5
?CYC?
Output
Yes
Input
5
C??MM
Output
No
Input
3
MMY
Output
No
-----Note-----
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
input()
s = input()
if 'MM' in s or 'YY' in s or 'CC' in s:
print ('No')
elif s.startswith('?') or s.endswith('?'):
print ('Yes')
elif '??' in s:
print ('Yes')
elif 'C?C' in s or 'M?M' in s or 'Y?Y' in s:
print ('Yes')
else:
print ('No')
``` | vfc_11838 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/957/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nCY??Y\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nC?C?Y\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n?CYC?\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nC??MM\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nMMY\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15\n??YYYYYY??YYYY?\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 522 | Solve the following coding problem using the programming language python:
Let $f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3}$ for $x \ge 4$.
You have given integers $n$, $f_{1}$, $f_{2}$, $f_{3}$, and $c$. Find $f_{n} \bmod (10^{9}+7)$.
-----Input-----
The only line contains five integers $n$, $f_{1}$, $f_{2}$, $f_{3}$, and $c$ ($4 \le n \le 10^{18}$, $1 \le f_{1}$, $f_{2}$, $f_{3}$, $c \le 10^{9}$).
-----Output-----
Print $f_{n} \bmod (10^{9} + 7)$.
-----Examples-----
Input
5 1 2 5 3
Output
72900
Input
17 97 41 37 11
Output
317451037
-----Note-----
In the first example, $f_{4} = 90$, $f_{5} = 72900$.
In the second example, $f_{17} \approx 2.28 \times 10^{29587}$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, f1, f2, f3, c = list(map(int,input().split()))
mat = [[1,1,1],[1,0,0],[0,1,0]]
final = [[1,0,0],[0,1,0],[0,0,1]]
nn = n - 3
N = 10**9 + 6
def prod(a, b):
m = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
for j in range(3):
m[i][j] = (a[i][0]*b[0][j] + a[i][1]*b[1][j]+a[i][2]*b[2][j]) % N
return m
while nn > 0:
if nn % 2 == 1:
final = prod(final, mat)
mat = prod(mat,mat)
nn //= 2
q = (final[0][0] * 3 + final[0][1] * 2 + final[0][2] * 1) % N
p = q - (n%N) + N
# p to potega c
ef3 = (final[0][0] * 1) % N
ef2 = (final[0][1] * 1) % N
ef1 = (final[0][2] * 1) % N
# print f1^ef1 *f2^ef2*f3^ef3 * c^p
def pot(a,w):
wyn = 1
while w > 0:
if w%2 == 1:
wyn = (wyn * a) % (N+1)
a = (a * a) % (N+1)
w //= 2
return wyn
l1 = pot(f1, ef1)
l2 = pot(f2, ef2)
l3 = pot(f3, ef3)
l4 = pot(c, p)
c = (l1*l2*l3*l4)%(N+1)
print(c)
``` | vfc_11842 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1182/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 1 2 5 3\n",
"output": "72900\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17 97 41 37 11\n",
"output": "317451037\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "607659049\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "27230 83472 9488 55320 2081\n",
"output": "791627460\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 523 | Solve the following coding problem using the programming language python:
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.
Gildong loves this concept so much, so he wants to play with it. He has $n$ distinct strings of equal length $m$. He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 50$) — the number of strings and the length of each string.
Next $n$ lines contain a string of length $m$ each, consisting of lowercase Latin letters only. All strings are distinct.
-----Output-----
In the first line, print the length of the longest palindrome string you made.
In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don't print this line at all.
-----Examples-----
Input
3 3
tab
one
bat
Output
6
tabbat
Input
4 2
oo
ox
xo
xx
Output
6
oxxxxo
Input
3 5
hello
codef
orces
Output
0
Input
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji
Output
20
ababwxyzijjizyxwbaba
-----Note-----
In the first example, "battab" is also a valid answer.
In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.
In the third example, the empty string is the only valid palindrome string.
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())
p = ''
q = []
arr = [input() for __ in range(n)]
s = set(arr)
for z in arr:
if z == z[::-1]:
p = z
else:
if z not in s: continue
if z[::-1] in s:
s.remove(z)
s.remove(z[::-1])
q += z,
res = ''.join(q)
res = res + p + res[::-1]
print(len(res))
print(res)
``` | vfc_11846 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1304/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\ntab\none\nbat\n",
"output": "6\ntabbat\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\noo\nox\nxo\nxx\n",
"output": "6\noxxxxo\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 524 | Solve the following coding problem using the programming language python:
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$, so that for every $0 \le i \le n-1$ then $a_i = c^i$.
Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$, you are allowed to: Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$), then Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$) with a cost of $1$.
Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.
-----Input-----
The first line contains an integer $n$ ($3 \le n \le 10^5$).
The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ($1 \le a_i \le 10^9$).
-----Output-----
Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.
-----Examples-----
Input
3
1 3 2
Output
1
Input
3
1000000000 1000000000 1000000000
Output
1999982505
-----Note-----
In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$, then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
if(n>65):
print(sum(a)-n)
elif(n==1 or n==2):
print(a[0]-1)
else:
ans=10**20
for i in range(1,50000):
now=1
ta=0
for j in a:
ta+=abs(now-j)
now*=i
ans=min(ans,ta)
print(ans)
``` | vfc_11850 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1397/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1000000000 1000000000 1000000000\n",
"output": "1999982505\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n51261 11877 300 30936722 84 75814681 352366 23 424 16392314 27267 832 4 562873474 33 516967731 158909407 32148531 66 757\n",
"output": "850575966\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 912387428 4\n",
"output": "45210\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits