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 | 183 | Solve the following coding problem using the programming language python:
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.
First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that: Decimal representation of x (without leading zeroes) consists of exactly n digits; There exists some integer y > 0 such that: $y \operatorname{mod} k = 0$; decimal representation of y is a suffix of decimal representation of x.
As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.
Can you help Amr escape this embarrassing situation?
-----Input-----
Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 10^9).
-----Output-----
Print the required number modulo m.
-----Examples-----
Input
1 2 1000
Output
4
Input
2 2 1000
Output
45
Input
5 3 1103
Output
590
-----Note-----
A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,k,m=list(map(int,input().split()))
d,r,p,P=0,0,1%k,(10**(n-1))*9
F=[0]*k
F[0]=1
while d<n:
d+=1
P//=10
E=[0]*k
if P==0:P=1
i=1
# print("E=",E)
# print("F=",F)
while i<10:
j=(-i*p)%k
f=0
while f<k:
E[f]+=F[j]
f+=1
j+=1
if j==k:j=0
i+=1
r+=E[0]*P
p=p*10%k
E[0]=0
i=1
while i<k:
F[i]=(F[i]+E[i])%m
i+=1
# print(E,P)
F[0]=1
#print("r=",r)
print(r%m)
#i=10**n
#j=10**(n-1)
#r=0
#F=[0]*k
#while j<i:
# x=str(j)
# l=len(x)
# a=l
# while a:
# a-=1
# s=int(x[a:l])
# if s>0 and s%k==0:
# r+=1
# break
# j+=1
#print()
#print(r)
"""
3 6 9
13 16 19 12 15 18
23 26 29 21 24 27
33 36 39 30
43 46 49 42 45 48
53 56 59 51 54 57
63 66 69 60
73 76 79 72 75 78
83 86 89 81 84 87
93 96 99 90
"""
``` | vfc_10486 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/507/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 1000\n",
"output": "4",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 184 | Solve the following coding problem using the programming language python:
You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
-----Input-----
The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
-----Output-----
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
-----Examples-----
Input
1 4 2
Output
6
Input
5 5 5
Output
14
Input
0 2 0
Output
0
-----Note-----
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import base64
import zlib
pro = base64.decodebytes("""eJxtUUFuwyAQvPOKVarKkDhOm2MlX/uC3qqqAhs7KBgswGr6+y4QrLqqL7DD7OzMWk2zdQFGGWbu
PVG59N/rdeLhUu6Om95OpVJBumCtXqlCedkFQgalpYcW3twiSS/FMmLxyrWXhKihzGrwXLx0lEHb
QjU4e5HmWgHOgKTwQgC/0p/EIoDeGh96ZRC0szR0F6QPjTI7lt4fCsMuoVCqREGgqqH6qjIxBSZo
cADdTZTXIFie6dCZM8BhDwJOp7SDZuz6zLn3OMXplv+uTKCKwWAdKECDysxLoKzxs1Z4fpRObkb5
6ZfNTDSDbimlAo44+QDPLI4+MzRBYy1Yto0bxPqINTzCOe7uKSsUlQPKFJFzFtmkWlN3dhKcmhpu
2xw05R14FyyG1NSwdQm/QJxwY/+93OKGdA2uRgtt3hPp1RALLjzV2OkYmZSJCB40ku/AISORju2M
XOEPkISOLVzJ/ShtPCedXfwLCdxjfPIDQSHUSQ==
""".encode())
pro = zlib.decompress(pro)
pro = pro.decode()
exec(pro)
``` | vfc_10490 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/950/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 4 2\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 185 | Solve the following coding problem using the programming language python:
Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.
There are $n$ manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the $k$-th manhole from the left. She is thinking what to do.
In one turn, Nastya can do one of the following: if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong). go to a neighboring manhole; if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves).
[Image] The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it).
Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.
Note one time more that Nastya can open a manhole only when there are no stones onto it.
-----Input-----
The first and only line contains two integers $n$ and $k$, separated by space ($2 \leq n \leq 5000$, $1 \leq k \leq n$) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the $n$ manholes.
-----Output-----
Print a single integer — minimum number of moves which lead Nastya to pick all the coins.
-----Examples-----
Input
2 2
Output
6
Input
4 2
Output
13
Input
5 1
Output
15
-----Note-----
Let's consider the example where $n = 2$, $k = 2$. Nastya should play as follows:
At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole. Then she opens the second manhole and pick the coin from it. Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it.
So, $6$ moves are required to win.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = list(map(int,input().split()))
if k == 1 or k == n:
print(3 * n)
else:
print(3 * n + min(k - 1, n - k))
``` | vfc_10494 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1136/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 186 | Solve the following coding problem using the programming language python:
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
-----Input-----
The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
-----Output-----
Print a single integer, denoting the minimum possible height of the tallest tower.
-----Examples-----
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
-----Note-----
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
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()))
start = 0
end = 10**10
while (end - start > 1):
mid = (end + start) // 2
two = mid // 2 - mid // 6
three = mid // 3 - mid // 6
six = mid // 6
nn = n
mm = m
nn -= two
mm -= three
nn = max(nn, 0)
mm = max(mm, 0)
if (six >= nn + mm):
end = mid
else:
start = mid
print(end)
``` | vfc_10498 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/626/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1000000\n",
"output": "3000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 187 | Solve the following coding problem using the programming language python:
Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number.
The following n lines contain a sequence of integers a_1, a_2, ..., a_{n} (one integer per line, 1 ≤ a_{i} ≤ 100) — numbers written on the n cards.
-----Output-----
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
-----Examples-----
Input
4
11
27
27
11
Output
YES
11 27
Input
2
6
6
Output
NO
Input
6
10
20
30
20
10
20
Output
NO
Input
6
1
1
2
2
3
3
Output
NO
-----Note-----
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
b = list(set(a[::]))
if(len(b) == 2 and a.count(a[0]) == n//2):
print("YES")
print(b[0],b[1])
else: print("NO")
``` | vfc_10502 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/864/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n11\n27\n27\n11\n",
"output": "YES\n11 27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n6\n6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n10\n20\n30\n20\n10\n20\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1\n1\n2\n2\n3\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n100\n",
"output": "YES\n1 100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 188 | Solve the following coding problem using the programming language python:
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a_{i} soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.
[Image] A row in the airplane
Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.
Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.
The second line contains k integers a_1, a_2, a_3, ..., a_{k} (1 ≤ a_{i} ≤ 10000), where a_{i} denotes the number of soldiers in the i-th group.
It is guaranteed that a_1 + a_2 + ... + a_{k} ≤ 8·n.
-----Output-----
If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).
You can choose the case (lower or upper) for each letter arbitrary.
-----Examples-----
Input
2 2
5 8
Output
YES
Input
1 2
7 1
Output
NO
Input
1 2
4 4
Output
YES
Input
1 4
2 2 1 2
Output
YES
-----Note-----
In the first sample, Daenerys can place the soldiers like in the figure below:
[Image]
In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.
In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.
In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def r():
return list(map(int, input().split()))
n, k = list(map(int, input().split()))
a = r()
cnt4 = n
cnt2 = 2*n
cnt1 = 0
for i in range(k):
x = min((a[i]+1)//4, cnt4)
cnt4 -= x
a[i] = max(0, a[i]-4*x)
cnt2 += cnt4
cnt1 += cnt4
for i in range(k):
x = min(a[i]//2, cnt2)
cnt2 -= x
a[i] = max(0, a[i]-2*x)
cnt1 += cnt2
for i in range(k):
cnt1 -= a[i]
if (cnt1 < 0):
print('NO')
else:
print('YES')
``` | vfc_10506 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/839/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n5 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n7 1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 189 | Solve the following coding problem using the programming language python:
Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$.
For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to $b$ is $|a - b|$, where $|x|$ means the absolute value of $x$.
A stick length $a_i$ is called almost good for some integer $t$ if $|a_i - t| \le 1$.
Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer $t$ and the total cost of changing is minimum possible. The value of $t$ is not fixed in advance and you can choose it as any positive integer.
As an answer, print the value of $t$ and the minimum cost. If there are multiple optimal choices for $t$, print any of them.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 1000$) — the number of sticks.
The second line contains $n$ integers $a_i$ ($1 \le a_i \le 100$) — the lengths of the sticks.
-----Output-----
Print the value of $t$ and the minimum possible cost. If there are multiple optimal choices for $t$, print any of them.
-----Examples-----
Input
3
10 1 4
Output
3 7
Input
5
1 1 2 2 3
Output
2 0
-----Note-----
In the first example, we can change $1$ into $2$ and $10$ into $4$ with cost $|1 - 2| + |10 - 4| = 1 + 6 = 7$ and the resulting lengths $[2, 4, 4]$ are almost good for $t = 3$.
In the second example, the sticks lengths are already almost good for $t = 2$, so we don't have to do anything.
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()))
t = 0
mn = 1000000000
for i in range(1,100):
cur = 0
for j in range(n):
cur += max(0,abs(i-a[j])-1)
if cur < mn:
mn = cur
t = i
print(t,mn)
``` | vfc_10510 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1105/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 1 4\n",
"output": "3 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 2 2 3\n",
"output": "2 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n",
"output": "4 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "1 0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 190 | Solve the following coding problem using the programming language python:
Карта звёздного неба представляет собой прямоугольное поле, состоящее из n строк по m символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда).
Новое издание карты звёздного неба будет напечатано на квадратных листах, поэтому требуется найти минимально возможную сторону квадрата, в который могут поместиться все звезды. Границы искомого квадрата должны быть параллельны сторонам заданного прямоугольного поля.
-----Входные данные-----
В первой строке входных данных записаны два числа n и m (1 ≤ n, m ≤ 1000) — количество строк и столбцов на карте звездного неба.
В следующих n строках задано по m символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда).
Гарантируется, что на небе есть хотя бы одна звезда.
-----Выходные данные-----
Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды.
-----Примеры-----
Входные данные
4 4
....
..*.
...*
..**
Выходные данные
3
Входные данные
1 3
*.*
Выходные данные
3
Входные данные
2 1
.
*
Выходные данные
1
-----Примечание-----
Один из возможных ответов на первый тестовый пример:
[Image]
Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба):
[Image]
Ответ на третий тестовый пример:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = input().split()
n = int(n)
m = int(m)
a = []
N = n
for i in range(n) :
a.append(input().split())
for i in range(n) :
if a[i][0].find('*') == -1 :
n-=1
else :
break
if n != 1 :
for i in range(len(a)-1,-1,-1) :
if a[i][0].find('*') == -1 :
n-=1
else :
break
#print(n)
M = m
br = 0
for i in range(m) :
count = 0
for j in range(len(a)) :
if a[j][0][i] != ('*') :
count+=1
else :
br = 1
break
if br == 1 :
break
if count == N :
m-=1
br = 0
if m != 1 :
for i in range(M-1,-1,-1) :
count = 0
for j in range(len(a)) :
if a[j][0][i] != ('*') :
count+=1
else :
br = 1
break
if br == 1 :
break
if count == N :
m-=1
#print(m)
if m > n :
print(m)
else :
print(n)
``` | vfc_10514 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/647/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n....\n..*.\n...*\n..**\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 3\n*.*\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n.\n*\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n*\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n.*\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n*.\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 191 | Solve the following coding problem using the programming language python:
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and the number $k$. Exactly $k$ times the following happens: Two numbers $i$ and $j$ are chosen equiprobable such that ($1 \leq i < j \leq n$). The numbers in the $i$ and $j$ positions are swapped.
Sonya's task is to find the probability that after all the operations are completed, the $a$ array will be sorted in non-decreasing order. She turned to you for help. Help Sonya solve this problem.
It can be shown that the desired probability is either $0$ or it can be represented as $\dfrac{P}{Q}$, where $P$ and $Q$ are coprime integers and $Q \not\equiv 0~\pmod {10^9+7}$.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \leq n \leq 100, 1 \leq k \leq 10^9$) — the length of the array $a$ and the number of operations.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$) — the description of the array $a$.
-----Output-----
If the desired probability is $0$, print $0$, otherwise print the value $P \cdot Q^{-1}$ $\pmod {10^9+7}$, where $P$ and $Q$ are defined above.
-----Examples-----
Input
3 2
0 1 0
Output
333333336
Input
5 1
1 1 1 0 0
Output
0
Input
6 4
1 0 0 1 1 0
Output
968493834
-----Note-----
In the first example, all possible variants of the final array $a$, after applying exactly two operations: $(0, 1, 0)$, $(0, 0, 1)$, $(1, 0, 0)$, $(1, 0, 0)$, $(0, 1, 0)$, $(0, 0, 1)$, $(0, 0, 1)$, $(1, 0, 0)$, $(0, 1, 0)$. Therefore, the answer is $\dfrac{3}{9}=\dfrac{1}{3}$.
In the second example, the array will not be sorted in non-decreasing order after one operation, therefore 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, T = list(map(int, input().split()))
A = [int(a) for a in input().split()]
if sum(A) > N//2:
A = [1-a for a in A][::-1]
K = sum(A)
S = sum(A[-K:])
M = K + 1
P = 10**9+7
inv = pow(N*(N-1)//2, P-2, P)
X = [[0]*M for _ in range(M)]
for i in range(M):
if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P
if i < M-1: X[i+1][i] = (N-2*K+i+1)*(i+1)*inv%P
X[i][i] = (1-((K-i)**2*inv)-(N-2*K+i)*(i)*inv)%P
def ddd(n):
for i in range(1, 100):
if (n*i%P) < 100:
return (n*i%P), i
return -1, -1
def poww(MM, n):
if n == 1:
return MM
if n % 2:
return mult(poww(MM, n-1), MM)
return poww(mult(MM,MM), n//2)
def mult(M1, M2):
Y = [[0] * M for _ in range(M)]
for i in range(M):
for j in range(M):
for k in range(M):
Y[i][j] += M1[i][k] * M2[k][j]
Y[i][j] %= P
return Y
X = poww(X, T)
print(X[S][K])
``` | vfc_10518 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1151/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n0 1 0\n",
"output": "333333336",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n1 1 1 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 4\n1 0 0 1 1 0\n",
"output": "968493834",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 193 | Solve the following coding problem using the programming language python:
The determinant of a matrix 2 × 2 is defined as follows:$\operatorname{det} \left(\begin{array}{ll}{a} & {b} \\{c} & {d} \end{array} \right) = a d - b c$
A matrix is called degenerate if its determinant is equal to zero.
The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements.
You are given a matrix $A = \left(\begin{array}{ll}{a} & {b} \\{c} & {d} \end{array} \right)$. Consider any degenerate matrix B such that norm ||A - B|| is minimum possible. Determine ||A - B||.
-----Input-----
The first line contains two integers a and b (|a|, |b| ≤ 10^9), the elements of the first row of matrix A.
The second line contains two integers c and d (|c|, |d| ≤ 10^9) the elements of the second row of matrix A.
-----Output-----
Output a single real number, the minimum possible value of ||A - B||. Your answer is considered to be correct if its absolute or relative error does not exceed 10^{ - 9}.
-----Examples-----
Input
1 2
3 4
Output
0.2000000000
Input
1 0
0 1
Output
0.5000000000
-----Note-----
In the first sample matrix B is $\left(\begin{array}{ll}{1.2} & {1.8} \\{2.8} & {4.2} \end{array} \right)$
In the second sample matrix B is $\left(\begin{array}{ll}{0.5} & {0.5} \\{0.5} & {0.5} \end{array} \right)$
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def seg(x, y, h):
A = [x - h, x + h]
B = [y - h, y + h]
Z = []
for a in A:
for b in B:
Z.append(a * b)
Z.sort()
return (Z[0], Z[-1])
def check(a, b, c, d, h):
x1, y1 = seg(a, d, h)
x2, y2 = seg(b, c, h)
return max(x1, x2) <= min(y1, y2)
a, b = list(map(int, input().split()))
c, d = list(map(int, input().split()))
l = 0
r = max(abs(a), abs(b), abs(c), abs(d))
for i in range(100):
m = (l + r) / 2
if check(a, b, c, d, m):
r = m
else:
l = m
print((r + l) / 2)
``` | vfc_10526 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/549/H",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n3 4\n",
"output": "0.2000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 194 | Solve the following coding problem using the programming language python:
In a small restaurant there are a tables for one person and b tables for two persons.
It it known that n groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.
If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.
You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.
-----Input-----
The first line contains three integers n, a and b (1 ≤ n ≤ 2·10^5, 1 ≤ a, b ≤ 2·10^5) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers t_1, t_2, ..., t_{n} (1 ≤ t_{i} ≤ 2) — the description of clients in chronological order. If t_{i} is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.
-----Output-----
Print the total number of people the restaurant denies service to.
-----Examples-----
Input
4 1 2
1 2 1 1
Output
0
Input
4 1 1
1 1 2 1
Output
2
-----Note-----
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.
In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
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()))
l = input().split()
o = 0
c = 0
for i in l:
if i == '2':
if b > 0:
b -= 1
else:
o += 2
if i == '1':
if a > 0:
a -= 1
elif b > 0:
b -= 1
c += 1
elif c > 0:
c -= 1
else:
o += 1
print(o)
``` | vfc_10530 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/828/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 2\n1 2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1 1\n1 1 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 2\n2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 3\n1 2 2 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 6 1\n1 1 1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 195 | Solve the following coding problem using the programming language python:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
-----Input-----
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
-----Output-----
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
-----Examples-----
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
-----Note-----
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
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,n=list(map(int,input().split()))
x=a+b-c
print(n-x if c<=a and c<=b and x<n else -1)
``` | vfc_10534 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/991/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 10 5 20\n",
"output": "5",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 196 | Solve the following coding problem using the programming language python:
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).
Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year.
Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.
Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 10^9 + 7, because it is easy to see that it is always integer.
-----Input-----
The only line contains two integers x and k (0 ≤ x, k ≤ 10^18), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.
-----Output-----
In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 10^9 + 7.
-----Examples-----
Input
2 0
Output
4
Input
2 1
Output
7
Input
3 2
Output
21
-----Note-----
In the first example a year consists on only one month, so the wardrobe does not eat dresses at all.
In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x, k = map(int, input().split())
if x == 0:
print(0)
else:
mod = 10 ** 9 + 7
p = pow(2, k, mod)
ans = (x * (p * 2) - (p - 1)) % mod
print(ans)
``` | vfc_10538 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/992/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 0\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 197 | Solve the following coding problem using the programming language python:
An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared $n$ problems; and since the platform is very popular, $998244351$ coder from all over the world is going to solve them.
For each problem, the authors estimated the number of people who would solve it: for the $i$-th problem, the number of accepted solutions will be between $l_i$ and $r_i$, inclusive.
The creator of ForceCoders uses different criteria to determine if the contest is good or bad. One of these criteria is the number of inversions in the problem order. An inversion is a pair of problems $(x, y)$ such that $x$ is located earlier in the contest ($x < y$), but the number of accepted solutions for $y$ is strictly greater.
Obviously, both the creator of ForceCoders and the authors of the contest want the contest to be good. Now they want to calculate the probability that there will be no inversions in the problem order, assuming that for each problem $i$, any integral number of accepted solutions for it (between $l_i$ and $r_i$) is equally probable, and all these numbers are independent.
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 50$) — the number of problems in the contest.
Then $n$ lines follow, the $i$-th line contains two integers $l_i$ and $r_i$ ($0 \le l_i \le r_i \le 998244351$) — the minimum and maximum number of accepted solutions for the $i$-th problem, respectively.
-----Output-----
The probability that there will be no inversions in the contest can be expressed as an irreducible fraction $\frac{x}{y}$, where $y$ is coprime with $998244353$. Print one integer — the value of $xy^{-1}$, taken modulo $998244353$, where $y^{-1}$ is an integer such that $yy^{-1} \equiv 1$ $(mod$ $998244353)$.
-----Examples-----
Input
3
1 2
1 2
1 2
Output
499122177
Input
2
42 1337
13 420
Output
578894053
Input
2
1 1
0 0
Output
1
Input
2
1 1
1 1
Output
1
-----Note-----
The real answer in the first test is $\frac{1}{2}$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from bisect import bisect_left
M = 998244353
def pw(x, y):
if y == 0:
return 1
res = pw(x, y//2)
res = res * res % M
if y % 2 == 1:
res = res * x % M
return res
def cal(x, y):
y += x - 1
res = 1
for i in range(1, x + 1):
res = res * (y - i + 1)
res = res * pw(i, M - 2) % M
return res % M
n = int(input())
a = []
b = []
res = 1
for i in range(n):
a.append(list(map(int, input().split())))
res = res * (a[-1][1] + 1 - a[-1][0]) % M
b.append(a[-1][0])
b.append(a[-1][1] + 1)
b = set(b)
b = sorted(list(b))
g = [b[i + 1] - b[i] for i in range(len(b) - 1)]
for i in range(n):
a[i][0] = bisect_left(b, a[i][0])
a[i][1] = bisect_left(b, a[i][1] + 1)
a = a[::-1]
f = [[0 for _ in range(len(b))] for __ in range(n)]
for i in range(a[0][0], len(b)):
if i == 0:
f[0][i] = g[i]
else:
if i < a[0][1]:
f[0][i] = (f[0][i - 1] + g[i]) % M
else:
f[0][i] = f[0][i - 1]
for i in range(1, n):
for j in range(a[i][0], len(b)):
if j > 0:
f[i][j] = f[i][j - 1]
if j < a[i][1]:
for k in range(i, -1, -1):
if a[k][1] <= j or j < a[k][0]:
break
if k == 0 or j != 0:
tmp = cal(i - k + 1, g[j])
if k > 0:
f[i][j] += f[k - 1][j - 1] * tmp % M
else:
f[i][j] += tmp
f[i][j] %= M
#print(f)
#print(f[n - 1][len(b) - 1], res)
print(f[n - 1][len(b) - 1] * pw(res, M - 2) % M)
``` | vfc_10542 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1295/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2\n1 2\n1 2\n",
"output": "499122177\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n42 1337\n13 420\n",
"output": "578894053\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 198 | Solve the following coding problem using the programming language python:
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 2·10^9) — the length of Pasha's stick.
-----Output-----
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
-----Examples-----
Input
6
Output
1
Input
20
Output
4
-----Note-----
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x = int(input())
if x%2==1:
print(0)
quit()
if x%2 ==0:
x//=2
if x%2==0:
print(x//2-1)
else:
print(x//2)
``` | vfc_10546 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/610/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 199 | Solve the following coding problem using the programming language python:
The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by $s$ liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by $s$ liters of kvass.
-----Input-----
The first line contains two integers $n$ and $s$ ($1 \le n \le 10^3$, $1 \le s \le 10^{12}$) — the number of kegs and glass volume.
The second line contains $n$ integers $v_1, v_2, \ldots, v_n$ ($1 \le v_i \le 10^9$) — the volume of $i$-th keg.
-----Output-----
If the Fair Nut cannot pour his glass by $s$ liters of kvass, print $-1$. Otherwise, print a single integer — how much kvass in the least keg can be.
-----Examples-----
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
-----Note-----
In the first example, the answer is $3$, the Fair Nut can take $1$ liter from the first keg and $2$ liters from the third keg. There are $3$ liters of kvass in each keg.
In the second example, the answer is $2$, the Fair Nut can take $3$ liters from the first keg and $1$ liter from the second keg.
In the third example, the Fair Nut can't pour his cup by $7$ liters, so the answer is $-1$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def doit():
xx = input().split()
n = int(xx[0])
s = int(xx[1])
v = [int(k) for k in input().split()]
S = sum(v)
newS = S - s
if newS < 0:
return -1
return min(newS//n, min(v))
print(doit())
``` | vfc_10550 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1084/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n4 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 200 | Solve the following coding problem using the programming language python:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h_1 cm from the ground. On the height h_2 cm (h_2 > h_1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
-----Input-----
The first line contains two integers h_1, h_2 (1 ≤ h_1 < h_2 ≤ 10^5) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 10^5) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
-----Output-----
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
-----Examples-----
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
-----Note-----
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
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 *
h1, h2 = [int(i) for i in input().split()]
a, b = [int(i) for i in input().split()]
a *= 12
b *= 12
if a <= b and h2 - h1 > (a // 12 * 8):
print(-1)
return
h1 += (a // 12 * 8)
if h1 >= h2:
print(0)
return
day = int(ceil((h2 - h1) / (a - b)))
print(day)
``` | vfc_10554 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/652/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 30\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 13\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 19\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 50\n5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1000\n2 1\n",
"output": "82\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999 1000\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 201 | Solve the following coding problem using the programming language python:
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? [Image]
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs W_{r} grams and each blue candy weighs W_{b} grams. Eating a single red candy gives Om Nom H_{r} joy units and eating a single blue candy gives Om Nom H_{b} joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
-----Input-----
The single line contains five integers C, H_{r}, H_{b}, W_{r}, W_{b} (1 ≤ C, H_{r}, H_{b}, W_{r}, W_{b} ≤ 10^9).
-----Output-----
Print a single integer — the maximum number of joy units that Om Nom can get.
-----Examples-----
Input
10 3 5 2 3
Output
16
-----Note-----
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
f = sys.stdin
C, Hr, Hb, Wr, Wb = map(int, f.readline().strip().split())
if Hr/Wr < Hb/Wb:
Hr, Hb, Wr, Wb = Hb, Hr, Wb, Wr
if (C % Wr) == 0 and (C // Wr) > 0:
print((C // Wr)*Hr)
elif (C // Wr) == 0:
print((C // Wb)*Hb)
else:
nmax = (C // Wr)
pmax = nmax*Hr + ((C - nmax*Wr) // Wb) * Hb
dmax = ((C - (nmax-0)*Wr) % Wb)
#print(0, pmax, dmax)
#
#pm1 = (nmax-1)*Hr + ((C - (nmax-1)*Wr) // Wb) * Hb
#if pm1>pmax:
# pmax = pm1
if Hr/Wr > Hb/Wb:
dx = dmax * (Hb/Wb) / (Hr/Wr - Hb/Wb)
elif Hr/Wr < Hb/Wb:
dx = 0
else:
dx = Wb * Wr
if Wr<Wb:
nmax = (C // Wb)
pmax = nmax*Hb + ((C - nmax*Wb) // Wr) * Hr
if Wr>Wb:
nmax = (C // Wr)
pmax = nmax*Hr + ((C - nmax*Wr) // Wb) * Hb
if Wr>Wb and dx>0:
for k in range(1, C//Wr):
if k*Wr > dx:
break
pk = (nmax-k)*Hr + ((C - (nmax-k)*Wr) // Wb) * Hb
dk = ((C - (nmax-k)*Wr) % Wb)
#print(k, pmax, pk, dk)
if pk>pmax:
pmax = pk
if dk==0 :
break
elif Wr<Wb and dx>0:
for j in range(1, C//Wb+1):
k = nmax - (C-j*Wb)//Wr
if k*Wr > dx:
break
pk = (nmax-k)*Hr + ((C - (nmax-k)*Wr) // Wb) * Hb
dk = ((C - (nmax-k)*Wr) % Wb)
#print(j, k, pmax, pk, dk, (nmax-k), ((C - (nmax-k)*Wr) // Wb) )
if pk>pmax:
pmax = pk
#dmax = dk
if dk==0 :
break
# elif Wr<Wb and dx>0:
# for j in range(1, C//Wb+1):
# k = (j*Wb - dmax)//Wr
# if k*Wr > dx:
# break
# pk = (nmax-k)*Hr + ((C - (nmax-k)*Wr) // Wb) * Hb
# dk = ((C - (nmax-k)*Wr) % Wb)
# print(j, k, pmax, pk, dk, (nmax-k), ((C - (nmax-k)*Wr) // Wb) )
# if pk>pmax:
# pmax = pk
# #dmax = dk
# if dk==0 :
# break
print(pmax)
``` | vfc_10558 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/526/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3 5 2 3\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3 1 6 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "982068341 55 57 106 109\n",
"output": "513558662\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "930064129 32726326 25428197 83013449 64501049\n",
"output": "363523396\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "927155987 21197 15994 54746 41309\n",
"output": "358983713\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "902303498 609628987 152407246 8 2\n",
"output": "68758795931537065\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 202 | Solve the following coding problem using the programming language python:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.
-----Input-----
The first line contains two integers x_1, y_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9) — the start position of the robot.
The second line contains two integers x_2, y_2 ( - 10^9 ≤ x_2, y_2 ≤ 10^9) — the finish position of the robot.
-----Output-----
Print the only integer d — the minimal number of steps to get the finish position.
-----Examples-----
Input
0 0
4 5
Output
5
Input
3 4
6 1
Output
3
-----Note-----
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.
In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = map(int, input().split())
d, c = map(int, input().split())
print(max(abs(a - d), abs(b - c)))
``` | vfc_10562 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/620/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0\n4 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n6 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 203 | Solve the following coding problem using the programming language python:
There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated: Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.
-----Output-----
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
-----Examples-----
Input
5
DDRRR
Output
D
Input
6
DDRRRR
Output
R
-----Note-----
Consider one of the voting scenarios for the first sample: Employee 1 denies employee 5 to vote. Employee 2 denies employee 3 to vote. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). Employee 4 denies employee 2 to vote. Employee 5 has no right to vote and skips his turn (he was denied by employee 1). Employee 1 denies employee 4. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.
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()
countr = s.count('R')
countd = n - countr
cr = 0
cd = 0
i = 0
news = []
while countr != 0 and countd != 0:
if s[i] == 'D':
if cd == 0:
cr += 1
countr -= 1
news.append('D')
else:
cd -= 1
else:
if cr == 0:
cd += 1
countd -= 1
news.append('R')
else:
cr -= 1
i += 1
if i >= n:
s = list(news)
news = []
n = len(s)
i = 0
if countr > 0:
print('R')
else:
print('D')
``` | vfc_10566 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/749/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nDDRRR\n",
"output": "D\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 204 | Solve the following coding problem using the programming language python:
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is $w$, and the height of the screen is $h$, then the following condition should be met: $\frac{w}{h} = \frac{x}{y}$.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers $w$ and $h$ there is a TV set with screen width $w$ and height $h$ in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers $w$ and $h$, beforehand, such that $(w \le a)$, $(h \le b)$ and $(\frac{w}{h} = \frac{x}{y})$.
In other words, Monocarp wants to determine the number of TV sets having aspect ratio $\frac{x}{y}$, screen width not exceeding $a$, and screen height not exceeding $b$. Two TV sets are considered different if they have different screen width or different screen height.
-----Input-----
The first line contains four integers $a$, $b$, $x$, $y$ ($1 \le a, b, x, y \le 10^{18}$) — the constraints on the screen width and height, and on the aspect ratio.
-----Output-----
Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
-----Examples-----
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
-----Note-----
In the first example, there are $3$ possible variants: $(5, 3)$, $(10, 6)$, $(15, 9)$.
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: $(3, 2)$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def gcd(a, b):
while b:
a, b = b, a % b
return a
a, b, x, y = list(map(int, input().split()))
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))
``` | vfc_10570 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1041/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "17 15 5 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 16 7 22\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 6 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597\n",
"output": "1000000063\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 206 | Solve the following coding problem using the programming language python:
A frog is initially at position $0$ on the number line. The frog has two positive integers $a$ and $b$. From a position $k$, it can either jump to position $k+a$ or $k-b$.
Let $f(x)$ be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval $[0, x]$. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from $0$.
Given an integer $m$, find $\sum_{i=0}^{m} f(i)$. That is, find the sum of all $f(i)$ for $i$ from $0$ to $m$.
-----Input-----
The first line contains three integers $m, a, b$ ($1 \leq m \leq 10^9, 1 \leq a,b \leq 10^5$).
-----Output-----
Print a single integer, the desired sum.
-----Examples-----
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
-----Note-----
In the first example, we must find $f(0)+f(1)+\ldots+f(7)$. We have $f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8$. The sum of these values is $19$.
In the second example, we have $f(i) = i+1$, so we want to find $\sum_{i=0}^{10^9} i+1$.
In the third example, the frog can't make any jumps in any case.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
m,a,b=map(int,input().split())
g=math.gcd(a,b)
a1=a//g
b1=b//g
alls=g*(a1+b1-1)
dists=[0]+[-1]*(a1+b1-1)
dist=0
far=0
while dist!=b1:
if dist<b1:
dist+=a1
far=max(dist,far)
else:
dist-=b1
if dists[dist]==-1:
dists[dist]=far
tot=0
for i in range(a1+b1):
if i*g<=m and dists[i]*g<=m:
tot+=(m+1-dists[i]*g)
if alls<m:
mod=m%g
times=m//g
diff=times-a1-b1
tot1=g*(diff*(diff+1)//2)+(mod+1)*(diff+1)
tot+=tot1
print(tot)
``` | vfc_10578 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1146/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 5 3\n",
"output": "19\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 207 | Solve the following coding problem using the programming language python:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a_1, a_2, ..., a_{n} of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
-----Input-----
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 100) — the elements of the sequence.
-----Output-----
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
-----Examples-----
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
-----Note-----
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
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()]
n = read_ints()
a = read_ints()
if len(a) % 2 and a[0] % 2 and a[-1] % 2:
print('Yes')
else:
print('No')
``` | vfc_10582 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/849/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 0 1 5 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 3 1\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 208 | Solve the following coding problem using the programming language python:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
-----Input-----
The first line contains four space-separated x_1, y_1, x_2, y_2 ( - 100 ≤ x_1, y_1, x_2, y_2 ≤ 100) integers, where x_1 and y_1 are coordinates of the first tree and x_2 and y_2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
-----Output-----
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x_3, y_3, x_4, y_4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that x_3, y_3, x_4, y_4 must be in the range ( - 1000 ≤ x_3, y_3, x_4, y_4 ≤ 1000).
-----Examples-----
Input
0 0 0 1
Output
1 0 1 1
Input
0 0 1 1
Output
0 1 1 0
Input
0 0 1 2
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x1, y1, x2, y2 = map(int, input().split())
#diagonal
if x1 != x2 and y1 != y2:
if abs(x1 - x2) == abs(y1 - y2):
print(x1, y2, x2, y1)
else:
print(-1)
#same side
elif x1 == x2:
aux = abs(y2 - y1)
print(x1 + aux, y1, x1 + aux, y2)
elif y1 == y2:
aux = abs(x2 - x1)
print(x1, y1 + aux, x2, y1 + aux)
``` | vfc_10586 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/459/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 0 1\n",
"output": "1 0 1 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 209 | Solve the following coding problem using the programming language python:
Jzzhu has invented a kind of sequences, they meet the following property:$f_{1} = x ; f_{2} = y ; \forall i(i \geq 2), f_{i} = f_{i - 1} + f_{i + 1}$
You are given x and y, please calculate f_{n} modulo 1000000007 (10^9 + 7).
-----Input-----
The first line contains two integers x and y (|x|, |y| ≤ 10^9). The second line contains a single integer n (1 ≤ n ≤ 2·10^9).
-----Output-----
Output a single integer representing f_{n} modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
-----Note-----
In the first sample, f_2 = f_1 + f_3, 3 = 2 + f_3, f_3 = 1.
In the second sample, f_2 = - 1; - 1 modulo (10^9 + 7) equals (10^9 + 6).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
x, y = [int(i) for i in input().split()]
n = int(input())
result = [x, y, y - x, -x, -y, x - y][(n - 1) % 6]
print(result % 1000000007)
main()
``` | vfc_10590 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/450/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 211 | Solve the following coding problem using the programming language python:
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.
Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (10^9 + 9).
-----Input-----
The single line contains three space-separated integers n, m and k (2 ≤ k ≤ n ≤ 10^9; 0 ≤ m ≤ n).
-----Output-----
Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (10^9 + 9).
-----Examples-----
Input
5 3 2
Output
3
Input
5 4 2
Output
6
-----Note-----
Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.
Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.
Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though 2000000020 mod 1000000009 is a smaller number.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
MOD = 1000000009
n,m,k = [int(x) for x in input().split()]
num0 = n-m
num1fin = num0*(k-1)
if num1fin >= m:
print(m)
else:
num1open = m-num1fin
sets = num1open//k
rem = num1open%k
print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD)
``` | vfc_10598 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/337/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "300 300 3\n",
"output": "17717644\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 213 | Solve the following coding problem using the programming language python:
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers k_{i}, f_{i} (1 ≤ k_{i} ≤ 100, 1 ≤ f_{i} ≤ 100), which means that the flat k_{i} is on the f_{i}-th floor. All values k_{i} are distinct.
It is guaranteed that the given information is not self-contradictory.
-----Output-----
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
-----Examples-----
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
-----Note-----
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def floo(num, k):
return (num - 1) // k + 1
def main():
n, m = map(int, input().split())
low = 1
high = 10**9
if (m == 0):
if (n == 1):
print(1)
else:
print(-1)
return
for i in range(m):
k, f = map(int, input().split())
low = max(low, (k + f - 1) // f)
if (f > 1):
high = min(high, (k - 1) // (f - 1))
if (floo(n, low) == floo(n, high)):
print(floo(n, low))
else:
print(-1)
main()
``` | vfc_10606 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/858/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 3\n6 2\n2 1\n7 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 214 | Solve the following coding problem using the programming language python:
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.
Vasya has a board with $2\times n$ squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully.
Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns.
-----Input-----
The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$.
-----Output-----
Output a single integer — the maximum amount of bishwocks that can be placed onto the given board.
-----Examples-----
Input
00
00
Output
1
Input
00X00X0XXX0
0XXX0X00X00
Output
4
Input
0X0X0
0X0X0
Output
0
Input
0XXX0
00000
Output
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
f = []
for i in range(2):
f.append(list(input()))
answer = 0
n = len(f[0])
for i in range(n):
if f[0][i] == f[1][i] == '0' and i + 1 < n:
if f[0][i + 1] == '0':
answer += 1
f[0][i + 1] = 'X'
elif f[1][i + 1] == '0':
answer += 1
f[1][i + 1] = 'X'
elif (f[1][i] == '0' or f[0][i] == '0') and i + 1 < n and f[0][i + 1] == f[1][i + 1] == '0':
answer += 1
f[0][i + 1] = f[1][i + 1] = 'X'
print(answer)
``` | vfc_10610 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/991/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "00\n00\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "00X00X0XXX0\n0XXX0X00X00\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0X0X0\n0X0X0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0XXX0\n00000\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0\nX\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 215 | Solve the following coding problem using the programming language python:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on positions from A in the string are all distinct and lowercase; there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a_1 < j < a_2 for some a_1 and a_2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
-----Output-----
Print maximum number of elements in pretty set of positions for string s.
-----Examples-----
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
-----Note-----
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so 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
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
n = int(input())
a = list(input())
ans = 0
for i in range(n):
for j in range(i,n):
b = a[i:j+1]
for k in b:
if k.lower() != k:
break
else:
b = set(b)
ans = max(ans,len(b))
print(ans)
``` | vfc_10614 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/864/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11\naaaaBaabAbA\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\nzACaAbbaazzC\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nABC\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 216 | Solve the following coding problem using the programming language python:
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a_1, a_2, ..., a_{n} ( - 100 ≤ a_{i} ≤ 100) — the elements of sequence a.
-----Output-----
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
-----Examples-----
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
-----Note-----
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.
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().strip().split(' ')))
s = 0
for i in range(n):
s+=abs(arr[i])
print(s)
``` | vfc_10618 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/946/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 -2 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n16 23 16 15 42 8\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n-1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n-1 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 217 | Solve the following coding problem using the programming language python:
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys.
The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0.
-----Input-----
The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
-----Output-----
Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.
-----Examples-----
Input
6 9 2 4
Output
4
Input
6 10 2 4
Output
2
Input
6 5 4 3
Output
-1
-----Note-----
In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
a,b,f,k = map_input()
tot = a*k
s = 2*a-f
cur = 0
cnt = b
go = 0
ans = 0
while cur < tot:
go = 1-go
if(go == 1):
if cnt < s and cnt < tot-cur:
if(cnt < f):
print(-1)
break
cnt = b
ans += 1
cnt -= (a-f)
else: cnt -= a
else:
if cnt < a+f and cnt < tot-cur:
if(cnt < a-f):
print(-1)
break
cnt = b
ans += 1
cnt -= (f)
else:cnt -= a
cur += a
# print(cur,cnt,ans)
if(cnt < 0):
print(-1)
break
else:
print(ans)
``` | vfc_10622 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/864/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 9 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 218 | Solve the following coding problem using the programming language python:
You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.
For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test).
-----Input-----
The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100).
The second line contains the string s consists of lowercase and uppercase latin letters and digits.
-----Output-----
If it's impossible to split the string s to the strings of length p and q print the only number "-1".
Otherwise in the first line print integer k — the number of strings in partition of s.
Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right.
If there are several solutions print any of them.
-----Examples-----
Input
5 2 3
Hello
Output
2
He
llo
Input
10 9 5
Codeforces
Output
2
Codef
orces
Input
6 4 5
Privet
Output
-1
Input
8 1 1
abacabac
Output
8
a
b
a
c
a
b
a
c
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 = map(int, input().split(' '))
x = input()
for i in range(105):
for j in range(105):
if i*b+j*c == a:
print(i+j)
for k in range(i):
print(x[:b])
x = x[b:]
for l in range(j):
print(x[:c])
x = x[c:]
quit()
print(-1)
``` | vfc_10626 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/612/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 3\nHello\n",
"output": "2\nHe\nllo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9 5\nCodeforces\n",
"output": "2\nCodef\norces\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 219 | Solve the following coding problem using the programming language python:
A sportsman starts from point x_{start} = 0 and runs to point with coordinate x_{finish} = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x_1, x_2, ..., x_{n}. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
-----Input-----
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 10^9, 1 ≤ s, d ≤ 10^9) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
-----Output-----
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format: print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters; print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
-----Examples-----
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m, s, d = list(map(int, input().split()))
beg = [float('-inf')]
end = [float('-inf')]
a = [int(i) for i in input().split()]
for x in sorted(a):
if (x - end[-1] > s + 1):
beg.append(x)
end.append(x)
else:
end[-1] = x
last = 0
R = []
J = []
for i in range(1, len(beg)):
R.append(beg[i] - 1 - last)
last = (beg[i] - 1)
J.append(end[i] + 1 - last)
last = (end[i] + 1)
ok = True
for x in J:
if (x > d):
ok = False
for x in R:
if (x < s):
ok = False
if ok:
for i in range(len(R)):
print('RUN', R[i])
print('JUMP', J[i])
if (last < m):
print('RUN', m - last)
else:
print('IMPOSSIBLE')
``` | vfc_10630 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/637/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10 1 3\n3 4 7\n",
"output": "RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 9 2 3\n6 4\n",
"output": "IMPOSSIBLE\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 220 | Solve the following coding problem using the programming language python:
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
-----Input-----
The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and bitwise xor of the pair of positive integers, respectively.
-----Output-----
Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.
-----Examples-----
Input
9 5
Output
4
Input
3 3
Output
2
Input
5 2
Output
0
-----Note-----
In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).
In the second sample, the only solutions are (1, 2) and (2, 1).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s, x = list(map(int, input().split()))
rem = int(s == x) * 2
p, t, cur = [], 0, 1
for i in range(64):
if x % 2:
t += 1
s -= cur
else:
p.append(cur * 2)
cur *= 2
x //= 2
for i in p[::-1]:
if s >= i: s -= i
ans = 0 if s else 2 ** t - rem
print(ans)
``` | vfc_10634 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/627/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 221 | Solve the following coding problem using the programming language python:
Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.
This time Miroslav laid out $n$ skewers parallel to each other, and enumerated them with consecutive integers from $1$ to $n$ in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number $i$, it leads to turning $k$ closest skewers from each side of the skewer $i$, that is, skewers number $i - k$, $i - k + 1$, ..., $i - 1$, $i + 1$, ..., $i + k - 1$, $i + k$ (if they exist).
For example, let $n = 6$ and $k = 1$. When Miroslav turns skewer number $3$, then skewers with numbers $2$, $3$, and $4$ will come up turned over. If after that he turns skewer number $1$, then skewers number $1$, $3$, and $4$ will be turned over, while skewer number $2$ will be in the initial position (because it is turned again).
As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all $n$ skewers with the minimal possible number of actions. For example, for the above example $n = 6$ and $k = 1$, two turnings are sufficient: he can turn over skewers number $2$ and $5$.
Help Miroslav turn over all $n$ skewers.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \leq n \leq 1000$, $0 \leq k \leq 1000$) — the number of skewers and the number of skewers from each side that are turned in one step.
-----Output-----
The first line should contain integer $l$ — the minimum number of actions needed by Miroslav to turn over all $n$ skewers. After than print $l$ integers from $1$ to $n$ denoting the number of the skewer that is to be turned over at the corresponding step.
-----Examples-----
Input
7 2
Output
2
1 6
Input
5 1
Output
2
1 4
-----Note-----
In the first example the first operation turns over skewers $1$, $2$ and $3$, the second operation turns over skewers $4$, $5$, $6$ and $7$.
In the second example it is also correct to turn over skewers $2$ and $5$, but turning skewers $2$ and $4$, or $1$ and $5$ are incorrect solutions because the skewer $3$ is in the initial state after these operations.
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())
if n <= k + k + 1:
print(1)
print((n + 1) // 2)
else:
answer = -1
answer_n = 10**100
for i in range(min(k + 1, n)):
t = n - (k + i + 1)
if t % (k + k + 1) >= k + 1:
if 2 + t // (k + k + 1) < answer_n:
answer = i + 1
answer_n = 2 + t // (k + k + 1)
if t % (k + k + 1) == 0:
if 1 + t // (k + k + 1) < answer_n:
answer = i + 1
answer_n = 1 + t // (k + k + 1)
print(answer_n)
while answer <= n:
print(answer, end = ' ')
answer += k + k + 1
``` | vfc_10638 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1040/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 2\n",
"output": "2\n1 6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n",
"output": "2\n1 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 0\n",
"output": "10\n1 2 3 4 5 6 7 8 9 10 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n",
"output": "4\n1 4 7 10 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n",
"output": "1\n10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 222 | Solve the following coding problem using the programming language python:
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.
An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
-----Output-----
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
-----Examples-----
Input
8314
Output
2
Input
625
Output
0
Input
333
Output
-1
-----Note-----
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the square from $333$, so the answer is -1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ar=[]
for i in range(1,10**5):
if(i*i>2*10**9):break
ar.append(i*i)
s=input()
ans=len(s)
for x in ar:
s2=str(x)
i=0
for x in range(len(s)):
if i<len(s2) and s[x]==s2[i]:
i+=1
if(i==len(s2)):
ans=min(ans,len(s)-i)
if(ans==len(s)):
print(-1)
else:
print(ans)
``` | vfc_10642 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/962/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8314\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 223 | Solve the following coding problem using the programming language python:
Let's define a function $f(p)$ on a permutation $p$ as follows. Let $g_i$ be the greatest common divisor (GCD) of elements $p_1$, $p_2$, ..., $p_i$ (in other words, it is the GCD of the prefix of length $i$). Then $f(p)$ is the number of distinct elements among $g_1$, $g_2$, ..., $g_n$.
Let $f_{max}(n)$ be the maximum value of $f(p)$ among all permutations $p$ of integers $1$, $2$, ..., $n$.
Given an integers $n$, count the number of permutations $p$ of integers $1$, $2$, ..., $n$, such that $f(p)$ is equal to $f_{max}(n)$. Since the answer may be large, print the remainder of its division by $1000\,000\,007 = 10^9 + 7$.
-----Input-----
The only line contains the integer $n$ ($2 \le n \le 10^6$) — the length of the permutations.
-----Output-----
The only line should contain your answer modulo $10^9+7$.
-----Examples-----
Input
2
Output
1
Input
3
Output
4
Input
6
Output
120
-----Note-----
Consider the second example: these are the permutations of length $3$: $[1,2,3]$, $f(p)=1$. $[1,3,2]$, $f(p)=1$. $[2,1,3]$, $f(p)=2$. $[2,3,1]$, $f(p)=2$. $[3,1,2]$, $f(p)=2$. $[3,2,1]$, $f(p)=2$.
The maximum value $f_{max}(3) = 2$, and there are $4$ permutations $p$ such that $f(p)=2$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
p=10**9+7
import math
def inv(k,p):
prod=1
while k>1:
prod*=(p//k+1)
k=(k*(p//k+1))%p
return prod%p
n=int(input())
a=[]
k=int(math.log2(n))
x=n
while x>0:
y=x//2
a.append(x-y)
x=y
c=[sum(a[i:]) for i in range(k+1)]
b=[n//(3*2**i)-n//(6*2**i) for i in range(k+1)]
d=[n//2**i-n//(3*2**i) for i in range(k+1)]
facs=[1]*(n+1)
for i in range(2,n+1):
facs[i]=(i*facs[i-1])%p
if n<3*(2**(k-1)):
start=k
else:
start=0
tot=0
for j in range(start,k+1):
prod=1
for i in range(j,k):
prod*=b[i]
prod*=d[j]
for i in range(j):
prod*=a[i]
prod%=p
prod*=facs[n]
e=[a[i] for i in range(j)]+[d[j]]+[b[i] for i in range(j,k)]
f=[sum(e[:i+1]) for i in range(k+1)]
g=1
for guy in f:
g*=guy
prod*=inv(g,p)
prod%=p
tot+=prod
print(tot%p)
``` | vfc_10646 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1174/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n",
"output": "120",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "15120",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "64\n",
"output": "676169815",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1227\n",
"output": "9412302",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 224 | Solve the following coding problem using the programming language python:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. [Image] The picture corresponds to the first example.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
-----Input-----
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
-----Output-----
Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
-----Examples-----
Input
ABABBBACFEYUKOTT
Output
4
Input
AAA
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# You lost the game.
s = str(input())
n = len(s)
d = -1
r = 0
V = "AEIOUY"
for i in range(n):
if V.count(s[i]):
r = max(r,i-d)
d = i
print(max(r, n-d))
``` | vfc_10650 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/733/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ABABBBACFEYUKOTT\n",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "AAA\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 225 | Solve the following coding problem using the programming language python:
Dawid has four bags of candies. The $i$-th of them contains $a_i$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?
Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.
-----Input-----
The only line contains four integers $a_1$, $a_2$, $a_3$ and $a_4$ ($1 \leq a_i \leq 100$) — the numbers of candies in each bag.
-----Output-----
Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).
-----Examples-----
Input
1 7 11 5
Output
YES
Input
7 3 2 5
Output
NO
-----Note-----
In the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $12$ candies.
In the second sample test, it's impossible to distribute the bags.
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()))
for i in range(16):
cur1,cur2=0,0
for j in range(4):
if (i&(1<<j))==0:
cur1+=l[j]
else:
cur2+=l[j]
if cur1==cur2:
print("YES")
quit()
print("NO")
``` | vfc_10654 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1230/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 7 11 5\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 226 | Solve the following coding problem using the programming language python:
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
-----Input-----
Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
-----Output-----
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
-----Examples-----
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
-----Note-----
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
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 = a[::-1]
d = 0
for i in range(len(a)):
d = max(0 + d, a[i] + (sum(a[:i]) - d))
print(sum(a)-d, d)
``` | vfc_10658 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/859/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n141 592 653\n",
"output": "653 733\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n10 21 10 21 10\n",
"output": "31 41\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n100000\n",
"output": "0 100000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 227 | Solve the following coding problem using the programming language python:
You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≤ i ≤ m) contains the value of zero. Consider the following sequence, consisting of n operations.
The first operation is assigning the value of a_1 to some variable b_{x} (1 ≤ x ≤ m). Each of the following n - 1 operations is assigning to some variable b_{y} the value that is equal to the sum of values that are stored in the variables b_{i} and b_{j} (1 ≤ i, j, y ≤ m). At that, the value that is assigned on the t-th operation, must equal a_{t}. For each operation numbers y, i, j are chosen anew.
Your task is to find the minimum number of variables m, such that those variables can help you perform the described sequence of operations.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 23). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{k} ≤ 10^9).
It is guaranteed that all numbers in the sequence are distinct.
-----Output-----
In a single line print a single number — the minimum number of variables m, such that those variables can help you perform the described sequence of operations.
If you cannot perform the sequence of operations at any m, print -1.
-----Examples-----
Input
5
1 2 3 6 8
Output
2
Input
3
3 6 5
Output
-1
Input
6
2 4 8 6 10 18
Output
3
-----Note-----
In the first sample, you can use two variables b_1 and b_2 to perform the following sequence of operations. b_1 := 1; b_2 := b_1 + b_1; b_1 := b_1 + b_2; b_1 := b_1 + b_1; b_1 := b_1 + b_2.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def Solve(x,B):
if((X,x,B) in Mem):
return Mem[(X,x,B)]
if(len(B)>X):
return False
if(x==len(L)):
return True
if(Form(L[x],B)):
A=list(B)
for e in range(len(B)):
r=A[e]
A[e]=L[x]
if(Solve(x+1,tuple(sorted(A)))):
Mem[(X,x,B)]=True
return True
A[e]=r
A+=[L[x]]
if(Solve(x+1,tuple(sorted(A)))):
Mem[(X,x,B)]=True
return True
Mem[(X,x,B)]=False
return False
def Form(x,B):
for i in range(len(B)):
for j in range(i,len(B)):
if(B[i]+B[j]==x):
return True
return False
n=int(input())
L=list(map(int,input().split()))
done=False
Mem={}
for X in range(1,n+1):
if(Solve(1,(L[0],))):
print(X)
done=True
break
if(not done):
print(-1)
``` | vfc_10662 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/279/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 6 8\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 228 | Solve the following coding problem using the programming language python:
Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exactly $\frac{n}{2}$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $\frac{n}{2}$ nonempty piles).
Given the starting configuration, determine who will win the game.
-----Input-----
The first line contains one integer $n$ ($2 \leq n \leq 50$) — the number of piles. It is guaranteed that $n$ is an even number.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 50$) — the number of stones in the piles.
-----Output-----
Print a single string "Alice" if Alice wins; otherwise, print "Bob" (without double quotes).
-----Examples-----
Input
2
8 8
Output
Bob
Input
4
3 1 4 1
Output
Alice
-----Note-----
In the first example, each player can only remove stones from one pile ($\frac{2}{2}=1$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.
In the second example, Alice can remove $2$ stones from the first pile and $3$ stones from the third pile on her first move to guarantee a win.
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=list(map(int,input().split()))
print("Bob"if s.count(min(s))>n/2 else"Alice")
``` | vfc_10666 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1147/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n8 8\n",
"output": "Bob\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 1 4 1\n",
"output": "Alice\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n42 49 42 42\n",
"output": "Bob\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 229 | Solve the following coding problem using the programming language python:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
-----Input-----
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — elements of the array.
-----Output-----
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
-----Examples-----
Input
5
1 3 3 2 1
Output
YES
Input
5
1 2 3 4 5
Output
NO
-----Note-----
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
read = lambda: list(map(int, input().split()))
n = int(input())
a = list(read())
s = set()
for i in a:
s.add(i)
f1 = len(s) < 3
f2 = len(s) == 3 and max(s) + min(s) == 2 * sorted(s)[1]
print('YES' if f1 or f2 else 'NO')
``` | vfc_10670 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/714/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 231 | Solve the following coding problem using the programming language python:
The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to n in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house n, house 3 is opposite house n - 2, house 5 is opposite house n - 4 and so on. [Image]
Vasya needs to get to house number a as quickly as possible. He starts driving from the beginning of the street and drives his car to house a. To get from the beginning of the street to houses number 1 and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.
Your task is: find the minimum time Vasya needs to reach house a.
-----Input-----
The first line of the input contains two integers, n and a (1 ≤ a ≤ n ≤ 100 000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number n is even.
-----Output-----
Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house a.
-----Examples-----
Input
4 2
Output
2
Input
8 5
Output
3
-----Note-----
In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with n = 8. House 5 is the one before last at Vasya's left.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, a = list(map(int,input().split()))
if a % 2 == 1:
print(a // 2 + 1)
else:
print((n-a) // 2 + 1)
``` | vfc_10678 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/638/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 232 | Solve the following coding problem using the programming language python:
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k_1 knights with lightsabers of the first color, k_2 knights with lightsabers of the second color, ..., k_{m} knights with lightsabers of the m-th color. Help her find out if this is possible.
-----Input-----
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k_1, k_2, ..., k_{m} (with $1 \leq \sum_{i = 1}^{m} k_{i} \leq n$) – the desired counts of lightsabers of each color from 1 to m.
-----Output-----
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
-----Example-----
Input
5 2
1 1 2 2 1
1 2
Output
YES
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input().split()
n, m = int(s[0]), int(s[1])
cl = list(map(int, input().split()))
com = list(map(int, input().split()))
res = False
for i in range(n):
for j in range(i, n):
e = True
t = cl[i:j+1]
for k in range(1, m+1):
e = t.count(k)==com[k-1] and e
if e:
res = True
break
if res: print('YES')
else: print('NO')
``` | vfc_10682 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/958/F1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 1 2 2 1\n1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 1\n1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 1\n2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 2\n1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 233 | Solve the following coding problem using the programming language python:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
-----Input-----
The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds.
The next n lines contains rounds description. i-th of them contains pair of integers m_{i} and c_{i} (1 ≤ m_{i}, c_{i} ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.
-----Output-----
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
-----Examples-----
Input
3
3 5
2 1
4 2
Output
Mishka
Input
2
6 1
1 6
Output
Friendship is magic!^^
Input
3
1 5
3 3
2 2
Output
Chris
-----Note-----
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x = 0
y = 0
for _ in range(int(input())):
a, b = list(map(int, input().split()))
x += (a > b)
y += (b > a)
if x > y:
print("Mishka")
elif y > x:
print("Chris")
else:
print("Friendship is magic!^^")
``` | vfc_10686 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/703/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 5\n2 1\n4 2\n",
"output": "Mishka",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n6 1\n1 6\n",
"output": "Friendship is magic!^^",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 5\n3 3\n2 2\n",
"output": "Chris",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1\n",
"output": "Mishka",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 234 | Solve the following coding problem using the programming language python:
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $n \times m$, where each cell is either empty, or contains a digit from $1$ to $8$, or a bomb. The field is valid if for each cell: if there is a digit $k$ in the cell, then exactly $k$ neighboring cells have bombs. if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $8$ neighboring cells).
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.
The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive.
-----Output-----
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
-----Examples-----
Input
3 3
111
1*1
111
Output
YES
Input
2 4
*.*.
1211
Output
NO
-----Note-----
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in Wikipedia's article.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
r, c = list(map(int, input().split()))
b = [list(input()) for i in range(r)]
for y in range(r):
for x in range(c):
if b[y][x] == '.':
b[y][x] = '0'
ok = True
for Y in range(r):
for X in range(c):
if not b[Y][X].isdigit():
continue
p = 0
for dy in range(-1, 2):
for dx in range(-1, 2):
y = Y + dy
x = X + dx
if 0 <= y < r and 0 <= x < c:
p += b[y][x] == '*'
if p != int(b[Y][X]):
ok = False
print(["NO", "YES"][ok])
``` | vfc_10690 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/984/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n111\n1*1\n111\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n*.*.\n1211\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10\n.....1*1..\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 235 | Solve the following coding problem using the programming language python:
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on.
If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all.
Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box.
-----Output-----
Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
-----Example-----
Input
68
Output
3
-----Note-----
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first):
$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$.
In total, Vasya would eat $39$ candies, while Petya — $29$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def can(n, k):
total = n
s = 0
while n > 0:
cur = min(n, k)
s += cur
n -= cur
n -= n // 10
return s * 2 >= total
n = int(input())
le = 0
rg = n
while rg - le > 1:
mid = (rg + le) // 2
if can(n, mid):
rg = mid
else:
le = mid
print(rg)
``` | vfc_10694 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/991/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "68\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "42\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "43\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 236 | Solve the following coding problem using the programming language python:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. $0$
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts.
Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.
Note that the final necklace should remain as one circular part of the same length as the initial necklace.
-----Input-----
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
-----Output-----
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
-o-o--
Output
YES
Input
-o---
Output
YES
Input
-o---o-
Output
NO
Input
ooo
Output
YES
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
s = input()
links = s.count('-')
pearls = s.count('o')
if pearls == 0 or links % pearls == 0:
print('YES')
else:
print('NO')
main()
``` | vfc_10698 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/980/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-o-o--\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-o---\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-o---o-\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ooo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "---\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "--o-o-----o----o--oo-o-----ooo-oo---o--\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 237 | Solve the following coding problem using the programming language python:
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
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 = map(int, input().split())
ans = 1
m -= n
left = k - 1
right = n - k
put = 1
while (m >= put):
m -= put
ans += 1
put += (left > 0) + (right > 0)
if (left): left -= 1
if (right): right -= 1
if (left == right == 0):
ans += (m // put)
break
print(ans)
``` | vfc_10702 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/760/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 6 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 6 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1000000000 1\n",
"output": "1000000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 238 | Solve the following coding problem using the programming language python:
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$.
You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$.
The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$.
The cost of empty subarray is equal to zero.
For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$.
Your task is to find the maximum cost of some subarray (possibly empty) of array $a$.
-----Input-----
The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$).
-----Output-----
Print the maximum cost of some subarray of array $a$.
-----Examples-----
Input
7 3 10
2 -4 15 -3 4 8 3
Output
7
Input
5 2 1000
-13 -4 -9 -20 -11
Output
0
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()))
A = [int(a) for a in input().split()]
S = [0]
for a in A:
S.append(S[-1]+M*a-K)
MI = [(10**50)] * M
ans = 0
for i in range(N+1):
MI[i%M] = min(MI[i%M], S[i])
for j in range(M):
ans = max(ans, (S[i]-MI[(i-j)%M] - K*((-j)%M))//M)
print(ans)
``` | vfc_10706 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1197/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 3 10\n2 -4 15 -3 4 8 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 1000\n-13 -4 -9 -20 -11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10 10\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "4999999990\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10 10\n1000000000 1000000000 -1000000000 1000000000 1000000000\n",
"output": "2999999990\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 239 | Solve the following coding problem using the programming language python:
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p_1, p_2, p_3, p_4 consists of the line segments p_1 p_2, p_2 p_3, p_3 p_4, and its length is the sum of the lengths of the individual line segments.
-----Input-----
The only line of the input contains two integers n and m (0 ≤ n, m ≤ 1000). It is guaranteed that grid contains at least 4 different points.
-----Output-----
Print 4 lines with two integers per line separated by space — coordinates of points p_1, p_2, p_3, p_4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10^{ - 6} precision.
-----Examples-----
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
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 = list(map(int, input().split()))
if n == 0 :
print(0, 1)
print(0, m)
print(0, 0)
print(0, m - 1)
elif m == 0 :
print(1, 0)
print(n, 0)
print(0, 0)
print(n - 1, 0)
else :
l = math.sqrt((n - 1) ** 2 + m ** 2) + math.sqrt(n ** 2 + m ** 2) + math.sqrt(n ** 2 + (m - 1) ** 2)
l1 = max(m, n) + math.sqrt(n * n + m * m) * 2
l2 = math.sqrt(n ** 2 + m ** 2) + math.sqrt((n - 1) ** 2 + m ** 2) * 2
l3 = math.sqrt(n ** 2 + m ** 2) + math.sqrt((m - 1) ** 2 + n ** 2) * 2
ans = max(l, l1, l2, l3)
if l == ans :
print(1, 0)
print(n, m)
print(0, 0)
print(n, m - 1)
elif l1 == ans :
if n > m :
print(n, m)
print(0, 0)
print(n, 0)
print(0, m)
else :
print(n, m)
print(0, 0)
print(0, m)
print(n, 0)
elif l2 == ans :
print(1, 0)
print(n, m)
print(0, 0)
print(n - 1, m)
else :
print(0, 1)
print(n, m)
print(0, 0)
print(n, m - 1)
``` | vfc_10710 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/452/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "1 1\n0 0\n1 0\n0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 10\n",
"output": "0 1\n0 10\n0 0\n0 9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n",
"output": "10 9\n0 0\n10 10\n1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100\n",
"output": "0 1\n100 100\n0 0\n99 100\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 240 | Solve the following coding problem using the programming language python:
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.
Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of n (a substring of n is a sequence of consecutive digits of the number n).
Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used).
-----Input-----
The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000.
The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes.
It is guaranteed that the input data is correct, and the answer always exists.
-----Output-----
Print the smalles integer n which Vasya could pass to Kate.
-----Examples-----
Input
003512
021
Output
30021
Input
199966633300
63
Output
3036366999
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 Counter
s = list(map(int, input()))
substr = input().rstrip()
t = list(map(int, substr))
m = len(s)
x, y = 0, m
z = (x + y) // 2
while z != x:
if z + math.floor(math.log10(z)) + 1 <= m:
x = z
else:
y = z
z = (x + y)//2
m1 = z
k = math.floor(math.log10(m1)) + 1
D = Counter(s)
D.subtract(list(map(int, str(m1))))
D.subtract(t)
try:
c1 = min(i for i in range(1, 10) if D[i] > 0)
c2 = t[0]
D[c1] -= 1
_prefix = [c1]
for c in range(c2):
_prefix += [c] * D[c]
_suffix = []
for c in range(c2 + 1, 10):
_suffix += [c] * D[c]
num = ''.join([str(c2)] * D[c2])
prefix = ''.join(map(str, _prefix))
suffix = ''.join(map(str, _suffix))
if c2 == 0:
print((min(prefix + substr + num + suffix,
prefix + num + substr + suffix)))
else:
D[c1] += 1
st = []
for c in range(10):
st += [c] * D[c]
print((min(prefix + substr + num + suffix,
prefix + num + substr + suffix,
substr + ''.join(map(str, st)))))
except ValueError:
print(substr + '0'*D[0])
``` | vfc_10714 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/670/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "003512\n021\n",
"output": "30021\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 241 | Solve the following coding problem using the programming language python:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m.
The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max.
-----Input-----
The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers t_{i} (1 ≤ t_{i} ≤ 100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures.
-----Output-----
If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes).
-----Examples-----
Input
2 1 1 2
1
Output
Correct
Input
3 1 1 3
2
Output
Correct
Input
2 1 1 3
2
Output
Incorrect
-----Note-----
In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
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, mn, mx = map(int, input().split())
A = list(map(int, input().split()))
a = min(A)
b = max(A)
if a < mn or b > mx:
print("Incorrect")
return
cnt = 0
if a > mn:
cnt += 1
if b < mx:
cnt += 1
if m + cnt <= n:
print("Correct")
else:
print("Incorrect")
main()
``` | vfc_10718 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/413/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 1 2\n1\n",
"output": "Correct\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1 3\n2\n",
"output": "Correct\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1 3\n2\n",
"output": "Incorrect\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1 5\n3\n",
"output": "Correct\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 1 5\n1 5\n",
"output": "Correct\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 242 | Solve the following coding problem using the programming language python:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?
-----Input-----
The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.
-----Output-----
First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.
-----Examples-----
Input
1
Output
5
5 6 7 8 9
Input
5
Output
0
-----Note-----
The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
m = int(input())
a = 0
while m > 0:
a += 5
b = a
c = 0
while b % 5 == 0:
b //= 5
c += 1
m -= c
if m < 0: print(0)
else:
print(5)
print(a, a + 1, a + 2, a + 3, a + 4)
``` | vfc_10722 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/633/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "5\n5 6 7 8 9 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "5\n10 11 12 13 14 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "5\n15 16 17 18 19 ",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 243 | Solve the following coding problem using the programming language python:
Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with $n$ vertices and $m$ weighted edges. There are $k$ special vertices: $x_1, x_2, \ldots, x_k$.
Let's define the cost of the path as the maximum weight of the edges in it. And the distance between two vertexes as the minimum cost of the paths connecting them.
For each special vertex, find another special vertex which is farthest from it (in terms of the previous paragraph, i.e. the corresponding distance is maximum possible) and output the distance between them.
The original constraints are really small so he thought the problem was boring. Now, he raises the constraints and hopes you can solve it for him.
-----Input-----
The first line contains three integers $n$, $m$ and $k$ ($2 \leq k \leq n \leq 10^5$, $n-1 \leq m \leq 10^5$) — the number of vertices, the number of edges and the number of special vertices.
The second line contains $k$ distinct integers $x_1, x_2, \ldots, x_k$ ($1 \leq x_i \leq n$).
Each of the following $m$ lines contains three integers $u$, $v$ and $w$ ($1 \leq u,v \leq n, 1 \leq w \leq 10^9$), denoting there is an edge between $u$ and $v$ of weight $w$. The given graph is undirected, so an edge $(u, v)$ can be used in the both directions.
The graph may have multiple edges and self-loops.
It is guaranteed, that the graph is connected.
-----Output-----
The first and only line should contain $k$ integers. The $i$-th integer is the distance between $x_i$ and the farthest special vertex from it.
-----Examples-----
Input
2 3 2
2 1
1 2 3
1 2 2
2 2 1
Output
2 2
Input
4 5 3
1 2 3
1 2 5
4 2 1
2 3 2
1 4 4
1 3 3
Output
3 3 3
-----Note-----
In the first example, the distance between vertex $1$ and $2$ equals to $2$ because one can walk through the edge of weight $2$ connecting them. So the distance to the farthest node for both $1$ and $2$ equals to $2$.
In the second example, one can find that distance between $1$ and $2$, distance between $1$ and $3$ are both $3$ and the distance between $2$ and $3$ is $2$.
The graph may have multiple edges between and self-loops, as in the first example.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def g():
return list(map(int,input().split()))
n,m,k=g()
p=list(range(n+1))
z=[0]*(n+1)
for x in g():
z[x]=1
e=[]
for i in range(m):
u,v,w=g()
e+=[(w,u,v)]
e=sorted(e)
def q(x):
if x!=p[x]:
p[x]=q(p[x])
return p[x]
for w,u,v in e:
u=q(u);v=q(v)
if u!=v:
if u%5==3:
u,v=v,u
p[u]=v;z[v]+=z[u]
if z[v]==k:
print(((str(w)+' ')*k));return
``` | vfc_10726 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1081/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n",
"output": "2 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"output": "3 3 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7 4\n1 2 3 4\n1 2 3\n5 1 4\n3 1 1\n4 2 5\n2 5 6\n2 3 3\n3 4 6\n",
"output": "5 5 5 5 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 244 | Solve the following coding problem using the programming language python:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
-----Input-----
The first line of the input contains an integer n (1 ≤ n ≤ 2·10^9) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
-----Output-----
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
-----Examples-----
Input
4
2
Output
1
Input
1
1
Output
0
-----Note-----
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
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())
k = int(input())
n %= 6
a = [0, 1, 2]
for i in range(1, n + 1):
if (i % 2 == 1):
a[0], a[1] = a[1], a[0]
else:
a[1], a[2] = a[2], a[1]
print(a[k])
main()
``` | vfc_10730 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/777/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 245 | Solve the following coding problem using the programming language python:
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle).
Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 5). Next n lines contain four integers each, describing a single rectangle: x_1, y_1, x_2, y_2 (0 ≤ x_1 < x_2 ≤ 31400, 0 ≤ y_1 < y_2 ≤ 31400) — x_1 and x_2 are x-coordinates of the left and right edges of the rectangle, and y_1 and y_2 are y-coordinates of the bottom and top edges of the rectangle.
No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle).
-----Output-----
In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.
-----Examples-----
Input
5
0 0 2 3
0 3 3 5
2 0 5 2
3 2 5 5
2 2 3 3
Output
YES
Input
4
0 0 2 3
0 3 3 5
2 0 5 2
3 2 5 5
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
s = 0
INF = 10**9
minx = miny = INF
maxx = maxy = -INF
for i in range(n):
x1, y1, x2, y2 = list(map(int, input().split()))
s += abs(x1 - x2) * abs(y1 - y2)
minx = min(minx, x1, x2)
maxx = max(maxx, x1, x2)
miny = min(miny, y1, y2)
maxy = max(maxy, y1, y2)
if (maxx - minx) == (maxy - miny) and s == (maxx - minx) ** 2:
print ("YES")
else:
print ("NO")
``` | vfc_10734 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/325/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 15000 20000\n0 20000 15000 31400\n15000 0 31400 31400\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n10359 859 28918 4384\n2895 26520 28918 26882\n2895 26424 28918 26520\n2895 859 10359 4384\n2895 4384 28918 26424\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n12750 0 25688 1\n1094 0 12750 1\n0 0 956 1\n956 0 1094 1\n25688 0 31400 1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 246 | Solve the following coding problem using the programming language python:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 ≤ n, s ≤ 10^18).
-----Output-----
Print one integer — the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def check(x, s):
k = 0
for i in str(x):
k += int(i)
return x - k >= s
n, s = map(int, input().split())
l = 0
r = n
while r - l > 1:
m = (l + r) // 2
if check(m, s):
r = m
else:
l = m
if check(r, s):
print(n - r + 1)
else:
print(0)
``` | vfc_10738 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/817/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25 20\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "300 1000\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 247 | Solve the following coding problem using the programming language python:
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of points you are given.
Then n lines follow, each line containing two integers x_{i} and y_{i} (|x_{i}|, |y_{i}| ≤ 10^9)— coordinates of i-th point. All n points are distinct.
-----Output-----
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
-----Examples-----
Input
5
0 0
0 1
1 1
1 -1
2 2
Output
YES
Input
5
0 0
1 0
2 1
1 1
2 3
Output
NO
-----Note-----
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
L = [(0, 0)] * n
for i in range(n):
t = input().split(' ')
a = int(t[0])
b = int(t[1])
L[i] = (a, b)
if n <= 4:
print("YES")
else:
b0 = True
b1 = True
b2 = True
L0 = []
L1 = []
L2 = []
for j in range(n):
if (L[0][0]-L[1][0])*(L[0][1]-L[j][1])!=(L[0][1]-L[1][1])*(L[0][0]-L[j][0]):
L2.append(L[j])
if (L[2][0]-L[0][0])*(L[2][1]-L[j][1])!=(L[2][1]-L[0][1])*(L[2][0]-L[j][0]):
L1.append(L[j])
if (L[2][0]-L[1][0])*(L[2][1]-L[j][1])!=(L[2][1]-L[1][1])*(L[2][0]-L[j][0]):
L0.append(L[j])
if len(L0) >= 3:
for j in range(2, len(L0)):
if (L0[0][0]-L0[1][0])*(L0[0][1]-L0[j][1])!=(L0[0][1]-L0[1][1])*(L0[0][0]-L0[j][0]):
b0 = False
if len(L1) >= 3:
for j in range(2, len(L1)):
if (L1[0][0]-L1[1][0])*(L1[0][1]-L1[j][1])!=(L1[0][1]-L1[1][1])*(L1[0][0]-L1[j][0]):
b1 = False
if len(L2) >= 3:
for j in range(2, len(L2)):
if (L2[0][0]-L2[1][0])*(L2[0][1]-L2[j][1])!=(L2[0][1]-L2[1][1])*(L2[0][0]-L2[j][0]):
b2 = False
if b0 or b1 or b2:
print("YES")
else:
print("NO")
``` | vfc_10742 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/961/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n-1000000000 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 248 | Solve the following coding problem using the programming language python:
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)^2t games in total. Since the answer can be very large, you should print it modulo 10^9 + 7. Please solve this problem for Memory.
-----Input-----
The first and only line of input contains the four integers a, b, k, and t (1 ≤ a, b ≤ 100, 1 ≤ k ≤ 1000, 1 ≤ t ≤ 100) — the amount Memory and Lexa start with, the number k, and the number of turns respectively.
-----Output-----
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (10^9 + 7) in one line.
-----Examples-----
Input
1 2 2 1
Output
6
Input
1 1 1 2
Output
31
Input
2 12 3 1
Output
0
-----Note-----
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins.
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
f=[0]*500000
def POW(a,b):
if(b==0):
return 1
if(b&1):
return POW(a,b//2)**2*a%mod
else:
return POW(a,b//2)**2
def C(n,m):
if(m>n):
return 0
t=f[n]*POW(f[m],mod-2)%mod*POW(f[n-m],mod-2)%mod
return t
f[0]=1
for i in range(1,500000):
f[i]=f[i-1]*i%mod
a,b,k,t=list(map(int,input().split(' ')))
ans=0
for i in range(0,2*t+1):
t1=POW(-1,i)*C(2*t,i)%mod
t2=(C(210000+2*k*t-a+b+2*t-1-(2*k+1)*i+1,2*t)-C(1+2*k*t-a+b+2*t-1-(2*k+1)*i,2*t))%mod
ans=(ans+t1*t2)%mod
print(ans)
``` | vfc_10746 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/712/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 2 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 2\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 12 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 249 | Solve the following coding problem using the programming language python:
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a_1, a_2, ..., a_{n}, where a_{i} denotes the distance of the i-th mark from the origin (a_1 = 0, a_{n} = l).
Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, a_{j} - a_{i} = d).
Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.
Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.
-----Input-----
The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 10^5, 2 ≤ l ≤ 10^9, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of n integers a_1, a_2, ..., a_{n} (0 = a_1 < a_2 < ... < a_{n} = l), where a_{i} shows the distance from the i-th mark to the origin.
-----Output-----
In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.
In the second line print v space-separated integers p_1, p_2, ..., p_{v} (0 ≤ p_{i} ≤ l). Number p_{i} means that the i-th mark should be at the distance of p_{i} centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.
-----Examples-----
Input
3 250 185 230
0 185 250
Output
1
230
Input
4 250 185 230
0 20 185 250
Output
0
Input
2 300 185 230
0 300
Output
2
185 230
-----Note-----
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import itertools
import math
def can_measure(a, d):
return any(i + d in a for i in a)
def main():
n, l, x, y = list(map(int, input().split()))
a = set(map(int, input().split()))
can_x = can_measure(a, x)
can_y = can_measure(a, y)
if can_x and can_y:
print(0)
elif can_x:
print(1)
print(y)
elif can_y:
print(1)
print(x)
else:
for i in a:
if i + x + y in a:
print(1)
print(i + x)
break
else:
t = i + x - y in a
if 0 <= i + x <= l and t:
print(1)
print(i + x)
break;
if 0 <= i - y <= l and t:
print(1)
print(i - y)
break;
else:
print(2)
print(x, y)
def __starting_point():
main()
__starting_point()
``` | vfc_10750 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/479/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 250 185 230\n0 185 250\n",
"output": "1\n230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 250 185 230\n0 20 185 250\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 300 185 230\n0 300\n",
"output": "2\n185 230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 300 4 5\n0 6 7 300\n",
"output": "1\n11\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 251 | Solve the following coding problem using the programming language python:
There is a toy building consisting of $n$ towers. Each tower consists of several cubes standing on each other. The $i$-th tower consists of $h_i$ cubes, so it has height $h_i$.
Let's define operation slice on some height $H$ as following: for each tower $i$, if its height is greater than $H$, then remove some top cubes to make tower's height equal to $H$. Cost of one "slice" equals to the total number of removed cubes from all towers.
Let's name slice as good one if its cost is lower or equal to $k$ ($k \ge n$).
[Image]
Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n \le k \le 10^9$) — the number of towers and the restriction on slices, respectively.
The second line contains $n$ space separated integers $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 2 \cdot 10^5$) — the initial heights of towers.
-----Output-----
Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth.
-----Examples-----
Input
5 5
3 1 2 2 4
Output
2
Input
4 5
2 3 4 5
Output
2
-----Note-----
In the first example it's optimal to make $2$ slices. The first slice is on height $2$ (its cost is $3$), and the second one is on height $1$ (its cost is $4$).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def ii():
return int(input())
def mi():
return list(map(int, input().split()))
def li():
return list(mi())
n, k = mi()
h = li()
m = max(h)
f = [0] * (m + 1)
for hi in h:
f[hi] += 1
for i in range(m - 1, 0, -1):
f[i] += f[i + 1]
ans = 0
i = m
while i > 0:
if f[i] == n:
break
j = i
cur = 0
while j > 0:
if cur + f[j] > k:
break
cur += f[j]
j -= 1
ans += 1
i = j
print(ans)
``` | vfc_10758 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1065/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n3 1 2 2 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n2 3 4 5\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 252 | Solve the following coding problem using the programming language python:
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $(l \le j \le r)$. The score of the game is the total value of the remaining cards on the segment $(a_l + a_{l + 1} + \dots + a_{j - 1} + a_{j + 1} + \dots + a_{r - 1} + a_r)$. In particular, if Alice chooses a segment with just one element, then the score after Bob removes the only card is $0$.
Alice wants to make the score as big as possible. Bob takes such a card that the score is as small as possible.
What segment should Alice choose so that the score is maximum possible? Output the maximum score.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of cards.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-30 \le a_i \le 30$) — the values on the cards.
-----Output-----
Print a single integer — the final score of the game.
-----Examples-----
Input
5
5 -2 10 -1 4
Output
6
Input
8
5 2 5 3 -30 -30 6 9
Output
10
Input
3
-10 6 -15
Output
0
-----Note-----
In the first example Alice chooses a segment $[1;5]$ — the entire row of cards. Bob removes card $3$ with the value $10$ from the segment. Thus, the final score is $5 + (-2) + (-1) + 4 = 6$.
In the second example Alice chooses a segment $[1;4]$, so that Bob removes either card $1$ or $3$ with the value $5$, making the answer $5 + 2 + 3 = 10$.
In the third example Alice can choose any of the segments of length $1$: $[1;1]$, $[2;2]$ or $[3;3]$. Bob removes the only card, so the score is $0$. If Alice chooses some other segment then the answer will be less than $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()))
curr = 0
best = 0
prevs = [0] * 31
for v in l:
curr += v
if v >= 0:
for i in range(0, v):
prevs[i] = curr
for i in range(v, 31):
best = max(curr - prevs[i] - i, best)
else:
for i in range(31):
prevs[i] = min(prevs[i], curr)
print(best)
``` | vfc_10762 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1359/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 -2 10 -1 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n5 2 5 3 -30 -30 6 9\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 253 | Solve the following coding problem using the programming language python:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + k_{i}, x + 2k_{i}, x + 3k_{i} and so on.
Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x_1, x_2 and x_3 (not necessarily distinct) so that he will switch on the first garland during x_1-th second, the second one — during x_2-th second, and the third one — during x_3-th second, respectively, and during each second starting from max(x_1, x_2, x_3) at least one garland will be lit.
Help Mishka by telling him if it is possible to do this!
-----Input-----
The first line contains three integers k_1, k_2 and k_3 (1 ≤ k_{i} ≤ 1500) — time intervals of the garlands.
-----Output-----
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO.
-----Examples-----
Input
2 2 3
Output
YES
Input
4 2 3
Output
NO
-----Note-----
In the first example Mishka can choose x_1 = 1, x_2 = 2, x_3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x_3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.
In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
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 = sorted(map(int, input().split()))
if a > 3:
print('NO')
elif a == 3:
if b > 3:
print('NO')
elif b == 3:
if c > 3:
print('NO')
else:
print("YES")
elif a == 1:
print('YES')
else:
if b == 2:
print('YES')
elif b > 4:
print('NO')
elif b == 4:
if c == 4:
print('YES')
else:
print('NO')
else:
print('NO')
``` | vfc_10766 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/911/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 254 | Solve the following coding problem using the programming language python:
You are given a string $s$ of length $n$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.
Calculate the minimum number of operations to delete the whole string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 500$) — the length of string $s$.
The second line contains the string $s$ ($|s| = n$) consisting of lowercase Latin letters.
-----Output-----
Output a single integer — the minimal number of operation to delete string $s$.
-----Examples-----
Input
5
abaca
Output
3
Input
8
abcddcba
Output
4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#credits https://www.geeksforgeeks.org/minimum-steps-to-delete-a-ssing-after-repeated-deletion-of-palindrome-subssings/
n=int(input())
s=input()
N = len(s)
dp = [[0 for x in range(N + 1)]
for y in range(N + 1)]
D = [[[] for x in range(N + 1)]
for y in range(N + 1)]
ss=""
re=""
for i in range(0,N):
if re!=s[i]:
ss+=re
re=s[i]
ss+=re
a=ss
N=len(a)
for l in range(1, N + 1):
i = 0
j = l - 1
while j < N:
if (l == 1):
dp[i][j] = 1
else:
dp[i][j] =1+dp[i + 1][j]
for K in range(i + 1, j + 1):
if (a[i] == a[K]):
if dp[i][j]>=dp[i ][K - 1] + dp[K + 1][j]:
dp[i][j] = dp[i][K - 1] + dp[K + 1][j]
i += 1
j += 1
print(dp[0][N-1])
``` | vfc_10770 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1132/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nabaca\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 255 | Solve the following coding problem using the programming language python:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100), where a_{i} is the i-th boy's dancing skill.
Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b_1, b_2, ..., b_{m} (1 ≤ b_{j} ≤ 100), where b_{j} is the j-th girl's dancing skill.
-----Output-----
Print a single number — the required maximum possible number of pairs.
-----Examples-----
Input
4
1 4 6 2
5
5 1 5 7 9
Output
3
Input
4
1 2 3 4
4
10 11 12 13
Output
0
Input
5
1 1 1 1 1
3
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
n=int(input())
a=sorted(map(int,input().split()))
m=int(input())
b=sorted(map(int,input().split()))
c=0
for i in range(n):
for j in range(m):
if abs(a[i]-b[j]) <= 1:
b[j]=-10
c+=1
break
print(c)
``` | vfc_10774 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/489/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 4 6 2\n5\n5 1 5 7 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 4\n4\n10 11 12 13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n3\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 256 | Solve the following coding problem using the programming language python:
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack).
Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the i-th player is a_{i}, the attack skill is b_{i}.
Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents.
We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence.
The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team.
-----Input-----
The input contain the players' description in four lines. The i-th line contains two space-separated integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 100) — the defence and the attack skill of the i-th player, correspondingly.
-----Output-----
If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes).
-----Examples-----
Input
1 100
100 1
99 99
99 99
Output
Team 1
Input
1 1
2 2
3 3
2 2
Output
Team 2
Input
3 3
2 2
1 1
2 2
Output
Draw
-----Note-----
Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence.
Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a,b=list(map(int,input().split()))
c,d=list(map(int,input().split()))
x,y=list(map(int,input().split()))
z,w=list(map(int,input().split()))
Team1=False
Team2=False
if(a>w and a>y and d>x and d>z):
Team1=True
if(c>w and c>y and b>x and b>z):
Team1=True
if(((x>b and w>c) or (z>b and y>c)) and ((x>d and w>a) or (z>d and y>a))):
Team2=True
if(Team1):
print("Team 1")
elif(Team2):
print("Team 2")
else:
print("Draw")
``` | vfc_10778 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/411/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 100\n100 1\n99 99\n99 99\n",
"output": "Team 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n2 2\n3 3\n2 2\n",
"output": "Team 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n2 2\n1 1\n2 2\n",
"output": "Draw\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 258 | Solve the following coding problem using the programming language python:
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.
Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits.
Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket.
If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.
-----Input-----
The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ — the number of digits in the ticket.
The second line contains a string of $n$ digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.
-----Output-----
If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).
-----Examples-----
Input
4
0523
Output
Bicarp
Input
2
??
Output
Bicarp
Input
8
?054??0?
Output
Bicarp
Input
6
???00?
Output
Monocarp
-----Note-----
Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.
In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
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()
left=0
right=0
left_ques=0
right_ques=0
for i in range(n):
if i<n//2:
if s[i]=='?':
left_ques+=1
else :
left+=int(s[i])
else :
if s[i]=='?':
right_ques+=1
else :
right+=int(s[i])
x=min(left_ques,right_ques)
left_ques-=x
right_ques-=x
if left_ques==0 and right_ques==0:
if left==right:
print("Bicarp")
else :
print("Monocarp")
else :
if left_ques==0:
if right_ques%2==0:
x=9*(right_ques//2)+right
if x==left:
print("Bicarp")
else :
print("Monocarp")
else :
print("Monocarp")
else :
if left_ques%2==0:
x=9*(left_ques//2)+left
if x==right:
print("Bicarp")
else :
print("Monocarp")
else :
print("Monocarp")
``` | vfc_10786 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1215/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0523\n",
"output": "Bicarp\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n??\n",
"output": "Bicarp\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n?054??0?\n",
"output": "Bicarp\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n???00?\n",
"output": "Monocarp\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "80\n????66??8?0?????0??8?45?328??0?6???121038??????4?17??12847??3??65??6?????2????62\n",
"output": "Monocarp\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n923?5???\n",
"output": "Bicarp\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 259 | Solve the following coding problem using the programming language python:
It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.
Serval will go to the bus station at time $t$, and there are $n$ bus routes which stop at this station. For the $i$-th bus route, the first bus arrives at time $s_i$ minutes, and each bus of this route comes $d_i$ minutes later than the previous one.
As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.
-----Input-----
The first line contains two space-separated integers $n$ and $t$ ($1\leq n\leq 100$, $1\leq t\leq 10^5$) — the number of bus routes and the time Serval goes to the station.
Each of the next $n$ lines contains two space-separated integers $s_i$ and $d_i$ ($1\leq s_i,d_i\leq 10^5$) — the time when the first bus of this route arrives and the interval between two buses of this route.
-----Output-----
Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.
-----Examples-----
Input
2 2
6 4
9 5
Output
1
Input
5 5
3 3
2 5
5 6
4 9
6 1
Output
3
Input
3 7
2 2
2 3
2 4
Output
1
-----Note-----
In the first example, the first bus of the first route arrives at time $6$, and the first bus of the second route arrives at time $9$, so the first route is the answer.
In the second example, a bus of the third route arrives at time $5$, so it is the answer.
In the third example, buses of the first route come at times $2$, $4$, $6$, $8$, and so fourth, buses of the second route come at times $2$, $5$, $8$, and so fourth and buses of the third route come at times $2$, $6$, $10$, and so on, so $1$ and $2$ are both acceptable answers while $3$ is not.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# AC
import sys
class Main:
def __init__(self):
self.buff = None
self.index = 0
def __next__(self):
if self.buff is None or self.index == len(self.buff):
self.buff = sys.stdin.readline().split()
self.index = 0
val = self.buff[self.index]
self.index += 1
return val
def next_int(self):
return int(next(self))
def cal(self, s):
if len(s) == 1:
return s[0]
if s[0] == 0:
return self.cal(s[1:])
v = 1
for c in s:
v *= c
return v
def solve(self):
n = self.next_int()
t = self.next_int()
ii = 0
tt = 10000000
for i in range(0, n):
fr = self.next_int()
d = self.next_int()
if fr < t:
fr += (t - fr + d - 1) // d * d
if fr < tt:
tt = fr
ii = i
print(ii + 1)
def __starting_point():
Main().solve()
__starting_point()
``` | vfc_10790 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1153/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n6 4\n9 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n3 3\n2 5\n5 6\n4 9\n6 1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 260 | Solve the following coding problem using the programming language python:
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one".
The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18.
-----Input-----
The first line contains two space-separated integers, m and k (0 ≤ m ≤ 10^18; 1 ≤ k ≤ 64).
-----Output-----
Print the required number n (1 ≤ n ≤ 10^18). If there are multiple answers, print any of them.
-----Examples-----
Input
1 1
Output
1
Input
3 2
Output
5
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def nck(n, k, cache = {}):
if k > n or k < 0: return 0
if k == 0 or k == n: return 1
if k*2 > n: k = n-k
if (n, k) in cache: return cache[(n, k)]
z = cache[(n, k)] = nck(n-1, k-1) + nck(n-1, k)
return z
def bits(n):
b = 0
while n:
if n&1: b += 1
n >>= 1
return b
def count(n, k):
z, b, c = 0, 63, 0
for b in reversed(range(64)):
if (n>>b)&1:
z += nck(b, k-c)
c += 1
if not k: break
return z + (bits(n) == k)
def solve(m, k):
lo, hi = 1, 10**18
while lo < hi:
mi = (lo+hi)//2
if count(2*mi, k) - count(mi, k) < m:
lo = mi+1
else:
hi = mi
return hi
m, k = [int(x) for x in input().split()]
print(solve(m, k))
``` | vfc_10794 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/431/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 11\n",
"output": "1024\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 261 | Solve the following coding problem using the programming language python:
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. [Image]
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i_1, he can make a sequence of jumps through the platforms i_1 < i_2 < ... < i_{k}, if i_2 - i_1 = i_3 - i_2 = ... = i_{k} - i_{k} - 1. Of course, all segments i_1, i_2, ... i_{k} should be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i_1, i_2, ..., i_5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100) — the number of segments on the level.
Next line contains the scheme of the level represented as a string of n characters '*' and '.'.
-----Output-----
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
-----Examples-----
Input
16
.**.*..*.***.**.
Output
yes
Input
11
.*.*...*.*.
Output
no
-----Note-----
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
kk=0
x = int(input())
y = input()
z = [i for i in range(len(y)) if y[i] == '*']
for i in range(0, 100):
for j in range(1, 100):
if i in z and i+j in z and i+2*j in z and i+3*j in z and i+4*j in z:
kk=1
if kk==1:
print("yes")
else:
print("no")
``` | vfc_10798 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/526/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "16\n.**.*..*.***.**.\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n.*.*...*.*.\n",
"output": "no",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**\n",
"output": "yes",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 263 | Solve the following coding problem using the programming language python:
There are $n$ benches in the Berland Central park. It is known that $a_i$ people are currently sitting on the $i$-th bench. Another $m$ people are coming to the park and each of them is going to have a seat on some bench out of $n$ available.
Let $k$ be the maximum number of people sitting on one bench after additional $m$ people came to the park. Calculate the minimum possible $k$ and the maximum possible $k$.
Nobody leaves the taken seat during the whole process.
-----Input-----
The first line contains a single integer $n$ $(1 \le n \le 100)$ — the number of benches in the park.
The second line contains a single integer $m$ $(1 \le m \le 10\,000)$ — the number of people additionally coming to the park.
Each of the next $n$ lines contains a single integer $a_i$ $(1 \le a_i \le 100)$ — the initial number of people on the $i$-th bench.
-----Output-----
Print the minimum possible $k$ and the maximum possible $k$, where $k$ is the maximum number of people sitting on one bench after additional $m$ people came to the park.
-----Examples-----
Input
4
6
1
1
1
1
Output
3 7
Input
1
10
5
Output
15 15
Input
3
6
1
6
5
Output
6 12
Input
3
7
1
6
5
Output
7 13
-----Note-----
In the first example, each of four benches is occupied by a single person. The minimum $k$ is $3$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $k$ is $7$. That requires all six new people to occupy the same bench.
The second example has its minimum $k$ equal to $15$ and maximum $k$ equal to $15$, as there is just a single bench in the park and all $10$ people will occupy it.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
m = int(input())
a = []
for i in range(n):
a.append(int(input()))
mx = max(a) + m
while m:
for i in range(n):
if a[i] == min(a):
a[i] += 1
m -= 1
break
print(max(a), mx)
``` | vfc_10806 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1042/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n6\n1\n1\n1\n1\n",
"output": "3 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n5\n",
"output": "15 15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n6\n1\n6\n5\n",
"output": "6 12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n7\n1\n6\n5\n",
"output": "7 13\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 264 | Solve the following coding problem using the programming language python:
There is an airplane which has n rows from front to back. There will be m people boarding this airplane.
This airplane has an entrance at the very front and very back of the plane.
Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the plane one by one starting with person 1. Each person can independently choose either the front entrance or back entrance to enter the plane.
When a person walks into the plane, they walk directly to their assigned seat and will try to sit in it. If it is occupied, they will continue walking in the direction they walked in until they are at empty seat - they will take the earliest empty seat that they can find. If they get to the end of the row without finding a seat, they will be angry.
Find the number of ways to assign tickets to the passengers and board the plane without anyone getting angry. Two ways are different if there exists a passenger who chose a different entrance in both ways, or the assigned seat is different. Print this count modulo 10^9 + 7.
-----Input-----
The first line of input will contain two integers n, m (1 ≤ m ≤ n ≤ 1 000 000), the number of seats, and the number of passengers, respectively.
-----Output-----
Print a single number, the number of ways, modulo 10^9 + 7.
-----Example-----
Input
3 3
Output
128
-----Note-----
Here, we will denote a passenger by which seat they were assigned, and which side they came from (either "F" or "B" for front or back, respectively).
For example, one valid way is 3B, 3B, 3B (i.e. all passengers were assigned seat 3 and came from the back entrance). Another valid way would be 2F, 1B, 3F.
One invalid way would be 2B, 2B, 2B, since the third passenger would get to the front without finding a seat.
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, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)
``` | vfc_10810 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/838/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000 1000000\n",
"output": "233176135\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000 500000\n",
"output": "211837745\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 265 | Solve the following coding problem using the programming language python:
A company of $n$ friends wants to order exactly two pizzas. It is known that in total there are $9$ pizza ingredients in nature, which are denoted by integers from $1$ to $9$.
Each of the $n$ friends has one or more favorite ingredients: the $i$-th of friends has the number of favorite ingredients equal to $f_i$ ($1 \le f_i \le 9$) and your favorite ingredients form the sequence $b_{i1}, b_{i2}, \dots, b_{if_i}$ ($1 \le b_{it} \le 9$).
The website of CodePizza restaurant has exactly $m$ ($m \ge 2$) pizzas. Each pizza is characterized by a set of $r_j$ ingredients $a_{j1}, a_{j2}, \dots, a_{jr_j}$ ($1 \le r_j \le 9$, $1 \le a_{jt} \le 9$) , which are included in it, and its price is $c_j$.
Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 10^5, 2 \le m \le 10^5$) — the number of friends in the company and the number of pizzas, respectively.
Next, the $n$ lines contain descriptions of favorite ingredients of the friends: the $i$-th of them contains the number of favorite ingredients $f_i$ ($1 \le f_i \le 9$) and a sequence of distinct integers $b_{i1}, b_{i2}, \dots, b_{if_i}$ ($1 \le b_{it} \le 9$).
Next, the $m$ lines contain pizza descriptions: the $j$-th of them contains the integer price of the pizza $c_j$ ($1 \le c_j \le 10^9$), the number of ingredients $r_j$ ($1 \le r_j \le 9$) and the ingredients themselves as a sequence of distinct integers $a_{j1}, a_{j2}, \dots, a_{jr_j}$ ($1 \le a_{jt} \le 9$).
-----Output-----
Output two integers $j_1$ and $j_2$ ($1 \le j_1,j_2 \le m$, $j_1 \ne j_2$) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.
-----Examples-----
Input
3 4
2 6 7
4 2 3 9 5
3 2 3 9
100 1 7
400 3 3 2 5
100 2 9 2
500 3 2 9 5
Output
2 3
Input
4 3
1 1
1 2
1 3
1 4
10 4 1 2 3 4
20 4 1 2 3 4
30 4 1 2 3 4
Output
1 2
Input
1 5
9 9 8 7 6 5 4 3 2 1
3 4 1 2 3 4
1 4 5 6 7 8
4 4 1 3 5 7
1 4 2 4 6 8
5 4 1 9 2 8
Output
2 4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# author: ThePonyCoder
# created: 23.06.2019, 21:58
# filename: f.py
# path: C:/Users/User/Desktop/python/Prog/CodeForces/rounds/cf_568/f.py
import os
# import random
# sys.setrecursionlimit(999999999)
import string
from math import inf
from functools import lru_cache
if os.getcwd() == 'C:\\Users\\User\\Desktop\\python\\Prog\\CodeForces' \
or os.environ['COMPUTERNAME'] == 'USER145':
import pdb
import sys
pdb = pdb.Pdb(stdin=sys.stdin, stdout=sys.stdout)
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
from pprint import pprint
from hypothesis import given, settings
from hypothesis import strategies as st
def ri():
return [int(i) for i in input().split()]
def to_bits(l):
ans = 0
for i in l:
ans |= (1 << i - 1)
return ans
user_masks = [0 for i in range(1 << 10)]
pizzas = [[] for i in range(1 << 10)]
@lru_cache()
def count_sat_users(mask):
ans = 0
cmask = mask
while cmask:
ans += user_masks[cmask]
cmask = (cmask - 1) & mask
return ans
def main():
n, m = ri()
for _ in range(n):
k, *a = ri()
bits = to_bits(a)
user_masks[bits] += 1
ans = (float(-inf), float(inf), -1, -1)
for i in range(m):
c, k, *a = ri()
bits = to_bits(a)
pizzas[bits].append((c, i + 1, bits)) # цена, номер, маска
pizzas[bits].sort()
while len(pizzas[bits]) > 2:
pizzas[bits].pop()
# pprint(pizzas)
for mask_F in range(1 << 9):
for mask_S in range(1 << 9):
if len(pizzas[mask_F]) and len(pizzas[mask_S]) \
and mask_F != mask_S:
mask = mask_F | mask_S
satisfied_users = count_sat_users(mask)
f_pizza = next(iter(pizzas[mask_F]))
s_pizza = next(iter(pizzas[mask_S]))
summary_cost = 0
summary_cost += f_pizza[0]
summary_cost += s_pizza[0]
ans = max(ans,
(satisfied_users,
-summary_cost,
s_pizza[1],
f_pizza[1]))
# bruting all masks
bmask = mask
while bmask:
satisfied_users += user_masks[bmask]
bmask = (bmask - 1) & mask
if len(pizzas[mask_F]) == 2:
satisfied_users = count_sat_users(mask_F)
it = iter(pizzas[mask_F])
f_pizza = next(it)
s_pizza = next(it)
summary_cost = 0
summary_cost += f_pizza[0] + s_pizza[0]
ans = max(ans,
(satisfied_users,
-summary_cost,
s_pizza[1],
f_pizza[1]))
if len(pizzas[mask_S]) == 2:
satisfied_users = count_sat_users(mask_S)
it = iter(pizzas[mask_S])
f_pizza = next(it)
s_pizza = next(it)
summary_cost = 0
summary_cost += f_pizza[0] + s_pizza[0]
ans = max(ans,
(satisfied_users,
-summary_cost,
s_pizza[1],
f_pizza[1]))
aans = [ans[2],ans[3]]
aans.sort()
print(*aans, sep=' ')
main()
``` | vfc_10814 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1185/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n2 6 7\n4 2 3 9 5\n3 2 3 9\n100 1 7\n400 3 3 2 5\n100 2 9 2\n500 3 2 9 5\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 1\n1 2\n1 3\n1 4\n10 4 1 2 3 4\n20 4 1 2 3 4\n30 4 1 2 3 4\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n9 9 8 7 6 5 4 3 2 1\n3 4 1 2 3 4\n1 4 5 6 7 8\n4 4 1 3 5 7\n1 4 2 4 6 8\n5 4 1 9 2 8\n",
"output": "2 4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 266 | Solve the following coding problem using the programming language python:
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
M,S=list(map(int,input().split()))
if S==0 and M==1:
print('0 0')
return
elif S==0 or M*9 < S:
print('-1 -1')
return
m,s=M,S
l=[]
if s<=(m-1)*9+1:
l.append(1)
s-=1
while len(l)<m:
r = (m-len(l)-1)*9
if s<=r:
l.append(0)
else:
l.append(s-r)
s-=s-r
m,s=M,S
h=[]
while s>=9:
h.append(9)
s-=9
while len(h)<m:
h.append(s)
s=0
print(''.join(repr(x) for x in l), ''.join(repr(x) for x in h))
``` | vfc_10818 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/489/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 15\n",
"output": "69 96\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n",
"output": "10 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10\n",
"output": "109 910\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100\n",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 900\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 267 | Solve the following coding problem using the programming language python:
You are given two integers $l$ and $r$ ($l \le r$). Your task is to calculate the sum of numbers from $l$ to $r$ (including $l$ and $r$) such that each number contains at most $k$ different digits, and print this sum modulo $998244353$.
For example, if $k = 1$ then you have to calculate all numbers from $l$ to $r$ such that each number is formed using only one digit. For $l = 10, r = 50$ the answer is $11 + 22 + 33 + 44 = 110$.
-----Input-----
The only line of the input contains three integers $l$, $r$ and $k$ ($1 \le l \le r < 10^{18}, 1 \le k \le 10$) — the borders of the segment and the maximum number of different digits.
-----Output-----
Print one integer — the sum of numbers from $l$ to $r$ such that each number contains at most $k$ different digits, modulo $998244353$.
-----Examples-----
Input
10 50 2
Output
1230
Input
1 2345 10
Output
2750685
Input
101 154 2
Output
2189
-----Note-----
For the first example the answer is just the sum of numbers from $l$ to $r$ which equals to $\frac{50 \cdot 51}{2} - \frac{9 \cdot 10}{2} = 1230$. This example also explained in the problem statement but for $k = 1$.
For the second example the answer is just the sum of numbers from $l$ to $r$ which equals to $\frac{2345 \cdot 2346}{2} = 2750685$.
For the third example the answer is $101 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 121 + 122 + 131 + 133 + 141 + 144 + 151 = 2189$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
l, r, k =list(map(int,input().split()))
d = {i:2**i for i in range(10)}
cache = {}
def can(i, m):
return d[i] & m
def calc(m):
b = 1
c = 0
for i in range(10):
if b & m:
c += 1
b *= 2
return c
def sm(ln, k, m, s='', first=False):
if ln < 1:
return 0, 1
if (ln, k, m, s, first) in cache:
return cache[(ln, k, m, s, first)]
ans = 0
count = 0
base = 10 ** (ln-1)
use_new = calc(m) < k
if s:
finish = int(s[0])+1
else:
finish = 10
for i in range(finish):
if use_new or can(i, m):
ss = s[1:]
if i != finish-1:
ss = ''
nm = m | d[i]
nfirst = False
if i == 0 and first:
nm = m
nfirst = True
nexta, nextc = sm(ln-1, k, nm, ss, nfirst)
ans += base * i * nextc + nexta
count += nextc
# print(ln, k, m, s, first, ans, count)
cache[(ln, k, m, s, first)] = (ans, count)
return ans, count
def call(a, k):
s = str(a)
return sm(len(s), k, 0, s, True)[0]
#print(call(r, k) - call(l-1, k))
print((call(r, k) - call(l-1, k)) % 998244353)
``` | vfc_10822 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1073/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 50 2\n",
"output": "1230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2345 10\n",
"output": "2750685\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101 154 2\n",
"output": "2189\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 268 | Solve the following coding problem using the programming language python:
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers — saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:
Each pencil belongs to exactly one box; Each non-empty box has at least k pencils in it; If pencils i and j belong to the same box, then |a_{i} - a_{j}| ≤ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |a_{i} - a_{j}| ≤ d and they belong to different boxes.
Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO".
-----Input-----
The first line contains three integer numbers n, k and d (1 ≤ k ≤ n ≤ 5·10^5, 0 ≤ d ≤ 10^9) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.
The second line contains n integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — saturation of color of each pencil.
-----Output-----
Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO".
-----Examples-----
Input
6 3 10
7 2 7 7 4 2
Output
YES
Input
6 2 3
4 5 3 13 4 10
Output
YES
Input
3 2 5
10 16 22
Output
NO
-----Note-----
In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.
In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.
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 bisect import bisect
[n, k, d] = list(map(int, input().strip().split()))
ais = list(map(int, input().strip().split()))
if k == 1:
print ('YES')
return
ais.sort()
# can do ais[i:]
cando = [False for _ in range(n)]
j = n - 1 # j is such that a[j] > a[i] + d >= a[j - 1] (upper_bound) a[:j] <= a[i] + d < a[j:]
count = 0 # sum(cando[i + k:j + 1])
for i in reversed(list(range(n))):
if i + k < n and cando[i + k]:
count += 1
if n - i < k:
continue
if ais[-1] - ais[i] <= d:
cando[i] = True
continue
while ais[j - 1] > ais[i] + d:
if cando[j]:
count -= 1
j -= 1
cando[i] = (count > 0)
if cando[0]:
print ('YES')
else:
print ('NO')
``` | vfc_10826 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/985/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3 10\n7 2 7 7 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2 3\n4 5 3 13 4 10\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 269 | Solve the following coding problem using the programming language python:
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.
Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.
It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.
Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.
-----Input-----
The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland: 'R' — the light bulb is red, 'B' — the light bulb is blue, 'Y' — the light bulb is yellow, 'G' — the light bulb is green, '!' — the light bulb is dead.
The string s can not contain other symbols except those five which were described.
It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.
It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.
-----Output-----
In the only line print four integers k_{r}, k_{b}, k_{y}, k_{g} — the number of dead light bulbs of red, blue, yellow and green colors accordingly.
-----Examples-----
Input
RYBGRYBGR
Output
0 0 0 0
Input
!RGYB
Output
0 1 0 0
Input
!!!!YGRB
Output
1 1 1 1
Input
!GB!RG!Y!
Output
2 1 1 0
-----Note-----
In the first example there are no dead light bulbs.
In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to 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 = input()
n = len(s)
t = 'RBYG'
for i in t:
ind = s.find(i) % 4
ans = 0
while ind < n:
ans += s[ind] == '!'
ind += 4
print(ans, end=' ')
``` | vfc_10830 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/758/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "RYBGRYBGR\n",
"output": "0 0 0 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "!RGYB\n",
"output": "0 1 0 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "!!!!YGRB\n",
"output": "1 1 1 1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 271 | Solve the following coding problem using the programming language python:
Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.
For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.
For given n find out to which integer will Vasya round it.
-----Input-----
The first line contains single integer n (0 ≤ n ≤ 10^9) — number that Vasya has.
-----Output-----
Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
-----Examples-----
Input
5
Output
0
Input
113
Output
110
Input
1000000000
Output
1000000000
Input
5432359
Output
5432360
-----Note-----
In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
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 = int(input())
print(10 * round(n / 10))
``` | vfc_10838 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/898/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "113\n",
"output": "110\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 272 | Solve the following coding problem using the programming language python:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
-----Input-----
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
-----Output-----
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
-----Examples-----
Input
helloworld
ehoolwlroz
Output
3
h e
l o
d z
Input
hastalavistababy
hastalavistababy
Output
0
Input
merrychristmas
christmasmerry
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = input()
b = input()
symbols = {}
pairs = []
for i in range(len(a)):
if a[i] in symbols:
if symbols[a[i]] != b[i]:
print('-1')
break
elif b[i] in symbols:
if symbols[b[i]] != a[i]:
print('-1')
break
else:
symbols[a[i]] = b[i]
symbols[b[i]] = a[i]
if a[i] != b[i]:
pairs.append((a[i], b[i]))
else:
print(len(pairs))
for elem in pairs:
print(elem[0], elem[1])
``` | vfc_10842 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/748/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "helloworld\nehoolwlroz\n",
"output": "3\nh e\nl o\nd z\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "hastalavistababy\nhastalavistababy\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "merrychristmas\nchristmasmerry\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "kusyvdgccw\nkusyvdgccw\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "bbbbbabbab\naaaaabaaba\n",
"output": "1\nb a\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 273 | Solve the following coding problem using the programming language python:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).
As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".
-----Input-----
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
-----Output-----
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
-----Examples-----
Input
harry potter
Output
hap
Input
tom riddle
Output
tomr
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 *
import itertools
import sys
def main():
a, b = input().split()
ans = a + b
n = len(a)
m = len(b)
for i in range(1, n + 1):
for j in range(1, m + 1):
c = a[:i] + b[:j]
# print(c)
ans = min(ans, c)
print(ans)
main()
``` | vfc_10846 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/909/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "harry potter\n",
"output": "hap\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "tom riddle\n",
"output": "tomr\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a qdpinbmcrf\n",
"output": "aq\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 274 | Solve the following coding problem using the programming language python:
A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular.
Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height — use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as:
+- -++- -+
|+- -++- -+|| |
|| || ||| |
|+- -++- -+|| |
+- -++- -+
Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above.
Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height.
The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image.
Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique.
-----Input-----
The first line contains an even integer n (2 ≤ n ≤ 100) — the length of the sequence of brackets.
The second line contains the sequence of brackets — these are n symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular.
-----Output-----
Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces.
-----Examples-----
Input
8
[[][]][]
Output
+- -++- -+
|+- -++- -+|| |
|| || ||| |
|+- -++- -+|| |
+- -++- -+
Input
6
[[[]]]
Output
+- -+
|+- -+|
||+- -+||
||| |||
||+- -+||
|+- -+|
+- -+
Input
6
[[][]]
Output
+- -+
|+- -++- -+|
|| || ||
|+- -++- -+|
+- -+
Input
2
[]
Output
+- -+
| |
+- -+
Input
4
[][]
Output
+- -++- -+
| || |
+- -++- -+
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
x = input()
d = [0] * n
cd = 0
xp = []
for i in range(n):
if x[i] == '[':
d[i] = cd
cd = cd + 1
else:
cd = cd - 1
d[i] = cd
for i in range(n-1):
xp.append((x[i], d[i]))
if x[i] == '[' and x[i+1] == ']':
xp.extend([(' ', d[i]), (' ', d[i]), (' ', d[i])])
xp.append((x[n-1], d[n-1]))
md = max(d)
h = md * 2 + 3
res = []
for i in range(h):
l = [' ' for j in xp]
res.append(l)
for i in range(len(xp)):
for j in range(h):
if xp[i][0] == '[' and j > xp[i][1] and j < h - xp[i][1] - 1:
res[j][i] = '|'
elif xp[i][0] == ']' and j > xp[i][1] and j < h - xp[i][1] - 1:
res[j][i] = '|'
elif xp[i][0] == '[' and (j == xp[i][1] or j == h - xp[i][1] - 1):
res[j][i] = '+'
res[j][i+1] = '-'
elif xp[i][0] == ']' and (j == xp[i][1] or j == h - xp[i][1] - 1):
res[j][i] = '+'
res[j][i-1] = '-'
for i in range(h):
print(''.join(res[i]))
``` | vfc_10850 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/770/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n[[][]][]\n",
"output": "+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n[[[]]]\n",
"output": "+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n[[][]]\n",
"output": "+- -+\n|+- -++- -+|\n|| || ||\n|+- -++- -+|\n+- -+\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 275 | Solve the following coding problem using the programming language python:
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number $q = \frac{\sqrt{5} + 1}{2}$, in particular that q^2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a_0a_1...a_{n} equals to $\sum_{i = 0}^{n} a_{i} \cdot q^{n - i}$.
Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help.
Given two numbers written in golden system notation, determine which of them has larger decimal value.
-----Input-----
Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000.
-----Output-----
Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal.
-----Examples-----
Input
1000
111
Output
<
Input
00100
11
Output
=
Input
110
101
Output
>
-----Note-----
In the first example first number equals to $((\sqrt{5} + 1) / 2)^{3} \approx 1.618033988^{3} \approx 4.236$, while second number is approximately 1.618033988^2 + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number.
In the second example numbers are equal. Each of them is ≈ 2.618.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
u = v = 0
a, b = input(), input()
n, m = len(a), len(b)
if n > m: b = '0' * (n - m) + b
else: a = '0' * (m - n) + a
for i in range(max(n, m)):
u, v = v + u, u + int(a[i]) - int(b[i])
if u > 1:
print('>')
return
elif u < -1:
print('<')
return
d = 2 * v + u
if u == v == 0: print('=')
elif u >= 0 and d >= 0: print('>')
elif u <= 0 and d <= 0: print('<')
else: print('>' if (u * u > v * (v + u)) ^ (u < 0) else '<')
``` | vfc_10854 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/457/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1000\n111\n",
"output": "<\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 276 | Solve the following coding problem using the programming language python:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: the Power Gem of purple color, the Time Gem of green color, the Space Gem of blue color, the Soul Gem of orange color, the Reality Gem of red color, the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
-----Input-----
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
-----Output-----
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
-----Examples-----
Input
4
red
purple
yellow
orange
Output
2
Space
Time
Input
0
Output
6
Time
Mind
Soul
Power
Reality
Space
-----Note-----
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six.
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() for i in range(n)]
sol = []
for i in range(6):
c = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'][i]
if c not in a:
sol.append(['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'][i])
print(len(sol))
for i in sol:
print(i)
``` | vfc_10858 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/987/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nred\npurple\nyellow\norange\n",
"output": "2\nTime\nSpace\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 277 | Solve the following coding problem using the programming language python:
The last stage of Football World Cup is played using the play-off system.
There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet.
-----Input-----
The only line contains three integers n, a and b (2 ≤ n ≤ 256, 1 ≤ a, b ≤ n) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal.
-----Output-----
In the only line print "Final!" (without quotes), if teams a and b can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams a and b can meet. The round are enumerated from 1.
-----Examples-----
Input
4 1 2
Output
1
Input
8 2 6
Output
Final!
Input
8 7 5
Output
2
-----Note-----
In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.
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, a, b = list(map(int, input().split()))
cnt = 0
l = [set([x]) for x in range(1, n+1)]
while 1:
l = list([tup[0] | tup[1] for tup in zip(l[::2], l[1::2])])
cnt += 1
for el in l:
if a in el and b in el:
print(cnt if len(el) < n else 'Final!')
return
``` | vfc_10862 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/931/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 278 | Solve the following coding problem using the programming language python:
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.
Pavel has a plan: a permutation p and a sequence b_1, b_2, ..., b_{n}, consisting of zeros and ones. Each second Pavel move skewer on position i to position p_{i}, and if b_{i} equals 1 then he reverses it. So he hope that every skewer will visit every position in both directions.
Unfortunately, not every pair of permutation p and sequence b suits Pavel. What is the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements? Note that after changing the permutation should remain a permutation as well.
There is no problem for Pavel, if some skewer visits some of the placements several times before he ends to cook. In other words, a permutation p and a sequence b suit him if there is an integer k (k ≥ 2n), so that after k seconds each skewer visits each of the 2n placements.
It can be shown that some suitable pair of permutation p and sequence b exists for any n.
-----Input-----
The first line contain the integer n (1 ≤ n ≤ 2·10^5) — the number of skewers.
The second line contains a sequence of integers p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ n) — the permutation, according to which Pavel wants to move the skewers.
The third line contains a sequence b_1, b_2, ..., b_{n} consisting of zeros and ones, according to which Pavel wants to reverse the skewers.
-----Output-----
Print single integer — the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements.
-----Examples-----
Input
4
4 3 2 1
0 1 1 1
Output
2
Input
3
2 3 1
0 0 0
Output
1
-----Note-----
In the first example Pavel can change the permutation to 4, 3, 1, 2.
In the second example Pavel can change any element of b to 1.
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 = int(input())
p = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
num_cycles = 0
checked = set()
for i in range(n):
if i in checked:
continue
checked.add(i)
nxt = p[i] - 1
while nxt != i:
checked.add(nxt)
nxt = p[nxt] - 1
num_cycles += 1
ans += num_cycles if num_cycles != 1 else 0
ans += (sum(b) % 2) == 0
print(ans)
``` | vfc_10866 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/756/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 3 2 1\n0 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 279 | Solve the following coding problem using the programming language python:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v_1 meters per second, and in the end it is v_2 meters per second. We know that this section of the route took exactly t seconds to pass.
Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.
-----Input-----
The first line contains two integers v_1 and v_2 (1 ≤ v_1, v_2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.
It is guaranteed that there is a way to complete the segment so that: the speed in the first second equals v_1, the speed in the last second equals v_2, the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.
-----Output-----
Print the maximum possible length of the path segment in meters.
-----Examples-----
Input
5 6
4 2
Output
26
Input
10 10
10 0
Output
100
-----Note-----
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.
In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
v1, v2 = list(map(int, input().split()))
t, d = list(map(int, input().split()))
vm = [0] * t
v = v1
for i in range(t):
vm[i] = v
v += d
v = v2
for i in range(t - 1, -1, -1):
vm[i] = min(v, vm[i])
v += d
print(sum(vm))
``` | vfc_10870 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/534/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n4 2\n",
"output": "26",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n10 0\n",
"output": "100",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "87 87\n2 10\n",
"output": "174",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 11\n6 2\n",
"output": "36",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 10\n10 10\n",
"output": "550",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 281 | Solve the following coding problem using the programming language python:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, [Image]. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
-----Input-----
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 10^18).
-----Output-----
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
-----Examples-----
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
-----Note-----
In the first example, the last digit of $\frac{4 !}{2 !} = 12$ is 2;
In the second example, the last digit of $\frac{10 !}{0 !} = 3628800$ is 0;
In the third example, the last digit of $\frac{109 !}{107 !} = 11772$ is 2.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = map(int, input().split())
if b - a > 10:
print(0)
else:
s = 1
for i in range(a + 1, b + 1):
s *= i
print(str(s)[-1])
``` | vfc_10878 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/869/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "107 109\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 13\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "998244355 998244359\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999999000000000 1000000000000000000\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 282 | Solve the following coding problem using the programming language python:
A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d.
For each point from 1 to n is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and n.
Determine the minimal number of jumps that the frog needs to reach home which is in the point n from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
-----Input-----
The first line contains two integers n and d (2 ≤ n ≤ 100, 1 ≤ d ≤ n - 1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string s of length n, consisting of zeros and ones. If a character of the string s equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string s equal to one.
-----Output-----
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point n from the point 1.
-----Examples-----
Input
8 4
10010101
Output
2
Input
4 2
1001
Output
-1
Input
8 4
11100101
Output
3
Input
12 3
101111100101
Output
4
-----Note-----
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
'''input
4 2
1001
'''
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
n,d = map_input()
s = input()
cur = 0
cnt = 0
while cur < n-1:
j = -1
for i in range(cur+1,min(cur+d+1,n)):
if s[i] == '1': j = i
if j == -1:
print(-1)
break
cur = j
cnt += 1
else: print(cnt)
``` | vfc_10882 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/910/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 4\n10010101\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1001\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 283 | Solve the following coding problem using the programming language python:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.
-----Input-----
The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis.
-----Output-----
Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 10^3. It is guaranteed the the answer exists.
-----Examples-----
Input
3
Output
1
Input
4
Output
2
-----Note-----
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def prime(x):
if x < 2:
return False
if x == 2:
return True
if x % 2 == 0:
return False
for d in range(3, x, 2):
if d * d > x:
break
if x % d == 0:
return False
return True
def main():
n = int(input())
for m in range(1, 1001):
if not prime(n * m + 1):
ans = m
break
print(ans)
main()
``` | vfc_10886 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/755/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "153\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 284 | Solve the following coding problem using the programming language python:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?
Please help Kolya answer this question.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 10^9) — Kolya's initial game-coin score.
-----Output-----
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
-----Examples-----
Input
1359257
Output
YES
Input
17851817
Output
NO
-----Note-----
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
# Copyright (C) 2016 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
def main():
n = int(input())
ans = False
for a in range(0, 1001):
for b in range(0, 1001):
left = n - 1234567 * a - 123456 * b
if left >= 0 and left % 1234 == 0:
ans = True
print("YES" if ans else "NO")
main()
``` | vfc_10890 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/681/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1359257\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17851817\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "17851818\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "438734347\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 285 | Solve the following coding problem using the programming language python:
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = k_{i}·x + b_{i}. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x_1 < x_2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that: y' = k_{i} * x' + b_{i}, that is, point (x', y') belongs to the line number i; y' = k_{j} * x' + b_{j}, that is, point (x', y') belongs to the line number j; x_1 < x' < x_2, that is, point (x', y') lies inside the strip bounded by x_1 < x_2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
-----Input-----
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x_1 and x_2 ( - 1 000 000 ≤ x_1 < x_2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers k_{i}, b_{i} ( - 1 000 000 ≤ k_{i}, b_{i} ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either k_{i} ≠ k_{j}, or b_{i} ≠ b_{j}.
-----Output-----
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
-----Examples-----
Input
4
1 2
1 2
1 0
0 1
0 2
Output
NO
Input
2
1 3
1 0
-1 3
Output
YES
Input
2
1 3
1 0
0 2
Output
YES
Input
2
1 3
1 0
0 3
Output
NO
-----Note-----
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
k = []
x = int(input())
c, d = list(map(int, input().split(' ')))
for i in range(x):
a, b = list(map(int, input().split(' ')))
k.append([c*a+b, d*a+b])
k.sort()
for i in range(len(k)-1):
if k[i+1][1] < k[i][1]:
print("YES")
quit()
print("NO")
``` | vfc_10894 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/593/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 3\n1 0\n-1 3\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 3\n1 0\n0 2\n",
"output": "YES",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 286 | Solve the following coding problem using the programming language python:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits.
-----Input-----
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
-----Output-----
Output one integer — the answer to the problem.
-----Examples-----
Input
7
Output
4
Input
8
Output
5
Input
9
Output
5
-----Note-----
In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
print(1 + n // 2)
``` | vfc_10898 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/964/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 287 | Solve the following coding problem using the programming language python:
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.
Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
-----Input-----
The only line of the input contains two integers: n and k (1 ≤ n ≤ 10^9, 0 ≤ k ≤ n).
-----Output-----
Print the minimum possible and the maximum possible number of apartments good for Maxim.
-----Example-----
Input
6 3
Output
1 3
-----Note-----
In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
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,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 main():
n,k = LI()
if k == 0 or n==k:
return '0 0'
return "1 {}".format(min(n-k, k*2))
print(main())
``` | vfc_10902 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/854/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 0\n",
"output": "0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 8\n",
"output": "0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "966871928 890926970\n",
"output": "1 75944958\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 288 | Solve the following coding problem using the programming language python:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
-----Input-----
The only line of the input contains a single integer n (2 ≤ n ≤ 10^18) — the number of players to participate in the tournament.
-----Output-----
Print the maximum number of games in which the winner of the tournament can take part.
-----Examples-----
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
-----Note-----
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
x = 0
cur = 1
lst = 1
while cur + lst <= n:
cur, lst = cur + lst, cur
x += 1
print(x)
``` | vfc_10906 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/735/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 289 | Solve the following coding problem using the programming language python:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
-----Input-----
The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
-----Output-----
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
-----Examples-----
Input
VK
Output
1
Input
VV
Output
1
Input
V
Output
0
Input
VKKKKKKKKKVVVVVVVVVK
Output
3
Input
KVKV
Output
1
-----Note-----
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
d = dict()
d['V'] = 'K'
d['K'] = 'V'
m = s.count('VK')
s = list(s)
for i in range(len(s)):
s[i] = d[s[i]]
m = max(m,''.join(s).count('VK'))
s[i] = d[s[i]]
print(m)
``` | vfc_10910 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/801/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "VK\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "VV\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "V\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "VKKKKKKKKKVVVVVVVVVK\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "KVKV\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "VKKVVVKVKVK\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 290 | Solve the following coding problem using the programming language python:
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $n$ squares in the snow with a side length of $1$. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length $1$, parallel to the coordinate axes, with vertices at integer points.
In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends $(x, y)$ and $(x, y+1)$. Then Sofia looks if there is already a drawn segment with the coordinates of the ends $(x', y)$ and $(x', y+1)$ for some $x'$. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates $x$, $x+1$ and the differing coordinate $y$.
For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: [Image]
After that, she can draw the remaining two segments, using the first two as a guide: [Image]
If Sofia needs to draw two squares, she will have to draw three segments using a ruler: [Image]
After that, she can draw the remaining four segments, using the first three as a guide: [Image]
Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.
-----Input-----
The only line of input contains a single integer $n$ ($1 \le n \le 10^{9}$), the number of squares that Sofia wants to draw.
-----Output-----
Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw $n$ squares in the manner described above.
-----Examples-----
Input
1
Output
2
Input
2
Output
3
Input
4
Output
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 = b = 1
while a * b < n:
if a < b:
a += 1
else:
b += 1
print(a+b)
``` | vfc_10914 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1099/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 291 | Solve the following coding problem using the programming language python:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
-----Input-----
The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.
-----Output-----
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
-----Examples-----
Input
4 7
Output
2
Input
4 9
Output
3
Input
1 1
Output
1
-----Note-----
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def l2i(s):
return [int(i) for i in s.split()]
a, b=l2i(input())
t=0
while (a<=b):
a*=3
b*=2
t+=1
print(t)
``` | vfc_10918 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/791/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 292 | Solve the following coding problem using the programming language python:
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left to the right from 1 to 2^{h}. The exit is located at some node n where 1 ≤ n ≤ 2^{h}, the player doesn't know where the exit is so he has to guess his way out!
Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules: Character 'L' means "go to the left child of the current node"; Character 'R' means "go to the right child of the current node"; If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node; If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command; If he reached a leaf node that is not the exit, he returns to the parent of the current node; If he reaches an exit, the game is finished.
Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?
-----Input-----
Input consists of two integers h, n (1 ≤ h ≤ 50, 1 ≤ n ≤ 2^{h}).
-----Output-----
Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.
-----Examples-----
Input
1 2
Output
2
Input
2 3
Output
5
Input
3 6
Output
10
Input
10 1024
Output
2046
-----Note-----
A perfect binary tree of height h is a binary tree consisting of h + 1 levels. Level 0 consists of a single node called root, level h consists of 2^{h} nodes called leaves. Each node that is not a leaf has exactly two children, left and right one.
Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
h, n = list(map(int, input().split()))
c, m = 0, 2 ** h
r = 0
while m > 1:
if c == 0:
if n > m // 2:
r += m - 1
n -= m // 2
c = 1 - c
else:
if n > m // 2:
n -= m // 2
else:
r += m - 1
c = 1 - c
c = 1 - c
r += 1
m //= 2
#print(c, m, r, n)
print(r)
``` | vfc_10922 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/507/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n",
"output": "2",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits